< prev index next >

src/share/vm/prims/jvm.cpp

Print this page




1669     typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL);
1670     return (jbyteArray) JNIHandles::make_local(env, a);
1671   }
1672 
1673   return NULL;
1674 JVM_END
1675 
1676 JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field))
1677   assert (field != NULL, "illegal field");
1678   JVMWrapper("JVM_GetFieldTypeAnnotations");
1679 
1680   fieldDescriptor fd;
1681   bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL);
1682   if (!gotFd) {
1683     return NULL;
1684   }
1685 
1686   return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD));
1687 JVM_END
1688 
1689 static void bounds_check(constantPoolHandle cp, jint index, TRAPS) {
1690   if (!cp->is_within_bounds(index)) {
1691     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
1692   }
1693 }
1694 
1695 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method))
1696 {
1697   JVMWrapper("JVM_GetMethodParameters");
1698   // method is a handle to a java.lang.reflect.Method object
1699   Method* method_ptr = jvm_get_method_common(method);
1700   methodHandle mh (THREAD, method_ptr);
1701   Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method));
1702   const int num_params = mh->method_parameters_length();
1703 
1704   if (num_params < 0) {
1705     // A -1 return value from method_parameters_length means there is no
1706     // parameter data.  Return null to indicate this to the reflection
1707     // API.
1708     assert(num_params == -1, "num_params should be -1 if it is less than zero");
1709     return (jobjectArray)NULL;


1777   }
1778 
1779   objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
1780   objArrayHandle result (THREAD, r);
1781 
1782   int out_idx = 0;
1783   fieldDescriptor fd;
1784   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
1785     if (!publicOnly || fs.access_flags().is_public()) {
1786       fd.reinitialize(k, fs.index());
1787       oop field = Reflection::new_field(&fd, CHECK_NULL);
1788       result->obj_at_put(out_idx, field);
1789       ++out_idx;
1790     }
1791   }
1792   assert(out_idx == num_fields, "just checking");
1793   return (jobjectArray) JNIHandles::make_local(env, result());
1794 }
1795 JVM_END
1796 
1797 static bool select_method(methodHandle method, bool want_constructor) {
1798   if (want_constructor) {
1799     return (method->is_initializer() && !method->is_static());
1800   } else {
1801     return  (!method->is_initializer() && !method->is_overpass());
1802   }
1803 }
1804 
1805 static jobjectArray get_class_declared_methods_helper(
1806                                   JNIEnv *env,
1807                                   jclass ofClass, jboolean publicOnly,
1808                                   bool want_constructor,
1809                                   Klass* klass, TRAPS) {
1810 
1811   JvmtiVMObjectAllocEventCollector oam;
1812 
1813   // Exclude primitive types and array types
1814   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1815       || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) {
1816     // Return empty array
1817     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);


