< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

  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"

 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))

 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);

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   }

1824     int length = components->length();
1825     assert(length >= 0, "unexpected record_components length");
1826     objArrayOop record_components =
1827       oopFactory::new_objArray(vmClasses::RecordComponent_klass(), length, CHECK_NULL);
1828     objArrayHandle components_h (THREAD, record_components);
1829 
1830     for (int x = 0; x < length; x++) {
1831       RecordComponent* component = components->at(x);
1832       assert(component != NULL, "unexpected NULL record component");
1833       oop component_oop = java_lang_reflect_RecordComponent::create(ik, component, CHECK_NULL);
1834       components_h->obj_at_put(x, component_oop);
1835     }
1836     return (jobjectArray)JNIHandles::make_local(THREAD, components_h());
1837   }
1838 
1839   return NULL;
1840 }
1841 JVM_END
1842 
1843 static bool select_method(const methodHandle& method, bool want_constructor) {


1844   if (want_constructor) {
1845     return (method->is_initializer() && !method->is_static());
1846   } else {
1847     return  (!method->is_initializer() && !method->is_overpass());


1848   }
1849 }
1850 
1851 static jobjectArray get_class_declared_methods_helper(
1852                                   JNIEnv *env,
1853                                   jclass ofClass, jboolean publicOnly,
1854                                   bool want_constructor,
1855                                   Klass* klass, TRAPS) {
1856 
1857   JvmtiVMObjectAllocEventCollector oam;
1858 
1859   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1860   // Exclude primitive types and array types
1861   if (java_lang_Class::is_primitive(ofMirror)
1862       || java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1863     // Return empty array
1864     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1865     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1866   }
1867 

1890     }
1891   }
1892 
1893   // Allocate result
1894   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1895   objArrayHandle result (THREAD, r);
1896 
1897   // Now just put the methods that we selected above, but go by their idnum
1898   // in case of redefinition.  The methods can be redefined at any safepoint,
1899   // so above when allocating the oop array and below when creating reflect
1900   // objects.
1901   for (int i = 0; i < num_methods; i++) {
1902     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1903     if (method.is_null()) {
1904       // Method may have been deleted and seems this API can handle null
1905       // Otherwise should probably put a method that throws NSME
1906       result->obj_at_put(i, NULL);
1907     } else {
1908       oop m;
1909       if (want_constructor) {


1910         m = Reflection::new_constructor(method, CHECK_NULL);
1911       } else {
1912         m = Reflection::new_method(method, false, CHECK_NULL);
1913       }
1914       result->obj_at_put(i, m);
1915     }
1916   }
1917 
1918   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1919 }
1920 
1921 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1922 {
1923   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1924                                            /*want_constructor*/ false,
1925                                            vmClasses::reflect_Method_klass(), THREAD);
1926 }
1927 JVM_END
1928 
1929 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

2172   constantTag tag = cp->tag_at(index);
2173   if (!tag.is_method() && !tag.is_interface_method()) {
2174     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2175   }
2176   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2177   Klass* k_o;
2178   if (force_resolution) {
2179     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2180   } else {
2181     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2182     if (k_o == NULL) return NULL;
2183   }
2184   InstanceKlass* k = InstanceKlass::cast(k_o);
2185   Symbol* name = cp->uncached_name_ref_at(index);
2186   Symbol* sig  = cp->uncached_signature_ref_at(index);
2187   methodHandle m (THREAD, k->find_method(name, sig));
2188   if (m.is_null()) {
2189     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2190   }
2191   oop method;
2192   if (!m->is_initializer() || m->is_static()) {
2193     method = Reflection::new_method(m, true, CHECK_NULL);
2194   } else {
2195     method = Reflection::new_constructor(m, CHECK_NULL);


2196   }
2197   return JNIHandles::make_local(THREAD, method);
2198 }
2199 
2200 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2201 {
2202   JvmtiVMObjectAllocEventCollector oam;
2203   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2204   bounds_check(cp, index, CHECK_NULL);
2205   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2206   return res;
2207 }
2208 JVM_END
2209 
2210 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2211 {
2212   JvmtiVMObjectAllocEventCollector oam;
2213   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2214   bounds_check(cp, index, CHECK_NULL);
2215   jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);

