< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

  40 #include "classfile/modules.hpp"
  41 #include "classfile/packageEntry.hpp"
  42 #include "classfile/stringTable.hpp"
  43 #include "classfile/symbolTable.hpp"
  44 #include "classfile/systemDictionary.hpp"
  45 #include "classfile/vmClasses.hpp"
  46 #include "classfile/vmSymbols.hpp"
  47 #include "gc/shared/collectedHeap.inline.hpp"
  48 #include "interpreter/bytecode.hpp"
  49 #include "interpreter/bytecodeUtils.hpp"
  50 #include "jfr/jfrEvents.hpp"
  51 #include "jvm.h"
  52 #include "logging/log.hpp"
  53 #include "memory/oopFactory.hpp"
  54 #include "memory/referenceType.hpp"
  55 #include "memory/resourceArea.hpp"
  56 #include "memory/universe.hpp"
  57 #include "oops/access.inline.hpp"
  58 #include "oops/constantPool.hpp"
  59 #include "oops/fieldStreams.inline.hpp"

  60 #include "oops/instanceKlass.hpp"
  61 #include "oops/klass.inline.hpp"
  62 #include "oops/method.hpp"
  63 #include "oops/recordComponent.hpp"
  64 #include "oops/objArrayKlass.hpp"
  65 #include "oops/objArrayOop.inline.hpp"
  66 #include "oops/oop.inline.hpp"
  67 #include "prims/foreignGlobals.hpp"
  68 #include "prims/jvm_misc.hpp"
  69 #include "prims/jvmtiExport.hpp"
  70 #include "prims/jvmtiThreadState.inline.hpp"
  71 #include "prims/stackwalk.hpp"
  72 #include "runtime/arguments.hpp"
  73 #include "runtime/atomic.hpp"
  74 #include "runtime/continuation.hpp"
  75 #include "runtime/globals_extension.hpp"
  76 #include "runtime/handles.inline.hpp"
  77 #include "runtime/init.hpp"
  78 #include "runtime/interfaceSupport.inline.hpp"
  79 #include "runtime/deoptimization.hpp"

 407 
 408   return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
 409 JVM_END
 410 
 411 
 412 /*
 413  * Return the temporary directory that the VM uses for the attach
 414  * and perf data files.
 415  *
 416  * It is important that this directory is well-known and the
 417  * same for all VM instances. It cannot be affected by configuration
 418  * variables such as java.io.tmpdir.
 419  */
 420 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
 421   HandleMark hm(THREAD);
 422   const char* temp_dir = os::get_temp_directory();
 423   Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
 424   return (jstring) JNIHandles::make_local(THREAD, h());
 425 JVM_END
 426 























 427 
 428 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
 429 
 430 extern volatile jint vm_created;
 431 
 432 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
 433   EventShutdown event;
 434   if (event.should_commit()) {
 435     event.set_reason("Shutdown requested from Java");
 436     event.commit();
 437   }
 438 JVM_END
 439 
 440 
 441 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
 442   before_exit(thread, true);
 443   vm_exit(code);
 444 JVM_END
 445 
 446 

 606 
 607   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 608   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, last_batch_count, buffer_size,
 609                                   start_index, frames_array_h, THREAD);
 610 JVM_END
 611 
 612 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 613   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 614   objArrayHandle frames_array_h(THREAD, fa);
 615   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 616   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 617 
 618   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 619 JVM_END
 620 
 621 // java.lang.Object ///////////////////////////////////////////////
 622 
 623 
 624 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 625   // as implemented in the classic virtual machine; return 0 if object is null
 626   return handle == nullptr ? 0 :
 627          checked_cast<jint>(ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)));




















 628 JVM_END
 629 
 630 
 631 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 632   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 633   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 634   if (JvmtiExport::should_post_monitor_wait()) {
 635     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 636 
 637     // The current thread already owns the monitor and it has not yet
 638     // been added to the wait queue so the current thread cannot be
 639     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 640     // event handler cannot accidentally consume an unpark() meant for
 641     // the ParkEvent associated with this ObjectMonitor.
 642   }
 643   ObjectSynchronizer::wait(obj, ms, CHECK);
 644 JVM_END
 645 
 646 
 647 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))

 659 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 660   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 661   Klass* klass = obj->klass();
 662   JvmtiVMObjectAllocEventCollector oam;
 663 
 664 #ifdef ASSERT
 665   // Just checking that the cloneable flag is set correct
 666   if (obj->is_array()) {
 667     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 668   } else {
 669     guarantee(obj->is_instance(), "should be instanceOop");
 670     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 671     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 672   }
 673 #endif
 674 
 675   // Check if class of obj supports the Cloneable interface.
 676   // All arrays are considered to be cloneable (See JLS 20.1.5).
 677   // All j.l.r.Reference classes are considered non-cloneable.
 678   if (!klass->is_cloneable() ||

 679       (klass->is_instance_klass() &&
 680        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 681     ResourceMark rm(THREAD);
 682     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 683   }
 684 
 685   // Make shallow object copy
 686   const size_t size = obj->size();
 687   oop new_obj_oop = nullptr;
 688   if (obj->is_array()) {
 689     const int length = ((arrayOop)obj())->length();
 690     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 691                                                    /* do_zero */ true, CHECK_NULL);
 692   } else {
 693     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 694   }
 695 
 696   HeapAccess<>::clone(obj(), new_obj_oop, size);
 697 
 698   Handle new_obj(THREAD, new_obj_oop);

