< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page




  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "gc/shared/collectedHeap.inline.hpp"
  40 #include "interpreter/bytecode.hpp"
  41 #include "jfr/jfrEvents.hpp"
  42 #include "logging/log.hpp"
  43 #include "memory/heapShared.hpp"
  44 #include "memory/oopFactory.hpp"
  45 #include "memory/referenceType.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "memory/universe.hpp"
  48 #include "oops/access.inline.hpp"
  49 #include "oops/constantPool.hpp"
  50 #include "oops/fieldStreams.hpp"
  51 #include "oops/instanceKlass.hpp"
  52 #include "oops/method.hpp"
  53 #include "oops/objArrayKlass.hpp"
  54 #include "oops/objArrayOop.inline.hpp"
  55 #include "oops/oop.inline.hpp"

  56 #include "prims/jvm_misc.hpp"
  57 #include "prims/jvmtiExport.hpp"
  58 #include "prims/jvmtiThreadState.hpp"
  59 #include "prims/nativeLookup.hpp"
  60 #include "prims/stackwalk.hpp"
  61 #include "runtime/arguments.hpp"
  62 #include "runtime/atomic.hpp"
  63 #include "runtime/handles.inline.hpp"
  64 #include "runtime/init.hpp"
  65 #include "runtime/interfaceSupport.inline.hpp"
  66 #include "runtime/deoptimization.hpp"
  67 #include "runtime/handshake.hpp"
  68 #include "runtime/java.hpp"
  69 #include "runtime/javaCalls.hpp"
  70 #include "runtime/jfieldIDWorkaround.hpp"
  71 #include "runtime/jniHandles.inline.hpp"
  72 #include "runtime/orderAccess.hpp"
  73 #include "runtime/os.inline.hpp"
  74 #include "runtime/perfData.hpp"
  75 #include "runtime/reflection.hpp"


 658   JVMWrapper("JVM_Clone");
 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(SystemDictionary::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_instance_klass() &&
 679        InstanceKlass::cast(klass)->reference_type() != REF_NONE)) {
 680     ResourceMark rm(THREAD);
 681     THROW_MSG_0(vmSymbols::java_lang_CloneNotSupportedException(), klass->external_name());
 682   }
 683 
 684   // Make shallow object copy
 685   const int size = obj->size();
 686   oop new_obj_oop = NULL;
 687   if (obj->is_array()) {
 688     const int length = ((arrayOop)obj())->length();
 689     new_obj_oop = Universe::heap()->array_allocate(klass, size, length,
 690                                                    /* do_zero */ true, CHECK_NULL);
 691   } else {
 692     new_obj_oop = Universe::heap()->obj_allocate(klass, size, CHECK_NULL);
 693   }
 694 
 695   HeapAccess<>::clone(obj(), new_obj_oop, size);
 696 
 697   Handle new_obj(THREAD, new_obj_oop);


 745       if (!m->caller_sensitive()) {
 746         THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), err_msg("CallerSensitive annotation expected at frame %d", n));
 747       }
 748       break;
 749     default:
 750       if (!m->is_ignored_by_security_stack_walk()) {
 751         // We have reached the desired frame; return the holder class.
 752         return (jclass) JNIHandles::make_local(env, m->method_holder()->java_mirror());
 753       }
 754       break;
 755     }
 756   }
 757   return NULL;
 758 JVM_END
 759 
 760 
 761 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
 762   JVMWrapper("JVM_FindPrimitiveClass");
 763   oop mirror = NULL;
 764   BasicType t = name2type(utf);
 765   if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY) {
 766     mirror = Universe::java_mirror(t);
 767   }
 768   if (mirror == NULL) {
 769     THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
 770   } else {
 771     return (jclass) JNIHandles::make_local(env, mirror);
 772   }
 773 JVM_END
 774 
 775 
 776 // Returns a class loaded by the bootstrap class loader; or null
 777 // if not found.  ClassNotFoundException is not thrown.
 778 // FindClassFromBootLoader is exported to the launcher for windows.
 779 JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env,
 780                                               const char* name))
 781   JVMWrapper("JVM_FindClassFromBootLoader");
 782 
 783   // Java libraries should ensure that name is never null...
 784   if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
 785     // It's impossible to create this class;  the name cannot fit


