41 #include "classfile/modules.hpp"
42 #include "classfile/packageEntry.hpp"
43 #include "classfile/stringTable.hpp"
44 #include "classfile/symbolTable.hpp"
45 #include "classfile/systemDictionary.hpp"
46 #include "classfile/vmClasses.hpp"
47 #include "classfile/vmSymbols.hpp"
48 #include "gc/shared/collectedHeap.inline.hpp"
49 #include "interpreter/bytecode.hpp"
50 #include "interpreter/bytecodeUtils.hpp"
51 #include "jfr/jfrEvents.hpp"
52 #include "jvm.h"
53 #include "logging/log.hpp"
54 #include "memory/oopFactory.hpp"
55 #include "memory/referenceType.hpp"
56 #include "memory/resourceArea.hpp"
57 #include "memory/universe.hpp"
58 #include "oops/access.inline.hpp"
59 #include "oops/constantPool.hpp"
60 #include "oops/fieldStreams.inline.hpp"
61 #include "oops/instanceKlass.hpp"
62 #include "oops/klass.inline.hpp"
63 #include "oops/method.hpp"
64 #include "oops/objArrayKlass.hpp"
65 #include "oops/objArrayOop.inline.hpp"
66 #include "oops/oop.inline.hpp"
67 #include "oops/recordComponent.hpp"
68 #include "prims/foreignGlobals.hpp"
69 #include "prims/jvm_misc.hpp"
70 #include "prims/jvmtiExport.hpp"
71 #include "prims/jvmtiThreadState.inline.hpp"
72 #include "prims/stackwalk.hpp"
73 #include "runtime/arguments.hpp"
74 #include "runtime/atomicAccess.hpp"
75 #include "runtime/continuation.hpp"
76 #include "runtime/deoptimization.hpp"
77 #include "runtime/globals_extension.hpp"
78 #include "runtime/handles.inline.hpp"
79 #include "runtime/handshake.hpp"
80 #include "runtime/init.hpp"
81 #include "runtime/interfaceSupport.inline.hpp"
82 #include "runtime/java.hpp"
83 #include "runtime/javaCalls.hpp"
84 #include "runtime/javaThread.hpp"
85 #include "runtime/jfieldIDWorkaround.hpp"
86 #include "runtime/jniHandles.inline.hpp"
87 #include "runtime/mountUnmountDisabler.hpp"
407
408 return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
409 JVM_END
410
411
412 /*
413 * Return the temporary directory that the VM uses for the attach
414 * and perf data files.
415 *
416 * It is important that this directory is well-known and the
417 * same for all VM instances. It cannot be affected by configuration
418 * variables such as java.io.tmpdir.
419 */
420 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
421 HandleMark hm(THREAD);
422 const char* temp_dir = os::get_temp_directory();
423 Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
424 return (jstring) JNIHandles::make_local(THREAD, h());
425 JVM_END
426
427
428 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
429
430 extern volatile jint vm_created;
431
432 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
433 EventShutdown event;
434 if (event.should_commit()) {
435 event.set_reason("Shutdown requested from Java");
436 event.commit();
437 }
438 JVM_END
439
440
441 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
442 before_exit(thread, true);
443 vm_exit(code);
444 JVM_END
445
446
613
614 Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
615 return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, last_batch_count, buffer_size,
616 start_index, frames_array_h, THREAD);
617 JVM_END
618
619 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
620 objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
621 objArrayHandle frames_array_h(THREAD, fa);
622 Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
623 Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
624
625 StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
626 JVM_END
627
628 // java.lang.Object ///////////////////////////////////////////////
629
630
631 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
632 // as implemented in the classic virtual machine; return 0 if object is null
633 return handle == nullptr ? 0 :
634 checked_cast<jint>(ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)));
635 JVM_END
636
637
638 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
639 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
640 ObjectSynchronizer::wait(obj, ms, CHECK);
641 JVM_END
642
643
644 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
645 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
646 ObjectSynchronizer::notify(obj, CHECK);
647 JVM_END
648
649
650 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
651 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
652 ObjectSynchronizer::notifyall(obj, CHECK);
653 JVM_END
654
662 // Just checking that the cloneable flag is set correct
663 if (obj->is_array()) {
664 guarantee(klass->is_cloneable(), "all arrays are cloneable");
665 } else {
666 guarantee(obj->is_instance(), "should be instanceOop");
667 bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
668 guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
669 }
670 #endif
671
672 // Check if class of obj supports the Cloneable interface.
673 // All arrays are considered to be cloneable (See JLS 20.1.5).
674 // All j.l.r.Reference classes are considered non-cloneable.
675 if (!klass->is_cloneable() ||
676 (klass->is_instance_klass() &&
677 InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
678 ResourceMark rm(THREAD);
679 THROW_MSG_NULL(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
680 }
681
682 // Make shallow object copy
683 const size_t size = obj->size();
684 oop new_obj_oop = nullptr;
685 if (obj->is_array()) {
686 const int length = ((arrayOop)obj())->length();
687 new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
688 /* do_zero */ true, CHECK_NULL);
689 } else {
690 new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
691 }
692
693 HeapAccess<>::clone(obj(), new_obj_oop, size);
694
695 Handle new_obj(THREAD, new_obj_oop);
696 // Caution: this involves a java upcall, so the clone should be
697 // "gc-robust" by this stage.
698 if (klass->has_finalizer()) {
699 assert(obj->is_instance(), "should be instanceOop");
700 new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
701 new_obj = Handle(THREAD, new_obj_oop);
1154 oop result = java_lang_Class::name(java_class, CHECK_NULL);
1155 return (jstring) JNIHandles::make_local(THREAD, result);
1156 JVM_END
1157
1158
1159 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1160 JvmtiVMObjectAllocEventCollector oam;
1161 oop mirror = JNIHandles::resolve_non_null(cls);
1162
1163 // Special handling for primitive objects
1164 if (java_lang_Class::is_primitive(mirror)) {
1165 // Primitive objects does not have any interfaces
1166 objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1167 return (jobjectArray) JNIHandles::make_local(THREAD, r);
1168 }
1169
1170 Klass* klass = java_lang_Class::as_Klass(mirror);
1171 // Figure size of result array
1172 int size;
1173 if (klass->is_instance_klass()) {
1174 size = InstanceKlass::cast(klass)->local_interfaces()->length();
1175 } else {
1176 assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1177 size = 2;
1178 }
1179
1180 // Allocate result array
1181 objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1182 objArrayHandle result (THREAD, r);
1183 // Fill in result
1184 if (klass->is_instance_klass()) {
1185 // Regular instance klass, fill in all local interfaces
1186 for (int index = 0; index < size; index++) {
1187 InstanceKlass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
1188 result->obj_at_put(index, k->java_mirror());
1189 }
1190 } else {
1191 // All arrays implement java.lang.Cloneable and java.io.Serializable
1192 result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1193 result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1194 }
1658 }
1659
1660 InstanceKlass* k = java_lang_Class::as_InstanceKlass(ofMirror);
1661
1662 // Ensure class is linked
1663 k->link_class(CHECK_NULL);
1664
1665 Array<Method*>* methods = k->methods();
1666 int methods_length = methods->length();
1667
1668 // Save original method_idnum in case of redefinition, which can change
1669 // the idnum of obsolete methods. The new method will have the same idnum
1670 // but if we refresh the methods array, the counts will be wrong.
1671 ResourceMark rm(THREAD);
1672 GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
1673 int num_methods = 0;
1674
1675 // Select methods matching the criteria.
1676 for (int i = 0; i < methods_length; i++) {
1677 Method* method = methods->at(i);
1678 if (want_constructor && !method->is_object_initializer()) {
1679 continue;
1680 }
1681 if (!want_constructor &&
1682 (method->is_object_initializer() || method->is_static_initializer() ||
1683 method->is_overpass())) {
1684 continue;
1685 }
1686 if (publicOnly && !method->is_public()) {
1687 continue;
1688 }
1689 idnums->push(method->method_idnum());
1690 ++num_methods;
1691 }
1692
1693 // Allocate result
1694 objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1695 objArrayHandle result (THREAD, r);
1696
1697 // Now just put the methods that we selected above, but go by their idnum
1698 // in case of redefinition. The methods can be redefined at any safepoint,
1699 // so above when allocating the oop array and below when creating reflect
1700 // objects.
1701 for (int i = 0; i < num_methods; i++) {
1702 methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1703 if (method.is_null()) {
1704 // Method may have been deleted and seems this API can handle null
1705 // Otherwise should probably put a method that throws NSME
1706 result->obj_at_put(i, nullptr);
1707 } else {
1708 oop m;
1709 if (want_constructor) {
1710 m = Reflection::new_constructor(method, CHECK_NULL);
1711 } else {
1712 m = Reflection::new_method(method, false, CHECK_NULL);
1713 }
1714 result->obj_at_put(i, m);
1715 }
1716 }
1717
1718 return (jobjectArray) JNIHandles::make_local(THREAD, result());
1719 }
1720
1721 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1722 {
1723 return get_class_declared_methods_helper(env, ofClass, publicOnly,
1724 /*want_constructor*/ false,
1725 vmClasses::reflect_Method_klass(), THREAD);
1726 }
1727 JVM_END
1728
1729 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1950 constantTag tag = cp->tag_at(index);
1951 if (!tag.is_method() && !tag.is_interface_method()) {
1952 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1953 }
1954 int klass_ref = cp->uncached_klass_ref_index_at(index);
1955 Klass* k_o;
1956 if (force_resolution) {
1957 k_o = cp->klass_at(klass_ref, CHECK_NULL);
1958 } else {
1959 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
1960 if (k_o == nullptr) return nullptr;
1961 }
1962 InstanceKlass* k = InstanceKlass::cast(k_o);
1963 Symbol* name = cp->uncached_name_ref_at(index);
1964 Symbol* sig = cp->uncached_signature_ref_at(index);
1965 methodHandle m (THREAD, k->find_method(name, sig));
1966 if (m.is_null()) {
1967 THROW_MSG_NULL(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
1968 }
1969 oop method;
1970 if (m->is_object_initializer()) {
1971 method = Reflection::new_constructor(m, CHECK_NULL);
1972 } else {
1973 // new_method accepts <clinit> as Method here
1974 method = Reflection::new_method(m, true, CHECK_NULL);
1975 }
1976 return JNIHandles::make_local(THREAD, method);
1977 }
1978
1979 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jint index))
1980 {
1981 JvmtiVMObjectAllocEventCollector oam;
1982 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1983 bounds_check(cp, index, CHECK_NULL);
1984 jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
1985 return res;
1986 }
1987 JVM_END
1988
1989 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jint index))
1990 {
1991 JvmtiVMObjectAllocEventCollector oam;
1992 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1993 bounds_check(cp, index, CHECK_NULL);
2400
2401
2402 JVM_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
2403 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2404 Method* method = ik->methods()->at(method_index);
2405 return method->size_of_parameters();
2406 JVM_END
2407
2408
2409 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2410 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2411 Method* method = ik->methods()->at(method_index);
2412 return method->verifier_max_stack();
2413 JVM_END
2414
2415
2416 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2417 ResourceMark rm(THREAD);
2418 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2419 Method* method = ik->methods()->at(method_index);
2420 return method->name() == vmSymbols::object_initializer_name();
2421 JVM_END
2422
2423
2424 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2425 ResourceMark rm(THREAD);
2426 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2427 Method* method = ik->methods()->at(method_index);
2428 return method->is_overpass();
2429 JVM_END
2430
2431 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2432 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2433 Method* method = ik->methods()->at(method_index);
2434 return method->name()->as_utf8();
2435 JVM_END
2436
2437
2438 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
2439 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2440 Method* method = ik->methods()->at(method_index);
3194 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3195 void* find_result = os::dll_lookup(handle, name);
3196 log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3197 find_result != nullptr ? "Found" : "Failed to find",
3198 name, p2i(handle));
3199 return find_result;
3200 JVM_END
3201
3202
3203 // JNI version ///////////////////////////////////////////////////////////////////////////////
3204
3205 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3206 return Threads::is_supported_jni_version_including_1_1(version);
3207 JVM_END
3208
3209
3210 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3211 return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3212 JVM_END
3213
3214 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3215 return VMContinuations ? JNI_TRUE : JNI_FALSE;
3216 JVM_END
3217
3218 JVM_LEAF(jboolean, JVM_IsForeignLinkerSupported(void))
3219 return ForeignGlobals::is_foreign_linker_supported() ? JNI_TRUE : JNI_FALSE;
3220 JVM_END
3221
3222 JVM_LEAF(jboolean, JVM_IsStaticallyLinked(void))
3223 return is_vm_statically_linked() ? JNI_TRUE : JNI_FALSE;
3224 JVM_END
3225
3226 // String support ///////////////////////////////////////////////////////////////////////////
3227
3228 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3229 JvmtiVMObjectAllocEventCollector oam;
3230 if (str == nullptr) return nullptr;
3231 oop string = JNIHandles::resolve_non_null(str);
3232 oop result = StringTable::intern(string, CHECK_NULL);
3233 return (jstring) JNIHandles::make_local(THREAD, result);
3273
3274 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3275 Handle loader, jboolean throwError, TRAPS) {
3276 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, throwError != 0, CHECK_NULL);
3277
3278 // Check if we should initialize the class
3279 if (init && klass->is_instance_klass()) {
3280 klass->initialize(CHECK_NULL);
3281 }
3282 return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3283 }
3284
3285
3286 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3287
3288 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3289 Handle method_handle;
3290 if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3291 method_handle = Handle(THREAD, JNIHandles::resolve(method));
3292 Handle receiver(THREAD, JNIHandles::resolve(obj));
3293 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3294 oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3295 jobject res = JNIHandles::make_local(THREAD, result);
3296 if (JvmtiExport::should_post_vm_object_alloc()) {
3297 oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3298 assert(ret_type != nullptr, "sanity check: ret_type oop must not be null!");
3299 if (java_lang_Class::is_primitive(ret_type)) {
3300 // Only for primitive type vm allocates memory for java object.
3301 // See box() method.
3302 JvmtiExport::post_vm_object_alloc(thread, result);
3303 }
3304 }
3305 return res;
3306 } else {
3307 THROW_NULL(vmSymbols::java_lang_StackOverflowError());
3308 }
3309 JVM_END
3310
3311
3312 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3313 oop constructor_mirror = JNIHandles::resolve(c);
3314 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3315 oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3316 jobject res = JNIHandles::make_local(THREAD, result);
3317 if (JvmtiExport::should_post_vm_object_alloc()) {
3318 JvmtiExport::post_vm_object_alloc(thread, result);
3319 }
3320 return res;
3321 JVM_END
3322
3323 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3324 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3325 HeapShared::initialize_from_archived_subgraph(THREAD, k);
3326 JVM_END
3327
3328 JVM_ENTRY(void, JVM_RegisterLambdaProxyClassForArchiving(JNIEnv* env,
3329 jclass caller,
3330 jstring interfaceMethodName,
3331 jobject factoryType,
3332 jobject interfaceMethodType,
3333 jobject implementationMember,
3334 jobject dynamicMethodType,
3531 JvmtiVMObjectAllocEventCollector oam;
3532
3533 // Check if threads is null
3534 if (threads == nullptr) {
3535 THROW_NULL(vmSymbols::java_lang_NullPointerException());
3536 }
3537
3538 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads));
3539 objArrayHandle ah(THREAD, a);
3540 int num_threads = ah->length();
3541 // check if threads is non-empty array
3542 if (num_threads == 0) {
3543 THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3544 }
3545
3546 // check if threads is not an array of objects of Thread class
3547 Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass();
3548 if (k != vmClasses::Thread_klass()) {
3549 THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3550 }
3551
3552 ResourceMark rm(THREAD);
3553
3554 GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
3555 for (int i = 0; i < num_threads; i++) {
3556 oop thread_obj = ah->obj_at(i);
3557 instanceHandle h(THREAD, (instanceOop) thread_obj);
3558 thread_handle_array->append(h);
3559 }
3560
3561 // The JavaThread references in thread_handle_array are validated
3562 // in VM_ThreadDump::doit().
3563 Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL);
3564 return (jobjectArray)JNIHandles::make_local(THREAD, stacktraces());
3565
3566 JVM_END
3567
3568 // JVM monitoring and management support
3569 JVM_LEAF(void*, JVM_GetManagement(jint version))
3570 return Management::get_jmm_interface(version);
3571 JVM_END
3572
3573 // com.sun.tools.attach.VirtualMachine agent properties support
3574 //
3575 // Initialize the agent properties with the properties maintained in the VM
3576 JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties))
|
41 #include "classfile/modules.hpp"
42 #include "classfile/packageEntry.hpp"
43 #include "classfile/stringTable.hpp"
44 #include "classfile/symbolTable.hpp"
45 #include "classfile/systemDictionary.hpp"
46 #include "classfile/vmClasses.hpp"
47 #include "classfile/vmSymbols.hpp"
48 #include "gc/shared/collectedHeap.inline.hpp"
49 #include "interpreter/bytecode.hpp"
50 #include "interpreter/bytecodeUtils.hpp"
51 #include "jfr/jfrEvents.hpp"
52 #include "jvm.h"
53 #include "logging/log.hpp"
54 #include "memory/oopFactory.hpp"
55 #include "memory/referenceType.hpp"
56 #include "memory/resourceArea.hpp"
57 #include "memory/universe.hpp"
58 #include "oops/access.inline.hpp"
59 #include "oops/constantPool.hpp"
60 #include "oops/fieldStreams.inline.hpp"
61 #include "oops/flatArrayKlass.hpp"
62 #include "oops/instanceKlass.hpp"
63 #include "oops/klass.inline.hpp"
64 #include "oops/method.hpp"
65 #include "oops/objArrayKlass.hpp"
66 #include "oops/objArrayOop.inline.hpp"
67 #include "oops/oop.inline.hpp"
68 #include "oops/recordComponent.hpp"
69 #include "oops/refArrayOop.inline.hpp"
70 #include "prims/foreignGlobals.hpp"
71 #include "prims/jvm_misc.hpp"
72 #include "prims/jvmtiExport.hpp"
73 #include "prims/jvmtiThreadState.inline.hpp"
74 #include "prims/stackwalk.hpp"
75 #include "runtime/arguments.hpp"
76 #include "runtime/atomicAccess.hpp"
77 #include "runtime/continuation.hpp"
78 #include "runtime/deoptimization.hpp"
79 #include "runtime/globals_extension.hpp"
80 #include "runtime/handles.inline.hpp"
81 #include "runtime/handshake.hpp"
82 #include "runtime/init.hpp"
83 #include "runtime/interfaceSupport.inline.hpp"
84 #include "runtime/java.hpp"
85 #include "runtime/javaCalls.hpp"
86 #include "runtime/javaThread.hpp"
87 #include "runtime/jfieldIDWorkaround.hpp"
88 #include "runtime/jniHandles.inline.hpp"
89 #include "runtime/mountUnmountDisabler.hpp"
409
410 return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
411 JVM_END
412
413
414 /*
415 * Return the temporary directory that the VM uses for the attach
416 * and perf data files.
417 *
418 * It is important that this directory is well-known and the
419 * same for all VM instances. It cannot be affected by configuration
420 * variables such as java.io.tmpdir.
421 */
422 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
423 HandleMark hm(THREAD);
424 const char* temp_dir = os::get_temp_directory();
425 Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
426 return (jstring) JNIHandles::make_local(THREAD, h());
427 JVM_END
428
429 static void validate_array_arguments(Klass* elmClass, jint len, TRAPS) {
430 if (len < 0) {
431 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Array length is negative");
432 }
433 elmClass->initialize(CHECK);
434 if (elmClass->is_array_klass() || elmClass->is_identity_class()) {
435 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Element class is not a value class");
436 }
437 if (elmClass->is_abstract()) {
438 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Element class is abstract");
439 }
440 }
441
442 JVM_ENTRY(jarray, JVM_CopyOfSpecialArray(JNIEnv *env, jarray orig, jint from, jint to))
443 oop o = JNIHandles::resolve_non_null(orig);
444 assert(o->is_array(), "Must be");
445 oop array = nullptr;
446 arrayOop org = (arrayOop)o;
447 arrayHandle oh(THREAD, org);
448 ObjArrayKlass* ak = ObjArrayKlass::cast(org->klass());
449 InlineKlass* vk = InlineKlass::cast(ak->element_klass());
450 int len = to - from; // length of the new array
451 if (ak->is_null_free_array_klass()) {
452 if ((len != 0) && (from >= org->length() || to > org->length())) {
453 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Copying of null-free array with uninitialized elements");
454 }
455 }
456 if (org->is_flatArray()) {
457 FlatArrayKlass* fak = FlatArrayKlass::cast(org->klass());
458 LayoutKind lk = fak->layout_kind();
459 ArrayKlass::ArrayProperties props = ArrayKlass::array_properties_from_layout(lk);
460 array = oopFactory::new_flatArray(vk, len, props, lk, CHECK_NULL);
461 arrayHandle ah(THREAD, (arrayOop)array);
462 int end = to < oh()->length() ? to : oh()->length();
463 for (int i = from; i < end; i++) {
464 void* src = ((flatArrayOop)oh())->value_at_addr(i, fak->layout_helper());
465 void* dst = ((flatArrayOop)ah())->value_at_addr(i - from, fak->layout_helper());
466 vk->copy_payload_to_addr(src, dst, lk, false);
467 }
468 array = ah();
469 } else {
470 ArrayKlass::ArrayProperties props = org->is_null_free_array() ? ArrayKlass::ArrayProperties::NULL_RESTRICTED : ArrayKlass::ArrayProperties::DEFAULT;
471 array = oopFactory::new_objArray(vk, len, props, CHECK_NULL);
472 int end = to < oh()->length() ? to : oh()->length();
473 for (int i = from; i < end; i++) {
474 if (i < ((objArrayOop)oh())->length()) {
475 ((objArrayOop)array)->obj_at_put(i - from, ((objArrayOop)oh())->obj_at(i));
476 } else {
477 assert(!ak->is_null_free_array_klass(), "Must be a nullable array");
478 ((objArrayOop)array)->obj_at_put(i - from, nullptr);
479 }
480 }
481 }
482 return (jarray) JNIHandles::make_local(THREAD, array);
483 JVM_END
484
485 JVM_ENTRY(jarray, JVM_NewNullRestrictedNonAtomicArray(JNIEnv *env, jclass elmClass, jint len, jobject initVal))
486 oop mirror = JNIHandles::resolve_non_null(elmClass);
487 oop init = JNIHandles::resolve(initVal);
488 if (init == nullptr) {
489 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Initial value cannot be null");
490 }
491 Handle init_h(THREAD, init);
492 Klass* klass = java_lang_Class::as_Klass(mirror);
493 if (klass != init_h()->klass()) {
494 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Type mismatch between array and initial value");
495 }
496 validate_array_arguments(klass, len, CHECK_NULL);
497 InlineKlass* vk = InlineKlass::cast(klass);
498 ArrayKlass::ArrayProperties props = (ArrayKlass::ArrayProperties)(ArrayKlass::ArrayProperties::NON_ATOMIC | ArrayKlass::ArrayProperties::NULL_RESTRICTED);
499 objArrayOop array = oopFactory::new_objArray(klass, len, props, CHECK_NULL);
500 for (int i = 0; i < len; i++) {
501 array->obj_at_put(i, init_h() /*, CHECK_NULL*/ );
502 }
503 return (jarray) JNIHandles::make_local(THREAD, array);
504 JVM_END
505
506 JVM_ENTRY(jarray, JVM_NewNullRestrictedAtomicArray(JNIEnv *env, jclass elmClass, jint len, jobject initVal))
507 oop mirror = JNIHandles::resolve_non_null(elmClass);
508 oop init = JNIHandles::resolve(initVal);
509 if (init == nullptr) {
510 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Initial value cannot be null");
511 }
512 Handle init_h(THREAD, init);
513 Klass* klass = java_lang_Class::as_Klass(mirror);
514 if (klass != init_h()->klass()) {
515 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Type mismatch between array and initial value");
516 }
517 validate_array_arguments(klass, len, CHECK_NULL);
518 InlineKlass* vk = InlineKlass::cast(klass);
519 ArrayKlass::ArrayProperties props = (ArrayKlass::ArrayProperties)(ArrayKlass::ArrayProperties::NULL_RESTRICTED);
520 objArrayOop array = oopFactory::new_objArray(klass, len, props, CHECK_NULL);
521 for (int i = 0; i < len; i++) {
522 array->obj_at_put(i, init_h() /*, CHECK_NULL*/ );
523 }
524 return (jarray) JNIHandles::make_local(THREAD, array);
525 JVM_END
526
527 JVM_ENTRY(jarray, JVM_NewNullableAtomicArray(JNIEnv *env, jclass elmClass, jint len))
528 oop mirror = JNIHandles::resolve_non_null(elmClass);
529 Klass* klass = java_lang_Class::as_Klass(mirror);
530 klass->initialize(CHECK_NULL);
531 validate_array_arguments(klass, len, CHECK_NULL);
532 InlineKlass* vk = InlineKlass::cast(klass);
533 ArrayKlass::ArrayProperties props = (ArrayKlass::ArrayProperties)(ArrayKlass::ArrayProperties::DEFAULT);
534 objArrayOop array = oopFactory::new_objArray(klass, len, props, CHECK_NULL);
535 return (jarray) JNIHandles::make_local(THREAD, array);
536 JVM_END
537
538 JVM_ENTRY(jboolean, JVM_IsFlatArray(JNIEnv *env, jobject obj))
539 arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
540 return oop->is_flatArray();
541 JVM_END
542
543 JVM_ENTRY(jboolean, JVM_IsNullRestrictedArray(JNIEnv *env, jobject obj))
544 arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
545 return oop->is_null_free_array();
546 JVM_END
547
548 JVM_ENTRY(jboolean, JVM_IsAtomicArray(JNIEnv *env, jobject obj))
549 // There are multiple cases where an array can/must support atomic access:
550 // - the array is a reference array
551 // - the array uses an atomic flat layout: NULLABLE_ATOMIC_FLAT or NULL_FREE_ATOMIC_FLAT
552 // - the array is flat and its component type is naturally atomic
553 arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
554 if (oop->is_refArray()) return true;
555 if (oop->is_flatArray()) {
556 FlatArrayKlass* fak = FlatArrayKlass::cast(oop->klass());
557 if (LayoutKindHelper::is_atomic_flat(fak->layout_kind())) return true;
558 if (fak->element_klass()->is_naturally_atomic()) return true;
559 }
560 return false;
561 JVM_END
562
563 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
564
565 extern volatile jint vm_created;
566
567 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
568 EventShutdown event;
569 if (event.should_commit()) {
570 event.set_reason("Shutdown requested from Java");
571 event.commit();
572 }
573 JVM_END
574
575
576 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
577 before_exit(thread, true);
578 vm_exit(code);
579 JVM_END
580
581
748
749 Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
750 return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, last_batch_count, buffer_size,
751 start_index, frames_array_h, THREAD);
752 JVM_END
753
754 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
755 objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
756 objArrayHandle frames_array_h(THREAD, fa);
757 Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
758 Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
759
760 StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
761 JVM_END
762
763 // java.lang.Object ///////////////////////////////////////////////
764
765
766 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
767 // as implemented in the classic virtual machine; return 0 if object is null
768 if (handle == nullptr) {
769 return 0;
770 }
771 oop obj = JNIHandles::resolve_non_null(handle);
772 if (Arguments::is_valhalla_enabled() && obj->klass()->is_inline_klass()) {
773 // Check if mark word contains hash code already
774 intptr_t hash = obj->mark().hash();
775 if (hash != markWord::no_hash) {
776 return checked_cast<jint>(hash);
777 }
778
779 // Compute hash by calling ValueObjectMethods.valueObjectHashCode
780 JavaValue result(T_INT);
781 JavaCallArguments args;
782 Handle ho(THREAD, obj);
783 args.push_oop(ho);
784 methodHandle method(THREAD, Universe::value_object_hash_code_method());
785 JavaCalls::call(&result, method, &args, THREAD);
786 if (HAS_PENDING_EXCEPTION) {
787 if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
788 Handle e(THREAD, PENDING_EXCEPTION);
789 CLEAR_PENDING_EXCEPTION;
790 THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in hashCode", e, false);
791 }
792 }
793 hash = result.get_jint();
794
795 // Store hash in the mark word
796 markWord old_mark, new_mark, test;
797 do {
798 old_mark = ho->mark();
799 new_mark = old_mark.copy_set_hash(hash);
800 test = ho->cas_set_mark(new_mark, old_mark);
801 } while (test != old_mark);
802
803 return checked_cast<jint>(new_mark.hash());
804 } else {
805 return checked_cast<jint>(ObjectSynchronizer::FastHashCode(THREAD, obj));
806 }
807 JVM_END
808
809
810 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
811 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
812 ObjectSynchronizer::wait(obj, ms, CHECK);
813 JVM_END
814
815
816 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
817 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
818 ObjectSynchronizer::notify(obj, CHECK);
819 JVM_END
820
821
822 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
823 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
824 ObjectSynchronizer::notifyall(obj, CHECK);
825 JVM_END
826
834 // Just checking that the cloneable flag is set correct
835 if (obj->is_array()) {
836 guarantee(klass->is_cloneable(), "all arrays are cloneable");
837 } else {
838 guarantee(obj->is_instance(), "should be instanceOop");
839 bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
840 guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
841 }
842 #endif
843
844 // Check if class of obj supports the Cloneable interface.
845 // All arrays are considered to be cloneable (See JLS 20.1.5).
846 // All j.l.r.Reference classes are considered non-cloneable.
847 if (!klass->is_cloneable() ||
848 (klass->is_instance_klass() &&
849 InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
850 ResourceMark rm(THREAD);
851 THROW_MSG_NULL(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
852 }
853
854 if (klass->is_inline_klass()) {
855 // Value instances have no identity, so return the current instance instead of allocating a new one
856 // Value classes cannot have finalizers, so the method can return immediately
857 return JNIHandles::make_local(THREAD, obj());
858 }
859
860 // Make shallow object copy
861 const size_t size = obj->size();
862 oop new_obj_oop = nullptr;
863 if (obj->is_array()) {
864 const int length = ((arrayOop)obj())->length();
865 new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
866 /* do_zero */ true, CHECK_NULL);
867 } else {
868 new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
869 }
870
871 HeapAccess<>::clone(obj(), new_obj_oop, size);
872
873 Handle new_obj(THREAD, new_obj_oop);
874 // Caution: this involves a java upcall, so the clone should be
875 // "gc-robust" by this stage.
876 if (klass->has_finalizer()) {
877 assert(obj->is_instance(), "should be instanceOop");
878 new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
879 new_obj = Handle(THREAD, new_obj_oop);
1332 oop result = java_lang_Class::name(java_class, CHECK_NULL);
1333 return (jstring) JNIHandles::make_local(THREAD, result);
1334 JVM_END
1335
1336
1337 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1338 JvmtiVMObjectAllocEventCollector oam;
1339 oop mirror = JNIHandles::resolve_non_null(cls);
1340
1341 // Special handling for primitive objects
1342 if (java_lang_Class::is_primitive(mirror)) {
1343 // Primitive objects does not have any interfaces
1344 objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1345 return (jobjectArray) JNIHandles::make_local(THREAD, r);
1346 }
1347
1348 Klass* klass = java_lang_Class::as_Klass(mirror);
1349 // Figure size of result array
1350 int size;
1351 if (klass->is_instance_klass()) {
1352 InstanceKlass* ik = InstanceKlass::cast(klass);
1353 size = ik->local_interfaces()->length();
1354 } else {
1355 assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1356 size = 2;
1357 }
1358
1359 // Allocate result array
1360 objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1361 objArrayHandle result (THREAD, r);
1362 // Fill in result
1363 if (klass->is_instance_klass()) {
1364 // Regular instance klass, fill in all local interfaces
1365 for (int index = 0; index < size; index++) {
1366 InstanceKlass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
1367 result->obj_at_put(index, k->java_mirror());
1368 }
1369 } else {
1370 // All arrays implement java.lang.Cloneable and java.io.Serializable
1371 result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1372 result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1373 }
1837 }
1838
1839 InstanceKlass* k = java_lang_Class::as_InstanceKlass(ofMirror);
1840
1841 // Ensure class is linked
1842 k->link_class(CHECK_NULL);
1843
1844 Array<Method*>* methods = k->methods();
1845 int methods_length = methods->length();
1846
1847 // Save original method_idnum in case of redefinition, which can change
1848 // the idnum of obsolete methods. The new method will have the same idnum
1849 // but if we refresh the methods array, the counts will be wrong.
1850 ResourceMark rm(THREAD);
1851 GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
1852 int num_methods = 0;
1853
1854 // Select methods matching the criteria.
1855 for (int i = 0; i < methods_length; i++) {
1856 Method* method = methods->at(i);
1857 if (want_constructor && !method->is_object_constructor()) {
1858 continue;
1859 }
1860 if (!want_constructor &&
1861 (method->is_object_constructor() || method->is_class_initializer() ||
1862 method->is_overpass())) {
1863 continue;
1864 }
1865 if (publicOnly && !method->is_public()) {
1866 continue;
1867 }
1868 idnums->push(method->method_idnum());
1869 ++num_methods;
1870 }
1871
1872 // Allocate result
1873 objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1874 objArrayHandle result (THREAD, r);
1875
1876 // Now just put the methods that we selected above, but go by their idnum
1877 // in case of redefinition. The methods can be redefined at any safepoint,
1878 // so above when allocating the oop array and below when creating reflect
1879 // objects.
1880 for (int i = 0; i < num_methods; i++) {
1881 methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1882 if (method.is_null()) {
1883 // Method may have been deleted and seems this API can handle null
1884 // Otherwise should probably put a method that throws NSME
1885 result->obj_at_put(i, nullptr);
1886 } else {
1887 oop m;
1888 if (want_constructor) {
1889 assert(method->is_object_constructor(), "must be");
1890 m = Reflection::new_constructor(method, CHECK_NULL);
1891 } else {
1892 m = Reflection::new_method(method, false, CHECK_NULL);
1893 }
1894 result->obj_at_put(i, m);
1895 }
1896 }
1897
1898 return (jobjectArray) JNIHandles::make_local(THREAD, result());
1899 }
1900
1901 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1902 {
1903 return get_class_declared_methods_helper(env, ofClass, publicOnly,
1904 /*want_constructor*/ false,
1905 vmClasses::reflect_Method_klass(), THREAD);
1906 }
1907 JVM_END
1908
1909 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
2130 constantTag tag = cp->tag_at(index);
2131 if (!tag.is_method() && !tag.is_interface_method()) {
2132 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2133 }
2134 int klass_ref = cp->uncached_klass_ref_index_at(index);
2135 Klass* k_o;
2136 if (force_resolution) {
2137 k_o = cp->klass_at(klass_ref, CHECK_NULL);
2138 } else {
2139 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2140 if (k_o == nullptr) return nullptr;
2141 }
2142 InstanceKlass* k = InstanceKlass::cast(k_o);
2143 Symbol* name = cp->uncached_name_ref_at(index);
2144 Symbol* sig = cp->uncached_signature_ref_at(index);
2145 methodHandle m (THREAD, k->find_method(name, sig));
2146 if (m.is_null()) {
2147 THROW_MSG_NULL(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2148 }
2149 oop method;
2150 if (m->is_object_constructor()) {
2151 method = Reflection::new_constructor(m, CHECK_NULL);
2152 } else {
2153 method = Reflection::new_method(m, true, CHECK_NULL);
2154 }
2155 return JNIHandles::make_local(THREAD, method);
2156 }
2157
2158 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jint index))
2159 {
2160 JvmtiVMObjectAllocEventCollector oam;
2161 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2162 bounds_check(cp, index, CHECK_NULL);
2163 jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2164 return res;
2165 }
2166 JVM_END
2167
2168 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jint index))
2169 {
2170 JvmtiVMObjectAllocEventCollector oam;
2171 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2172 bounds_check(cp, index, CHECK_NULL);
2579
2580
2581 JVM_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
2582 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2583 Method* method = ik->methods()->at(method_index);
2584 return method->size_of_parameters();
2585 JVM_END
2586
2587
2588 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2589 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2590 Method* method = ik->methods()->at(method_index);
2591 return method->verifier_max_stack();
2592 JVM_END
2593
2594
2595 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2596 ResourceMark rm(THREAD);
2597 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2598 Method* method = ik->methods()->at(method_index);
2599 return method->is_object_constructor();
2600 JVM_END
2601
2602
2603 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2604 ResourceMark rm(THREAD);
2605 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2606 Method* method = ik->methods()->at(method_index);
2607 return method->is_overpass();
2608 JVM_END
2609
2610 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2611 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2612 Method* method = ik->methods()->at(method_index);
2613 return method->name()->as_utf8();
2614 JVM_END
2615
2616
2617 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
2618 InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2619 Method* method = ik->methods()->at(method_index);
3373 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3374 void* find_result = os::dll_lookup(handle, name);
3375 log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3376 find_result != nullptr ? "Found" : "Failed to find",
3377 name, p2i(handle));
3378 return find_result;
3379 JVM_END
3380
3381
3382 // JNI version ///////////////////////////////////////////////////////////////////////////////
3383
3384 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3385 return Threads::is_supported_jni_version_including_1_1(version);
3386 JVM_END
3387
3388
3389 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3390 return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3391 JVM_END
3392
3393 JVM_LEAF(jboolean, JVM_IsValhallaEnabled(void))
3394 return Arguments::is_valhalla_enabled() ? JNI_TRUE : JNI_FALSE;
3395 JVM_END
3396
3397 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3398 return VMContinuations ? JNI_TRUE : JNI_FALSE;
3399 JVM_END
3400
3401 JVM_LEAF(jboolean, JVM_IsForeignLinkerSupported(void))
3402 return ForeignGlobals::is_foreign_linker_supported() ? JNI_TRUE : JNI_FALSE;
3403 JVM_END
3404
3405 JVM_LEAF(jboolean, JVM_IsStaticallyLinked(void))
3406 return is_vm_statically_linked() ? JNI_TRUE : JNI_FALSE;
3407 JVM_END
3408
3409 // String support ///////////////////////////////////////////////////////////////////////////
3410
3411 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3412 JvmtiVMObjectAllocEventCollector oam;
3413 if (str == nullptr) return nullptr;
3414 oop string = JNIHandles::resolve_non_null(str);
3415 oop result = StringTable::intern(string, CHECK_NULL);
3416 return (jstring) JNIHandles::make_local(THREAD, result);
3456
3457 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3458 Handle loader, jboolean throwError, TRAPS) {
3459 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, throwError != 0, CHECK_NULL);
3460
3461 // Check if we should initialize the class
3462 if (init && klass->is_instance_klass()) {
3463 klass->initialize(CHECK_NULL);
3464 }
3465 return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3466 }
3467
3468
3469 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3470
3471 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3472 Handle method_handle;
3473 if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3474 method_handle = Handle(THREAD, JNIHandles::resolve(method));
3475 Handle receiver(THREAD, JNIHandles::resolve(obj));
3476 objArrayHandle args(THREAD, (objArrayOop)JNIHandles::resolve(args0));
3477 assert(args() == nullptr || !args->is_flatArray(), "args are never flat or are they???");
3478
3479 oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3480 jobject res = JNIHandles::make_local(THREAD, result);
3481 if (JvmtiExport::should_post_vm_object_alloc()) {
3482 oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3483 assert(ret_type != nullptr, "sanity check: ret_type oop must not be null!");
3484 if (java_lang_Class::is_primitive(ret_type)) {
3485 // Only for primitive type vm allocates memory for java object.
3486 // See box() method.
3487 JvmtiExport::post_vm_object_alloc(thread, result);
3488 }
3489 }
3490 return res;
3491 } else {
3492 THROW_NULL(vmSymbols::java_lang_StackOverflowError());
3493 }
3494 JVM_END
3495
3496
3497 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3498 objArrayHandle args(THREAD, (objArrayOop)JNIHandles::resolve(args0));
3499 assert(args() == nullptr || !args->is_flatArray(), "args are never flat or are they???");
3500 oop constructor_mirror = JNIHandles::resolve(c);
3501 oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3502 jobject res = JNIHandles::make_local(THREAD, result);
3503 if (JvmtiExport::should_post_vm_object_alloc()) {
3504 JvmtiExport::post_vm_object_alloc(thread, result);
3505 }
3506 return res;
3507 JVM_END
3508
3509 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3510 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3511 HeapShared::initialize_from_archived_subgraph(THREAD, k);
3512 JVM_END
3513
3514 JVM_ENTRY(void, JVM_RegisterLambdaProxyClassForArchiving(JNIEnv* env,
3515 jclass caller,
3516 jstring interfaceMethodName,
3517 jobject factoryType,
3518 jobject interfaceMethodType,
3519 jobject implementationMember,
3520 jobject dynamicMethodType,
3717 JvmtiVMObjectAllocEventCollector oam;
3718
3719 // Check if threads is null
3720 if (threads == nullptr) {
3721 THROW_NULL(vmSymbols::java_lang_NullPointerException());
3722 }
3723
3724 objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads));
3725 objArrayHandle ah(THREAD, a);
3726 int num_threads = ah->length();
3727 // check if threads is non-empty array
3728 if (num_threads == 0) {
3729 THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3730 }
3731
3732 // check if threads is not an array of objects of Thread class
3733 Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass();
3734 if (k != vmClasses::Thread_klass()) {
3735 THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3736 }
3737 refArrayHandle rah(THREAD, (refArrayOop)ah()); // j.l.Thread is an identity class, arrays are always reference arrays
3738
3739 ResourceMark rm(THREAD);
3740
3741 GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
3742 for (int i = 0; i < num_threads; i++) {
3743 oop thread_obj = rah->obj_at(i);
3744 instanceHandle h(THREAD, (instanceOop) thread_obj);
3745 thread_handle_array->append(h);
3746 }
3747
3748 // The JavaThread references in thread_handle_array are validated
3749 // in VM_ThreadDump::doit().
3750 Handle stacktraces = ThreadService::dump_stack_traces(thread_handle_array, num_threads, CHECK_NULL);
3751 return (jobjectArray)JNIHandles::make_local(THREAD, stacktraces());
3752
3753 JVM_END
3754
3755 // JVM monitoring and management support
3756 JVM_LEAF(void*, JVM_GetManagement(jint version))
3757 return Management::get_jmm_interface(version);
3758 JVM_END
3759
3760 // com.sun.tools.attach.VirtualMachine agent properties support
3761 //
3762 // Initialize the agent properties with the properties maintained in the VM
3763 JVM_ENTRY(jobject, JVM_InitAgentProperties(JNIEnv *env, jobject properties))
|