2446   Klass* k = java_lang_Class::as_Klass(r);
2447   assert(k->is_instance_klass(), "must be an instance klass");
2448   if (!k->is_instance_klass()) return false;
2449 
2450   ResourceMark rm(THREAD);
2451   const char* name = k->name()->as_C_string();
2452   bool system_class = k->class_loader() == NULL;
2453   return JavaAssertions::enabled(name, system_class);
2454 
2455 JVM_END
2456 
2457 
2458 // Return a new AssertionStatusDirectives object with the fields filled in with
2459 // command-line assertion arguments (i.e., -ea, -da).
2460 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2461   JvmtiVMObjectAllocEventCollector oam;
2462   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2463   return JNIHandles::make_local(THREAD, asd);
2464 JVM_END
2465 





































2466 // Verification ////////////////////////////////////////////////////////////////////////////////
2467 
2468 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2469 
2470 // RedefineClasses support: bug 6214132 caused verification to fail.
2471 // All functions from this section should call the jvmtiThreadSate function:
2472 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2473 // The function returns a Klass* of the _scratch_class if the verifier
2474 // was invoked in the middle of the class redefinition.
2475 // Otherwise it returns its argument value which is the _the_class Klass*.
2476 // Please, refer to the description in the jvmtiThreadSate.hpp.
2477 
2478 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2479   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2480   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2481   return k->name()->as_utf8();
2482 JVM_END
2483 
2484 
2485 JVM_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))

2608   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2609   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2610   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2611   return method->size_of_parameters();
2612 JVM_END
2613 
2614 
2615 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2616   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2617   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2618   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2619   return method->verifier_max_stack();
2620 JVM_END
2621 
2622 
2623 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2624   ResourceMark rm(THREAD);
2625   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2626   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2627   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2628   return method->name() == vmSymbols::object_initializer_name();
2629 JVM_END
2630 
2631 
2632 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2633   ResourceMark rm(THREAD);
2634   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2635   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2636   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2637   return method->is_overpass();
2638 JVM_END
2639 
2640 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2641   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2642   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2643   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2644   return method->name()->as_utf8();
2645 JVM_END
2646 
2647 
2648 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))

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