1644 
1645   objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
1646   objArrayHandle result (THREAD, r);
1647 
1648   int out_idx = 0;
1649   fieldDescriptor fd;
1650   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
1651     if (!publicOnly || fs.access_flags().is_public()) {
1652       fd.reinitialize(k, fs.index());
1653       oop field = Reflection::new_field(&fd, CHECK_NULL);
1654       result->obj_at_put(out_idx, field);
1655       ++out_idx;
1656     }
1657   }
1658   assert(out_idx == num_fields, "just checking");
1659   return (jobjectArray) JNIHandles::make_local(env, result());
1660 }
1661 JVM_END
1662 
1663 static bool select_method(const methodHandle& method, bool want_constructor) {


1664   if (want_constructor) {
1665     return (method->is_initializer() && !method->is_static());
1666   } else {
1667     return  (!method->is_initializer() && !method->is_overpass());


1668   }
1669 }
1670 
1671 static jobjectArray get_class_declared_methods_helper(
1672                                   JNIEnv *env,
1673                                   jclass ofClass, jboolean publicOnly,
1674                                   bool want_constructor,
1675                                   Klass* klass, TRAPS) {
1676 
1677   JvmtiVMObjectAllocEventCollector oam;
1678 
1679   // Exclude primitive types and array types
1680   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1681       || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) {
1682     // Return empty array
1683     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1684     return (jobjectArray) JNIHandles::make_local(env, res);
1685   }
1686 
1687   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));


1709     }
1710   }
1711 
1712   // Allocate result
1713   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1714   objArrayHandle result (THREAD, r);
1715 
1716   // Now just put the methods that we selected above, but go by their idnum
1717   // in case of redefinition.  The methods can be redefined at any safepoint,
1718   // so above when allocating the oop array and below when creating reflect
1719   // objects.
1720   for (int i = 0; i < num_methods; i++) {
1721     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1722     if (method.is_null()) {
1723       // Method may have been deleted and seems this API can handle null
1724       // Otherwise should probably put a method that throws NSME
1725       result->obj_at_put(i, NULL);
1726     } else {
1727       oop m;
1728       if (want_constructor) {


1729         m = Reflection::new_constructor(method, CHECK_NULL);
1730       } else {
1731         m = Reflection::new_method(method, false, CHECK_NULL);
1732       }
1733       result->obj_at_put(i, m);
1734     }
1735   }
1736 
1737   return (jobjectArray) JNIHandles::make_local(env, result());
1738 }
1739 
1740 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1741 {
1742   JVMWrapper("JVM_GetClassDeclaredMethods");
1743   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1744                                            /*want_constructor*/ false,
1745                                            SystemDictionary::reflect_Method_klass(), THREAD);
1746 }
1747 JVM_END
1748 


1925   constantTag tag = cp->tag_at(index);
1926   if (!tag.is_method() && !tag.is_interface_method()) {
1927     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1928   }
1929   int klass_ref  = cp->uncached_klass_ref_index_at(index);
1930   Klass* k_o;
1931   if (force_resolution) {
1932     k_o = cp->klass_at(klass_ref, CHECK_NULL);
1933   } else {
1934     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
1935     if (k_o == NULL) return NULL;
1936   }
1937   InstanceKlass* k = InstanceKlass::cast(k_o);
1938   Symbol* name = cp->uncached_name_ref_at(index);
1939   Symbol* sig  = cp->uncached_signature_ref_at(index);
1940   methodHandle m (THREAD, k->find_method(name, sig));
1941   if (m.is_null()) {
1942     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
1943   }
1944   oop method;
1945   if (!m->is_initializer() || m->is_static()) {
1946     method = Reflection::new_method(m, true, CHECK_NULL);
1947   } else {
1948     method = Reflection::new_constructor(m, CHECK_NULL);


1949   }
1950   return JNIHandles::make_local(method);
1951 }
1952 
1953 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
1954 {
1955   JVMWrapper("JVM_ConstantPoolGetMethodAt");
1956   JvmtiVMObjectAllocEventCollector oam;
1957   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1958   bounds_check(cp, index, CHECK_NULL);
1959   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
1960   return res;
1961 }
1962 JVM_END
1963 
1964 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
1965 {
1966   JVMWrapper("JVM_ConstantPoolGetMethodAtIfLoaded");
1967   JvmtiVMObjectAllocEventCollector oam;
1968   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));


