1 /*
2 * Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "code/nmethod.hpp"
26 #include "compiler/compilationLog.hpp"
27 #include "compiler/compileTask.hpp"
28 #include "logging/log.hpp"
29 #include "memory/resourceArea.hpp"
30 #include "runtime/thread.hpp"
31 #include "utilities/ostream.hpp"
32
33 CompilationLog* CompilationLog::_log;
34
35 CompilationLog::CompilationLog() : StringEventLog("Compilation events", "jit") {
36 }
37
38 void CompilationLog::log_compile(JavaThread* thread, CompileTask* task) {
39 StringLogMessage lm;
40 stringStream sstr(lm.buffer(), lm.size());
41 // msg.time_stamp().update_to(tty->time_stamp().ticks());
42 task->print(&sstr, nullptr, true, false);
43 log(thread, "%s", (const char*)lm);
44 }
45
46 void CompilationLog::log_nmethod(JavaThread* thread, nmethod* nm) {
47 log(thread, "nmethod %d %s " INTPTR_FORMAT " code [" INTPTR_FORMAT ", " INTPTR_FORMAT "]",
48 nm->compile_id(), nm->compile_kind(),
49 p2i(nm), p2i(nm->code_begin()), p2i(nm->code_end()));
50 }
51
52 void CompilationLog::log_failure(JavaThread* thread, CompileTask* task, const char* reason, const char* retry_message) {
53 StringLogMessage lm;
54 if (task == nullptr) {
55 lm.print("Id not known, task was 0; COMPILE SKIPPED: %s", reason);
56 } else {
57 lm.print("%4d COMPILE SKIPPED: %s", task->compile_id(), reason);
58 }
59 if (retry_message != nullptr) {
60 lm.append(" (%s)", retry_message);
61 }
62 lm.print("\n");
63 log(thread, "%s", (const char*)lm);
64 }
65
66 void CompilationLog::log_metaspace_failure(const char* reason) {
67 // Note: This method can be called from non-Java/compiler threads to
68 // log the global metaspace failure that might affect profiling.
69 ResourceMark rm;
70 StringLogMessage lm;
71 lm.print("%4d COMPILE PROFILING SKIPPED: %s", -1, reason);
72 lm.print("\n");
73 log(Thread::current(), "%s", (const char*)lm);
74 }
75
76 void CompilationLog::init() {
77 _log = new CompilationLog();
78 }