1175   oop result = java_lang_Class::name(java_class, CHECK_NULL);
1176   return (jstring) JNIHandles::make_local(THREAD, result);
1177 JVM_END
1178 
1179 
1180 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1181   JvmtiVMObjectAllocEventCollector oam;
1182   oop mirror = JNIHandles::resolve_non_null(cls);
1183 
1184   // Special handling for primitive objects
1185   if (java_lang_Class::is_primitive(mirror)) {
1186     // Primitive objects does not have any interfaces
1187     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1188     return (jobjectArray) JNIHandles::make_local(THREAD, r);
1189   }
1190 
1191   Klass* klass = java_lang_Class::as_Klass(mirror);
1192   // Figure size of result array
1193   int size;
1194   if (klass->is_instance_klass()) {
1195     size = InstanceKlass::cast(klass)->local_interfaces()->length();

1196   } else {
1197     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1198     size = 2;
1199   }
1200 
1201   // Allocate result array
1202   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1203   objArrayHandle result (THREAD, r);
1204   // Fill in result
1205   if (klass->is_instance_klass()) {
1206     // Regular instance klass, fill in all local interfaces
1207     for (int index = 0; index < size; index++) {
1208       Klass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);

1209       result->obj_at_put(index, k->java_mirror());
1210     }
1211   } else {
1212     // All arrays implement java.lang.Cloneable and java.io.Serializable
1213     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1214     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1215   }
1216   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1217 JVM_END
1218 
1219 
1220 JVM_ENTRY(jboolean, JVM_IsInterface(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   jboolean result = k->is_interface();
1227   assert(!result || k->is_instance_klass(),
1228          "all interfaces are instance types");
1229   // The compiler intrinsic for isInterface tests the
1230   // Klass::_access_flags bits in the same way.
1231   return result;
1232 JVM_END
1233 
1234 JVM_ENTRY(jboolean, JVM_IsHiddenClass(JNIEnv *env, jclass cls))
1235   oop mirror = JNIHandles::resolve_non_null(cls);
1236   if (java_lang_Class::is_primitive(mirror)) {
1237     return JNI_FALSE;
1238   }
1239   Klass* k = java_lang_Class::as_Klass(mirror);
1240   return k->is_hidden();
1241 JVM_END
1242 



















1243 JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls))
1244   JvmtiVMObjectAllocEventCollector oam;
1245   oop mirror = JNIHandles::resolve_non_null(cls);
1246   if (java_lang_Class::is_primitive(mirror)) {
1247     // There are no signers for primitive types
1248     return nullptr;
1249   }
1250 
1251   objArrayHandle signers(THREAD, java_lang_Class::signers(mirror));
1252 
1253   // If there are no signers set in the class, or if the class
1254   // is an array, return null.
1255   if (signers == nullptr) return nullptr;
1256 
1257   // copy of the signers array
1258   Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass();
1259   objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL);
1260   for (int index = 0; index < signers->length(); index++) {
1261     signers_copy->obj_at_put(index, signers->obj_at(index));
1262   }

1837     int length = components->length();
1838     assert(length >= 0, "unexpected record_components length");
1839     objArrayOop record_components =
1840       oopFactory::new_objArray(vmClasses::RecordComponent_klass(), length, CHECK_NULL);
1841     objArrayHandle components_h (THREAD, record_components);
1842 
1843     for (int x = 0; x < length; x++) {
1844       RecordComponent* component = components->at(x);
1845       assert(component != nullptr, "unexpected null record component");
1846       oop component_oop = java_lang_reflect_RecordComponent::create(ik, component, CHECK_NULL);
1847       components_h->obj_at_put(x, component_oop);
1848     }
1849     return (jobjectArray)JNIHandles::make_local(THREAD, components_h());
1850   }
1851 
1852   return nullptr;
1853 }
1854 JVM_END
1855 
1856 static bool select_method(const methodHandle& method, bool want_constructor) {

1857   if (want_constructor) {
1858     return (method->is_initializer() && !method->is_static());
1859   } else {
1860     return  (!method->is_initializer() && !method->is_overpass());


1861   }
1862 }
1863 
1864 static jobjectArray get_class_declared_methods_helper(
1865                                   JNIEnv *env,
1866                                   jclass ofClass, jboolean publicOnly,
1867                                   bool want_constructor,
1868                                   Klass* klass, TRAPS) {
1869 
1870   JvmtiVMObjectAllocEventCollector oam;
1871 
1872   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1873   // Exclude primitive types and array types
1874   if (java_lang_Class::is_primitive(ofMirror)
1875       || java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1876     // Return empty array
1877     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1878     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1879   }
1880 

1903     }
1904   }
1905 
1906   // Allocate result
1907   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1908   objArrayHandle result (THREAD, r);
1909 
1910   // Now just put the methods that we selected above, but go by their idnum
1911   // in case of redefinition.  The methods can be redefined at any safepoint,
1912   // so above when allocating the oop array and below when creating reflect
1913   // objects.
1914   for (int i = 0; i < num_methods; i++) {
1915     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1916     if (method.is_null()) {
1917       // Method may have been deleted and seems this API can handle null
1918       // Otherwise should probably put a method that throws NSME
1919       result->obj_at_put(i, nullptr);
1920     } else {
1921       oop m;
1922       if (want_constructor) {

1923         m = Reflection::new_constructor(method, CHECK_NULL);
1924       } else {
1925         m = Reflection::new_method(method, false, CHECK_NULL);
1926       }
1927       result->obj_at_put(i, m);
1928     }
1929   }
1930 
1931   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1932 }
1933 
1934 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1935 {
1936   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1937                                            /*want_constructor*/ false,
1938                                            vmClasses::reflect_Method_klass(), THREAD);
1939 }
1940 JVM_END
1941 
1942 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