2216   assert(k->is_instance_klass(), "must be an instance klass");
2217   if (!k->is_instance_klass()) return false;
2218 
2219   ResourceMark rm(THREAD);
2220   const char* name = k->name()->as_C_string();
2221   bool system_class = k->class_loader() == NULL;
2222   return JavaAssertions::enabled(name, system_class);
2223 
2224 JVM_END
2225 
2226 
2227 // Return a new AssertionStatusDirectives object with the fields filled in with
2228 // command-line assertion arguments (i.e., -ea, -da).
2229 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2230   JVMWrapper("JVM_AssertionStatusDirectives");
2231   JvmtiVMObjectAllocEventCollector oam;
2232   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2233   return JNIHandles::make_local(env, asd);
2234 JVM_END
2235 










































2236 // Verification ////////////////////////////////////////////////////////////////////////////////
2237 
2238 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2239 
2240 // RedefineClasses support: bug 6214132 caused verification to fail.
2241 // All functions from this section should call the jvmtiThreadSate function:
2242 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2243 // The function returns a Klass* of the _scratch_class if the verifier
2244 // was invoked in the middle of the class redefinition.
2245 // Otherwise it returns its argument value which is the _the_class Klass*.
2246 // Please, refer to the description in the jvmtiThreadSate.hpp.
2247 
2248 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2249   JVMWrapper("JVM_GetClassNameUTF");
2250   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2251   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2252   return k->name()->as_utf8();
2253 JVM_END
2254 
2255 
2256 JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
2257   JVMWrapper("JVM_GetClassCPTypes");
2258   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2259   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2260   // types will have length zero if this is not an InstanceKlass
2261   // (length is determined by call to JVM_GetClassCPEntriesCount)
2262   if (k->is_instance_klass()) {
2263     ConstantPool* cp = InstanceKlass::cast(k)->constants();
2264     for (int index = cp->length() - 1; index >= 0; index--) {
2265       constantTag tag = cp->tag_at(index);
2266       types[index] = (tag.is_unresolved_klass()) ? JVM_CONSTANT_Class : tag.value();
2267     }
2268   }
2269 JVM_END
2270 
2271 
2272 JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
2273   JVMWrapper("JVM_GetClassCPEntriesCount");
2274   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2275   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2276   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->constants()->length();
2277 JVM_END
2278 
2279 
2280 JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
2281   JVMWrapper("JVM_GetClassFieldsCount");
2282   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2283   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2284   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->java_fields_count();
2285 JVM_END
2286 


2395   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2396   return method->size_of_parameters();
2397 JVM_END
2398 
2399 
2400 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2401   JVMWrapper("JVM_GetMethodIxMaxStack");
2402   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2403   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2404   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2405   return method->verifier_max_stack();
2406 JVM_END
2407 
2408 
2409 JVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2410   JVMWrapper("JVM_IsConstructorIx");
2411   ResourceMark rm(THREAD);
2412   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2413   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2414   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2415   return method->name() == vmSymbols::object_initializer_name();
2416 JVM_END
2417 
2418 
2419 JVM_QUICK_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2420   JVMWrapper("JVM_IsVMGeneratedMethodIx");
2421   ResourceMark rm(THREAD);
2422   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2423   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2424   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2425   return method->is_overpass();
2426 JVM_END
2427 
2428 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2429   JVMWrapper("JVM_GetMethodIxIxUTF");
2430   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2431   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2432   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2433   return method->name()->as_utf8();
2434 JVM_END
2435 


