< 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, Universe::value_object_hash_code_method());
 769       JavaCalls::call(&result, method, &args, THREAD);
 770       if (HAS_PENDING_EXCEPTION) {
 771         if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
 772           Handle e(THREAD, PENDING_EXCEPTION);
 773           CLEAR_PENDING_EXCEPTION;
 774           THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in hashCode", e, false);
 775         }
 776       }
 777       return result.get_jint();
 778   } else {
 779     return checked_cast<jint>(ObjectSynchronizer::FastHashCode(THREAD, obj));
 780   }
 781 JVM_END
 782 
 783 
 784 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 785   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 786   ObjectSynchronizer::wait(obj, ms, CHECK);
 787 JVM_END
 788 
 789 
 790 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 791   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 792   ObjectSynchronizer::notify(obj, CHECK);
 793 JVM_END
 794 
 795 
 796 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 797   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 798   ObjectSynchronizer::notifyall(obj, CHECK);
 799 JVM_END
 800 

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

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

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

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

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

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

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

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

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

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

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