< prev index next >

src/hotspot/share/prims/jvm.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


1899   return NULL;
1900 }
1901 JVM_END
1902 
1903 
1904 JVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject obj, jobject unused))
1905 {
1906   JVMWrapper("JVM_ConstantPoolGetSize");
1907   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1908   return cp->length();
1909 }
1910 JVM_END
1911 
1912 
1913 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index))
1914 {
1915   JVMWrapper("JVM_ConstantPoolGetClassAt");
1916   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1917   bounds_check(cp, index, CHECK_NULL);
1918   constantTag tag = cp->tag_at(index);
1919   if (!tag.is_klass() && !tag.is_unresolved_klass() &&
1920       !tag.is_value_type() && !tag.is_unresolved_value_type()) {
1921     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1922   }
1923   Klass* k = cp->klass_at(index, CHECK_NULL);
1924   return (jclass) JNIHandles::make_local(k->java_mirror());
1925 }
1926 JVM_END
1927 
1928 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
1929 {
1930   JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded");
1931   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1932   bounds_check(cp, index, CHECK_NULL);
1933   constantTag tag = cp->tag_at(index);
1934   if (!tag.is_klass() && !tag.is_unresolved_klass() &&
1935       !tag.is_value_type() && !tag.is_unresolved_value_type()) {
1936     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1937   }
1938   Klass* k = ConstantPool::klass_at_if_loaded(cp, index);
1939   if (k == NULL) return NULL;
1940   return (jclass) JNIHandles::make_local(k->java_mirror());
1941 }
1942 JVM_END
1943 
1944 static jobject get_method_at_helper(const constantPoolHandle& cp, jint index, bool force_resolution, TRAPS) {
1945   constantTag tag = cp->tag_at(index);
1946   if (!tag.is_method() && !tag.is_interface_method()) {
1947     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1948   }
1949   int klass_ref  = cp->uncached_klass_ref_index_at(index);
1950   Klass* k_o;
1951   if (force_resolution) {
1952     k_o = cp->klass_at(klass_ref, CHECK_NULL);
1953   } else {
1954     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
1955     if (k_o == NULL) return NULL;


2192     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2193   }
2194   Symbol* sym = cp->symbol_at(index);
2195   Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
2196   return (jstring) JNIHandles::make_local(str());
2197 }
2198 JVM_END
2199 
2200 JVM_ENTRY(jbyte, JVM_ConstantPoolGetTagAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2201 {
2202   JVMWrapper("JVM_ConstantPoolGetTagAt");
2203   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2204   bounds_check(cp, index, CHECK_0);
2205   constantTag tag = cp->tag_at(index);
2206   jbyte result = tag.value();
2207   // If returned tag values are not from the JVM spec, e.g. tags from 100 to 105,
2208   // they are changed to the corresponding tags from the JVM spec, so that java code in
2209   // sun.reflect.ConstantPool will return only tags from the JVM spec, not internal ones.
2210   if (tag.is_klass_or_reference()) {
2211       result = JVM_CONSTANT_Class;
2212   } else if (tag.is_value_type_or_reference()) {
2213       // Return Class, JVM_CONSTANT_Value not externally visible
2214       result = JVM_CONSTANT_Class;
2215   } else if (tag.is_string_index()) {
2216       result = JVM_CONSTANT_String;
2217   } else if (tag.is_method_type_in_error()) {
2218       result = JVM_CONSTANT_MethodType;
2219   } else if (tag.is_method_handle_in_error()) {
2220       result = JVM_CONSTANT_MethodHandle;
2221   } else if (tag.is_dynamic_constant_in_error()) {
2222       result = JVM_CONSTANT_Dynamic;
2223   }
2224   return result;
2225 }
2226 JVM_END
2227 
2228 // Assertion support. //////////////////////////////////////////////////////////
2229 
2230 JVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls))
2231   JVMWrapper("JVM_DesiredAssertionStatus");
2232   assert(cls != NULL, "bad class");
2233 
2234   oop r = JNIHandles::resolve(cls);


