< 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/os.inline.hpp"

 396 
 397   return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
 398 JVM_END
 399 
 400 
 401 /*
 402  * Return the temporary directory that the VM uses for the attach
 403  * and perf data files.
 404  *
 405  * It is important that this directory is well-known and the
 406  * same for all VM instances. It cannot be affected by configuration
 407  * variables such as java.io.tmpdir.
 408  */
 409 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
 410   HandleMark hm(THREAD);
 411   const char* temp_dir = os::get_temp_directory();
 412   Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
 413   return (jstring) JNIHandles::make_local(THREAD, h());
 414 JVM_END
 415 





































































































































 416 
 417 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
 418 
 419 extern volatile jint vm_created;
 420 
 421 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
 422   EventShutdown event;
 423   if (event.should_commit()) {
 424     event.set_reason("Shutdown requested from Java");
 425     event.commit();
 426   }
 427 JVM_END
 428 
 429 
 430 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
 431   before_exit(thread, true);
 432   vm_exit(code);
 433 JVM_END
 434 
 435 

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





















 626 JVM_END
 627 
 628 
 629 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 630   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 631   ObjectSynchronizer::wait(obj, ms, CHECK);
 632 JVM_END
 633 
 634 
 635 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 636   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 637   ObjectSynchronizer::notify(obj, CHECK);
 638 JVM_END
 639 
 640 
 641 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 642   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 643   ObjectSynchronizer::notifyall(obj, CHECK);
 644 JVM_END
 645 

 653   // Just checking that the cloneable flag is set correct
 654   if (obj->is_array()) {
 655     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 656   } else {
 657     guarantee(obj->is_instance(), "should be instanceOop");
 658     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 659     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 660   }
 661 #endif
 662 
 663   // Check if class of obj supports the Cloneable interface.
 664   // All arrays are considered to be cloneable (See JLS 20.1.5).
 665   // All j.l.r.Reference classes are considered non-cloneable.
 666   if (!klass->is_cloneable() ||
 667       (klass->is_instance_klass() &&
 668        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 669     ResourceMark rm(THREAD);
 670     THROW_MSG_NULL(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 671   }
 672 






 673   // Make shallow object copy
 674   const size_t size = obj->size();
 675   oop new_obj_oop = nullptr;
 676   if (obj->is_array()) {
 677     const int length = ((arrayOop)obj())->length();
 678     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 679                                                    /* do_zero */ true, CHECK_NULL);
 680   } else {
 681     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 682   }
 683 
 684   HeapAccess<>::clone(obj(), new_obj_oop, size);
 685 
 686   Handle new_obj(THREAD, new_obj_oop);
 687   // Caution: this involves a java upcall, so the clone should be
 688   // "gc-robust" by this stage.
 689   if (klass->has_finalizer()) {
 690     assert(obj->is_instance(), "should be instanceOop");
 691     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 692     new_obj = Handle(THREAD, new_obj_oop);

1145   oop result = java_lang_Class::name(java_class, CHECK_NULL);
1146   return (jstring) JNIHandles::make_local(THREAD, result);
1147 JVM_END
1148 
1149 
1150 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1151   JvmtiVMObjectAllocEventCollector oam;
1152   oop mirror = JNIHandles::resolve_non_null(cls);
1153 
1154   // Special handling for primitive objects
1155   if (java_lang_Class::is_primitive(mirror)) {
1156     // Primitive objects does not have any interfaces
1157     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1158     return (jobjectArray) JNIHandles::make_local(THREAD, r);
1159   }
1160 
1161   Klass* klass = java_lang_Class::as_Klass(mirror);
1162   // Figure size of result array
1163   int size;
1164   if (klass->is_instance_klass()) {
1165     size = InstanceKlass::cast(klass)->local_interfaces()->length();

1166   } else {
1167     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1168     size = 2;
1169   }
1170 
1171   // Allocate result array
1172   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1173   objArrayHandle result (THREAD, r);
1174   // Fill in result
1175   if (klass->is_instance_klass()) {
1176     // Regular instance klass, fill in all local interfaces
1177     for (int index = 0; index < size; index++) {
1178       InstanceKlass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
1179       result->obj_at_put(index, k->java_mirror());
1180     }
1181   } else {
1182     // All arrays implement java.lang.Cloneable and java.io.Serializable
1183     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1184     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1185   }
1186   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1187 JVM_END
1188 
1189 
1190 JVM_ENTRY(jboolean, JVM_IsHiddenClass(JNIEnv *env, jclass cls))
1191   oop mirror = JNIHandles::resolve_non_null(cls);
1192   if (java_lang_Class::is_primitive(mirror)) {
1193     return JNI_FALSE;
1194   }
1195   Klass* k = java_lang_Class::as_Klass(mirror);
1196   return k->is_hidden();
1197 JVM_END
1198 
1199 
1200 class ScopedValueBindingsResolver {
1201 public:
1202   InstanceKlass* Carrier_klass;
1203   ScopedValueBindingsResolver(JavaThread* THREAD) {
1204     Klass *k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ScopedValue_Carrier(), true, THREAD);
1205     Carrier_klass = InstanceKlass::cast(k);
1206   }
1207 };
1208 
1209 JVM_ENTRY(jobject, JVM_FindScopedValueBindings(JNIEnv *env, jclass cls))
1210   ResourceMark rm(THREAD);
1211   GrowableArray<Handle>* local_array = new GrowableArray<Handle>(12);
1212   JvmtiVMObjectAllocEventCollector oam;
1213 
1214   static ScopedValueBindingsResolver resolver(THREAD);
1215 
1216   // Iterate through Java frames
1217   vframeStream vfst(thread);
1218   for(; !vfst.at_end(); vfst.next()) {
1219     int loc = -1;

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

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

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

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

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




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

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


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


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

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

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

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

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

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

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

1362 class ScopedValueBindingsResolver {
1363 public:
1364   InstanceKlass* Carrier_klass;
1365   ScopedValueBindingsResolver(JavaThread* THREAD) {
1366     Klass *k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ScopedValue_Carrier(), true, THREAD);
1367     Carrier_klass = InstanceKlass::cast(k);
1368   }
1369 };
1370 
1371 JVM_ENTRY(jobject, JVM_FindScopedValueBindings(JNIEnv *env, jclass cls))
1372   ResourceMark rm(THREAD);
1373   GrowableArray<Handle>* local_array = new GrowableArray<Handle>(12);
1374   JvmtiVMObjectAllocEventCollector oam;
1375 
1376   static ScopedValueBindingsResolver resolver(THREAD);
1377 
1378   // Iterate through Java frames
1379   vframeStream vfst(thread);
1380   for(; !vfst.at_end(); vfst.next()) {
1381     int loc = -1;

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

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

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

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

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

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

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

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