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/recordComponent.hpp"
65 #include "oops/objArrayKlass.hpp"
66 #include "oops/objArrayOop.inline.hpp"
67 #include "oops/oop.inline.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/atomic.hpp"
75 #include "runtime/continuation.hpp"
76 #include "runtime/globals_extension.hpp"
77 #include "runtime/handles.inline.hpp"
78 #include "runtime/init.hpp"
79 #include "runtime/interfaceSupport.inline.hpp"
80 #include "runtime/deoptimization.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);
1147 oop result = java_lang_Class::name(java_class, CHECK_NULL);
1148 return (jstring) JNIHandles::make_local(THREAD, result);
1149 JVM_END
1150
1151
1152 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1153 JvmtiVMObjectAllocEventCollector oam;
1154 oop mirror = JNIHandles::resolve_non_null(cls);
1155
1156 // Special handling for primitive objects
1157 if (java_lang_Class::is_primitive(mirror)) {
1158 // Primitive objects does not have any interfaces
1159 objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1160 return (jobjectArray) JNIHandles::make_local(THREAD, r);
1161 }
1162
1163 Klass* klass = java_lang_Class::as_Klass(mirror);
1164 // Figure size of result array
1165 int size;
1166 if (klass->is_instance_klass()) {
1167 size = InstanceKlass::cast(klass)->local_interfaces()->length();
1168 } else {
1169 assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1170 size = 2;
1171 }
1172
1173 // Allocate result array
1174 objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1175 objArrayHandle result (THREAD, r);
1176 // Fill in result
1177 if (klass->is_instance_klass()) {
1178 // Regular instance klass, fill in all local interfaces
1179 for (int index = 0; index < size; index++) {
1180 Klass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
1181 result->obj_at_put(index, k->java_mirror());
1182 }
1183 } else {
1184 // All arrays implement java.lang.Cloneable and java.io.Serializable
1185 result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1186 result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1187 }
1188 return (jobjectArray) JNIHandles::make_local(THREAD, result());
1189 JVM_END
1190
1191
1192 JVM_ENTRY(jboolean, JVM_IsHiddenClass(JNIEnv *env, jclass cls))
1193 oop mirror = JNIHandles::resolve_non_null(cls);
1194 if (java_lang_Class::is_primitive(mirror)) {
1195 return JNI_FALSE;
1196 }
1197 Klass* k = java_lang_Class::as_Klass(mirror);
1198 return k->is_hidden();
1199 JVM_END
1200
1201
1202 class ScopedValueBindingsResolver {
1203 public:
1204 InstanceKlass* Carrier_klass;
1205 ScopedValueBindingsResolver(JavaThread* THREAD) {
1206 Klass *k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ScopedValue_Carrier(), true, THREAD);
1207 Carrier_klass = InstanceKlass::cast(k);
1208 }
1209 };
1210
1211 JVM_ENTRY(jobject, JVM_FindScopedValueBindings(JNIEnv *env, jclass cls))
1212 ResourceMark rm(THREAD);
1213 GrowableArray<Handle>* local_array = new GrowableArray<Handle>(12);
1214 JvmtiVMObjectAllocEventCollector oam;
1215
1216 static ScopedValueBindingsResolver resolver(THREAD);
1217
1218 // Iterate through Java frames
1219 vframeStream vfst(thread);
1220 for(; !vfst.at_end(); vfst.next()) {
1221 int loc = -1;
1665 }
1666
1667 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(ofMirror));
1668
1669 // Ensure class is linked
1670 k->link_class(CHECK_NULL);
1671
1672 Array<Method*>* methods = k->methods();
1673 int methods_length = methods->length();
1674
1675 // Save original method_idnum in case of redefinition, which can change
1676 // the idnum of obsolete methods. The new method will have the same idnum
1677 // but if we refresh the methods array, the counts will be wrong.
1678 ResourceMark rm(THREAD);
1679 GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
1680 int num_methods = 0;
1681
1682 // Select methods matching the criteria.
1683 for (int i = 0; i < methods_length; i++) {
1684 Method* method = methods->at(i);
1685 if (want_constructor && !method->is_object_initializer()) {
1686 continue;
1687 }
1688 if (!want_constructor &&
1689 (method->is_object_initializer() || method->is_static_initializer() ||
1690 method->is_overpass())) {
1691 continue;
1692 }
1693 if (publicOnly && !method->is_public()) {
1694 continue;
1695 }
1696 idnums->push(method->method_idnum());
1697 ++num_methods;
1698 }
1699
1700 // Allocate result
1701 objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1702 objArrayHandle result (THREAD, r);
1703
1704 // Now just put the methods that we selected above, but go by their idnum
1705 // in case of redefinition. The methods can be redefined at any safepoint,
1706 // so above when allocating the oop array and below when creating reflect
1707 // objects.
1708 for (int i = 0; i < num_methods; i++) {
1709 methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1710 if (method.is_null()) {
1711 // Method may have been deleted and seems this API can handle null
1712 // Otherwise should probably put a method that throws NSME
1713 result->obj_at_put(i, nullptr);
1714 } else {
1715 oop m;
1716 if (want_constructor) {
1717 m = Reflection::new_constructor(method, CHECK_NULL);
1718 } else {
1719 m = Reflection::new_method(method, false, CHECK_NULL);
1720 }
1721 result->obj_at_put(i, m);
1722 }
1723 }
1724
1725 return (jobjectArray) JNIHandles::make_local(THREAD, result());
1726 }
1727
1728 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1729 {
1730 return get_class_declared_methods_helper(env, ofClass, publicOnly,
1731 /*want_constructor*/ false,
1732 vmClasses::reflect_Method_klass(), THREAD);
1733 }
1734 JVM_END
1735
1736 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1979 constantTag tag = cp->tag_at(index);
1980 if (!tag.is_method() && !tag.is_interface_method()) {
1981 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1982 }
1983 int klass_ref = cp->uncached_klass_ref_index_at(index);
1984 Klass* k_o;
1985 if (force_resolution) {
1986 k_o = cp->klass_at(klass_ref, CHECK_NULL);
1987 } else {
1988 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
1989 if (k_o == nullptr) return nullptr;
1990 }
1991 InstanceKlass* k = InstanceKlass::cast(k_o);
1992 Symbol* name = cp->uncached_name_ref_at(index);
1993 Symbol* sig = cp->uncached_signature_ref_at(index);
1994 methodHandle m (THREAD, k->find_method(name, sig));
1995 if (m.is_null()) {
1996 THROW_MSG_NULL(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
1997 }
1998 oop method;
1999 if (m->is_object_initializer()) {
2000 method = Reflection::new_constructor(m, CHECK_NULL);
2001 } else {
2002 // new_method accepts <clinit> as Method here
2003 method = Reflection::new_method(m, true, CHECK_NULL);
2004 }
2005 return JNIHandles::make_local(THREAD, method);
2006 }
2007
2008 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2009 {
2010 JvmtiVMObjectAllocEventCollector oam;
2011 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2012 bounds_check(cp, index, CHECK_NULL);
2013 jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2014 return res;
2015 }
2016 JVM_END
2017
2018 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2019 {
2020 JvmtiVMObjectAllocEventCollector oam;
2021 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2022 bounds_check(cp, index, CHECK_NULL);
2432 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2433 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2434 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2435 return method->size_of_parameters();
2436 JVM_END
2437
2438
2439 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2440 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2441 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2442 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2443 return method->verifier_max_stack();
2444 JVM_END
2445
2446
2447 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2448 ResourceMark rm(THREAD);
2449 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2450 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2451 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2452 return method->name() == vmSymbols::object_initializer_name();
2453 JVM_END
2454
2455
2456 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2457 ResourceMark rm(THREAD);
2458 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2459 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2460 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2461 return method->is_overpass();
2462 JVM_END
2463
2464 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2465 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2466 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2467 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2468 return method->name()->as_utf8();
2469 JVM_END
2470
2471
2472 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
3223 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3224 void* find_result = os::dll_lookup(handle, name);
3225 log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3226 find_result != nullptr ? "Found" : "Failed to find",
3227 name, p2i(handle));
3228 return find_result;
3229 JVM_END
3230
3231
3232 // JNI version ///////////////////////////////////////////////////////////////////////////////
3233
3234 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3235 return Threads::is_supported_jni_version_including_1_1(version);
3236 JVM_END
3237
3238
3239 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3240 return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3241 JVM_END
3242
3243 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3244 return VMContinuations ? JNI_TRUE : JNI_FALSE;
3245 JVM_END
3246
3247 JVM_LEAF(jboolean, JVM_IsForeignLinkerSupported(void))
3248 return ForeignGlobals::is_foreign_linker_supported() ? JNI_TRUE : JNI_FALSE;
3249 JVM_END
3250
3251 JVM_LEAF(jboolean, JVM_IsStaticallyLinked(void))
3252 return is_vm_statically_linked() ? JNI_TRUE : JNI_FALSE;
3253 JVM_END
3254
3255 // String support ///////////////////////////////////////////////////////////////////////////
3256
3257 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3258 JvmtiVMObjectAllocEventCollector oam;
3259 if (str == nullptr) return nullptr;
3260 oop string = JNIHandles::resolve_non_null(str);
3261 oop result = StringTable::intern(string, CHECK_NULL);
3262 return (jstring) JNIHandles::make_local(THREAD, result);
3302
3303 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3304 Handle loader, jboolean throwError, TRAPS) {
3305 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, throwError != 0, CHECK_NULL);
3306
3307 // Check if we should initialize the class
3308 if (init && klass->is_instance_klass()) {
3309 klass->initialize(CHECK_NULL);
3310 }
3311 return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3312 }
3313
3314
3315 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3316
3317 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3318 Handle method_handle;
3319 if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3320 method_handle = Handle(THREAD, JNIHandles::resolve(method));
3321 Handle receiver(THREAD, JNIHandles::resolve(obj));
3322 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3323 oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3324 jobject res = JNIHandles::make_local(THREAD, result);
3325 if (JvmtiExport::should_post_vm_object_alloc()) {
3326 oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3327 assert(ret_type != nullptr, "sanity check: ret_type oop must not be null!");
3328 if (java_lang_Class::is_primitive(ret_type)) {
3329 // Only for primitive type vm allocates memory for java object.
3330 // See box() method.
3331 JvmtiExport::post_vm_object_alloc(thread, result);
3332 }
3333 }
3334 return res;
3335 } else {
3336 THROW_NULL(vmSymbols::java_lang_StackOverflowError());
3337 }
3338 JVM_END
3339
3340
3341 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3342 oop constructor_mirror = JNIHandles::resolve(c);
3343 objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3344 oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3345 jobject res = JNIHandles::make_local(THREAD, result);
3346 if (JvmtiExport::should_post_vm_object_alloc()) {
3347 JvmtiExport::post_vm_object_alloc(thread, result);
3348 }
3349 return res;
3350 JVM_END
3351
3352 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3353 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3354 HeapShared::initialize_from_archived_subgraph(THREAD, k);
3355 JVM_END
3356
3357 JVM_ENTRY(void, JVM_RegisterLambdaProxyClassForArchiving(JNIEnv* env,
3358 jclass caller,
3359 jstring interfaceMethodName,
3360 jobject factoryType,
3361 jobject interfaceMethodType,
3362 jobject implementationMember,
3363 jobject dynamicMethodType,
|
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/recordComponent.hpp"
66 #include "oops/objArrayKlass.hpp"
67 #include "oops/objArrayOop.inline.hpp"
68 #include "oops/oop.inline.hpp"
69 #include "prims/foreignGlobals.hpp"
70 #include "prims/jvm_misc.hpp"
71 #include "prims/jvmtiExport.hpp"
72 #include "prims/jvmtiThreadState.inline.hpp"
73 #include "prims/stackwalk.hpp"
74 #include "runtime/arguments.hpp"
75 #include "runtime/atomic.hpp"
76 #include "runtime/continuation.hpp"
77 #include "runtime/globals_extension.hpp"
78 #include "runtime/handles.inline.hpp"
79 #include "runtime/init.hpp"
80 #include "runtime/interfaceSupport.inline.hpp"
81 #include "runtime/deoptimization.hpp"
397
398 return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
399 JVM_END
400
401
402 /*
403 * Return the temporary directory that the VM uses for the attach
404 * and perf data files.
405 *
406 * It is important that this directory is well-known and the
407 * same for all VM instances. It cannot be affected by configuration
408 * variables such as java.io.tmpdir.
409 */
410 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
411 HandleMark hm(THREAD);
412 const char* temp_dir = os::get_temp_directory();
413 Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
414 return (jstring) JNIHandles::make_local(THREAD, h());
415 JVM_END
416
417 static void validate_array_arguments(Klass* elmClass, jint len, TRAPS) {
418 if (len < 0) {
419 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Array length is negative");
420 }
421 elmClass->initialize(CHECK);
422 if (elmClass->is_array_klass() || elmClass->is_identity_class()) {
423 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Element class is not a value class");
424 }
425 if (elmClass->is_abstract()) {
426 THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Element class is abstract");
427 }
428 }
429
430 JVM_ENTRY(jarray, JVM_CopyOfSpecialArray(JNIEnv *env, jarray orig, jint from, jint to))
431 oop o = JNIHandles::resolve_non_null(orig);
432 assert(o->is_array(), "Must be");
433 oop array = nullptr;
434 arrayOop org = (arrayOop)o;
435 arrayHandle oh(THREAD, org);
436 ArrayKlass* ak = ArrayKlass::cast(org->klass());
437 InlineKlass* vk = InlineKlass::cast(ak->element_klass());
438 int len = to - from; // length of the new array
439 if (ak->is_null_free_array_klass()) {
440 if (from >= org->length() || to > org->length()) {
441 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Copying of null-free array with uninitialized elements");
442 }
443 }
444 if (org->is_flatArray()) {
445 FlatArrayKlass* fak = FlatArrayKlass::cast(org->klass());
446 LayoutKind lk = fak->layout_kind();
447 array = oopFactory::new_flatArray(vk, len, lk, CHECK_NULL);
448 arrayHandle ah(THREAD, (arrayOop)array);
449 int end = to < oh()->length() ? to : oh()->length();
450 for (int i = from; i < end; i++) {
451 void* src = ((flatArrayOop)oh())->value_at_addr(i, fak->layout_helper());
452 void* dst = ((flatArrayOop)ah())->value_at_addr(i - from, fak->layout_helper());
453 vk->copy_payload_to_addr(src, dst, lk, false);
454 }
455 array = ah();
456 } else {
457 if (org->is_null_free_array()) {
458 array = oopFactory::new_null_free_objArray(vk, len, CHECK_NULL);
459 } else {
460 array = oopFactory::new_objArray(vk, len, CHECK_NULL);
461 }
462 int end = to < oh()->length() ? to : oh()->length();
463 for (int i = from; i < end; i++) {
464 if (i < ((objArrayOop)oh())->length()) {
465 ((objArrayOop)array)->obj_at_put(i - from, ((objArrayOop)oh())->obj_at(i));
466 } else {
467 assert(!ak->is_null_free_array_klass(), "Must be a nullable array");
468 ((objArrayOop)array)->obj_at_put(i - from, nullptr);
469 }
470 }
471 }
472 return (jarray) JNIHandles::make_local(THREAD, array);
473 JVM_END
474
475 JVM_ENTRY(jarray, JVM_NewNullRestrictedNonAtomicArray(JNIEnv *env, jclass elmClass, jint len, jobject initVal))
476 oop mirror = JNIHandles::resolve_non_null(elmClass);
477 oop init = JNIHandles::resolve(initVal);
478 if (init == nullptr) {
479 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Initial value cannot be null");
480 }
481 Handle init_h(THREAD, init);
482 Klass* klass = java_lang_Class::as_Klass(mirror);
483 if (klass != init_h()->klass()) {
484 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Type mismatch between array and initial value");
485 }
486 validate_array_arguments(klass, len, CHECK_NULL);
487 InlineKlass* vk = InlineKlass::cast(klass);
488 oop array = nullptr;
489 if (vk->maybe_flat_in_array() && vk->has_non_atomic_layout()) {
490 array = oopFactory::new_flatArray(vk, len, LayoutKind::NON_ATOMIC_FLAT, CHECK_NULL);
491 for (int i = 0; i < len; i++) {
492 ((flatArrayOop)array)->write_value_to_flat_array(init_h(), i, CHECK_NULL);
493 }
494 } else {
495 array = oopFactory::new_null_free_objArray(vk, len, CHECK_NULL);
496 for (int i = 0; i < len; i++) {
497 ((objArrayOop)array)->obj_at_put(i, init_h());
498 }
499 }
500 return (jarray) JNIHandles::make_local(THREAD, array);
501 JVM_END
502
503 JVM_ENTRY(jarray, JVM_NewNullRestrictedAtomicArray(JNIEnv *env, jclass elmClass, jint len, jobject initVal))
504 oop mirror = JNIHandles::resolve_non_null(elmClass);
505 oop init = JNIHandles::resolve(initVal);
506 if (init == nullptr) {
507 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Initial value cannot be null");
508 }
509 Handle init_h(THREAD, init);
510 Klass* klass = java_lang_Class::as_Klass(mirror);
511 if (klass != init_h()->klass()) {
512 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Type mismatch between array and initial value");
513 }
514 validate_array_arguments(klass, len, CHECK_NULL);
515 InlineKlass* vk = InlineKlass::cast(klass);
516 oop array = nullptr;
517 if (vk->maybe_flat_in_array() && vk->is_naturally_atomic() && vk->has_non_atomic_layout()) {
518 array = oopFactory::new_flatArray(vk, len, LayoutKind::NON_ATOMIC_FLAT, CHECK_NULL);
519 for (int i = 0; i < len; i++) {
520 ((flatArrayOop)array)->write_value_to_flat_array(init_h(), i, CHECK_NULL);
521 }
522 } else if (vk->maybe_flat_in_array() && vk->has_atomic_layout()) {
523 array = oopFactory::new_flatArray(vk, len, LayoutKind::ATOMIC_FLAT, CHECK_NULL);
524 for (int i = 0; i < len; i++) {
525 ((flatArrayOop)array)->write_value_to_flat_array(init_h(), i, CHECK_NULL);
526 }
527 } else {
528 array = oopFactory::new_null_free_objArray(vk, len, CHECK_NULL);
529 for (int i = 0; i < len; i++) {
530 // need a type check here
531
532 ((objArrayOop)array)->obj_at_put(i, init_h());
533 }
534 }
535 return (jarray) JNIHandles::make_local(THREAD, array);
536 JVM_END
537
538 JVM_ENTRY(jarray, JVM_NewNullableAtomicArray(JNIEnv *env, jclass elmClass, jint len))
539 oop mirror = JNIHandles::resolve_non_null(elmClass);
540 Klass* klass = java_lang_Class::as_Klass(mirror);
541 klass->initialize(CHECK_NULL);
542 validate_array_arguments(klass, len, CHECK_NULL);
543 InlineKlass* vk = InlineKlass::cast(klass);
544 oop array = nullptr;
545 if (vk->maybe_flat_in_array() && vk->has_nullable_atomic_layout()) {
546 array = oopFactory::new_flatArray(vk, len, LayoutKind::NULLABLE_ATOMIC_FLAT, CHECK_NULL);
547 } else {
548 array = oopFactory::new_objArray(vk, len, CHECK_NULL);
549 }
550 return (jarray) JNIHandles::make_local(THREAD, array);
551 JVM_END
552
553 JVM_ENTRY(jboolean, JVM_IsFlatArray(JNIEnv *env, jobject obj))
554 arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
555 return oop->is_flatArray();
556 JVM_END
557
558 JVM_ENTRY(jboolean, JVM_IsNullRestrictedArray(JNIEnv *env, jobject obj))
559 arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
560 return oop->is_null_free_array();
561 JVM_END
562
563 JVM_ENTRY(jboolean, JVM_IsAtomicArray(JNIEnv *env, jobject obj))
564 // There are multiple cases where an array can/must support atomic access:
565 // - the array is a reference array
566 // - the array uses an atomic flat layout: NULLABLE_ATOMIC_FLAT or ATOMIC_FLAT
567 // - the array is flat and its component type is naturally atomic
568 arrayOop oop = arrayOop(JNIHandles::resolve_non_null(obj));
569 if (oop->is_objArray()) return true;
570 if (oop->is_flatArray()) {
571 FlatArrayKlass* fak = FlatArrayKlass::cast(oop->klass());
572 if (fak->layout_kind() == LayoutKind::ATOMIC_FLAT || fak->layout_kind() == LayoutKind::NULLABLE_ATOMIC_FLAT) {
573 return true;
574 }
575 if (fak->element_klass()->is_naturally_atomic()) return true;
576 }
577 return false;
578 JVM_END
579
580 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
581
582 extern volatile jint vm_created;
583
584 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
585 EventShutdown event;
586 if (event.should_commit()) {
587 event.set_reason("Shutdown requested from Java");
588 event.commit();
589 }
590 JVM_END
591
592
593 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
594 before_exit(thread, true);
595 vm_exit(code);
596 JVM_END
597
598
767
768 Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
769 return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, last_batch_count, buffer_size,
770 start_index, frames_array_h, THREAD);
771 JVM_END
772
773 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
774 objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
775 objArrayHandle frames_array_h(THREAD, fa);
776 Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
777 Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
778
779 StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
780 JVM_END
781
782 // java.lang.Object ///////////////////////////////////////////////
783
784
785 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
786 // as implemented in the classic virtual machine; return 0 if object is null
787 if (handle == nullptr) {
788 return 0;
789 }
790 oop obj = JNIHandles::resolve_non_null(handle);
791 if (EnableValhalla && obj->klass()->is_inline_klass()) {
792 JavaValue result(T_INT);
793 JavaCallArguments args;
794 Handle ho(THREAD, obj);
795 args.push_oop(ho);
796 methodHandle method(THREAD, Universe::value_object_hash_code_method());
797 JavaCalls::call(&result, method, &args, THREAD);
798 if (HAS_PENDING_EXCEPTION) {
799 if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
800 Handle e(THREAD, PENDING_EXCEPTION);
801 CLEAR_PENDING_EXCEPTION;
802 THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in hashCode", e, false);
803 }
804 }
805 return result.get_jint();
806 } else {
807 return checked_cast<jint>(ObjectSynchronizer::FastHashCode(THREAD, obj));
808 }
809 JVM_END
810
811
812 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
813 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
814 ObjectSynchronizer::wait(obj, ms, CHECK);
815 JVM_END
816
817
818 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
819 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
820 ObjectSynchronizer::notify(obj, CHECK);
821 JVM_END
822
823
824 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
825 Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
826 ObjectSynchronizer::notifyall(obj, CHECK);
827 JVM_END
828
836 // Just checking that the cloneable flag is set correct
837 if (obj->is_array()) {
838 guarantee(klass->is_cloneable(), "all arrays are cloneable");
839 } else {
840 guarantee(obj->is_instance(), "should be instanceOop");
841 bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
842 guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
843 }
844 #endif
845
846 // Check if class of obj supports the Cloneable interface.
847 // All arrays are considered to be cloneable (See JLS 20.1.5).
848 // All j.l.r.Reference classes are considered non-cloneable.
849 if (!klass->is_cloneable() ||
850 (klass->is_instance_klass() &&
851 InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
852 ResourceMark rm(THREAD);
853 THROW_MSG_NULL(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
854 }
855
856 if (klass->is_inline_klass()) {
857 // Value instances have no identity, so return the current instance instead of allocating a new one
858 // Value classes cannot have finalizers, so the method can return immediately
859 return JNIHandles::make_local(THREAD, obj());
860 }
861
862 // Make shallow object copy
863 const size_t size = obj->size();
864 oop new_obj_oop = nullptr;
865 if (obj->is_array()) {
866 const int length = ((arrayOop)obj())->length();
867 new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
868 /* do_zero */ true, CHECK_NULL);
869 } else {
870 new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
871 }
872
873 HeapAccess<>::clone(obj(), new_obj_oop, size);
874
875 Handle new_obj(THREAD, new_obj_oop);
876 // Caution: this involves a java upcall, so the clone should be
877 // "gc-robust" by this stage.
878 if (klass->has_finalizer()) {
879 assert(obj->is_instance(), "should be instanceOop");
880 new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
881 new_obj = Handle(THREAD, new_obj_oop);
1336 oop result = java_lang_Class::name(java_class, CHECK_NULL);
1337 return (jstring) JNIHandles::make_local(THREAD, result);
1338 JVM_END
1339
1340
1341 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1342 JvmtiVMObjectAllocEventCollector oam;
1343 oop mirror = JNIHandles::resolve_non_null(cls);
1344
1345 // Special handling for primitive objects
1346 if (java_lang_Class::is_primitive(mirror)) {
1347 // Primitive objects does not have any interfaces
1348 objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1349 return (jobjectArray) JNIHandles::make_local(THREAD, r);
1350 }
1351
1352 Klass* klass = java_lang_Class::as_Klass(mirror);
1353 // Figure size of result array
1354 int size;
1355 if (klass->is_instance_klass()) {
1356 InstanceKlass* ik = InstanceKlass::cast(klass);
1357 size = ik->local_interfaces()->length();
1358 } else {
1359 assert(klass->is_objArray_klass() || klass->is_typeArray_klass() || klass->is_flatArray_klass(), "Illegal mirror klass");
1360 size = 2;
1361 }
1362
1363 // Allocate result array
1364 objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1365 objArrayHandle result (THREAD, r);
1366 // Fill in result
1367 if (klass->is_instance_klass()) {
1368 // Regular instance klass, fill in all local interfaces
1369 for (int index = 0; index < size; index++) {
1370 InstanceKlass* ik = InstanceKlass::cast(klass);
1371 Klass* k = ik->local_interfaces()->at(index);
1372 result->obj_at_put(index, k->java_mirror());
1373 }
1374 } else {
1375 // All arrays implement java.lang.Cloneable and java.io.Serializable
1376 result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1377 result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1378 }
1379 return (jobjectArray) JNIHandles::make_local(THREAD, result());
1380 JVM_END
1381
1382
1383 JVM_ENTRY(jboolean, JVM_IsHiddenClass(JNIEnv *env, jclass cls))
1384 oop mirror = JNIHandles::resolve_non_null(cls);
1385 if (java_lang_Class::is_primitive(mirror)) {
1386 return JNI_FALSE;
1387 }
1388 Klass* k = java_lang_Class::as_Klass(mirror);
1389 return k->is_hidden();
1390 JVM_END
1391
1392 class ScopedValueBindingsResolver {
1393 public:
1394 InstanceKlass* Carrier_klass;
1395 ScopedValueBindingsResolver(JavaThread* THREAD) {
1396 Klass *k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_ScopedValue_Carrier(), true, THREAD);
1397 Carrier_klass = InstanceKlass::cast(k);
1398 }
1399 };
1400
1401 JVM_ENTRY(jobject, JVM_FindScopedValueBindings(JNIEnv *env, jclass cls))
1402 ResourceMark rm(THREAD);
1403 GrowableArray<Handle>* local_array = new GrowableArray<Handle>(12);
1404 JvmtiVMObjectAllocEventCollector oam;
1405
1406 static ScopedValueBindingsResolver resolver(THREAD);
1407
1408 // Iterate through Java frames
1409 vframeStream vfst(thread);
1410 for(; !vfst.at_end(); vfst.next()) {
1411 int loc = -1;
1855 }
1856
1857 InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(ofMirror));
1858
1859 // Ensure class is linked
1860 k->link_class(CHECK_NULL);
1861
1862 Array<Method*>* methods = k->methods();
1863 int methods_length = methods->length();
1864
1865 // Save original method_idnum in case of redefinition, which can change
1866 // the idnum of obsolete methods. The new method will have the same idnum
1867 // but if we refresh the methods array, the counts will be wrong.
1868 ResourceMark rm(THREAD);
1869 GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
1870 int num_methods = 0;
1871
1872 // Select methods matching the criteria.
1873 for (int i = 0; i < methods_length; i++) {
1874 Method* method = methods->at(i);
1875 if (want_constructor && !method->is_object_constructor()) {
1876 continue;
1877 }
1878 if (!want_constructor &&
1879 (method->is_object_constructor() || method->is_class_initializer() ||
1880 method->is_overpass())) {
1881 continue;
1882 }
1883 if (publicOnly && !method->is_public()) {
1884 continue;
1885 }
1886 idnums->push(method->method_idnum());
1887 ++num_methods;
1888 }
1889
1890 // Allocate result
1891 objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1892 objArrayHandle result (THREAD, r);
1893
1894 // Now just put the methods that we selected above, but go by their idnum
1895 // in case of redefinition. The methods can be redefined at any safepoint,
1896 // so above when allocating the oop array and below when creating reflect
1897 // objects.
1898 for (int i = 0; i < num_methods; i++) {
1899 methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1900 if (method.is_null()) {
1901 // Method may have been deleted and seems this API can handle null
1902 // Otherwise should probably put a method that throws NSME
1903 result->obj_at_put(i, nullptr);
1904 } else {
1905 oop m;
1906 if (want_constructor) {
1907 assert(method->is_object_constructor(), "must be");
1908 m = Reflection::new_constructor(method, CHECK_NULL);
1909 } else {
1910 m = Reflection::new_method(method, false, CHECK_NULL);
1911 }
1912 result->obj_at_put(i, m);
1913 }
1914 }
1915
1916 return (jobjectArray) JNIHandles::make_local(THREAD, result());
1917 }
1918
1919 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1920 {
1921 return get_class_declared_methods_helper(env, ofClass, publicOnly,
1922 /*want_constructor*/ false,
1923 vmClasses::reflect_Method_klass(), THREAD);
1924 }
1925 JVM_END
1926
1927 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))
2170 constantTag tag = cp->tag_at(index);
2171 if (!tag.is_method() && !tag.is_interface_method()) {
2172 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2173 }
2174 int klass_ref = cp->uncached_klass_ref_index_at(index);
2175 Klass* k_o;
2176 if (force_resolution) {
2177 k_o = cp->klass_at(klass_ref, CHECK_NULL);
2178 } else {
2179 k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2180 if (k_o == nullptr) return nullptr;
2181 }
2182 InstanceKlass* k = InstanceKlass::cast(k_o);
2183 Symbol* name = cp->uncached_name_ref_at(index);
2184 Symbol* sig = cp->uncached_signature_ref_at(index);
2185 methodHandle m (THREAD, k->find_method(name, sig));
2186 if (m.is_null()) {
2187 THROW_MSG_NULL(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2188 }
2189 oop method;
2190 if (m->is_object_constructor()) {
2191 method = Reflection::new_constructor(m, CHECK_NULL);
2192 } else {
2193 method = Reflection::new_method(m, true, CHECK_NULL);
2194 }
2195 return JNIHandles::make_local(THREAD, method);
2196 }
2197
2198 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2199 {
2200 JvmtiVMObjectAllocEventCollector oam;
2201 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2202 bounds_check(cp, index, CHECK_NULL);
2203 jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2204 return res;
2205 }
2206 JVM_END
2207
2208 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2209 {
2210 JvmtiVMObjectAllocEventCollector oam;
2211 constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2212 bounds_check(cp, index, CHECK_NULL);
2622 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2623 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2624 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2625 return method->size_of_parameters();
2626 JVM_END
2627
2628
2629 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2630 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2631 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2632 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2633 return method->verifier_max_stack();
2634 JVM_END
2635
2636
2637 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2638 ResourceMark rm(THREAD);
2639 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2640 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2641 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2642 return method->is_object_constructor();
2643 JVM_END
2644
2645
2646 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2647 ResourceMark rm(THREAD);
2648 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2649 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2650 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2651 return method->is_overpass();
2652 JVM_END
2653
2654 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2655 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2656 k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2657 Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2658 return method->name()->as_utf8();
2659 JVM_END
2660
2661
2662 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
3413 JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name))
3414 void* find_result = os::dll_lookup(handle, name);
3415 log_info(library)("%s %s in library with handle " INTPTR_FORMAT,
3416 find_result != nullptr ? "Found" : "Failed to find",
3417 name, p2i(handle));
3418 return find_result;
3419 JVM_END
3420
3421
3422 // JNI version ///////////////////////////////////////////////////////////////////////////////
3423
3424 JVM_LEAF(jboolean, JVM_IsSupportedJNIVersion(jint version))
3425 return Threads::is_supported_jni_version_including_1_1(version);
3426 JVM_END
3427
3428
3429 JVM_LEAF(jboolean, JVM_IsPreviewEnabled(void))
3430 return Arguments::enable_preview() ? JNI_TRUE : JNI_FALSE;
3431 JVM_END
3432
3433 JVM_LEAF(jboolean, JVM_IsValhallaEnabled(void))
3434 return EnableValhalla ? JNI_TRUE : JNI_FALSE;
3435 JVM_END
3436
3437 JVM_LEAF(jboolean, JVM_IsContinuationsSupported(void))
3438 return VMContinuations ? JNI_TRUE : JNI_FALSE;
3439 JVM_END
3440
3441 JVM_LEAF(jboolean, JVM_IsForeignLinkerSupported(void))
3442 return ForeignGlobals::is_foreign_linker_supported() ? JNI_TRUE : JNI_FALSE;
3443 JVM_END
3444
3445 JVM_LEAF(jboolean, JVM_IsStaticallyLinked(void))
3446 return is_vm_statically_linked() ? JNI_TRUE : JNI_FALSE;
3447 JVM_END
3448
3449 // String support ///////////////////////////////////////////////////////////////////////////
3450
3451 JVM_ENTRY(jstring, JVM_InternString(JNIEnv *env, jstring str))
3452 JvmtiVMObjectAllocEventCollector oam;
3453 if (str == nullptr) return nullptr;
3454 oop string = JNIHandles::resolve_non_null(str);
3455 oop result = StringTable::intern(string, CHECK_NULL);
3456 return (jstring) JNIHandles::make_local(THREAD, result);
3496
3497 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3498 Handle loader, jboolean throwError, TRAPS) {
3499 Klass* klass = SystemDictionary::resolve_or_fail(name, loader, throwError != 0, CHECK_NULL);
3500
3501 // Check if we should initialize the class
3502 if (init && klass->is_instance_klass()) {
3503 klass->initialize(CHECK_NULL);
3504 }
3505 return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3506 }
3507
3508
3509 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3510
3511 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3512 Handle method_handle;
3513 if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3514 method_handle = Handle(THREAD, JNIHandles::resolve(method));
3515 Handle receiver(THREAD, JNIHandles::resolve(obj));
3516 objArrayHandle args(THREAD, (objArrayOop)JNIHandles::resolve(args0));
3517 assert(args() == nullptr || !args->is_flatArray(), "args are never flat or are they???");
3518
3519 oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3520 jobject res = JNIHandles::make_local(THREAD, result);
3521 if (JvmtiExport::should_post_vm_object_alloc()) {
3522 oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3523 assert(ret_type != nullptr, "sanity check: ret_type oop must not be null!");
3524 if (java_lang_Class::is_primitive(ret_type)) {
3525 // Only for primitive type vm allocates memory for java object.
3526 // See box() method.
3527 JvmtiExport::post_vm_object_alloc(thread, result);
3528 }
3529 }
3530 return res;
3531 } else {
3532 THROW_NULL(vmSymbols::java_lang_StackOverflowError());
3533 }
3534 JVM_END
3535
3536
3537 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3538 objArrayHandle args(THREAD, (objArrayOop)JNIHandles::resolve(args0));
3539 assert(args() == nullptr || !args->is_flatArray(), "args are never flat or are they???");
3540 oop constructor_mirror = JNIHandles::resolve(c);
3541 oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3542 jobject res = JNIHandles::make_local(THREAD, result);
3543 if (JvmtiExport::should_post_vm_object_alloc()) {
3544 JvmtiExport::post_vm_object_alloc(thread, result);
3545 }
3546 return res;
3547 JVM_END
3548
3549 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3550 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3551 HeapShared::initialize_from_archived_subgraph(THREAD, k);
3552 JVM_END
3553
3554 JVM_ENTRY(void, JVM_RegisterLambdaProxyClassForArchiving(JNIEnv* env,
3555 jclass caller,
3556 jstring interfaceMethodName,
3557 jobject factoryType,
3558 jobject interfaceMethodType,
3559 jobject implementationMember,
3560 jobject dynamicMethodType,
|