< prev index next >

src/hotspot/share/prims/whitebox.cpp

Print this page

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

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

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

  66 #include "oops/typeArrayOop.inline.hpp"
  67 #include "prims/resolvedMethodTable.hpp"
  68 #include "prims/wbtestmethods/parserTests.hpp"
  69 #include "prims/whitebox.inline.hpp"
  70 #include "runtime/arguments.hpp"
  71 #include "runtime/atomic.hpp"
  72 #include "runtime/deoptimization.hpp"
  73 #include "runtime/fieldDescriptor.inline.hpp"
  74 #include "runtime/flags/jvmFlag.hpp"
  75 #include "runtime/flags/jvmFlagAccess.hpp"
  76 #include "runtime/frame.inline.hpp"
  77 #include "runtime/handles.inline.hpp"
  78 #include "runtime/handshake.hpp"
  79 #include "runtime/interfaceSupport.inline.hpp"
  80 #include "runtime/javaCalls.hpp"
  81 #include "runtime/jniHandles.inline.hpp"
  82 #include "runtime/os.hpp"
  83 #include "runtime/stackFrameStream.inline.hpp"
  84 #include "runtime/sweeper.hpp"
  85 #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);

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






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

  33 #include "classfile/javaClasses.inline.hpp"
  34 #include "classfile/modules.hpp"
  35 #include "classfile/protectionDomainCache.hpp"
  36 #include "classfile/stringTable.hpp"
  37 #include "classfile/symbolTable.hpp"
  38 #include "classfile/systemDictionary.hpp"
  39 #include "classfile/vmSymbols.hpp"
  40 #include "code/codeCache.hpp"
  41 #include "compiler/compilationPolicy.hpp"
  42 #include "compiler/directivesParser.hpp"
  43 #include "compiler/methodMatcher.hpp"
  44 #include "gc/shared/concurrentGCBreakpoints.hpp"
  45 #include "gc/shared/gcConfig.hpp"
  46 #include "gc/shared/gcLocker.inline.hpp"
  47 #include "gc/shared/genArguments.hpp"
  48 #include "gc/shared/genCollectedHeap.hpp"
  49 #include "jvmtifiles/jvmtiEnv.hpp"
  50 #include "logging/log.hpp"
  51 #include "memory/iterator.hpp"
  52 #include "memory/metadataFactory.hpp"
  53 #include "memory/iterator.inline.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/compressedOops.inline.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/objArrayOop.inline.hpp"
  69 #include "oops/typeArrayOop.inline.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/jniHandles.inline.hpp"
  85 #include "runtime/os.hpp"
  86 #include "runtime/stackFrameStream.inline.hpp"
  87 #include "runtime/sweeper.hpp"
  88 #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);

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