< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

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

  61 #include "oops/instanceKlass.hpp"
  62 #include "oops/klass.inline.hpp"
  63 #include "oops/method.hpp"
  64 #include "oops/objArrayKlass.hpp"
  65 #include "oops/objArrayOop.inline.hpp"
  66 #include "oops/oop.inline.hpp"
  67 #include "oops/recordComponent.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/atomicAccess.hpp"
  75 #include "runtime/continuation.hpp"
  76 #include "runtime/deoptimization.hpp"
  77 #include "runtime/globals_extension.hpp"
  78 #include "runtime/handles.inline.hpp"
  79 #include "runtime/handshake.hpp"
  80 #include "runtime/init.hpp"
  81 #include "runtime/interfaceSupport.inline.hpp"
  82 #include "runtime/java.hpp"
  83 #include "runtime/javaCalls.hpp"
  84 #include "runtime/javaThread.hpp"
  85 #include "runtime/jfieldIDWorkaround.hpp"
  86 #include "runtime/jniHandles.inline.hpp"
  87 #include "runtime/mountUnmountDisabler.hpp"

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





































































































































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

 618 
 619   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 620   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, last_batch_count, buffer_size,
 621                                   start_index, frames_array_h, THREAD);
 622 JVM_END
 623 
 624 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 625   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 626   objArrayHandle frames_array_h(THREAD, fa);
 627   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 628   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 629 
 630   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 631 JVM_END
 632 
 633 // java.lang.Object ///////////////////////////////////////////////
 634 
 635 
 636 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 637   // as implemented in the classic virtual machine; return 0 if object is null
 638   return handle == nullptr ? 0 :
 639          checked_cast<jint>(ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)));





















 640 JVM_END
 641 
 642 
 643 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 644   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 645   ObjectSynchronizer::wait(obj, ms, CHECK);
 646 JVM_END
 647 
 648 
 649 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 650   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 651   ObjectSynchronizer::notify(obj, CHECK);
 652 JVM_END
 653 
 654 
 655 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 656   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 657   ObjectSynchronizer::notifyall(obj, CHECK);
 658 JVM_END
 659 

 667   // Just checking that the cloneable flag is set correct
 668   if (obj->is_array()) {
 669     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 670   } else {
 671     guarantee(obj->is_instance(), "should be instanceOop");
 672     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 673     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 674   }
 675 #endif
 676 
 677   // Check if class of obj supports the Cloneable interface.
 678   // All arrays are considered to be cloneable (See JLS 20.1.5).
 679   // All j.l.r.Reference classes are considered non-cloneable.
 680   if (!klass->is_cloneable() ||
 681       (klass->is_instance_klass() &&
 682        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 683     ResourceMark rm(THREAD);
 684     THROW_MSG_NULL(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 685   }
 686 






 687   // Make shallow object copy
 688   const size_t size = obj->size();
 689   oop new_obj_oop = nullptr;
 690   if (obj->is_array()) {
 691     const int length = ((arrayOop)obj())->length();
 692     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 693                                                    /* do_zero */ true, CHECK_NULL);
 694   } else {
 695     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 696   }
 697 
 698   HeapAccess<>::clone(obj(), new_obj_oop, size);
 699 
 700   Handle new_obj(THREAD, new_obj_oop);
 701   // Caution: this involves a java upcall, so the clone should be
 702   // "gc-robust" by this stage.
 703   if (klass->has_finalizer()) {
 704     assert(obj->is_instance(), "should be instanceOop");
 705     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 706     new_obj = Handle(THREAD, new_obj_oop);

1159   oop result = java_lang_Class::name(java_class, CHECK_NULL);
1160   return (jstring) JNIHandles::make_local(THREAD, result);
1161 JVM_END
1162 
1163 
1164 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1165   JvmtiVMObjectAllocEventCollector oam;
1166   oop mirror = JNIHandles::resolve_non_null(cls);
1167 
1168   // Special handling for primitive objects
1169   if (java_lang_Class::is_primitive(mirror)) {
1170     // Primitive objects does not have any interfaces
1171     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1172     return (jobjectArray) JNIHandles::make_local(THREAD, r);
1173   }
1174 
1175   Klass* klass = java_lang_Class::as_Klass(mirror);
1176   // Figure size of result array
1177   int size;
1178   if (klass->is_instance_klass()) {
1179     size = InstanceKlass::cast(klass)->local_interfaces()->length();

1180   } else {
1181     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1182     size = 2;
1183   }
1184 
1185   // Allocate result array
1186   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1187   objArrayHandle result (THREAD, r);
1188   // Fill in result
1189   if (klass->is_instance_klass()) {
1190     // Regular instance klass, fill in all local interfaces
1191     for (int index = 0; index < size; index++) {
1192       InstanceKlass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
1193       result->obj_at_put(index, k->java_mirror());
1194     }
1195   } else {
1196     // All arrays implement java.lang.Cloneable and java.io.Serializable
1197     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1198     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1199   }

1663   }
1664 
1665   InstanceKlass* k = java_lang_Class::as_InstanceKlass(ofMirror);
1666 
1667   // Ensure class is linked
1668   k->link_class(CHECK_NULL);
1669 
1670   Array<Method*>* methods = k->methods();
1671   int methods_length = methods->length();
1672 
1673   // Save original method_idnum in case of redefinition, which can change
1674   // the idnum of obsolete methods.  The new method will have the same idnum
1675   // but if we refresh the methods array, the counts will be wrong.
1676   ResourceMark rm(THREAD);
1677   GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
1678   int num_methods = 0;
1679 
1680   // Select methods matching the criteria.
1681   for (int i = 0; i < methods_length; i++) {
1682     Method* method = methods->at(i);
1683     if (want_constructor && !method->is_object_initializer()) {
1684       continue;
1685     }
1686     if (!want_constructor &&
1687         (method->is_object_initializer() || method->is_static_initializer() ||
1688          method->is_overpass())) {
1689       continue;
1690     }
1691     if (publicOnly && !method->is_public()) {
1692       continue;
1693     }
1694     idnums->push(method->method_idnum());
1695     ++num_methods;
1696   }
1697 
1698   // Allocate result
1699   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1700   objArrayHandle result (THREAD, r);
1701 
1702   // Now just put the methods that we selected above, but go by their idnum
1703   // in case of redefinition.  The methods can be redefined at any safepoint,
1704   // so above when allocating the oop array and below when creating reflect
1705   // objects.
1706   for (int i = 0; i < num_methods; i++) {
1707     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1708     if (method.is_null()) {
1709       // Method may have been deleted and seems this API can handle null
1710       // Otherwise should probably put a method that throws NSME
1711       result->obj_at_put(i, nullptr);
1712     } else {
1713       oop m;
1714       if (want_constructor) {

1715         m = Reflection::new_constructor(method, CHECK_NULL);
1716       } else {
1717         m = Reflection::new_method(method, false, CHECK_NULL);
1718       }
1719       result->obj_at_put(i, m);
1720     }
1721   }
1722 
1723   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1724 }
1725 
1726 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1727 {
1728   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1729                                            /*want_constructor*/ false,
1730                                            vmClasses::reflect_Method_klass(), THREAD);
1731 }
1732 JVM_END
1733 
1734 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