2185   constantTag tag = cp->tag_at(index);
2186   if (!tag.is_method() && !tag.is_interface_method()) {
2187     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2188   }
2189   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2190   Klass* k_o;
2191   if (force_resolution) {
2192     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2193   } else {
2194     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2195     if (k_o == nullptr) return nullptr;
2196   }
2197   InstanceKlass* k = InstanceKlass::cast(k_o);
2198   Symbol* name = cp->uncached_name_ref_at(index);
2199   Symbol* sig  = cp->uncached_signature_ref_at(index);
2200   methodHandle m (THREAD, k->find_method(name, sig));
2201   if (m.is_null()) {
2202     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2203   }
2204   oop method;
2205   if (!m->is_initializer() || m->is_static()) {
2206     method = Reflection::new_method(m, true, CHECK_NULL);
2207   } else {
2208     method = Reflection::new_constructor(m, CHECK_NULL);


2209   }
2210   return JNIHandles::make_local(THREAD, method);
2211 }
2212 
2213 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2214 {
2215   JvmtiVMObjectAllocEventCollector oam;
2216   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2217   bounds_check(cp, index, CHECK_NULL);
2218   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2219   return res;
2220 }
2221 JVM_END
2222 
2223 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2224 {
2225   JvmtiVMObjectAllocEventCollector oam;
2226   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2227   bounds_check(cp, index, CHECK_NULL);
2228   jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);

2459   Klass* k = java_lang_Class::as_Klass(r);
2460   assert(k->is_instance_klass(), "must be an instance klass");
2461   if (!k->is_instance_klass()) return false;
2462 
2463   ResourceMark rm(THREAD);
2464   const char* name = k->name()->as_C_string();
2465   bool system_class = k->class_loader() == nullptr;
2466   return JavaAssertions::enabled(name, system_class);
2467 
2468 JVM_END
2469 
2470 
2471 // Return a new AssertionStatusDirectives object with the fields filled in with
2472 // command-line assertion arguments (i.e., -ea, -da).
2473 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2474   JvmtiVMObjectAllocEventCollector oam;
2475   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2476   return JNIHandles::make_local(THREAD, asd);
2477 JVM_END
2478 





































2479 // Verification ////////////////////////////////////////////////////////////////////////////////
2480 
2481 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2482 
2483 // RedefineClasses support: bug 6214132 caused verification to fail.
2484 // All functions from this section should call the jvmtiThreadSate function:
2485 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2486 // The function returns a Klass* of the _scratch_class if the verifier
2487 // was invoked in the middle of the class redefinition.
2488 // Otherwise it returns its argument value which is the _the_class Klass*.
2489 // Please, refer to the description in the jvmtiThreadSate.hpp.
2490 
2491 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2492   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2493   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2494   return k->name()->as_utf8();
2495 JVM_END
2496 
2497 
2498 JVM_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))

2621   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2622   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2623   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2624   return method->size_of_parameters();
2625 JVM_END
2626 
2627 
2628 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2629   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2630   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2631   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2632   return method->verifier_max_stack();
2633 JVM_END
2634 
2635 
2636 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2637   ResourceMark rm(THREAD);
2638   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2639   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2640   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2641   return method->name() == vmSymbols::object_initializer_name();
2642 JVM_END
2643 
2644 
2645 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2646   ResourceMark rm(THREAD);
2647   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2648   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2649   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2650   return method->is_overpass();
2651 JVM_END
2652 
2653 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2654   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2655   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2656   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2657   return method->name()->as_utf8();
2658 JVM_END
2659 
2660 
2661 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))

3458 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3459   void* find_result = os::dll_lookup(handle, name);
3460   log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3461                     find_result != nullptr ? "Found" : "Failed to find",
3462                     name, p2i(handle));
3463   return find_result;
3464 JVM_END
3465 
3466 
3467 // JNI version ///////////////////////////////////////////////////////////////////////////////
3468 
3469 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3470   return Threads::is_supported_jni_version_including_1_1(version);
3471 JVM_END
3472 
3473 
3474 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3475   return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3476 JVM_END
3477 