2311 // Please, refer to the description in the jvmtiThreadSate.hpp.
2312 
2313 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2314   JVMWrapper("JVM_GetClassNameUTF");
2315   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2316   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2317   return k->name()->as_utf8();
2318 JVM_END
2319 
2320 
2321 JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
2322   JVMWrapper("JVM_GetClassCPTypes");
2323   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2324   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2325   // types will have length zero if this is not an InstanceKlass
2326   // (length is determined by call to JVM_GetClassCPEntriesCount)
2327   if (k->is_instance_klass()) {
2328     ConstantPool* cp = InstanceKlass::cast(k)->constants();
2329     for (int index = cp->length() - 1; index >= 0; index--) {
2330       constantTag tag = cp->tag_at(index);
2331       // For a value type return Class, JVM_CONSTANT_Value not externally visible
2332       types[index] = (tag.is_unresolved_klass() || tag.is_unresolved_value_type()) ? JVM_CONSTANT_Class : tag.value();
2333     }
2334   }
2335 JVM_END
2336 
2337 
2338 JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
2339   JVMWrapper("JVM_GetClassCPEntriesCount");
2340   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2341   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2342   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->constants()->length();
2343 JVM_END
2344 
2345 
2346 JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
2347   JVMWrapper("JVM_GetClassFieldsCount");
2348   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2349   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2350   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->java_fields_count();
2351 JVM_END
2352 


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


1899   return NULL;
1900 }
1901 JVM_END
1902 
1903 
1904 JVM_ENTRY(jint, JVM_ConstantPoolGetSize(JNIEnv *env, jobject obj, jobject unused))
1905 {
1906   JVMWrapper("JVM_ConstantPoolGetSize");
1907   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1908   return cp->length();
1909 }
1910 JVM_END
1911 
1912 
1913 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAt(JNIEnv *env, jobject obj, jobject unused, jint index))
1914 {
1915   JVMWrapper("JVM_ConstantPoolGetClassAt");
1916   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1917   bounds_check(cp, index, CHECK_NULL);
1918   constantTag tag = cp->tag_at(index);
1919   if (!tag.is_klass() && !tag.is_unresolved_klass()) {

1920     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1921   }
1922   Klass* k = cp->klass_at(index, CHECK_NULL);
1923   return (jclass) JNIHandles::make_local(k->java_mirror());
1924 }
1925 JVM_END
1926 
1927 JVM_ENTRY(jclass, JVM_ConstantPoolGetClassAtIfLoaded(JNIEnv *env, jobject obj, jobject unused, jint index))
1928 {
1929   JVMWrapper("JVM_ConstantPoolGetClassAtIfLoaded");
1930   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
1931   bounds_check(cp, index, CHECK_NULL);
1932   constantTag tag = cp->tag_at(index);
1933   if (!tag.is_klass() && !tag.is_unresolved_klass()) {

1934     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1935   }
1936   Klass* k = ConstantPool::klass_at_if_loaded(cp, index);
1937   if (k == NULL) return NULL;
1938   return (jclass) JNIHandles::make_local(k->java_mirror());
1939 }
1940 JVM_END
1941 
1942 static jobject get_method_at_helper(const constantPoolHandle& cp, jint index, bool force_resolution, TRAPS) {
1943   constantTag tag = cp->tag_at(index);
1944   if (!tag.is_method() && !tag.is_interface_method()) {
1945     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
1946   }
1947   int klass_ref  = cp->uncached_klass_ref_index_at(index);
1948   Klass* k_o;
1949   if (force_resolution) {
1950     k_o = cp->klass_at(klass_ref, CHECK_NULL);
1951   } else {
1952     k_o = ConstantPool::klass_at_if_loaded(cp, klass_ref);
1953     if (k_o == NULL) return NULL;


2190     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Wrong type at constant pool index");
2191   }
2192   Symbol* sym = cp->symbol_at(index);
2193   Handle str = java_lang_String::create_from_symbol(sym, CHECK_NULL);
2194   return (jstring) JNIHandles::make_local(str());
2195 }
2196 JVM_END
2197 
2198 JVM_ENTRY(jbyte, JVM_ConstantPoolGetTagAt(JNIEnv *env, jobject obj, jobject unused, jint index))
2199 {
2200   JVMWrapper("JVM_ConstantPoolGetTagAt");
2201   constantPoolHandle cp = constantPoolHandle(THREAD, reflect_ConstantPool::get_cp(JNIHandles::resolve_non_null(obj)));
2202   bounds_check(cp, index, CHECK_0);
2203   constantTag tag = cp->tag_at(index);
2204   jbyte result = tag.value();
2205   // If returned tag values are not from the JVM spec, e.g. tags from 100 to 105,
2206   // they are changed to the corresponding tags from the JVM spec, so that java code in
2207   // sun.reflect.ConstantPool will return only tags from the JVM spec, not internal ones.
2208   if (tag.is_klass_or_reference()) {
2209       result = JVM_CONSTANT_Class;



2210   } else if (tag.is_string_index()) {
2211       result = JVM_CONSTANT_String;
2212   } else if (tag.is_method_type_in_error()) {
2213       result = JVM_CONSTANT_MethodType;
2214   } else if (tag.is_method_handle_in_error()) {
2215       result = JVM_CONSTANT_MethodHandle;
2216   } else if (tag.is_dynamic_constant_in_error()) {
2217       result = JVM_CONSTANT_Dynamic;
2218   }
2219   return result;
2220 }
2221 JVM_END
2222 
2223 // Assertion support. //////////////////////////////////////////////////////////
2224 
2225 JVM_ENTRY(jboolean, JVM_DesiredAssertionStatus(JNIEnv *env, jclass unused, jclass cls))
2226   JVMWrapper("JVM_DesiredAssertionStatus");
2227   assert(cls != NULL, "bad class");
2228 
2229   oop r = JNIHandles::resolve(cls);


