< 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.inline.hpp"
  69 #include "prims/stackwalk.hpp"
  70 #include "runtime/arguments.hpp"
  71 #include "runtime/atomic.hpp"
  72 #include "runtime/continuation.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"

 596 
 597   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 598   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count,
 599                                   start_index, frames_array_h, THREAD);
 600 JVM_END
 601 
 602 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 603   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 604   objArrayHandle frames_array_h(THREAD, fa);
 605   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 606   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 607 
 608   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 609 JVM_END
 610 
 611 // java.lang.Object ///////////////////////////////////////////////
 612 
 613 
 614 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 615   // as implemented in the classic virtual machine; return 0 if object is NULL
 616   return handle == NULL ? 0 : ObjectSynchronizer::FastHashCode (THREAD, JNIHandles::resolve_non_null(handle)) ;





















 617 JVM_END
 618 
 619 
 620 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 621   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 622   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 623   if (JvmtiExport::should_post_monitor_wait()) {
 624     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 625 
 626     // The current thread already owns the monitor and it has not yet
 627     // been added to the wait queue so the current thread cannot be
 628     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 629     // event handler cannot accidentally consume an unpark() meant for
 630     // the ParkEvent associated with this ObjectMonitor.
 631   }
 632   ObjectSynchronizer::wait(obj, ms, CHECK);
 633 JVM_END
 634 
 635 
 636 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))

 648 JVM_ENTRY(jobject, JVM_Clone(JNIEnv* env, jobject handle))
 649   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 650   Klass* klass = obj->klass();
 651   JvmtiVMObjectAllocEventCollector oam;
 652 
 653 #ifdef ASSERT
 654   // Just checking that the cloneable flag is set correct
 655   if (obj->is_array()) {
 656     guarantee(klass->is_cloneable(), "all arrays are cloneable");
 657   } else {
 658     guarantee(obj->is_instance(), "should be instanceOop");
 659     bool cloneable = klass->is_subtype_of(vmClasses::Cloneable_klass());
 660     guarantee(cloneable == klass->is_cloneable(), "incorrect cloneable flag");
 661   }
 662 #endif
 663 
 664   // Check if class of obj supports the Cloneable interface.
 665   // All arrays are considered to be cloneable (See JLS 20.1.5).
 666   // All j.l.r.Reference classes are considered non-cloneable.
 667   if (!klass->is_cloneable() ||

 668       (klass->is_instance_klass() &&
 669        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 670     ResourceMark rm(THREAD);
 671     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 672   }
 673 
 674   // Make shallow object copy
 675   const size_t size = obj->size();
 676   oop new_obj_oop = NULL;
 677   if (obj->is_array()) {
 678     const int length = ((arrayOop)obj())->length();
 679     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 680                                                    /* do_zero */ true, CHECK_NULL);
 681   } else {
 682     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 683   }
 684 
 685   HeapAccess<>::clone(obj(), new_obj_oop, size);
 686 
 687   Handle new_obj(THREAD, new_obj_oop);

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

1182   } else {
1183     assert(klass->is_objArray_klass() || klass->is_typeArray_klass(), "Illegal mirror klass");
1184     size = 2;
1185   }
1186 
1187   // Allocate result array
1188   objArrayOop r = oopFactory::new_objArray(vmClasses::Class_klass(), size, CHECK_NULL);
1189   objArrayHandle result (THREAD, r);
1190   // Fill in result
1191   if (klass->is_instance_klass()) {
1192     // Regular instance klass, fill in all local interfaces
1193     for (int index = 0; index < size; index++) {
1194       Klass* k = InstanceKlass::cast(klass)->local_interfaces()->at(index);

1195       result->obj_at_put(index, k->java_mirror());
1196     }
1197   } else {
1198     // All arrays implement java.lang.Cloneable and java.io.Serializable
1199     result->obj_at_put(0, vmClasses::Cloneable_klass()->java_mirror());
1200     result->obj_at_put(1, vmClasses::Serializable_klass()->java_mirror());
1201   }
1202   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1203 JVM_END
1204 
1205 
1206 JVM_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
1207   oop mirror = JNIHandles::resolve_non_null(cls);
1208   if (java_lang_Class::is_primitive(mirror)) {
1209     return JNI_FALSE;
1210   }
1211   Klass* k = java_lang_Class::as_Klass(mirror);
1212   jboolean result = k->is_interface();
1213   assert(!result || k->is_instance_klass(),
1214          "all interfaces are instance types");