3478 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3479   return VMContinuations ? JNI_TRUE : JNI_FALSE;
3480 JVM_END
3481 
3482 JVM_LEAF(jboolean, JVM_IsForeignLinkerSupported(void))
3483   return ForeignGlobals::is_foreign_linker_supported() ? JNI_TRUE : JNI_FALSE;
3484 JVM_END
3485 
3486 // String support ///////////////////////////////////////////////////////////////////////////
3487 
3488 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3489   JvmtiVMObjectAllocEventCollector oam;
3490   if (str == nullptr) return nullptr;
3491   oop string = JNIHandles::resolve_non_null(str);
3492   oop result = StringTable::intern(string, CHECK_NULL);
3493   return (jstring) JNIHandles::make_local(THREAD, result);
3494 JVM_END
3495 
3496 
3497 // VM Raw monitor support //////////////////////////////////////////////////////////////////////

3539   //   the checkPackageAccess relative to the initiating class loader via the
3540   //   protection_domain. The protection_domain is passed as null by the java code
3541   //   if there is no security manager in 3-arg Class.forName().
3542   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3543 
3544   // Check if we should initialize the class
3545   if (init && klass->is_instance_klass()) {
3546     klass->initialize(CHECK_NULL);
3547   }
3548   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3549 }
3550 
3551 
3552 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3553 
3554 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3555   Handle method_handle;
3556   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3557     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3558     Handle receiver(THREAD, JNIHandles::resolve(obj));
3559     objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3560     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3561     jobject res = JNIHandles::make_local(THREAD, result);
3562     if (JvmtiExport::should_post_vm_object_alloc()) {
3563       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3564       assert(ret_type != nullptr, "sanity check: ret_type oop must not be null!");
3565       if (java_lang_Class::is_primitive(ret_type)) {
3566         // Only for primitive type vm allocates memory for java object.
3567         // See box() method.
3568         JvmtiExport::post_vm_object_alloc(thread, result);
3569       }
3570     }
3571     return res;
3572   } else {
3573     THROW_0(vmSymbols::java_lang_StackOverflowError());
3574   }
3575 JVM_END
3576 
3577 
3578 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))