1955   constantTag tag = cp->tag_at(index);
1956   if (!tag.is_method() && !tag.is_interface_method()) {
1957     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1958   }
1959   int klass_ref  = cp->uncached_klass_ref_index_at(index);
1960   Klass* k_o;
1961   if (force_resolution) {
1962     k_o = cp->klass_at(klass_ref, CHECK_NULL);
1963   } else {
1964     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
1965     if (k_o == nullptr) return nullptr;
1966   }
1967   InstanceKlass* k = InstanceKlass::cast(k_o);
1968   Symbol* name = cp->uncached_name_ref_at(index);
1969   Symbol* sig  = cp->uncached_signature_ref_at(index);
1970   methodHandle m (THREAD, k->find_method(name, sig));
1971   if (m.is_null()) {
1972     THROW_MSG_NULL(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
1973   }
1974   oop method;
1975   if (m->is_object_initializer()) {
1976     method = Reflection::new_constructor(m, CHECK_NULL);
1977   } else {
1978     // new_method accepts <clinit> as Method here
1979     method = Reflection::new_method(m, true, CHECK_NULL);
1980   }
1981   return JNIHandles::make_local(THREAD, method);
1982 }
1983 
1984 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jint index))
1985 {
1986   JvmtiVMObjectAllocEventCollector oam;
1987   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1988   bounds_check(cp, index, CHECK_NULL);
1989   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
1990   return res;
1991 }
1992 JVM_END
1993 
1994 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jint index))
1995 {
1996   JvmtiVMObjectAllocEventCollector oam;
1997   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1998   bounds_check(cp, index, CHECK_NULL);

2405 
2406 
2407 JVM_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
2408   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2409   Method* method = ik->methods()->at(method_index);
2410   return method->size_of_parameters();
2411 JVM_END
2412 
2413 
2414 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2415   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2416   Method* method = ik->methods()->at(method_index);
2417   return method->verifier_max_stack();
2418 JVM_END
2419 
2420 
2421 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2422   ResourceMark rm(THREAD);
2423   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2424   Method* method = ik->methods()->at(method_index);
2425   return method->name() == vmSymbols::object_initializer_name();
2426 JVM_END
2427 
2428 
2429 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2430   ResourceMark rm(THREAD);
2431   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2432   Method* method = ik->methods()->at(method_index);
2433   return method->is_overpass();
2434 JVM_END
2435 
2436 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2437   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2438   Method* method = ik->methods()->at(method_index);
2439   return method->name()->as_utf8();
2440 JVM_END
2441 
2442 
2443 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
2444   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2445   Method* method = ik->methods()->at(method_index);

3199 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3200   void* find_result = os::dll_lookup(handle, name);
3201   log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3202                     find_result != nullptr ? "Found" : "Failed to find",
3203                     name, p2i(handle));
3204   return find_result;
3205 JVM_END
3206 
3207 
3208 // JNI version ///////////////////////////////////////////////////////////////////////////////
3209 
3210 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3211   return Threads::is_supported_jni_version_including_1_1(version);
3212 JVM_END
3213 
3214 
3215 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3216   return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3217 JVM_END
3218 