3433   //   protection_domain. The protection_domain is passed as NULL by the java code
3434   //   if there is no security manager in 3-arg Class.forName().
3435   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3436 
3437   // Check if we should initialize the class
3438   if (init && klass->is_instance_klass()) {
3439     klass->initialize(CHECK_NULL);
3440   }
3441   return (jclass) JNIHandles::make_local(env, klass->java_mirror());
3442 }
3443 
3444 
3445 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3446 
3447 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3448   JVMWrapper("JVM_InvokeMethod");
3449   Handle method_handle;
3450   if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3451     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3452     Handle receiver(THREAD, JNIHandles::resolve(obj));
3453     objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3454     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3455     jobject res = JNIHandles::make_local(env, result);
3456     if (JvmtiExport::should_post_vm_object_alloc()) {
3457       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3458       assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
3459       if (java_lang_Class::is_primitive(ret_type)) {
3460         // Only for primitive type vm allocates memory for java object.
3461         // See box() method.
3462         JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
3463       }
3464     }
3465     return res;
3466   } else {
3467     THROW_0(vmSymbols::java_lang_StackOverflowError());
3468   }
3469 JVM_END
3470 
3471 
3472 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3473   JVMWrapper("JVM_NewInstanceFromConstructor");

3474   oop constructor_mirror = JNIHandles::resolve(c);
3475   objArrayHandle args(THREAD, objArrayOop(JNIHandles::resolve(args0)));
3476   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3477   jobject res = JNIHandles::make_local(env, result);
3478   if (JvmtiExport::should_post_vm_object_alloc()) {
3479     JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
3480   }
3481   return res;
3482 JVM_END
3483 
3484 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3485 
3486 JVM_LEAF(jboolean, JVM_SupportsCX8())
3487   JVMWrapper("JVM_SupportsCX8");
3488   return VM_Version::supports_cx8();
3489 JVM_END
3490 
3491 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3492   JVMWrapper("JVM_InitializeFromArchive");
3493   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3494   assert(k->is_klass(), "just checking");
3495   HeapShared::initialize_from_archived_subgraph(k);




  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "gc/shared/collectedHeap.inline.hpp"
  40 #include "interpreter/bytecode.hpp"
  41 #include "jfr/jfrEvents.hpp"
  42 #include "logging/log.hpp"
  43 #include "memory/heapShared.hpp"
  44 #include "memory/oopFactory.hpp"
  45 #include "memory/referenceType.hpp"
  46 #include "memory/resourceArea.hpp"
  47 #include "memory/universe.hpp"
  48 #include "oops/access.inline.hpp"
  49 #include "oops/constantPool.hpp"
  50 #include "oops/fieldStreams.hpp"
  51 #include "oops/instanceKlass.hpp"
  52 #include "oops/method.hpp"
  53 #include "oops/objArrayKlass.hpp"
  54 #include "oops/objArrayOop.inline.hpp"
  55 #include "oops/oop.inline.hpp"
  56 #include "oops/valueArrayKlass.hpp"
  57 #include "prims/jvm_misc.hpp"
  58 #include "prims/jvmtiExport.hpp"
  59 #include "prims/jvmtiThreadState.hpp"
  60 #include "prims/nativeLookup.hpp"
  61 #include "prims/stackwalk.hpp"
  62 #include "runtime/arguments.hpp"
  63 #include "runtime/atomic.hpp"
  64 #include "runtime/handles.inline.hpp"
  65 #include "runtime/init.hpp"
  66 #include "runtime/interfaceSupport.inline.hpp"
  67 #include "runtime/deoptimization.hpp"
  68 #include "runtime/handshake.hpp"
  69 #include "runtime/java.hpp"
  70 #include "runtime/javaCalls.hpp"
  71 #include "runtime/jfieldIDWorkaround.hpp"
  72 #include "runtime/jniHandles.inline.hpp"
  73 #include "runtime/orderAccess.hpp"
  74 #include "runtime/os.inline.hpp"
  75 #include "runtime/perfData.hpp"
  76 #include "runtime/reflection.hpp"


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


 747       if (!m->caller_sensitive()) {
 748         THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), err_msg("CallerSensitive annotation expected at frame %d", n));
 749       }
 750       break;
 751     default:
 752       if (!m->is_ignored_by_security_stack_walk()) {
 753         // We have reached the desired frame; return the holder class.
 754         return (jclass) JNIHandles::make_local(env, m->method_holder()->java_mirror());
 755       }
 756       break;
 757     }
 758   }
 759   return NULL;
 760 JVM_END
 761 
 762 
 763 JVM_ENTRY(jclass, JVM_FindPrimitiveClass(JNIEnv* env, const char* utf))
 764   JVMWrapper("JVM_FindPrimitiveClass");
 765   oop mirror = NULL;
 766   BasicType t = name2type(utf);
 767   if (t != T_ILLEGAL && t != T_OBJECT && t != T_ARRAY && t != T_VALUETYPE) {
 768     mirror = Universe::java_mirror(t);
 769   }
 770   if (mirror == NULL) {
 771     THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), (char*) utf);
 772   } else {
 773     return (jclass) JNIHandles::make_local(env, mirror);
 774   }
 775 JVM_END
 776 
 777 
 778 // Returns a class loaded by the bootstrap class loader; or null
 779 // if not found.  ClassNotFoundException is not thrown.
 780 // FindClassFromBootLoader is exported to the launcher for windows.
 781 JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env,
 782                                               const char* name))
 783   JVMWrapper("JVM_FindClassFromBootLoader");
 784 
 785   // Java libraries should ensure that name is never null...
 786   if (name == NULL || (int)strlen(name) > Symbol::max_length()) {
 787     // It's impossible to create this class;  the name cannot fit


1646 
1647   objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
1648   objArrayHandle result (THREAD, r);
1649 
1650   int out_idx = 0;
1651   fieldDescriptor fd;
1652   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
1653     if (!publicOnly || fs.access_flags().is_public()) {
1654       fd.reinitialize(k, fs.index());
1655       oop field = Reflection::new_field(&fd, CHECK_NULL);
1656       result->obj_at_put(out_idx, field);
1657       ++out_idx;
1658     }
1659   }
1660   assert(out_idx == num_fields, "just checking");
1661   return (jobjectArray) JNIHandles::make_local(env, result());
1662 }
1663 JVM_END
1664 
1665 static bool select_method(const methodHandle& method, bool want_constructor) {
1666   bool is_ctor = (method->is_object_constructor() ||
1667                   method->is_static_init_factory());
1668   if (want_constructor) {
1669     return is_ctor;
1670   } else {
1671     return (!is_ctor &&
1672             !method->is_class_initializer() &&
1673             !method->is_overpass());
1674   }
1675 }
1676 
1677 static jobjectArray get_class_declared_methods_helper(
1678                                   JNIEnv *env,
1679                                   jclass ofClass, jboolean publicOnly,
1680                                   bool want_constructor,
1681                                   Klass* klass, TRAPS) {
1682 
1683   JvmtiVMObjectAllocEventCollector oam;
1684 
1685   // Exclude primitive types and array types
1686   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1687       || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) {
1688     // Return empty array
1689     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);
1690     return (jobjectArray) JNIHandles::make_local(env, res);
1691   }
1692 
1693   InstanceKlass* k = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));


