< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

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


  61 #include "oops/instanceKlass.hpp"
  62 #include "oops/klass.inline.hpp"
  63 #include "oops/method.hpp"
  64 #include "oops/objArrayKlass.hpp"
  65 #include "oops/objArrayOop.inline.hpp"
  66 #include "oops/oop.inline.hpp"

  67 #include "oops/recordComponent.hpp"


  68 #include "prims/foreignGlobals.hpp"
  69 #include "prims/jvm_misc.hpp"
  70 #include "prims/jvmtiExport.hpp"
  71 #include "prims/jvmtiThreadState.inline.hpp"
  72 #include "prims/stackwalk.hpp"
  73 #include "runtime/arguments.hpp"
  74 #include "runtime/atomicAccess.hpp"
  75 #include "runtime/continuation.hpp"
  76 #include "runtime/deoptimization.hpp"
  77 #include "runtime/globals_extension.hpp"
  78 #include "runtime/handles.inline.hpp"
  79 #include "runtime/handshake.hpp"
  80 #include "runtime/init.hpp"
  81 #include "runtime/interfaceSupport.inline.hpp"
  82 #include "runtime/java.hpp"
  83 #include "runtime/javaCalls.hpp"
  84 #include "runtime/javaThread.hpp"
  85 #include "runtime/jfieldIDWorkaround.hpp"
  86 #include "runtime/jniHandles.inline.hpp"
  87 #include "runtime/mountUnmountDisabler.hpp"

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
























































































































































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

 522   }
 523   if (method->is_native()) {
 524     return nullptr;
 525   }
 526 
 527   stringStream ss;
 528   bool ok = BytecodeUtils::get_NPE_message_at(&ss, method, bci);
 529   if (ok) {
 530     oop result = java_lang_String::create_oop_from_str(ss.base(), CHECK_NULL);
 531     return (jstring) JNIHandles::make_local(THREAD, result);
 532   } else {
 533     return nullptr;
 534   }
 535 JVM_END
 536 
 537 // java.lang.StackTraceElement //////////////////////////////////////////////
 538 
 539 
 540 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject backtrace, jint depth))
 541   Handle backtraceh(THREAD, JNIHandles::resolve(backtrace));
 542   objArrayOop st = objArrayOop(JNIHandles::resolve(elements));
 543   objArrayHandle stack_trace(THREAD, st);
 544   // Fill in the allocated stack trace
 545   java_lang_Throwable::get_stack_trace_elements(depth, backtraceh, stack_trace, CHECK);
 546 JVM_END
 547 
 548 
 549 JVM_ENTRY(void, JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo))
 550   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(stackFrameInfo));
 551   Handle stack_trace_element(THREAD, JNIHandles::resolve_non_null(element));
 552   java_lang_StackFrameInfo::to_stack_trace_element(stack_frame_info, stack_trace_element, CHECK);
 553 JVM_END
 554 
 555 
 556 // java.lang.StackWalker //////////////////////////////////////////////////////
 557 JVM_ENTRY(void, JVM_ExpandStackFrameInfo(JNIEnv *env, jobject obj))
 558   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(obj));
 559 
 560   bool have_name = (java_lang_StackFrameInfo::name(stack_frame_info()) != nullptr);
 561   bool have_type = (java_lang_StackFrameInfo::type(stack_frame_info()) != nullptr);
 562   Method* method = java_lang_StackFrameInfo::get_method(stack_frame_info());
 563   if (!have_name) {

 566   }
 567   if (!have_type) {
 568     Handle type = java_lang_String::create_from_symbol(method->signature(), CHECK);
 569     java_lang_StackFrameInfo::set_type(stack_frame_info(), type());
 570   }
 571 JVM_END
 572 
 573 JVM_ENTRY(jobject, JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jint mode,
 574                                      jint skip_frames, jobject contScope, jobject cont,
 575                                      jint buffer_size, jint start_index, jobjectArray frames))
 576   if (!thread->has_last_Java_frame()) {
 577     THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: no stack trace", nullptr);
 578   }
 579 
 580   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 581   Handle contScope_h(THREAD, JNIHandles::resolve(contScope));
 582   Handle cont_h(THREAD, JNIHandles::resolve(cont));
 583   // frames array is a ClassFrameInfo[] array when only getting caller reference,
 584   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 585   // be null.
 586   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 587   objArrayHandle frames_array_h(THREAD, fa);
 588 
 589   if (frames_array_h->length() < buffer_size) {
 590     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", nullptr);
 591   }
 592 
 593   oop result = StackWalk::walk(stackStream_h, mode, skip_frames, contScope_h, cont_h,
 594                                buffer_size, start_index, frames_array_h, CHECK_NULL);
 595   return JNIHandles::make_local(THREAD, result);
 596 JVM_END
 597 
 598 
 599 JVM_ENTRY(jint, JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jint mode, jlong anchor,
 600                                   jint last_batch_count, jint buffer_size, jint start_index,
 601                                   jobjectArray frames))
 602   // frames array is a ClassFrameInfo[] array when only getting caller reference,
 603   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 604   // be null.
 605   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 606   objArrayHandle frames_array_h(THREAD, fa);
 607 
 608   if (frames_array_h->length() < buffer_size) {
 609     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers");
 610   }
 611 
 612   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 613   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, last_batch_count, buffer_size,
 614                                   start_index, frames_array_h, THREAD);
 615 JVM_END
 616 
 617 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 618   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 619   objArrayHandle frames_array_h(THREAD, fa);
 620   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 621   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 622 
 623   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 624 JVM_END
 625 
 626 // java.lang.Object ///////////////////////////////////////////////
 627 
 628 
 629 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 630   // as implemented in the classic virtual machine; return 0 if object is null
 631   return handle == nullptr ? 0 :
 632          checked_cast<jint>(ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)));















































 633 JVM_END
 634 
 635 
 636 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 637   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 638   ObjectSynchronizer::wait(obj, ms, CHECK);
 639 JVM_END
 640 
 641 
 642 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 643   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 644   ObjectSynchronizer::notify(obj, CHECK);
 645 JVM_END
 646 
 647 
 648 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 649   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 650   ObjectSynchronizer::notifyall(obj, CHECK);
 651 JVM_END
 652 

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






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

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

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