3219 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3220   return VMContinuations ? JNI_TRUE : JNI_FALSE;
3221 JVM_END
3222 
3223 JVM_LEAF(jboolean, JVM_IsForeignLinkerSupported(void))
3224   return ForeignGlobals::is_foreign_linker_supported() ? JNI_TRUE : JNI_FALSE;
3225 JVM_END
3226 
3227 JVM_LEAF(jboolean, JVM_IsStaticallyLinked(void))
3228   return is_vm_statically_linked() ? JNI_TRUE : JNI_FALSE;
3229 JVM_END
3230 
3231 // String support ///////////////////////////////////////////////////////////////////////////
3232 
3233 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3234   JvmtiVMObjectAllocEventCollector oam;
3235   if (str == nullptr) return nullptr;
3236   oop string = JNIHandles::resolve_non_null(str);
3237   oop result = StringTable::intern(string, CHECK_NULL);
3238   return (jstring) JNIHandles::make_local(THREAD, result);

3278 
3279 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3280                                     Handle loader, jboolean throwError, TRAPS) {
3281   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, throwError != 0, CHECK_NULL);
3282 
3283   // Check if we should initialize the class
3284   if (init && klass->is_instance_klass()) {
3285     klass->initialize(CHECK_NULL);
3286   }
3287   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3288 }
3289 
3290 
3291 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3292 
3293 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3294   Handle method_handle;
3295   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3296     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3297     Handle receiver(THREAD, JNIHandles::resolve(obj));
3298     objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));


3299     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3300     jobject res = JNIHandles::make_local(THREAD, result);
3301     if (JvmtiExport::should_post_vm_object_alloc()) {
3302       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3303       assert(ret_type != nullptr, "sanity check: ret_type oop must not be null!");
3304       if (java_lang_Class::is_primitive(ret_type)) {
3305         // Only for primitive type vm allocates memory for java object.
3306         // See box() method.
3307         JvmtiExport::post_vm_object_alloc(thread, result);
3308       }
3309     }
3310     return res;
3311   } else {
3312     THROW_NULL(vmSymbols::java_lang_StackOverflowError());
3313   }
3314 JVM_END
3315 
3316 
3317 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))


3318   oop constructor_mirror = JNIHandles::resolve(c);
3319   objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3320   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3321   jobject res = JNIHandles::make_local(THREAD, result);
3322   if (JvmtiExport::should_post_vm_object_alloc()) {
3323     JvmtiExport::post_vm_object_alloc(thread, result);
3324   }
3325   return res;
3326 JVM_END
3327 
3328 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3329   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3330   HeapShared::initialize_from_archived_subgraph(THREAD, k);
3331 JVM_END
3332 
3333 JVM_ENTRY(void, JVM_RegisterLambdaProxyClassForArchiving(JNIEnv* env,
3334                                               jclass caller,
3335                                               jstring interfaceMethodName,
3336                                               jobject factoryType,
3337                                               jobject interfaceMethodType,
3338                                               jobject implementationMember,
3339                                               jobject dynamicMethodType,

3536   JvmtiVMObjectAllocEventCollector oam;
3537 
3538   // Check if threads is null
3539   if (threads == nullptr) {
3540     THROW_NULL(vmSymbols::java_lang_NullPointerException());
3541   }
3542 
3543   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads));
3544   objArrayHandle ah(THREAD, a);
3545   int num_threads = ah->length();
3546   // check if threads is non-empty array
3547   if (num_threads == 0) {
3548     THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3549   }
3550 
3551   // check if threads is not an array of objects of Thread class
3552   Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass();
3553   if (k != vmClasses::Thread_klass()) {
3554     THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3555   }

