2
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2023, 2024, Red Hat, Inc. and/or its affiliates.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
26
#include "precompiled.hpp"
28
#if defined(COMPILER1) || defined(COMPILER2)
31
#include "c1/c1_Compilation.hpp"
33
#include "ci/ciEnv.hpp"
34
#include "compiler/abstractCompiler.hpp"
35
#include "compiler/compilationFailureInfo.hpp"
36
#include "compiler/compileTask.hpp"
38
#include "opto/node.hpp"
39
#include "opto/compile.hpp"
41
#include "runtime/os.hpp"
42
#include "utilities/ostream.hpp"
43
#include "utilities/nativeCallStack.hpp"
45
int CompilationFailureInfo::current_compile_id_or_0() {
46
ciEnv* env = ciEnv::current();
47
return (env != nullptr) ? env->compile_id() : 0;
50
CompilationFailureInfo::CompilationFailureInfo(const char* failure_reason) :
52
_failure_reason(os::strdup(failure_reason)),
53
_elapsed_seconds(os::elapsedTime()),
54
_compile_id(current_compile_id_or_0())
57
CompilationFailureInfo::~CompilationFailureInfo() {
58
os::free(_failure_reason);
61
void CompilationFailureInfo::print_on(outputStream* st) const {
63
os::print_elapsed_time(st, _elapsed_seconds);
64
st->print_cr(" Compile id: %d", _compile_id);
65
st->print_cr(" Reason: '%s'", _failure_reason);
66
st->print_cr(" Callstack: ");
71
// Convenience function to print current compile failure iff
72
// current thread is compiler thread and there is a pending failure.
73
// Otherwise prints nothing.
74
bool CompilationFailureInfo::print_pending_compilation_failure(outputStream* st) {
76
const CompilationFailureInfo* info = nullptr;
78
// Carefully tiptoeing because we are called from the error reporter and
79
// nothing is certain.
81
const Thread* const t = Thread::current();
82
if (t == nullptr || !t->is_Compiler_thread()) {
86
const ciEnv* const env = ciEnv::current();
91
const CompileTask* const task = env->task();
92
if (task == nullptr) {
96
const AbstractCompiler* const compiler = task->compiler();
97
if (compiler == nullptr) {
102
if (compiler->type() == compiler_c1) {
103
const Compilation* const C = (Compilation*)env->compiler_data();
105
info = C->first_failure_details();
110
if (compiler->type() == compiler_c2) {
111
const Compile* const C = (Compile*)env->compiler_data();
113
info = C->first_failure_details();
118
if (info != nullptr) {
119
st->print_cr("Pending compilation failure details for thread " PTR_FORMAT ":", p2i(t));
126
#endif // defined(COMPILER1) || defined(COMPILER2)