1240 
1241   return nullptr;
1242 JVM_END
1243 
1244 JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass))
1245   JvmtiVMObjectAllocEventCollector oam;
1246   // ofClass is a reference to a java_lang_Class object. The mirror object
1247   // of an InstanceKlass
1248   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1249   if (java_lang_Class::is_primitive(ofMirror) ||
1250       ! java_lang_Class::as_Klass(ofMirror)->is_instance_klass()) {
1251     oop result = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1252     return (jobjectArray)JNIHandles::make_local(THREAD, result);
1253   }
1254 
1255   InstanceKlass* k = java_lang_Class::as_InstanceKlass(ofMirror);
1256   InnerClassesIterator iter(k);
1257 
1258   if (iter.length() == 0) {
1259     // Neither an inner nor outer class
1260     oop result = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1261     return (jobjectArray)JNIHandles::make_local(THREAD, result);
1262   }
1263 
1264   // find inner class info
1265   constantPoolHandle cp(thread, k->constants());
1266   int length = iter.length();
1267 
1268   // Allocate temp. result array
1269   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), length/4, CHECK_NULL);
1270   objArrayHandle result (THREAD, r);
1271   int members = 0;
1272 
1273   for (; !iter.done(); iter.next()) {
1274     int ioff = iter.inner_class_info_index();
1275     int ooff = iter.outer_class_info_index();
1276 
1277     if (ioff != 0 && ooff != 0) {
1278       // Check to see if the name matches the class we're looking for
1279       // before attempting to find the class.
1280       if (cp->klass_name_at_matches(k, ooff)) {
1281         Klass* outer_klass = cp->klass_at(ooff, CHECK_NULL);
1282         if (outer_klass == k) {
1283            Klass* ik = cp->klass_at(ioff, CHECK_NULL);
1284            InstanceKlass* inner_klass = InstanceKlass::cast(ik);
1285 
1286            // Throws an exception if outer klass has not declared k as
1287            // an inner klass
1288            Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL);
1289 
1290            result->obj_at_put(members, inner_klass->java_mirror());
1291            members++;
1292         }
1293       }
1294     }
1295   }
1296 
1297   if (members != length) {
1298     // Return array of right length
1299     objArrayOop res = oopFactory::new_objArray(vmClasses::Class_klass(), members, CHECK_NULL);
1300     for(int i = 0; i < members; i++) {
1301       res->obj_at_put(i, result->obj_at(i));
1302     }
1303     return (jobjectArray)JNIHandles::make_local(THREAD, res);
1304   }
1305 
1306   return (jobjectArray)JNIHandles::make_local(THREAD, result());
1307 JVM_END
1308 
1309 
1310 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass))
1311 {
1312   // ofClass is a reference to a java_lang_Class object.
1313   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1314   if (java_lang_Class::is_primitive(ofMirror)) {
1315     return nullptr;
1316   }
1317   Klass* klass = java_lang_Class::as_Klass(ofMirror);
1318   if (!klass->is_instance_klass()) {
1319     return nullptr;

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

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

1750 }
1751 JVM_END
1752 
1753 JVM_ENTRY(jobjectArray, JVM_GetNestMembers(JNIEnv* env, jclass current))
1754 {
1755   // current is not a primitive or array class
1756   ResourceMark rm(THREAD);
1757   InstanceKlass* c = java_lang_Class::as_InstanceKlass(JNIHandles::resolve_non_null(current));
1758   InstanceKlass* host = c->nest_host(THREAD);
1759 
1760   log_trace(class, nestmates)("Calling GetNestMembers for type %s with nest-host %s",
1761                               c->external_name(), host->external_name());
1762   {
1763     JvmtiVMObjectAllocEventCollector oam;
1764     Array<u2>* members = host->nest_members();
1765     int length = members == nullptr ? 0 : members->length();
1766 
1767     log_trace(class, nestmates)(" - host has %d listed nest members", length);
1768 
1769     // nest host is first in the array so make it one bigger
1770     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(),
1771                                              length + 1, CHECK_NULL);
1772     objArrayHandle result(THREAD, r);
1773     result->obj_at_put(0, host->java_mirror());
1774     if (length != 0) {
1775       int count = 0;
1776       for (int i = 0; i < length; i++) {
1777         int cp_index = members->at(i);
1778         Klass* k = host->constants()->klass_at(cp_index, THREAD);
1779         if (HAS_PENDING_EXCEPTION) {
1780           if (PENDING_EXCEPTION->is_a(vmClasses::VirtualMachineError_klass())) {
1781             return nullptr; // propagate VMEs
1782           }
1783           if (log_is_enabled(Trace, class, nestmates)) {
1784             stringStream ss;
1785             char* target_member_class = host->constants()->klass_name_at(cp_index)->as_C_string();
1786             ss.print(" - resolution of nest member %s failed: ", target_member_class);
1787             java_lang_Throwable::print(PENDING_EXCEPTION, &ss);
1788             log_trace(class, nestmates)("%s", ss.as_string());
1789           }
1790           CLEAR_PENDING_EXCEPTION;
1791           continue;
1792         }

1827   }
1828 }
1829 JVM_END
1830 
1831 JVM_ENTRY(jobjectArray, JVM_GetPermittedSubclasses(JNIEnv* env, jclass current))
1832 {
1833   oop mirror = JNIHandles::resolve_non_null(current);
1834   assert(!java_lang_Class::is_primitive(mirror), "should not be");
1835   InstanceKlass* ik = java_lang_Class::as_InstanceKlass(mirror);
1836 
1837   ResourceMark rm(THREAD);
1838   log_trace(class, sealed)("Calling GetPermittedSubclasses for %s type %s",
1839                            ik->is_sealed() ? "sealed" : "non-sealed", ik->external_name());
1840   if (ik->is_sealed()) {
1841     JvmtiVMObjectAllocEventCollector oam;
1842     Array<u2>* subclasses = ik->permitted_subclasses();
1843     int length = subclasses->length();
1844 
1845     log_trace(class, sealed)(" - sealed class has %d permitted subclasses", length);
1846 
1847     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(),
1848                                              length, CHECK_NULL);
1849     objArrayHandle result(THREAD, r);
1850     int count = 0;
1851     for (int i = 0; i < length; i++) {
1852       int cp_index = subclasses->at(i);
1853       Klass* k = ik->constants()->klass_at(cp_index, THREAD);
1854       if (HAS_PENDING_EXCEPTION) {
1855         if (PENDING_EXCEPTION->is_a(vmClasses::VirtualMachineError_klass())) {
1856           return nullptr; // propagate VMEs
1857         }
1858         if (log_is_enabled(Trace, class, sealed)) {
1859           stringStream ss;
1860           char* permitted_subclass = ik->constants()->klass_name_at(cp_index)->as_C_string();
1861           ss.print(" - resolution of permitted subclass %s failed: ", permitted_subclass);
1862           java_lang_Throwable::print(PENDING_EXCEPTION, &ss);
1863           log_trace(class, sealed)("%s", ss.as_string());
1864         }
1865 
1866         CLEAR_PENDING_EXCEPTION;
1867         continue;
1868       }
1869       if (k->is_instance_klass()) {

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

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

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


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


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

3512   for (int i = 0; i < num_threads; i++) {
3513     Handle h = tle.get_threadObj(i);
3514     threads_ah->obj_at_put(i, h());
3515   }
3516 
3517   return (jobjectArray) JNIHandles::make_local(THREAD, threads_ah());
3518 JVM_END
3519 
3520 
3521 // Support for java.lang.Thread.getStackTrace() and getAllStackTraces() methods
3522 // Return StackTraceElement[][], each element is the stack trace of a thread in
3523 // the corresponding entry in the given threads array
3524 JVM_ENTRY(jobjectArray, JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads))
3525   JvmtiVMObjectAllocEventCollector oam;
3526 
3527   // Check if threads is null
3528   if (threads == nullptr) {
3529     THROW_NULL(vmSymbols::java_lang_NullPointerException());
3530   }
3531 
3532   objArrayOop a = objArrayOop(JNIHandles::resolve_non_null(threads));
3533   objArrayHandle ah(THREAD, a);
3534   int num_threads = ah->length();
3535   // check if threads is non-empty array
3536   if (num_threads == 0) {
3537     THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3538   }
3539 
3540   // check if threads is not an array of objects of Thread class
3541   Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass();
3542   if (k != vmClasses::Thread_klass()) {
3543     THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3544   }
3545 
3546   ResourceMark rm(THREAD);
3547 
3548   GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
3549   for (int i = 0; i < num_threads; i++) {
3550     oop thread_obj = ah->obj_at(i);
3551     instanceHandle h(THREAD, (instanceOop) thread_obj);
3552     thread_handle_array->append(h);
3553   }

  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/inlineKlass.inline.hpp"
  63 #include "oops/instanceKlass.hpp"
  64 #include "oops/klass.inline.hpp"
  65 #include "oops/method.hpp"
  66 #include "oops/objArrayKlass.hpp"
  67 #include "oops/objArrayOop.inline.hpp"
  68 #include "oops/oop.inline.hpp"
  69 #include "oops/oopCast.inline.hpp"
  70 #include "oops/recordComponent.hpp"
  71 #include "oops/refArrayOop.inline.hpp"
  72 #include "oops/valuePayload.inline.hpp"
  73 #include "prims/foreignGlobals.hpp"
  74 #include "prims/jvm_misc.hpp"
  75 #include "prims/jvmtiExport.hpp"
  76 #include "prims/jvmtiThreadState.inline.hpp"
  77 #include "prims/stackwalk.hpp"
  78 #include "runtime/arguments.hpp"
  79 #include "runtime/atomicAccess.hpp"
  80 #include "runtime/continuation.hpp"
  81 #include "runtime/deoptimization.hpp"
  82 #include "runtime/globals_extension.hpp"
  83 #include "runtime/handles.inline.hpp"
  84 #include "runtime/handshake.hpp"
  85 #include "runtime/init.hpp"
  86 #include "runtime/interfaceSupport.inline.hpp"
  87 #include "runtime/java.hpp"
  88 #include "runtime/javaCalls.hpp"
  89 #include "runtime/javaThread.hpp"
  90 #include "runtime/jfieldIDWorkaround.hpp"
  91 #include "runtime/jniHandles.inline.hpp"
  92 #include "runtime/mountUnmountDisabler.hpp"

 410 
 411   return (jobjectArray) JNIHandles::make_local(THREAD, result_h());
 412 JVM_END
 413 
 414 
 415 /*
 416  * Return the temporary directory that the VM uses for the attach
 417  * and perf data files.
 418  *
 419  * It is important that this directory is well-known and the
 420  * same for all VM instances. It cannot be affected by configuration
 421  * variables such as java.io.tmpdir.
 422  */
 423 JVM_ENTRY(jstring, JVM_GetTemporaryDirectory(JNIEnv *env))
 424   HandleMark hm(THREAD);
 425   const char* temp_dir = os::get_temp_directory();
 426   Handle h = java_lang_String::create_from_platform_dependent_str(temp_dir, CHECK_NULL);
 427   return (jstring) JNIHandles::make_local(THREAD, h());
 428 JVM_END
 429 
 430 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   objArrayOop dest = nullptr;
 434   arrayOop org = (arrayOop)o;
 435   arrayHandle oh(THREAD, org);
 436   ObjArrayKlass* ak = ObjArrayKlass::cast(org->klass());
 437   int len = to - from;  // length of the new array
 438   assert(len >= 0, "Java caller checks that from <= to");
 439   int orig_length = org->length();
 440   if (ak->is_null_free_array_klass()) {
 441     if ((len != 0) && (from >= orig_length || to > orig_length)) {
 442       THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Copying of null-free array with uninitialized elements");
 443     }
 444   }
 445 
 446   if (ak->is_flatArray_klass()) {
 447     FlatArrayKlass* const fak = FlatArrayKlass::cast(org->klass());
 448     dest = fak->allocate_instance(len, CHECK_NULL);
 449   } else {
 450     const ArrayProperties props = ArrayProperties::Default().with_null_restricted(ak->is_null_free_array_klass());
 451     InlineKlass* vk = InlineKlass::cast(ak->element_klass());
 452     dest = oopFactory::new_objArray(vk, len, props,  CHECK_NULL);
 453   }
 454 
 455   objArrayHandle dh(THREAD, dest);
 456 
 457   int copy_len = MIN2(to, orig_length) - MIN2(from, orig_length);
 458   if (copy_len != 0) {
 459     assert(!ak->is_null_free_array_klass() || copy_len == len,
 460            "Failed to throw the IllegalArgumentException");
 461     ak->copy_array(oh(), from, dh(), 0, copy_len, CHECK_NULL);
 462     // Null out values past the length of the copy
 463     for (int i = copy_len; i < len; i++) {
 464       dh()->obj_at_put(i, nullptr);
 465     }
 466   } else {
 467     for (int i = 0; i < len; i++) {
 468       assert(!dh()->is_null_free_array(), "Should have thrown an IAE above");
 469       dh()->obj_at_put(i, nullptr);
 470     }
 471   }
 472 
 473   return (jarray) JNIHandles::make_local(THREAD, dh());
 474 
 475 JVM_END
 476 
 477 #ifdef ASSERT
 478 static void verify_array_arguments(jclass elmClass, jint len) {
 479   assert(len >= 0, "Negative array length");
 480   assert(elmClass != nullptr, "Null element class");
 481   oop mirror = JNIHandles::resolve_non_null(elmClass);
 482   Klass* klass = java_lang_Class::as_Klass(mirror);
 483   assert(klass->is_inline_klass(), "Element class must be an inline class");
 484 }
 485 #endif // ASSERT
 486 
 487 JVM_ENTRY(jarray, JVM_NewNullRestrictedNonAtomicArray(JNIEnv *env, jclass elmClass, jint len, jobject initVal))
 488   DEBUG_ONLY(verify_array_arguments(elmClass, len));
 489   oop mirror = JNIHandles::resolve_non_null(elmClass);
 490   Klass* klass = java_lang_Class::as_Klass(mirror);
 491   oop init = JNIHandles::resolve_non_null(initVal);
 492   Handle init_h(THREAD, init);
 493   assert(klass == init_h()->klass(), "Type mismatch between array and initial value");
 494   const ArrayProperties props = ArrayProperties::Default()
 495     .with_null_restricted()
 496     .with_non_atomic();
 497   objArrayOop array = oopFactory::new_objArray(klass, len, props, CHECK_NULL);
 498   for (int i = 0; i < len; i++) {
 499     array->obj_at_put(i, init_h() /*, CHECK_NULL*/ );
 500   }
 501   return (jarray) JNIHandles::make_local(THREAD, array);
 502 JVM_END
 503 
 504 JVM_ENTRY(jarray, JVM_NewNullRestrictedAtomicArray(JNIEnv *env, jclass elmClass, jint len, jobject initVal))
 505   DEBUG_ONLY(verify_array_arguments(elmClass, len);)
 506   oop mirror = JNIHandles::resolve_non_null(elmClass);
 507   Klass* klass = java_lang_Class::as_Klass(mirror);
 508   oop init = JNIHandles::resolve_non_null(initVal);
 509   Handle init_h(THREAD, init);
 510   assert(klass == init_h()->klass(), "Type mismatch between array and initial value");
 511   const ArrayProperties props = ArrayProperties::Default().with_null_restricted();
 512   objArrayOop array = oopFactory::new_objArray(klass, len, props, CHECK_NULL);
 513   for (int i = 0; i < len; i++) {
 514     array->obj_at_put(i, init_h() /*, CHECK_NULL*/ );
 515   }
 516   return (jarray) JNIHandles::make_local(THREAD, array);
 517 JVM_END
 518 
 519 JVM_ENTRY(jarray, JVM_NewNullableAtomicArray(JNIEnv *env, jclass elmClass, jint len))
 520   DEBUG_ONLY(verify_array_arguments(elmClass, len);)
 521   oop mirror = JNIHandles::resolve_non_null(elmClass);
 522   Klass* klass = java_lang_Class::as_Klass(mirror);
 523   objArrayOop array = oopFactory::new_objArray(klass, len, ArrayProperties::Default(), CHECK_NULL);
 524   return (jarray) JNIHandles::make_local(THREAD, array);
 525 JVM_END
 526 
 527 JVM_ENTRY(jarray, JVM_NewReferenceArray(JNIEnv *env, jclass elmClass, jint len))
 528   DEBUG_ONLY(verify_array_arguments(elmClass, len);)
 529   oop mirror = JNIHandles::resolve_non_null(elmClass);
 530   Klass* klass = java_lang_Class::as_Klass(mirror);
 531   refArrayOop array = oopFactory::new_refArray(klass, len, ArrayProperties::Default(), CHECK_NULL);
 532   return (jarray) JNIHandles::make_local(THREAD, array);
 533 JVM_END
 534 
 535 JVM_ENTRY(jboolean, JVM_IsFlatArray(JNIEnv *env, jarray array))
 536   oop o = JNIHandles::resolve_non_null(array);
 537   Klass* klass = o->klass();
 538 
 539   assert(klass->is_objArray_klass(), "Expects an object array");
 540 
 541   return klass->is_flatArray_klass();
 542 JVM_END
 543 
 544 JVM_ENTRY(jboolean, JVM_IsNullRestrictedArray(JNIEnv *env, jarray array))
 545   oop o = JNIHandles::resolve_non_null(array);
 546   Klass* klass = o->klass();
 547 
 548   assert(klass->is_objArray_klass(), "Expects an object array");
 549 
 550   return klass->is_null_free_array_klass();
 551 JVM_END
 552 
 553 JVM_ENTRY(jboolean, JVM_IsAtomicArray(JNIEnv *env, jarray array))
 554   // There are multiple cases where an array can/must support atomic access:
 555   //   - the array is a reference array
 556   //   - the array uses an atomic flat layout: NULLABLE_ATOMIC_FLAT or NULL_FREE_ATOMIC_FLAT
 557   //   - the array is flat and its component type is naturally atomic
 558   oop o = JNIHandles::resolve_non_null(array);
 559   Klass* klass = o->klass();
 560 
 561   assert(klass->is_objArray_klass(), "Expects an object array");
 562 
 563   if (klass->is_refArray_klass()) {
 564     return true;
 565   }
 566 
 567   if (klass->is_flatArray_klass()) {
 568     FlatArrayKlass* fak = FlatArrayKlass::cast(klass);
 569     if (LayoutKindHelper::is_atomic_flat(fak->layout_kind())) {
 570       return true;
 571     }
 572     bool is_null_free = !LayoutKindHelper::is_nullable_flat(fak->layout_kind());
 573     if (fak->element_klass()->is_naturally_atomic(is_null_free)) {
 574       return true;
 575     }
 576 
 577     return false;
 578   }
 579 
 580   ShouldNotReachHere();
 581 JVM_END
 582 
 583 // java.lang.Runtime /////////////////////////////////////////////////////////////////////////
 584 
 585 extern volatile jint vm_created;
 586 
 587 JVM_ENTRY_NO_ENV(void, JVM_BeforeHalt())
 588   EventShutdown event;
 589   if (event.should_commit()) {
 590     event.set_reason("Shutdown requested from Java");
 591     event.commit();
 592   }
 593 JVM_END
 594 
 595 
 596 JVM_ENTRY_NO_ENV(void, JVM_Halt(jint code))
 597   before_exit(thread, true);
 598   vm_exit(code);
 599 JVM_END
 600 
 601 

 679   }
 680   if (method->is_native()) {
 681     return nullptr;
 682   }
 683 
 684   stringStream ss;
 685   bool ok = BytecodeUtils::get_NPE_message_at(&ss, method, bci);
 686   if (ok) {
 687     oop result = java_lang_String::create_oop_from_str(ss.base(), CHECK_NULL);
 688     return (jstring) JNIHandles::make_local(THREAD, result);
 689   } else {
 690     return nullptr;
 691   }
 692 JVM_END
 693 
 694 // java.lang.StackTraceElement //////////////////////////////////////////////
 695 
 696 
 697 JVM_ENTRY(void, JVM_InitStackTraceElementArray(JNIEnv *env, jobjectArray elements, jobject backtrace, jint depth))
 698   Handle backtraceh(THREAD, JNIHandles::resolve(backtrace));
 699   refArrayOop st = refArrayOop(JNIHandles::resolve(elements));
 700   refArrayHandle stack_trace(THREAD, st);
 701   // Fill in the allocated stack trace
 702   java_lang_Throwable::get_stack_trace_elements(depth, backtraceh, stack_trace, CHECK);
 703 JVM_END
 704 
 705 
 706 JVM_ENTRY(void, JVM_InitStackTraceElement(JNIEnv* env, jobject element, jobject stackFrameInfo))
 707   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(stackFrameInfo));
 708   Handle stack_trace_element(THREAD, JNIHandles::resolve_non_null(element));
 709   java_lang_StackFrameInfo::to_stack_trace_element(stack_frame_info, stack_trace_element, CHECK);
 710 JVM_END
 711 
 712 
 713 // java.lang.StackWalker //////////////////////////////////////////////////////
 714 JVM_ENTRY(void, JVM_ExpandStackFrameInfo(JNIEnv *env, jobject obj))
 715   Handle stack_frame_info(THREAD, JNIHandles::resolve_non_null(obj));
 716 
 717   bool have_name = (java_lang_StackFrameInfo::name(stack_frame_info()) != nullptr);
 718   bool have_type = (java_lang_StackFrameInfo::type(stack_frame_info()) != nullptr);
 719   Method* method = java_lang_StackFrameInfo::get_method(stack_frame_info());
 720   if (!have_name) {

 723   }
 724   if (!have_type) {
 725     Handle type = java_lang_String::create_from_symbol(method->signature(), CHECK);
 726     java_lang_StackFrameInfo::set_type(stack_frame_info(), type());
 727   }
 728 JVM_END
 729 
 730 JVM_ENTRY(jobject, JVM_CallStackWalk(JNIEnv *env, jobject stackStream, jint mode,
 731                                      jint skip_frames, jobject contScope, jobject cont,
 732                                      jint buffer_size, jint start_index, jobjectArray frames))
 733   if (!thread->has_last_Java_frame()) {
 734     THROW_MSG_(vmSymbols::java_lang_InternalError(), "doStackWalk: no stack trace", nullptr);
 735   }
 736 
 737   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 738   Handle contScope_h(THREAD, JNIHandles::resolve(contScope));
 739   Handle cont_h(THREAD, JNIHandles::resolve(cont));
 740   // frames array is a ClassFrameInfo[] array when only getting caller reference,
 741   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 742   // be null.
 743   refArrayOop fa = refArrayOop(JNIHandles::resolve_non_null(frames));
 744   refArrayHandle frames_array_h(THREAD, fa);
 745 
 746   if (frames_array_h->length() < buffer_size) {
 747     THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers", nullptr);
 748   }
 749 
 750   oop result = StackWalk::walk(stackStream_h, mode, skip_frames, contScope_h, cont_h,
 751                                buffer_size, start_index, frames_array_h, CHECK_NULL);
 752   return JNIHandles::make_local(THREAD, result);
 753 JVM_END
 754 
 755 
 756 JVM_ENTRY(jint, JVM_MoreStackWalk(JNIEnv *env, jobject stackStream, jint mode, jlong anchor,
 757                                   jint last_batch_count, jint buffer_size, jint start_index,
 758                                   jobjectArray frames))
 759   // frames array is a ClassFrameInfo[] array when only getting caller reference,
 760   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 761   // be null.
 762   refArrayOop fa = refArrayOop(JNIHandles::resolve_non_null(frames));
 763   refArrayHandle frames_array_h(THREAD, fa);
 764 
 765   if (frames_array_h->length() < buffer_size) {
 766     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers");
 767   }
 768 
 769   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 770   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, last_batch_count, buffer_size,
 771                                   start_index, frames_array_h, THREAD);
 772 JVM_END
 773 
 774 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 775   refArrayOop fa = refArrayOop(JNIHandles::resolve_non_null(frames));
 776   refArrayHandle frames_array_h(THREAD, fa);
 777   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 778   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 779 
 780   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 781 JVM_END
 782 
 783 // java.lang.Object ///////////////////////////////////////////////
 784 
 785 
 786 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 787   // as implemented in the classic virtual machine; return 0 if object is null
 788   if (handle == nullptr) {
 789     return 0;
 790   }
 791   oop obj = JNIHandles::resolve_non_null(handle);
 792   if (Arguments::is_valhalla_enabled() && obj->klass()->is_inline_klass()) {
 793     const intptr_t obj_identity_hash = obj->mark().hash();
 794     // Check if mark word contains hash code already.
 795     // It is possible that the generated identity hash is 0, which is not
 796     // distinct from the no_hash value. In such a case, the hash will be
 797     // computed and set every time JVM_IHashCode is called. If that happens,
 798     // the only consequence is losing out on the optimization.
 799     if (obj_identity_hash != markWord::no_hash) {
 800       return checked_cast<jint>(obj_identity_hash);
 801     }
 802 
 803     // Compute hash by calling ValueObjectMethods.valueObjectHashCode.
 804     // The identity hash is invariantly immutable (see its JavaDoc comment).
 805     JavaValue result(T_INT);
 806     JavaCallArguments args;
 807     Handle ho(THREAD, obj);
 808     args.push_oop(ho);
 809     methodHandle method(THREAD, Universe::value_object_hash_code_method());
 810     JavaCalls::call(&result, method, &args, THREAD);
 811     Exceptions::wrap_exception_in_internal_error("Internal error in hashCode", CHECK_0);
 812 
 813     const intptr_t identity_hash = result.get_jint();
 814 
 815     // We now have to set the hash via CAS. It's possible that this will race
 816     // other threads. By our invariant of immutability, when there is a
 817     // race, the identity hash code is going to be one of the following:
 818     // a) 0, another thread updated other markWord bits; b) identity_hash set
 819     // by another thread; or c) identity_hash set by the current thread.
 820     // A nonzero identity hash code that is not the identity_hash computed
 821     // earlier indicates a violation of the invariant.
 822     markWord current_mark, old_mark, new_mark;
 823     do {
 824       current_mark = ho->mark();
 825       new_mark = current_mark.copy_set_hash(identity_hash);
 826       old_mark = ho->cas_set_mark(new_mark, current_mark);
 827       assert(old_mark.has_no_hash() || old_mark.hash() == new_mark.hash(),
 828             "CAS identity hash invariant violated, expected=" INTPTR_FORMAT " actual=" INTPTR_FORMAT,
 829             new_mark.hash(),
 830             old_mark.hash());
 831     } while (old_mark != current_mark);
 832 
 833     return checked_cast<jint>(new_mark.hash());
 834   } else {
 835     return checked_cast<jint>(ObjectSynchronizer::FastHashCode(THREAD, obj));
 836   }
 837 JVM_END
 838 
 839 
 840 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 841   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 842   ObjectSynchronizer::wait(obj, ms, CHECK);
 843 JVM_END
 844 
 845 
 846 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))
 847   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 848   ObjectSynchronizer::notify(obj, CHECK);
 849 JVM_END
 850 
 851 
 852 JVM_ENTRY(void, JVM_MonitorNotifyAll(JNIEnv* env, jobject handle))
 853   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 854   ObjectSynchronizer::notifyall(obj, CHECK);
 855 JVM_END
 856 

 864   // Just checking that the cloneable flag is set correct
 865   if (obj->is_array()) {
 866     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 867   } else {
 868     guarantee(obj->is_instance(), "should be instanceOop");
 869     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 870     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 871   }
 872 #endif
 873 
 874   // Check if class of obj supports the Cloneable interface.
 875   // All arrays are considered to be cloneable (See JLS 20.1.5).
 876   // All j.l.r.Reference classes are considered non-cloneable.
 877   if (!klass->is_cloneable() ||
 878       (klass->is_instance_klass() &&
 879        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 880     ResourceMark rm(THREAD);
 881     THROW_MSG_NULL(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 882   }
 883 
 884   if (klass->is_inline_klass()) {
 885     // Value instances have no identity, so return the current instance instead of allocating a new one
 886     // Value classes cannot have finalizers, so the method can return immediately
 887     return JNIHandles::make_local(THREAD, obj());
 888   }
 889 
 890   // Make shallow object copy
 891   const size_t size = obj->size();
 892   oop new_obj_oop = nullptr;
 893   if (obj->is_array()) {
 894     const int length = ((arrayOop)obj())->length();
 895     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 896                                                    /* do_zero */ true, CHECK_NULL);
 897   } else {
 898     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 899   }
 900 
 901   HeapAccess<>::clone(obj(), new_obj_oop, size);
 902 
 903   Handle new_obj(THREAD, new_obj_oop);
 904   // Caution: this involves a java upcall, so the clone should be
 905   // "gc-robust" by this stage.
 906   if (klass->has_finalizer()) {
 907     assert(obj->is_instance(), "should be instanceOop");
 908     new_obj_oop = InstanceKlass::register_finalizer(instanceOop(new_obj()), CHECK_NULL);
 909     new_obj = Handle(THREAD, new_obj_oop);

1362   oop result = java_lang_Class::name(java_class, CHECK_NULL);
1363   return (jstring) JNIHandles::make_local(THREAD, result);
1364 JVM_END
1365 
1366 
1367 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1368   JvmtiVMObjectAllocEventCollector oam;
1369   oop mirror = JNIHandles::resolve_non_null(cls);
1370 
1371   // Special handling for primitive objects
1372   if (java_lang_Class::is_primitive(mirror)) {
1373     // Primitive objects does not have any interfaces
1374     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1375     return (jobjectArray) JNIHandles::make_local(THREAD, r);
1376   }
1377 
1378   Klass* klass = java_lang_Class::as_Klass(mirror);
1379   // Figure size of result array
1380   int size;
1381   if (klass->is_instance_klass()) {
1382     InstanceKlass* ik = InstanceKlass::cast(klass);
1383     size = ik->local_interfaces()->length();
1384   } else {
1385     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1386     size = 2;
1387   }
1388 
1389   // Allocate result array
1390   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1391   objArrayHandle result (THREAD, r);
1392   // Fill in result
1393   if (klass->is_instance_klass()) {
1394     // Regular instance klass, fill in all local interfaces
1395     for (int index = 0; index < size; index++) {
1396       InstanceKlass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);
1397       result->obj_at_put(index, k->java_mirror());
1398     }
1399   } else {
1400     // All arrays implement java.lang.Cloneable and java.io.Serializable
1401     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1402     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1403   }

1451 
1452   return nullptr;
1453 JVM_END
1454 
1455 JVM_ENTRY(jobjectArray, JVM_GetDeclaredClasses(JNIEnv *env, jclass ofClass))
1456   JvmtiVMObjectAllocEventCollector oam;
1457   // ofClass is a reference to a java_lang_Class object. The mirror object
1458   // of an InstanceKlass
1459   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1460   if (java_lang_Class::is_primitive(ofMirror) ||
1461       ! java_lang_Class::as_Klass(ofMirror)->is_instance_klass()) {
1462     oop result = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1463     return (jobjectArray)JNIHandles::make_local(THREAD, result);
1464   }
1465 
1466   InstanceKlass* k = java_lang_Class::as_InstanceKlass(ofMirror);
1467   InnerClassesIterator iter(k);
1468 
1469   if (iter.length() == 0) {
1470     // Neither an inner nor outer class
1471     oop result = oopFactory::new_refArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1472     return (jobjectArray)JNIHandles::make_local(THREAD, result);
1473   }
1474 
1475   // find inner class info
1476   constantPoolHandle cp(thread, k->constants());
1477   int length = iter.length();
1478 
1479   // Allocate temp. result array
1480   refArrayOop r = oopFactory::new_refArray(vmClasses::Class_klass(), length / 4, CHECK_NULL);
1481   refArrayHandle result(THREAD, r);
1482   int members = 0;
1483 
1484   for (; !iter.done(); iter.next()) {
1485     int ioff = iter.inner_class_info_index();
1486     int ooff = iter.outer_class_info_index();
1487 
1488     if (ioff != 0 && ooff != 0) {
1489       // Check to see if the name matches the class we're looking for
1490       // before attempting to find the class.
1491       if (cp->klass_name_at_matches(k, ooff)) {
1492         Klass* outer_klass = cp->klass_at(ooff, CHECK_NULL);
1493         if (outer_klass == k) {
1494            Klass* ik = cp->klass_at(ioff, CHECK_NULL);
1495            InstanceKlass* inner_klass = InstanceKlass::cast(ik);
1496 
1497            // Throws an exception if outer klass has not declared k as
1498            // an inner klass
1499            Reflection::check_for_inner_class(k, inner_klass, true, CHECK_NULL);
1500 
1501            result->obj_at_put(members, inner_klass->java_mirror());
1502            members++;
1503         }
1504       }
1505     }
1506   }
1507 
1508   if (members != length) {
1509     // Return array of right length
1510     refArrayOop res = oopFactory::new_refArray(vmClasses::Class_klass(), members, CHECK_NULL);
1511     for(int i = 0; i < members; i++) {
1512       res->obj_at_put(i, result->obj_at(i));
1513     }
1514     return (jobjectArray)JNIHandles::make_local(THREAD, res);
1515   }
1516 
1517   return (jobjectArray)JNIHandles::make_local(THREAD, result());
1518 JVM_END
1519 
1520 
1521 JVM_ENTRY(jclass, JVM_GetDeclaringClass(JNIEnv *env, jclass ofClass))
1522 {
1523   // ofClass is a reference to a java_lang_Class object.
1524   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1525   if (java_lang_Class::is_primitive(ofMirror)) {
1526     return nullptr;
1527   }
1528   Klass* klass = java_lang_Class::as_Klass(ofMirror);
1529   if (!klass->is_instance_klass()) {
1530     return nullptr;

1867   }
1868 
1869   InstanceKlass* k = java_lang_Class::as_InstanceKlass(ofMirror);
1870 
1871   // Ensure class is linked
1872   k->link_class(CHECK_NULL);
1873 
1874   Array<Method*>* methods = k->methods();
1875   int methods_length = methods->length();
1876 
1877   // Save original method_idnum in case of redefinition, which can change
1878   // the idnum of obsolete methods.  The new method will have the same idnum
1879   // but if we refresh the methods array, the counts will be wrong.
1880   ResourceMark rm(THREAD);
1881   GrowableArray<int>* idnums = new GrowableArray<int>(methods_length);
1882   int num_methods = 0;
1883 
1884   // Select methods matching the criteria.
1885   for (int i = 0; i < methods_length; i++) {
1886     Method* method = methods->at(i);
1887     if (want_constructor && !method->is_object_constructor()) {
1888       continue;
1889     }
1890     if (!want_constructor &&
1891         (method->is_object_constructor() || method->is_class_initializer() ||
1892          method->is_overpass())) {
1893       continue;
1894     }
1895     if (publicOnly && !method->is_public()) {
1896       continue;
1897     }
1898     idnums->push(method->method_idnum());
1899     ++num_methods;
1900   }
1901 
1902   // Allocate result
1903   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1904   objArrayHandle result (THREAD, r);
1905 
1906   // Now just put the methods that we selected above, but go by their idnum
1907   // in case of redefinition.  The methods can be redefined at any safepoint,
1908   // so above when allocating the oop array and below when creating reflect
1909   // objects.
1910   for (int i = 0; i < num_methods; i++) {
1911     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1912     if (method.is_null()) {
1913       // Method may have been deleted and seems this API can handle null
1914       // Otherwise should probably put a method that throws NSME
1915       result->obj_at_put(i, nullptr);
1916     } else {
1917       oop m;
1918       if (want_constructor) {
1919         assert(method->is_object_constructor(), "must be");
1920         m = Reflection::new_constructor(method, CHECK_NULL);
1921       } else {
1922         m = Reflection::new_method(method, false, CHECK_NULL);
1923       }
1924       result->obj_at_put(i, m);
1925     }
1926   }
1927 
1928   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1929 }
1930 
1931 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1932 {
1933   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1934                                            /*want_constructor*/ false,
1935                                            vmClasses::reflect_Method_klass(), THREAD);
1936 }
1937 JVM_END
1938 
1939 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

