< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page

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

  59 #include "oops/instanceKlass.hpp"
  60 #include "oops/klass.inline.hpp"
  61 #include "oops/method.hpp"
  62 #include "oops/recordComponent.hpp"
  63 #include "oops/objArrayKlass.hpp"
  64 #include "oops/objArrayOop.inline.hpp"
  65 #include "oops/oop.inline.hpp"
  66 #include "prims/jvm_misc.hpp"
  67 #include "prims/jvmtiExport.hpp"
  68 #include "prims/jvmtiThreadState.hpp"
  69 #include "prims/stackwalk.hpp"
  70 #include "runtime/arguments.hpp"
  71 #include "runtime/atomic.hpp"
  72 #include "runtime/globals_extension.hpp"
  73 #include "runtime/handles.inline.hpp"
  74 #include "runtime/init.hpp"
  75 #include "runtime/interfaceSupport.inline.hpp"
  76 #include "runtime/deoptimization.hpp"
  77 #include "runtime/handshake.hpp"
  78 #include "runtime/java.hpp"

 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   int limit = start_index+frame_count;
 590   if (frames_array_h->length() < limit) {
 591     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers");
 592   }
 593 
 594   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 595   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count,
 596                                    start_index, frames_array_h, THREAD);
 597 JVM_END
 598 
 599 // java.lang.Object ///////////////////////////////////////////////
 600 
 601 
 602 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 603   // as implemented in the classic virtual machine; return 0 if object is NULL
 604   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;





















 605 JVM_END
 606 
 607 
 608 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 609   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 610   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 611   if (JvmtiExport::should_post_monitor_wait()) {
 612     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 613 
 614     // The current thread already owns the monitor and it has not yet
 615     // been added to the wait queue so the current thread cannot be
 616     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 617     // event handler cannot accidentally consume an unpark() meant for
 618     // the ParkEvent associated with this ObjectMonitor.
 619   }
 620   ObjectSynchronizer::wait(obj, ms, CHECK);
 621 JVM_END
 622 
 623 
 624 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))

 636 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 637   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 638   Klass* klass = obj->klass();
 639   JvmtiVMObjectAllocEventCollector oam;
 640 
 641 #ifdef ASSERT
 642   // Just checking that the cloneable flag is set correct
 643   if (obj->is_array()) {
 644     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 645   } else {
 646     guarantee(obj->is_instance(), "should be instanceOop");
 647     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 648     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 649   }
 650 #endif
 651 
 652   // Check if class of obj supports the Cloneable interface.
 653   // All arrays are considered to be cloneable (See JLS 20.1.5).
 654   // All j.l.r.Reference classes are considered non-cloneable.
 655   if (!klass->is_cloneable() ||

 656       (klass->is_instance_klass() &&
 657        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 658     ResourceMark rm(THREAD);
 659     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 660   }
 661 
 662   // Make shallow object copy
 663   const size_t size = obj->size();
 664   oop new_obj_oop = NULL;
 665   if (obj->is_array()) {
 666     const int length = ((arrayOop)obj())->length();
 667     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 668                                                    /* do_zero */ true, CHECK_NULL);
 669   } else {
 670     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 671   }
 672 
 673   HeapAccess<>::clone(obj(), new_obj_oop, size);
 674 
 675   Handle new_obj(THREAD, new_obj_oop);

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

1164   } else {
1165     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1166     size = 2;
1167   }
1168 
1169   // Allocate result array
1170   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1171   objArrayHandle result (THREAD, r);
1172   // Fill in result
1173   if (klass->is_instance_klass()) {
1174     // Regular instance klass, fill in all local interfaces
1175     for (int index = 0; index < size; index++) {
1176       Klass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);

1177       result->obj_at_put(index, k->java_mirror());
1178     }
1179   } else {
1180     // All arrays implement java.lang.Cloneable and java.io.Serializable
1181     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1182     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1183   }
1184   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1185 JVM_END
1186 
1187 
1188 JVM_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
1189   oop mirror = JNIHandles::resolve_non_null(cls);
1190   if (java_lang_Class::is_primitive(mirror)) {
1191     return JNI_FALSE;
1192   }
1193   Klass* k = java_lang_Class::as_Klass(mirror);
1194   jboolean result = k->is_interface();
1195   assert(!result || k->is_instance_klass(),
1196          "all interfaces are instance types");