3473 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3474   return VMContinuations ? JNI_TRUE : JNI_FALSE;
3475 JVM_END
3476 
3477 // String support ///////////////////////////////////////////////////////////////////////////
3478 
3479 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3480   JvmtiVMObjectAllocEventCollector oam;
3481   if (str == NULL) return NULL;
3482   oop string = JNIHandles::resolve_non_null(str);
3483   oop result = StringTable::intern(string, CHECK_NULL);
3484   return (jstring) JNIHandles::make_local(THREAD, result);
3485 JVM_END
3486 
3487 
3488 // VM Raw monitor support //////////////////////////////////////////////////////////////////////
3489 
3490 // VM Raw monitors (not to be confused with JvmtiRawMonitors) are a simple mutual exclusion
3491 // lock (not actually monitors: no wait/notify) that is exported by the VM for use by JDK
3492 // library code. They may be used by JavaThreads and non-JavaThreads and do not participate

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

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

  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/flatArrayKlass.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/jvm_misc.hpp"
  68 #include "prims/jvmtiExport.hpp"
  69 #include "prims/jvmtiThreadState.inline.hpp"
  70 #include "prims/stackwalk.hpp"
  71 #include "runtime/arguments.hpp"
  72 #include "runtime/atomic.hpp"
  73 #include "runtime/continuation.hpp"
  74 #include "runtime/globals_extension.hpp"
  75 #include "runtime/handles.inline.hpp"
  76 #include "runtime/init.hpp"
  77 #include "runtime/interfaceSupport.inline.hpp"
  78 #include "runtime/deoptimization.hpp"
  79 #include "runtime/handshake.hpp"

 597 
 598   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 599   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count,
 600                                   start_index, frames_array_h, THREAD);
 601 JVM_END
 602 
 603 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 604   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 605   objArrayHandle frames_array_h(THREAD, fa);
 606   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 607   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 608 
 609   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 610 JVM_END
 611 
 612 // java.lang.Object ///////////////////////////////////////////////
 613 
 614 
 615 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 616   // as implemented in the classic virtual machine; return 0 if object is NULL
 617   if (handle == NULL) {
 618     return 0;
 619   }
 620   oop obj = JNIHandles::resolve_non_null(handle);
 621   if (EnableValhalla && obj->klass()->is_inline_klass()) {
 622       JavaValue result(T_INT);
 623       JavaCallArguments args;
 624       Handle ho(THREAD, obj);
 625       args.push_oop(ho);
 626       methodHandle method(THREAD, Universe::value_object_hash_code_method());
 627       JavaCalls::call(&result, method, &args, THREAD);
 628       if (HAS_PENDING_EXCEPTION) {
 629         if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
 630           Handle e(THREAD, PENDING_EXCEPTION);
 631           CLEAR_PENDING_EXCEPTION;
 632           THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in hashCode", e, false);
 633         }
 634       }
 635       return result.get_jint();
 636   } else {
 637     return ObjectSynchronizer::FastHashCode(THREAD, obj);
 638   }
 639 JVM_END
 640 
 641 
 642 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 643   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 644   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 645   if (JvmtiExport::should_post_monitor_wait()) {
 646     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 647 
 648     // The current thread already owns the monitor and it has not yet
 649     // been added to the wait queue so the current thread cannot be
 650     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 651     // event handler cannot accidentally consume an unpark() meant for
 652     // the ParkEvent associated with this ObjectMonitor.
 653   }
 654   ObjectSynchronizer::wait(obj, ms, CHECK);
 655 JVM_END
 656 
 657 
 658 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))

 670 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 671   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 672   Klass* klass = obj->klass();
 673   JvmtiVMObjectAllocEventCollector oam;
 674 
 675 #ifdef ASSERT
 676   // Just checking that the cloneable flag is set correct
 677   if (obj->is_array()) {
 678     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 679   } else {
 680     guarantee(obj->is_instance(), "should be instanceOop");
 681     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 682     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 683   }
 684 #endif
 685 
 686   // Check if class of obj supports the Cloneable interface.
 687   // All arrays are considered to be cloneable (See JLS 20.1.5).
 688   // All j.l.r.Reference classes are considered non-cloneable.
 689   if (!klass->is_cloneable() ||
 690        klass->is_inline_klass() ||
 691       (klass->is_instance_klass() &&
 692        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 693     ResourceMark rm(THREAD);
 694     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 695   }
 696 
 697   // Make shallow object copy
 698   const size_t size = obj->size();
 699   oop new_obj_oop = NULL;
 700   if (obj->is_array()) {
 701     const int length = ((arrayOop)obj())->length();
 702     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 703                                                    /* do_zero */ true, CHECK_NULL);
 704   } else {
 705     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 706   }
 707 
 708   HeapAccess<>::clone(obj(), new_obj_oop, size);
 709 
 710   Handle new_obj(THREAD, new_obj_oop);

