< prev index next >

src/hotspot/share/prims/whitebox.cpp

Print this page

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

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

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

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

1847 
1848 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
1849   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1850   ConstantPool* cp = ik->constants();
1851   if (cp->cache() == NULL) {
1852     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
1853   }
1854   jint cpci = index;
1855   jint cpciTag = ConstantPool::CPCACHE_INDEX_TAG;
1856   if (cpciTag > cpci || cpci >= cp->cache()->length() + cpciTag) {
1857     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool cache index is out of range");
1858   }
1859   jint cpi = cp->remap_instruction_operand_from_cache(cpci);
1860   return cpi;
1861 WB_END
1862 
1863 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1864   return ConstantPool::encode_invokedynamic_index(index);
1865 WB_END
1866 























































































1867 WB_ENTRY(void, WB_ClearInlineCaches(JNIEnv* env, jobject wb, jboolean preserve_static_stubs))
1868   VM_ClearICs clear_ics(preserve_static_stubs == JNI_TRUE);
1869   VMThread::execute(&clear_ics);
1870 WB_END
1871 
1872 template <typename T>
1873 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1874   assert(value != NULL, "sanity");
1875   if (method == NULL || name == NULL) {
1876     return false;
1877   }
1878   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1879   CHECK_JNI_EXCEPTION_(env, false);
1880   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1881   // can't be in VM when we call JNI
1882   ThreadToNativeFromVM ttnfv(thread);
1883   const char* flag_name = env->GetStringUTFChars(name, NULL);
1884   CHECK_JNI_EXCEPTION_(env, false);
1885   enum CompileCommand option = CompilerOracle::string_to_option(flag_name);
1886   env->ReleaseStringUTFChars(name, flag_name);