1758     int length = components->length();
1759     assert(length >= 0, "unexpected record_components length");
1760     objArrayOop record_components =
1761       oopFactory::new_objArray(vmClasses::RecordComponent_klass(), length, CHECK_NULL);
1762     objArrayHandle components_h (THREAD, record_components);
1763 
1764     for (int x = 0; x < length; x++) {
1765       RecordComponent* component = components->at(x);
1766       assert(component != NULL, "unexpected NULL record component");
1767       oop component_oop = java_lang_reflect_RecordComponent::create(ik, component, CHECK_NULL);
1768       components_h->obj_at_put(x, component_oop);
1769     }
1770     return (jobjectArray)JNIHandles::make_local(THREAD, components_h());
1771   }
1772 
1773   return NULL;
1774 }
1775 JVM_END
1776 
1777 static bool select_method(const methodHandle& method, bool want_constructor) {


1778   if (want_constructor) {
1779     return (method->is_initializer() && !method->is_static());
1780   } else {
1781     return  (!method->is_initializer() && !method->is_overpass());


1782   }
1783 }
1784 
1785 static jobjectArray get_class_declared_methods_helper(
1786                                   JNIEnv *env,
1787                                   jclass ofClass, jboolean publicOnly,
1788                                   bool want_constructor,
1789                                   Klass* klass, TRAPS) {
1790 
1791   JvmtiVMObjectAllocEventCollector oam;
1792 
1793   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1794   // Exclude primitive types and array types
1795   if (java_lang_Class::is_primitive(ofMirror)
1796       || java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1797     // Return empty array
1798     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1799     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1800   }
1801 

1824     }
1825   }
1826 
1827   // Allocate result
1828   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1829   objArrayHandle result (THREAD, r);
1830 
1831   // Now just put the methods that we selected above, but go by their idnum
1832   // in case of redefinition.  The methods can be redefined at any safepoint,
1833   // so above when allocating the oop array and below when creating reflect
1834   // objects.
1835   for (int i = 0; i < num_methods; i++) {
1836     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1837     if (method.is_null()) {
1838       // Method may have been deleted and seems this API can handle null
1839       // Otherwise should probably put a method that throws NSME
1840       result->obj_at_put(i, NULL);
1841     } else {
1842       oop m;
1843       if (want_constructor) {


1844         m = Reflection::new_constructor(method, CHECK_NULL);
1845       } else {
1846         m = Reflection::new_method(method, false, CHECK_NULL);
1847       }
1848       result->obj_at_put(i, m);
1849     }
1850   }
1851 
1852   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1853 }
1854 
1855 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1856 {
1857   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1858                                            /*want_constructor*/ false,
1859                                            vmClasses::reflect_Method_klass(), THREAD);
1860 }
1861 JVM_END
1862 
1863 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

2106   constantTag tag = cp->tag_at(index);
2107   if (!tag.is_method() && !tag.is_interface_method()) {
2108     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2109   }
2110   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2111   Klass* k_o;
2112   if (force_resolution) {
2113     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2114   } else {
2115     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2116     if (k_o == NULL) return NULL;
2117   }
2118   InstanceKlass* k = InstanceKlass::cast(k_o);
2119   Symbol* name = cp->uncached_name_ref_at(index);
2120   Symbol* sig  = cp->uncached_signature_ref_at(index);
2121   methodHandle m (THREAD, k->find_method(name, sig));
2122   if (m.is_null()) {
2123     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2124   }
2125   oop method;
2126   if (!m->is_initializer() || m->is_static()) {
2127     method = Reflection::new_method(m, true, CHECK_NULL);
2128   } else {
2129     method = Reflection::new_constructor(m, CHECK_NULL);


2130   }
2131   return JNIHandles::make_local(THREAD, method);
2132 }
2133 
2134 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2135 {
2136   JvmtiVMObjectAllocEventCollector oam;
2137   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2138   bounds_check(cp, index, CHECK_NULL);
2139   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2140   return res;
2141 }
2142 JVM_END
2143 
2144 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2145 {
2146   JvmtiVMObjectAllocEventCollector oam;
2147   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2148   bounds_check(cp, index, CHECK_NULL);
2149   jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);