3579   oop constructor_mirror = JNIHandles::resolve(c);
3580   objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3581   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3582   jobject res = JNIHandles::make_local(THREAD, result);
3583   if (JvmtiExport::should_post_vm_object_alloc()) {
3584     JvmtiExport::post_vm_object_alloc(thread, result);
3585   }
3586   return res;
3587 JVM_END
3588 
3589 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3590 
3591 JVM_LEAF(jboolean, JVM_SupportsCX8())
3592   return VM_Version::supports_cx8();
3593 JVM_END
3594 
3595 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3596   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3597   assert(k->is_klass(), "just checking");
3598   HeapShared::initialize_from_archived_subgraph(THREAD, k);
3599 JVM_END
3600 

  40 #include "classfile/modules.hpp"
  41 #include "classfile/packageEntry.hpp"
  42 #include "classfile/stringTable.hpp"
  43 #include "classfile/symbolTable.hpp"
  44 #include "classfile/systemDictionary.hpp"
  45 #include "classfile/vmClasses.hpp"
  46 #include "classfile/vmSymbols.hpp"
  47 #include "gc/shared/collectedHeap.inline.hpp"
  48 #include "interpreter/bytecode.hpp"
  49 #include "interpreter/bytecodeUtils.hpp"
  50 #include "jfr/jfrEvents.hpp"
  51 #include "jvm.h"
  52 #include "logging/log.hpp"
  53 #include "memory/oopFactory.hpp"
  54 #include "memory/referenceType.hpp"
  55 #include "memory/resourceArea.hpp"
  56 #include "memory/universe.hpp"
  57 #include "oops/access.inline.hpp"
  58 #include "oops/constantPool.hpp"
  59 #include "oops/fieldStreams.inline.hpp"
  60 #include "oops/flatArrayKlass.hpp"
  61 #include "oops/instanceKlass.hpp"
  62 #include "oops/klass.inline.hpp"
  63 #include "oops/method.hpp"
  64 #include "oops/recordComponent.hpp"
  65 #include "oops/objArrayKlass.hpp"
  66 #include "oops/objArrayOop.inline.hpp"
  67 #include "oops/oop.inline.hpp"
  68 #include "prims/foreignGlobals.hpp"
  69 #include "prims/jvm_misc.hpp"
  70 #include "prims/jvmtiExport.hpp"
  71 #include "prims/jvmtiThreadState.inline.hpp"
  72 #include "prims/stackwalk.hpp"
  73 #include "runtime/arguments.hpp"
  74 #include "runtime/atomic.hpp"
  75 #include "runtime/continuation.hpp"
  76 #include "runtime/globals_extension.hpp"
  77 #include "runtime/handles.inline.hpp"
  78 #include "runtime/init.hpp"
  79 #include "runtime/interfaceSupport.inline.hpp"
  80 #include "runtime/deoptimization.hpp"

 408 
 409   return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
 410 JVM_END
 411 
 412 
 413 /*
 414  * Return the temporary directory that the VM uses for the attach
 415  * and perf data files.
 416  *
 417  * It is important that this directory is well-known and the
 418  * same for all VM instances. It cannot be affected by configuration
 419  * variables such as java.io.tmpdir.
 420  */
 421 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
 422   HandleMark hm(THREAD);
 423   const char* temp_dir = os::get_temp_directory();
 424   Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
 425   return (jstring) JNIHandles::make_local(THREAD, h());
 426 JVM_END
 427 
 428 JVM_ENTRY(jarray, JVM_NewNullRestrictedArray(JNIEnv *env, jclass elmClass, jint len))
 429   if (len < 0) {
 430     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Array length is negative");
 431   }
 432   oop mirror = JNIHandles::resolve_non_null(elmClass);
 433   Klass* klass = java_lang_Class::as_Klass(mirror);
 434   klass->initialize(CHECK_NULL);
 435   if (klass->is_identity_class()) {
 436     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Element class is not a value class");
 437   }
 438   InstanceKlass* ik = InstanceKlass::cast(klass);
 439   if (!ik->is_implicitly_constructible()) {
 440     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Element class is not annotated with @ImplicitlyConstructible");
 441   }
 442   oop array = oopFactory::new_valueArray(ik, len, CHECK_NULL);
 443   return (jarray) JNIHandles::make_local(THREAD, array);
 444 JVM_END
 445 
 446 
 447 JVM_ENTRY(jboolean, JVM_IsNullRestrictedArray(JNIEnv *env, jobject obj))
 448   arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
 449   return oop->is_null_free_array();
 450 JVM_END
 451 
 452 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
 453 
 454 extern volatile jint vm_created;
 455 
 456 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
 457   EventShutdown event;
 458   if (event.should_commit()) {
 459     event.set_reason("Shutdown requested from Java");
 460     event.commit();
 461   }
 462 JVM_END
 463 
 464 
 465 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
 466   before_exit(thread, true);
 467   vm_exit(code);
 468 JVM_END
 469 
 470 

 630 
 631   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 632   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, last_batch_count, buffer_size,
 633                                   start_index, frames_array_h, THREAD);
 634 JVM_END
 635 
 636 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 637   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 638   objArrayHandle frames_array_h(THREAD, fa);
 639   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 640   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 641 
 642   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 643 JVM_END
 644 
 645 // java.lang.Object ///////////////////////////////////////////////
 646 
 647 
 648 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 649   // as implemented in the classic virtual machine; return 0 if object is null
 650   if (handle == nullptr) {
 651     return 0;
 652   }
 653   oop obj = JNIHandles::resolve_non_null(handle);
 654   if (EnableValhalla && obj->klass()->is_inline_klass()) {
 655       JavaValue result(T_INT);
 656       JavaCallArguments args;
 657       Handle ho(THREAD, obj);
 658       args.push_oop(ho);
 659       methodHandle method(THREAD, Universe::value_object_hash_code_method());
 660       JavaCalls::call(&result, method, &args, THREAD);
 661       if (HAS_PENDING_EXCEPTION) {
 662         if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
 663           Handle e(THREAD, PENDING_EXCEPTION);
 664           CLEAR_PENDING_EXCEPTION;
 665           THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in hashCode", e, false);
 666         }
 667       }
 668       return result.get_jint();
 669   } else {
 670     return checked_cast<jint>(ObjectSynchronizer::FastHashCode(THREAD, obj));
 671   }
 672 JVM_END
 673 
 674 
 675 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 676   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 677   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 678   if (JvmtiExport::should_post_monitor_wait()) {
 679     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 680 
 681     // The current thread already owns the monitor and it has not yet
 682     // been added to the wait queue so the current thread cannot be
 683     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 684     // event handler cannot accidentally consume an unpark() meant for
 685     // the ParkEvent associated with this ObjectMonitor.
 686   }
 687   ObjectSynchronizer::wait(obj, ms, CHECK);
 688 JVM_END
 689 
 690 
 691 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))

 703 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 704   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 705   Klass* klass = obj->klass();
 706   JvmtiVMObjectAllocEventCollector oam;
 707 
 708 #ifdef ASSERT
 709   // Just checking that the cloneable flag is set correct
 710   if (obj->is_array()) {
 711     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 712   } else {
 713     guarantee(obj->is_instance(), "should be instanceOop");
 714     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 715     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 716   }
 717 #endif
 718 
 719   // Check if class of obj supports the Cloneable interface.
 720   // All arrays are considered to be cloneable (See JLS 20.1.5).
 721   // All j.l.r.Reference classes are considered non-cloneable.
 722   if (!klass->is_cloneable() ||
 723        klass->is_inline_klass() ||
 724       (klass->is_instance_klass() &&
 725        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 726     ResourceMark rm(THREAD);
 727     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 728   }
 729 
 730   // Make shallow object copy
 731   const size_t size = obj->size();
 732   oop new_obj_oop = nullptr;
 733   if (obj->is_array()) {
 734     const int length = ((arrayOop)obj())->length();
 735     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 736                                                    /* do_zero */ true, CHECK_NULL);
 737   } else {
 738     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 739   }
 740 
 741   HeapAccess<>::clone(obj(), new_obj_oop, size);
 742 
 743   Handle new_obj(THREAD, new_obj_oop);