1715     }
1716   }
1717 
1718   // Allocate result
1719   objArrayOop r = oopFactory::new_objArray(klass, num_methods, CHECK_NULL);
1720   objArrayHandle result (THREAD, r);
1721 
1722   // Now just put the methods that we selected above, but go by their idnum
1723   // in case of redefinition.  The methods can be redefined at any safepoint,
1724   // so above when allocating the oop array and below when creating reflect
1725   // objects.
1726   for (int i = 0; i < num_methods; i++) {
1727     methodHandle method(THREAD, k->method_with_idnum(idnums->at(i)));
1728     if (method.is_null()) {
1729       // Method may have been deleted and seems this API can handle null
1730       // Otherwise should probably put a method that throws NSME
1731       result->obj_at_put(i, NULL);
1732     } else {
1733       oop m;
1734       if (want_constructor) {
1735         assert(method->is_object_constructor() ||
1736                method->is_static_init_factory(), "must be");
1737         m = Reflection::new_constructor(method, CHECK_NULL);
1738       } else {
1739         m = Reflection::new_method(method, false, CHECK_NULL);
1740       }
1741       result->obj_at_put(i, m);
1742     }
1743   }
1744 
1745   return (jobjectArray) JNIHandles::make_local(env, result());
1746 }
1747 
1748 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredMethods(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1749 {
1750   JVMWrapper("JVM_GetClassDeclaredMethods");
1751   return get_class_declared_methods_helper(env, ofClass, publicOnly,
1752                                            /*want_constructor*/ false,
1753                                            SystemDictionary::reflect_Method_klass(), THREAD);
1754 }
1755 JVM_END
1756 


1933   constantTag tag = cp->tag_at(index);
1934   if (!tag.is_method() && !tag.is_interface_method()) {
1935     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1936   }
1937   int klass_ref  = cp->uncached_klass_ref_index_at(index);
1938   Klass* k_o;
1939   if (force_resolution) {
1940     k_o = cp->klass_at(klass_ref, CHECK_NULL);
1941   } else {
1942     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
1943     if (k_o == NULL) return NULL;
1944   }
1945   InstanceKlass* k = InstanceKlass::cast(k_o);
1946   Symbol* name = cp->uncached_name_ref_at(index);
1947   Symbol* sig  = cp->uncached_signature_ref_at(index);
1948   methodHandle m (THREAD, k->find_method(name, sig));
1949   if (m.is_null()) {
1950     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
1951   }
1952   oop method;
1953   if (m->is_object_constructor()) {


1954     method = Reflection::new_constructor(m, CHECK_NULL);
1955   } else {
1956     method = Reflection::new_method(m, true, CHECK_NULL);
1957   }
1958   return JNIHandles::make_local(method);
1959 }
1960 
1961 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAt(JNIEnv *env, jobject obj, jobject unused, jint index))
1962 {
1963   JVMWrapper("JVM_ConstantPoolGetMethodAt");
1964   JvmtiVMObjectAllocEventCollector oam;
1965   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1966   bounds_check(cp, index, CHECK_NULL);
1967   jobject res = get_method_at_helper(cp, index, true, CHECK_NULL);
1968   return res;
1969 }
1970 JVM_END
1971 
1972 JVM_ENTRY(jobject, JVM_ConstantPoolGetMethodAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
1973 {
1974   JVMWrapper("JVM_ConstantPoolGetMethodAtIfLoaded");
1975   JvmtiVMObjectAllocEventCollector oam;
1976   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));