2306 // Please, refer to the description in the jvmtiThreadSate.hpp.
2307 
2308 JVM_ENTRY(const char*, JVM_GetClassNameUTF(JNIEnv *env, jclass cls))
2309   JVMWrapper("JVM_GetClassNameUTF");
2310   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2311   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2312   return k->name()->as_utf8();
2313 JVM_END
2314 
2315 
2316 JVM_QUICK_ENTRY(void, JVM_GetClassCPTypes(JNIEnv *env, jclass cls, unsigned char *types))
2317   JVMWrapper("JVM_GetClassCPTypes");
2318   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2319   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2320   // types will have length zero if this is not an InstanceKlass
2321   // (length is determined by call to JVM_GetClassCPEntriesCount)
2322   if (k->is_instance_klass()) {
2323     ConstantPool* cp = InstanceKlass::cast(k)->constants();
2324     for (int index = cp->length() - 1; index >= 0; index--) {
2325       constantTag tag = cp->tag_at(index);
2326       types[index] = tag.is_unresolved_klass() ? JVM_CONSTANT_Class : tag.value();

2327     }
2328   }
2329 JVM_END
2330 
2331 
2332 JVM_QUICK_ENTRY(jint, JVM_GetClassCPEntriesCount(JNIEnv *env, jclass cls))
2333   JVMWrapper("JVM_GetClassCPEntriesCount");
2334   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2335   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2336   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->constants()->length();
2337 JVM_END
2338 
2339 
2340 JVM_QUICK_ENTRY(jint, JVM_GetClassFieldsCount(JNIEnv *env, jclass cls))
2341   JVMWrapper("JVM_GetClassFieldsCount");
2342   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(cls));
2343   k = JvmtiThreadState::class_to_verify_considering_redefinition(k, thread);
2344   return (!k->is_instance_klass()) ? 0 : InstanceKlass::cast(k)->java_fields_count();
2345 JVM_END
2346 


< prev index next >