1184   oop result = java_lang_Class::name(java_class, CHECK_NULL);
1185   return (jstring) JNIHandles::make_local(THREAD, result);
1186 JVM_END
1187 
1188 
1189 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1190   JvmtiVMObjectAllocEventCollector oam;
1191   oop mirror = JNIHandles::resolve_non_null(cls);
1192 
1193   // Special handling for primitive objects
1194   if (java_lang_Class::is_primitive(mirror)) {
1195     // Primitive objects does not have any interfaces
1196     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1197     return (jobjectArray) JNIHandles::make_local(THREAD, r);
1198   }
1199 
1200   Klass* klass = java_lang_Class::as_Klass(mirror);
1201   // Figure size of result array
1202   int size;
1203   if (klass->is_instance_klass()) {
1204     InstanceKlass* ik = InstanceKlass::cast(klass);
1205     size = ik->local_interfaces()->length();
1206   } else {
1207     assert(klass->is_objArray_klass() || klass->is_typeArray_klass() || klass->is_flatArray_klass(), "Illegal mirror klass");
1208     size = 2;
1209   }
1210 
1211   // Allocate result array
1212   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1213   objArrayHandle result (THREAD, r);
1214   // Fill in result
1215   if (klass->is_instance_klass()) {
1216     // Regular instance klass, fill in all local interfaces
1217     for (int index = 0; index < size; index++) {
1218       InstanceKlass* ik = InstanceKlass::cast(klass);
1219       Klass* k = ik->local_interfaces()->at(index);
1220       result->obj_at_put(index, k->java_mirror());
1221     }
1222   } else {
1223     // All arrays implement java.lang.Cloneable and java.io.Serializable
1224     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1225     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1226   }
1227   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1228 JVM_END
1229 
1230 
1231 JVM_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
1232   oop mirror = JNIHandles::resolve_non_null(cls);
1233   if (java_lang_Class::is_primitive(mirror)) {
1234     return JNI_FALSE;
1235   }
1236   Klass* k = java_lang_Class::as_Klass(mirror);
1237   jboolean result = k->is_interface();
1238   assert(!result || k->is_instance_klass(),
1239          "all interfaces are instance types");
1240   // The compiler intrinsic for isInterface tests the
1241   // Klass::_access_flags bits in the same way.
1242   return result;
1243 JVM_END
1244 
1245 JVM_ENTRY(jboolean, JVM_IsHiddenClass(JNIEnv *env, jclass cls))
1246   oop mirror = JNIHandles::resolve_non_null(cls);
1247   if (java_lang_Class::is_primitive(mirror)) {
1248     return JNI_FALSE;
1249   }
1250   Klass* k = java_lang_Class::as_Klass(mirror);
1251   return k->is_hidden();
1252 JVM_END
1253 
1254 JVM_ENTRY(jboolean, JVM_IsIdentityClass(JNIEnv *env, jclass cls))
1255   oop mirror = JNIHandles::resolve_non_null(cls);
1256   if (java_lang_Class::is_primitive(mirror)) {
1257     return JNI_FALSE;
1258   }
1259   Klass* k = java_lang_Class::as_Klass(mirror);
1260   if (EnableValhalla) {
1261     return k->is_array_klass() || k->is_identity_class();
1262   } else {
1263     return k->is_interface() ? JNI_FALSE : JNI_TRUE;
1264   }
1265 JVM_END
1266 
1267 JVM_ENTRY(jobjectArray, JVM_GetClassSigners(JNIEnv *env, jclass cls))
1268   JvmtiVMObjectAllocEventCollector oam;
1269   oop mirror = JNIHandles::resolve_non_null(cls);
1270   if (java_lang_Class::is_primitive(mirror)) {
1271     // There are no signers for primitive types
1272     return NULL;
1273   }
1274 
1275   objArrayHandle signers(THREAD, java_lang_Class::signers(mirror));
1276 
1277   // If there are no signers set in the class, or if the class
1278   // is an array, return NULL.
1279   if (signers == NULL) return NULL;
1280 
1281   // copy of the signers array
1282   Klass* element = ObjArrayKlass::cast(signers->klass())->element_klass();
1283   objArrayOop signers_copy = oopFactory::new_objArray(element, signers->length(), CHECK_NULL);
1284   for (int index = 0; index < signers->length(); index++) {
1285     signers_copy->obj_at_put(index, signers->obj_at(index));
1286   }