2224   assert(k->is_instance_klass(), "must be an instance klass");
2225   if (!k->is_instance_klass()) return false;
2226 
2227   ResourceMark rm(THREAD);
2228   const char* name = k->name()->as_C_string();
2229   bool system_class = k->class_loader() == NULL;
2230   return JavaAssertions::enabled(name, system_class);
2231 
2232 JVM_END
2233 
2234 
2235 // Return a new AssertionStatusDirectives object with the fields filled in with
2236 // command-line assertion arguments (i.e., -ea, -da).
2237 JVM_ENTRY(jobject, JVM_AssertionStatusDirectives(JNIEnv *env, jclass unused))
2238   JVMWrapper("JVM_AssertionStatusDirectives");
2239   JvmtiVMObjectAllocEventCollector oam;
2240   oop asd = JavaAssertions::createAssertionStatusDirectives(CHECK_NULL);
2241   return JNIHandles::make_local(env, asd);
2242 JVM_END
2243 
2244 // Arrays support /////////////////////////////////////////////////////////////
2245 
2246 JVM_ENTRY(jboolean, JVM_ArrayIsAccessAtomic(JNIEnv *env, jclass unused, jobject array))
2247   JVMWrapper("JVM_ArrayIsAccessAtomic");
2248   oop o = JNIHandles::resolve(array);
2249   Klass* k = o->klass();
2250   if ((o == NULL) || (!k->is_array_klass())) {
2251     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
2252   }
2253   if (k->is_valueArray_klass()) {
2254     return ValueArrayKlass::cast(k)->is_atomic();
2255   }
2256   return true;
2257 JVM_END
2258 
2259 JVM_ENTRY(jobject, JVM_ArrayEnsureAccessAtomic(JNIEnv *env, jclass unused, jobject array))
2260   JVMWrapper("JVM_ArrayEnsureAccessAtomic");
2261   oop o = JNIHandles::resolve(array);
2262   Klass* k = o->klass();
2263   if ((o == NULL) || (!k->is_array_klass())) {
2264     THROW_0(vmSymbols::java_lang_IllegalArgumentException());
2265   }
2266   if (k->is_valueArray_klass()) {
2267     ValueArrayKlass* vk = ValueArrayKlass::cast(k);
2268     if (!vk->is_atomic()) {
2269       /**
2270        * Need to decide how to implement:
2271        *
2272        * 1) Change to objArrayOop layout, therefore oop->klass() differs so
2273        * then "<atomic>[Qfoo;" klass needs to subclass "[Qfoo;" to pass through
2274        * "checkcast" & "instanceof"
2275        *
2276        * 2) Use extra header in the valueArrayOop to flag atomicity required and
2277        * possibly per instance lock structure. Said info, could be placed in
2278        * "trailer" rather than disturb the current arrayOop
2279        */
2280       Unimplemented();
2281     }
2282   }
2283   return array;
2284 JVM_END
2285 
2286 // Verification ////////////////////////////////////////////////////////////////////////////////
2287 
2288 // Reflection for the verifier /////////////////////////////////////////////////////////////////
2289 
2290 // RedefineClasses support: bug 6214132 caused verification to fail.
2291 // All functions from this section should call the jvmtiThreadSate function:
2292 //   Klass* class_to_verify_considering_redefinition(Klass* klass).
2293 // The function returns a Klass* of the _scratch_class if the verifier
2294 // was invoked in the middle of the class redefinition.
2295 // Otherwise it returns its argument value which is the _the_class Klass*.
2296 // Please, refer to the description in the jvmtiThreadSate.hpp.
2297 
2298 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2299   JVMWrapper("JVM_GetClassNameUTF");
2300   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2301   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2302   return k->name()->as_utf8();
2303 JVM_END
2304 
2305 
2306 JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
2307   JVMWrapper("JVM_GetClassCPTypes");
2308   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2309   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2310   // types will have length zero if this is not an InstanceKlass
2311   // (length is determined by call to JVM_GetClassCPEntriesCount)
2312   if (k->is_instance_klass()) {
2313     ConstantPool* cp = InstanceKlass::cast(k)->constants();
2314     for (int index = cp->length() - 1; index >= 0; index--) {
2315       constantTag tag = cp->tag_at(index);
2316       types[index] = tag.is_unresolved_klass() ? JVM_CONSTANT_Class : tag.value();
2317     }
2318   }
2319 JVM_END
2320 
2321 
2322 JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
2323   JVMWrapper("JVM_GetClassCPEntriesCount");
2324   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2325   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2326   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->constants()->length();
2327 JVM_END
2328 
2329 
2330 JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
2331   JVMWrapper("JVM_GetClassFieldsCount");
2332   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2333   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2334   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->java_fields_count();
2335 JVM_END
2336 


