< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page
rev 55090 : secret-sfac


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


1669   if (want_constructor) {
1670     return (method->is_initializer() && !method->is_static());
1671   } else {
1672     return  (!method->is_initializer() && !method->is_overpass());


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


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


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


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


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


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




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


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


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


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


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


< prev index next >