Mercurial > hg > truffle
diff src/share/vm/prims/jvm.cpp @ 7462:ade95d680b42
8004728: Add hotspot support for parameter reflection
Summary: Add hotspot support for parameter reflection
Reviewed-by: acorn, jrose, coleenp
Contributed-by: eric.mccorkle@oracle.com
author | coleenp |
---|---|
date | Tue, 08 Jan 2013 14:01:36 -0500 |
parents | 35431a769282 |
children | 989155e2d07a f9eb431c3efe ff0a7943fd29 |
line wrap: on
line diff
--- a/src/share/vm/prims/jvm.cpp Mon Jan 07 15:32:51 2013 -0500 +++ b/src/share/vm/prims/jvm.cpp Tue Jan 08 14:01:36 2013 -0500 @@ -1515,7 +1515,7 @@ JVM_END -static Method* jvm_get_method_common(jobject method, TRAPS) { +static Method* jvm_get_method_common(jobject method) { // some of this code was adapted from from jni_FromReflectedMethod oop reflected = JNIHandles::resolve_non_null(method); @@ -1533,8 +1533,7 @@ } Klass* k = java_lang_Class::as_Klass(mirror); - KlassHandle kh(THREAD, k); - Method* m = InstanceKlass::cast(kh())->method_with_idnum(slot); + Method* m = InstanceKlass::cast(k)->method_with_idnum(slot); if (m == NULL) { assert(false, "cannot find method"); return NULL; // robustness @@ -1548,7 +1547,7 @@ JVMWrapper("JVM_GetMethodAnnotations"); // method is a handle to a java.lang.reflect.Method object - Method* m = jvm_get_method_common(method, CHECK_NULL); + Method* m = jvm_get_method_common(method); return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(m->annotations(), THREAD)); JVM_END @@ -1558,7 +1557,7 @@ JVMWrapper("JVM_GetMethodDefaultAnnotationValue"); // method is a handle to a java.lang.reflect.Method object - Method* m = jvm_get_method_common(method, CHECK_NULL); + Method* m = jvm_get_method_common(method); return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(m->annotation_default(), THREAD)); JVM_END @@ -1568,7 +1567,7 @@ JVMWrapper("JVM_GetMethodParameterAnnotations"); // method is a handle to a java.lang.reflect.Method object - Method* m = jvm_get_method_common(method, CHECK_NULL); + Method* m = jvm_get_method_common(method); return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(m->parameter_annotations(), THREAD)); JVM_END @@ -1590,6 +1589,32 @@ return NULL; JVM_END +JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method)) +{ + JVMWrapper("JVM_GetMethodParameters"); + // method is a handle to a java.lang.reflect.Method object + Method* method_ptr = jvm_get_method_common(method); + methodHandle mh (THREAD, method_ptr); + Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method)); + const int num_params = mh->method_parameters_length(); + + if(0 != num_params) { + objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL); + objArrayHandle result (THREAD, result_oop); + + for(int i = 0; i < num_params; i++) { + MethodParametersElement* params = mh->method_parameters_start(); + Symbol* const sym = mh->constants()->symbol_at(params[i].name_cp_index); + oop param = Reflection::new_parameter(reflected_method, i, sym, + params[i].flags, CHECK_NULL); + result->obj_at_put(i, param); + } + return (jobjectArray)JNIHandles::make_local(env, result()); + } else { + return (jobjectArray)NULL; + } +} +JVM_END // New (JDK 1.4) reflection implementation /////////////////////////////////////