3556 
3557   ResourceMark rm(THREAD);
3558 
3559   GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
3560   for (int i = 0; i < num_threads; i++) {
3561     oop thread_obj = ah->obj_at(i);
3562     instanceHandle h(THREAD, (instanceOop) thread_obj);
3563     thread_handle_array->append(h);
3564   }
3565 
3566   // The JavaThread references in thread_handle_array are validated
3567   // in VM_ThreadDump::doit().
3568   Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL);
3569   return (jobjectArray)JNIHandles::make_local(THREAD, stacktraces());
3570 
3571 JVM_END
3572 
3573 // JVM monitoring and management support
3574 JVM_LEAF(void*, JVM_GetManagement(jint version))
3575   return Management::get_jmm_interface(version);
3576 JVM_END
3577 
3578 // com.sun.tools.attach.VirtualMachine agent properties support
3579 //
3580 // Initialize the agent properties with the properties maintained in the VM
3581 JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties))

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

 412 
 413   return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
 414 JVM_END
 415 
 416 
 417 /*
 418  * Return the temporary directory that the VM uses for the attach
 419  * and perf data files.
 420  *
 421  * It is important that this directory is well-known and the
 422  * same for all VM instances. It cannot be affected by configuration
 423  * variables such as java.io.tmpdir.
 424  */
 425 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
 426   HandleMark hm(THREAD);
 427   const char* temp_dir = os::get_temp_directory();
 428   Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
 429   return (jstring) JNIHandles::make_local(THREAD, h());
 430 JVM_END
 431 
 432 static void validate_array_arguments(Klass* elmClass, jint len, TRAPS) {
 433   if (len < 0) {
 434     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Array length is negative");
 435   }
 436   elmClass->initialize(CHECK);
 437   if (elmClass->is_array_klass() || elmClass->is_identity_class()) {
 438     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Element class is not a value class");
 439   }
 440   if (elmClass->is_abstract()) {
 441     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Element class is abstract");
 442   }
 443 }
 444 
 445 JVM_ENTRY(jarray, JVM_CopyOfSpecialArray(JNIEnv *env, jarray orig, jint from, jint to))
 446   oop o = JNIHandles::resolve_non_null(orig);
 447   assert(o->is_array(), "Must be");
 448   oop array = nullptr;
 449   arrayOop org = (arrayOop)o;
 450   arrayHandle oh(THREAD, org);
 451   ObjArrayKlass* ak = ObjArrayKlass::cast(org->klass());
 452   InlineKlass* vk = InlineKlass::cast(ak->element_klass());
 453   int len = to - from;  // length of the new array
 454   if (ak->is_null_free_array_klass()) {
 455     if ((len != 0) && (from >= org->length() || to > org->length())) {
 456       THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Copying of null-free array with uninitialized elements");
 457     }
 458   }
 459   if (org->is_flatArray()) {
 460     FlatArrayKlass* fak = FlatArrayKlass::cast(org->klass());
 461     LayoutKind lk = fak->layout_kind();
 462     ArrayKlass::ArrayProperties props = ArrayKlass::array_properties_from_layout(lk);
 463     array = oopFactory::new_flatArray(vk, len, props, lk, CHECK_NULL);
 464     arrayHandle ah(THREAD, (arrayOop)array);
 465     int end = to < oh()->length() ? to : oh()->length();
 466     for (int i = from; i < end; i++) {
 467       void* src = ((flatArrayOop)oh())->value_at_addr(i, fak->layout_helper());
 468       void* dst = ((flatArrayOop)ah())->value_at_addr(i - from, fak->layout_helper());
 469       vk->copy_payload_to_addr(src, dst, lk, false);
 470     }
 471     array = ah();
 472   } else {
 473     ArrayKlass::ArrayProperties props = org->is_null_free_array() ? ArrayKlass::ArrayProperties::NULL_RESTRICTED : ArrayKlass::ArrayProperties::DEFAULT;
 474     array = oopFactory::new_objArray(vk, len, props,  CHECK_NULL);
 475     int end = to < oh()->length() ? to : oh()->length();
 476     for (int i = from; i < end; i++) {
 477       if (i < ((objArrayOop)oh())->length()) {
 478         ((objArrayOop)array)->obj_at_put(i - from, ((objArrayOop)oh())->obj_at(i));
 479       } else {
 480         assert(!ak->is_null_free_array_klass(), "Must be a nullable array");
 481         ((objArrayOop)array)->obj_at_put(i - from, nullptr);
 482       }
 483     }
 484   }
 485   return (jarray) JNIHandles::make_local(THREAD, array);
 486 JVM_END
 487 
 488 JVM_ENTRY(jarray, JVM_NewNullRestrictedNonAtomicArray(JNIEnv *env, jclass elmClass, jint len, jobject initVal))
 489   oop mirror = JNIHandles::resolve_non_null(elmClass);
 490   oop init = JNIHandles::resolve(initVal);
 491   if (init == nullptr) {
 492     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Initial value cannot be null");
 493   }
 494   Handle init_h(THREAD, init);
 495   Klass* klass = java_lang_Class::as_Klass(mirror);
 496   if (klass != init_h()->klass()) {
 497     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Type mismatch between array and initial value");
 498   }
 499   validate_array_arguments(klass, len, CHECK_NULL);
 500   InlineKlass* vk = InlineKlass::cast(klass);
 501   ArrayKlass::ArrayProperties props = (ArrayKlass::ArrayProperties)(ArrayKlass::ArrayProperties::NON_ATOMIC | ArrayKlass::ArrayProperties::NULL_RESTRICTED);
 502   objArrayOop array = oopFactory::new_objArray(klass, len, props, CHECK_NULL);
 503   for (int i = 0; i < len; i++) {
 504     array->obj_at_put(i, init_h() /*, CHECK_NULL*/ );
 505   }
 506   return (jarray) JNIHandles::make_local(THREAD, array);
 507 JVM_END
 508 
 509 JVM_ENTRY(jarray, JVM_NewNullRestrictedAtomicArray(JNIEnv *env, jclass elmClass, jint len, jobject initVal))
 510   oop mirror = JNIHandles::resolve_non_null(elmClass);
 511   oop init = JNIHandles::resolve(initVal);
 512   if (init == nullptr) {
 513     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Initial value cannot be null");
 514   }
 515   Handle init_h(THREAD, init);
 516   Klass* klass = java_lang_Class::as_Klass(mirror);
 517   if (klass != init_h()->klass()) {
 518     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Type mismatch between array and initial value");
 519   }
 520   validate_array_arguments(klass, len, CHECK_NULL);
 521   InlineKlass* vk = InlineKlass::cast(klass);
 522   ArrayKlass::ArrayProperties props = (ArrayKlass::ArrayProperties)(ArrayKlass::ArrayProperties::NULL_RESTRICTED);
 523   objArrayOop array = oopFactory::new_objArray(klass, len, props, CHECK_NULL);
 524   for (int i = 0; i < len; i++) {
 525     array->obj_at_put(i, init_h() /*, CHECK_NULL*/ );
 526   }
 527   return (jarray) JNIHandles::make_local(THREAD, array);
 528 JVM_END
 529 
 530 JVM_ENTRY(jarray, JVM_NewNullableAtomicArray(JNIEnv *env, jclass elmClass, jint len))
 531   oop mirror = JNIHandles::resolve_non_null(elmClass);
 532   Klass* klass = java_lang_Class::as_Klass(mirror);
 533   klass->initialize(CHECK_NULL);
 534   validate_array_arguments(klass, len, CHECK_NULL);
 535   InlineKlass* vk = InlineKlass::cast(klass);
 536   ArrayKlass::ArrayProperties props = (ArrayKlass::ArrayProperties)(ArrayKlass::ArrayProperties::DEFAULT);
 537   objArrayOop array = oopFactory::new_objArray(klass, len, props, CHECK_NULL);
 538   return (jarray) JNIHandles::make_local(THREAD, array);
 539 JVM_END
 540 
 541 JVM_ENTRY(jboolean, JVM_IsFlatArray(JNIEnv *env, jobject obj))
 542   arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
 543   return oop->is_flatArray();
 544 JVM_END
 545 
 546 JVM_ENTRY(jboolean, JVM_IsNullRestrictedArray(JNIEnv *env, jobject obj))
 547   arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
 548   return oop->is_null_free_array();
 549 JVM_END
 550 
 551 JVM_ENTRY(jboolean, JVM_IsAtomicArray(JNIEnv *env, jobject obj))
 552   // There are multiple cases where an array can/must support atomic access:
 553   //   - the array is a reference array
 554   //   - the array uses an atomic flat layout: NULLABLE_ATOMIC_FLAT or NULL_FREE_ATOMIC_FLAT
 555   //   - the array is flat and its component type is naturally atomic
 556   arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
 557   if (oop->is_refArray()) return true;
 558   if (oop->is_flatArray()) {
 559     FlatArrayKlass* fak = FlatArrayKlass::cast(oop->klass());
 560     if (LayoutKindHelper::is_atomic_flat(fak->layout_kind())) return true;
 561     if (fak->element_klass()->is_naturally_atomic()) return true;
 562   }
 563   return false;
 564 JVM_END
 565 
 566 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
 567 
 568 extern volatile jint vm_created;
 569 
 570 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
 571   EventShutdown event;
 572   if (event.should_commit()) {
 573     event.set_reason("Shutdown requested from Java");
 574     event.commit();
 575   }
 576 JVM_END
 577 
 578 
 579 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
 580   before_exit(thread, true);
 581   vm_exit(code);
 582 JVM_END
 583 
 584 

 753 
 754   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 755   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, last_batch_count, buffer_size,
 756                                   start_index, frames_array_h, THREAD);
 757 JVM_END
 758 
 759 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 760   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 761   objArrayHandle frames_array_h(THREAD, fa);
 762   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 763   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 764 
 765   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 766 JVM_END
 767 
 768 // java.lang.Object ///////////////////////////////////////////////
 769 
 770 
 771 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 772   // as implemented in the classic virtual machine; return 0 if object is null
 773   if (handle == nullptr) {
 774     return 0;
 775   }
 776   oop obj = JNIHandles::resolve_non_null(handle);
 777   if (Arguments::is_valhalla_enabled() && obj->klass()->is_inline_klass()) {
 778       JavaValue result(T_INT);
 779       JavaCallArguments args;
 780       Handle ho(THREAD, obj);
 781       args.push_oop(ho);
 782       methodHandle method(THREAD, UseAltSubstitutabilityMethod
 783               ? Universe::value_object_hash_codeAlt_method() : Universe::value_object_hash_code_method());
 784       JavaCalls::call(&result, method, &args, THREAD);
 785       if (HAS_PENDING_EXCEPTION) {
 786         if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
 787           Handle e(THREAD, PENDING_EXCEPTION);
 788           CLEAR_PENDING_EXCEPTION;
 789           THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in hashCode", e, false);
 790         }
 791       }
 792       return result.get_jint();
 793   } else {
 794     return checked_cast<jint>(ObjectSynchronizer::FastHashCode(THREAD, obj));
 795   }
 796 JVM_END
 797 
 798 
 799 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 800   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 801   ObjectSynchronizer::wait(obj, ms, CHECK);
 802 JVM_END
 803 
 804 
 805 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 806   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 807   ObjectSynchronizer::notify(obj, CHECK);
 808 JVM_END
 809 
 810 
 811 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 812   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 813   ObjectSynchronizer::notifyall(obj, CHECK);
 814 JVM_END
 815 

 823   // Just checking that the cloneable flag is set correct
 824   if (obj->is_array()) {
 825     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 826   } else {
 827     guarantee(obj->is_instance(), "should be instanceOop");
 828     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 829     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 830   }
 831 #endif
 832 
 833   // Check if class of obj supports the Cloneable interface.
 834   // All arrays are considered to be cloneable (See JLS 20.1.5).
 835   // All j.l.r.Reference classes are considered non-cloneable.
 836   if (!klass->is_cloneable() ||
 837       (klass->is_instance_klass() &&
 838        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 839     ResourceMark rm(THREAD);
 840     THROW_MSG_NULL(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 841   }
 842 
 843   if (klass->is_inline_klass()) {
 844     // Value instances have no identity, so return the current instance instead of allocating a new one
 845     // Value classes cannot have finalizers, so the method can return immediately
 846     return JNIHandles::make_local(THREAD, obj());
 847   }
 848 
 849   // Make shallow object copy
 850   const size_t size = obj->size();
 851   oop new_obj_oop = nullptr;
 852   if (obj->is_array()) {
 853     const int length = ((arrayOop)obj())->length();
 854     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 855                                                    /* do_zero */ true, CHECK_NULL);
 856   } else {
 857     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 858   }
 859 
 860   HeapAccess<>::clone(obj(), new_obj_oop, size);
 861 
 862   Handle new_obj(THREAD, new_obj_oop);
 863   // Caution: this involves a java upcall, so the clone should be
 864   // "gc-robust" by this stage.
 865   if (klass->has_finalizer()) {
 866     assert(obj->is_instance(), "should be instanceOop");
 867     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 868     new_obj = Handle(THREAD, new_obj_oop);

1321   oop result = java_lang_Class::name(java_class, CHECK_NULL);
1322   return (jstring) JNIHandles::make_local(THREAD, result);
1323 JVM_END
1324 
1325 
1326 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1327   JvmtiVMObjectAllocEventCollector oam;
1328   oop mirror = JNIHandles::resolve_non_null(cls);
1329 
1330   // Special handling for primitive objects
1331   if (java_lang_Class::is_primitive(mirror)) {
1332     // Primitive objects does not have any interfaces
1333     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1334     return (jobjectArray) JNIHandles::make_local(THREAD, r);
1335   }
1336 
1337   Klass* klass = java_lang_Class::as_Klass(mirror);
1338   // Figure size of result array
1339   int size;
1340   if (klass->is_instance_klass()) {
1341     InstanceKlass* ik = InstanceKlass::cast(klass);
1342     size = ik->local_interfaces()->length();
1343   } else {
1344     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1345     size = 2;
1346   }
1347 
1348   // Allocate result array
1349   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1350   objArrayHandle result (THREAD, r);
1351   // Fill in result
1352   if (klass->is_instance_klass()) {
1353     // Regular instance klass, fill in all local interfaces
1354     for (int index = 0; index < size; index++) {
1355       InstanceKlass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
1356       result->obj_at_put(index, k->java_mirror());
1357     }
1358   } else {
1359     // All arrays implement java.lang.Cloneable and java.io.Serializable
1360     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1361     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1362   }

1826   }
1827 
1828   InstanceKlass* k = java_lang_Class::as_InstanceKlass(ofMirror);
1829 
1830   // Ensure class is linked
1831   k->link_class(CHECK_NULL);
1832 
1833   Array<Method*>* methods = k->methods();
1834   int methods_length = methods->length();
1835 
1836   // Save original method_idnum in case of redefinition, which can change
1837   // the idnum of obsolete methods.  The new method will have the same idnum
1838   // but if we refresh the methods array, the counts will be wrong.
1839   ResourceMark rm(THREAD);
1840   GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
1841   int num_methods = 0;
1842 
1843   // Select methods matching the criteria.
1844   for (int i = 0; i < methods_length; i++) {
1845     Method* method = methods->at(i);
1846     if (want_constructor && !method->is_object_constructor()) {
1847       continue;
1848     }
1849     if (!want_constructor &&
1850         (method->is_object_constructor() || method->is_class_initializer() ||
1851          method->is_overpass())) {
1852       continue;
1853     }
1854     if (publicOnly && !method->is_public()) {
1855       continue;
1856     }
1857     idnums->push(method->method_idnum());
1858     ++num_methods;
1859   }
1860 
1861   // Allocate result
1862   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1863   objArrayHandle result (THREAD, r);
1864 
1865   // Now just put the methods that we selected above, but go by their idnum
1866   // in case of redefinition.  The methods can be redefined at any safepoint,
1867   // so above when allocating the oop array and below when creating reflect
1868   // objects.
1869   for (int i = 0; i < num_methods; i++) {
1870     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1871     if (method.is_null()) {
1872       // Method may have been deleted and seems this API can handle null
1873       // Otherwise should probably put a method that throws NSME
1874       result->obj_at_put(i, nullptr);
1875     } else {
1876       oop m;
1877       if (want_constructor) {
1878         assert(method->is_object_constructor(), "must be");
1879         m = Reflection::new_constructor(method, CHECK_NULL);
1880       } else {
1881         m = Reflection::new_method(method, false, CHECK_NULL);
1882       }
1883       result->obj_at_put(i, m);
1884     }
1885   }
1886 
1887   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1888 }
1889 
1890 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1891 {
1892   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1893                                            /*want_constructor*/ false,
1894                                            vmClasses::reflect_Method_klass(), THREAD);
1895 }
1896 JVM_END
1897 
1898 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