1776     int length = components->length();
1777     assert(length >= 0, "unexpected record_components length");
1778     objArrayOop record_components =
1779       oopFactory::new_objArray(vmClasses::RecordComponent_klass(), length, CHECK_NULL);
1780     objArrayHandle components_h (THREAD, record_components);
1781 
1782     for (int x = 0; x < length; x++) {
1783       RecordComponent* component = components->at(x);
1784       assert(component != NULL, "unexpected NULL record component");
1785       oop component_oop = java_lang_reflect_RecordComponent::create(ik, component, CHECK_NULL);
1786       components_h->obj_at_put(x, component_oop);
1787     }
1788     return (jobjectArray)JNIHandles::make_local(THREAD, components_h());
1789   }
1790 
1791   return NULL;
1792 }
1793 JVM_END
1794 
1795 static bool select_method(const methodHandle& method, bool want_constructor) {


1796   if (want_constructor) {
1797     return (method->is_initializer() && !method->is_static());
1798   } else {
1799     return  (!method->is_initializer() && !method->is_overpass());


1800   }
1801 }
1802 
1803 static jobjectArray get_class_declared_methods_helper(
1804                                   JNIEnv *env,
1805                                   jclass ofClass, jboolean publicOnly,
1806                                   bool want_constructor,
1807                                   Klass* klass, TRAPS) {
1808 
1809   JvmtiVMObjectAllocEventCollector oam;
1810 
1811   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1812   // Exclude primitive types and array types
1813   if (java_lang_Class::is_primitive(ofMirror)
1814       || java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1815     // Return empty array
1816     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1817     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1818   }
1819 

1842     }
1843   }
1844 
1845   // Allocate result
1846   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1847   objArrayHandle result (THREAD, r);
1848 
1849   // Now just put the methods that we selected above, but go by their idnum
1850   // in case of redefinition.  The methods can be redefined at any safepoint,
1851   // so above when allocating the oop array and below when creating reflect
1852   // objects.
1853   for (int i = 0; i < num_methods; i++) {
1854     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1855     if (method.is_null()) {
1856       // Method may have been deleted and seems this API can handle null
1857       // Otherwise should probably put a method that throws NSME
1858       result->obj_at_put(i, NULL);
1859     } else {
1860       oop m;
1861       if (want_constructor) {


1862         m = Reflection::new_constructor(method, CHECK_NULL);
1863       } else {
1864         m = Reflection::new_method(method, false, CHECK_NULL);
1865       }
1866       result->obj_at_put(i, m);
1867     }
1868   }
1869 
1870   return (jobjectArray) JNIHandles::make_local(THREAD, result());
1871 }
1872 
1873 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1874 {
1875   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1876                                            /*want_constructor*/ false,
1877                                            vmClasses::reflect_Method_klass(), THREAD);
1878 }
1879 JVM_END
1880 
1881 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredConstructors(JNIEnv *env, jclass ofClass, jboolean publicOnly))

