comparison 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
comparison
equal deleted inserted replaced
7460:6c3f47d964f3 7462:ade95d680b42
1513 1513
1514 return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.annotations(), THREAD)); 1514 return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.annotations(), THREAD));
1515 JVM_END 1515 JVM_END
1516 1516
1517 1517
1518 static Method* jvm_get_method_common(jobject method, TRAPS) { 1518 static Method* jvm_get_method_common(jobject method) {
1519 // some of this code was adapted from from jni_FromReflectedMethod 1519 // some of this code was adapted from from jni_FromReflectedMethod
1520 1520
1521 oop reflected = JNIHandles::resolve_non_null(method); 1521 oop reflected = JNIHandles::resolve_non_null(method);
1522 oop mirror = NULL; 1522 oop mirror = NULL;
1523 int slot = 0; 1523 int slot = 0;
1531 mirror = java_lang_reflect_Method::clazz(reflected); 1531 mirror = java_lang_reflect_Method::clazz(reflected);
1532 slot = java_lang_reflect_Method::slot(reflected); 1532 slot = java_lang_reflect_Method::slot(reflected);
1533 } 1533 }
1534 Klass* k = java_lang_Class::as_Klass(mirror); 1534 Klass* k = java_lang_Class::as_Klass(mirror);
1535 1535
1536 KlassHandle kh(THREAD, k); 1536 Method* m = InstanceKlass::cast(k)->method_with_idnum(slot);
1537 Method* m = InstanceKlass::cast(kh())->method_with_idnum(slot);
1538 if (m == NULL) { 1537 if (m == NULL) {
1539 assert(false, "cannot find method"); 1538 assert(false, "cannot find method");
1540 return NULL; // robustness 1539 return NULL; // robustness
1541 } 1540 }
1542 1541
1546 1545
1547 JVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method)) 1546 JVM_ENTRY(jbyteArray, JVM_GetMethodAnnotations(JNIEnv *env, jobject method))
1548 JVMWrapper("JVM_GetMethodAnnotations"); 1547 JVMWrapper("JVM_GetMethodAnnotations");
1549 1548
1550 // method is a handle to a java.lang.reflect.Method object 1549 // method is a handle to a java.lang.reflect.Method object
1551 Method* m = jvm_get_method_common(method, CHECK_NULL); 1550 Method* m = jvm_get_method_common(method);
1552 return (jbyteArray) JNIHandles::make_local(env, 1551 return (jbyteArray) JNIHandles::make_local(env,
1553 Annotations::make_java_array(m->annotations(), THREAD)); 1552 Annotations::make_java_array(m->annotations(), THREAD));
1554 JVM_END 1553 JVM_END
1555 1554
1556 1555
1557 JVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method)) 1556 JVM_ENTRY(jbyteArray, JVM_GetMethodDefaultAnnotationValue(JNIEnv *env, jobject method))
1558 JVMWrapper("JVM_GetMethodDefaultAnnotationValue"); 1557 JVMWrapper("JVM_GetMethodDefaultAnnotationValue");
1559 1558
1560 // method is a handle to a java.lang.reflect.Method object 1559 // method is a handle to a java.lang.reflect.Method object
1561 Method* m = jvm_get_method_common(method, CHECK_NULL); 1560 Method* m = jvm_get_method_common(method);
1562 return (jbyteArray) JNIHandles::make_local(env, 1561 return (jbyteArray) JNIHandles::make_local(env,
1563 Annotations::make_java_array(m->annotation_default(), THREAD)); 1562 Annotations::make_java_array(m->annotation_default(), THREAD));
1564 JVM_END 1563 JVM_END
1565 1564
1566 1565
1567 JVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method)) 1566 JVM_ENTRY(jbyteArray, JVM_GetMethodParameterAnnotations(JNIEnv *env, jobject method))
1568 JVMWrapper("JVM_GetMethodParameterAnnotations"); 1567 JVMWrapper("JVM_GetMethodParameterAnnotations");
1569 1568
1570 // method is a handle to a java.lang.reflect.Method object 1569 // method is a handle to a java.lang.reflect.Method object
1571 Method* m = jvm_get_method_common(method, CHECK_NULL); 1570 Method* m = jvm_get_method_common(method);
1572 return (jbyteArray) JNIHandles::make_local(env, 1571 return (jbyteArray) JNIHandles::make_local(env,
1573 Annotations::make_java_array(m->parameter_annotations(), THREAD)); 1572 Annotations::make_java_array(m->parameter_annotations(), THREAD));
1574 JVM_END 1573 JVM_END
1575 1574
1576 /* Type use annotations support (JDK 1.8) */ 1575 /* Type use annotations support (JDK 1.8) */
1588 } 1587 }
1589 } 1588 }
1590 return NULL; 1589 return NULL;
1591 JVM_END 1590 JVM_END
1592 1591
1592 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method))
1593 {
1594 JVMWrapper("JVM_GetMethodParameters");
1595 // method is a handle to a java.lang.reflect.Method object
1596 Method* method_ptr = jvm_get_method_common(method);
1597 methodHandle mh (THREAD, method_ptr);
1598 Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method));
1599 const int num_params = mh->method_parameters_length();
1600
1601 if(0 != num_params) {
1602 objArrayOop result_oop = oopFactory::new_objArray(SystemDictionary::reflect_Parameter_klass(), num_params, CHECK_NULL);
1603 objArrayHandle result (THREAD, result_oop);
1604
1605 for(int i = 0; i < num_params; i++) {
1606 MethodParametersElement* params = mh->method_parameters_start();
1607 Symbol* const sym = mh->constants()->symbol_at(params[i].name_cp_index);
1608 oop param = Reflection::new_parameter(reflected_method, i, sym,
1609 params[i].flags, CHECK_NULL);
1610 result->obj_at_put(i, param);
1611 }
1612 return (jobjectArray)JNIHandles::make_local(env, result());
1613 } else {
1614 return (jobjectArray)NULL;
1615 }
1616 }
1617 JVM_END
1593 1618
1594 // New (JDK 1.4) reflection implementation ///////////////////////////////////// 1619 // New (JDK 1.4) reflection implementation /////////////////////////////////////
1595 1620
1596 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly)) 1621 JVM_ENTRY(jobjectArray, JVM_GetClassDeclaredFields(JNIEnv *env, jclass ofClass, jboolean publicOnly))
1597 { 1622 {