2119   constantTag tag = cp->tag_at(index);
2120   if (!tag.is_method() && !tag.is_interface_method()) {
2121     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2122   }
2123   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2124   Klass* k_o;
2125   if (force_resolution) {
2126     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2127   } else {
2128     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2129     if (k_o == nullptr) return nullptr;
2130   }
2131   InstanceKlass* k = InstanceKlass::cast(k_o);
2132   Symbol* name = cp->uncached_name_ref_at(index);
2133   Symbol* sig  = cp->uncached_signature_ref_at(index);
2134   methodHandle m (THREAD, k->find_method(name, sig));
2135   if (m.is_null()) {
2136     THROW_MSG_NULL(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2137   }
2138   oop method;
2139   if (m->is_object_constructor()) {
2140     method = Reflection::new_constructor(m, CHECK_NULL);
2141   } else {

2142     method = Reflection::new_method(m, true, CHECK_NULL);
2143   }
2144   return JNIHandles::make_local(THREAD, method);
2145 }
2146 
2147 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jint index))
2148 {
2149   JvmtiVMObjectAllocEventCollector oam;
2150   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2151   bounds_check(cp, index, CHECK_NULL);
2152   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2153   return res;
2154 }
2155 JVM_END
2156 
2157 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jint index))
2158 {
2159   JvmtiVMObjectAllocEventCollector oam;
2160   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2161   bounds_check(cp, index, CHECK_NULL);

2568 
2569 
2570 JVM_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
2571   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2572   Method* method = ik->methods()->at(method_index);
2573   return method->size_of_parameters();
2574 JVM_END
2575 
2576 
2577 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2578   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2579   Method* method = ik->methods()->at(method_index);
2580   return method->verifier_max_stack();
2581 JVM_END
2582 
2583 
2584 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2585   ResourceMark rm(THREAD);
2586   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2587   Method* method = ik->methods()->at(method_index);
2588   return method->is_object_constructor();
2589 JVM_END
2590 
2591 
2592 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2593   ResourceMark rm(THREAD);
2594   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2595   Method* method = ik->methods()->at(method_index);
2596   return method->is_overpass();
2597 JVM_END
2598 
2599 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2600   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2601   Method* method = ik->methods()->at(method_index);
2602   return method->name()->as_utf8();
2603 JVM_END
2604 
2605 
2606 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
2607   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2608   Method* method = ik->methods()->at(method_index);

3362 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3363   void* find_result = os::dll_lookup(handle, name);
3364   log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3365                     find_result != nullptr ? "Found" : "Failed to find",
3366                     name, p2i(handle));
3367   return find_result;
3368 JVM_END
3369 
3370 
3371 // JNI version ///////////////////////////////////////////////////////////////////////////////
3372 
3373 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3374   return Threads::is_supported_jni_version_including_1_1(version);
3375 JVM_END
3376 
3377 
3378 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3379   return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3380 JVM_END
3381 
3382 JVM_LEAF(jboolean, JVM_IsValhallaEnabled(void))
3383   return Arguments::is_valhalla_enabled() ? JNI_TRUE : JNI_FALSE;
3384 JVM_END
3385 
3386 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3387   return VMContinuations ? JNI_TRUE : JNI_FALSE;
3388 JVM_END
3389 
3390 JVM_LEAF(jboolean, JVM_IsForeignLinkerSupported(void))
3391   return ForeignGlobals::is_foreign_linker_supported() ? JNI_TRUE : JNI_FALSE;
3392 JVM_END
3393 
3394 JVM_LEAF(jboolean, JVM_IsStaticallyLinked(void))
3395   return is_vm_statically_linked() ? JNI_TRUE : JNI_FALSE;
3396 JVM_END
3397 
3398 // String support ///////////////////////////////////////////////////////////////////////////
3399 
3400 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3401   JvmtiVMObjectAllocEventCollector oam;
3402   if (str == nullptr) return nullptr;
3403   oop string = JNIHandles::resolve_non_null(str);
3404   oop result = StringTable::intern(string, CHECK_NULL);
3405   return (jstring) JNIHandles::make_local(THREAD, result);