2380   Klass* k = java_lang_Class::as_Klass(r);
2381   assert(k->is_instance_klass(), "must be an instance klass");
2382   if (!k->is_instance_klass()) return false;
2383 
2384   ResourceMark rm(THREAD);
2385   const char* name = k->name()->as_C_string();
2386   bool system_class = k->class_loader() == NULL;
2387   return JavaAssertions::enabled(name, system_class);
2388 
2389 JVM_END
2390 
2391 
2392 // Return a new AssertionStatusDirectives object with the fields filled in with
2393 // command-line assertion arguments (i.e., -ea, -da).
2394 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2395   JvmtiVMObjectAllocEventCollector oam;
2396   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2397   return JNIHandles::make_local(THREAD, asd);
2398 JVM_END
2399 





































2400 // Verification ////////////////////////////////////////////////////////////////////////////////
2401 
2402 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2403 
2404 // RedefineClasses support: bug 6214132 caused verification to fail.
2405 // All functions from this section should call the jvmtiThreadSate function:
2406 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2407 // The function returns a Klass* of the _scratch_class if the verifier
2408 // was invoked in the middle of the class redefinition.
2409 // Otherwise it returns its argument value which is the _the_class Klass*.
2410 // Please, refer to the description in the jvmtiThreadSate.hpp.
2411 
2412 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2413   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2414   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2415   return k->name()->as_utf8();
2416 JVM_END
2417 
2418 
2419 JVM_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))

2542   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2543   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2544   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2545   return method->size_of_parameters();
2546 JVM_END
2547 
2548 
2549 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2550   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2551   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2552   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2553   return method->verifier_max_stack();
2554 JVM_END
2555 
2556 
2557 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2558   ResourceMark rm(THREAD);
2559   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2560   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2561   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2562   return method->name() == vmSymbols::object_initializer_name();
2563 JVM_END
2564 
2565 
2566 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2567   ResourceMark rm(THREAD);
2568   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2569   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2570   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2571   return method->is_overpass();
2572 JVM_END
2573 
2574 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2575   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2576   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2577   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2578   return method->name()->as_utf8();
2579 JVM_END
2580 
2581 
2582 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))

3508   //   the checkPackageAccess relative to the initiating class loader via the
3509   //   protection_domain. The protection_domain is passed as NULL by the java code
3510   //   if there is no security manager in 3-arg Class.forName().
3511   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3512 
3513   // Check if we should initialize the class
3514   if (init && klass->is_instance_klass()) {
3515     klass->initialize(CHECK_NULL);
3516   }
3517   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3518 }
3519 
3520 
3521 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3522 
3523 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3524   Handle method_handle;
3525   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3526     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3527     Handle receiver(THREAD, JNIHandles::resolve(obj));
3528     objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3529     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3530     jobject res = JNIHandles::make_local(THREAD, result);
3531     if (JvmtiExport::should_post_vm_object_alloc()) {
3532       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3533       assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
3534       if (java_lang_Class::is_primitive(ret_type)) {
3535         // Only for primitive type vm allocates memory for java object.
3536         // See box() method.
3537         JvmtiExport::post_vm_object_alloc(thread, result);
3538       }
3539     }
3540     return res;
3541   } else {
3542     THROW_0(vmSymbols::java_lang_StackOverflowError());
3543   }
3544 JVM_END
3545 
3546 
3547 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))