1962 }
1963 JVM_END
1964 
1965 JVM_ENTRY(jobjectArray, JVM_GetNestMembers(JNIEnv* env, jclass current))
1966 {
1967   // current is not a primitive or array class
1968   ResourceMark rm(THREAD);
1969   InstanceKlass* c = java_lang_Class::as_InstanceKlass(JNIHandles::resolve_non_null(current));
1970   InstanceKlass* host = c->nest_host(THREAD);
1971 
1972   log_trace(class, nestmates)("Calling GetNestMembers for type %s with nest-host %s",
1973                               c->external_name(), host->external_name());
1974   {
1975     JvmtiVMObjectAllocEventCollector oam;
1976     Array<u2>* members = host->nest_members();
1977     int length = members == nullptr ? 0 : members->length();
1978 
1979     log_trace(class, nestmates)(" - host has %d listed nest members", length);
1980 
1981     // nest host is first in the array so make it one bigger
1982     refArrayOop r = oopFactory::new_refArray(vmClasses::Class_klass(), length + 1, CHECK_NULL);
1983     refArrayHandle result(THREAD, r);

1984     result->obj_at_put(0, host->java_mirror());
1985     if (length != 0) {
1986       int count = 0;
1987       for (int i = 0; i < length; i++) {
1988         int cp_index = members->at(i);
1989         Klass* k = host->constants()->klass_at(cp_index, THREAD);
1990         if (HAS_PENDING_EXCEPTION) {
1991           if (PENDING_EXCEPTION->is_a(vmClasses::VirtualMachineError_klass())) {
1992             return nullptr; // propagate VMEs
1993           }
1994           if (log_is_enabled(Trace, class, nestmates)) {
1995             stringStream ss;
1996             char* target_member_class = host->constants()->klass_name_at(cp_index)->as_C_string();
1997             ss.print(" - resolution of nest member %s failed: ", target_member_class);
1998             java_lang_Throwable::print(PENDING_EXCEPTION, &ss);
1999             log_trace(class, nestmates)("%s", ss.as_string());
2000           }
2001           CLEAR_PENDING_EXCEPTION;
2002           continue;
2003         }

2038   }
2039 }
2040 JVM_END
2041 
2042 JVM_ENTRY(jobjectArray, JVM_GetPermittedSubclasses(JNIEnv* env, jclass current))
2043 {
2044   oop mirror = JNIHandles::resolve_non_null(current);
2045   assert(!java_lang_Class::is_primitive(mirror), "should not be");
2046   InstanceKlass* ik = java_lang_Class::as_InstanceKlass(mirror);
2047 
2048   ResourceMark rm(THREAD);
2049   log_trace(class, sealed)("Calling GetPermittedSubclasses for %s type %s",
2050                            ik->is_sealed() ? "sealed" : "non-sealed", ik->external_name());
2051   if (ik->is_sealed()) {
2052     JvmtiVMObjectAllocEventCollector oam;
2053     Array<u2>* subclasses = ik->permitted_subclasses();
2054     int length = subclasses->length();
2055 
2056     log_trace(class, sealed)(" - sealed class has %d permitted subclasses", length);
2057 
2058     refArrayOop r = oopFactory::new_refArray(vmClasses::Class_klass(), length, CHECK_NULL);
2059     refArrayHandle result(THREAD, r);

2060     int count = 0;
2061     for (int i = 0; i < length; i++) {
2062       int cp_index = subclasses->at(i);
2063       Klass* k = ik->constants()->klass_at(cp_index, THREAD);
2064       if (HAS_PENDING_EXCEPTION) {
2065         if (PENDING_EXCEPTION->is_a(vmClasses::VirtualMachineError_klass())) {
2066           return nullptr; // propagate VMEs
2067         }
2068         if (log_is_enabled(Trace, class, sealed)) {
2069           stringStream ss;
2070           char* permitted_subclass = ik->constants()->klass_name_at(cp_index)->as_C_string();
2071           ss.print(" - resolution of permitted subclass %s failed: ", permitted_subclass);
2072           java_lang_Throwable::print(PENDING_EXCEPTION, &ss);
2073           log_trace(class, sealed)("%s", ss.as_string());
2074         }
2075 
2076         CLEAR_PENDING_EXCEPTION;
2077         continue;
2078       }
2079       if (k->is_instance_klass()) {

2158   constantTag tag = cp->tag_at(index);
2159   if (!tag.is_method() && !tag.is_interface_method()) {
2160     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2161   }
2162   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2163   Klass* k_o;
2164   if (force_resolution) {
2165     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2166   } else {
2167     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2168     if (k_o == nullptr) return nullptr;
2169   }
2170   InstanceKlass* k = InstanceKlass::cast(k_o);
2171   Symbol* name = cp->uncached_name_ref_at(index);
2172   Symbol* sig  = cp->uncached_signature_ref_at(index);
2173   methodHandle m (THREAD, k->find_method(name, sig));
2174   if (m.is_null()) {
2175     THROW_MSG_NULL(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2176   }
2177   oop method;
2178   if (m->is_object_constructor()) {
2179     method = Reflection::new_constructor(m, CHECK_NULL);
2180   } else {

2181     method = Reflection::new_method(m, true, CHECK_NULL);
2182   }
2183   return JNIHandles::make_local(THREAD, method);
2184 }
2185 
2186 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jint index))
2187 {
2188   JvmtiVMObjectAllocEventCollector oam;
2189   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2190   bounds_check(cp, index, CHECK_NULL);
2191   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2192   return res;
2193 }
2194 JVM_END
2195 
2196 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jint index))
2197 {
2198   JvmtiVMObjectAllocEventCollector oam;
2199   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2200   bounds_check(cp, index, CHECK_NULL);

2607 
2608 
2609 JVM_ENTRY(jint, JVM_GetMethodIxArgsSize(JNIEnv *env, jclass cls, int method_index))
2610   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2611   Method* method = ik->methods()->at(method_index);
2612   return method->size_of_parameters();
2613 JVM_END
2614 
2615 
2616 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2617   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2618   Method* method = ik->methods()->at(method_index);
2619   return method->verifier_max_stack();
2620 JVM_END
2621 
2622 
2623 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2624   ResourceMark rm(THREAD);
2625   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2626   Method* method = ik->methods()->at(method_index);
2627   return method->is_object_constructor();
2628 JVM_END
2629 
2630 
2631 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2632   ResourceMark rm(THREAD);
2633   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2634   Method* method = ik->methods()->at(method_index);
2635   return method->is_overpass();
2636 JVM_END
2637 
2638 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2639   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2640   Method* method = ik->methods()->at(method_index);
2641   return method->name()->as_utf8();
2642 JVM_END
2643 
2644 
2645 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))
2646   InstanceKlass* ik = get_instance_klass_considering_redefinition(cls, thread);
2647   Method* method = ik->methods()->at(method_index);

3476 
3477 jclass find_class_from_class_loader(JNIEnv* env, Symbol* name, jboolean init,
3478                                     Handle loader, jboolean throwError, TRAPS) {
3479   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, throwError != 0, CHECK_NULL);
3480 
3481   // Check if we should initialize the class
3482   if (init && klass->is_instance_klass()) {
3483     klass->initialize(CHECK_NULL);
3484   }
3485   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3486 }
3487 
3488 
3489 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3490 
3491 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3492   Handle method_handle;
3493   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3494     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3495     Handle receiver(THREAD, JNIHandles::resolve(obj));
3496     objArrayHandle args(THREAD, (objArrayOop)JNIHandles::resolve(args0));
3497     assert(args() == nullptr || !args->is_flatArray(), "args are never flat");
3498 
3499     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3500     jobject res = JNIHandles::make_local(THREAD, result);
3501     if (JvmtiExport::should_post_vm_object_alloc()) {
3502       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3503       assert(ret_type != nullptr, "sanity check: ret_type oop must not be null!");
3504       if (java_lang_Class::is_primitive(ret_type)) {
3505         // Only for primitive type vm allocates memory for java object.
3506         // See box() method.
3507         JvmtiExport::post_vm_object_alloc(thread, result);
3508       }
3509     }
3510     return res;
3511   } else {
3512     THROW_NULL(vmSymbols::java_lang_StackOverflowError());
3513   }
3514 JVM_END
3515 
3516 
3517 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3518   objArrayHandle args(THREAD, (objArrayOop)JNIHandles::resolve(args0));
3519   assert(args() == nullptr || !args->is_flatArray(), "args are never flat");
3520   oop constructor_mirror = JNIHandles::resolve(c);