2124   constantTag tag = cp->tag_at(index);
2125   if (!tag.is_method() && !tag.is_interface_method()) {
2126     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2127   }
2128   int klass_ref  = cp->uncached_klass_ref_index_at(index);
2129   Klass* k_o;
2130   if (force_resolution) {
2131     k_o = cp->klass_at(klass_ref, CHECK_NULL);
2132   } else {
2133     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
2134     if (k_o == NULL) return NULL;
2135   }
2136   InstanceKlass* k = InstanceKlass::cast(k_o);
2137   Symbol* name = cp->uncached_name_ref_at(index);
2138   Symbol* sig  = cp->uncached_signature_ref_at(index);
2139   methodHandle m (THREAD, k->find_method(name, sig));
2140   if (m.is_null()) {
2141     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
2142   }
2143   oop method;
2144   if (!m->is_initializer() || m->is_static()) {
2145     method = Reflection::new_method(m, true, CHECK_NULL);
2146   } else {
2147     method = Reflection::new_constructor(m, CHECK_NULL);


2148   }
2149   return JNIHandles::make_local(THREAD, method);
2150 }
2151 
2152 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2153 {
2154   JvmtiVMObjectAllocEventCollector oam;
2155   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2156   bounds_check(cp, index, CHECK_NULL);
2157   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
2158   return res;
2159 }
2160 JVM_END
2161 
2162 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
2163 {
2164   JvmtiVMObjectAllocEventCollector oam;
2165   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2166   bounds_check(cp, index, CHECK_NULL);
2167   jobject res = get_method_at_helper(cp, index, false, CHECK_NULL);

2398   Klass* k = java_lang_Class::as_Klass(r);
2399   assert(k->is_instance_klass(), "must be an instance klass");
2400   if (!k->is_instance_klass()) return false;
2401 
2402   ResourceMark rm(THREAD);
2403   const char* name = k->name()->as_C_string();
2404   bool system_class = k->class_loader() == NULL;
2405   return JavaAssertions::enabled(name, system_class);
2406 
2407 JVM_END
2408 
2409 
2410 // Return a new AssertionStatusDirectives object with the fields filled in with
2411 // command-line assertion arguments (i.e., -ea, -da).
2412 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2413   JvmtiVMObjectAllocEventCollector oam;
2414   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2415   return JNIHandles::make_local(THREAD, asd);
2416 JVM_END
2417 





































2418 // Verification ////////////////////////////////////////////////////////////////////////////////
2419 
2420 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2421 
2422 // RedefineClasses support: bug 6214132 caused verification to fail.
2423 // All functions from this section should call the jvmtiThreadSate function:
2424 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2425 // The function returns a Klass* of the _scratch_class if the verifier
2426 // was invoked in the middle of the class redefinition.
2427 // Otherwise it returns its argument value which is the _the_class Klass*.
2428 // Please, refer to the description in the jvmtiThreadSate.hpp.
2429 
2430 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2431   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2432   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2433   return k->name()->as_utf8();
2434 JVM_END
2435 
2436 
2437 JVM_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))

2560   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2561   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2562   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2563   return method->size_of_parameters();
2564 JVM_END
2565 
2566 
2567 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
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->verifier_max_stack();
2572 JVM_END
2573 
2574 
2575 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2576   ResourceMark rm(THREAD);
2577   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2578   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2579   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2580   return method->name() == vmSymbols::object_initializer_name();
2581 JVM_END
2582 
2583 
2584 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2585   ResourceMark rm(THREAD);
2586   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2587   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2588   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2589   return method->is_overpass();
2590 JVM_END
2591 
2592 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2593   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2594   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2595   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2596   return method->name()->as_utf8();
2597 JVM_END
2598 
2599 
2600 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))

3554   //   the checkPackageAccess relative to the initiating class loader via the
3555   //   protection_domain. The protection_domain is passed as NULL by the java code
3556   //   if there is no security manager in 3-arg Class.forName().
3557   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3558 
3559   // Check if we should initialize the class
3560   if (init && klass->is_instance_klass()) {
3561     klass->initialize(CHECK_NULL);
3562   }
3563   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3564 }
3565 
3566 
3567 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3568 
3569 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3570   Handle method_handle;
3571   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3572     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3573     Handle receiver(THREAD, JNIHandles::resolve(obj));
3574     objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3575     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3576     jobject res = JNIHandles::make_local(THREAD, result);
3577     if (JvmtiExport::should_post_vm_object_alloc()) {
3578       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3579       assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
3580       if (java_lang_Class::is_primitive(ret_type)) {
3581         // Only for primitive type vm allocates memory for java object.
3582         // See box() method.
3583         JvmtiExport::post_vm_object_alloc(thread, result);
3584       }
3585     }
3586     return res;
3587   } else {
3588     THROW_0(vmSymbols::java_lang_StackOverflowError());
3589   }
3590 JVM_END
3591 
3592 
3593 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))

