< prev index next >

src/hotspot/share/prims/whitebox.cpp

Print this page

  35 #include "classfile/javaClasses.inline.hpp"
  36 #include "classfile/modules.hpp"
  37 #include "classfile/protectionDomainCache.hpp"
  38 #include "classfile/stringTable.hpp"
  39 #include "classfile/symbolTable.hpp"
  40 #include "classfile/systemDictionary.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "code/codeCache.hpp"
  43 #include "compiler/compilationPolicy.hpp"
  44 #include "compiler/directivesParser.hpp"
  45 #include "compiler/methodMatcher.hpp"
  46 #include "gc/shared/concurrentGCBreakpoints.hpp"
  47 #include "gc/shared/gcConfig.hpp"
  48 #include "gc/shared/gcLocker.inline.hpp"
  49 #include "gc/shared/genArguments.hpp"
  50 #include "gc/shared/genCollectedHeap.hpp"
  51 #include "jvmtifiles/jvmtiEnv.hpp"
  52 #include "logging/log.hpp"
  53 #include "memory/iterator.hpp"
  54 #include "memory/metadataFactory.hpp"

  55 #include "memory/metaspace/testHelpers.hpp"
  56 #include "memory/metaspaceUtils.hpp"
  57 #include "memory/oopFactory.hpp"
  58 #include "memory/resourceArea.hpp"
  59 #include "memory/universe.hpp"
  60 #include "oops/array.hpp"
  61 #include "oops/compressedOops.hpp"

  62 #include "oops/constantPool.inline.hpp"
  63 #include "oops/klass.inline.hpp"
  64 #include "oops/method.inline.hpp"
  65 #include "oops/objArrayKlass.hpp"
  66 #include "oops/objArrayOop.inline.hpp"
  67 #include "oops/oop.inline.hpp"

  68 #include "oops/typeArrayOop.inline.hpp"
  69 #include "prims/jvmtiEnvBase.hpp"
  70 #include "prims/resolvedMethodTable.hpp"
  71 #include "prims/wbtestmethods/parserTests.hpp"
  72 #include "prims/whitebox.inline.hpp"
  73 #include "runtime/arguments.hpp"
  74 #include "runtime/atomic.hpp"
  75 #include "runtime/deoptimization.hpp"
  76 #include "runtime/fieldDescriptor.inline.hpp"
  77 #include "runtime/flags/jvmFlag.hpp"
  78 #include "runtime/flags/jvmFlagAccess.hpp"
  79 #include "runtime/frame.inline.hpp"
  80 #include "runtime/handles.inline.hpp"
  81 #include "runtime/handshake.hpp"
  82 #include "runtime/interfaceSupport.inline.hpp"
  83 #include "runtime/javaCalls.hpp"
  84 #include "runtime/javaThread.inline.hpp"
  85 #include "runtime/jniHandles.inline.hpp"
  86 #include "runtime/os.hpp"
  87 #include "runtime/stackFrameStream.inline.hpp"

1875 
1876 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
1877   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1878   ConstantPool* cp = ik->constants();
1879   if (cp->cache() == nullptr) {
1880     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
1881   }
1882   jint cpci = index;
1883   jint cpciTag = ConstantPool::CPCACHE_INDEX_TAG;
1884   if (cpciTag > cpci || cpci >= cp->cache()->length() + cpciTag) {
1885     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool cache index is out of range");
1886   }
1887   jint cpi = cp->remap_instruction_operand_from_cache(cpci);
1888   return cpi;
1889 WB_END
1890 
1891 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1892   return ConstantPool::encode_invokedynamic_index(index);
1893 WB_END
1894 























































































1895 WB_ENTRY(jint, WB_getIndyInfoLength(JNIEnv* env, jobject wb, jclass klass))
1896   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1897   ConstantPool* cp = ik->constants();
1898   if (cp->cache() == nullptr) {
1899       return -1;
1900   }
1901   return cp->resolved_indy_entries_length();
1902 WB_END
1903 
1904 WB_ENTRY(jint, WB_getIndyCPIndex(JNIEnv* env, jobject wb, jclass klass, jint index))
1905   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1906   ConstantPool* cp = ik->constants();
1907   if (cp->cache() == nullptr) {
1908       return -1;
1909   }
1910   return cp->resolved_indy_entry_at(index)->constant_pool_index();
1911 WB_END
1912 
1913 WB_ENTRY(jobject, WB_printClasses(JNIEnv* env, jobject wb, jstring class_name_pattern, jint flags))
1914   ThreadToNativeFromVM ttnfv(thread);