3445 
3446 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3447                                     Handle loader, jboolean throwError, TRAPS) {
3448   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, throwError != 0, CHECK_NULL);
3449 
3450   // Check if we should initialize the class
3451   if (init && klass->is_instance_klass()) {
3452     klass->initialize(CHECK_NULL);
3453   }
3454   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3455 }
3456 
3457 
3458 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3459 
3460 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3461   Handle method_handle;
3462   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3463     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3464     Handle receiver(THREAD, JNIHandles::resolve(obj));
3465     objArrayHandle args(THREAD, (objArrayOop)JNIHandles::resolve(args0));
3466     assert(args() == nullptr || !args->is_flatArray(), "args are never flat or are they???");
3467 
3468     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3469     jobject res = JNIHandles::make_local(THREAD, result);
3470     if (JvmtiExport::should_post_vm_object_alloc()) {
3471       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3472       assert(ret_type != nullptr, "sanity check: ret_type oop must not be null!");
3473       if (java_lang_Class::is_primitive(ret_type)) {
3474         // Only for primitive type vm allocates memory for java object.
3475         // See box() method.
3476         JvmtiExport::post_vm_object_alloc(thread, result);
3477       }
3478     }
3479     return res;
3480   } else {
3481     THROW_NULL(vmSymbols::java_lang_StackOverflowError());
3482   }
3483 JVM_END
3484 
3485 
3486 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3487   objArrayHandle args(THREAD, (objArrayOop)JNIHandles::resolve(args0));
3488   assert(args() == nullptr || !args->is_flatArray(), "args are never flat or are they???");
3489   oop constructor_mirror = JNIHandles::resolve(c);