3521   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3522   jobject res = JNIHandles::make_local(THREAD, result);
3523   if (JvmtiExport::should_post_vm_object_alloc()) {
3524     JvmtiExport::post_vm_object_alloc(thread, result);
3525   }
3526   return res;
3527 JVM_END
3528 
3529 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3530   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3531   HeapShared::initialize_from_archived_subgraph(THREAD, k);
3532 JVM_END
3533 
3534 JVM_ENTRY(void, JVM_RegisterLambdaProxyClassForArchiving(JNIEnv* env,
3535                                               jclass caller,
3536                                               jstring interfaceMethodName,
3537                                               jobject factoryType,
3538                                               jobject interfaceMethodType,
3539                                               jobject implementationMember,
3540                                               jobject dynamicMethodType,

3724   for (int i = 0; i < num_threads; i++) {
3725     Handle h = tle.get_threadObj(i);
3726     threads_ah->obj_at_put(i, h());
3727   }
3728 
3729   return (jobjectArray) JNIHandles::make_local(THREAD, threads_ah());
3730 JVM_END
3731 
3732 
3733 // Support for java.lang.Thread.getStackTrace() and getAllStackTraces() methods
3734 // Return StackTraceElement[][], each element is the stack trace of a thread in
3735 // the corresponding entry in the given threads array
3736 JVM_ENTRY(jobjectArray, JVM_DumpThreads(JNIEnv *env, jclass threadClass, jobjectArray threads))
3737   JvmtiVMObjectAllocEventCollector oam;
3738 
3739   // Check if threads is null
3740   if (threads == nullptr) {
3741     THROW_NULL(vmSymbols::java_lang_NullPointerException());
3742   }
3743 
3744   refArrayOop a = oop_cast<refArrayOop>(JNIHandles::resolve_non_null(threads));
3745   refArrayHandle ah(THREAD, a);
3746   int num_threads = ah->length();
3747   // check if threads is non-empty array
3748   if (num_threads == 0) {
3749     THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3750   }
3751 
3752   // check if threads is not an array of objects of Thread class
3753   Klass* k = ObjArrayKlass::cast(ah->klass())->element_klass();
3754   if (k != vmClasses::Thread_klass()) {
3755     THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
3756   }
3757 
3758   ResourceMark rm(THREAD);
3759 
3760   GrowableArray<instanceHandle>* thread_handle_array = new GrowableArray<instanceHandle>(num_threads);
3761   for (int i = 0; i < num_threads; i++) {
3762     oop thread_obj = ah->obj_at(i);
3763     instanceHandle h(THREAD, (instanceOop) thread_obj);
3764     thread_handle_array->append(h);
3765   }
< prev index next >