1 /*
   2  * Copyright (c) 1997, 2022, 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 "precompiled.hpp"
  26 #include "cds/classListParser.hpp"
  27 #include "cds/classListWriter.hpp"
  28 #include "cds/dynamicArchive.hpp"
  29 #include "cds/heapShared.hpp"
  30 #include "cds/lambdaFormInvokers.hpp"
  31 #include "classfile/classFileStream.hpp"
  32 #include "classfile/classLoader.inline.hpp"
  33 #include "classfile/classLoaderData.hpp"
  34 #include "classfile/classLoaderData.inline.hpp"
  35 #include "classfile/classLoadInfo.hpp"
  36 #include "classfile/javaAssertions.hpp"
  37 #include "classfile/javaClasses.inline.hpp"
  38 #include "classfile/moduleEntry.hpp"
  39 #include "classfile/modules.hpp"
  40 #include "classfile/packageEntry.hpp"
  41 #include "classfile/stringTable.hpp"
  42 #include "classfile/symbolTable.hpp"
  43 #include "classfile/systemDictionary.hpp"
  44 #include "classfile/vmClasses.hpp"
  45 #include "classfile/vmSymbols.hpp"
  46 #include "gc/shared/collectedHeap.inline.hpp"
  47 #include "interpreter/bytecode.hpp"
  48 #include "interpreter/bytecodeUtils.hpp"
  49 #include "jfr/jfrEvents.hpp"
  50 #include "jvm.h"
  51 #include "logging/log.hpp"
  52 #include "memory/oopFactory.hpp"
  53 #include "memory/referenceType.hpp"
  54 #include "memory/resourceArea.hpp"
  55 #include "memory/universe.hpp"
  56 #include "oops/access.inline.hpp"
  57 #include "oops/constantPool.hpp"
  58 #include "oops/fieldStreams.inline.hpp"
  59 #include "oops/instanceKlass.hpp"
  60 #include "oops/klass.inline.hpp"
  61 #include "oops/method.hpp"
  62 #include "oops/recordComponent.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "prims/jvm_misc.hpp"
  67 #include "prims/jvmtiExport.hpp"
  68 #include "prims/jvmtiThreadState.inline.hpp"
  69 #include "prims/stackwalk.hpp"
  70 #include "runtime/arguments.hpp"
  71 #include "runtime/atomic.hpp"
  72 #include "runtime/continuation.hpp"
  73 #include "runtime/globals_extension.hpp"
  74 #include "runtime/handles.inline.hpp"
  75 #include "runtime/init.hpp"
  76 #include "runtime/interfaceSupport.inline.hpp"
  77 #include "runtime/deoptimization.hpp"
  78 #include "runtime/handshake.hpp"
  79 #include "runtime/java.hpp"
  80 #include "runtime/javaCalls.hpp"
  81 #include "runtime/javaThread.hpp"
  82 #include "runtime/jfieldIDWorkaround.hpp"
  83 #include "runtime/jniHandles.inline.hpp"
  84 #include "runtime/os.inline.hpp"
  85 #include "runtime/osThread.hpp"
  86 #include "runtime/perfData.hpp"
  87 #include "runtime/reflection.hpp"
  88 #include "runtime/synchronizer.hpp"
  89 #include "runtime/threadIdentifier.hpp"
  90 #include "runtime/threadSMR.hpp"
  91 #include "runtime/vframe.inline.hpp"
  92 #include "runtime/vmOperations.hpp"
  93 #include "runtime/vm_version.hpp"
  94 #include "services/attachListener.hpp"
  95 #include "services/management.hpp"
  96 #include "services/threadService.hpp"
  97 #include "utilities/copy.hpp"
  98 #include "utilities/defaultStream.hpp"
  99 #include "utilities/dtrace.hpp"
 100 #include "utilities/events.hpp"
 101 #include "utilities/macros.hpp"
 102 #include "utilities/utf8.hpp"
 103 #if INCLUDE_CDS
 104 #include "classfile/systemDictionaryShared.hpp"
 105 #endif
 106 #if INCLUDE_JFR
 107 #include "jfr/jfr.hpp"
 108 #endif
 109 #if INCLUDE_MANAGEMENT
 110 #include "services/finalizerService.hpp"
 111 #endif
 112 
 113 #include <errno.h>
 114 
 115 /*
 116   NOTE about use of any ctor or function call that can trigger a safepoint/GC:
 117   such ctors and calls MUST NOT come between an oop declaration/init and its
 118   usage because if objects are move this may cause various memory stomps, bus
 119   errors and segfaults. Here is a cookbook for causing so called "naked oop
 120   failures":
 121 
 122       JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields<etc> {
 123           // Object address to be held directly in mirror & not visible to GC
 124           oop mirror = JNIHandles::resolve_non_null(ofClass);
 125 
 126           // If this ctor can hit a safepoint, moving objects around, then
 127           ComplexConstructor foo;
 128 
 129           // Boom! mirror may point to JUNK instead of the intended object
 130           (some dereference of mirror)
 131 
 132           // Here's another call that may block for GC, making mirror stale
 133           MutexLocker ml(some_lock);
 134 
 135           // And here's an initializer that can result in a stale oop
 136           // all in one step.
 137           oop o = call_that_can_throw_exception(TRAPS);
 138 
 139 
 140   The solution is to keep the oop declaration BELOW the ctor or function
 141   call that might cause a GC, do another resolve to reassign the oop, or
 142   consider use of a Handle instead of an oop so there is immunity from object
 143   motion. But note that the "QUICK" entries below do not have a handlemark
 144   and thus can only support use of handles passed in.
 145 */
 146 
 147 static void trace_class_resolution_impl(Klass* to_class, TRAPS) {
 148   ResourceMark rm;
 149   int line_number = -1;
 150   const char * source_file = NULL;
 151   const char * trace = "explicit";
 152   InstanceKlass* caller = NULL;
 153   JavaThread* jthread = THREAD;
 154   if (jthread->has_last_Java_frame()) {
 155     vframeStream vfst(jthread);
 156 
 157     // scan up the stack skipping ClassLoader, AccessController and PrivilegedAction frames
 158     TempNewSymbol access_controller = SymbolTable::new_symbol("java/security/AccessController");
 159     Klass* access_controller_klass = SystemDictionary::resolve_or_fail(access_controller, false, CHECK);
 160     TempNewSymbol privileged_action = SymbolTable::new_symbol("java/security/PrivilegedAction");
 161     Klass* privileged_action_klass = SystemDictionary::resolve_or_fail(privileged_action, false, CHECK);
 162 
 163     Method* last_caller = NULL;
 164 
 165     while (!vfst.at_end()) {
 166       Method* m = vfst.method();
 167       if (!vfst.method()->method_holder()->is_subclass_of(vmClasses::ClassLoader_klass())&&
 168           !vfst.method()->method_holder()->is_subclass_of(access_controller_klass) &&
 169           !vfst.method()->method_holder()->is_subclass_of(privileged_action_klass)) {
 170         break;
 171       }
 172       last_caller = m;
 173       vfst.next();
 174     }
 175     // if this is called from Class.forName0 and that is called from Class.forName,
 176     // then print the caller of Class.forName.  If this is Class.loadClass, then print
 177     // that caller, otherwise keep quiet since this should be picked up elsewhere.
 178     bool found_it = false;
 179     if (!vfst.at_end() &&
 180         vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() &&
 181         vfst.method()->name() == vmSymbols::forName0_name()) {
 182       vfst.next();
 183       if (!vfst.at_end() &&
 184           vfst.method()->method_holder()->name() == vmSymbols::java_lang_Class() &&
 185           vfst.method()->name() == vmSymbols::forName_name()) {
 186         vfst.next();
 187         found_it = true;
 188       }
 189     } else if (last_caller != NULL &&
 190                last_caller->method_holder()->name() ==
 191                  vmSymbols::java_lang_ClassLoader() &&
 192                last_caller->name() == vmSymbols::loadClass_name()) {
 193       found_it = true;
 194     } else if (!vfst.at_end()) {
 195       if (vfst.method()->is_native()) {
 196         // JNI call
 197         found_it = true;
 198       }
 199     }
 200     if (found_it && !vfst.at_end()) {
 201       // found the caller
 202       caller = vfst.method()->method_holder();
 203       line_number = vfst.method()->line_number_from_bci(vfst.bci());
 204       if (line_number == -1) {
 205         // show method name if it's a native method
 206         trace = vfst.method()->name_and_sig_as_C_string();
 207       }
 208       Symbol* s = caller->source_file_name();
 209       if (s != NULL) {
 210         source_file = s->as_C_string();
 211       }
 212     }
 213   }
 214   if (caller != NULL) {
 215     if (to_class != caller) {
 216       const char * from = caller->external_name();
 217       const char * to = to_class->external_name();
 218       // print in a single call to reduce interleaving between threads
 219       if (source_file != NULL) {
 220         log_debug(class, resolve)("%s %s %s:%d (%s)", from, to, source_file, line_number, trace);
 221       } else {
 222         log_debug(class, resolve)("%s %s (%s)", from, to, trace);
 223       }
 224     }
 225   }
 226 }
 227 
 228 void trace_class_resolution(Klass* to_class) {
 229   EXCEPTION_MARK;
 230   trace_class_resolution_impl(to_class, THREAD);
 231   if (HAS_PENDING_EXCEPTION) {
 232     CLEAR_PENDING_EXCEPTION;
 233   }
 234 }
 235 
 236 // java.lang.System //////////////////////////////////////////////////////////////////////
 237 
 238 
 239 JVM_LEAF(jlong, JVM_CurrentTimeMillis(JNIEnv *env, jclass ignored))
 240   return os::javaTimeMillis();
 241 JVM_END
 242 
 243 JVM_LEAF(jlong, JVM_NanoTime(JNIEnv *env, jclass ignored))
 244   return os::javaTimeNanos();
 245 JVM_END
 246 
 247 // The function below is actually exposed by jdk.internal.misc.VM and not
 248 // java.lang.System, but we choose to keep it here so that it stays next
 249 // to JVM_CurrentTimeMillis and JVM_NanoTime
 250 
 251 const jlong MAX_DIFF_SECS = CONST64(0x0100000000); //  2^32
 252 const jlong MIN_DIFF_SECS = -MAX_DIFF_SECS; // -2^32
 253 
 254 JVM_LEAF(jlong, JVM_GetNanoTimeAdjustment(JNIEnv *env, jclass ignored, jlong offset_secs))
 255   jlong seconds;
 256   jlong nanos;
 257 
 258   os::javaTimeSystemUTC(seconds, nanos);
 259 
 260   // We're going to verify that the result can fit in a long.
 261   // For that we need the difference in seconds between 'seconds'
 262   // and 'offset_secs' to be such that:
 263   //     |seconds - offset_secs| < (2^63/10^9)
 264   // We're going to approximate 10^9 ~< 2^30 (1000^3 ~< 1024^3)
 265   // which makes |seconds - offset_secs| < 2^33
 266   // and we will prefer +/- 2^32 as the maximum acceptable diff
 267   // as 2^32 has a more natural feel than 2^33...
 268   //
 269   // So if |seconds - offset_secs| >= 2^32 - we return a special
 270   // sentinel value (-1) which the caller should take as an
 271   // exception value indicating that the offset given to us is
 272   // too far from range of the current time - leading to too big
 273   // a nano adjustment. The caller is expected to recover by
 274   // computing a more accurate offset and calling this method
 275   // again. (For the record 2^32 secs is ~136 years, so that
 276   // should rarely happen)
 277   //
 278   jlong diff = seconds - offset_secs;
 279   if (diff >= MAX_DIFF_SECS || diff <= MIN_DIFF_SECS) {
 280      return -1; // sentinel value: the offset is too far off the target
 281   }
 282 
 283   // return the adjustment. If you compute a time by adding
 284   // this number of nanoseconds along with the number of seconds
 285   // in the offset you should get the current UTC time.
 286   return (diff * (jlong)1000000000) + nanos;
 287 JVM_END
 288 
 289 JVM_ENTRY(void, JVM_ArrayCopy(JNIEnv *env, jclass ignored, jobject src, jint src_pos,
 290                                jobject dst, jint dst_pos, jint length))
 291   // Check if we have null pointers
 292   if (src == NULL || dst == NULL) {
 293     THROW(vmSymbols::java_lang_NullPointerException());
 294   }
 295   arrayOop s = arrayOop(JNIHandles::resolve_non_null(src));
 296   arrayOop d = arrayOop(JNIHandles::resolve_non_null(dst));
 297   assert(oopDesc::is_oop(s), "JVM_ArrayCopy: src not an oop");
 298   assert(oopDesc::is_oop(d), "JVM_ArrayCopy: dst not an oop");
 299   // Do copy
 300   s->klass()->copy_array(s, src_pos, d, dst_pos, length, thread);
 301 JVM_END
 302 
 303 
 304 static void set_property(Handle props, const char* key, const char* value, TRAPS) {
 305   JavaValue r(T_OBJECT);
 306   // public synchronized Object put(Object key, Object value);
 307   HandleMark hm(THREAD);
 308   Handle key_str    = java_lang_String::create_from_platform_dependent_str(key, CHECK);
 309   Handle value_str  = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK);
 310   JavaCalls::call_virtual(&r,
 311                           props,
 312                           vmClasses::Properties_klass(),
 313                           vmSymbols::put_name(),
 314                           vmSymbols::object_object_object_signature(),
 315                           key_str,
 316                           value_str,
 317                           THREAD);
 318 }
 319 
 320 
 321 #define PUTPROP(props, name, value) set_property((props), (name), (value), CHECK_(properties));
 322 
 323 /*
 324  * Return all of the system properties in a Java String array with alternating
 325  * names and values from the jvm SystemProperty.
 326  * Which includes some internal and all commandline -D defined properties.
 327  */
 328 JVM_ENTRY(jobjectArray, JVM_GetProperties(JNIEnv *env))
 329   ResourceMark rm(THREAD);
 330   HandleMark hm(THREAD);
 331   int ndx = 0;
 332   int fixedCount = 2;
 333 
 334   SystemProperty* p = Arguments::system_properties();
 335   int count = Arguments::PropertyList_count(p);
 336 
 337   // Allocate result String array
 338   InstanceKlass* ik = vmClasses::String_klass();
 339   objArrayOop r = oopFactory::new_objArray(ik, (count + fixedCount) * 2, CHECK_NULL);
 340   objArrayHandle result_h(THREAD, r);
 341 
 342   while (p != NULL) {
 343     const char * key = p->key();
 344     if (strcmp(key, "sun.nio.MaxDirectMemorySize") != 0) {
 345         const char * value = p->value();
 346         Handle key_str    = java_lang_String::create_from_platform_dependent_str(key, CHECK_NULL);
 347         Handle value_str  = java_lang_String::create_from_platform_dependent_str((value != NULL ? value : ""), CHECK_NULL);
 348         result_h->obj_at_put(ndx * 2,  key_str());
 349         result_h->obj_at_put(ndx * 2 + 1, value_str());
 350         ndx++;
 351     }
 352     p = p->next();
 353   }
 354 
 355   // Convert the -XX:MaxDirectMemorySize= command line flag
 356   // to the sun.nio.MaxDirectMemorySize property.
 357   // Do this after setting user properties to prevent people
 358   // from setting the value with a -D option, as requested.
 359   // Leave empty if not supplied
 360   if (!FLAG_IS_DEFAULT(MaxDirectMemorySize)) {
 361     char as_chars[256];
 362     jio_snprintf(as_chars, sizeof(as_chars), JULONG_FORMAT, MaxDirectMemorySize);
 363     Handle key_str = java_lang_String::create_from_platform_dependent_str("sun.nio.MaxDirectMemorySize", CHECK_NULL);
 364     Handle value_str  = java_lang_String::create_from_platform_dependent_str(as_chars, CHECK_NULL);
 365     result_h->obj_at_put(ndx * 2,  key_str());
 366     result_h->obj_at_put(ndx * 2 + 1, value_str());
 367     ndx++;
 368   }
 369 
 370   // JVM monitoring and management support
 371   // Add the sun.management.compiler property for the compiler's name
 372   {
 373 #undef CSIZE
 374 #if defined(_LP64) || defined(_WIN64)
 375   #define CSIZE "64-Bit "
 376 #else
 377   #define CSIZE
 378 #endif // 64bit
 379 
 380 #if COMPILER1_AND_COMPILER2
 381     const char* compiler_name = "HotSpot " CSIZE "Tiered Compilers";
 382 #else
 383 #if defined(COMPILER1)
 384     const char* compiler_name = "HotSpot " CSIZE "Client Compiler";
 385 #elif defined(COMPILER2)
 386     const char* compiler_name = "HotSpot " CSIZE "Server Compiler";
 387 #elif INCLUDE_JVMCI
 388     #error "INCLUDE_JVMCI should imply COMPILER1_OR_COMPILER2"
 389 #else
 390     const char* compiler_name = "";
 391 #endif // compilers
 392 #endif // COMPILER1_AND_COMPILER2
 393 
 394     if (*compiler_name != '\0' &&
 395         (Arguments::mode() != Arguments::_int)) {
 396       Handle key_str = java_lang_String::create_from_platform_dependent_str("sun.management.compiler", CHECK_NULL);
 397       Handle value_str  = java_lang_String::create_from_platform_dependent_str(compiler_name, CHECK_NULL);
 398       result_h->obj_at_put(ndx * 2,  key_str());
 399       result_h->obj_at_put(ndx * 2 + 1, value_str());
 400       ndx++;
 401     }
 402   }
 403 
 404   return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
 405 JVM_END
 406 
 407 
 408 /*
 409  * Return the temporary directory that the VM uses for the attach
 410  * and perf data files.
 411  *
 412  * It is important that this directory is well-known and the
 413  * same for all VM instances. It cannot be affected by configuration
 414  * variables such as java.io.tmpdir.
 415  */
 416 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
 417   HandleMark hm(THREAD);
 418   const char* temp_dir = os::get_temp_directory();
 419   Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
 420   return (jstring) JNIHandles::make_local(THREAD, h());
 421 JVM_END
 422 
 423 
 424 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
 425 
 426 extern volatile jint vm_created;
 427 
 428 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
 429 #if INCLUDE_CDS
 430   // Link all classes for dynamic CDS dumping before vm exit.
 431   if (DynamicArchive::should_dump_at_vm_exit()) {
 432     DynamicArchive::prepare_for_dump_at_exit();
 433   }
 434 #endif
 435   EventShutdown event;
 436   if (event.should_commit()) {
 437     event.set_reason("Shutdown requested from Java");
 438     event.commit();
 439   }
 440 JVM_END
 441 
 442 
 443 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
 444   before_exit(thread, true);
 445   vm_exit(code);
 446 JVM_END
 447 
 448 
 449 JVM_ENTRY_NO_ENV(void, JVM_GC(void))
 450   if (!DisableExplicitGC) {
 451     EventSystemGC event;
 452     event.set_invokedConcurrent(ExplicitGCInvokesConcurrent);
 453     Universe::heap()->collect(GCCause::_java_lang_system_gc);
 454     event.commit();
 455   }
 456 JVM_END
 457 
 458 
 459 JVM_LEAF(jlong, JVM_MaxObjectInspectionAge(void))
 460   return Universe::heap()->millis_since_last_whole_heap_examined();
 461 JVM_END
 462 
 463 
 464 static inline jlong convert_size_t_to_jlong(size_t val) {
 465   // In the 64-bit vm, a size_t can overflow a jlong (which is signed).
 466   NOT_LP64 (return (jlong)val;)
 467   LP64_ONLY(return (jlong)MIN2(val, (size_t)max_jlong);)
 468 }
 469 
 470 JVM_ENTRY_NO_ENV(jlong, JVM_TotalMemory(void))
 471   size_t n = Universe::heap()->capacity();
 472   return convert_size_t_to_jlong(n);
 473 JVM_END
 474 
 475 
 476 JVM_ENTRY_NO_ENV(jlong, JVM_FreeMemory(void))
 477   size_t n = Universe::heap()->unused();
 478   return convert_size_t_to_jlong(n);
 479 JVM_END
 480 
 481 
 482 JVM_ENTRY_NO_ENV(jlong, JVM_MaxMemory(void))
 483   size_t n = Universe::heap()->max_capacity();
 484   return convert_size_t_to_jlong(n);
 485 JVM_END
 486 
 487 
 488 JVM_ENTRY_NO_ENV(jint, JVM_ActiveProcessorCount(void))
 489   return os::active_processor_count();
 490 JVM_END
 491 
 492 JVM_LEAF(jboolean, JVM_IsUseContainerSupport(void))
 493 #ifdef LINUX
 494   if (UseContainerSupport) {
 495     return JNI_TRUE;
 496   }
 497 #endif
 498   return JNI_FALSE;
 499 JVM_END
 500 
 501 // java.lang.Throwable //////////////////////////////////////////////////////
 502 
 503 JVM_ENTRY(void, JVM_FillInStackTrace(JNIEnv *env, jobject receiver))
 504   Handle exception(thread, JNIHandles::resolve_non_null(receiver));
 505   java_lang_Throwable::fill_in_stack_trace(exception);
 506 JVM_END
 507 
 508 // java.lang.NullPointerException ///////////////////////////////////////////
 509 
 510 JVM_ENTRY(jstring, JVM_GetExtendedNPEMessage(JNIEnv *env, jthrowable throwable))
 511   if (!ShowCodeDetailsInExceptionMessages) return NULL;
 512 
 513   oop exc = JNIHandles::resolve_non_null(throwable);
 514 
 515   Method* method;
 516   int bci;
 517   if (!java_lang_Throwable::get_top_method_and_bci(exc, &method, &bci)) {
 518     return NULL;
 519   }
 520   if (method->is_native()) {
 521     return NULL;
 522   }
 523 
 524   stringStream ss;
 525   bool ok = BytecodeUtils::get_NPE_message_at(&ss, method, bci);
 526   if (ok) {
 527     oop result = java_lang_String::create_oop_from_str(ss.base(), CHECK_NULL);
 528     return (jstring) JNIHandles::make_local(THREAD, result);
 529   } else {
 530     return NULL;
 531   }
 532 JVM_END
 533 
 534 // java.lang.StackTraceElement //////////////////////////////////////////////
 535 
 536 
 537 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject backtrace, jint depth))
 538   Handle backtraceh(THREAD, JNIHandles::resolve(backtrace));
 539   objArrayOop st = objArrayOop(JNIHandles::resolve(elements));
 540   objArrayHandle stack_trace(THREAD, st);
 541   // Fill in the allocated stack trace
 542   java_lang_Throwable::get_stack_trace_elements(depth, backtraceh, stack_trace, CHECK);
 543 JVM_END
 544 
 545 
 546 JVM_ENTRY(void, JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo))
 547   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(stackFrameInfo));
 548   Handle stack_trace_element(THREAD, JNIHandles::resolve_non_null(element));
 549   java_lang_StackFrameInfo::to_stack_trace_element(stack_frame_info, stack_trace_element, THREAD);
 550 JVM_END
 551 
 552 
 553 // java.lang.StackWalker //////////////////////////////////////////////////////
 554 
 555 
 556 JVM_ENTRY(jobject, JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jlong mode,
 557                                      jint skip_frames, jobject contScope, jobject cont,
 558                                      jint frame_count, jint start_index, jobjectArray frames))
 559   if (!thread->has_last_Java_frame()) {
 560     THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: no stack trace", NULL);
 561   }
 562 
 563   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 564   Handle contScope_h(THREAD, JNIHandles::resolve(contScope));
 565   Handle cont_h(THREAD, JNIHandles::resolve(cont));
 566   // frames array is a Class<?>[] array when only getting caller reference,
 567   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 568   // be null.
 569   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 570   objArrayHandle frames_array_h(THREAD, fa);
 571 
 572   int limit = start_index + frame_count;
 573   if (frames_array_h->length() < limit) {
 574     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", NULL);
 575   }
 576 
 577   oop result = StackWalk::walk(stackStream_h, mode, skip_frames, contScope_h, cont_h,
 578                                frame_count, start_index, frames_array_h, CHECK_NULL);
 579   return JNIHandles::make_local(THREAD, result);
 580 JVM_END
 581 
 582 
 583 JVM_ENTRY(jint, JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jlong mode, jlong anchor,
 584                                   jint frame_count, jint start_index,
 585                                   jobjectArray frames))
 586   // frames array is a Class<?>[] array when only getting caller reference,
 587   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 588   // be null.
 589   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 590   objArrayHandle frames_array_h(THREAD, fa);
 591 
 592   int limit = start_index+frame_count;
 593   if (frames_array_h->length() < limit) {
 594     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers");
 595   }
 596 
 597   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 598   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count,
 599                                   start_index, frames_array_h, THREAD);
 600 JVM_END
 601 
 602 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 603   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 604   objArrayHandle frames_array_h(THREAD, fa);
 605   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 606   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 607 
 608   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 609 JVM_END
 610 
 611 // java.lang.Object ///////////////////////////////////////////////
 612 
 613 
 614 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 615   // as implemented in the classic virtual machine; return 0 if object is NULL
 616   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;
 617 JVM_END
 618 
 619 
 620 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 621   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 622   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 623   if (JvmtiExport::should_post_monitor_wait()) {
 624     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 625 
 626     // The current thread already owns the monitor and it has not yet
 627     // been added to the wait queue so the current thread cannot be
 628     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 629     // event handler cannot accidentally consume an unpark() meant for
 630     // the ParkEvent associated with this ObjectMonitor.
 631   }
 632   ObjectSynchronizer::wait(obj, ms, CHECK);
 633 JVM_END
 634 
 635 
 636 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 637   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 638   ObjectSynchronizer::notify(obj, CHECK);
 639 JVM_END
 640 
 641 
 642 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 643   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 644   ObjectSynchronizer::notifyall(obj, CHECK);
 645 JVM_END
 646 
 647 
 648 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 649   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 650   Klass* klass = obj->klass();
 651   JvmtiVMObjectAllocEventCollector oam;
 652 
 653 #ifdef ASSERT
 654   // Just checking that the cloneable flag is set correct
 655   if (obj->is_array()) {
 656     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 657   } else {
 658     guarantee(obj->is_instance(), "should be instanceOop");
 659     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 660     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 661   }
 662 #endif
 663 
 664   // Check if class of obj supports the Cloneable interface.
 665   // All arrays are considered to be cloneable (See JLS 20.1.5).
 666   // All j.l.r.Reference classes are considered non-cloneable.
 667   if (!klass->is_cloneable() ||
 668       (klass->is_instance_klass() &&
 669        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 670     ResourceMark rm(THREAD);
 671     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 672   }
 673 
 674   // Make shallow object copy
 675   const size_t size = obj->size();
 676   oop new_obj_oop = NULL;
 677   if (obj->is_array()) {
 678     const int length = ((arrayOop)obj())->length();
 679     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 680                                                    /* do_zero */ true, CHECK_NULL);
 681   } else {
 682     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 683   }
 684 
 685   HeapAccess<>::clone(obj(), new_obj_oop, size);
 686 
 687   Handle new_obj(THREAD, new_obj_oop);
 688   // Caution: this involves a java upcall, so the clone should be
 689   // "gc-robust" by this stage.
 690   if (klass->has_finalizer()) {
 691     assert(obj->is_instance(), "should be instanceOop");
 692     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 693     new_obj = Handle(THREAD, new_obj_oop);
 694   }
 695 
 696   return JNIHandles::make_local(THREAD, new_obj());
 697 JVM_END
 698 
 699 // java.lang.ref.Finalizer ////////////////////////////////////////////////////
 700 
 701 JVM_ENTRY(void, JVM_ReportFinalizationComplete(JNIEnv * env, jobject finalizee))
 702   MANAGEMENT_ONLY(FinalizerService::on_complete(JNIHandles::resolve_non_null(finalizee), THREAD);)
 703 JVM_END
 704 
 705 JVM_LEAF(jboolean, JVM_IsFinalizationEnabled(JNIEnv * env))
 706   return InstanceKlass::is_finalization_enabled();
 707 JVM_END
 708 
 709 // jdk.internal.vm.Continuation /////////////////////////////////////////////////////
 710 
 711 JVM_ENTRY(void, JVM_RegisterContinuationMethods(JNIEnv *env, jclass cls))
 712   CONT_RegisterNativeMethods(env, cls);
 713 JVM_END
 714 
 715 // java.io.File ///////////////////////////////////////////////////////////////
 716 
 717 JVM_LEAF(char*, JVM_NativePath(char* path))
 718   return os::native_path(path);
 719 JVM_END
 720 
 721 
 722 // Misc. class handling ///////////////////////////////////////////////////////////
 723 
 724 
 725 JVM_ENTRY(jclass, JVM_GetCallerClass(JNIEnv* env))
 726   // Getting the class of the caller frame.
 727   //
 728   // The call stack at this point looks something like this:
 729   //
 730   // [0] [ @CallerSensitive public sun.reflect.Reflection.getCallerClass ]
 731   // [1] [ @CallerSensitive API.method                                   ]
 732   // [.] [ (skipped intermediate frames)                                 ]
 733   // [n] [ caller                                                        ]
 734   vframeStream vfst(thread);
 735   // Cf. LibraryCallKit::inline_native_Reflection_getCallerClass
 736   for (int n = 0; !vfst.at_end(); vfst.security_next(), n++) {
 737     Method* m = vfst.method();
 738     assert(m != NULL, "sanity");
 739     switch (n) {
 740     case 0:
 741       // This must only be called from Reflection.getCallerClass
 742       if (m->intrinsic_id() != vmIntrinsics::_getCallerClass) {
 743         THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetCallerClass must only be called from Reflection.getCallerClass");
 744       }
 745       // fall-through
 746     case 1:
 747       // Frame 0 and 1 must be caller sensitive.
 748       if (!m->caller_sensitive()) {
 749         THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), err_msg("CallerSensitive annotation expected at frame %d", n));
 750       }
 751       break;
 752     default:
 753       if (!m->is_ignored_by_security_stack_walk()) {
 754         // We have reached the desired frame; return the holder class.
 755         return (jclass) JNIHandles::make_local(THREAD, m->method_holder()->java_mirror());
 756       }
 757       break;
 758     }
 759   }
 760   return NULL;
 761 JVM_END
 762 
 763 
 764 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
 765   oop mirror = NULL;
 766   BasicType t = name2type(utf);
 767   if (t != T_ILLEGAL && !is_reference_type(t)) {
 768     mirror = Universe::java_mirror(t);
 769   }
 770   if (mirror == NULL) {
 771     THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
 772   } else {
 773     return (jclass) JNIHandles::make_local(THREAD, mirror);
 774   }
 775 JVM_END
 776 
 777 
 778 // Returns a class loaded by the bootstrap class loader; or null
 779 // if not found.  ClassNotFoundException is not thrown.
 780 // FindClassFromBootLoader is exported to the launcher for windows.
 781 JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env,
 782                                               const char* name))
 783   // Java libraries should ensure that name is never null or illegal.
 784   if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
 785     // It's impossible to create this class;  the name cannot fit
 786     // into the constant pool.
 787     return NULL;
 788   }
 789   assert(UTF8::is_legal_utf8((const unsigned char*)name, (int)strlen(name), false), "illegal UTF name");
 790 
 791   TempNewSymbol h_name = SymbolTable::new_symbol(name);
 792   Klass* k = SystemDictionary::resolve_or_null(h_name, CHECK_NULL);
 793   if (k == NULL) {
 794     return NULL;
 795   }
 796 
 797   if (log_is_enabled(Debug, class, resolve)) {
 798     trace_class_resolution(k);
 799   }
 800   return (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
 801 JVM_END
 802 
 803 // Find a class with this name in this loader, using the caller's protection domain.
 804 JVM_ENTRY(jclass, JVM_FindClassFromCaller(JNIEnv* env, const char* name,
 805                                           jboolean init, jobject loader,
 806                                           jclass caller))
 807   TempNewSymbol h_name =
 808        SystemDictionary::class_name_symbol(name, vmSymbols::java_lang_ClassNotFoundException(),
 809                                            CHECK_NULL);
 810 
 811   oop loader_oop = JNIHandles::resolve(loader);
 812   oop from_class = JNIHandles::resolve(caller);
 813   oop protection_domain = NULL;
 814   // If loader is null, shouldn't call ClassLoader.checkPackageAccess; otherwise get
 815   // NPE. Put it in another way, the bootstrap class loader has all permission and
 816   // thus no checkPackageAccess equivalence in the VM class loader.
 817   // The caller is also passed as NULL by the java code if there is no security
 818   // manager to avoid the performance cost of getting the calling class.
 819   if (from_class != NULL && loader_oop != NULL) {
 820     protection_domain = java_lang_Class::as_Klass(from_class)->protection_domain();
 821   }
 822 
 823   Handle h_loader(THREAD, loader_oop);
 824   Handle h_prot(THREAD, protection_domain);
 825   jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
 826                                                h_prot, false, THREAD);
 827 
 828   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
 829     trace_class_resolution(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(result)));
 830   }
 831   return result;
 832 JVM_END
 833 
 834 // Currently only called from the old verifier.
 835 JVM_ENTRY(jclass, JVM_FindClassFromClass(JNIEnv *env, const char *name,
 836                                          jboolean init, jclass from))
 837   TempNewSymbol h_name =
 838        SystemDictionary::class_name_symbol(name, vmSymbols::java_lang_ClassNotFoundException(),
 839                                            CHECK_NULL);
 840   oop from_class_oop = JNIHandles::resolve(from);
 841   Klass* from_class = (from_class_oop == NULL)
 842                            ? (Klass*)NULL
 843                            : java_lang_Class::as_Klass(from_class_oop);
 844   oop class_loader = NULL;
 845   oop protection_domain = NULL;
 846   if (from_class != NULL) {
 847     class_loader = from_class->class_loader();
 848     protection_domain = from_class->protection_domain();
 849   }
 850   Handle h_loader(THREAD, class_loader);
 851   Handle h_prot  (THREAD, protection_domain);
 852   jclass result = find_class_from_class_loader(env, h_name, init, h_loader,
 853                                                h_prot, true, thread);
 854 
 855   if (log_is_enabled(Debug, class, resolve) && result != NULL) {
 856     // this function is generally only used for class loading during verification.
 857     ResourceMark rm;
 858     oop from_mirror = JNIHandles::resolve_non_null(from);
 859     Klass* from_class = java_lang_Class::as_Klass(from_mirror);
 860     const char * from_name = from_class->external_name();
 861 
 862     oop mirror = JNIHandles::resolve_non_null(result);
 863     Klass* to_class = java_lang_Class::as_Klass(mirror);
 864     const char * to = to_class->external_name();
 865     log_debug(class, resolve)("%s %s (verification)", from_name, to);
 866   }
 867 
 868   return result;
 869 JVM_END
 870 
 871 // common code for JVM_DefineClass() and JVM_DefineClassWithSource()
 872 static jclass jvm_define_class_common(const char *name,
 873                                       jobject loader, const jbyte *buf,
 874                                       jsize len, jobject pd, const char *source,
 875                                       TRAPS) {
 876   if (source == NULL)  source = "__JVM_DefineClass__";
 877 
 878   JavaThread* jt = THREAD;
 879 
 880   PerfClassTraceTime vmtimer(ClassLoader::perf_define_appclass_time(),
 881                              ClassLoader::perf_define_appclass_selftime(),
 882                              ClassLoader::perf_define_appclasses(),
 883                              jt->get_thread_stat()->perf_recursion_counts_addr(),
 884                              jt->get_thread_stat()->perf_timers_addr(),
 885                              PerfClassTraceTime::DEFINE_CLASS);
 886 
 887   if (UsePerfData) {
 888     ClassLoader::perf_app_classfile_bytes_read()->inc(len);
 889   }
 890 
 891   // Class resolution will get the class name from the .class stream if the name is null.
 892   TempNewSymbol class_name = name == NULL ? NULL :
 893        SystemDictionary::class_name_symbol(name, vmSymbols::java_lang_NoClassDefFoundError(),
 894                                            CHECK_NULL);
 895 
 896   ResourceMark rm(THREAD);
 897   ClassFileStream st((u1*)buf, len, source, ClassFileStream::verify);
 898   Handle class_loader (THREAD, JNIHandles::resolve(loader));
 899   Handle protection_domain (THREAD, JNIHandles::resolve(pd));
 900   ClassLoadInfo cl_info(protection_domain);
 901   Klass* k = SystemDictionary::resolve_from_stream(&st, class_name,
 902                                                    class_loader,
 903                                                    cl_info,
 904                                                    CHECK_NULL);
 905 
 906   if (log_is_enabled(Debug, class, resolve)) {
 907     trace_class_resolution(k);
 908   }
 909 
 910   return (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
 911 }
 912 
 913 enum {
 914   NESTMATE              = java_lang_invoke_MemberName::MN_NESTMATE_CLASS,
 915   HIDDEN_CLASS          = java_lang_invoke_MemberName::MN_HIDDEN_CLASS,
 916   STRONG_LOADER_LINK    = java_lang_invoke_MemberName::MN_STRONG_LOADER_LINK,
 917   ACCESS_VM_ANNOTATIONS = java_lang_invoke_MemberName::MN_ACCESS_VM_ANNOTATIONS
 918 };
 919 
 920 /*
 921  * Define a class with the specified flags that indicates if it's a nestmate,
 922  * hidden, or strongly referenced from class loader.
 923  */
 924 static jclass jvm_lookup_define_class(jclass lookup, const char *name,
 925                                       const jbyte *buf, jsize len, jobject pd,
 926                                       jboolean init, int flags, jobject classData, TRAPS) {
 927   ResourceMark rm(THREAD);
 928 
 929   Klass* lookup_k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(lookup));
 930   // Lookup class must be a non-null instance
 931   if (lookup_k == NULL) {
 932     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Lookup class is null");
 933   }
 934   assert(lookup_k->is_instance_klass(), "Lookup class must be an instance klass");
 935 
 936   Handle class_loader (THREAD, lookup_k->class_loader());
 937 
 938   bool is_nestmate = (flags & NESTMATE) == NESTMATE;
 939   bool is_hidden = (flags & HIDDEN_CLASS) == HIDDEN_CLASS;
 940   bool is_strong = (flags & STRONG_LOADER_LINK) == STRONG_LOADER_LINK;
 941   bool vm_annotations = (flags & ACCESS_VM_ANNOTATIONS) == ACCESS_VM_ANNOTATIONS;
 942 
 943   InstanceKlass* host_class = NULL;
 944   if (is_nestmate) {
 945     host_class = InstanceKlass::cast(lookup_k)->nest_host(CHECK_NULL);
 946   }
 947 
 948   log_info(class, nestmates)("LookupDefineClass: %s - %s%s, %s, %s, %s",
 949                              name,
 950                              is_nestmate ? "with dynamic nest-host " : "non-nestmate",
 951                              is_nestmate ? host_class->external_name() : "",
 952                              is_hidden ? "hidden" : "not hidden",
 953                              is_strong ? "strong" : "weak",
 954                              vm_annotations ? "with vm annotations" : "without vm annotation");
 955 
 956   if (!is_hidden) {
 957     // classData is only applicable for hidden classes
 958     if (classData != NULL) {
 959       THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "classData is only applicable for hidden classes");
 960     }
 961     if (is_nestmate) {
 962       THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "dynamic nestmate is only applicable for hidden classes");
 963     }
 964     if (!is_strong) {
 965       THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "an ordinary class must be strongly referenced by its defining loader");
 966     }
 967     if (vm_annotations) {
 968       THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "vm annotations only allowed for hidden classes");
 969     }
 970     if (flags != STRONG_LOADER_LINK) {
 971       THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
 972                   err_msg("invalid flag 0x%x", flags));
 973     }
 974   }
 975 
 976   // Class resolution will get the class name from the .class stream if the name is null.
 977   TempNewSymbol class_name = name == NULL ? NULL :
 978        SystemDictionary::class_name_symbol(name, vmSymbols::java_lang_NoClassDefFoundError(),
 979                                            CHECK_NULL);
 980 
 981   Handle protection_domain (THREAD, JNIHandles::resolve(pd));
 982   const char* source = is_nestmate ? host_class->external_name() : "__JVM_LookupDefineClass__";
 983   ClassFileStream st((u1*)buf, len, source, ClassFileStream::verify);
 984 
 985   InstanceKlass* ik = NULL;
 986   if (!is_hidden) {
 987     ClassLoadInfo cl_info(protection_domain);
 988     ik = SystemDictionary::resolve_from_stream(&st, class_name,
 989                                                class_loader,
 990                                                cl_info,
 991                                                CHECK_NULL);
 992 
 993     if (log_is_enabled(Debug, class, resolve)) {
 994       trace_class_resolution(ik);
 995     }
 996   } else { // hidden
 997     Handle classData_h(THREAD, JNIHandles::resolve(classData));
 998     ClassLoadInfo cl_info(protection_domain,
 999                           host_class,
1000                           classData_h,
1001                           is_hidden,
1002                           is_strong,
1003                           vm_annotations);
1004     ik = SystemDictionary::resolve_from_stream(&st, class_name,
1005                                                class_loader,
1006                                                cl_info,
1007                                                CHECK_NULL);
1008 
1009     // The hidden class loader data has been artificially been kept alive to
1010     // this point. The mirror and any instances of this class have to keep
1011     // it alive afterwards.
1012     ik->class_loader_data()->dec_keep_alive();
1013 
1014     if (is_nestmate && log_is_enabled(Debug, class, nestmates)) {
1015       ModuleEntry* module = ik->module();
1016       const char * module_name = module->is_named() ? module->name()->as_C_string() : UNNAMED_MODULE;
1017       log_debug(class, nestmates)("Dynamic nestmate: %s/%s, nest_host %s, %s",
1018                                   module_name,
1019                                   ik->external_name(),
1020                                   host_class->external_name(),
1021                                   ik->is_hidden() ? "is hidden" : "is not hidden");
1022     }
1023   }
1024   assert(Reflection::is_same_class_package(lookup_k, ik),
1025          "lookup class and defined class are in different packages");
1026 
1027   if (init) {
1028     ik->initialize(CHECK_NULL);
1029   } else {
1030     ik->link_class(CHECK_NULL);
1031   }
1032 
1033   return (jclass) JNIHandles::make_local(THREAD, ik->java_mirror());
1034 }
1035 
1036 JVM_ENTRY(jclass, JVM_DefineClass(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd))
1037   return jvm_define_class_common(name, loader, buf, len, pd, NULL, THREAD);
1038 JVM_END
1039 
1040 /*
1041  * Define a class with the specified lookup class.
1042  *  lookup:  Lookup class
1043  *  name:    the name of the class
1044  *  buf:     class bytes
1045  *  len:     length of class bytes
1046  *  pd:      protection domain
1047  *  init:    initialize the class
1048  *  flags:   properties of the class
1049  *  classData: private static pre-initialized field
1050  */
1051 JVM_ENTRY(jclass, JVM_LookupDefineClass(JNIEnv *env, jclass lookup, const char *name, const jbyte *buf,
1052           jsize len, jobject pd, jboolean initialize, int flags, jobject classData))
1053 
1054   if (lookup == NULL) {
1055     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Lookup class is null");
1056   }
1057 
1058   assert(buf != NULL, "buf must not be NULL");
1059 
1060   return jvm_lookup_define_class(lookup, name, buf, len, pd, initialize, flags, classData, THREAD);
1061 JVM_END
1062 
1063 JVM_ENTRY(jclass, JVM_DefineClassWithSource(JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len, jobject pd, const char *source))
1064 
1065   return jvm_define_class_common(name, loader, buf, len, pd, source, THREAD);
1066 JVM_END
1067 
1068 JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name))
1069   ResourceMark rm(THREAD);
1070 
1071   Handle h_name (THREAD, JNIHandles::resolve_non_null(name));
1072   char* str = java_lang_String::as_utf8_string(h_name());
1073 
1074   // Sanity check, don't expect null
1075   if (str == NULL) return NULL;
1076 
1077   // Internalize the string, converting '.' to '/' in string.
1078   char* p = (char*)str;
1079   while (*p != '\0') {
1080     if (*p == '.') {
1081       *p = '/';
1082     }
1083     p++;
1084   }
1085 
1086   const int str_len = (int)(p - str);
1087   if (str_len > Symbol::max_length()) {
1088     // It's impossible to create this class;  the name cannot fit
1089     // into the constant pool.
1090     return NULL;
1091   }
1092   TempNewSymbol klass_name = SymbolTable::new_symbol(str, str_len);
1093 
1094   // Security Note:
1095   //   The Java level wrapper will perform the necessary security check allowing
1096   //   us to pass the NULL as the initiating class loader.
1097   Handle h_loader(THREAD, JNIHandles::resolve(loader));
1098   Klass* k = SystemDictionary::find_instance_or_array_klass(THREAD, klass_name,
1099                                                             h_loader,
1100                                                             Handle());
1101 #if INCLUDE_CDS
1102   if (k == NULL) {
1103     // If the class is not already loaded, try to see if it's in the shared
1104     // archive for the current classloader (h_loader).
1105     k = SystemDictionaryShared::find_or_load_shared_class(klass_name, h_loader, CHECK_NULL);
1106   }
1107 #endif
1108   return (k == NULL) ? NULL :
1109             (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
1110 JVM_END
1111 
1112 // Module support //////////////////////////////////////////////////////////////////////////////
1113 
1114 JVM_ENTRY(void, JVM_DefineModule(JNIEnv *env, jobject module, jboolean is_open, jstring version,
1115                                  jstring location, jobjectArray packages))
1116   Handle h_module (THREAD, JNIHandles::resolve(module));
1117   Modules::define_module(h_module, is_open, version, location, packages, CHECK);
1118 JVM_END
1119 
1120 JVM_ENTRY(void, JVM_SetBootLoaderUnnamedModule(JNIEnv *env, jobject module))
1121   Handle h_module (THREAD, JNIHandles::resolve(module));
1122   Modules::set_bootloader_unnamed_module(h_module, CHECK);
1123 JVM_END
1124 
1125 JVM_ENTRY(void, JVM_AddModuleExports(JNIEnv *env, jobject from_module, jstring package, jobject to_module))
1126   Handle h_from_module (THREAD, JNIHandles::resolve(from_module));
1127   Handle h_to_module (THREAD, JNIHandles::resolve(to_module));
1128   Modules::add_module_exports_qualified(h_from_module, package, h_to_module, CHECK);
1129 JVM_END
1130 
1131 JVM_ENTRY(void, JVM_AddModuleExportsToAllUnnamed(JNIEnv *env, jobject from_module, jstring package))
1132   Handle h_from_module (THREAD, JNIHandles::resolve(from_module));
1133   Modules::add_module_exports_to_all_unnamed(h_from_module, package, CHECK);
1134 JVM_END
1135 
1136 JVM_ENTRY(void, JVM_AddModuleExportsToAll(JNIEnv *env, jobject from_module, jstring package))
1137   Handle h_from_module (THREAD, JNIHandles::resolve(from_module));
1138   Modules::add_module_exports(h_from_module, package, Handle(), CHECK);
1139 JVM_END
1140 
1141 JVM_ENTRY (void, JVM_AddReadsModule(JNIEnv *env, jobject from_module, jobject source_module))
1142   Handle h_from_module (THREAD, JNIHandles::resolve(from_module));
1143   Handle h_source_module (THREAD, JNIHandles::resolve(source_module));
1144   Modules::add_reads_module(h_from_module, h_source_module, CHECK);
1145 JVM_END
1146 
1147 JVM_ENTRY(void, JVM_DefineArchivedModules(JNIEnv *env, jobject platform_loader, jobject system_loader))
1148   Handle h_platform_loader (THREAD, JNIHandles::resolve(platform_loader));
1149   Handle h_system_loader (THREAD, JNIHandles::resolve(system_loader));
1150   Modules::define_archived_modules(h_platform_loader, h_system_loader, CHECK);
1151 JVM_END
1152 
1153 // Reflection support //////////////////////////////////////////////////////////////////////////////
1154 
1155 JVM_ENTRY(jstring, JVM_InitClassName(JNIEnv *env, jclass cls))
1156   assert (cls != NULL, "illegal class");
1157   JvmtiVMObjectAllocEventCollector oam;
1158   ResourceMark rm(THREAD);
1159   HandleMark hm(THREAD);
1160   Handle java_class(THREAD, JNIHandles::resolve(cls));
1161   oop result = java_lang_Class::name(java_class, CHECK_NULL);
1162   return (jstring) JNIHandles::make_local(THREAD, result);
1163 JVM_END
1164 
1165 
1166 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1167   JvmtiVMObjectAllocEventCollector oam;
1168   oop mirror = JNIHandles::resolve_non_null(cls);
1169 
1170   // Special handling for primitive objects
1171   if (java_lang_Class::is_primitive(mirror)) {
1172     // Primitive objects does not have any interfaces
1173     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1174     return (jobjectArray) JNIHandles::make_local(THREAD, r);
1175   }
1176 
1177   Klass* klass = java_lang_Class::as_Klass(mirror);
1178   // Figure size of result array
1179   int size;
1180   if (klass->is_instance_klass()) {
1181     size = InstanceKlass::cast(klass)->local_interfaces()->length();
1182   } else {
1183     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1184     size = 2;
1185   }
1186 
1187   // Allocate result array
1188   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1189   objArrayHandle result (THREAD, r);
1190   // Fill in result
1191   if (klass->is_instance_klass()) {
1192     // Regular instance klass, fill in all local interfaces
1193     for (int index = 0; index < size; index++) {
1194       Klass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
1195       result->obj_at_put(index, k->java_mirror());
1196     }
1197   } else {
1198     // All arrays implement java.lang.Cloneable and java.io.Serializable
1199     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1200     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1201   }
1202   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1203 JVM_END
1204 
1205 
1206 JVM_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
1207   oop mirror = JNIHandles::resolve_non_null(cls);
1208   if (java_lang_Class::is_primitive(mirror)) {
1209     return JNI_FALSE;
1210   }
1211   Klass* k = java_lang_Class::as_Klass(mirror);
1212   jboolean result = k->is_interface();
1213   assert(!result || k->is_instance_klass(),
1214          "all interfaces are instance types");
1215   // The compiler intrinsic for isInterface tests the
1216   // Klass::_access_flags bits in the same way.
1217   return result;
1218 JVM_END
1219 
1220 JVM_ENTRY(jboolean, JVM_IsHiddenClass(JNIEnv *env, jclass cls))
1221   oop mirror = JNIHandles::resolve_non_null(cls);
1222   if (java_lang_Class::is_primitive(mirror)) {
1223     return JNI_FALSE;
1224   }
1225   Klass* k = java_lang_Class::as_Klass(mirror);
1226   return k->is_hidden();
1227 JVM_END
1228 
1229 JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls))
1230   JvmtiVMObjectAllocEventCollector oam;
1231   oop mirror = JNIHandles::resolve_non_null(cls);
1232   if (java_lang_Class::is_primitive(mirror)) {
1233     // There are no signers for primitive types
1234     return NULL;
1235   }
1236 
1237   objArrayHandle signers(THREAD, java_lang_Class::signers(mirror));
1238 
1239   // If there are no signers set in the class, or if the class
1240   // is an array, return NULL.
1241   if (signers == NULL) return NULL;
1242 
1243   // copy of the signers array
1244   Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass();
1245   objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL);
1246   for (int index = 0; index < signers->length(); index++) {
1247     signers_copy->obj_at_put(index, signers->obj_at(index));
1248   }
1249 
1250   // return the copy
1251   return (jobjectArray) JNIHandles::make_local(THREAD, signers_copy);
1252 JVM_END
1253 
1254 
1255 JVM_ENTRY(void, JVM_SetClassSigners(JNIEnv *env, jclass cls, jobjectArray signers))
1256   oop mirror = JNIHandles::resolve_non_null(cls);
1257   if (!java_lang_Class::is_primitive(mirror)) {
1258     // This call is ignored for primitive types and arrays.
1259     // Signers are only set once, ClassLoader.java, and thus shouldn't
1260     // be called with an array.  Only the bootstrap loader creates arrays.
1261     Klass* k = java_lang_Class::as_Klass(mirror);
1262     if (k->is_instance_klass()) {
1263       java_lang_Class::set_signers(k->java_mirror(), objArrayOop(JNIHandles::resolve(signers)));
1264     }
1265   }
1266 JVM_END
1267 
1268 
1269 JVM_ENTRY(jobject, JVM_GetProtectionDomain(JNIEnv *env, jclass cls))
1270   oop mirror = JNIHandles::resolve_non_null(cls);
1271   if (mirror == NULL) {
1272     THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
1273   }
1274 
1275   if (java_lang_Class::is_primitive(mirror)) {
1276     // Primitive types does not have a protection domain.
1277     return NULL;
1278   }
1279 
1280   oop pd = java_lang_Class::protection_domain(mirror);
1281   return (jobject) JNIHandles::make_local(THREAD, pd);
1282 JVM_END
1283 
1284 
1285 // Returns the inherited_access_control_context field of the running thread.
1286 JVM_ENTRY(jobject, JVM_GetInheritedAccessControlContext(JNIEnv *env, jclass cls))
1287   oop result = java_lang_Thread::inherited_access_control_context(thread->threadObj());
1288   return JNIHandles::make_local(THREAD, result);
1289 JVM_END
1290 
1291 JVM_ENTRY(jobject, JVM_GetStackAccessControlContext(JNIEnv *env, jclass cls))
1292   if (!UsePrivilegedStack) return NULL;
1293 
1294   ResourceMark rm(THREAD);
1295   GrowableArray<Handle>* local_array = new GrowableArray<Handle>(12);
1296   JvmtiVMObjectAllocEventCollector oam;
1297 
1298   // count the protection domains on the execution stack. We collapse
1299   // duplicate consecutive protection domains into a single one, as
1300   // well as stopping when we hit a privileged frame.
1301 
1302   oop previous_protection_domain = NULL;
1303   Handle privileged_context(thread, NULL);
1304   bool is_privileged = false;
1305   oop protection_domain = NULL;
1306 
1307   // Iterate through Java frames
1308   vframeStream vfst(thread);
1309   for(; !vfst.at_end(); vfst.next()) {
1310     // get method of frame
1311     Method* method = vfst.method();
1312 
1313     // stop at the first privileged frame
1314     if (method->method_holder() == vmClasses::AccessController_klass() &&
1315       method->name() == vmSymbols::executePrivileged_name())
1316     {
1317       // this frame is privileged
1318       is_privileged = true;
1319 
1320       javaVFrame *priv = vfst.asJavaVFrame();       // executePrivileged
1321 
1322       StackValueCollection* locals = priv->locals();
1323       StackValue* ctx_sv = locals->at(1); // AccessControlContext context
1324       StackValue* clr_sv = locals->at(2); // Class<?> caller
1325       assert(!ctx_sv->obj_is_scalar_replaced(), "found scalar-replaced object");
1326       assert(!clr_sv->obj_is_scalar_replaced(), "found scalar-replaced object");
1327       privileged_context    = ctx_sv->get_obj();
1328       Handle caller         = clr_sv->get_obj();
1329 
1330       Klass *caller_klass = java_lang_Class::as_Klass(caller());
1331       protection_domain  = caller_klass->protection_domain();
1332     } else {
1333       protection_domain = method->method_holder()->protection_domain();
1334     }
1335 
1336     if ((previous_protection_domain != protection_domain) && (protection_domain != NULL)) {
1337       local_array->push(Handle(thread, protection_domain));
1338       previous_protection_domain = protection_domain;
1339     }
1340 
1341     if (is_privileged) break;
1342   }
1343 
1344 
1345   // either all the domains on the stack were system domains, or
1346   // we had a privileged system domain
1347   if (local_array->is_empty()) {
1348     if (is_privileged && privileged_context.is_null()) return NULL;
1349 
1350     oop result = java_security_AccessControlContext::create(objArrayHandle(), is_privileged, privileged_context, CHECK_NULL);
1351     return JNIHandles::make_local(THREAD, result);
1352   }
1353 
1354   objArrayOop context = oopFactory::new_objArray(vmClasses::ProtectionDomain_klass(),
1355                                                  local_array->length(), CHECK_NULL);
1356   objArrayHandle h_context(thread, context);
1357   for (int index = 0; index < local_array->length(); index++) {
1358     h_context->obj_at_put(index, local_array->at(index)());
1359   }
1360 
1361   oop result = java_security_AccessControlContext::create(h_context, is_privileged, privileged_context, CHECK_NULL);
1362 
1363   return JNIHandles::make_local(THREAD, result);
1364 JVM_END
1365 
1366 class ScopedValueBindingsResolver {
1367 public:
1368   InstanceKlass* Carrier_klass;
1369   ScopedValueBindingsResolver(JavaThread* THREAD) {
1370     Klass *k = SystemDictionary::resolve_or_fail(vmSymbols::jdk_incubator_concurrent_ScopedValue_Carrier(), true, THREAD);
1371     Carrier_klass = InstanceKlass::cast(k);
1372   }
1373 };
1374 
1375 JVM_ENTRY(jobject, JVM_FindScopedValueBindings(JNIEnv *env, jclass cls))
1376   ResourceMark rm(THREAD);
1377   GrowableArray<Handle>* local_array = new GrowableArray<Handle>(12);
1378   JvmtiVMObjectAllocEventCollector oam;
1379 
1380   bool found = false;
1381 
1382   static ScopedValueBindingsResolver resolver(THREAD);
1383 
1384   // Iterate through Java frames
1385   vframeStream vfst(thread);
1386   for(; !vfst.at_end(); vfst.next()) {
1387     int loc = 0;
1388     // get method of frame
1389     Method* method = vfst.method();
1390 
1391     Symbol *name = method->name();
1392 
1393     InstanceKlass* holder = method->method_holder();
1394     if (name == vmSymbols::runWith_method_name()) {
1395       if ((holder == resolver.Carrier_klass
1396            || holder == vmClasses::VirtualThread_klass()
1397            || holder == vmClasses::Thread_klass())) {
1398         loc = 1;
1399       }
1400     }
1401 
1402     if (loc != 0) {
1403       javaVFrame *frame = vfst.asJavaVFrame();
1404       StackValueCollection* locals = frame->locals();
1405       StackValue* head_sv = locals->at(loc); // jdk/incubator/concurrent/ScopedValue$Snapshot
1406       Handle result = head_sv->get_obj();
1407       assert(!head_sv->obj_is_scalar_replaced(), "found scalar-replaced object");
1408       if (result() != NULL) {
1409         return JNIHandles::make_local(THREAD, result());
1410       }
1411     }
1412   }
1413 
1414   return NULL;
1415 JVM_END
1416 
1417 JVM_ENTRY(jboolean, JVM_IsArrayClass(JNIEnv *env, jclass cls))
1418   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
1419   return (k != NULL) && k->is_array_klass() ? true : false;
1420 JVM_END
1421 
1422 
1423 JVM_ENTRY(jboolean, JVM_IsPrimitiveClass(JNIEnv *env, jclass cls))
1424   oop mirror = JNIHandles::resolve_non_null(cls);
1425   return (jboolean) java_lang_Class::is_primitive(mirror);
1426 JVM_END
1427 
1428 
1429 JVM_ENTRY(jint, JVM_GetClassModifiers(JNIEnv *env, jclass cls))
1430   oop mirror = JNIHandles::resolve_non_null(cls);
1431   if (java_lang_Class::is_primitive(mirror)) {
1432     // Primitive type
1433     return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
1434   }
1435 
1436   Klass* k = java_lang_Class::as_Klass(mirror);
1437   debug_only(int computed_modifiers = k->compute_modifier_flags());
1438   assert(k->modifier_flags() == computed_modifiers, "modifiers cache is OK");
1439   return k->modifier_flags();
1440 JVM_END
1441 
1442 
1443 // Inner class reflection ///////////////////////////////////////////////////////////////////////////////
1444 
1445 JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass))
1446   JvmtiVMObjectAllocEventCollector oam;
1447   // ofClass is a reference to a java_lang_Class object. The mirror object
1448   // of an InstanceKlass
1449   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1450   if (java_lang_Class::is_primitive(ofMirror) ||
1451       ! java_lang_Class::as_Klass(ofMirror)->is_instance_klass()) {
1452     oop result = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1453     return (jobjectArray)JNIHandles::make_local(THREAD, result);
1454   }
1455 
1456   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(ofMirror));
1457   InnerClassesIterator iter(k);
1458 
1459   if (iter.length() == 0) {
1460     // Neither an inner nor outer class
1461     oop result = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1462     return (jobjectArray)JNIHandles::make_local(THREAD, result);
1463   }
1464 
1465   // find inner class info
1466   constantPoolHandle cp(thread, k->constants());
1467   int length = iter.length();
1468 
1469   // Allocate temp. result array
1470   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), length/4, CHECK_NULL);
1471   objArrayHandle result (THREAD, r);
1472   int members = 0;
1473 
1474   for (; !iter.done(); iter.next()) {
1475     int ioff = iter.inner_class_info_index();
1476     int ooff = iter.outer_class_info_index();
1477 
1478     if (ioff != 0 && ooff != 0) {
1479       // Check to see if the name matches the class we're looking for
1480       // before attempting to find the class.
1481       if (cp->klass_name_at_matches(k, ooff)) {
1482         Klass* outer_klass = cp->klass_at(ooff, CHECK_NULL);
1483         if (outer_klass == k) {
1484            Klass* ik = cp->klass_at(ioff, CHECK_NULL);
1485            InstanceKlass* inner_klass = InstanceKlass::cast(ik);
1486 
1487            // Throws an exception if outer klass has not declared k as
1488            // an inner klass
1489            Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL);
1490 
1491            result->obj_at_put(members, inner_klass->java_mirror());
1492            members++;
1493         }
1494       }
1495     }
1496   }
1497 
1498   if (members != length) {
1499     // Return array of right length
1500     objArrayOop res = oopFactory::new_objArray(vmClasses::Class_klass(), members, CHECK_NULL);
1501     for(int i = 0; i < members; i++) {
1502       res->obj_at_put(i, result->obj_at(i));
1503     }
1504     return (jobjectArray)JNIHandles::make_local(THREAD, res);
1505   }
1506 
1507   return (jobjectArray)JNIHandles::make_local(THREAD, result());
1508 JVM_END
1509 
1510 
1511 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass))
1512 {
1513   // ofClass is a reference to a java_lang_Class object.
1514   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1515   if (java_lang_Class::is_primitive(ofMirror)) {
1516     return NULL;
1517   }
1518   Klass* klass = java_lang_Class::as_Klass(ofMirror);
1519   if (!klass->is_instance_klass()) {
1520     return NULL;
1521   }
1522 
1523   bool inner_is_member = false;
1524   Klass* outer_klass
1525     = InstanceKlass::cast(klass)->compute_enclosing_class(&inner_is_member, CHECK_NULL);
1526   if (outer_klass == NULL)  return NULL;  // already a top-level class
1527   if (!inner_is_member)  return NULL;     // a hidden class (inside a method)
1528   return (jclass) JNIHandles::make_local(THREAD, outer_klass->java_mirror());
1529 }
1530 JVM_END
1531 
1532 JVM_ENTRY(jstring, JVM_GetSimpleBinaryName(JNIEnv *env, jclass cls))
1533 {
1534   oop mirror = JNIHandles::resolve_non_null(cls);
1535   if (java_lang_Class::is_primitive(mirror)) {
1536     return NULL;
1537   }
1538   Klass* klass = java_lang_Class::as_Klass(mirror);
1539   if (!klass->is_instance_klass()) {
1540     return NULL;
1541   }
1542   InstanceKlass* k = InstanceKlass::cast(klass);
1543   int ooff = 0, noff = 0;
1544   if (k->find_inner_classes_attr(&ooff, &noff, THREAD)) {
1545     if (noff != 0) {
1546       constantPoolHandle i_cp(thread, k->constants());
1547       Symbol* name = i_cp->symbol_at(noff);
1548       Handle str = java_lang_String::create_from_symbol(name, CHECK_NULL);
1549       return (jstring) JNIHandles::make_local(THREAD, str());
1550     }
1551   }
1552   return NULL;
1553 }
1554 JVM_END
1555 
1556 JVM_ENTRY(jstring, JVM_GetClassSignature(JNIEnv *env, jclass cls))
1557   assert (cls != NULL, "illegal class");
1558   JvmtiVMObjectAllocEventCollector oam;
1559   ResourceMark rm(THREAD);
1560   oop mirror = JNIHandles::resolve_non_null(cls);
1561   // Return null for arrays and primitives
1562   if (!java_lang_Class::is_primitive(mirror)) {
1563     Klass* k = java_lang_Class::as_Klass(mirror);
1564     if (k->is_instance_klass()) {
1565       Symbol* sym = InstanceKlass::cast(k)->generic_signature();
1566       if (sym == NULL) return NULL;
1567       Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
1568       return (jstring) JNIHandles::make_local(THREAD, str());
1569     }
1570   }
1571   return NULL;
1572 JVM_END
1573 
1574 
1575 JVM_ENTRY(jbyteArray, JVM_GetClassAnnotations(JNIEnv *env, jclass cls))
1576   assert (cls != NULL, "illegal class");
1577   oop mirror = JNIHandles::resolve_non_null(cls);
1578   // Return null for arrays and primitives
1579   if (!java_lang_Class::is_primitive(mirror)) {
1580     Klass* k = java_lang_Class::as_Klass(mirror);
1581     if (k->is_instance_klass()) {
1582       typeArrayOop a = Annotations::make_java_array(InstanceKlass::cast(k)->class_annotations(), CHECK_NULL);
1583       return (jbyteArray) JNIHandles::make_local(THREAD, a);
1584     }
1585   }
1586   return NULL;
1587 JVM_END
1588 
1589 
1590 static bool jvm_get_field_common(jobject field, fieldDescriptor& fd) {
1591   // some of this code was adapted from from jni_FromReflectedField
1592 
1593   oop reflected = JNIHandles::resolve_non_null(field);
1594   oop mirror    = java_lang_reflect_Field::clazz(reflected);
1595   Klass* k    = java_lang_Class::as_Klass(mirror);
1596   int slot      = java_lang_reflect_Field::slot(reflected);
1597   int modifiers = java_lang_reflect_Field::modifiers(reflected);
1598 
1599   InstanceKlass* ik = InstanceKlass::cast(k);
1600   intptr_t offset = ik->field_offset(slot);
1601 
1602   if (modifiers & JVM_ACC_STATIC) {
1603     // for static fields we only look in the current class
1604     if (!ik->find_local_field_from_offset(offset, true, &fd)) {
1605       assert(false, "cannot find static field");
1606       return false;
1607     }
1608   } else {
1609     // for instance fields we start with the current class and work
1610     // our way up through the superclass chain
1611     if (!ik->find_field_from_offset(offset, false, &fd)) {
1612       assert(false, "cannot find instance field");
1613       return false;
1614     }
1615   }
1616   return true;
1617 }
1618 
1619 static Method* jvm_get_method_common(jobject method) {
1620   // some of this code was adapted from from jni_FromReflectedMethod
1621 
1622   oop reflected = JNIHandles::resolve_non_null(method);
1623   oop mirror    = NULL;
1624   int slot      = 0;
1625 
1626   if (reflected->klass() == vmClasses::reflect_Constructor_klass()) {
1627     mirror = java_lang_reflect_Constructor::clazz(reflected);
1628     slot   = java_lang_reflect_Constructor::slot(reflected);
1629   } else {
1630     assert(reflected->klass() == vmClasses::reflect_Method_klass(),
1631            "wrong type");
1632     mirror = java_lang_reflect_Method::clazz(reflected);
1633     slot   = java_lang_reflect_Method::slot(reflected);
1634   }
1635   Klass* k = java_lang_Class::as_Klass(mirror);
1636 
1637   Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
1638   assert(m != NULL, "cannot find method");
1639   return m;  // caller has to deal with NULL in product mode
1640 }
1641 
1642 /* Type use annotations support (JDK 1.8) */
1643 
1644 JVM_ENTRY(jbyteArray, JVM_GetClassTypeAnnotations(JNIEnv *env, jclass cls))
1645   assert (cls != NULL, "illegal class");
1646   ResourceMark rm(THREAD);
1647   // Return null for arrays and primitives
1648   if (!java_lang_Class::is_primitive(JNIHandles::resolve(cls))) {
1649     Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
1650     if (k->is_instance_klass()) {
1651       AnnotationArray* type_annotations = InstanceKlass::cast(k)->class_type_annotations();
1652       if (type_annotations != NULL) {
1653         typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL);
1654         return (jbyteArray) JNIHandles::make_local(THREAD, a);
1655       }
1656     }
1657   }
1658   return NULL;
1659 JVM_END
1660 
1661 JVM_ENTRY(jbyteArray, JVM_GetMethodTypeAnnotations(JNIEnv *env, jobject method))
1662   assert (method != NULL, "illegal method");
1663   // method is a handle to a java.lang.reflect.Method object
1664   Method* m = jvm_get_method_common(method);
1665   if (m == NULL) {
1666     return NULL;
1667   }
1668 
1669   AnnotationArray* type_annotations = m->type_annotations();
1670   if (type_annotations != NULL) {
1671     typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL);
1672     return (jbyteArray) JNIHandles::make_local(THREAD, a);
1673   }
1674 
1675   return NULL;
1676 JVM_END
1677 
1678 JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field))
1679   assert (field != NULL, "illegal field");
1680   fieldDescriptor fd;
1681   bool gotFd = jvm_get_field_common(field, fd);
1682   if (!gotFd) {
1683     return NULL;
1684   }
1685 
1686   return (jbyteArray) JNIHandles::make_local(THREAD, Annotations::make_java_array(fd.type_annotations(), THREAD));
1687 JVM_END
1688 
1689 static void bounds_check(const constantPoolHandle& cp, jint index, TRAPS) {
1690   if (!cp->is_within_bounds(index)) {
1691     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
1692   }
1693 }
1694 
1695 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method))
1696 {
1697   // method is a handle to a java.lang.reflect.Method object
1698   Method* method_ptr = jvm_get_method_common(method);
1699   methodHandle mh (THREAD, method_ptr);
1700   Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method));
1701   const int num_params = mh->method_parameters_length();
1702 
1703   if (num_params < 0) {
1704     // A -1 return value from method_parameters_length means there is no
1705     // parameter data.  Return null to indicate this to the reflection
1706     // API.
1707     assert(num_params == -1, "num_params should be -1 if it is less than zero");
1708     return (jobjectArray)NULL;
1709   } else {
1710     // Otherwise, we return something up to reflection, even if it is
1711     // a zero-length array.  Why?  Because in some cases this can
1712     // trigger a MalformedParametersException.
1713 
1714     // make sure all the symbols are properly formatted
1715     for (int i = 0; i < num_params; i++) {
1716       MethodParametersElement* params = mh->method_parameters_start();
1717       int index = params[i].name_cp_index;
1718       constantPoolHandle cp(THREAD, mh->constants());
1719       bounds_check(cp, index, CHECK_NULL);
1720 
1721       if (0 != index && !mh->constants()->tag_at(index).is_utf8()) {
1722         THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1723                     "Wrong type at constant pool index");
1724       }
1725 
1726     }
1727 
1728     objArrayOop result_oop = oopFactory::new_objArray(vmClasses::reflect_Parameter_klass(), num_params, CHECK_NULL);
1729     objArrayHandle result (THREAD, result_oop);
1730 
1731     for (int i = 0; i < num_params; i++) {
1732       MethodParametersElement* params = mh->method_parameters_start();
1733       // For a 0 index, give a NULL symbol
1734       Symbol* sym = 0 != params[i].name_cp_index ?
1735         mh->constants()->symbol_at(params[i].name_cp_index) : NULL;
1736       int flags = params[i].flags;
1737       oop param = Reflection::new_parameter(reflected_method, i, sym,
1738                                             flags, CHECK_NULL);
1739       result->obj_at_put(i, param);
1740     }
1741     return (jobjectArray)JNIHandles::make_local(THREAD, result());
1742   }
1743 }
1744 JVM_END
1745 
1746 // New (JDK 1.4) reflection implementation /////////////////////////////////////
1747 
1748 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1749 {
1750   JvmtiVMObjectAllocEventCollector oam;
1751 
1752   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1753   // Exclude primitive types and array types
1754   if (java_lang_Class::is_primitive(ofMirror) ||
1755       java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1756     // Return empty array
1757     oop res = oopFactory::new_objArray(vmClasses::reflect_Field_klass(), 0, CHECK_NULL);
1758     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1759   }
1760 
1761   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(ofMirror));
1762   constantPoolHandle cp(THREAD, k->constants());
1763 
1764   // Ensure class is linked
1765   k->link_class(CHECK_NULL);
1766 
1767   // Allocate result
1768   int num_fields;
1769 
1770   if (publicOnly) {
1771     num_fields = 0;
1772     for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
1773       if (fs.access_flags().is_public()) ++num_fields;
1774     }
1775   } else {
1776     num_fields = k->java_fields_count();
1777   }
1778 
1779   objArrayOop r = oopFactory::new_objArray(vmClasses::reflect_Field_klass(), num_fields, CHECK_NULL);
1780   objArrayHandle result (THREAD, r);
1781 
1782   int out_idx = 0;
1783   fieldDescriptor fd;
1784   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
1785     if (!publicOnly || fs.access_flags().is_public()) {
1786       fd.reinitialize(k, fs.index());
1787       oop field = Reflection::new_field(&fd, CHECK_NULL);
1788       result->obj_at_put(out_idx, field);
1789       ++out_idx;
1790     }
1791   }
1792   assert(out_idx == num_fields, "just checking");
1793   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1794 }
1795 JVM_END
1796 
1797 // A class is a record if and only if it is final and a direct subclass of
1798 // java.lang.Record and has a Record attribute; otherwise, it is not a record.
1799 JVM_ENTRY(jboolean, JVM_IsRecord(JNIEnv *env, jclass cls))
1800 {
1801   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
1802   if (k != NULL && k->is_instance_klass()) {
1803     InstanceKlass* ik = InstanceKlass::cast(k);
1804     return ik->is_record();
1805   } else {
1806     return false;
1807   }
1808 }
1809 JVM_END
1810 
1811 // Returns an array containing the components of the Record attribute,
1812 // or NULL if the attribute is not present.
1813 //
1814 // Note that this function returns the components of the Record attribute
1815 // even if the class is not a record.
1816 JVM_ENTRY(jobjectArray, JVM_GetRecordComponents(JNIEnv* env, jclass ofClass))
1817 {
1818   Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass));
1819   assert(c->is_instance_klass(), "must be");
1820   InstanceKlass* ik = InstanceKlass::cast(c);
1821 
1822   Array<RecordComponent*>* components = ik->record_components();
1823   if (components != NULL) {
1824     JvmtiVMObjectAllocEventCollector oam;
1825     constantPoolHandle cp(THREAD, ik->constants());
1826     int length = components->length();
1827     assert(length >= 0, "unexpected record_components length");
1828     objArrayOop record_components =
1829       oopFactory::new_objArray(vmClasses::RecordComponent_klass(), length, CHECK_NULL);
1830     objArrayHandle components_h (THREAD, record_components);
1831 
1832     for (int x = 0; x < length; x++) {
1833       RecordComponent* component = components->at(x);
1834       assert(component != NULL, "unexpected NULL record component");
1835       oop component_oop = java_lang_reflect_RecordComponent::create(ik, component, CHECK_NULL);
1836       components_h->obj_at_put(x, component_oop);
1837     }
1838     return (jobjectArray)JNIHandles::make_local(THREAD, components_h());
1839   }
1840 
1841   return NULL;
1842 }
1843 JVM_END
1844 
1845 static bool select_method(const methodHandle& method, bool want_constructor) {
1846   if (want_constructor) {
1847     return (method->is_initializer() && !method->is_static());
1848   } else {
1849     return  (!method->is_initializer() && !method->is_overpass());
1850   }
1851 }
1852 
1853 static jobjectArray get_class_declared_methods_helper(
1854                                   JNIEnv *env,
1855                                   jclass ofClass, jboolean publicOnly,
1856                                   bool want_constructor,
1857                                   Klass* klass, TRAPS) {
1858 
1859   JvmtiVMObjectAllocEventCollector oam;
1860 
1861   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1862   // Exclude primitive types and array types
1863   if (java_lang_Class::is_primitive(ofMirror)
1864       || java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1865     // Return empty array
1866     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1867     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1868   }
1869 
1870   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(ofMirror));
1871 
1872   // Ensure class is linked
1873   k->link_class(CHECK_NULL);
1874 
1875   Array<Method*>* methods = k->methods();
1876   int methods_length = methods->length();
1877 
1878   // Save original method_idnum in case of redefinition, which can change
1879   // the idnum of obsolete methods.  The new method will have the same idnum
1880   // but if we refresh the methods array, the counts will be wrong.
1881   ResourceMark rm(THREAD);
1882   GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
1883   int num_methods = 0;
1884 
1885   for (int i = 0; i < methods_length; i++) {
1886     methodHandle method(THREAD, methods->at(i));
1887     if (select_method(method, want_constructor)) {
1888       if (!publicOnly || method->is_public()) {
1889         idnums->push(method->method_idnum());
1890         ++num_methods;
1891       }
1892     }
1893   }
1894 
1895   // Allocate result
1896   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1897   objArrayHandle result (THREAD, r);
1898 
1899   // Now just put the methods that we selected above, but go by their idnum
1900   // in case of redefinition.  The methods can be redefined at any safepoint,
1901   // so above when allocating the oop array and below when creating reflect
1902   // objects.
1903   for (int i = 0; i < num_methods; i++) {
1904     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1905     if (method.is_null()) {
1906       // Method may have been deleted and seems this API can handle null
1907       // Otherwise should probably put a method that throws NSME
1908       result->obj_at_put(i, NULL);
1909     } else {
1910       oop m;
1911       if (want_constructor) {
1912         m = Reflection::new_constructor(method, CHECK_NULL);
1913       } else {
1914         m = Reflection::new_method(method, false, CHECK_NULL);
1915       }
1916       result->obj_at_put(i, m);
1917     }
1918   }
1919 
1920   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1921 }
1922 
1923 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1924 {
1925   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1926                                            /*want_constructor*/ false,
1927                                            vmClasses::reflect_Method_klass(), THREAD);
1928 }
1929 JVM_END
1930 
1931 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1932 {
1933   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1934                                            /*want_constructor*/ true,
1935                                            vmClasses::reflect_Constructor_klass(), THREAD);
1936 }
1937 JVM_END
1938 
1939 JVM_ENTRY(jint, JVM_GetClassAccessFlags(JNIEnv *env, jclass cls))
1940 {
1941   oop mirror = JNIHandles::resolve_non_null(cls);
1942   if (java_lang_Class::is_primitive(mirror)) {
1943     // Primitive type
1944     return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
1945   }
1946 
1947   Klass* k = java_lang_Class::as_Klass(mirror);
1948   return k->access_flags().as_int() & JVM_ACC_WRITTEN_FLAGS;
1949 }
1950 JVM_END
1951 
1952 JVM_ENTRY(jboolean, JVM_AreNestMates(JNIEnv *env, jclass current, jclass member))
1953 {
1954   Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current));
1955   assert(c->is_instance_klass(), "must be");
1956   InstanceKlass* ck = InstanceKlass::cast(c);
1957   Klass* m = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(member));
1958   assert(m->is_instance_klass(), "must be");
1959   InstanceKlass* mk = InstanceKlass::cast(m);
1960   return ck->has_nestmate_access_to(mk, THREAD);
1961 }
1962 JVM_END
1963 
1964 JVM_ENTRY(jclass, JVM_GetNestHost(JNIEnv* env, jclass current))
1965 {
1966   // current is not a primitive or array class
1967   Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current));
1968   assert(c->is_instance_klass(), "must be");
1969   InstanceKlass* ck = InstanceKlass::cast(c);
1970   InstanceKlass* host = ck->nest_host(THREAD);
1971   return (jclass) (host == NULL ? NULL :
1972                    JNIHandles::make_local(THREAD, host->java_mirror()));
1973 }
1974 JVM_END
1975 
1976 JVM_ENTRY(jobjectArray, JVM_GetNestMembers(JNIEnv* env, jclass current))
1977 {
1978   // current is not a primitive or array class
1979   ResourceMark rm(THREAD);
1980   Klass* c = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(current));
1981   assert(c->is_instance_klass(), "must be");
1982   InstanceKlass* ck = InstanceKlass::cast(c);
1983   InstanceKlass* host = ck->nest_host(THREAD);
1984 
1985   log_trace(class, nestmates)("Calling GetNestMembers for type %s with nest-host %s",
1986                               ck->external_name(), host->external_name());
1987   {
1988     JvmtiVMObjectAllocEventCollector oam;
1989     Array<u2>* members = host->nest_members();
1990     int length = members == NULL ? 0 : members->length();
1991 
1992     log_trace(class, nestmates)(" - host has %d listed nest members", length);
1993 
1994     // nest host is first in the array so make it one bigger
1995     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(),
1996                                              length + 1, CHECK_NULL);
1997     objArrayHandle result(THREAD, r);
1998     result->obj_at_put(0, host->java_mirror());
1999     if (length != 0) {
2000       int count = 0;
2001       for (int i = 0; i < length; i++) {
2002         int cp_index = members->at(i);
2003         Klass* k = host->constants()->klass_at(cp_index, THREAD);
2004         if (HAS_PENDING_EXCEPTION) {
2005           if (PENDING_EXCEPTION->is_a(vmClasses::VirtualMachineError_klass())) {
2006             return NULL; // propagate VMEs
2007           }
2008           if (log_is_enabled(Trace, class, nestmates)) {
2009             stringStream ss;
2010             char* target_member_class = host->constants()->klass_name_at(cp_index)->as_C_string();
2011             ss.print(" - resolution of nest member %s failed: ", target_member_class);
2012             java_lang_Throwable::print(PENDING_EXCEPTION, &ss);
2013             log_trace(class, nestmates)("%s", ss.as_string());
2014           }
2015           CLEAR_PENDING_EXCEPTION;
2016           continue;
2017         }
2018         if (k->is_instance_klass()) {
2019           InstanceKlass* ik = InstanceKlass::cast(k);
2020           InstanceKlass* nest_host_k = ik->nest_host(CHECK_NULL);
2021           if (nest_host_k == host) {
2022             result->obj_at_put(count+1, k->java_mirror());
2023             count++;
2024             log_trace(class, nestmates)(" - [%d] = %s", count, ik->external_name());
2025           } else {
2026             log_trace(class, nestmates)(" - skipping member %s with different host %s",
2027                                         ik->external_name(), nest_host_k->external_name());
2028           }
2029         } else {
2030           log_trace(class, nestmates)(" - skipping member %s that is not an instance class",
2031                                       k->external_name());
2032         }
2033       }
2034       if (count < length) {
2035         // we had invalid entries so we need to compact the array
2036         log_trace(class, nestmates)(" - compacting array from length %d to %d",
2037                                     length + 1, count + 1);
2038 
2039         objArrayOop r2 = oopFactory::new_objArray(vmClasses::Class_klass(),
2040                                                   count + 1, CHECK_NULL);
2041         objArrayHandle result2(THREAD, r2);
2042         for (int i = 0; i < count + 1; i++) {
2043           result2->obj_at_put(i, result->obj_at(i));
2044         }
2045         return (jobjectArray)JNIHandles::make_local(THREAD, result2());
2046       }
2047     }
2048     else {
2049       assert(host == ck || ck->is_hidden(), "must be singleton nest or dynamic nestmate");
2050     }
2051     return (jobjectArray)JNIHandles::make_local(THREAD, result());
2052   }
2053 }
2054 JVM_END
2055 
2056 JVM_ENTRY(jobjectArray, JVM_GetPermittedSubclasses(JNIEnv* env, jclass current))
2057 {
2058   oop mirror = JNIHandles::resolve_non_null(current);
2059   assert(!java_lang_Class::is_primitive(mirror), "should not be");
2060   Klass* c = java_lang_Class::as_Klass(mirror);
2061   assert(c->is_instance_klass(), "must be");
2062   InstanceKlass* ik = InstanceKlass::cast(c);
2063   ResourceMark rm(THREAD);
2064   log_trace(class, sealed)("Calling GetPermittedSubclasses for %s type %s",
2065                            ik->is_sealed() ? "sealed" : "non-sealed", ik->external_name());
2066   if (ik->is_sealed()) {
2067     JvmtiVMObjectAllocEventCollector oam;
2068     Array<u2>* subclasses = ik->permitted_subclasses();
2069     int length = subclasses->length();
2070 
2071     log_trace(class, sealed)(" - sealed class has %d permitted subclasses", length);
2072 
2073     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(),
2074                                              length, CHECK_NULL);
2075     objArrayHandle result(THREAD, r);
2076     int count = 0;
2077     for (int i = 0; i < length; i++) {
2078       int cp_index = subclasses->at(i);
2079       Klass* k = ik->constants()->klass_at(cp_index, THREAD);
2080       if (HAS_PENDING_EXCEPTION) {
2081         if (PENDING_EXCEPTION->is_a(vmClasses::VirtualMachineError_klass())) {
2082           return NULL; // propagate VMEs
2083         }
2084         if (log_is_enabled(Trace, class, sealed)) {
2085           stringStream ss;
2086           char* permitted_subclass = ik->constants()->klass_name_at(cp_index)->as_C_string();
2087           ss.print(" - resolution of permitted subclass %s failed: ", permitted_subclass);
2088           java_lang_Throwable::print(PENDING_EXCEPTION, &ss);
2089           log_trace(class, sealed)("%s", ss.as_string());
2090         }
2091 
2092         CLEAR_PENDING_EXCEPTION;
2093         continue;
2094       }
2095       if (k->is_instance_klass()) {
2096         result->obj_at_put(count++, k->java_mirror());
2097         log_trace(class, sealed)(" - [%d] = %s", count, k->external_name());
2098       }
2099     }
2100     if (count < length) {
2101       // we had invalid entries so we need to compact the array
2102       objArrayOop r2 = oopFactory::new_objArray(vmClasses::Class_klass(),
2103                                                 count, CHECK_NULL);
2104       objArrayHandle result2(THREAD, r2);
2105       for (int i = 0; i < count; i++) {
2106         result2->obj_at_put(i, result->obj_at(i));
2107       }
2108       return (jobjectArray)JNIHandles::make_local(THREAD, result2());
2109     }
2110     return (jobjectArray)JNIHandles::make_local(THREAD, result());
2111   } else {
2112     return NULL;
2113   }
2114 }
2115 JVM_END
2116 
2117 // Constant pool access //////////////////////////////////////////////////////////
2118 
2119 JVM_ENTRY(jobject, JVM_GetClassConstantPool(JNIEnv *env, jclass cls))
2120 {
2121   JvmtiVMObjectAllocEventCollector oam;
2122   oop mirror = JNIHandles::resolve_non_null(cls);
2123   // Return null for primitives and arrays
2124   if (!java_lang_Class::is_primitive(mirror)) {
2125     Klass* k = java_lang_Class::as_Klass(mirror);
2126     if (k->is_instance_klass()) {
2127       InstanceKlass* k_h = InstanceKlass::cast(k);
2128       Handle jcp = reflect_ConstantPool::create(CHECK_NULL);
2129       reflect_ConstantPool::set_cp(jcp(), k_h->constants());
2130       return JNIHandles::make_local(THREAD, jcp());
2131     }
2132   }
2133   return NULL;
2134 }
2135 JVM_END
2136 
2137 
2138 JVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject obj, jobject unused))
2139 {
2140   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2141   return cp->length();
2142 }
2143 JVM_END
2144 
2145 
2146 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2147 {
2148   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2149   bounds_check(cp, index, CHECK_NULL);
2150   constantTag tag = cp->tag_at(index);
2151   if (!tag.is_klass() && !tag.is_unresolved_klass()) {
2152     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2153   }
2154   Klass* k = cp->klass_at(index, CHECK_NULL);
2155   return (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
2156 }
2157 JVM_END
2158 
2159 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2160 {
2161   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2162   bounds_check(cp, index, CHECK_NULL);
2163   constantTag tag = cp->tag_at(index);
2164   if (!tag.is_klass() && !tag.is_unresolved_klass()) {
2165     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2166   }
2167   Klass* k = ConstantPool::klass_at_if_loaded(cp, index);
2168   if (k == NULL) return NULL;
2169   return (jclass) JNIHandles::make_local(THREAD, k->java_mirror());
2170 }
2171 JVM_END
2172 
2173 static jobject get_method_at_helper(const constantPoolHandle& cp, jint index, bool force_resolution, TRAPS) {
2174   constantTag tag = cp->tag_at(index);
2175   if (!tag.is_method() && !tag.is_interface_method()) {
2176     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2177   }
2178   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2179   Klass* k_o;
2180   if (force_resolution) {
2181     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2182   } else {
2183     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2184     if (k_o == NULL) return NULL;
2185   }
2186   InstanceKlass* k = InstanceKlass::cast(k_o);
2187   Symbol* name = cp->uncached_name_ref_at(index);
2188   Symbol* sig  = cp->uncached_signature_ref_at(index);
2189   methodHandle m (THREAD, k->find_method(name, sig));
2190   if (m.is_null()) {
2191     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2192   }
2193   oop method;
2194   if (!m->is_initializer() || m->is_static()) {
2195     method = Reflection::new_method(m, true, CHECK_NULL);
2196   } else {
2197     method = Reflection::new_constructor(m, CHECK_NULL);
2198   }
2199   return JNIHandles::make_local(THREAD, method);
2200 }
2201 
2202 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2203 {
2204   JvmtiVMObjectAllocEventCollector oam;
2205   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2206   bounds_check(cp, index, CHECK_NULL);
2207   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2208   return res;
2209 }
2210 JVM_END
2211 
2212 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2213 {
2214   JvmtiVMObjectAllocEventCollector oam;
2215   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2216   bounds_check(cp, index, CHECK_NULL);
2217   jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);
2218   return res;
2219 }
2220 JVM_END
2221 
2222 static jobject get_field_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
2223   constantTag tag = cp->tag_at(index);
2224   if (!tag.is_field()) {
2225     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2226   }
2227   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2228   Klass* k_o;
2229   if (force_resolution) {
2230     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2231   } else {
2232     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2233     if (k_o == NULL) return NULL;
2234   }
2235   InstanceKlass* k = InstanceKlass::cast(k_o);
2236   Symbol* name = cp->uncached_name_ref_at(index);
2237   Symbol* sig  = cp->uncached_signature_ref_at(index);
2238   fieldDescriptor fd;
2239   Klass* target_klass = k->find_field(name, sig, &fd);
2240   if (target_klass == NULL) {
2241     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up field in target class");
2242   }
2243   oop field = Reflection::new_field(&fd, CHECK_NULL);
2244   return JNIHandles::make_local(THREAD, field);
2245 }
2246 
2247 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAt(JNIEnv *env, jobject obj, jobject unusedl, jint index))
2248 {
2249   JvmtiVMObjectAllocEventCollector oam;
2250   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2251   bounds_check(cp, index, CHECK_NULL);
2252   jobject res = get_field_at_helper(cp, index, true, CHECK_NULL);
2253   return res;
2254 }
2255 JVM_END
2256 
2257 JVM_ENTRY(jobject, JVM_ConstantPoolGetFieldAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2258 {
2259   JvmtiVMObjectAllocEventCollector oam;
2260   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2261   bounds_check(cp, index, CHECK_NULL);
2262   jobject res = get_field_at_helper(cp, index, false, CHECK_NULL);
2263   return res;
2264 }
2265 JVM_END
2266 
2267 JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetMemberRefInfoAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2268 {
2269   JvmtiVMObjectAllocEventCollector oam;
2270   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2271   bounds_check(cp, index, CHECK_NULL);
2272   constantTag tag = cp->tag_at(index);
2273   if (!tag.is_field_or_method()) {
2274     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2275   }
2276   int klass_ref = cp->uncached_klass_ref_index_at(index);
2277   Symbol*  klass_name  = cp->klass_name_at(klass_ref);
2278   Symbol*  member_name = cp->uncached_name_ref_at(index);
2279   Symbol*  member_sig  = cp->uncached_signature_ref_at(index);
2280   objArrayOop  dest_o = oopFactory::new_objArray(vmClasses::String_klass(), 3, CHECK_NULL);
2281   objArrayHandle dest(THREAD, dest_o);
2282   Handle str = java_lang_String::create_from_symbol(klass_name, CHECK_NULL);
2283   dest->obj_at_put(0, str());
2284   str = java_lang_String::create_from_symbol(member_name, CHECK_NULL);
2285   dest->obj_at_put(1, str());
2286   str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL);
2287   dest->obj_at_put(2, str());
2288   return (jobjectArray) JNIHandles::make_local(THREAD, dest());
2289 }
2290 JVM_END
2291 
2292 JVM_ENTRY(jint, JVM_ConstantPoolGetClassRefIndexAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2293 {
2294   JvmtiVMObjectAllocEventCollector oam;
2295   constantPoolHandle cp(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2296   bounds_check(cp, index, CHECK_0);
2297   constantTag tag = cp->tag_at(index);
2298   if (!tag.is_field_or_method()) {
2299     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2300   }
2301   return (jint) cp->uncached_klass_ref_index_at(index);
2302 }
2303 JVM_END
2304 
2305 JVM_ENTRY(jint, JVM_ConstantPoolGetNameAndTypeRefIndexAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2306 {
2307   JvmtiVMObjectAllocEventCollector oam;
2308   constantPoolHandle cp(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2309   bounds_check(cp, index, CHECK_0);
2310   constantTag tag = cp->tag_at(index);
2311   if (!tag.is_invoke_dynamic() && !tag.is_field_or_method()) {
2312     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2313   }
2314   return (jint) cp->uncached_name_and_type_ref_index_at(index);
2315 }
2316 JVM_END
2317 
2318 JVM_ENTRY(jobjectArray, JVM_ConstantPoolGetNameAndTypeRefInfoAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2319 {
2320   JvmtiVMObjectAllocEventCollector oam;
2321   constantPoolHandle cp(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2322   bounds_check(cp, index, CHECK_NULL);
2323   constantTag tag = cp->tag_at(index);
2324   if (!tag.is_name_and_type()) {
2325     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2326   }
2327   Symbol* member_name = cp->symbol_at(cp->name_ref_index_at(index));
2328   Symbol* member_sig = cp->symbol_at(cp->signature_ref_index_at(index));
2329   objArrayOop dest_o = oopFactory::new_objArray(vmClasses::String_klass(), 2, CHECK_NULL);
2330   objArrayHandle dest(THREAD, dest_o);
2331   Handle str = java_lang_String::create_from_symbol(member_name, CHECK_NULL);
2332   dest->obj_at_put(0, str());
2333   str = java_lang_String::create_from_symbol(member_sig, CHECK_NULL);
2334   dest->obj_at_put(1, str());
2335   return (jobjectArray) JNIHandles::make_local(THREAD, dest());
2336 }
2337 JVM_END
2338 
2339 JVM_ENTRY(jint, JVM_ConstantPoolGetIntAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2340 {
2341   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2342   bounds_check(cp, index, CHECK_0);
2343   constantTag tag = cp->tag_at(index);
2344   if (!tag.is_int()) {
2345     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2346   }
2347   return cp->int_at(index);
2348 }
2349 JVM_END
2350 
2351 JVM_ENTRY(jlong, JVM_ConstantPoolGetLongAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2352 {
2353   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2354   bounds_check(cp, index, CHECK_(0L));
2355   constantTag tag = cp->tag_at(index);
2356   if (!tag.is_long()) {
2357     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2358   }
2359   return cp->long_at(index);
2360 }
2361 JVM_END
2362 
2363 JVM_ENTRY(jfloat, JVM_ConstantPoolGetFloatAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2364 {
2365   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2366   bounds_check(cp, index, CHECK_(0.0f));
2367   constantTag tag = cp->tag_at(index);
2368   if (!tag.is_float()) {
2369     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2370   }
2371   return cp->float_at(index);
2372 }
2373 JVM_END
2374 
2375 JVM_ENTRY(jdouble, JVM_ConstantPoolGetDoubleAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2376 {
2377   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2378   bounds_check(cp, index, CHECK_(0.0));
2379   constantTag tag = cp->tag_at(index);
2380   if (!tag.is_double()) {
2381     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2382   }
2383   return cp->double_at(index);
2384 }
2385 JVM_END
2386 
2387 JVM_ENTRY(jstring, JVM_ConstantPoolGetStringAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2388 {
2389   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2390   bounds_check(cp, index, CHECK_NULL);
2391   constantTag tag = cp->tag_at(index);
2392   if (!tag.is_string()) {
2393     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2394   }
2395   oop str = cp->string_at(index, CHECK_NULL);
2396   return (jstring) JNIHandles::make_local(THREAD, str);
2397 }
2398 JVM_END
2399 
2400 JVM_ENTRY(jstring, JVM_ConstantPoolGetUTF8At(JNIEnv *env, jobject obj, jobject unused, jint index))
2401 {
2402   JvmtiVMObjectAllocEventCollector oam;
2403   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2404   bounds_check(cp, index, CHECK_NULL);
2405   constantTag tag = cp->tag_at(index);
2406   if (!tag.is_symbol()) {
2407     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2408   }
2409   Symbol* sym = cp->symbol_at(index);
2410   Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
2411   return (jstring) JNIHandles::make_local(THREAD, str());
2412 }
2413 JVM_END
2414 
2415 JVM_ENTRY(jbyte, JVM_ConstantPoolGetTagAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2416 {
2417   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2418   bounds_check(cp, index, CHECK_0);
2419   constantTag tag = cp->tag_at(index);
2420   jbyte result = tag.value();
2421   // If returned tag values are not from the JVM spec, e.g. tags from 100 to 105,
2422   // they are changed to the corresponding tags from the JVM spec, so that java code in
2423   // sun.reflect.ConstantPool will return only tags from the JVM spec, not internal ones.
2424   if (tag.is_klass_or_reference()) {
2425       result = JVM_CONSTANT_Class;
2426   } else if (tag.is_string_index()) {
2427       result = JVM_CONSTANT_String;
2428   } else if (tag.is_method_type_in_error()) {
2429       result = JVM_CONSTANT_MethodType;
2430   } else if (tag.is_method_handle_in_error()) {
2431       result = JVM_CONSTANT_MethodHandle;
2432   } else if (tag.is_dynamic_constant_in_error()) {
2433       result = JVM_CONSTANT_Dynamic;
2434   }
2435   return result;
2436 }
2437 JVM_END
2438 
2439 // Assertion support. //////////////////////////////////////////////////////////
2440 
2441 JVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls))
2442   assert(cls != NULL, "bad class");
2443 
2444   oop r = JNIHandles::resolve(cls);
2445   assert(! java_lang_Class::is_primitive(r), "primitive classes not allowed");
2446   if (java_lang_Class::is_primitive(r)) return false;
2447 
2448   Klass* k = java_lang_Class::as_Klass(r);
2449   assert(k->is_instance_klass(), "must be an instance klass");
2450   if (!k->is_instance_klass()) return false;
2451 
2452   ResourceMark rm(THREAD);
2453   const char* name = k->name()->as_C_string();
2454   bool system_class = k->class_loader() == NULL;
2455   return JavaAssertions::enabled(name, system_class);
2456 
2457 JVM_END
2458 
2459 
2460 // Return a new AssertionStatusDirectives object with the fields filled in with
2461 // command-line assertion arguments (i.e., -ea, -da).
2462 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2463   JvmtiVMObjectAllocEventCollector oam;
2464   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2465   return JNIHandles::make_local(THREAD, asd);
2466 JVM_END
2467 
2468 // Verification ////////////////////////////////////////////////////////////////////////////////
2469 
2470 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2471 
2472 // RedefineClasses support: bug 6214132 caused verification to fail.
2473 // All functions from this section should call the jvmtiThreadSate function:
2474 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2475 // The function returns a Klass* of the _scratch_class if the verifier
2476 // was invoked in the middle of the class redefinition.
2477 // Otherwise it returns its argument value which is the _the_class Klass*.
2478 // Please, refer to the description in the jvmtiThreadSate.hpp.
2479 
2480 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2481   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2482   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2483   return k->name()->as_utf8();
2484 JVM_END
2485 
2486 
2487 JVM_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
2488   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2489   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2490   // types will have length zero if this is not an InstanceKlass
2491   // (length is determined by call to JVM_GetClassCPEntriesCount)
2492   if (k->is_instance_klass()) {
2493     ConstantPool* cp = InstanceKlass::cast(k)->constants();
2494     for (int index = cp->length() - 1; index >= 0; index--) {
2495       constantTag tag = cp->tag_at(index);
2496       types[index] = (tag.is_unresolved_klass()) ? (unsigned char) JVM_CONSTANT_Class : tag.value();
2497     }
2498   }
2499 JVM_END
2500 
2501 
2502 JVM_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
2503   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2504   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2505   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->constants()->length();
2506 JVM_END
2507 
2508 
2509 JVM_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
2510   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2511   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2512   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->java_fields_count();
2513 JVM_END
2514 
2515 
2516 JVM_ENTRY(jint, JVM_GetClassMethodsCount(JNIEnv *env, jclass cls))
2517   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2518   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2519   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->methods()->length();
2520 JVM_END
2521 
2522 
2523 // The following methods, used for the verifier, are never called with
2524 // array klasses, so a direct cast to InstanceKlass is safe.
2525 // Typically, these methods are called in a loop with bounds determined
2526 // by the results of JVM_GetClass{Fields,Methods}Count, which return
2527 // zero for arrays.
2528 JVM_ENTRY(void, JVM_GetMethodIxExceptionIndexes(JNIEnv *env, jclass cls, jint method_index, unsigned short *exceptions))
2529   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2530   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2531   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2532   int length = method->checked_exceptions_length();
2533   if (length > 0) {
2534     CheckedExceptionElement* table= method->checked_exceptions_start();
2535     for (int i = 0; i < length; i++) {
2536       exceptions[i] = table[i].class_cp_index;
2537     }
2538   }
2539 JVM_END
2540 
2541 
2542 JVM_ENTRY(jint, JVM_GetMethodIxExceptionsCount(JNIEnv *env, jclass cls, jint method_index))
2543   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2544   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2545   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2546   return method->checked_exceptions_length();
2547 JVM_END
2548 
2549 
2550 JVM_ENTRY(void, JVM_GetMethodIxByteCode(JNIEnv *env, jclass cls, jint method_index, unsigned char *code))
2551   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2552   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2553   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2554   memcpy(code, method->code_base(), method->code_size());
2555 JVM_END
2556 
2557 
2558 JVM_ENTRY(jint, JVM_GetMethodIxByteCodeLength(JNIEnv *env, jclass cls, jint method_index))
2559   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2560   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2561   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2562   return method->code_size();
2563 JVM_END
2564 
2565 
2566 JVM_ENTRY(void, JVM_GetMethodIxExceptionTableEntry(JNIEnv *env, jclass cls, jint method_index, jint entry_index, JVM_ExceptionTableEntryType *entry))
2567   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2568   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2569   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2570   ExceptionTable extable(method);
2571   entry->start_pc   = extable.start_pc(entry_index);
2572   entry->end_pc     = extable.end_pc(entry_index);
2573   entry->handler_pc = extable.handler_pc(entry_index);
2574   entry->catchType  = extable.catch_type_index(entry_index);
2575 JVM_END
2576 
2577 
2578 JVM_ENTRY(jint, JVM_GetMethodIxExceptionTableLength(JNIEnv *env, jclass cls, int method_index))
2579   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2580   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2581   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2582   return method->exception_table_length();
2583 JVM_END
2584 
2585 
2586 JVM_ENTRY(jint, JVM_GetMethodIxModifiers(JNIEnv *env, jclass cls, int method_index))
2587   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2588   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2589   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2590   return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
2591 JVM_END
2592 
2593 
2594 JVM_ENTRY(jint, JVM_GetFieldIxModifiers(JNIEnv *env, jclass cls, int field_index))
2595   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2596   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2597   return InstanceKlass::cast(k)->field_access_flags(field_index) & JVM_RECOGNIZED_FIELD_MODIFIERS;
2598 JVM_END
2599 
2600 
2601 JVM_ENTRY(jint, JVM_GetMethodIxLocalsCount(JNIEnv *env, jclass cls, int method_index))
2602   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2603   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2604   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2605   return method->max_locals();
2606 JVM_END
2607 
2608 
2609 JVM_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
2610   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2611   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2612   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2613   return method->size_of_parameters();
2614 JVM_END
2615 
2616 
2617 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2618   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2619   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2620   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2621   return method->verifier_max_stack();
2622 JVM_END
2623 
2624 
2625 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2626   ResourceMark rm(THREAD);
2627   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2628   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2629   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2630   return method->name() == vmSymbols::object_initializer_name();
2631 JVM_END
2632 
2633 
2634 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2635   ResourceMark rm(THREAD);
2636   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2637   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2638   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2639   return method->is_overpass();
2640 JVM_END
2641 
2642 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2643   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2644   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2645   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2646   return method->name()->as_utf8();
2647 JVM_END
2648 
2649 
2650 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
2651   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2652   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2653   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2654   return method->signature()->as_utf8();
2655 JVM_END
2656 
2657 /**
2658  * All of these JVM_GetCP-xxx methods are used by the old verifier to
2659  * read entries in the constant pool.  Since the old verifier always
2660  * works on a copy of the code, it will not see any rewriting that
2661  * may possibly occur in the middle of verification.  So it is important
2662  * that nothing it calls tries to use the cpCache instead of the raw
2663  * constant pool, so we must use cp->uncached_x methods when appropriate.
2664  */
2665 JVM_ENTRY(const char*, JVM_GetCPFieldNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2666   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2667   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2668   ConstantPool* cp = InstanceKlass::cast(k)->constants();
2669   switch (cp->tag_at(cp_index).value()) {
2670     case JVM_CONSTANT_Fieldref:
2671       return cp->uncached_name_ref_at(cp_index)->as_utf8();
2672     default:
2673       fatal("JVM_GetCPFieldNameUTF: illegal constant");
2674   }
2675   ShouldNotReachHere();
2676   return NULL;
2677 JVM_END
2678 
2679 
2680 JVM_ENTRY(const char*, JVM_GetCPMethodNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2681   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2682   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2683   ConstantPool* cp = InstanceKlass::cast(k)->constants();
2684   switch (cp->tag_at(cp_index).value()) {
2685     case JVM_CONSTANT_InterfaceMethodref:
2686     case JVM_CONSTANT_Methodref:
2687       return cp->uncached_name_ref_at(cp_index)->as_utf8();
2688     default:
2689       fatal("JVM_GetCPMethodNameUTF: illegal constant");
2690   }
2691   ShouldNotReachHere();
2692   return NULL;
2693 JVM_END
2694 
2695 
2696 JVM_ENTRY(const char*, JVM_GetCPMethodSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
2697   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2698   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2699   ConstantPool* cp = InstanceKlass::cast(k)->constants();
2700   switch (cp->tag_at(cp_index).value()) {
2701     case JVM_CONSTANT_InterfaceMethodref:
2702     case JVM_CONSTANT_Methodref:
2703       return cp->uncached_signature_ref_at(cp_index)->as_utf8();
2704     default:
2705       fatal("JVM_GetCPMethodSignatureUTF: illegal constant");
2706   }
2707   ShouldNotReachHere();
2708   return NULL;
2709 JVM_END
2710 
2711 
2712 JVM_ENTRY(const char*, JVM_GetCPFieldSignatureUTF(JNIEnv *env, jclass cls, jint cp_index))
2713   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2714   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2715   ConstantPool* cp = InstanceKlass::cast(k)->constants();
2716   switch (cp->tag_at(cp_index).value()) {
2717     case JVM_CONSTANT_Fieldref:
2718       return cp->uncached_signature_ref_at(cp_index)->as_utf8();
2719     default:
2720       fatal("JVM_GetCPFieldSignatureUTF: illegal constant");
2721   }
2722   ShouldNotReachHere();
2723   return NULL;
2724 JVM_END
2725 
2726 
2727 JVM_ENTRY(const char*, JVM_GetCPClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2728   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2729   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2730   ConstantPool* cp = InstanceKlass::cast(k)->constants();
2731   Symbol* classname = cp->klass_name_at(cp_index);
2732   return classname->as_utf8();
2733 JVM_END
2734 
2735 
2736 JVM_ENTRY(const char*, JVM_GetCPFieldClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2737   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2738   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2739   ConstantPool* cp = InstanceKlass::cast(k)->constants();
2740   switch (cp->tag_at(cp_index).value()) {
2741     case JVM_CONSTANT_Fieldref: {
2742       int class_index = cp->uncached_klass_ref_index_at(cp_index);
2743       Symbol* classname = cp->klass_name_at(class_index);
2744       return classname->as_utf8();
2745     }
2746     default:
2747       fatal("JVM_GetCPFieldClassNameUTF: illegal constant");
2748   }
2749   ShouldNotReachHere();
2750   return NULL;
2751 JVM_END
2752 
2753 
2754 JVM_ENTRY(const char*, JVM_GetCPMethodClassNameUTF(JNIEnv *env, jclass cls, jint cp_index))
2755   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2756   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2757   ConstantPool* cp = InstanceKlass::cast(k)->constants();
2758   switch (cp->tag_at(cp_index).value()) {
2759     case JVM_CONSTANT_Methodref:
2760     case JVM_CONSTANT_InterfaceMethodref: {
2761       int class_index = cp->uncached_klass_ref_index_at(cp_index);
2762       Symbol* classname = cp->klass_name_at(class_index);
2763       return classname->as_utf8();
2764     }
2765     default:
2766       fatal("JVM_GetCPMethodClassNameUTF: illegal constant");
2767   }
2768   ShouldNotReachHere();
2769   return NULL;
2770 JVM_END
2771 
2772 
2773 JVM_ENTRY(jint, JVM_GetCPFieldModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
2774   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2775   Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls));
2776   k        = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2777   k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
2778   ConstantPool* cp = InstanceKlass::cast(k)->constants();
2779   ConstantPool* cp_called = InstanceKlass::cast(k_called)->constants();
2780   switch (cp->tag_at(cp_index).value()) {
2781     case JVM_CONSTANT_Fieldref: {
2782       Symbol* name      = cp->uncached_name_ref_at(cp_index);
2783       Symbol* signature = cp->uncached_signature_ref_at(cp_index);
2784       InstanceKlass* ik = InstanceKlass::cast(k_called);
2785       for (JavaFieldStream fs(ik); !fs.done(); fs.next()) {
2786         if (fs.name() == name && fs.signature() == signature) {
2787           return fs.access_flags().as_short() & JVM_RECOGNIZED_FIELD_MODIFIERS;
2788         }
2789       }
2790       return -1;
2791     }
2792     default:
2793       fatal("JVM_GetCPFieldModifiers: illegal constant");
2794   }
2795   ShouldNotReachHere();
2796   return 0;
2797 JVM_END
2798 
2799 
2800 JVM_ENTRY(jint, JVM_GetCPMethodModifiers(JNIEnv *env, jclass cls, int cp_index, jclass called_cls))
2801   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2802   Klass* k_called = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(called_cls));
2803   k        = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2804   k_called = JvmtiThreadState::class_to_verify_considering_redefinition(k_called, thread);
2805   ConstantPool* cp = InstanceKlass::cast(k)->constants();
2806   switch (cp->tag_at(cp_index).value()) {
2807     case JVM_CONSTANT_Methodref:
2808     case JVM_CONSTANT_InterfaceMethodref: {
2809       Symbol* name      = cp->uncached_name_ref_at(cp_index);
2810       Symbol* signature = cp->uncached_signature_ref_at(cp_index);
2811       Array<Method*>* methods = InstanceKlass::cast(k_called)->methods();
2812       int methods_count = methods->length();
2813       for (int i = 0; i < methods_count; i++) {
2814         Method* method = methods->at(i);
2815         if (method->name() == name && method->signature() == signature) {
2816             return method->access_flags().as_int() & JVM_RECOGNIZED_METHOD_MODIFIERS;
2817         }
2818       }
2819       return -1;
2820     }
2821     default:
2822       fatal("JVM_GetCPMethodModifiers: illegal constant");
2823   }
2824   ShouldNotReachHere();
2825   return 0;
2826 JVM_END
2827 
2828 
2829 // Misc //////////////////////////////////////////////////////////////////////////////////////////////
2830 
2831 JVM_LEAF(void, JVM_ReleaseUTF(const char *utf))
2832   // So long as UTF8::convert_to_utf8 returns resource strings, we don't have to do anything
2833 JVM_END
2834 
2835 
2836 JVM_ENTRY(jboolean, JVM_IsSameClassPackage(JNIEnv *env, jclass class1, jclass class2))
2837   oop class1_mirror = JNIHandles::resolve_non_null(class1);
2838   oop class2_mirror = JNIHandles::resolve_non_null(class2);
2839   Klass* klass1 = java_lang_Class::as_Klass(class1_mirror);
2840   Klass* klass2 = java_lang_Class::as_Klass(class2_mirror);
2841   return (jboolean) Reflection::is_same_class_package(klass1, klass2);
2842 JVM_END
2843 
2844 // Printing support //////////////////////////////////////////////////
2845 extern "C" {
2846 
2847 ATTRIBUTE_PRINTF(3, 0)
2848 int jio_vsnprintf(char *str, size_t count, const char *fmt, va_list args) {
2849   // Reject count values that are negative signed values converted to
2850   // unsigned; see bug 4399518, 4417214
2851   if ((intptr_t)count <= 0) return -1;
2852 
2853   int result = os::vsnprintf(str, count, fmt, args);
2854   if (result > 0 && (size_t)result >= count) {
2855     result = -1;
2856   }
2857 
2858   return result;
2859 }
2860 
2861 ATTRIBUTE_PRINTF(3, 4)
2862 int jio_snprintf(char *str, size_t count, const char *fmt, ...) {
2863   va_list args;
2864   int len;
2865   va_start(args, fmt);
2866   len = jio_vsnprintf(str, count, fmt, args);
2867   va_end(args);
2868   return len;
2869 }
2870 
2871 ATTRIBUTE_PRINTF(2, 3)
2872 int jio_fprintf(FILE* f, const char *fmt, ...) {
2873   int len;
2874   va_list args;
2875   va_start(args, fmt);
2876   len = jio_vfprintf(f, fmt, args);
2877   va_end(args);
2878   return len;
2879 }
2880 
2881 ATTRIBUTE_PRINTF(2, 0)
2882 int jio_vfprintf(FILE* f, const char *fmt, va_list args) {
2883   if (Arguments::vfprintf_hook() != NULL) {
2884      return Arguments::vfprintf_hook()(f, fmt, args);
2885   } else {
2886     return vfprintf(f, fmt, args);
2887   }
2888 }
2889 
2890 ATTRIBUTE_PRINTF(1, 2)
2891 JNIEXPORT int jio_printf(const char *fmt, ...) {
2892   int len;
2893   va_list args;
2894   va_start(args, fmt);
2895   len = jio_vfprintf(defaultStream::output_stream(), fmt, args);
2896   va_end(args);
2897   return len;
2898 }
2899 
2900 // HotSpot specific jio method
2901 void jio_print(const char* s, size_t len) {
2902   // Try to make this function as atomic as possible.
2903   if (Arguments::vfprintf_hook() != NULL) {
2904     jio_fprintf(defaultStream::output_stream(), "%.*s", (int)len, s);
2905   } else {
2906     // Make an unused local variable to avoid warning from gcc compiler.
2907     ssize_t count = os::write(defaultStream::output_fd(), s, (int)len);
2908   }
2909 }
2910 
2911 } // Extern C
2912 
2913 // java.lang.Thread //////////////////////////////////////////////////////////////////////////////
2914 
2915 // In most of the JVM thread support functions we need to access the
2916 // thread through a ThreadsListHandle to prevent it from exiting and
2917 // being reclaimed while we try to operate on it. The exceptions to this
2918 // rule are when operating on the current thread, or if the monitor of
2919 // the target java.lang.Thread is locked at the Java level - in both
2920 // cases the target cannot exit.
2921 
2922 static void thread_entry(JavaThread* thread, TRAPS) {
2923   HandleMark hm(THREAD);
2924   Handle obj(THREAD, thread->threadObj());
2925   JavaValue result(T_VOID);
2926   JavaCalls::call_virtual(&result,
2927                           obj,
2928                           vmClasses::Thread_klass(),
2929                           vmSymbols::run_method_name(),
2930                           vmSymbols::void_method_signature(),
2931                           THREAD);
2932 }
2933 
2934 
2935 JVM_ENTRY(void, JVM_StartThread(JNIEnv* env, jobject jthread))
2936 #if INCLUDE_CDS
2937   if (DumpSharedSpaces) {
2938     // During java -Xshare:dump, if we allow multiple Java threads to
2939     // execute in parallel, symbols and classes may be loaded in
2940     // random orders which will make the resulting CDS archive
2941     // non-deterministic.
2942     //
2943     // Lucikly, during java -Xshare:dump, it's important to run only
2944     // the code in the main Java thread (which is NOT started here) that
2945     // creates the module graph, etc. It's safe to not start the other
2946     // threads which are launched by class static initializers
2947     // (ReferenceHandler, FinalizerThread and CleanerImpl).
2948     if (log_is_enabled(Info, cds)) {
2949       ResourceMark rm;
2950       oop t = JNIHandles::resolve_non_null(jthread);
2951       log_info(cds)("JVM_StartThread() ignored: %s", t->klass()->external_name());
2952     }
2953     return;
2954   }
2955 #endif
2956   JavaThread *native_thread = NULL;
2957 
2958   // We cannot hold the Threads_lock when we throw an exception,
2959   // due to rank ordering issues. Example:  we might need to grab the
2960   // Heap_lock while we construct the exception.
2961   bool throw_illegal_thread_state = false;
2962 
2963   // We must release the Threads_lock before we can post a jvmti event
2964   // in Thread::start.
2965   {
2966     // Ensure that the C++ Thread and OSThread structures aren't freed before
2967     // we operate.
2968     MutexLocker mu(Threads_lock);
2969 
2970     // Since JDK 5 the java.lang.Thread threadStatus is used to prevent
2971     // re-starting an already started thread, so we should usually find
2972     // that the JavaThread is null. However for a JNI attached thread
2973     // there is a small window between the Thread object being created
2974     // (with its JavaThread set) and the update to its threadStatus, so we
2975     // have to check for this
2976     if (java_lang_Thread::thread(JNIHandles::resolve_non_null(jthread)) != NULL) {
2977       throw_illegal_thread_state = true;
2978     } else {
2979       jlong size =
2980              java_lang_Thread::stackSize(JNIHandles::resolve_non_null(jthread));
2981       // Allocate the C++ Thread structure and create the native thread.  The
2982       // stack size retrieved from java is 64-bit signed, but the constructor takes
2983       // size_t (an unsigned type), which may be 32 or 64-bit depending on the platform.
2984       //  - Avoid truncating on 32-bit platforms if size is greater than UINT_MAX.
2985       //  - Avoid passing negative values which would result in really large stacks.
2986       NOT_LP64(if (size > SIZE_MAX) size = SIZE_MAX;)
2987       size_t sz = size > 0 ? (size_t) size : 0;
2988       native_thread = new JavaThread(&thread_entry, sz);
2989 
2990       // At this point it may be possible that no osthread was created for the
2991       // JavaThread due to lack of memory. Check for this situation and throw
2992       // an exception if necessary. Eventually we may want to change this so
2993       // that we only grab the lock if the thread was created successfully -
2994       // then we can also do this check and throw the exception in the
2995       // JavaThread constructor.
2996       if (native_thread->osthread() != NULL) {
2997         // Note: the current thread is not being used within "prepare".
2998         native_thread->prepare(jthread);
2999       }
3000     }
3001   }
3002 
3003   if (throw_illegal_thread_state) {
3004     THROW(vmSymbols::java_lang_IllegalThreadStateException());
3005   }
3006 
3007   assert(native_thread != NULL, "Starting null thread?");
3008 
3009   if (native_thread->osthread() == NULL) {
3010     ResourceMark rm(thread);
3011     log_warning(os, thread)("Failed to start the native thread for java.lang.Thread \"%s\"",
3012                             JavaThread::name_for(JNIHandles::resolve_non_null(jthread)));
3013     // No one should hold a reference to the 'native_thread'.
3014     native_thread->smr_delete();
3015     if (JvmtiExport::should_post_resource_exhausted()) {
3016       JvmtiExport::post_resource_exhausted(
3017         JVMTI_RESOURCE_EXHAUSTED_OOM_ERROR | JVMTI_RESOURCE_EXHAUSTED_THREADS,
3018         os::native_thread_creation_failed_msg());
3019     }
3020     THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(),
3021               os::native_thread_creation_failed_msg());
3022   }
3023 
3024   JFR_ONLY(Jfr::on_java_thread_start(thread, native_thread);)
3025 
3026   Thread::start(native_thread);
3027 
3028 JVM_END
3029 
3030 
3031 JVM_ENTRY(jboolean, JVM_IsThreadAlive(JNIEnv* env, jobject jthread))
3032   oop thread_oop = JNIHandles::resolve_non_null(jthread);
3033   return java_lang_Thread::is_alive(thread_oop);
3034 JVM_END
3035 
3036 
3037 JVM_ENTRY(void, JVM_SetThreadPriority(JNIEnv* env, jobject jthread, jint prio))
3038   ThreadsListHandle tlh(thread);
3039   oop java_thread = NULL;
3040   JavaThread* receiver = NULL;
3041   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, &java_thread);
3042   java_lang_Thread::set_priority(java_thread, (ThreadPriority)prio);
3043 
3044   if (is_alive) {
3045     // jthread refers to a live JavaThread.
3046     Thread::set_priority(receiver, (ThreadPriority)prio);
3047   }
3048   // Implied else: If the JavaThread hasn't started yet, then the
3049   // priority set in the java.lang.Thread object above will be pushed
3050   // down when it does start.
3051 JVM_END
3052 
3053 
3054 JVM_LEAF(void, JVM_Yield(JNIEnv *env, jclass threadClass))
3055   if (os::dont_yield()) return;
3056   HOTSPOT_THREAD_YIELD();
3057   os::naked_yield();
3058 JVM_END
3059 
3060 JVM_ENTRY(void, JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis))
3061   if (millis < 0) {
3062     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "timeout value is negative");
3063   }
3064 
3065   if (thread->is_interrupted(true) && !HAS_PENDING_EXCEPTION) {
3066     THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3067   }
3068 
3069   // Save current thread state and restore it at the end of this block.
3070   // And set new thread state to SLEEPING.
3071   JavaThreadSleepState jtss(thread);
3072 
3073   HOTSPOT_THREAD_SLEEP_BEGIN(millis);
3074 
3075   if (millis == 0) {
3076     os::naked_yield();
3077   } else {
3078     ThreadState old_state = thread->osthread()->get_state();
3079     thread->osthread()->set_state(SLEEPING);
3080     if (!thread->sleep(millis)) { // interrupted
3081       // An asynchronous exception could have been thrown on
3082       // us while we were sleeping. We do not overwrite those.
3083       if (!HAS_PENDING_EXCEPTION) {
3084         HOTSPOT_THREAD_SLEEP_END(1);
3085 
3086         // TODO-FIXME: THROW_MSG returns which means we will not call set_state()
3087         // to properly restore the thread state.  That's likely wrong.
3088         THROW_MSG(vmSymbols::java_lang_InterruptedException(), "sleep interrupted");
3089       }
3090     }
3091     thread->osthread()->set_state(old_state);
3092   }
3093   HOTSPOT_THREAD_SLEEP_END(0);
3094 JVM_END
3095 
3096 JVM_ENTRY(jobject, JVM_CurrentCarrierThread(JNIEnv* env, jclass threadClass))
3097   oop jthread = thread->threadObj();
3098   assert(jthread != NULL, "no current carrier thread!");
3099   return JNIHandles::make_local(THREAD, jthread);
3100 JVM_END
3101 
3102 JVM_ENTRY(jobject, JVM_CurrentThread(JNIEnv* env, jclass threadClass))
3103   oop theThread = thread->vthread();
3104   assert(theThread != (oop)NULL, "no current thread!");
3105   return JNIHandles::make_local(THREAD, theThread);
3106 JVM_END
3107 
3108 JVM_ENTRY(void, JVM_SetCurrentThread(JNIEnv* env, jobject thisThread,
3109                                      jobject theThread))
3110   oop threadObj = JNIHandles::resolve(theThread);
3111   thread->set_vthread(threadObj);
3112   JFR_ONLY(Jfr::on_set_current_thread(thread, threadObj);)
3113 JVM_END
3114 
3115 JVM_ENTRY(jlong, JVM_GetNextThreadIdOffset(JNIEnv* env, jclass threadClass))
3116   return ThreadIdentifier::unsafe_offset();
3117 JVM_END
3118 
3119 JVM_ENTRY(void, JVM_Interrupt(JNIEnv* env, jobject jthread))
3120   ThreadsListHandle tlh(thread);
3121   JavaThread* receiver = NULL;
3122   bool is_alive = tlh.cv_internal_thread_to_JavaThread(jthread, &receiver, NULL);
3123   if (is_alive) {
3124     // jthread refers to a live JavaThread.
3125     receiver->interrupt();
3126   }
3127 JVM_END
3128 
3129 // Return true iff the current thread has locked the object passed in
3130 
3131 JVM_ENTRY(jboolean, JVM_HoldsLock(JNIEnv* env, jclass threadClass, jobject obj))
3132   if (obj == NULL) {
3133     THROW_(vmSymbols::java_lang_NullPointerException(), JNI_FALSE);
3134   }
3135   Handle h_obj(THREAD, JNIHandles::resolve(obj));
3136   return ObjectSynchronizer::current_thread_holds_lock(thread, h_obj);
3137 JVM_END
3138 
3139 JVM_ENTRY(jobject, JVM_GetStackTrace(JNIEnv *env, jobject jthread))
3140   oop trace = java_lang_Thread::async_get_stack_trace(JNIHandles::resolve(jthread), THREAD);
3141   return JNIHandles::make_local(THREAD, trace);
3142 JVM_END
3143 
3144 JVM_ENTRY(void, JVM_DumpAllStacks(JNIEnv* env, jclass))
3145   VM_PrintThreads op;
3146   VMThread::execute(&op);
3147   if (JvmtiExport::should_post_data_dump()) {
3148     JvmtiExport::post_data_dump();
3149   }
3150 JVM_END
3151 
3152 JVM_ENTRY(void, JVM_SetNativeThreadName(JNIEnv* env, jobject jthread, jstring name))
3153   // We don't use a ThreadsListHandle here because the current thread
3154   // must be alive.
3155   oop java_thread = JNIHandles::resolve_non_null(jthread);
3156   JavaThread* thr = java_lang_Thread::thread(java_thread);
3157   if (thread == thr && !thr->has_attached_via_jni()) {
3158     // Thread naming is only supported for the current thread and
3159     // we don't set the name of an attached thread to avoid stepping
3160     // on other programs.
3161     ResourceMark rm(thread);
3162     const char *thread_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
3163     os::set_native_thread_name(thread_name);
3164   }
3165 JVM_END
3166 
3167 JVM_ENTRY(jobject, JVM_ScopedValueCache(JNIEnv* env, jclass threadClass))
3168   oop theCache = thread->scopedValueCache();
3169   return JNIHandles::make_local(THREAD, theCache);
3170 JVM_END
3171 
3172 JVM_ENTRY(void, JVM_SetScopedValueCache(JNIEnv* env, jclass threadClass,
3173                                        jobject theCache))
3174   arrayOop objs = arrayOop(JNIHandles::resolve(theCache));
3175   thread->set_scopedValueCache(objs);
3176 JVM_END
3177 
3178 // java.lang.SecurityManager ///////////////////////////////////////////////////////////////////////
3179 
3180 JVM_ENTRY(jobjectArray, JVM_GetClassContext(JNIEnv *env))
3181   ResourceMark rm(THREAD);
3182   JvmtiVMObjectAllocEventCollector oam;
3183   vframeStream vfst(thread);
3184 
3185   if (vmClasses::reflect_CallerSensitive_klass() != NULL) {
3186     // This must only be called from SecurityManager.getClassContext
3187     Method* m = vfst.method();
3188     if (!(m->method_holder() == vmClasses::SecurityManager_klass() &&
3189           m->name()          == vmSymbols::getClassContext_name() &&
3190           m->signature()     == vmSymbols::void_class_array_signature())) {
3191       THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVM_GetClassContext must only be called from SecurityManager.getClassContext");
3192     }
3193   }
3194 
3195   // Collect method holders
3196   GrowableArray<Klass*>* klass_array = new GrowableArray<Klass*>();
3197   for (; !vfst.at_end(); vfst.security_next()) {
3198     Method* m = vfst.method();
3199     // Native frames are not returned
3200     if (!m->is_ignored_by_security_stack_walk() && !m->is_native()) {
3201       Klass* holder = m->method_holder();
3202       assert(holder->is_klass(), "just checking");
3203       klass_array->append(holder);
3204     }
3205   }
3206 
3207   // Create result array of type [Ljava/lang/Class;
3208   objArrayOop result = oopFactory::new_objArray(vmClasses::Class_klass(), klass_array->length(), CHECK_NULL);
3209   // Fill in mirrors corresponding to method holders
3210   for (int i = 0; i < klass_array->length(); i++) {
3211     result->obj_at_put(i, klass_array->at(i)->java_mirror());
3212   }
3213 
3214   return (jobjectArray) JNIHandles::make_local(THREAD, result);
3215 JVM_END
3216 
3217 
3218 // java.lang.Package ////////////////////////////////////////////////////////////////
3219 
3220 
3221 JVM_ENTRY(jstring, JVM_GetSystemPackage(JNIEnv *env, jstring name))
3222   ResourceMark rm(THREAD);
3223   JvmtiVMObjectAllocEventCollector oam;
3224   char* str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
3225   oop result = ClassLoader::get_system_package(str, CHECK_NULL);
3226 return (jstring) JNIHandles::make_local(THREAD, result);
3227 JVM_END
3228 
3229 
3230 JVM_ENTRY(jobjectArray, JVM_GetSystemPackages(JNIEnv *env))
3231   JvmtiVMObjectAllocEventCollector oam;
3232   objArrayOop result = ClassLoader::get_system_packages(CHECK_NULL);
3233   return (jobjectArray) JNIHandles::make_local(THREAD, result);
3234 JVM_END
3235 
3236 
3237 // java.lang.ref.Reference ///////////////////////////////////////////////////////////////
3238 
3239 
3240 JVM_ENTRY(jobject, JVM_GetAndClearReferencePendingList(JNIEnv* env))
3241   MonitorLocker ml(Heap_lock);
3242   oop ref = Universe::reference_pending_list();
3243   if (ref != NULL) {
3244     Universe::clear_reference_pending_list();
3245   }
3246   return JNIHandles::make_local(THREAD, ref);
3247 JVM_END
3248 
3249 JVM_ENTRY(jboolean, JVM_HasReferencePendingList(JNIEnv* env))
3250   MonitorLocker ml(Heap_lock);
3251   return Universe::has_reference_pending_list();
3252 JVM_END
3253 
3254 JVM_ENTRY(void, JVM_WaitForReferencePendingList(JNIEnv* env))
3255   MonitorLocker ml(Heap_lock);
3256   while (!Universe::has_reference_pending_list()) {
3257     ml.wait();
3258   }
3259 JVM_END
3260 
3261 JVM_ENTRY(jboolean, JVM_ReferenceRefersTo(JNIEnv* env, jobject ref, jobject o))
3262   oop ref_oop = JNIHandles::resolve_non_null(ref);
3263   // PhantomReference has it's own implementation of refersTo().
3264   // See: JVM_PhantomReferenceRefersTo
3265   assert(!java_lang_ref_Reference::is_phantom(ref_oop), "precondition");
3266   oop referent = java_lang_ref_Reference::weak_referent_no_keepalive(ref_oop);
3267   return referent == JNIHandles::resolve(o);
3268 JVM_END
3269 
3270 JVM_ENTRY(void, JVM_ReferenceClear(JNIEnv* env, jobject ref))
3271   oop ref_oop = JNIHandles::resolve_non_null(ref);
3272   // FinalReference has it's own implementation of clear().
3273   assert(!java_lang_ref_Reference::is_final(ref_oop), "precondition");
3274   if (java_lang_ref_Reference::unknown_referent_no_keepalive(ref_oop) == NULL) {
3275     // If the referent has already been cleared then done.
3276     // However, if the referent is dead but has not yet been cleared by
3277     // concurrent reference processing, it should NOT be cleared here.
3278     // Instead, clearing should be left to the GC.  Clearing it here could
3279     // detectably lose an expected notification, which is impossible with
3280     // STW reference processing.  The clearing in enqueue() doesn't have
3281     // this problem, since the enqueue covers the notification, but it's not
3282     // worth the effort to handle that case specially.
3283     return;
3284   }
3285   java_lang_ref_Reference::clear_referent(ref_oop);
3286 JVM_END
3287 
3288 
3289 // java.lang.ref.PhantomReference //////////////////////////////////////////////////
3290 
3291 
3292 JVM_ENTRY(jboolean, JVM_PhantomReferenceRefersTo(JNIEnv* env, jobject ref, jobject o))
3293   oop ref_oop = JNIHandles::resolve_non_null(ref);
3294   oop referent = java_lang_ref_Reference::phantom_referent_no_keepalive(ref_oop);
3295   return referent == JNIHandles::resolve(o);
3296 JVM_END
3297 
3298 
3299 // ObjectInputStream ///////////////////////////////////////////////////////////////
3300 
3301 // Return the first user-defined class loader up the execution stack, or null
3302 // if only code from the bootstrap or platform class loader is on the stack.
3303 
3304 JVM_ENTRY(jobject, JVM_LatestUserDefinedLoader(JNIEnv *env))
3305   for (vframeStream vfst(thread); !vfst.at_end(); vfst.next()) {
3306     InstanceKlass* ik = vfst.method()->method_holder();
3307     oop loader = ik->class_loader();
3308     if (loader != NULL && !SystemDictionary::is_platform_class_loader(loader)) {
3309       // Skip reflection related frames
3310       if (!ik->is_subclass_of(vmClasses::reflect_MethodAccessorImpl_klass()) &&
3311           !ik->is_subclass_of(vmClasses::reflect_ConstructorAccessorImpl_klass())) {
3312         return JNIHandles::make_local(THREAD, loader);
3313       }
3314     }
3315   }
3316   return NULL;
3317 JVM_END
3318 
3319 
3320 // Array ///////////////////////////////////////////////////////////////////////////////////////////
3321 
3322 
3323 // resolve array handle and check arguments
3324 static inline arrayOop check_array(JNIEnv *env, jobject arr, bool type_array_only, TRAPS) {
3325   if (arr == NULL) {
3326     THROW_0(vmSymbols::java_lang_NullPointerException());
3327   }
3328   oop a = JNIHandles::resolve_non_null(arr);
3329   if (!a->is_array()) {
3330     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array");
3331   } else if (type_array_only && !a->is_typeArray()) {
3332     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Argument is not an array of primitive type");
3333   }
3334   return arrayOop(a);
3335 }
3336 
3337 
3338 JVM_ENTRY(jint, JVM_GetArrayLength(JNIEnv *env, jobject arr))
3339   arrayOop a = check_array(env, arr, false, CHECK_0);
3340   return a->length();
3341 JVM_END
3342 
3343 
3344 JVM_ENTRY(jobject, JVM_GetArrayElement(JNIEnv *env, jobject arr, jint index))
3345   JvmtiVMObjectAllocEventCollector oam;
3346   arrayOop a = check_array(env, arr, false, CHECK_NULL);
3347   jvalue value;
3348   BasicType type = Reflection::array_get(&value, a, index, CHECK_NULL);
3349   oop box = Reflection::box(&value, type, CHECK_NULL);
3350   return JNIHandles::make_local(THREAD, box);
3351 JVM_END
3352 
3353 
3354 JVM_ENTRY(jvalue, JVM_GetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jint wCode))
3355   jvalue value;
3356   value.i = 0; // to initialize value before getting used in CHECK
3357   arrayOop a = check_array(env, arr, true, CHECK_(value));
3358   assert(a->is_typeArray(), "just checking");
3359   BasicType type = Reflection::array_get(&value, a, index, CHECK_(value));
3360   BasicType wide_type = (BasicType) wCode;
3361   if (type != wide_type) {
3362     Reflection::widen(&value, type, wide_type, CHECK_(value));
3363   }
3364   return value;
3365 JVM_END
3366 
3367 
3368 JVM_ENTRY(void, JVM_SetArrayElement(JNIEnv *env, jobject arr, jint index, jobject val))
3369   arrayOop a = check_array(env, arr, false, CHECK);
3370   oop box = JNIHandles::resolve(val);
3371   jvalue value;
3372   value.i = 0; // to initialize value before getting used in CHECK
3373   BasicType value_type;
3374   if (a->is_objArray()) {
3375     // Make sure we do no unbox e.g. java/lang/Integer instances when storing into an object array
3376     value_type = Reflection::unbox_for_regular_object(box, &value);
3377   } else {
3378     value_type = Reflection::unbox_for_primitive(box, &value, CHECK);
3379   }
3380   Reflection::array_set(&value, a, index, value_type, CHECK);
3381 JVM_END
3382 
3383 
3384 JVM_ENTRY(void, JVM_SetPrimitiveArrayElement(JNIEnv *env, jobject arr, jint index, jvalue v, unsigned char vCode))
3385   arrayOop a = check_array(env, arr, true, CHECK);
3386   assert(a->is_typeArray(), "just checking");
3387   BasicType value_type = (BasicType) vCode;
3388   Reflection::array_set(&v, a, index, value_type, CHECK);
3389 JVM_END
3390 
3391 
3392 JVM_ENTRY(jobject, JVM_NewArray(JNIEnv *env, jclass eltClass, jint length))
3393   JvmtiVMObjectAllocEventCollector oam;
3394   oop element_mirror = JNIHandles::resolve(eltClass);
3395   oop result = Reflection::reflect_new_array(element_mirror, length, CHECK_NULL);
3396   return JNIHandles::make_local(THREAD, result);
3397 JVM_END
3398 
3399 
3400 JVM_ENTRY(jobject, JVM_NewMultiArray(JNIEnv *env, jclass eltClass, jintArray dim))
3401   JvmtiVMObjectAllocEventCollector oam;
3402   arrayOop dim_array = check_array(env, dim, true, CHECK_NULL);
3403   oop element_mirror = JNIHandles::resolve(eltClass);
3404   assert(dim_array->is_typeArray(), "just checking");
3405   oop result = Reflection::reflect_new_multi_array(element_mirror, typeArrayOop(dim_array), CHECK_NULL);
3406   return JNIHandles::make_local(THREAD, result);
3407 JVM_END
3408 
3409 
3410 // Library support ///////////////////////////////////////////////////////////////////////////
3411 
3412 JVM_LEAF(void*, JVM_LoadZipLibrary())
3413   ClassLoader::load_zip_library_if_needed();
3414   return ClassLoader::zip_library_handle();
3415 JVM_END
3416 
3417 JVM_ENTRY_NO_ENV(void*, JVM_LoadLibrary(const char* name, jboolean throwException))
3418   //%note jvm_ct
3419   char ebuf[1024];
3420   void *load_result;
3421   {
3422     ThreadToNativeFromVM ttnfvm(thread);
3423     load_result = os::dll_load(name, ebuf, sizeof ebuf);
3424   }
3425   if (load_result == NULL) {
3426     if (throwException) {
3427       char msg[1024];
3428       jio_snprintf(msg, sizeof msg, "%s: %s", name, ebuf);
3429       // Since 'ebuf' may contain a string encoded using
3430       // platform encoding scheme, we need to pass
3431       // Exceptions::unsafe_to_utf8 to the new_exception method
3432       // as the last argument. See bug 6367357.
3433       Handle h_exception =
3434         Exceptions::new_exception(thread,
3435                                   vmSymbols::java_lang_UnsatisfiedLinkError(),
3436                                   msg, Exceptions::unsafe_to_utf8);
3437 
3438       THROW_HANDLE_0(h_exception);
3439     } else {
3440       log_info(library)("Failed to load library %s", name);
3441       return load_result;
3442     }
3443   }
3444   log_info(library)("Loaded library %s, handle " INTPTR_FORMAT, name, p2i(load_result));
3445   return load_result;
3446 JVM_END
3447 
3448 
3449 JVM_LEAF(void, JVM_UnloadLibrary(void* handle))
3450   os::dll_unload(handle);
3451   log_info(library)("Unloaded library with handle " INTPTR_FORMAT, p2i(handle));
3452 JVM_END
3453 
3454 
3455 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3456   void* find_result = os::dll_lookup(handle, name);
3457   log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3458                     find_result != NULL ? "Found" : "Failed to find",
3459                     name, p2i(handle));
3460   return find_result;
3461 JVM_END
3462 
3463 
3464 // JNI version ///////////////////////////////////////////////////////////////////////////////
3465 
3466 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3467   return Threads::is_supported_jni_version_including_1_1(version);
3468 JVM_END
3469 
3470 
3471 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3472   return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3473 JVM_END
3474 
3475 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3476   return VMContinuations ? JNI_TRUE : JNI_FALSE;
3477 JVM_END
3478 
3479 // String support ///////////////////////////////////////////////////////////////////////////
3480 
3481 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3482   JvmtiVMObjectAllocEventCollector oam;
3483   if (str == NULL) return NULL;
3484   oop string = JNIHandles::resolve_non_null(str);
3485   oop result = StringTable::intern(string, CHECK_NULL);
3486   return (jstring) JNIHandles::make_local(THREAD, result);
3487 JVM_END
3488 
3489 
3490 // VM Raw monitor support //////////////////////////////////////////////////////////////////////
3491 
3492 // VM Raw monitors (not to be confused with JvmtiRawMonitors) are a simple mutual exclusion
3493 // lock (not actually monitors: no wait/notify) that is exported by the VM for use by JDK
3494 // library code. They may be used by JavaThreads and non-JavaThreads and do not participate
3495 // in the safepoint protocol, thread suspension, thread interruption, or anything of that
3496 // nature. JavaThreads will be "in native" when using this API from JDK code.
3497 
3498 
3499 JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
3500   VM_Exit::block_if_vm_exited();
3501   return new PlatformMutex();
3502 }
3503 
3504 
3505 JNIEXPORT void JNICALL  JVM_RawMonitorDestroy(void *mon) {
3506   VM_Exit::block_if_vm_exited();
3507   delete ((PlatformMutex*) mon);
3508 }
3509 
3510 
3511 JNIEXPORT jint JNICALL JVM_RawMonitorEnter(void *mon) {
3512   VM_Exit::block_if_vm_exited();
3513   ((PlatformMutex*) mon)->lock();
3514   return 0;
3515 }
3516 
3517 
3518 JNIEXPORT void JNICALL JVM_RawMonitorExit(void *mon) {
3519   VM_Exit::block_if_vm_exited();
3520   ((PlatformMutex*) mon)->unlock();
3521 }
3522 
3523 
3524 // Shared JNI/JVM entry points //////////////////////////////////////////////////////////////
3525 
3526 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3527                                     Handle loader, Handle protection_domain,
3528                                     jboolean throwError, TRAPS) {
3529   // Security Note:
3530   //   The Java level wrapper will perform the necessary security check allowing
3531   //   us to pass the NULL as the initiating class loader.  The VM is responsible for
3532   //   the checkPackageAccess relative to the initiating class loader via the
3533   //   protection_domain. The protection_domain is passed as NULL by the java code
3534   //   if there is no security manager in 3-arg Class.forName().
3535   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3536 
3537   // Check if we should initialize the class
3538   if (init && klass->is_instance_klass()) {
3539     klass->initialize(CHECK_NULL);
3540   }
3541   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3542 }
3543 
3544 
3545 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3546 
3547 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3548   Handle method_handle;
3549   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3550     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3551     Handle receiver(THREAD, JNIHandles::resolve(obj));
3552     objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3553     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3554     jobject res = JNIHandles::make_local(THREAD, result);
3555     if (JvmtiExport::should_post_vm_object_alloc()) {
3556       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3557       assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
3558       if (java_lang_Class::is_primitive(ret_type)) {
3559         // Only for primitive type vm allocates memory for java object.
3560         // See box() method.
3561         JvmtiExport::post_vm_object_alloc(thread, result);
3562       }
3563     }
3564     return res;
3565   } else {
3566     THROW_0(vmSymbols::java_lang_StackOverflowError());
3567   }
3568 JVM_END
3569 
3570 
3571 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3572   oop constructor_mirror = JNIHandles::resolve(c);
3573   objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3574   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3575   jobject res = JNIHandles::make_local(THREAD, result);
3576   if (JvmtiExport::should_post_vm_object_alloc()) {
3577     JvmtiExport::post_vm_object_alloc(thread, result);
3578   }
3579   return res;
3580 JVM_END
3581 
3582 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3583 
3584 JVM_LEAF(jboolean, JVM_SupportsCX8())
3585   return VM_Version::supports_cx8();
3586 JVM_END
3587 
3588 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3589   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3590   assert(k->is_klass(), "just checking");
3591   HeapShared::initialize_from_archived_subgraph(THREAD, k);
3592 JVM_END
3593 
3594 JVM_ENTRY(void, JVM_RegisterLambdaProxyClassForArchiving(JNIEnv* env,
3595                                               jclass caller,
3596                                               jstring interfaceMethodName,
3597                                               jobject factoryType,
3598                                               jobject interfaceMethodType,
3599                                               jobject implementationMember,
3600                                               jobject dynamicMethodType,
3601                                               jclass lambdaProxyClass))
3602 #if INCLUDE_CDS
3603   if (!Arguments::is_dumping_archive()) {
3604     return;
3605   }
3606 
3607   Klass* caller_k = java_lang_Class::as_Klass(JNIHandles::resolve(caller));
3608   InstanceKlass* caller_ik = InstanceKlass::cast(caller_k);
3609   if (caller_ik->is_hidden()) {
3610     // Hidden classes not of type lambda proxy classes are currently not being archived.
3611     // If the caller_ik is of one of the above types, the corresponding lambda proxy class won't be
3612     // registered for archiving.
3613     return;
3614   }
3615   Klass* lambda_k = java_lang_Class::as_Klass(JNIHandles::resolve(lambdaProxyClass));
3616   InstanceKlass* lambda_ik = InstanceKlass::cast(lambda_k);
3617   assert(lambda_ik->is_hidden(), "must be a hidden class");
3618   assert(!lambda_ik->is_non_strong_hidden(), "expected a strong hidden class");
3619 
3620   Symbol* interface_method_name = NULL;
3621   if (interfaceMethodName != NULL) {
3622     interface_method_name = java_lang_String::as_symbol(JNIHandles::resolve_non_null(interfaceMethodName));
3623   }
3624   Handle factory_type_oop(THREAD, JNIHandles::resolve_non_null(factoryType));
3625   Symbol* factory_type = java_lang_invoke_MethodType::as_signature(factory_type_oop(), true);
3626 
3627   Handle interface_method_type_oop(THREAD, JNIHandles::resolve_non_null(interfaceMethodType));
3628   Symbol* interface_method_type = java_lang_invoke_MethodType::as_signature(interface_method_type_oop(), true);
3629 
3630   Handle implementation_member_oop(THREAD, JNIHandles::resolve_non_null(implementationMember));
3631   assert(java_lang_invoke_MemberName::is_method(implementation_member_oop()), "must be");
3632   Method* m = java_lang_invoke_MemberName::vmtarget(implementation_member_oop());
3633 
3634   Handle dynamic_method_type_oop(THREAD, JNIHandles::resolve_non_null(dynamicMethodType));
3635   Symbol* dynamic_method_type = java_lang_invoke_MethodType::as_signature(dynamic_method_type_oop(), true);
3636 
3637   SystemDictionaryShared::add_lambda_proxy_class(caller_ik, lambda_ik, interface_method_name, factory_type,
3638                                                  interface_method_type, m, dynamic_method_type, THREAD);
3639 #endif // INCLUDE_CDS
3640 JVM_END
3641 
3642 JVM_ENTRY(jclass, JVM_LookupLambdaProxyClassFromArchive(JNIEnv* env,
3643                                                         jclass caller,
3644                                                         jstring interfaceMethodName,
3645                                                         jobject factoryType,
3646                                                         jobject interfaceMethodType,
3647                                                         jobject implementationMember,
3648                                                         jobject dynamicMethodType))
3649 #if INCLUDE_CDS
3650 
3651   if (interfaceMethodName == NULL || factoryType == NULL || interfaceMethodType == NULL ||
3652       implementationMember == NULL || dynamicMethodType == NULL) {
3653     THROW_(vmSymbols::java_lang_NullPointerException(), NULL);
3654   }
3655 
3656   Klass* caller_k = java_lang_Class::as_Klass(JNIHandles::resolve(caller));
3657   InstanceKlass* caller_ik = InstanceKlass::cast(caller_k);
3658   if (!caller_ik->is_shared()) {
3659     // there won't be a shared lambda class if the caller_ik is not in the shared archive.
3660     return NULL;
3661   }
3662 
3663   Symbol* interface_method_name = java_lang_String::as_symbol(JNIHandles::resolve_non_null(interfaceMethodName));
3664   Handle factory_type_oop(THREAD, JNIHandles::resolve_non_null(factoryType));
3665   Symbol* factory_type = java_lang_invoke_MethodType::as_signature(factory_type_oop(), true);
3666 
3667   Handle interface_method_type_oop(THREAD, JNIHandles::resolve_non_null(interfaceMethodType));
3668   Symbol* interface_method_type = java_lang_invoke_MethodType::as_signature(interface_method_type_oop(), true);
3669 
3670   Handle implementation_member_oop(THREAD, JNIHandles::resolve_non_null(implementationMember));
3671   assert(java_lang_invoke_MemberName::is_method(implementation_member_oop()), "must be");
3672   Method* m = java_lang_invoke_MemberName::vmtarget(implementation_member_oop());
3673 
3674   Handle dynamic_method_type_oop(THREAD, JNIHandles::resolve_non_null(dynamicMethodType));
3675   Symbol* dynamic_method_type = java_lang_invoke_MethodType::as_signature(dynamic_method_type_oop(), true);
3676 
3677   InstanceKlass* lambda_ik = SystemDictionaryShared::get_shared_lambda_proxy_class(caller_ik, interface_method_name, factory_type,
3678                                                                                    interface_method_type, m, dynamic_method_type);
3679   jclass jcls = NULL;
3680   if (lambda_ik != NULL) {
3681     InstanceKlass* loaded_lambda = SystemDictionaryShared::prepare_shared_lambda_proxy_class(lambda_ik, caller_ik, THREAD);
3682     jcls = loaded_lambda == NULL ? NULL : (jclass) JNIHandles::make_local(THREAD, loaded_lambda->java_mirror());
3683   }
3684   return jcls;
3685 #else
3686   return NULL;
3687 #endif // INCLUDE_CDS
3688 JVM_END
3689 
3690 JVM_LEAF(jboolean, JVM_IsCDSDumpingEnabled(JNIEnv* env))
3691   return Arguments::is_dumping_archive();
3692 JVM_END
3693 
3694 JVM_LEAF(jboolean, JVM_IsSharingEnabled(JNIEnv* env))
3695   return UseSharedSpaces;
3696 JVM_END
3697 
3698 JVM_ENTRY_NO_ENV(jlong, JVM_GetRandomSeedForDumping())
3699   if (DumpSharedSpaces) {
3700     const char* release = VM_Version::vm_release();
3701     const char* dbg_level = VM_Version::jdk_debug_level();
3702     const char* version = VM_Version::internal_vm_info_string();
3703     jlong seed = (jlong)(java_lang_String::hash_code((const jbyte*)release, (int)strlen(release)) ^
3704                          java_lang_String::hash_code((const jbyte*)dbg_level, (int)strlen(dbg_level)) ^
3705                          java_lang_String::hash_code((const jbyte*)version, (int)strlen(version)));
3706     seed += (jlong)VM_Version::vm_major_version();
3707     seed += (jlong)VM_Version::vm_minor_version();
3708     seed += (jlong)VM_Version::vm_security_version();
3709     seed += (jlong)VM_Version::vm_patch_version();
3710     if (seed == 0) { // don't let this ever be zero.
3711       seed = 0x87654321;
3712     }
3713     log_debug(cds)("JVM_GetRandomSeedForDumping() = " JLONG_FORMAT, seed);
3714     return seed;
3715   } else {
3716     return 0;
3717   }
3718 JVM_END
3719 
3720 JVM_LEAF(jboolean, JVM_IsDumpingClassList(JNIEnv *env))
3721 #if INCLUDE_CDS
3722   return ClassListWriter::is_enabled() || DynamicDumpSharedSpaces;
3723 #else
3724   return false;
3725 #endif // INCLUDE_CDS
3726 JVM_END
3727 
3728 JVM_ENTRY(void, JVM_LogLambdaFormInvoker(JNIEnv *env, jstring line))
3729 #if INCLUDE_CDS
3730   assert(ClassListWriter::is_enabled() || DynamicDumpSharedSpaces,  "Should be set and open or do dynamic dump");
3731   if (line != NULL) {
3732     ResourceMark rm(THREAD);
3733     Handle h_line (THREAD, JNIHandles::resolve_non_null(line));
3734     char* c_line = java_lang_String::as_utf8_string(h_line());
3735     if (DynamicDumpSharedSpaces) {
3736       // Note: LambdaFormInvokers::append take same format which is not
3737       // same as below the print format. The line does not include LAMBDA_FORM_TAG.
3738       LambdaFormInvokers::append(os::strdup((const char*)c_line, mtInternal));
3739     }
3740     if (ClassListWriter::is_enabled()) {
3741       ClassListWriter w;
3742       w.stream()->print_cr("%s %s", LAMBDA_FORM_TAG, c_line);
3743     }
3744   }
3745 #endif // INCLUDE_CDS
3746 JVM_END
3747 
3748 JVM_ENTRY(void, JVM_DumpClassListToFile(JNIEnv *env, jstring listFileName))
3749 #if INCLUDE_CDS
3750   ResourceMark rm(THREAD);
3751   Handle file_handle(THREAD, JNIHandles::resolve_non_null(listFileName));
3752   char* file_name  = java_lang_String::as_utf8_string(file_handle());
3753   MetaspaceShared::dump_loaded_classes(file_name, THREAD);
3754 #endif // INCLUDE_CDS
3755 JVM_END
3756 
3757 JVM_ENTRY(void, JVM_DumpDynamicArchive(JNIEnv *env, jstring archiveName))
3758 #if INCLUDE_CDS
3759   ResourceMark rm(THREAD);
3760   Handle file_handle(THREAD, JNIHandles::resolve_non_null(archiveName));
3761   char* archive_name  = java_lang_String::as_utf8_string(file_handle());
3762   DynamicArchive::dump_for_jcmd(archive_name, CHECK);
3763 #endif // INCLUDE_CDS
3764 JVM_END
3765 
3766 // Returns an array of all live Thread objects (VM internal JavaThreads,
3767 // jvmti agent threads, and JNI attaching threads  are skipped)
3768 // See CR 6404306 regarding JNI attaching threads
3769 JVM_ENTRY(jobjectArray, JVM_GetAllThreads(JNIEnv *env, jclass dummy))
3770   ResourceMark rm(THREAD);
3771   ThreadsListEnumerator tle(THREAD, false, false);
3772   JvmtiVMObjectAllocEventCollector oam;
3773 
3774   int num_threads = tle.num_threads();
3775   objArrayOop r = oopFactory::new_objArray(vmClasses::Thread_klass(), num_threads, CHECK_NULL);
3776   objArrayHandle threads_ah(THREAD, r);
3777 
3778   for (int i = 0; i < num_threads; i++) {
3779     Handle h = tle.get_threadObj(i);
3780     threads_ah->obj_at_put(i, h());
3781   }
3782 
3783   return (jobjectArray) JNIHandles::make_local(THREAD, threads_ah());
3784 JVM_END
3785 
3786 
3787 // Support for java.lang.Thread.getStackTrace() and getAllStackTraces() methods
3788 // Return StackTraceElement[][], each element is the stack trace of a thread in
3789 // the corresponding entry in the given threads array
3790 JVM_ENTRY(jobjectArray, JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads))
3791   JvmtiVMObjectAllocEventCollector oam;
3792 
3793   // Check if threads is null
3794   if (threads == NULL) {
3795     THROW_(vmSymbols::java_lang_NullPointerException(), 0);
3796   }
3797 
3798   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads));
3799   objArrayHandle ah(THREAD, a);
3800   int num_threads = ah->length();
3801   // check if threads is non-empty array
3802   if (num_threads == 0) {
3803     THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0);
3804   }
3805 
3806   // check if threads is not an array of objects of Thread class
3807   Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass();
3808   if (k != vmClasses::Thread_klass()) {
3809     THROW_(vmSymbols::java_lang_IllegalArgumentException(), 0);
3810   }
3811 
3812   ResourceMark rm(THREAD);
3813 
3814   GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
3815   for (int i = 0; i < num_threads; i++) {
3816     oop thread_obj = ah->obj_at(i);
3817     instanceHandle h(THREAD, (instanceOop) thread_obj);
3818     thread_handle_array->append(h);
3819   }
3820 
3821   // The JavaThread references in thread_handle_array are validated
3822   // in VM_ThreadDump::doit().
3823   Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL);
3824   return (jobjectArray)JNIHandles::make_local(THREAD, stacktraces());
3825 
3826 JVM_END
3827 
3828 // JVM monitoring and management support
3829 JVM_LEAF(void*, JVM_GetManagement(jint version))
3830   return Management::get_jmm_interface(version);
3831 JVM_END
3832 
3833 // com.sun.tools.attach.VirtualMachine agent properties support
3834 //
3835 // Initialize the agent properties with the properties maintained in the VM
3836 JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties))
3837   ResourceMark rm;
3838 
3839   Handle props(THREAD, JNIHandles::resolve_non_null(properties));
3840 
3841   PUTPROP(props, "sun.java.command", Arguments::java_command());
3842   PUTPROP(props, "sun.jvm.flags", Arguments::jvm_flags());
3843   PUTPROP(props, "sun.jvm.args", Arguments::jvm_args());
3844   return properties;
3845 JVM_END
3846 
3847 JVM_ENTRY(jobjectArray, JVM_GetEnclosingMethodInfo(JNIEnv *env, jclass ofClass))
3848 {
3849   JvmtiVMObjectAllocEventCollector oam;
3850 
3851   if (ofClass == NULL) {
3852     return NULL;
3853   }
3854   Handle mirror(THREAD, JNIHandles::resolve_non_null(ofClass));
3855   // Special handling for primitive objects
3856   if (java_lang_Class::is_primitive(mirror())) {
3857     return NULL;
3858   }
3859   Klass* k = java_lang_Class::as_Klass(mirror());
3860   if (!k->is_instance_klass()) {
3861     return NULL;
3862   }
3863   InstanceKlass* ik = InstanceKlass::cast(k);
3864   int encl_method_class_idx = ik->enclosing_method_class_index();
3865   if (encl_method_class_idx == 0) {
3866     return NULL;
3867   }
3868   objArrayOop dest_o = oopFactory::new_objArray(vmClasses::Object_klass(), 3, CHECK_NULL);
3869   objArrayHandle dest(THREAD, dest_o);
3870   Klass* enc_k = ik->constants()->klass_at(encl_method_class_idx, CHECK_NULL);
3871   dest->obj_at_put(0, enc_k->java_mirror());
3872   int encl_method_method_idx = ik->enclosing_method_method_index();
3873   if (encl_method_method_idx != 0) {
3874     Symbol* sym = ik->constants()->symbol_at(
3875                         extract_low_short_from_int(
3876                           ik->constants()->name_and_type_at(encl_method_method_idx)));
3877     Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
3878     dest->obj_at_put(1, str());
3879     sym = ik->constants()->symbol_at(
3880               extract_high_short_from_int(
3881                 ik->constants()->name_and_type_at(encl_method_method_idx)));
3882     str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
3883     dest->obj_at_put(2, str());
3884   }
3885   return (jobjectArray) JNIHandles::make_local(THREAD, dest());
3886 }
3887 JVM_END
3888 
3889 // Returns an array of java.lang.String objects containing the input arguments to the VM.
3890 JVM_ENTRY(jobjectArray, JVM_GetVmArguments(JNIEnv *env))
3891   ResourceMark rm(THREAD);
3892 
3893   if (Arguments::num_jvm_args() == 0 && Arguments::num_jvm_flags() == 0) {
3894     return NULL;
3895   }
3896 
3897   char** vm_flags = Arguments::jvm_flags_array();
3898   char** vm_args = Arguments::jvm_args_array();
3899   int num_flags = Arguments::num_jvm_flags();
3900   int num_args = Arguments::num_jvm_args();
3901 
3902   InstanceKlass* ik = vmClasses::String_klass();
3903   objArrayOop r = oopFactory::new_objArray(ik, num_args + num_flags, CHECK_NULL);
3904   objArrayHandle result_h(THREAD, r);
3905 
3906   int index = 0;
3907   for (int j = 0; j < num_flags; j++, index++) {
3908     Handle h = java_lang_String::create_from_platform_dependent_str(vm_flags[j], CHECK_NULL);
3909     result_h->obj_at_put(index, h());
3910   }
3911   for (int i = 0; i < num_args; i++, index++) {
3912     Handle h = java_lang_String::create_from_platform_dependent_str(vm_args[i], CHECK_NULL);
3913     result_h->obj_at_put(index, h());
3914   }
3915   return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
3916 JVM_END
3917 
3918 JVM_LEAF(jint, JVM_FindSignal(const char *name))
3919   return os::get_signal_number(name);
3920 JVM_END
3921 
3922 JVM_ENTRY(void, JVM_VirtualThreadMountBegin(JNIEnv* env, jobject vthread, jboolean first_mount))
3923 #if INCLUDE_JVMTI
3924   if (!DoJVMTIVirtualThreadTransitions) {
3925     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
3926     return;
3927   }
3928   assert(!thread->is_in_tmp_VTMS_transition(), "sanity check");
3929   assert(!thread->is_in_VTMS_transition(), "sanity check");
3930   JvmtiVTMSTransitionDisabler::start_VTMS_transition(vthread, /* is_mount */ true);
3931 #else
3932   fatal("Should only be called with JVMTI enabled");
3933 #endif
3934 JVM_END
3935 
3936 JVM_ENTRY(void, JVM_VirtualThreadMountEnd(JNIEnv* env, jobject vthread, jboolean first_mount))
3937 #if INCLUDE_JVMTI
3938   if (!DoJVMTIVirtualThreadTransitions) {
3939     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
3940     return;
3941   }
3942   oop vt = JNIHandles::resolve(vthread);
3943 
3944   thread->rebind_to_jvmti_thread_state_of(vt);
3945 
3946   {
3947     MutexLocker mu(JvmtiThreadState_lock);
3948     JvmtiThreadState* state = thread->jvmti_thread_state();
3949     if (state != NULL && state->is_pending_interp_only_mode()) {
3950       JvmtiEventController::enter_interp_only_mode();
3951     }
3952   }
3953   assert(thread->is_in_VTMS_transition(), "sanity check");
3954   assert(!thread->is_in_tmp_VTMS_transition(), "sanity check");
3955   JvmtiVTMSTransitionDisabler::finish_VTMS_transition(vthread, /* is_mount */ true);
3956   if (first_mount) {
3957     // thread start
3958     if (JvmtiExport::can_support_virtual_threads()) {
3959       JvmtiEventController::thread_started(thread);
3960       if (JvmtiExport::should_post_vthread_start()) {
3961         JvmtiExport::post_vthread_start(vthread);
3962       }
3963     } else { // compatibility for vthread unaware agents: legacy thread_start
3964       if (PostVirtualThreadCompatibleLifecycleEvents &&
3965           JvmtiExport::should_post_thread_life()) {
3966         // JvmtiEventController::thread_started is called here
3967         JvmtiExport::post_thread_start(thread);
3968       }
3969     }
3970   }
3971   if (JvmtiExport::should_post_vthread_mount()) {
3972     JvmtiExport::post_vthread_mount(vthread);
3973   }
3974 #else
3975   fatal("Should only be called with JVMTI enabled");
3976 #endif
3977 JVM_END
3978 
3979 JVM_ENTRY(void, JVM_VirtualThreadUnmountBegin(JNIEnv* env, jobject vthread, jboolean last_unmount))
3980 #if INCLUDE_JVMTI
3981   if (!DoJVMTIVirtualThreadTransitions) {
3982     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
3983     return;
3984   }
3985   HandleMark hm(thread);
3986   Handle ct(thread, thread->threadObj());
3987 
3988   if (JvmtiExport::should_post_vthread_unmount()) {
3989     JvmtiExport::post_vthread_unmount(vthread);
3990   }
3991   if (last_unmount) {
3992     if (JvmtiExport::can_support_virtual_threads()) {
3993       if (JvmtiExport::should_post_vthread_end()) {
3994         JvmtiExport::post_vthread_end(vthread);
3995       }
3996     } else { // compatibility for vthread unaware agents: legacy thread_end
3997       if (PostVirtualThreadCompatibleLifecycleEvents &&
3998           JvmtiExport::should_post_thread_life()) {
3999         JvmtiExport::post_thread_end(thread);
4000       }
4001     }
4002   }
4003   assert(!thread->is_in_tmp_VTMS_transition(), "sanity check");
4004   assert(!thread->is_in_VTMS_transition(), "sanity check");
4005   JvmtiVTMSTransitionDisabler::start_VTMS_transition(vthread, /* is_mount */ false);
4006 
4007   if (last_unmount && thread->jvmti_thread_state() != NULL) {
4008     JvmtiExport::cleanup_thread(thread);
4009     thread->set_jvmti_thread_state(NULL);
4010     oop vt = JNIHandles::resolve(vthread);
4011     java_lang_Thread::set_jvmti_thread_state(vt, NULL);
4012   }
4013   thread->rebind_to_jvmti_thread_state_of(ct());
4014 #else
4015   fatal("Should only be called with JVMTI enabled");
4016 #endif
4017 JVM_END
4018 
4019 JVM_ENTRY(void, JVM_VirtualThreadUnmountEnd(JNIEnv* env, jobject vthread, jboolean last_unmount))
4020 #if INCLUDE_JVMTI
4021   if (!DoJVMTIVirtualThreadTransitions) {
4022     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
4023     return;
4024   }
4025   assert(thread->is_in_VTMS_transition(), "sanity check");
4026   assert(!thread->is_in_tmp_VTMS_transition(), "sanity check");
4027   JvmtiVTMSTransitionDisabler::finish_VTMS_transition(vthread, /* is_mount */ false);
4028 #else
4029   fatal("Should only be called with JVMTI enabled");
4030 #endif
4031 JVM_END
4032 
4033 JVM_ENTRY(void, JVM_VirtualThreadHideFrames(JNIEnv* env, jobject vthread, jboolean hide))
4034 #if INCLUDE_JVMTI
4035   if (!DoJVMTIVirtualThreadTransitions) {
4036     assert(!JvmtiExport::can_support_virtual_threads(), "sanity check");
4037     return;
4038   }
4039   assert(!thread->is_in_VTMS_transition(), "sanity check");
4040   assert(thread->is_in_tmp_VTMS_transition() != (bool)hide, "sanity check");
4041   thread->toggle_is_in_tmp_VTMS_transition();
4042 #else
4043   fatal("Should only be called with JVMTI enabled");
4044 #endif
4045 JVM_END
4046 
4047 /*
4048  * Return the current class's class file version.  The low order 16 bits of the
4049  * returned jint contain the class's major version.  The high order 16 bits
4050  * contain the class's minor version.
4051  */
4052 JVM_ENTRY(jint, JVM_GetClassFileVersion(JNIEnv* env, jclass current))
4053   oop mirror = JNIHandles::resolve_non_null(current);
4054   if (java_lang_Class::is_primitive(mirror)) {
4055     // return latest major version and minor version of 0.
4056     return JVM_CLASSFILE_MAJOR_VERSION;
4057   }
4058   assert(!java_lang_Class::as_Klass(mirror)->is_array_klass(), "unexpected array class");
4059 
4060   Klass* c = java_lang_Class::as_Klass(mirror);
4061   assert(c->is_instance_klass(), "must be");
4062   InstanceKlass* ik = InstanceKlass::cast(c);
4063   return (ik->minor_version() << 16) | ik->major_version();
4064 JVM_END
4065 
4066 /*
4067  * Ensure that code doing a stackwalk and using javaVFrame::locals() to
4068  * get the value will see a materialized value and not a scalar-replaced
4069  * null value.
4070  */
4071 JVM_ENTRY(void, JVM_EnsureMaterializedForStackWalk_func(JNIEnv* env, jobject vthread, jobject value))
4072   JVM_EnsureMaterializedForStackWalk(env, value);
4073 JVM_END