1862     int length = components->length();
1863     assert(length >= 0, "unexpected record_components length");
1864     objArrayOop record_components =
1865       oopFactory::new_objArray(vmClasses::RecordComponent_klass(), length, CHECK_NULL);
1866     objArrayHandle components_h (THREAD, record_components);
1867 
1868     for (int x = 0; x < length; x++) {
1869       RecordComponent* component = components->at(x);
1870       assert(component != NULL, "unexpected NULL record component");
1871       oop component_oop = java_lang_reflect_RecordComponent::create(ik, component, CHECK_NULL);
1872       components_h->obj_at_put(x, component_oop);
1873     }
1874     return (jobjectArray)JNIHandles::make_local(THREAD, components_h());
1875   }
1876 
1877   return NULL;
1878 }
1879 JVM_END
1880 
1881 static bool select_method(const methodHandle& method, bool want_constructor) {
1882   bool is_ctor = (method->is_object_constructor() ||
1883                   method->is_static_vnew_factory());
1884   if (want_constructor) {
1885     return is_ctor;
1886   } else {
1887     return (!is_ctor &&
1888             !method->is_class_initializer() &&
1889             !method->is_overpass());
1890   }
1891 }
1892 
1893 static jobjectArray get_class_declared_methods_helper(
1894                                   JNIEnv *env,
1895                                   jclass ofClass, jboolean publicOnly,
1896                                   bool want_constructor,
1897                                   Klass* klass, TRAPS) {
1898 
1899   JvmtiVMObjectAllocEventCollector oam;
1900 
1901   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1902   // Exclude primitive types and array types
1903   if (java_lang_Class::is_primitive(ofMirror)
1904       || java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1905     // Return empty array
1906     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1907     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1908   }
1909 

1932     }
1933   }
1934 
1935   // Allocate result
1936   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1937   objArrayHandle result (THREAD, r);
1938 
1939   // Now just put the methods that we selected above, but go by their idnum
1940   // in case of redefinition.  The methods can be redefined at any safepoint,
1941   // so above when allocating the oop array and below when creating reflect
1942   // objects.
1943   for (int i = 0; i < num_methods; i++) {
1944     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1945     if (method.is_null()) {
1946       // Method may have been deleted and seems this API can handle null
1947       // Otherwise should probably put a method that throws NSME
1948       result->obj_at_put(i, NULL);
1949     } else {
1950       oop m;
1951       if (want_constructor) {
1952         assert(method->is_object_constructor() ||
1953                method->is_static_vnew_factory(), "must be");
1954         m = Reflection::new_constructor(method, CHECK_NULL);
1955       } else {
1956         m = Reflection::new_method(method, false, CHECK_NULL);
1957       }
1958       result->obj_at_put(i, m);
1959     }
1960   }
1961 
1962   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1963 }
1964 
1965 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1966 {
1967   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1968                                            /*want_constructor*/ false,
1969                                            vmClasses::reflect_Method_klass(), THREAD);
1970 }
1971 JVM_END
1972 
1973 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

2216   constantTag tag = cp->tag_at(index);
2217   if (!tag.is_method() && !tag.is_interface_method()) {
2218     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2219   }
2220   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2221   Klass* k_o;
2222   if (force_resolution) {
2223     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2224   } else {
2225     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2226     if (k_o == NULL) return NULL;
2227   }
2228   InstanceKlass* k = InstanceKlass::cast(k_o);
2229   Symbol* name = cp->uncached_name_ref_at(index);
2230   Symbol* sig  = cp->uncached_signature_ref_at(index);
2231   methodHandle m (THREAD, k->find_method(name, sig));
2232   if (m.is_null()) {
2233     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2234   }
2235   oop method;
2236   if (m->is_object_constructor() || m->is_static_vnew_factory()) {


2237     method = Reflection::new_constructor(m, CHECK_NULL);
2238   } else {
2239     method = Reflection::new_method(m, true, CHECK_NULL);
2240   }
2241   return JNIHandles::make_local(THREAD, method);
2242 }
2243 
2244 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2245 {
2246   JvmtiVMObjectAllocEventCollector oam;
2247   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2248   bounds_check(cp, index, CHECK_NULL);
2249   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2250   return res;
2251 }
2252 JVM_END
2253 
2254 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2255 {
2256   JvmtiVMObjectAllocEventCollector oam;
2257   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2258   bounds_check(cp, index, CHECK_NULL);
2259   jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);

