src/share/vm/prims/jvm.cpp

Print this page




1781   }
1782 
1783   return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD));
1784 JVM_END
1785 
1786 static void bounds_check(constantPoolHandle cp, jint index, TRAPS) {
1787   if (!cp->is_within_bounds(index)) {
1788     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
1789   }
1790 }
1791 
1792 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method))
1793 {
1794   JVMWrapper("JVM_GetMethodParameters");
1795   // method is a handle to a java.lang.reflect.Method object
1796   Method* method_ptr = jvm_get_method_common(method);
1797   methodHandle mh (THREAD, method_ptr);
1798   Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method));
1799   const int num_params = mh->method_parameters_length();
1800 
1801   if (0 != num_params) {










1802     // make sure all the symbols are properly formatted
1803     for (int i = 0; i < num_params; i++) {
1804       MethodParametersElement* params = mh->method_parameters_start();
1805       int index = params[i].name_cp_index;
1806       bounds_check(mh->constants(), index, CHECK_NULL);
1807 
1808       if (0 != index && !mh->constants()->tag_at(index).is_utf8()) {
1809         THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1810                     "Wrong type at constant pool index");
1811       }
1812 
1813     }
1814 
1815     objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL);
1816     objArrayHandle result (THREAD, result_oop);
1817 
1818     for (int i = 0; i < num_params; i++) {
1819       MethodParametersElement* params = mh->method_parameters_start();
1820       // For a 0 index, give a NULL symbol
1821       Symbol* sym = 0 != params[i].name_cp_index ?
1822         mh->constants()->symbol_at(params[i].name_cp_index) : NULL;
1823       int flags = params[i].flags;
1824       oop param = Reflection::new_parameter(reflected_method, i, sym,
1825                                             flags, CHECK_NULL);
1826       result->obj_at_put(i, param);
1827     }
1828     return (jobjectArray)JNIHandles::make_local(env, result());
1829   } else {
1830     return (jobjectArray)NULL;
1831   }
1832 }
1833 JVM_END
1834 
1835 // New (JDK 1.4) reflection implementation /////////////////////////////////////
1836 
1837 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1838 {
1839   JVMWrapper("JVM_GetClassDeclaredFields");
1840   JvmtiVMObjectAllocEventCollector oam;
1841 
1842   // Exclude primitive types and array types
1843   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
1844       java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) {
1845     // Return empty array
1846     oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL);
1847     return (jobjectArray) JNIHandles::make_local(env, res);
1848   }
1849 
1850   instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));




1781   }
1782 
1783   return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD));
1784 JVM_END
1785 
1786 static void bounds_check(constantPoolHandle cp, jint index, TRAPS) {
1787   if (!cp->is_within_bounds(index)) {
1788     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
1789   }
1790 }
1791 
1792 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method))
1793 {
1794   JVMWrapper("JVM_GetMethodParameters");
1795   // method is a handle to a java.lang.reflect.Method object
1796   Method* method_ptr = jvm_get_method_common(method);
1797   methodHandle mh (THREAD, method_ptr);
1798   Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method));
1799   const int num_params = mh->method_parameters_length();
1800 
1801   if (num_params < 0) {
1802     // A -1 return value from method_parameters_length means there is no
1803     // parameter data.  Return null to indicate this to the reflection
1804     // API.
1805     assert(num_params == -1);
1806     return (jobjectArray)NULL;
1807   } else {
1808     // Otherwise, we return something up to reflection, even if it is
1809     // a zero-length array.  Why?  Because in some cases this can
1810     // trigger a MalformedParametersException.
1811 
1812     // make sure all the symbols are properly formatted
1813     for (int i = 0; i < num_params; i++) {
1814       MethodParametersElement* params = mh->method_parameters_start();
1815       int index = params[i].name_cp_index;
1816       bounds_check(mh->constants(), index, CHECK_NULL);
1817 
1818       if (0 != index && !mh->constants()->tag_at(index).is_utf8()) {
1819         THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1820                     "Wrong type at constant pool index");
1821       }
1822 
1823     }
1824 
1825     objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL);
1826     objArrayHandle result (THREAD, result_oop);
1827 
1828     for (int i = 0; i < num_params; i++) {
1829       MethodParametersElement* params = mh->method_parameters_start();
1830       // For a 0 index, give a NULL symbol
1831       Symbol* sym = 0 != params[i].name_cp_index ?
1832         mh->constants()->symbol_at(params[i].name_cp_index) : NULL;
1833       int flags = params[i].flags;
1834       oop param = Reflection::new_parameter(reflected_method, i, sym,
1835                                             flags, CHECK_NULL);
1836       result->obj_at_put(i, param);
1837     }
1838     return (jobjectArray)JNIHandles::make_local(env, result());


1839   }
1840 }
1841 JVM_END
1842 
1843 // New (JDK 1.4) reflection implementation /////////////////////////////////////
1844 
1845 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1846 {
1847   JVMWrapper("JVM_GetClassDeclaredFields");
1848   JvmtiVMObjectAllocEventCollector oam;
1849 
1850   // Exclude primitive types and array types
1851   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass)) ||
1852       java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->oop_is_array()) {
1853     // Return empty array
1854     oop res = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), 0, CHECK_NULL);
1855     return (jobjectArray) JNIHandles::make_local(env, res);
1856   }
1857 
1858   instanceKlassHandle k(THREAD, java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass)));