1220   oop result = java_lang_Class::name(java_class, CHECK_NULL);
1221   return (jstring) JNIHandles::make_local(THREAD, result);
1222 JVM_END
1223 
1224 
1225 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1226   JvmtiVMObjectAllocEventCollector oam;
1227   oop mirror = JNIHandles::resolve_non_null(cls);
1228 
1229   // Special handling for primitive objects
1230   if (java_lang_Class::is_primitive(mirror)) {
1231     // Primitive objects does not have any interfaces
1232     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1233     return (jobjectArray) JNIHandles::make_local(THREAD, r);
1234   }
1235 
1236   Klass* klass = java_lang_Class::as_Klass(mirror);
1237   // Figure size of result array
1238   int size;
1239   if (klass->is_instance_klass()) {
1240     InstanceKlass* ik = InstanceKlass::cast(klass);
1241     size = ik->local_interfaces()->length();
1242   } else {
1243     assert(klass->is_objArray_klass() || klass->is_typeArray_klass() || klass->is_flatArray_klass(), "Illegal mirror klass");
1244     size = 2;
1245   }
1246 
1247   // Allocate result array
1248   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1249   objArrayHandle result (THREAD, r);
1250   // Fill in result
1251   if (klass->is_instance_klass()) {
1252     // Regular instance klass, fill in all local interfaces
1253     for (int index = 0; index < size; index++) {
1254       InstanceKlass* ik = InstanceKlass::cast(klass);
1255       Klass* k = ik->local_interfaces()->at(index);
1256       result->obj_at_put(index, k->java_mirror());
1257     }
1258   } else {
1259     // All arrays implement java.lang.Cloneable and java.io.Serializable
1260     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1261     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1262   }
1263   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1264 JVM_END
1265 
1266 
1267 JVM_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
1268   oop mirror = JNIHandles::resolve_non_null(cls);
1269   if (java_lang_Class::is_primitive(mirror)) {
1270     return JNI_FALSE;
1271   }
1272   Klass* k = java_lang_Class::as_Klass(mirror);
1273   jboolean result = k->is_interface();
1274   assert(!result || k->is_instance_klass(),
1275          "all interfaces are instance types");
1276   // The compiler intrinsic for isInterface tests the
1277   // Klass::_access_flags bits in the same way.
1278   return result;
1279 JVM_END
1280 
1281 JVM_ENTRY(jboolean, JVM_IsHiddenClass(JNIEnv *env, jclass cls))
1282   oop mirror = JNIHandles::resolve_non_null(cls);
1283   if (java_lang_Class::is_primitive(mirror)) {
1284     return JNI_FALSE;
1285   }
1286   Klass* k = java_lang_Class::as_Klass(mirror);
1287   return k->is_hidden();
1288 JVM_END
1289 
1290 JVM_ENTRY(jboolean, JVM_IsIdentityClass(JNIEnv *env, jclass cls))
1291   oop mirror = JNIHandles::resolve_non_null(cls);
1292   if (java_lang_Class::is_primitive(mirror)) {
1293     return JNI_FALSE;
1294   }
1295   Klass* k = java_lang_Class::as_Klass(mirror);
1296   if (EnableValhalla) {
1297     return k->is_array_klass() || k->is_identity_class();
1298   } else {
1299     return k->is_interface() ? JNI_FALSE : JNI_TRUE;
1300   }
1301 JVM_END
1302 
1303 JVM_ENTRY(jboolean, JVM_IsImplicitlyConstructibleClass(JNIEnv *env, jclass cls))
1304   oop mirror = JNIHandles::resolve_non_null(cls);
1305   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(mirror));
1306   return ik->is_implicitly_constructible();
1307 JVM_END
1308 
1309 JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls))
1310   JvmtiVMObjectAllocEventCollector oam;
1311   oop mirror = JNIHandles::resolve_non_null(cls);
1312   if (java_lang_Class::is_primitive(mirror)) {
1313     // There are no signers for primitive types
1314     return nullptr;
1315   }
1316 
1317   objArrayHandle signers(THREAD, java_lang_Class::signers(mirror));
1318 
1319   // If there are no signers set in the class, or if the class
1320   // is an array, return null.
1321   if (signers == nullptr) return nullptr;
1322 
1323   // copy of the signers array
1324   Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass();
1325   objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL);
1326   for (int index = 0; index < signers->length(); index++) {
1327     signers_copy->obj_at_put(index, signers->obj_at(index));
1328   }