2490   Klass* k = java_lang_Class::as_Klass(r);
2491   assert(k->is_instance_klass(), "must be an instance klass");
2492   if (!k->is_instance_klass()) return false;
2493 
2494   ResourceMark rm(THREAD);
2495   const char* name = k->name()->as_C_string();
2496   bool system_class = k->class_loader() == NULL;
2497   return JavaAssertions::enabled(name, system_class);
2498 
2499 JVM_END
2500 
2501 
2502 // Return a new AssertionStatusDirectives object with the fields filled in with
2503 // command-line assertion arguments (i.e., -ea, -da).
2504 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2505   JvmtiVMObjectAllocEventCollector oam;
2506   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2507   return JNIHandles::make_local(THREAD, asd);
2508 JVM_END
2509 
2510 // Arrays support /////////////////////////////////////////////////////////////
2511 
2512 JVM_ENTRY(jboolean, JVM_ArrayIsAccessAtomic(JNIEnv *env, jclass unused, jobject array))
2513   oop o = JNIHandles::resolve(array);
2514   Klass* k = o->klass();
2515   if ((o == NULL) || (!k->is_array_klass())) {
2516     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
2517   }
2518   return ArrayKlass::cast(k)->element_access_is_atomic();
2519 JVM_END
2520 
2521 JVM_ENTRY(jobject, JVM_ArrayEnsureAccessAtomic(JNIEnv *env, jclass unused, jobject array))
2522   oop o = JNIHandles::resolve(array);
2523   Klass* k = o->klass();
2524   if ((o == NULL) || (!k->is_array_klass())) {
2525     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
2526   }
2527   if (k->is_flatArray_klass()) {
2528     FlatArrayKlass* vk = FlatArrayKlass::cast(k);
2529     if (!vk->element_access_is_atomic()) {
2530       /**
2531        * Need to decide how to implement:
2532        *
2533        * 1) Change to objArrayOop layout, therefore oop->klass() differs so
2534        * then "<atomic>[Qfoo;" klass needs to subclass "[Qfoo;" to pass through
2535        * "checkcast" & "instanceof"
2536        *
2537        * 2) Use extra header in the flatArrayOop to flag atomicity required and
2538        * possibly per instance lock structure. Said info, could be placed in
2539        * "trailer" rather than disturb the current arrayOop
2540        */
2541       Unimplemented();
2542     }
2543   }
2544   return array;
2545 JVM_END
2546 
2547 // Verification ////////////////////////////////////////////////////////////////////////////////
2548 
2549 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2550 
2551 // RedefineClasses support: bug 6214132 caused verification to fail.
2552 // All functions from this section should call the jvmtiThreadSate function:
2553 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2554 // The function returns a Klass* of the _scratch_class if the verifier
2555 // was invoked in the middle of the class redefinition.
2556 // Otherwise it returns its argument value which is the _the_class Klass*.
2557 // Please, refer to the description in the jvmtiThreadSate.hpp.
2558 
2559 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2560   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2561   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2562   return k->name()->as_utf8();
2563 JVM_END
2564 
2565 
2566 JVM_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))