2769                                                       (void*)&WB_DefineModule },
2770   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2771                                                       (void*)&WB_AddModuleExports },
2772   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2773                                                       (void*)&WB_AddReadsModule },
2774   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2775                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2776   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2777                                                       (void*)&WB_AddModuleExportsToAll },
2778   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2779   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2780   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2781   {CC"forceClassLoaderStatsSafepoint", CC"()V",       (void*)&WB_ForceClassLoaderStatsSafepoint },
2782   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2783   {CC"getConstantPoolCacheIndexTag0", CC"()I",  (void*)&WB_GetConstantPoolCacheIndexTag},
2784   {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_GetConstantPoolCacheLength},
2785   {CC"remapInstructionOperandFromCPCache0",
2786       CC"(Ljava/lang/Class;I)I",                      (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2787   {CC"encodeConstantPoolIndyIndex0",
2788       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},






2789   {CC"getIndyInfoLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_getIndyInfoLength},
2790   {CC"getIndyCPIndex0",    CC"(Ljava/lang/Class;I)I", (void*)&WB_getIndyCPIndex},
2791   {CC"printClasses0",      CC"(Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printClasses},
2792   {CC"printMethods0",      CC"(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printMethods},
2793   {CC"getMethodBooleanOption",
2794       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2795                                                       (void*)&WB_GetMethodBooleaneOption},
2796   {CC"getMethodIntxOption",
2797       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2798                                                       (void*)&WB_GetMethodIntxOption},
2799   {CC"getMethodUintxOption",
2800       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2801                                                       (void*)&WB_GetMethodUintxOption},
2802   {CC"getMethodDoubleOption",
2803       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2804                                                       (void*)&WB_GetMethodDoubleOption},
2805   {CC"getMethodStringOption",
2806       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2807                                                       (void*)&WB_GetMethodStringOption},
2808   {CC"getDefaultArchivePath",             CC"()Ljava/lang/String;",

  35 #include "classfile/javaClasses.inline.hpp"
  36 #include "classfile/modules.hpp"
  37 #include "classfile/protectionDomainCache.hpp"
  38 #include "classfile/stringTable.hpp"
  39 #include "classfile/symbolTable.hpp"
  40 #include "classfile/systemDictionary.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "code/codeCache.hpp"
  43 #include "compiler/compilationPolicy.hpp"
  44 #include "compiler/directivesParser.hpp"
  45 #include "compiler/methodMatcher.hpp"
  46 #include "gc/shared/concurrentGCBreakpoints.hpp"
  47 #include "gc/shared/gcConfig.hpp"
  48 #include "gc/shared/gcLocker.inline.hpp"
  49 #include "gc/shared/genArguments.hpp"
  50 #include "gc/shared/genCollectedHeap.hpp"
  51 #include "jvmtifiles/jvmtiEnv.hpp"
  52 #include "logging/log.hpp"
  53 #include "memory/iterator.hpp"
  54 #include "memory/metadataFactory.hpp"
  55 #include "memory/iterator.inline.hpp"
  56 #include "memory/metaspace/testHelpers.hpp"
  57 #include "memory/metaspaceUtils.hpp"
  58 #include "memory/oopFactory.hpp"
  59 #include "memory/resourceArea.hpp"
  60 #include "memory/universe.hpp"
  61 #include "oops/array.hpp"
  62 #include "oops/compressedOops.hpp"
  63 #include "oops/compressedOops.inline.hpp"
  64 #include "oops/constantPool.inline.hpp"
  65 #include "oops/klass.inline.hpp"
  66 #include "oops/method.inline.hpp"
  67 #include "oops/objArrayKlass.hpp"
  68 #include "oops/objArrayOop.inline.hpp"
  69 #include "oops/oop.inline.hpp"
  70 #include "oops/objArrayOop.inline.hpp"
  71 #include "oops/typeArrayOop.inline.hpp"
  72 #include "prims/jvmtiEnvBase.hpp"
  73 #include "prims/resolvedMethodTable.hpp"
  74 #include "prims/wbtestmethods/parserTests.hpp"
  75 #include "prims/whitebox.inline.hpp"
  76 #include "runtime/arguments.hpp"
  77 #include "runtime/atomic.hpp"
  78 #include "runtime/deoptimization.hpp"
  79 #include "runtime/fieldDescriptor.inline.hpp"
  80 #include "runtime/flags/jvmFlag.hpp"
  81 #include "runtime/flags/jvmFlagAccess.hpp"
  82 #include "runtime/frame.inline.hpp"
  83 #include "runtime/handles.inline.hpp"
  84 #include "runtime/handshake.hpp"
  85 #include "runtime/interfaceSupport.inline.hpp"
  86 #include "runtime/javaCalls.hpp"
  87 #include "runtime/javaThread.inline.hpp"
  88 #include "runtime/jniHandles.inline.hpp"
  89 #include "runtime/os.hpp"
  90 #include "runtime/stackFrameStream.inline.hpp"

1878 
1879 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
1880   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1881   ConstantPool* cp = ik->constants();
1882   if (cp->cache() == nullptr) {
1883     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
1884   }
1885   jint cpci = index;
1886   jint cpciTag = ConstantPool::CPCACHE_INDEX_TAG;
1887   if (cpciTag > cpci || cpci >= cp->cache()->length() + cpciTag) {
1888     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool cache index is out of range");
1889   }
1890   jint cpi = cp->remap_instruction_operand_from_cache(cpci);
1891   return cpi;
1892 WB_END
1893 
1894 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1895   return ConstantPool::encode_invokedynamic_index(index);
1896 WB_END
1897 
1898 WB_ENTRY(jobjectArray, WB_getObjectsViaKlassOopMaps(JNIEnv* env, jobject wb, jobject thing))
1899   oop aoop = JNIHandles::resolve(thing);
1900   if (!aoop->is_instance()) {
1901     return nullptr;
1902   }
1903   instanceHandle ih(THREAD, (instanceOop) aoop);
1904   InstanceKlass* klass = InstanceKlass::cast(ih->klass());
1905   if (klass->nonstatic_oop_map_count() == 0) {
1906     return nullptr;
1907   }
1908   const OopMapBlock* map = klass->start_of_nonstatic_oop_maps();
1909   const OopMapBlock* const end = map + klass->nonstatic_oop_map_count();
1910   int oop_count = 0;
1911   while (map < end) {
1912     oop_count += map->count();
1913     map++;
1914   }
1915 
1916   objArrayHandle result_array =
1917       oopFactory::new_objArray_handle(vmClasses::Object_klass(), oop_count, CHECK_NULL);
1918   map = klass->start_of_nonstatic_oop_maps();
1919   int index = 0;
1920   while (map < end) {
1921     int offset = map->offset();
1922     for (unsigned int j = 0; j < map->count(); j++) {
1923       result_array->obj_at_put(index++, ih->obj_field(offset));
1924       offset += heapOopSize;
1925     }
1926     map++;
1927   }
1928   return (jobjectArray)JNIHandles::make_local(THREAD, result_array());
1929 WB_END
1930 
1931 class CollectOops : public BasicOopIterateClosure {
1932  public:
1933   GrowableArray<Handle>* array;
1934 
1935   jobjectArray create_jni_result(JNIEnv* env, TRAPS) {
1936     objArrayHandle result_array =
1937         oopFactory::new_objArray_handle(vmClasses::Object_klass(), array->length(), CHECK_NULL);
1938     for (int i = 0 ; i < array->length(); i++) {
1939       result_array->obj_at_put(i, array->at(i)());
1940     }
1941     return (jobjectArray)JNIHandles::make_local(THREAD, result_array());
1942   }
1943 
1944   void add_oop(oop o) {
1945     Handle oh = Handle(Thread::current(), o);
1946     // Value might be oop, but JLS can't see as Object, just iterate through it...
1947     if (oh != nullptr && oh->is_inline_type()) {
1948       oh->oop_iterate(this);
1949     } else {
1950       array->append(oh);
1951     }
1952   }
1953 
1954   void do_oop(oop* o) { add_oop(HeapAccess<>::oop_load(o)); }
1955   void do_oop(narrowOop* v) { add_oop(HeapAccess<>::oop_load(v)); }
1956 };
1957 
1958 
1959 WB_ENTRY(jobjectArray, WB_getObjectsViaOopIterator(JNIEnv* env, jobject wb, jobject thing))
1960   ResourceMark rm(thread);
1961   Handle objh(thread, JNIHandles::resolve(thing));
1962   GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1963   CollectOops collectOops;
1964   collectOops.array = array;
1965   objh->oop_iterate(&collectOops);
1966   return collectOops.create_jni_result(env, THREAD);
1967 WB_END
1968 
1969 WB_ENTRY(jobjectArray, WB_getObjectsViaFrameOopIterator(JNIEnv* env, jobject wb, jint depth))
1970   ResourceMark rm(THREAD);
1971   GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1972   CollectOops collectOops;
1973   collectOops.array = array;
1974   StackFrameStream sfs(thread, false /* update */, true /* process_frames */);
1975   while (depth > 0) { // Skip the native WB API frame
1976     sfs.next();
1977     frame* f = sfs.current();
1978     f->oops_do(&collectOops, nullptr, sfs.register_map());
1979     depth--;
1980   }
1981   return collectOops.create_jni_result(env, THREAD);
1982 WB_END
1983 
1984 
1985 WB_ENTRY(jint, WB_getIndyInfoLength(JNIEnv* env, jobject wb, jclass klass))
1986   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1987   ConstantPool* cp = ik->constants();
1988   if (cp->cache() == nullptr) {
1989       return -1;
1990   }
1991   return cp->resolved_indy_entries_length();
1992 WB_END
1993 
1994 WB_ENTRY(jint, WB_getIndyCPIndex(JNIEnv* env, jobject wb, jclass klass, jint index))
1995   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1996   ConstantPool* cp = ik->constants();
1997   if (cp->cache() == nullptr) {
1998       return -1;
1999   }
2000   return cp->resolved_indy_entry_at(index)->constant_pool_index();
2001 WB_END
2002 
2003 WB_ENTRY(jobject, WB_printClasses(JNIEnv* env, jobject wb, jstring class_name_pattern, jint flags))
2004   ThreadToNativeFromVM ttnfv(thread);

2859                                                       (void*)&WB_DefineModule },
2860   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2861                                                       (void*)&WB_AddModuleExports },
2862   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2863                                                       (void*)&WB_AddReadsModule },
2864   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2865                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2866   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2867                                                       (void*)&WB_AddModuleExportsToAll },
2868   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2869   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2870   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2871   {CC"forceClassLoaderStatsSafepoint", CC"()V",       (void*)&WB_ForceClassLoaderStatsSafepoint },
2872   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2873   {CC"getConstantPoolCacheIndexTag0", CC"()I",  (void*)&WB_GetConstantPoolCacheIndexTag},
2874   {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_GetConstantPoolCacheLength},
2875   {CC"remapInstructionOperandFromCPCache0",
2876       CC"(Ljava/lang/Class;I)I",                      (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2877   {CC"encodeConstantPoolIndyIndex0",
2878       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},
2879   {CC"getObjectsViaKlassOopMaps0",
2880       CC"(Ljava/lang/Object;)[Ljava/lang/Object;",    (void*)&WB_getObjectsViaKlassOopMaps},
2881   {CC"getObjectsViaOopIterator0",
2882           CC"(Ljava/lang/Object;)[Ljava/lang/Object;",(void*)&WB_getObjectsViaOopIterator},
2883   {CC"getObjectsViaFrameOopIterator",
2884       CC"(I)[Ljava/lang/Object;",                     (void*)&WB_getObjectsViaFrameOopIterator},
2885   {CC"getIndyInfoLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_getIndyInfoLength},
2886   {CC"getIndyCPIndex0",    CC"(Ljava/lang/Class;I)I", (void*)&WB_getIndyCPIndex},
2887   {CC"printClasses0",      CC"(Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printClasses},
2888   {CC"printMethods0",      CC"(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printMethods},
2889   {CC"getMethodBooleanOption",
2890       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2891                                                       (void*)&WB_GetMethodBooleaneOption},
2892   {CC"getMethodIntxOption",
2893       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2894                                                       (void*)&WB_GetMethodIntxOption},
2895   {CC"getMethodUintxOption",
2896       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2897                                                       (void*)&WB_GetMethodUintxOption},
2898   {CC"getMethodDoubleOption",
2899       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2900                                                       (void*)&WB_GetMethodDoubleOption},
2901   {CC"getMethodStringOption",
2902       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2903                                                       (void*)&WB_GetMethodStringOption},
2904   {CC"getDefaultArchivePath",             CC"()Ljava/lang/String;",
< prev index next >