1903     int length = components->length();
1904     assert(length >= 0, "unexpected record_components length");
1905     objArrayOop record_components =
1906       oopFactory::new_objArray(vmClasses::RecordComponent_klass(), length, CHECK_NULL);
1907     objArrayHandle components_h (THREAD, record_components);
1908 
1909     for (int x = 0; x < length; x++) {
1910       RecordComponent* component = components->at(x);
1911       assert(component != nullptr, "unexpected null record component");
1912       oop component_oop = java_lang_reflect_RecordComponent::create(ik, component, CHECK_NULL);
1913       components_h->obj_at_put(x, component_oop);
1914     }
1915     return (jobjectArray)JNIHandles::make_local(THREAD, components_h());
1916   }
1917 
1918   return nullptr;
1919 }
1920 JVM_END
1921 
1922 static bool select_method(const methodHandle& method, bool want_constructor) {
1923   bool is_ctor = (method->is_object_constructor());
1924   if (want_constructor) {
1925     return is_ctor;
1926   } else {
1927     return (!is_ctor &&
1928             !method->is_class_initializer() &&
1929             !method->is_overpass());
1930   }
1931 }
1932 
1933 static jobjectArray get_class_declared_methods_helper(
1934                                   JNIEnv *env,
1935                                   jclass ofClass, jboolean publicOnly,
1936                                   bool want_constructor,
1937                                   Klass* klass, TRAPS) {
1938 
1939   JvmtiVMObjectAllocEventCollector oam;
1940 
1941   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1942   // Exclude primitive types and array types
1943   if (java_lang_Class::is_primitive(ofMirror)
1944       || java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1945     // Return empty array
1946     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1947     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1948   }
1949 

1972     }
1973   }
1974 
1975   // Allocate result
1976   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1977   objArrayHandle result (THREAD, r);
1978 
1979   // Now just put the methods that we selected above, but go by their idnum
1980   // in case of redefinition.  The methods can be redefined at any safepoint,
1981   // so above when allocating the oop array and below when creating reflect
1982   // objects.
1983   for (int i = 0; i < num_methods; i++) {
1984     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1985     if (method.is_null()) {
1986       // Method may have been deleted and seems this API can handle null
1987       // Otherwise should probably put a method that throws NSME
1988       result->obj_at_put(i, nullptr);
1989     } else {
1990       oop m;
1991       if (want_constructor) {
1992         assert(method->is_object_constructor(), "must be");
1993         m = Reflection::new_constructor(method, CHECK_NULL);
1994       } else {
1995         m = Reflection::new_method(method, false, CHECK_NULL);
1996       }
1997       result->obj_at_put(i, m);
1998     }
1999   }
2000 
2001   return (jobjectArray) JNIHandles::make_local(THREAD, result());
2002 }
2003 
2004 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
2005 {
2006   return get_class_declared_methods_helper(env, ofClass, publicOnly,
2007                                            /*want_constructor*/ false,
2008                                            vmClasses::reflect_Method_klass(), THREAD);
2009 }
2010 JVM_END
2011 
2012 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

2255   constantTag tag = cp->tag_at(index);
2256   if (!tag.is_method() && !tag.is_interface_method()) {
2257     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2258   }
2259   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2260   Klass* k_o;
2261   if (force_resolution) {
2262     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2263   } else {
2264     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2265     if (k_o == nullptr) return nullptr;
2266   }
2267   InstanceKlass* k = InstanceKlass::cast(k_o);
2268   Symbol* name = cp->uncached_name_ref_at(index);
2269   Symbol* sig  = cp->uncached_signature_ref_at(index);
2270   methodHandle m (THREAD, k->find_method(name, sig));
2271   if (m.is_null()) {
2272     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2273   }
2274   oop method;
2275   if (m->is_object_constructor()) {


2276     method = Reflection::new_constructor(m, CHECK_NULL);
2277   } else {
2278     method = Reflection::new_method(m, true, CHECK_NULL);
2279   }
2280   return JNIHandles::make_local(THREAD, method);
2281 }
2282 
2283 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2284 {
2285   JvmtiVMObjectAllocEventCollector oam;
2286   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2287   bounds_check(cp, index, CHECK_NULL);
2288   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2289   return res;
2290 }
2291 JVM_END
2292 
2293 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2294 {
2295   JvmtiVMObjectAllocEventCollector oam;
2296   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2297   bounds_check(cp, index, CHECK_NULL);
2298   jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);

2529   Klass* k = java_lang_Class::as_Klass(r);
2530   assert(k->is_instance_klass(), "must be an instance klass");
2531   if (!k->is_instance_klass()) return false;
2532 
2533   ResourceMark rm(THREAD);
2534   const char* name = k->name()->as_C_string();
2535   bool system_class = k->class_loader() == nullptr;
2536   return JavaAssertions::enabled(name, system_class);
2537 
2538 JVM_END
2539 
2540 
2541 // Return a new AssertionStatusDirectives object with the fields filled in with
2542 // command-line assertion arguments (i.e., -ea, -da).
2543 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2544   JvmtiVMObjectAllocEventCollector oam;
2545   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2546   return JNIHandles::make_local(THREAD, asd);
2547 JVM_END
2548 
2549 // Arrays support /////////////////////////////////////////////////////////////
2550 
2551 JVM_ENTRY(jboolean, JVM_ArrayIsAccessAtomic(JNIEnv *env, jclass unused, jobject array))
2552   oop o = JNIHandles::resolve(array);
2553   Klass* k = o->klass();
2554   if ((o == nullptr) || (!k->is_array_klass())) {
2555     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
2556   }
2557   return ArrayKlass::cast(k)->element_access_is_atomic();
2558 JVM_END
2559 
2560 JVM_ENTRY(jobject, JVM_ArrayEnsureAccessAtomic(JNIEnv *env, jclass unused, jobject array))
2561   oop o = JNIHandles::resolve(array);
2562   Klass* k = o->klass();
2563   if ((o == nullptr) || (!k->is_array_klass())) {
2564     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
2565   }
2566   if (k->is_flatArray_klass()) {
2567     FlatArrayKlass* vk = FlatArrayKlass::cast(k);
2568     if (!vk->element_access_is_atomic()) {
2569       /**
2570        * Need to decide how to implement:
2571        *
2572        * 1) Change to objArrayOop layout, therefore oop->klass() differs so
2573        * then "<atomic>[Qfoo;" klass needs to subclass "[Qfoo;" to pass through
2574        * "checkcast" & "instanceof"
2575        *
2576        * 2) Use extra header in the flatArrayOop to flag atomicity required and
2577        * possibly per instance lock structure. Said info, could be placed in
2578        * "trailer" rather than disturb the current arrayOop
2579        */
2580       Unimplemented();
2581     }
2582   }
2583   return array;
2584 JVM_END
2585 
2586 // Verification ////////////////////////////////////////////////////////////////////////////////
2587 
2588 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2589 
2590 // RedefineClasses support: bug 6214132 caused verification to fail.
2591 // All functions from this section should call the jvmtiThreadSate function:
2592 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2593 // The function returns a Klass* of the _scratch_class if the verifier
2594 // was invoked in the middle of the class redefinition.
2595 // Otherwise it returns its argument value which is the _the_class Klass*.
2596 // Please, refer to the description in the jvmtiThreadSate.hpp.
2597 
2598 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2599   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2600   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2601   return k->name()->as_utf8();
2602 JVM_END
2603 
2604 
2605 JVM_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))

