< prev index next >

src/hotspot/share/jfr/jni/jfrJavaSupport.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  *

 25 #include "classfile/javaClasses.inline.hpp"
 26 #include "classfile/modules.hpp"
 27 #include "classfile/symbolTable.hpp"
 28 #include "classfile/vmClasses.hpp"
 29 #include "classfile/vmSymbols.hpp"
 30 #include "jfr/instrumentation/jfrEventClassTransformer.hpp"
 31 #include "jfr/jni/jfrJavaCall.hpp"
 32 #include "jfr/jni/jfrJavaSupport.hpp"
 33 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"
 34 #include "jfr/recorder/checkpoint/types/traceid/jfrOopTraceId.inline.hpp"
 35 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceIdEpoch.hpp"
 36 #include "jfr/support/jfrThreadId.inline.hpp"
 37 #include "logging/log.hpp"
 38 #include "memory/oopFactory.hpp"
 39 #include "memory/resourceArea.hpp"
 40 #include "oops/instanceOop.hpp"
 41 #include "oops/klass.inline.hpp"
 42 #include "oops/objArrayKlass.hpp"
 43 #include "oops/objArrayOop.inline.hpp"
 44 #include "oops/oop.inline.hpp"

 45 #include "runtime/fieldDescriptor.inline.hpp"
 46 #include "runtime/handles.inline.hpp"
 47 #include "runtime/java.hpp"
 48 #include "runtime/javaCalls.hpp"
 49 #include "runtime/javaThread.hpp"
 50 #include "runtime/jniHandles.inline.hpp"
 51 #include "runtime/semaphore.inline.hpp"
 52 #include "runtime/synchronizer.hpp"
 53 #include "runtime/threadSMR.hpp"
 54 #include "utilities/growableArray.hpp"
 55 
 56 #ifdef ASSERT
 57 static void check_java_thread_state(JavaThread* t, JavaThreadState state) {
 58   assert(t != nullptr, "invariant");
 59   assert(t->is_Java_thread(), "invariant");
 60   assert(t->thread_state() == state, "invariant");
 61 }
 62 
 63 void JfrJavaSupport::check_java_thread_in_vm(JavaThread* t) {
 64   check_java_thread_state(t, _thread_in_vm);

525 const char* JfrJavaSupport::c_str(jstring string, Thread* thread, bool c_heap /* false */) {
526   return string != nullptr ? c_str(resolve_non_null(string), thread, c_heap) : nullptr;
527 }
528 
529 void JfrJavaSupport::free_c_str(const char* str, bool c_heap) {
530   if (c_heap) {
531     FREE_C_HEAP_ARRAY(char, str);
532   }
533 }
534 
535 static Symbol** allocate_symbol_array(bool c_heap, int length, Thread* thread) {
536   return c_heap ?
537            NEW_C_HEAP_ARRAY(Symbol*, length, mtTracing) :
538            NEW_RESOURCE_ARRAY_IN_THREAD(thread, Symbol*, length);
539 }
540 
541 Symbol** JfrJavaSupport::symbol_array(jobjectArray string_array, JavaThread* thread, intptr_t* result_array_size, bool c_heap /* false */) {
542   DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread));
543   assert(string_array != nullptr, "invariant");
544   assert(result_array_size != nullptr, "invariant");
545   objArrayOop arrayOop = objArrayOop(resolve_non_null(string_array));
546   const int length = arrayOop->length();
547   *result_array_size = length;
548   Symbol** result_array = allocate_symbol_array(c_heap, length, thread);
549   assert(result_array != nullptr, "invariant");
550   for (int i = 0; i < length; i++) {
551     oop object = arrayOop->obj_at(i);
552     Symbol* symbol = nullptr;
553     if (object != nullptr) {
554       const char* text = c_str(arrayOop->obj_at(i), thread, c_heap);
555       symbol = SymbolTable::new_symbol(text);
556       free_c_str(text, c_heap);
557     }
558     result_array[i] = symbol;
559   }
560   return result_array;
561 }
562 
563 /*
564  *  Exceptions and errors
565  */

  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  *

 25 #include "classfile/javaClasses.inline.hpp"
 26 #include "classfile/modules.hpp"
 27 #include "classfile/symbolTable.hpp"
 28 #include "classfile/vmClasses.hpp"
 29 #include "classfile/vmSymbols.hpp"
 30 #include "jfr/instrumentation/jfrEventClassTransformer.hpp"
 31 #include "jfr/jni/jfrJavaCall.hpp"
 32 #include "jfr/jni/jfrJavaSupport.hpp"
 33 #include "jfr/recorder/checkpoint/jfrCheckpointManager.hpp"
 34 #include "jfr/recorder/checkpoint/types/traceid/jfrOopTraceId.inline.hpp"
 35 #include "jfr/recorder/checkpoint/types/traceid/jfrTraceIdEpoch.hpp"
 36 #include "jfr/support/jfrThreadId.inline.hpp"
 37 #include "logging/log.hpp"
 38 #include "memory/oopFactory.hpp"
 39 #include "memory/resourceArea.hpp"
 40 #include "oops/instanceOop.hpp"
 41 #include "oops/klass.inline.hpp"
 42 #include "oops/objArrayKlass.hpp"
 43 #include "oops/objArrayOop.inline.hpp"
 44 #include "oops/oop.inline.hpp"
 45 #include "oops/oopCast.inline.hpp"
 46 #include "runtime/fieldDescriptor.inline.hpp"
 47 #include "runtime/handles.inline.hpp"
 48 #include "runtime/java.hpp"
 49 #include "runtime/javaCalls.hpp"
 50 #include "runtime/javaThread.hpp"
 51 #include "runtime/jniHandles.inline.hpp"
 52 #include "runtime/semaphore.inline.hpp"
 53 #include "runtime/synchronizer.hpp"
 54 #include "runtime/threadSMR.hpp"
 55 #include "utilities/growableArray.hpp"
 56 
 57 #ifdef ASSERT
 58 static void check_java_thread_state(JavaThread* t, JavaThreadState state) {
 59   assert(t != nullptr, "invariant");
 60   assert(t->is_Java_thread(), "invariant");
 61   assert(t->thread_state() == state, "invariant");
 62 }
 63 
 64 void JfrJavaSupport::check_java_thread_in_vm(JavaThread* t) {
 65   check_java_thread_state(t, _thread_in_vm);

526 const char* JfrJavaSupport::c_str(jstring string, Thread* thread, bool c_heap /* false */) {
527   return string != nullptr ? c_str(resolve_non_null(string), thread, c_heap) : nullptr;
528 }
529 
530 void JfrJavaSupport::free_c_str(const char* str, bool c_heap) {
531   if (c_heap) {
532     FREE_C_HEAP_ARRAY(char, str);
533   }
534 }
535 
536 static Symbol** allocate_symbol_array(bool c_heap, int length, Thread* thread) {
537   return c_heap ?
538            NEW_C_HEAP_ARRAY(Symbol*, length, mtTracing) :
539            NEW_RESOURCE_ARRAY_IN_THREAD(thread, Symbol*, length);
540 }
541 
542 Symbol** JfrJavaSupport::symbol_array(jobjectArray string_array, JavaThread* thread, intptr_t* result_array_size, bool c_heap /* false */) {
543   DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(thread));
544   assert(string_array != nullptr, "invariant");
545   assert(result_array_size != nullptr, "invariant");
546   refArrayOop arrayOop = oop_cast<refArrayOop>(resolve_non_null(string_array));
547   const int length = arrayOop->length();
548   *result_array_size = length;
549   Symbol** result_array = allocate_symbol_array(c_heap, length, thread);
550   assert(result_array != nullptr, "invariant");
551   for (int i = 0; i < length; i++) {
552     oop object = arrayOop->obj_at(i);
553     Symbol* symbol = nullptr;
554     if (object != nullptr) {
555       const char* text = c_str(arrayOop->obj_at(i), thread, c_heap);
556       symbol = SymbolTable::new_symbol(text);
557       free_c_str(text, c_heap);
558     }
559     result_array[i] = symbol;
560   }
561   return result_array;
562 }
563 
564 /*
565  *  Exceptions and errors
566  */
< prev index next >