3548   oop constructor_mirror = JNIHandles::resolve(c);
3549   objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3550   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3551   jobject res = JNIHandles::make_local(THREAD, result);
3552   if (JvmtiExport::should_post_vm_object_alloc()) {
3553     JvmtiExport::post_vm_object_alloc(thread, result);
3554   }
3555   return res;
3556 JVM_END
3557 
3558 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3559 
3560 JVM_LEAF(jboolean, JVM_SupportsCX8())
3561   return VM_Version::supports_cx8();
3562 JVM_END
3563 
3564 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3565   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3566   assert(k->is_klass(), "just checking");
3567   HeapShared::initialize_from_archived_subgraph(k, THREAD);
3568 JVM_END
3569 

  39 #include "classfile/moduleEntry.hpp"
  40 #include "classfile/modules.hpp"
  41 #include "classfile/packageEntry.hpp"
  42 #include "classfile/stringTable.hpp"
  43 #include "classfile/symbolTable.hpp"
  44 #include "classfile/systemDictionary.hpp"
  45 #include "classfile/vmClasses.hpp"
  46 #include "classfile/vmSymbols.hpp"
  47 #include "gc/shared/collectedHeap.inline.hpp"
  48 #include "interpreter/bytecode.hpp"
  49 #include "interpreter/bytecodeUtils.hpp"
  50 #include "jfr/jfrEvents.hpp"
  51 #include "logging/log.hpp"
  52 #include "memory/oopFactory.hpp"
  53 #include "memory/referenceType.hpp"
  54 #include "memory/resourceArea.hpp"
  55 #include "memory/universe.hpp"
  56 #include "oops/access.inline.hpp"
  57 #include "oops/constantPool.hpp"
  58 #include "oops/fieldStreams.inline.hpp"
  59 #include "oops/flatArrayKlass.hpp"
  60 #include "oops/instanceKlass.hpp"
  61 #include "oops/klass.inline.hpp"
  62 #include "oops/method.hpp"
  63 #include "oops/recordComponent.hpp"
  64 #include "oops/objArrayKlass.hpp"
  65 #include "oops/objArrayOop.inline.hpp"
  66 #include "oops/oop.inline.hpp"
  67 #include "prims/jvm_misc.hpp"
  68 #include "prims/jvmtiExport.hpp"
  69 #include "prims/jvmtiThreadState.hpp"
  70 #include "prims/stackwalk.hpp"
  71 #include "runtime/arguments.hpp"
  72 #include "runtime/atomic.hpp"
  73 #include "runtime/globals_extension.hpp"
  74 #include "runtime/handles.inline.hpp"
  75 #include "runtime/init.hpp"
  76 #include "runtime/interfaceSupport.inline.hpp"
  77 #include "runtime/deoptimization.hpp"
  78 #include "runtime/handshake.hpp"
  79 #include "runtime/java.hpp"

 585   // and a StackFrameInfo[] array (or derivative) otherwise. It should never
 586   // be null.
 587   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 588   objArrayHandle frames_array_h(THREAD, fa);
 589 
 590   int limit = start_index+frame_count;
 591   if (frames_array_h->length() < limit) {
 592     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "not enough space in buffers");
 593   }
 594 
 595   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 596   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count,
 597                                    start_index, frames_array_h, THREAD);
 598 JVM_END
 599 
 600 // java.lang.Object ///////////////////////////////////////////////
 601 
 602 
 603 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 604   // as implemented in the classic virtual machine; return 0 if object is NULL
 605   if (handle == NULL) {
 606     return 0;
 607   }
 608   oop obj = JNIHandles::resolve_non_null(handle);
 609   if (EnableValhalla && obj->klass()->is_inline_klass()) {
 610       JavaValue result(T_INT);
 611       JavaCallArguments args;
 612       Handle ho(THREAD, obj);
 613       args.push_oop(ho);
 614       methodHandle method(THREAD, Universe::primitive_type_hash_code_method());
 615       JavaCalls::call(&result, method, &args, THREAD);
 616       if (HAS_PENDING_EXCEPTION) {
 617         if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
 618           Handle e(THREAD, PENDING_EXCEPTION);
 619           CLEAR_PENDING_EXCEPTION;
 620           THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in hashCode", e, false);
 621         }
 622       }
 623       return result.get_jint();
 624   } else {
 625     return ObjectSynchronizer::FastHashCode(THREAD, obj);
 626   }
 627 JVM_END
 628 
 629 
 630 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 631   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 632   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 633   if (JvmtiExport::should_post_monitor_wait()) {
 634     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 635 
 636     // The current thread already owns the monitor and it has not yet
 637     // been added to the wait queue so the current thread cannot be
 638     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 639     // event handler cannot accidentally consume an unpark() meant for
 640     // the ParkEvent associated with this ObjectMonitor.
 641   }
 642   ObjectSynchronizer::wait(obj, ms, CHECK);
 643 JVM_END
 644 
 645 
 646 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))

 658 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 659   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 660   Klass* klass = obj->klass();
 661   JvmtiVMObjectAllocEventCollector oam;
 662 
 663 #ifdef ASSERT
 664   // Just checking that the cloneable flag is set correct
 665   if (obj->is_array()) {
 666     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 667   } else {
 668     guarantee(obj->is_instance(), "should be instanceOop");
 669     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 670     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 671   }
 672 #endif
 673 
 674   // Check if class of obj supports the Cloneable interface.
 675   // All arrays are considered to be cloneable (See JLS 20.1.5).
 676   // All j.l.r.Reference classes are considered non-cloneable.
 677   if (!klass->is_cloneable() ||
 678        klass->is_inline_klass() ||
 679       (klass->is_instance_klass() &&
 680        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 681     ResourceMark rm(THREAD);
 682     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 683   }
 684 
 685   // Make shallow object copy
 686   const size_t size = obj->size();
 687   oop new_obj_oop = NULL;
 688   if (obj->is_array()) {
 689     const int length = ((arrayOop)obj())->length();
 690     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 691                                                    /* do_zero */ true, CHECK_NULL);
 692   } else {
 693     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 694   }
 695 
 696   HeapAccess<>::clone(obj(), new_obj_oop, size);
 697 
 698   Handle new_obj(THREAD, new_obj_oop);