2445   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2446   return method->size_of_parameters();
2447 JVM_END
2448 
2449 
2450 JVM_QUICK_ENTRY(jint, JVM_GetMethodIxMaxStack(JNIEnv *env, jclass cls, int method_index))
2451   JVMWrapper("JVM_GetMethodIxMaxStack");
2452   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2453   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2454   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2455   return method->verifier_max_stack();
2456 JVM_END
2457 
2458 
2459 JVM_QUICK_ENTRY(jboolean, JVM_IsConstructorIx(JNIEnv *env, jclass cls, int method_index))
2460   JVMWrapper("JVM_IsConstructorIx");
2461   ResourceMark rm(THREAD);
2462   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2463   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2464   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2465   return method->is_object_constructor();
2466 JVM_END
2467 
2468 
2469 JVM_QUICK_ENTRY(jboolean, JVM_IsVMGeneratedMethodIx(JNIEnv *env, jclass cls, int method_index))
2470   JVMWrapper("JVM_IsVMGeneratedMethodIx");
2471   ResourceMark rm(THREAD);
2472   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2473   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2474   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2475   return method->is_overpass();
2476 JVM_END
2477 
2478 JVM_ENTRY(const char*, JVM_GetMethodIxNameUTF(JNIEnv *env, jclass cls, jint method_index))
2479   JVMWrapper("JVM_GetMethodIxIxUTF");
2480   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2481   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2482   Method* method = InstanceKlass::cast(k)->methods()->at(method_index);
2483   return method->name()->as_utf8();
2484 JVM_END
2485 


