< 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"

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























































































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

2667   {CC"DefineModule",       CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2668                                                       (void*)&WB_DefineModule },
2669   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2670                                                       (void*)&WB_AddModuleExports },
2671   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2672                                                       (void*)&WB_AddReadsModule },
2673   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2674                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2675   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2676                                                       (void*)&WB_AddModuleExportsToAll },
2677   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2678   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2679   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2680   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2681   {CC"getConstantPoolCacheIndexTag0", CC"()I",  (void*)&WB_GetConstantPoolCacheIndexTag},
2682   {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_GetConstantPoolCacheLength},
2683   {CC"remapInstructionOperandFromCPCache0",
2684       CC"(Ljava/lang/Class;I)I",                      (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2685   {CC"encodeConstantPoolIndyIndex0",
2686       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},






2687   {CC"getMethodBooleanOption",
2688       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2689                                                       (void*)&WB_GetMethodBooleaneOption},
2690   {CC"getMethodIntxOption",
2691       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2692                                                       (void*)&WB_GetMethodIntxOption},
2693   {CC"getMethodUintxOption",
2694       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2695                                                       (void*)&WB_GetMethodUintxOption},
2696   {CC"getMethodDoubleOption",
2697       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2698                                                       (void*)&WB_GetMethodDoubleOption},
2699   {CC"getMethodStringOption",
2700       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2701                                                       (void*)&WB_GetMethodStringOption},
2702   {CC"getDefaultArchivePath",             CC"()Ljava/lang/String;",
2703                                                       (void*)&WB_GetDefaultArchivePath},
2704   {CC"getCDSGenericHeaderMinVersion",     CC"()I",    (void*)&WB_GetCDSGenericHeaderMinVersion},
2705   {CC"getCurrentCDSVersion",              CC"()I",    (void*)&WB_GetCDSCurrentVersion},
2706   {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"

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

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