1946   Klass* k = cp->klass_at(index, CHECK_NULL);
1947   return (jclass) JNIHandles::make_local(k->java_mirror());
1948 }
1949 JVM_END
1950 
1951 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
1952 {
1953   JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded");
1954   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1955   bounds_check(cp, index, CHECK_NULL);
1956   constantTag tag = cp->tag_at(index);
1957   if (!tag.is_klass() && !tag.is_unresolved_klass()) {
1958     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1959   }
1960   Klass* k = ConstantPool::klass_at_if_loaded(cp, index);
1961   if (k == NULL) return NULL;
1962   return (jclass) JNIHandles::make_local(k->java_mirror());
1963 }
1964 JVM_END
1965 
1966 static jobject get_method_at_helper(constantPoolHandle cp, jint index, bool force_resolution, TRAPS) {
1967   constantTag tag = cp->tag_at(index);
1968   if (!tag.is_method() && !tag.is_interface_method()) {
1969     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1970   }
1971   int klass_ref  = cp->uncached_klass_ref_index_at(index);
1972   Klass* k_o;
1973   if (force_resolution) {
1974     k_o = cp->klass_at(klass_ref, CHECK_NULL);
1975   } else {
1976     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
1977     if (k_o == NULL) return NULL;
1978   }
1979   InstanceKlass* k = InstanceKlass::cast(k_o);
1980   Symbol* name = cp->uncached_name_ref_at(index);
1981   Symbol* sig  = cp->uncached_signature_ref_at(index);
1982   methodHandle m (THREAD, k->find_method(name, sig));
1983   if (m.is_null()) {
1984     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
1985   }
1986   oop method;




1669     typeArrayOop a = Annotations::make_java_array(type_annotations, CHECK_NULL);
1670     return (jbyteArray) JNIHandles::make_local(env, a);
1671   }
1672 
1673   return NULL;
1674 JVM_END
1675 
1676 JVM_ENTRY(jbyteArray, JVM_GetFieldTypeAnnotations(JNIEnv *env, jobject field))
1677   assert (field != NULL, "illegal field");
1678   JVMWrapper("JVM_GetFieldTypeAnnotations");
1679 
1680   fieldDescriptor fd;
1681   bool gotFd = jvm_get_field_common(field, fd, CHECK_NULL);
1682   if (!gotFd) {
1683     return NULL;
1684   }
1685 
1686   return (jbyteArray) JNIHandles::make_local(env, Annotations::make_java_array(fd.type_annotations(), THREAD));
1687 JVM_END
1688 
1689 static void bounds_check(const constantPoolHandle& cp, jint index, TRAPS) {
1690   if (!cp->is_within_bounds(index)) {
1691     THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool index out of bounds");
1692   }
1693 }
1694 
1695 JVM_ENTRY(jobjectArray, JVM_GetMethodParameters(JNIEnv *env, jobject method))
1696 {
1697   JVMWrapper("JVM_GetMethodParameters");
1698   // method is a handle to a java.lang.reflect.Method object
1699   Method* method_ptr = jvm_get_method_common(method);
1700   methodHandle mh (THREAD, method_ptr);
1701   Handle reflected_method (THREAD, JNIHandles::resolve_non_null(method));
1702   const int num_params = mh->method_parameters_length();
1703 
1704   if (num_params < 0) {
1705     // A -1 return value from method_parameters_length means there is no
1706     // parameter data.  Return null to indicate this to the reflection
1707     // API.
1708     assert(num_params == -1, "num_params should be -1 if it is less than zero");
1709     return (jobjectArray)NULL;


1777   }
1778 
1779   objArrayOop r = oopFactory::new_objArray(SystemDictionary::reflect_Field_klass(), num_fields, CHECK_NULL);
1780   objArrayHandle result (THREAD, r);
1781 
1782   int out_idx = 0;
1783   fieldDescriptor fd;
1784   for (JavaFieldStream fs(k); !fs.done(); fs.next()) {
1785     if (!publicOnly || fs.access_flags().is_public()) {
1786       fd.reinitialize(k, fs.index());
1787       oop field = Reflection::new_field(&fd, CHECK_NULL);
1788       result->obj_at_put(out_idx, field);
1789       ++out_idx;
1790     }
1791   }
1792   assert(out_idx == num_fields, "just checking");
1793   return (jobjectArray) JNIHandles::make_local(env, result());
1794 }
1795 JVM_END
1796 
1797 static bool select_method(const methodHandle& method, bool want_constructor) {
1798   if (want_constructor) {
1799     return (method->is_initializer() && !method->is_static());
1800   } else {
1801     return  (!method->is_initializer() && !method->is_overpass());
1802   }
1803 }
1804 
1805 static jobjectArray get_class_declared_methods_helper(
1806                                   JNIEnv *env,
1807                                   jclass ofClass, jboolean publicOnly,
1808                                   bool want_constructor,
1809                                   Klass* klass, TRAPS) {
1810 
1811   JvmtiVMObjectAllocEventCollector oam;
1812 
1813   // Exclude primitive types and array types
1814   if (java_lang_Class::is_primitive(JNIHandles::resolve_non_null(ofClass))
1815       || java_lang_Class::as_Klass(JNIHandles::resolve_non_null(ofClass))->is_array_klass()) {
1816     // Return empty array
1817     oop res = oopFactory::new_objArray(klass, 0, CHECK_NULL);


1946   Klass* k = cp->klass_at(index, CHECK_NULL);
1947   return (jclass) JNIHandles::make_local(k->java_mirror());
1948 }
1949 JVM_END
1950 
1951 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
1952 {
1953   JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded");
1954   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1955   bounds_check(cp, index, CHECK_NULL);
1956   constantTag tag = cp->tag_at(index);
1957   if (!tag.is_klass() && !tag.is_unresolved_klass()) {
1958     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1959   }
1960   Klass* k = ConstantPool::klass_at_if_loaded(cp, index);
1961   if (k == NULL) return NULL;
1962   return (jclass) JNIHandles::make_local(k->java_mirror());
1963 }
1964 JVM_END
1965 
1966 static jobject get_method_at_helper(const constantPoolHandle& cp, jint index, bool force_resolution, TRAPS) {
1967   constantTag tag = cp->tag_at(index);
1968   if (!tag.is_method() && !tag.is_interface_method()) {
1969     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1970   }
1971   int klass_ref  = cp->uncached_klass_ref_index_at(index);
1972   Klass* k_o;
1973   if (force_resolution) {
1974     k_o = cp->klass_at(klass_ref, CHECK_NULL);
1975   } else {
1976     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
1977     if (k_o == NULL) return NULL;
1978   }
1979   InstanceKlass* k = InstanceKlass::cast(k_o);
1980   Symbol* name = cp->uncached_name_ref_at(index);
1981   Symbol* sig  = cp->uncached_signature_ref_at(index);
1982   methodHandle m (THREAD, k->find_method(name, sig));
1983   if (m.is_null()) {
1984     THROW_MSG_0(vmSymbols::java_lang_RuntimeException(), "Unable to look up method in target class");
1985   }
1986   oop method;


< prev index next >