1166   oop result = java_lang_Class::name(java_class, CHECK_NULL);
1167   return (jstring) JNIHandles::make_local(THREAD, result);
1168 JVM_END
1169 
1170 
1171 JVM_ENTRY(jobjectArray, JVM_GetClassInterfaces(JNIEnv *env, jclass cls))
1172   JvmtiVMObjectAllocEventCollector oam;
1173   oop mirror = JNIHandles::resolve_non_null(cls);
1174 
1175   // Special handling for primitive objects
1176   if (java_lang_Class::is_primitive(mirror)) {
1177     // Primitive objects does not have any interfaces
1178     objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), 0, CHECK_NULL);
1179     return (jobjectArray) JNIHandles::make_local(THREAD, r);
1180   }
1181 
1182   Klass* klass = java_lang_Class::as_Klass(mirror);
1183   // Figure size of result array
1184   int size;
1185   if (klass->is_instance_klass()) {
1186     InstanceKlass* ik = InstanceKlass::cast(klass);
1187     size = ik->local_interfaces()->length();
1188   } else {
1189     assert(klass->is_objArray_klass() || klass->is_typeArray_klass() || klass->is_flatArray_klass(), "Illegal mirror klass");
1190     size = 2;
1191   }
1192 
1193   // Allocate result array
1194   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1195   objArrayHandle result (THREAD, r);
1196   // Fill in result
1197   if (klass->is_instance_klass()) {
1198     // Regular instance klass, fill in all local interfaces
1199     for (int index = 0; index < size; index++) {
1200       InstanceKlass* ik = InstanceKlass::cast(klass);
1201       Klass* k = ik->local_interfaces()->at(index);
1202       result->obj_at_put(index, k->java_mirror());
1203     }
1204   } else {
1205     // All arrays implement java.lang.Cloneable and java.io.Serializable
1206     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1207     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1208   }
1209   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1210 JVM_END
1211 
1212 
1213 JVM_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
1214   oop mirror = JNIHandles::resolve_non_null(cls);
1215   if (java_lang_Class::is_primitive(mirror)) {
1216     return JNI_FALSE;
1217   }
1218   Klass* k = java_lang_Class::as_Klass(mirror);
1219   jboolean result = k->is_interface();
1220   assert(!result || k->is_instance_klass(),
1221          "all interfaces are instance types");