2689   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2690   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2691   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2692   return method->size_of_parameters();
2693 JVM_END
2694 
2695 
2696 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_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   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2700   return method->verifier_max_stack();
2701 JVM_END
2702 
2703 
2704 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2705   ResourceMark rm(THREAD);
2706   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2707   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2708   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2709   return method->is_object_constructor();
2710 JVM_END
2711 
2712 
2713 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2714   ResourceMark rm(THREAD);
2715   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2716   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2717   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2718   return method->is_overpass();
2719 JVM_END
2720 
2721 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2722   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2723   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2724   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2725   return method->name()->as_utf8();
2726 JVM_END
2727 
2728 
2729 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))

3534 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3535   void* find_result = os::dll_lookup(handle, name);
3536   log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3537                     find_result != NULL ? "Found" : "Failed to find",
3538                     name, p2i(handle));
3539   return find_result;
3540 JVM_END
3541 
3542 
3543 // JNI version ///////////////////////////////////////////////////////////////////////////////
3544 
3545 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3546   return Threads::is_supported_jni_version_including_1_1(version);
3547 JVM_END
3548 
3549 
3550 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3551   return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3552 JVM_END
3553 
3554 JVM_LEAF(jboolean, JVM_IsValhallaEnabled(void))
3555   return EnableValhalla ? JNI_TRUE : JNI_FALSE;
3556 JVM_END
3557 
3558 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3559   return VMContinuations ? JNI_TRUE : JNI_FALSE;
3560 JVM_END
3561 
3562 // String support ///////////////////////////////////////////////////////////////////////////
3563 
3564 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3565   JvmtiVMObjectAllocEventCollector oam;
3566   if (str == NULL) return NULL;
3567   oop string = JNIHandles::resolve_non_null(str);
3568   oop result = StringTable::intern(string, CHECK_NULL);
3569   return (jstring) JNIHandles::make_local(THREAD, result);
3570 JVM_END
3571 
3572 
3573 // VM Raw monitor support //////////////////////////////////////////////////////////////////////
3574 
3575 // VM Raw monitors (not to be confused with JvmtiRawMonitors) are a simple mutual exclusion
3576 // lock (not actually monitors: no wait/notify) that is exported by the VM for use by JDK
3577 // library code. They may be used by JavaThreads and non-JavaThreads and do not participate

3615   //   the checkPackageAccess relative to the initiating class loader via the
3616   //   protection_domain. The protection_domain is passed as NULL by the java code
3617   //   if there is no security manager in 3-arg Class.forName().
3618   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3619 
3620   // Check if we should initialize the class
3621   if (init && klass->is_instance_klass()) {
3622     klass->initialize(CHECK_NULL);
3623   }
3624   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3625 }
3626 
3627 
3628 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3629 
3630 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3631   Handle method_handle;
3632   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3633     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3634     Handle receiver(THREAD, JNIHandles::resolve(obj));
3635     objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3636     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3637     jobject res = JNIHandles::make_local(THREAD, result);
3638     if (JvmtiExport::should_post_vm_object_alloc()) {
3639       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3640       assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
3641       if (java_lang_Class::is_primitive(ret_type)) {
3642         // Only for primitive type vm allocates memory for java object.
3643         // See box() method.
3644         JvmtiExport::post_vm_object_alloc(thread, result);
3645       }
3646     }
3647     return res;
3648   } else {
3649     THROW_0(vmSymbols::java_lang_StackOverflowError());
3650   }
3651 JVM_END
3652 
3653 
3654 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3655   objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3656   oop constructor_mirror = JNIHandles::resolve(c);

3657   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3658   jobject res = JNIHandles::make_local(THREAD, result);
3659   if (JvmtiExport::should_post_vm_object_alloc()) {
3660     JvmtiExport::post_vm_object_alloc(thread, result);
3661   }
3662   return res;
3663 JVM_END
3664 
3665 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3666 
3667 JVM_LEAF(jboolean, JVM_SupportsCX8())
3668   return VM_Version::supports_cx8();
3669 JVM_END
3670 
3671 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3672   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3673   assert(k->is_klass(), "just checking");
3674   HeapShared::initialize_from_archived_subgraph(THREAD, k);
3675 JVM_END
3676 
< prev index next >