< prev index next >

src/hotspot/share/jfr/utilities/jfrJavaLog.cpp

Print this page

  1 /*
  2  * Copyright (c) 2016, 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 "jfr/jni/jfrJavaSupport.hpp"
 26 #include "jfr/utilities/jfrJavaLog.hpp"
 27 #include "jfr/utilities/jfrLogTagSets.hpp"
 28 #include "logging/log.hpp"
 29 #include "logging/logConfiguration.hpp"
 30 #include "logging/logMessage.hpp"
 31 #include "memory/resourceArea.hpp"
 32 #include "oops/objArrayOop.inline.hpp"

 33 #include "runtime/javaThread.hpp"
 34 
 35 #define JFR_LOG_TAGS_CONCATED(T0, T1, T2, T3, T4, T5, ...)  \
 36   T0 ## _ ## T1 ## _ ## T2 ## _ ## T3 ## _ ## T4 ## _ ## T5
 37 
 38 enum JfrLogTagSetType {
 39 #define JFR_LOG_TAG(...) \
 40     EXPAND_VARARGS(JFR_LOG_TAGS_CONCATED(__VA_ARGS__, _NO_TAG, _NO_TAG, _NO_TAG, _NO_TAG, _NO_TAG, _NO_TAG)),
 41 
 42     JFR_LOG_TAG_SET_LIST
 43 
 44 #undef JFR_LOG_TAG
 45     JFR_LOG_TAG_SET_COUNT
 46 };
 47 
 48 struct jfrLogSubscriber
 49 {
 50   jobject log_tag_enum_ref;
 51   LogTagSet* log_tag_set;
 52 };

113   log_tag_sets[id].log_tag_enum_ref = JfrJavaSupport::global_jni_handle(log_tag, THREAD);
114   if (subscribed_updates) {
115     LogConfiguration::register_update_listener(&log_config_change);
116     log_config_change_internal(true, THREAD);
117     subscribed_updates = false;
118   } else {
119     log_config_change_internal(false, THREAD);
120   }
121 }
122 
123 void JfrJavaLog::log_event(JNIEnv* env, jint level, jobjectArray lines, bool system, TRAPS) {
124   DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
125   if (lines == nullptr) {
126     return;
127   }
128   if (level < (jint)LogLevel::First || level > (jint)LogLevel::Last) {
129     JfrJavaSupport::throw_illegal_argument_exception("LogLevel passed is outside valid range", THREAD);
130     return;
131   }
132 
133   objArrayOop the_lines = objArrayOop(JfrJavaSupport::resolve_non_null(lines));
134   assert(the_lines != nullptr, "invariant");
135   assert(the_lines->is_array(), "must be array");
136   const int length = the_lines->length();
137 
138   ResourceMark rm(THREAD);
139   LogMessage(jfr, event) jfr_event;
140   LogMessage(jfr, system, event) jfr_event_system;
141   for (int i = 0; i < length; ++i) {
142     const char* text = JfrJavaSupport::c_str(the_lines->obj_at(i), THREAD);
143     if (text == nullptr) {
144       // An oome has been thrown and is pending.
145       return;
146     }
147     if (system) {
148       jfr_event_system.write((LogLevelType)level, "%s", text);
149     } else {
150       jfr_event.write((LogLevelType)level, "%s", text);
151     }
152   }
153 }
154 
155 void JfrJavaLog::log(jint tag_set, jint level, jstring message, TRAPS) {

  1 /*
  2  * Copyright (c) 2016, 2026, 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 "jfr/jni/jfrJavaSupport.hpp"
 26 #include "jfr/utilities/jfrJavaLog.hpp"
 27 #include "jfr/utilities/jfrLogTagSets.hpp"
 28 #include "logging/log.hpp"
 29 #include "logging/logConfiguration.hpp"
 30 #include "logging/logMessage.hpp"
 31 #include "memory/resourceArea.hpp"
 32 #include "oops/objArrayOop.inline.hpp"
 33 #include "oops/oopCast.inline.hpp"
 34 #include "runtime/javaThread.hpp"
 35 
 36 #define JFR_LOG_TAGS_CONCATED(T0, T1, T2, T3, T4, T5, ...)  \
 37   T0 ## _ ## T1 ## _ ## T2 ## _ ## T3 ## _ ## T4 ## _ ## T5
 38 
 39 enum JfrLogTagSetType {
 40 #define JFR_LOG_TAG(...) \
 41     EXPAND_VARARGS(JFR_LOG_TAGS_CONCATED(__VA_ARGS__, _NO_TAG, _NO_TAG, _NO_TAG, _NO_TAG, _NO_TAG, _NO_TAG)),
 42 
 43     JFR_LOG_TAG_SET_LIST
 44 
 45 #undef JFR_LOG_TAG
 46     JFR_LOG_TAG_SET_COUNT
 47 };
 48 
 49 struct jfrLogSubscriber
 50 {
 51   jobject log_tag_enum_ref;
 52   LogTagSet* log_tag_set;
 53 };

114   log_tag_sets[id].log_tag_enum_ref = JfrJavaSupport::global_jni_handle(log_tag, THREAD);
115   if (subscribed_updates) {
116     LogConfiguration::register_update_listener(&log_config_change);
117     log_config_change_internal(true, THREAD);
118     subscribed_updates = false;
119   } else {
120     log_config_change_internal(false, THREAD);
121   }
122 }
123 
124 void JfrJavaLog::log_event(JNIEnv* env, jint level, jobjectArray lines, bool system, TRAPS) {
125   DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD));
126   if (lines == nullptr) {
127     return;
128   }
129   if (level < (jint)LogLevel::First || level > (jint)LogLevel::Last) {
130     JfrJavaSupport::throw_illegal_argument_exception("LogLevel passed is outside valid range", THREAD);
131     return;
132   }
133 
134   refArrayOop the_lines = oop_cast<refArrayOop>(JfrJavaSupport::resolve_non_null(lines));


135   const int length = the_lines->length();
136 
137   ResourceMark rm(THREAD);
138   LogMessage(jfr, event) jfr_event;
139   LogMessage(jfr, system, event) jfr_event_system;
140   for (int i = 0; i < length; ++i) {
141     const char* text = JfrJavaSupport::c_str(the_lines->obj_at(i), THREAD);
142     if (text == nullptr) {
143       // An oome has been thrown and is pending.
144       return;
145     }
146     if (system) {
147       jfr_event_system.write((LogLevelType)level, "%s", text);
148     } else {
149       jfr_event.write((LogLevelType)level, "%s", text);
150     }
151   }
152 }
153 
154 void JfrJavaLog::log(jint tag_set, jint level, jstring message, TRAPS) {
< prev index next >