1783     int length = components->length();
1784     assert(length >= 0, "unexpected record_components length");
1785     objArrayOop record_components =
1786       oopFactory::new_objArray(vmClasses::RecordComponent_klass(), length, CHECK_NULL);
1787     objArrayHandle components_h (THREAD, record_components);
1788 
1789     for (int x = 0; x < length; x++) {
1790       RecordComponent* component = components->at(x);
1791       assert(component != NULL, "unexpected NULL record component");
1792       oop component_oop = java_lang_reflect_RecordComponent::create(ik, component, CHECK_NULL);
1793       components_h->obj_at_put(x, component_oop);
1794     }
1795     return (jobjectArray)JNIHandles::make_local(THREAD, components_h());
1796   }
1797 
1798   return NULL;
1799 }
1800 JVM_END
1801 
1802 static bool select_method(const methodHandle& method, bool want_constructor) {
1803   bool is_ctor = (method->is_object_constructor() ||
1804                   method->is_static_init_factory());
1805   if (want_constructor) {
1806     return is_ctor;
1807   } else {
1808     return (!is_ctor &&
1809             !method->is_class_initializer() &&
1810             !method->is_overpass());
1811   }
1812 }
1813 
1814 static jobjectArray get_class_declared_methods_helper(
1815                                   JNIEnv *env,
1816                                   jclass ofClass, jboolean publicOnly,
1817                                   bool want_constructor,
1818                                   Klass* klass, TRAPS) {
1819 
1820   JvmtiVMObjectAllocEventCollector oam;
1821 
1822   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1823   // Exclude primitive types and array types
1824   if (java_lang_Class::is_primitive(ofMirror)
1825       || java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1826     // Return empty array
1827     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1828     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1829   }
1830 

1853     }
1854   }
1855 
1856   // Allocate result
1857   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1858   objArrayHandle result (THREAD, r);
1859 
1860   // Now just put the methods that we selected above, but go by their idnum
1861   // in case of redefinition.  The methods can be redefined at any safepoint,
1862   // so above when allocating the oop array and below when creating reflect
1863   // objects.
1864   for (int i = 0; i < num_methods; i++) {
1865     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1866     if (method.is_null()) {
1867       // Method may have been deleted and seems this API can handle null
1868       // Otherwise should probably put a method that throws NSME
1869       result->obj_at_put(i, NULL);
1870     } else {
1871       oop m;
1872       if (want_constructor) {
1873         assert(method->is_object_constructor() ||
1874                method->is_static_init_factory(), "must be");
1875         m = Reflection::new_constructor(method, CHECK_NULL);
1876       } else {
1877         m = Reflection::new_method(method, false, CHECK_NULL);
1878       }
1879       result->obj_at_put(i, m);
1880     }
1881   }
1882 
1883   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1884 }
1885 
1886 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1887 {
1888   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1889                                            /*want_constructor*/ false,
1890                                            vmClasses::reflect_Method_klass(), THREAD);
1891 }
1892 JVM_END
1893 
1894 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

2137   constantTag tag = cp->tag_at(index);
2138   if (!tag.is_method() && !tag.is_interface_method()) {
2139     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2140   }
2141   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2142   Klass* k_o;
2143   if (force_resolution) {
2144     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2145   } else {
2146     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2147     if (k_o == NULL) return NULL;
2148   }
2149   InstanceKlass* k = InstanceKlass::cast(k_o);
2150   Symbol* name = cp->uncached_name_ref_at(index);
2151   Symbol* sig  = cp->uncached_signature_ref_at(index);
2152   methodHandle m (THREAD, k->find_method(name, sig));
2153   if (m.is_null()) {
2154     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2155   }
2156   oop method;
2157   if (m->is_object_constructor() || m->is_static_init_factory()) {


2158     method = Reflection::new_constructor(m, CHECK_NULL);
2159   } else {
2160     method = Reflection::new_method(m, true, CHECK_NULL);
2161   }
2162   return JNIHandles::make_local(THREAD, method);
2163 }
2164 
2165 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2166 {
2167   JvmtiVMObjectAllocEventCollector oam;
2168   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2169   bounds_check(cp, index, CHECK_NULL);
2170   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2171   return res;
2172 }
2173 JVM_END
2174 
2175 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2176 {
2177   JvmtiVMObjectAllocEventCollector oam;
2178   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2179   bounds_check(cp, index, CHECK_NULL);
2180   jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);