3594   oop constructor_mirror = JNIHandles::resolve(c);
3595   objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3596   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3597   jobject res = JNIHandles::make_local(THREAD, result);
3598   if (JvmtiExport::should_post_vm_object_alloc()) {
3599     JvmtiExport::post_vm_object_alloc(thread, result);
3600   }
3601   return res;
3602 JVM_END
3603 
3604 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3605 
3606 JVM_LEAF(jboolean, JVM_SupportsCX8())
3607   return VM_Version::supports_cx8();
3608 JVM_END
3609 
3610 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3611   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3612   assert(k->is_klass(), "just checking");
3613   HeapShared::initialize_from_archived_subgraph(k, THREAD);
3614 JVM_END
3615 

  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.inline.hpp"
  70 #include "prims/stackwalk.hpp"
  71 #include "runtime/arguments.hpp"
  72 #include "runtime/atomic.hpp"
  73 #include "runtime/continuation.hpp"
  74 #include "runtime/globals_extension.hpp"
  75 #include "runtime/handles.inline.hpp"
  76 #include "runtime/init.hpp"
  77 #include "runtime/interfaceSupport.inline.hpp"
  78 #include "runtime/deoptimization.hpp"
  79 #include "runtime/handshake.hpp"

 597 
 598   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 599   return StackWalk::fetchNextBatch(stackStream_h, mode, anchor, frame_count,
 600                                   start_index, frames_array_h, THREAD);
 601 JVM_END
 602 
 603 JVM_ENTRY(void, JVM_SetStackWalkContinuation(JNIEnv *env, jobject stackStream, jlong anchor, jobjectArray frames, jobject cont))
 604   objArrayOop fa = objArrayOop(JNIHandles::resolve_non_null(frames));
 605   objArrayHandle frames_array_h(THREAD, fa);
 606   Handle stackStream_h(THREAD, JNIHandles::resolve_non_null(stackStream));
 607   Handle cont_h(THREAD, JNIHandles::resolve_non_null(cont));
 608 
 609   StackWalk::setContinuation(stackStream_h, anchor, frames_array_h, cont_h, THREAD);
 610 JVM_END
 611 
 612 // java.lang.Object ///////////////////////////////////////////////
 613 
 614 
 615 JVM_ENTRY(jint, JVM_IHashCode(JNIEnv* env, jobject handle))
 616   // as implemented in the classic virtual machine; return 0 if object is NULL
 617   if (handle == NULL) {
 618     return 0;
 619   }
 620   oop obj = JNIHandles::resolve_non_null(handle);
 621   if (EnableValhalla && obj->klass()->is_inline_klass()) {
 622       JavaValue result(T_INT);
 623       JavaCallArguments args;
 624       Handle ho(THREAD, obj);
 625       args.push_oop(ho);
 626       methodHandle method(THREAD, Universe::primitive_type_hash_code_method());
 627       JavaCalls::call(&result, method, &args, THREAD);
 628       if (HAS_PENDING_EXCEPTION) {
 629         if (!PENDING_EXCEPTION->is_a(vmClasses::Error_klass())) {
 630           Handle e(THREAD, PENDING_EXCEPTION);
 631           CLEAR_PENDING_EXCEPTION;
 632           THROW_MSG_CAUSE_(vmSymbols::java_lang_InternalError(), "Internal error in hashCode", e, false);
 633         }
 634       }
 635       return result.get_jint();
 636   } else {
 637     return ObjectSynchronizer::FastHashCode(THREAD, obj);
 638   }
 639 JVM_END
 640 
 641 
 642 JVM_ENTRY(void, JVM_MonitorWait(JNIEnv* env, jobject handle, jlong ms))
 643   Handle obj(THREAD, JNIHandles::resolve_non_null(handle));
 644   JavaThreadInObjectWaitState jtiows(thread, ms != 0);
 645   if (JvmtiExport::should_post_monitor_wait()) {
 646     JvmtiExport::post_monitor_wait(thread, obj(), ms);
 647 
 648     // The current thread already owns the monitor and it has not yet
 649     // been added to the wait queue so the current thread cannot be
 650     // made the successor. This means that the JVMTI_EVENT_MONITOR_WAIT
 651     // event handler cannot accidentally consume an unpark() meant for
 652     // the ParkEvent associated with this ObjectMonitor.
 653   }
 654   ObjectSynchronizer::wait(obj, ms, CHECK);
 655 JVM_END
 656 
 657 
 658 JVM_ENTRY(void, JVM_MonitorNotify(JNIEnv* env, jobject handle))

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

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

