< prev index next >

src/hotspot/share/prims/whitebox.cpp

Print this page

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

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

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

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

1815 
1816 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
1817   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1818   ConstantPool* cp = ik->constants();
1819   if (cp->cache() == NULL) {
1820     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
1821   }
1822   jint cpci = index;
1823   jint cpciTag = ConstantPool::CPCACHE_INDEX_TAG;
1824   if (cpciTag > cpci || cpci >= cp->cache()->length() + cpciTag) {
1825     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool cache index is out of range");
1826   }
1827   jint cpi = cp->remap_instruction_operand_from_cache(cpci);
1828   return cpi;
1829 WB_END
1830 
1831 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1832   return ConstantPool::encode_invokedynamic_index(index);
1833 WB_END
1834 























































































1835 WB_ENTRY(void, WB_ClearInlineCaches(JNIEnv* env, jobject wb, jboolean preserve_static_stubs))
1836   VM_ClearICs clear_ics(preserve_static_stubs == JNI_TRUE);
1837   VMThread::execute(&clear_ics);
1838 WB_END
1839 
1840 template <typename T>
1841 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1842   assert(value != NULL, "sanity");
1843   if (method == NULL || name == NULL) {
1844     return false;
1845   }
1846   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1847   CHECK_JNI_EXCEPTION_(env, false);
1848   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1849   // can't be in VM when we call JNI
1850   ThreadToNativeFromVM ttnfv(thread);
1851   const char* flag_name = env->GetStringUTFChars(name, NULL);
1852   CHECK_JNI_EXCEPTION_(env, false);
1853   enum CompileCommand option = CompilerOracle::string_to_option(flag_name);
1854   env->ReleaseStringUTFChars(name, flag_name);

2602   {CC"DefineModule",       CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2603                                                       (void*)&WB_DefineModule },
2604   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2605                                                       (void*)&WB_AddModuleExports },
2606   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2607                                                       (void*)&WB_AddReadsModule },
2608   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2609                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2610   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2611                                                       (void*)&WB_AddModuleExportsToAll },
2612   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2613   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2614   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2615   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2616   {CC"getConstantPoolCacheIndexTag0", CC"()I",  (void*)&WB_GetConstantPoolCacheIndexTag},
2617   {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_GetConstantPoolCacheLength},
2618   {CC"remapInstructionOperandFromCPCache0",
2619       CC"(Ljava/lang/Class;I)I",                      (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2620   {CC"encodeConstantPoolIndyIndex0",
2621       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},






2622   {CC"getMethodBooleanOption",
2623       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2624                                                       (void*)&WB_GetMethodBooleaneOption},
2625   {CC"getMethodIntxOption",
2626       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2627                                                       (void*)&WB_GetMethodIntxOption},
2628   {CC"getMethodUintxOption",
2629       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2630                                                       (void*)&WB_GetMethodUintxOption},
2631   {CC"getMethodDoubleOption",
2632       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2633                                                       (void*)&WB_GetMethodDoubleOption},
2634   {CC"getMethodStringOption",
2635       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2636                                                       (void*)&WB_GetMethodStringOption},
2637   {CC"getDefaultArchivePath",             CC"()Ljava/lang/String;",
2638                                                       (void*)&WB_GetDefaultArchivePath},
2639   {CC"isSharingEnabled",   CC"()Z",                   (void*)&WB_IsSharingEnabled},
2640   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
2641   {CC"isSharedInternedString", CC"(Ljava/lang/String;)Z", (void*)&WB_IsSharedInternedString },

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

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

2692   {CC"DefineModule",       CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2693                                                       (void*)&WB_DefineModule },
2694   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2695                                                       (void*)&WB_AddModuleExports },
2696   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2697                                                       (void*)&WB_AddReadsModule },
2698   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2699                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2700   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2701                                                       (void*)&WB_AddModuleExportsToAll },
2702   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2703   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2704   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2705   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2706   {CC"getConstantPoolCacheIndexTag0", CC"()I",  (void*)&WB_GetConstantPoolCacheIndexTag},
2707   {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_GetConstantPoolCacheLength},
2708   {CC"remapInstructionOperandFromCPCache0",
2709       CC"(Ljava/lang/Class;I)I",                      (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2710   {CC"encodeConstantPoolIndyIndex0",
2711       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},
2712   {CC"getObjectsViaKlassOopMaps0",
2713       CC"(Ljava/lang/Object;)[Ljava/lang/Object;",    (void*)&WB_getObjectsViaKlassOopMaps},
2714   {CC"getObjectsViaOopIterator0",
2715           CC"(Ljava/lang/Object;)[Ljava/lang/Object;",(void*)&WB_getObjectsViaOopIterator},
2716   {CC"getObjectsViaFrameOopIterator",
2717       CC"(I)[Ljava/lang/Object;",                     (void*)&WB_getObjectsViaFrameOopIterator},
2718   {CC"getMethodBooleanOption",
2719       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2720                                                       (void*)&WB_GetMethodBooleaneOption},
2721   {CC"getMethodIntxOption",
2722       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2723                                                       (void*)&WB_GetMethodIntxOption},
2724   {CC"getMethodUintxOption",
2725       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2726                                                       (void*)&WB_GetMethodUintxOption},
2727   {CC"getMethodDoubleOption",
2728       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2729                                                       (void*)&WB_GetMethodDoubleOption},
2730   {CC"getMethodStringOption",
2731       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2732                                                       (void*)&WB_GetMethodStringOption},
2733   {CC"getDefaultArchivePath",             CC"()Ljava/lang/String;",
2734                                                       (void*)&WB_GetDefaultArchivePath},
2735   {CC"isSharingEnabled",   CC"()Z",                   (void*)&WB_IsSharingEnabled},
2736   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
2737   {CC"isSharedInternedString", CC"(Ljava/lang/String;)Z", (void*)&WB_IsSharedInternedString },
< prev index next >