3490   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3491   jobject res = JNIHandles::make_local(THREAD, result);
3492   if (JvmtiExport::should_post_vm_object_alloc()) {
3493     JvmtiExport::post_vm_object_alloc(thread, result);
3494   }
3495   return res;
3496 JVM_END
3497 
3498 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3499   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3500   HeapShared::initialize_from_archived_subgraph(THREAD, k);
3501 JVM_END
3502 
3503 JVM_ENTRY(void, JVM_RegisterLambdaProxyClassForArchiving(JNIEnv* env,
3504                                               jclass caller,
3505                                               jstring interfaceMethodName,
3506                                               jobject factoryType,
3507                                               jobject interfaceMethodType,
3508                                               jobject implementationMember,
3509                                               jobject dynamicMethodType,

3706   JvmtiVMObjectAllocEventCollector oam;
3707 
3708   // Check if threads is null
3709   if (threads == nullptr) {
3710     THROW_NULL(vmSymbols::java_lang_NullPointerException());
3711   }
3712 
3713   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads));
3714   objArrayHandle ah(THREAD, a);
3715   int num_threads = ah->length();
3716   // check if threads is non-empty array
3717   if (num_threads == 0) {
3718     THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3719   }
3720 
3721   // check if threads is not an array of objects of Thread class
3722   Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass();
3723   if (k != vmClasses::Thread_klass()) {
3724     THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3725   }
3726   refArrayHandle rah(THREAD, (refArrayOop)ah()); // j.l.Thread is an identity class, arrays are always reference arrays
3727 
3728   ResourceMark rm(THREAD);
3729 
3730   GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
3731   for (int i = 0; i < num_threads; i++) {
3732     oop thread_obj = rah->obj_at(i);
3733     instanceHandle h(THREAD, (instanceOop) thread_obj);
3734     thread_handle_array->append(h);
3735   }
3736 
3737   // The JavaThread references in thread_handle_array are validated
3738   // in VM_ThreadDump::doit().
3739   Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL);
3740   return (jobjectArray)JNIHandles::make_local(THREAD, stacktraces());
3741 
3742 JVM_END
3743 
3744 // JVM monitoring and management support
3745 JVM_LEAF(void*, JVM_GetManagement(jint version))
3746   return Management::get_jmm_interface(version);
3747 JVM_END
3748 
3749 // com.sun.tools.attach.VirtualMachine agent properties support
3750 //
3751 // Initialize the agent properties with the properties maintained in the VM
3752 JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties))
< prev index next >