1801     int length = components->length();
1802     assert(length >= 0, "unexpected record_components length");
1803     objArrayOop record_components =
1804       oopFactory::new_objArray(vmClasses::RecordComponent_klass(), length, CHECK_NULL);
1805     objArrayHandle components_h (THREAD, record_components);
1806 
1807     for (int x = 0; x < length; x++) {
1808       RecordComponent* component = components->at(x);
1809       assert(component != NULL, "unexpected NULL record component");
1810       oop component_oop = java_lang_reflect_RecordComponent::create(ik, component, CHECK_NULL);
1811       components_h->obj_at_put(x, component_oop);
1812     }
1813     return (jobjectArray)JNIHandles::make_local(THREAD, components_h());
1814   }
1815 
1816   return NULL;
1817 }
1818 JVM_END
1819 
1820 static bool select_method(const methodHandle& method, bool want_constructor) {
1821   bool is_ctor = (method->is_object_constructor() ||
1822                   method->is_static_init_factory());
1823   if (want_constructor) {
1824     return is_ctor;
1825   } else {
1826     return (!is_ctor &&
1827             !method->is_class_initializer() &&
1828             !method->is_overpass());
1829   }
1830 }
1831 
1832 static jobjectArray get_class_declared_methods_helper(
1833                                   JNIEnv *env,
1834                                   jclass ofClass, jboolean publicOnly,
1835                                   bool want_constructor,
1836                                   Klass* klass, TRAPS) {
1837 
1838   JvmtiVMObjectAllocEventCollector oam;
1839 
1840   oop ofMirror = JNIHandles::resolve_non_null(ofClass);
1841   // Exclude primitive types and array types
1842   if (java_lang_Class::is_primitive(ofMirror)
1843       || java_lang_Class::as_Klass(ofMirror)->is_array_klass()) {
1844     // Return empty array
1845     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1846     return (jobjectArray) JNIHandles::make_local(THREAD, res);
1847   }
1848 

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

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


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

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

2628   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2629   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2630   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2631   return method->size_of_parameters();
2632 JVM_END
2633 
2634 
2635 JVM_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
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->verifier_max_stack();
2640 JVM_END
2641 
2642 
2643 JVM_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2644   ResourceMark rm(THREAD);
2645   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2646   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2647   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2648   return method->is_object_constructor();
2649 JVM_END
2650 
2651 
2652 JVM_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2653   ResourceMark rm(THREAD);
2654   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2655   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2656   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2657   return method->is_overpass();
2658 JVM_END
2659 
2660 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2661   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2662   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2663   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2664   return method->name()->as_utf8();
2665 JVM_END
2666 
2667 
2668 JVM_ENTRY(const char*, JVM_GetMethodIxSignatureUTF(JNIEnv *env, jclass cls, jint method_index))

3622   //   the checkPackageAccess relative to the initiating class loader via the
3623   //   protection_domain. The protection_domain is passed as NULL by the java code
3624   //   if there is no security manager in 3-arg Class.forName().
3625   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3626 
3627   // Check if we should initialize the class
3628   if (init && klass->is_instance_klass()) {
3629     klass->initialize(CHECK_NULL);
3630   }
3631   return (jclass) JNIHandles::make_local(THREAD, klass->java_mirror());
3632 }
3633 
3634 
3635 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3636 
3637 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3638   Handle method_handle;
3639   if (thread->stack_overflow_state()->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3640     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3641     Handle receiver(THREAD, JNIHandles::resolve(obj));
3642     objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3643     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3644     jobject res = JNIHandles::make_local(THREAD, result);
3645     if (JvmtiExport::should_post_vm_object_alloc()) {
3646       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3647       assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
3648       if (java_lang_Class::is_primitive(ret_type)) {
3649         // Only for primitive type vm allocates memory for java object.
3650         // See box() method.
3651         JvmtiExport::post_vm_object_alloc(thread, result);
3652       }
3653     }
3654     return res;
3655   } else {
3656     THROW_0(vmSymbols::java_lang_StackOverflowError());
3657   }
3658 JVM_END
3659 
3660 
3661 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3662   objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3663   oop constructor_mirror = JNIHandles::resolve(c);

3664   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3665   jobject res = JNIHandles::make_local(THREAD, result);
3666   if (JvmtiExport::should_post_vm_object_alloc()) {
3667     JvmtiExport::post_vm_object_alloc(thread, result);
3668   }
3669   return res;
3670 JVM_END
3671 
3672 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3673 
3674 JVM_LEAF(jboolean, JVM_SupportsCX8())
3675   return VM_Version::supports_cx8();
3676 JVM_END
3677 
3678 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3679   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3680   assert(k->is_klass(), "just checking");
3681   HeapShared::initialize_from_archived_subgraph(k, THREAD);
3682 JVM_END
3683 
< prev index next >