3483   //   protection_domain. The protection_domain is passed as NULL by the java code
3484   //   if there is no security manager in 3-arg Class.forName().
3485   Klass* klass = SystemDictionary::resolve_or_fail(name, loader, protection_domain, throwError != 0, CHECK_NULL);
3486 
3487   // Check if we should initialize the class
3488   if (init && klass->is_instance_klass()) {
3489     klass->initialize(CHECK_NULL);
3490   }
3491   return (jclass) JNIHandles::make_local(env, klass->java_mirror());
3492 }
3493 
3494 
3495 // Method ///////////////////////////////////////////////////////////////////////////////////////////
3496 
3497 JVM_ENTRY(jobject, JVM_InvokeMethod(JNIEnv *env, jobject method, jobject obj, jobjectArray args0))
3498   JVMWrapper("JVM_InvokeMethod");
3499   Handle method_handle;
3500   if (thread->stack_available((address) &method_handle) >= JVMInvokeMethodSlack) {
3501     method_handle = Handle(THREAD, JNIHandles::resolve(method));
3502     Handle receiver(THREAD, JNIHandles::resolve(obj));
3503     objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3504     oop result = Reflection::invoke_method(method_handle(), receiver, args, CHECK_NULL);
3505     jobject res = JNIHandles::make_local(env, result);
3506     if (JvmtiExport::should_post_vm_object_alloc()) {
3507       oop ret_type = java_lang_reflect_Method::return_type(method_handle());
3508       assert(ret_type != NULL, "sanity check: ret_type oop must not be NULL!");
3509       if (java_lang_Class::is_primitive(ret_type)) {
3510         // Only for primitive type vm allocates memory for java object.
3511         // See box() method.
3512         JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
3513       }
3514     }
3515     return res;
3516   } else {
3517     THROW_0(vmSymbols::java_lang_StackOverflowError());
3518   }
3519 JVM_END
3520 
3521 
3522 JVM_ENTRY(jobject, JVM_NewInstanceFromConstructor(JNIEnv *env, jobject c, jobjectArray args0))
3523   JVMWrapper("JVM_NewInstanceFromConstructor");
3524   objArrayHandle args = oopFactory::ensure_objArray(JNIHandles::resolve(args0), CHECK_NULL);
3525   oop constructor_mirror = JNIHandles::resolve(c);

3526   oop result = Reflection::invoke_constructor(constructor_mirror, args, CHECK_NULL);
3527   jobject res = JNIHandles::make_local(env, result);
3528   if (JvmtiExport::should_post_vm_object_alloc()) {
3529     JvmtiExport::post_vm_object_alloc(JavaThread::current(), result);
3530   }
3531   return res;
3532 JVM_END
3533 
3534 // Atomic ///////////////////////////////////////////////////////////////////////////////////////////
3535 
3536 JVM_LEAF(jboolean, JVM_SupportsCX8())
3537   JVMWrapper("JVM_SupportsCX8");
3538   return VM_Version::supports_cx8();
3539 JVM_END
3540 
3541 JVM_ENTRY(void, JVM_InitializeFromArchive(JNIEnv* env, jclass cls))
3542   JVMWrapper("JVM_InitializeFromArchive");
3543   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(cls));
3544   assert(k->is_klass(), "just checking");
3545   HeapShared::initialize_from_archived_subgraph(k);


< prev index next >