2411   Klass* k = java_lang_Class::as_Klass(r);
2412   assert(k->is_instance_klass(), "must be an instance klass");
2413   if (!k->is_instance_klass()) return false;
2414 
2415   ResourceMark rm(THREAD);
2416   const char* name = k->name()->as_C_string();
2417   bool system_class = k->class_loader() == NULL;
2418   return JavaAssertions::enabled(name, system_class);
2419 
2420 JVM_END
2421 
2422 
2423 // Return a new AssertionStatusDirectives object with the fields filled in with
2424 // command-line assertion arguments (i.e., -ea, -da).
2425 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2426   JvmtiVMObjectAllocEventCollector oam;
2427   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2428   return JNIHandles::make_local(THREAD, asd);
2429 JVM_END
2430 
2431 // Arrays support /////////////////////////////////////////////////////////////
2432 
2433 JVM_ENTRY(jboolean, JVM_ArrayIsAccessAtomic(JNIEnv *env, jclass unused, jobject array))
2434   oop o = JNIHandles::resolve(array);
2435   Klass* k = o->klass();
2436   if ((o == NULL) || (!k->is_array_klass())) {
2437     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
2438   }
2439   return ArrayKlass::cast(k)->element_access_is_atomic();
2440 JVM_END
2441 
2442 JVM_ENTRY(jobject, JVM_ArrayEnsureAccessAtomic(JNIEnv *env, jclass unused, jobject array))
2443   oop o = JNIHandles::resolve(array);
2444   Klass* k = o->klass();
2445   if ((o == NULL) || (!k->is_array_klass())) {
2446     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
2447   }
2448   if (k->is_flatArray_klass()) {
2449     FlatArrayKlass* vk = FlatArrayKlass::cast(k);
2450     if (!vk->element_access_is_atomic()) {
2451       /**
2452        * Need to decide how to implement:
2453        *
2454        * 1) Change to objArrayOop layout, therefore oop->klass() differs so
2455        * then "<atomic>[Qfoo;" klass needs to subclass "[Qfoo;" to pass through
2456        * "checkcast" & "instanceof"
2457        *
2458        * 2) Use extra header in the flatArrayOop to flag atomicity required and
2459        * possibly per instance lock structure. Said info, could be placed in
2460        * "trailer" rather than disturb the current arrayOop
2461        */
2462       Unimplemented();
2463     }
2464   }
2465   return array;
2466 JVM_END
2467 
2468 // Verification ////////////////////////////////////////////////////////////////////////////////
2469 
2470 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2471 
2472 // RedefineClasses support: bug 6214132 caused verification to fail.
2473 // All functions from this section should call the jvmtiThreadSate function:
2474 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2475 // The function returns a Klass* of the _scratch_class if the verifier
2476 // was invoked in the middle of the class redefinition.
2477 // Otherwise it returns its argument value which is the _the_class Klass*.
2478 // Please, refer to the description in the jvmtiThreadSate.hpp.
2479 
2480 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2481   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2482   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2483   return k->name()->as_utf8();
2484 JVM_END
2485 
2486 
2487 JVM_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))

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

3576   //   the checkPackageAccess relative to the initiating class loader via the
3577   //   protection_domain. The protection_domain is passed as NULL by the java code
3578   //   if there is no security manager in 3-arg Class.forName().
3579   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3580 
3581   // Check if we should initialize the class
3582   if (init && klass->is_instance_klass()) {
3583     klass->initialize(CHECK_NULL);
3584   }
3585   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3586 }
3587 
3588 
3589 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3590 
3591 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3592   Handle method_handle;
3593   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3594     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3595     Handle receiver(THREAD, JNIHandles::resolve(obj));
3596     objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3597     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3598     jobject res = JNIHandles::make_local(THREAD, result);
3599     if (JvmtiExport::should_post_vm_object_alloc()) {
3600       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3601       assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
3602       if (java_lang_Class::is_primitive(ret_type)) {
3603         // Only for primitive type vm allocates memory for java object.
3604         // See box() method.
3605         JvmtiExport::post_vm_object_alloc(thread, result);
3606       }
3607     }
3608     return res;
3609   } else {
3610     THROW_0(vmSymbols::java_lang_StackOverflowError());
3611   }
3612 JVM_END
3613 
3614 
3615 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3616   objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3617   oop constructor_mirror = JNIHandles::resolve(c);

3618   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3619   jobject res = JNIHandles::make_local(THREAD, result);
3620   if (JvmtiExport::should_post_vm_object_alloc()) {
3621     JvmtiExport::post_vm_object_alloc(thread, result);
3622   }
3623   return res;
3624 JVM_END
3625 
3626 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3627 
3628 JVM_LEAF(jboolean, JVM_SupportsCX8())
3629   return VM_Version::supports_cx8();
3630 JVM_END
3631 
3632 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3633   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3634   assert(k->is_klass(), "just checking");
3635   HeapShared::initialize_from_archived_subgraph(k, THREAD);
3636 JVM_END
3637 
< prev index next >