2674                                                       (void*)&WB_DefineModule },
2675   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2676                                                       (void*)&WB_AddModuleExports },
2677   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2678                                                       (void*)&WB_AddReadsModule },
2679   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2680                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2681   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2682                                                       (void*)&WB_AddModuleExportsToAll },
2683   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2684   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2685   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2686   {CC"forceClassLoaderStatsSafepoint", CC"()V",       (void*)&WB_ForceClassLoaderStatsSafepoint },
2687   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2688   {CC"getConstantPoolCacheIndexTag0", CC"()I",  (void*)&WB_GetConstantPoolCacheIndexTag},
2689   {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_GetConstantPoolCacheLength},
2690   {CC"remapInstructionOperandFromCPCache0",
2691       CC"(Ljava/lang/Class;I)I",                      (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2692   {CC"encodeConstantPoolIndyIndex0",
2693       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},






2694   {CC"getMethodBooleanOption",
2695       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2696                                                       (void*)&WB_GetMethodBooleaneOption},
2697   {CC"getMethodIntxOption",
2698       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2699                                                       (void*)&WB_GetMethodIntxOption},
2700   {CC"getMethodUintxOption",
2701       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2702                                                       (void*)&WB_GetMethodUintxOption},
2703   {CC"getMethodDoubleOption",
2704       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2705                                                       (void*)&WB_GetMethodDoubleOption},
2706   {CC"getMethodStringOption",
2707       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2708                                                       (void*)&WB_GetMethodStringOption},
2709   {CC"getDefaultArchivePath",             CC"()Ljava/lang/String;",
2710                                                       (void*)&WB_GetDefaultArchivePath},
2711   {CC"getCDSGenericHeaderMinVersion",     CC"()I",    (void*)&WB_GetCDSGenericHeaderMinVersion},
2712   {CC"getCurrentCDSVersion",              CC"()I",    (void*)&WB_GetCDSCurrentVersion},
2713   {CC"isSharingEnabled",   CC"()Z",                   (void*)&WB_IsSharingEnabled},

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

1850 
1851 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
1852   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1853   ConstantPool* cp = ik->constants();
1854   if (cp->cache() == NULL) {
1855     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
1856   }
1857   jint cpci = index;
1858   jint cpciTag = ConstantPool::CPCACHE_INDEX_TAG;
1859   if (cpciTag > cpci || cpci >= cp->cache()->length() + cpciTag) {
1860     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool cache index is out of range");
1861   }
1862   jint cpi = cp->remap_instruction_operand_from_cache(cpci);
1863   return cpi;
1864 WB_END
1865 
1866 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1867   return ConstantPool::encode_invokedynamic_index(index);
1868 WB_END
1869 
1870 WB_ENTRY(jobjectArray, WB_getObjectsViaKlassOopMaps(JNIEnv* env, jobject wb, jobject thing))
1871   oop aoop = JNIHandles::resolve(thing);
1872   if (!aoop->is_instance()) {
1873     return NULL;
1874   }
1875   instanceHandle ih(THREAD, (instanceOop) aoop);
1876   InstanceKlass* klass = InstanceKlass::cast(ih->klass());
1877   if (klass->nonstatic_oop_map_count() == 0) {
1878     return NULL;
1879   }
1880   const OopMapBlock* map = klass->start_of_nonstatic_oop_maps();
1881   const OopMapBlock* const end = map + klass->nonstatic_oop_map_count();
1882   int oop_count = 0;
1883   while (map < end) {
1884     oop_count += map->count();
1885     map++;
1886   }
1887 
1888   objArrayHandle result_array =
1889       oopFactory::new_objArray_handle(vmClasses::Object_klass(), oop_count, CHECK_NULL);
1890   map = klass->start_of_nonstatic_oop_maps();
1891   int index = 0;
1892   while (map < end) {
1893     int offset = map->offset();
1894     for (unsigned int j = 0; j < map->count(); j++) {
1895       result_array->obj_at_put(index++, ih->obj_field(offset));
1896       offset += heapOopSize;
1897     }
1898     map++;
1899   }
1900   return (jobjectArray)JNIHandles::make_local(THREAD, result_array());
1901 WB_END
1902 
1903 class CollectOops : public BasicOopIterateClosure {
1904  public:
1905   GrowableArray<Handle>* array;
1906 
1907   jobjectArray create_jni_result(JNIEnv* env, TRAPS) {
1908     objArrayHandle result_array =
1909         oopFactory::new_objArray_handle(vmClasses::Object_klass(), array->length(), CHECK_NULL);
1910     for (int i = 0 ; i < array->length(); i++) {
1911       result_array->obj_at_put(i, array->at(i)());
1912     }
1913     return (jobjectArray)JNIHandles::make_local(THREAD, result_array());
1914   }
1915 
1916   void add_oop(oop o) {
1917     Handle oh = Handle(Thread::current(), o);
1918     // Value might be oop, but JLS can't see as Object, just iterate through it...
1919     if (oh != NULL && oh->is_inline_type()) {
1920       oh->oop_iterate(this);
1921     } else {
1922       array->append(oh);
1923     }
1924   }
1925 
1926   void do_oop(oop* o) { add_oop(HeapAccess<>::oop_load(o)); }
1927   void do_oop(narrowOop* v) { add_oop(HeapAccess<>::oop_load(v)); }
1928 };
1929 
1930 
1931 WB_ENTRY(jobjectArray, WB_getObjectsViaOopIterator(JNIEnv* env, jobject wb, jobject thing))
1932   ResourceMark rm(thread);
1933   Handle objh(thread, JNIHandles::resolve(thing));
1934   GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1935   CollectOops collectOops;
1936   collectOops.array = array;
1937   objh->oop_iterate(&collectOops);
1938   return collectOops.create_jni_result(env, THREAD);
1939 WB_END
1940 
1941 WB_ENTRY(jobjectArray, WB_getObjectsViaFrameOopIterator(JNIEnv* env, jobject wb, jint depth))
1942   ResourceMark rm(THREAD);
1943   GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1944   CollectOops collectOops;
1945   collectOops.array = array;
1946   StackFrameStream sfs(thread, false /* update */, true /* process_frames */);
1947   while (depth > 0) { // Skip the native WB API frame
1948     sfs.next();
1949     frame* f = sfs.current();
1950     f->oops_do(&collectOops, NULL, sfs.register_map());
1951     depth--;
1952   }
1953   return collectOops.create_jni_result(env, THREAD);
1954 WB_END
1955 
1956 
1957 WB_ENTRY(void, WB_ClearInlineCaches(JNIEnv* env, jobject wb, jboolean preserve_static_stubs))
1958   VM_ClearICs clear_ics(preserve_static_stubs == JNI_TRUE);
1959   VMThread::execute(&clear_ics);
1960 WB_END
1961 
1962 template <typename T>
1963 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1964   assert(value != NULL, "sanity");
1965   if (method == NULL || name == NULL) {
1966     return false;
1967   }
1968   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1969   CHECK_JNI_EXCEPTION_(env, false);
1970   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1971   // can't be in VM when we call JNI
1972   ThreadToNativeFromVM ttnfv(thread);
1973   const char* flag_name = env->GetStringUTFChars(name, NULL);
1974   CHECK_JNI_EXCEPTION_(env, false);
1975   enum CompileCommand option = CompilerOracle::string_to_option(flag_name);
1976   env->ReleaseStringUTFChars(name, flag_name);

2764                                                       (void*)&WB_DefineModule },
2765   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2766                                                       (void*)&WB_AddModuleExports },
2767   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2768                                                       (void*)&WB_AddReadsModule },
2769   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2770                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2771   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2772                                                       (void*)&WB_AddModuleExportsToAll },
2773   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2774   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2775   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2776   {CC"forceClassLoaderStatsSafepoint", CC"()V",       (void*)&WB_ForceClassLoaderStatsSafepoint },
2777   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2778   {CC"getConstantPoolCacheIndexTag0", CC"()I",  (void*)&WB_GetConstantPoolCacheIndexTag},
2779   {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_GetConstantPoolCacheLength},
2780   {CC"remapInstructionOperandFromCPCache0",
2781       CC"(Ljava/lang/Class;I)I",                      (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2782   {CC"encodeConstantPoolIndyIndex0",
2783       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},
2784   {CC"getObjectsViaKlassOopMaps0",
2785       CC"(Ljava/lang/Object;)[Ljava/lang/Object;",    (void*)&WB_getObjectsViaKlassOopMaps},
2786   {CC"getObjectsViaOopIterator0",
2787           CC"(Ljava/lang/Object;)[Ljava/lang/Object;",(void*)&WB_getObjectsViaOopIterator},
2788   {CC"getObjectsViaFrameOopIterator",
2789       CC"(I)[Ljava/lang/Object;",                     (void*)&WB_getObjectsViaFrameOopIterator},
2790   {CC"getMethodBooleanOption",
2791       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2792                                                       (void*)&WB_GetMethodBooleaneOption},
2793   {CC"getMethodIntxOption",
2794       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2795                                                       (void*)&WB_GetMethodIntxOption},
2796   {CC"getMethodUintxOption",
2797       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2798                                                       (void*)&WB_GetMethodUintxOption},
2799   {CC"getMethodDoubleOption",
2800       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2801                                                       (void*)&WB_GetMethodDoubleOption},
2802   {CC"getMethodStringOption",
2803       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2804                                                       (void*)&WB_GetMethodStringOption},
2805   {CC"getDefaultArchivePath",             CC"()Ljava/lang/String;",
2806                                                       (void*)&WB_GetDefaultArchivePath},
2807   {CC"getCDSGenericHeaderMinVersion",     CC"()I",    (void*)&WB_GetCDSGenericHeaderMinVersion},
2808   {CC"getCurrentCDSVersion",              CC"()I",    (void*)&WB_GetCDSCurrentVersion},
2809   {CC"isSharingEnabled",   CC"()Z",                   (void*)&WB_IsSharingEnabled},
< prev index next >