2728   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2729   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2730   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2731   return method->size_of_parameters();
2732 JVM_END
2733 
2734 
2735 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2736   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2737   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2738   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2739   return method->verifier_max_stack();
2740 JVM_END
2741 
2742 
2743 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2744   ResourceMark rm(THREAD);
2745   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2746   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2747   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2748   return method->is_object_constructor();
2749 JVM_END
2750 
2751 
2752 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2753   ResourceMark rm(THREAD);
2754   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2755   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2756   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2757   return method->is_overpass();
2758 JVM_END
2759 
2760 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2761   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2762   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2763   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2764   return method->name()->as_utf8();
2765 JVM_END
2766 
2767 
2768 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))

3565 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3566   void* find_result = os::dll_lookup(handle, name);
3567   log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3568                     find_result != nullptr ? "Found" : "Failed to find",
3569                     name, p2i(handle));
3570   return find_result;
3571 JVM_END
3572 
3573 
3574 // JNI version ///////////////////////////////////////////////////////////////////////////////
3575 
3576 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3577   return Threads::is_supported_jni_version_including_1_1(version);
3578 JVM_END
3579 
3580 
3581 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3582   return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3583 JVM_END
3584 
3585 JVM_LEAF(jboolean, JVM_IsValhallaEnabled(void))
3586   return EnableValhalla ? JNI_TRUE : JNI_FALSE;
3587 JVM_END
3588 
3589 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3590   return VMContinuations ? JNI_TRUE : JNI_FALSE;
3591 JVM_END
3592 
3593 JVM_LEAF(jboolean, JVM_IsForeignLinkerSupported(void))
3594   return ForeignGlobals::is_foreign_linker_supported() ? JNI_TRUE : JNI_FALSE;
3595 JVM_END
3596 
3597 // String support ///////////////////////////////////////////////////////////////////////////
3598 
3599 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3600   JvmtiVMObjectAllocEventCollector oam;
3601   if (str == nullptr) return nullptr;
3602   oop string = JNIHandles::resolve_non_null(str);
3603   oop result = StringTable::intern(string, CHECK_NULL);
3604   return (jstring) JNIHandles::make_local(THREAD, result);
3605 JVM_END
3606 
3607 
3608 // VM Raw monitor support //////////////////////////////////////////////////////////////////////

3650   //   the checkPackageAccess relative to the initiating class loader via the
3651   //   protection_domain. The protection_domain is passed as null by the java code
3652   //   if there is no security manager in 3-arg Class.forName().
3653   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3654 
3655   // Check if we should initialize the class
3656   if (init && klass->is_instance_klass()) {
3657     klass->initialize(CHECK_NULL);
3658   }
3659   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3660 }
3661 
3662 
3663 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3664 
3665 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3666   Handle method_handle;
3667   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3668     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3669     Handle receiver(THREAD, JNIHandles::resolve(obj));
3670     objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3671     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3672     jobject res = JNIHandles::make_local(THREAD, result);
3673     if (JvmtiExport::should_post_vm_object_alloc()) {
3674       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3675       assert(ret_type != nullptr, "sanity check: ret_type oop must not be null!");
3676       if (java_lang_Class::is_primitive(ret_type)) {
3677         // Only for primitive type vm allocates memory for java object.
3678         // See box() method.
3679         JvmtiExport::post_vm_object_alloc(thread, result);
3680       }
3681     }
3682     return res;
3683   } else {
3684     THROW_0(vmSymbols::java_lang_StackOverflowError());
3685   }
3686 JVM_END
3687 
3688 
3689 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3690   objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3691   oop constructor_mirror = JNIHandles::resolve(c);

3692   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3693   jobject res = JNIHandles::make_local(THREAD, result);
3694   if (JvmtiExport::should_post_vm_object_alloc()) {
3695     JvmtiExport::post_vm_object_alloc(thread, result);
3696   }
3697   return res;
3698 JVM_END
3699 
3700 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3701 
3702 JVM_LEAF(jboolean, JVM_SupportsCX8())
3703   return VM_Version::supports_cx8();
3704 JVM_END
3705 
3706 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3707   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3708   assert(k->is_klass(), "just checking");
3709   HeapShared::initialize_from_archived_subgraph(THREAD, k);
3710 JVM_END
3711 
< prev index next >