< prev index next >

src/hotspot/share/prims/whitebox.cpp

Print this page

  34 #include "classfile/classPrinter.hpp"
  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 "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 "nmt/mallocSiteTable.hpp"
  60 #include "nmt/memTracker.hpp"
  61 #include "oops/array.hpp"
  62 #include "oops/compressedOops.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/typeArrayOop.inline.hpp"
  70 #include "prims/jvmtiEnvBase.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"

1861   nullStream dev_null;
1862   ClassLoaderStatsVMOperation force_op(&dev_null);
1863   VMThread::execute(&force_op);
1864 WB_END
1865 
1866 WB_ENTRY(jlong, WB_GetConstantPool(JNIEnv* env, jobject wb, jclass klass))
1867   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1868   return (jlong) ik->constants();
1869 WB_END
1870 
1871 WB_ENTRY(jobjectArray, WB_GetResolvedReferences(JNIEnv* env, jobject wb, jclass klass))
1872   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1873   objArrayOop resolved_refs= ik->constants()->resolved_references();
1874   return (jobjectArray)JNIHandles::make_local(THREAD, resolved_refs);
1875 WB_END
1876 
1877 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1878   return ConstantPool::encode_invokedynamic_index(index);
1879 WB_END
1880 























































































1881 WB_ENTRY(jint, WB_getFieldEntriesLength(JNIEnv* env, jobject wb, jclass klass))
1882   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1883   ConstantPool* cp = ik->constants();
1884   if (cp->cache() == nullptr) {
1885     return -1;
1886   }
1887   return cp->resolved_field_entries_length();
1888 WB_END
1889 
1890 WB_ENTRY(jint, WB_getFieldCPIndex(JNIEnv* env, jobject wb, jclass klass, jint index))
1891   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1892   ConstantPool* cp = ik->constants();
1893   if (cp->cache() == NULL) {
1894       return -1;
1895   }
1896   return cp->resolved_field_entry_at(index)->constant_pool_index();
1897 WB_END
1898 
1899 WB_ENTRY(jint, WB_getMethodEntriesLength(JNIEnv* env, jobject wb, jclass klass))
1900   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));

2788   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
2789   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
2790   {CC"DefineModule",       CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2791                                                       (void*)&WB_DefineModule },
2792   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2793                                                       (void*)&WB_AddModuleExports },
2794   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2795                                                       (void*)&WB_AddReadsModule },
2796   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2797                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2798   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2799                                                       (void*)&WB_AddModuleExportsToAll },
2800   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2801   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2802   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2803   {CC"forceClassLoaderStatsSafepoint", CC"()V",       (void*)&WB_ForceClassLoaderStatsSafepoint },
2804   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2805   {CC"getResolvedReferences0", CC"(Ljava/lang/Class;)[Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
2806   {CC"encodeConstantPoolIndyIndex0",
2807       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},






2808   {CC"getFieldEntriesLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_getFieldEntriesLength},
2809   {CC"getFieldCPIndex0",    CC"(Ljava/lang/Class;I)I", (void*)&WB_getFieldCPIndex},
2810   {CC"getMethodEntriesLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_getMethodEntriesLength},
2811   {CC"getMethodCPIndex0",    CC"(Ljava/lang/Class;I)I", (void*)&WB_getMethodCPIndex},
2812   {CC"getIndyInfoLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_getIndyInfoLength},
2813   {CC"getIndyCPIndex0",    CC"(Ljava/lang/Class;I)I", (void*)&WB_getIndyCPIndex},
2814   {CC"printClasses0",      CC"(Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printClasses},
2815   {CC"printMethods0",      CC"(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printMethods},
2816   {CC"getMethodBooleanOption",
2817       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2818                                                       (void*)&WB_GetMethodBooleaneOption},
2819   {CC"getMethodIntxOption",
2820       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2821                                                       (void*)&WB_GetMethodIntxOption},
2822   {CC"getMethodUintxOption",
2823       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2824                                                       (void*)&WB_GetMethodUintxOption},
2825   {CC"getMethodDoubleOption",
2826       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2827                                                       (void*)&WB_GetMethodDoubleOption},

  34 #include "classfile/classPrinter.hpp"
  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 "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 "nmt/mallocSiteTable.hpp"
  61 #include "nmt/memTracker.hpp"
  62 #include "oops/array.hpp"
  63 #include "oops/compressedOops.hpp"
  64 #include "oops/compressedOops.inline.hpp"
  65 #include "oops/constantPool.inline.hpp"
  66 #include "oops/klass.inline.hpp"
  67 #include "oops/method.inline.hpp"
  68 #include "oops/objArrayKlass.hpp"
  69 #include "oops/objArrayOop.inline.hpp"
  70 #include "oops/oop.inline.hpp"
  71 #include "oops/objArrayOop.inline.hpp"
  72 #include "oops/typeArrayOop.inline.hpp"
  73 #include "prims/jvmtiEnvBase.hpp"
  74 #include "prims/resolvedMethodTable.hpp"
  75 #include "prims/wbtestmethods/parserTests.hpp"
  76 #include "prims/whitebox.inline.hpp"
  77 #include "runtime/arguments.hpp"
  78 #include "runtime/atomic.hpp"
  79 #include "runtime/deoptimization.hpp"
  80 #include "runtime/fieldDescriptor.inline.hpp"
  81 #include "runtime/flags/jvmFlag.hpp"
  82 #include "runtime/flags/jvmFlagAccess.hpp"
  83 #include "runtime/frame.inline.hpp"
  84 #include "runtime/handles.inline.hpp"
  85 #include "runtime/handshake.hpp"
  86 #include "runtime/interfaceSupport.inline.hpp"
  87 #include "runtime/javaCalls.hpp"
  88 #include "runtime/javaThread.inline.hpp"
  89 #include "runtime/jniHandles.inline.hpp"
  90 #include "runtime/os.hpp"
  91 #include "runtime/stackFrameStream.inline.hpp"

1864   nullStream dev_null;
1865   ClassLoaderStatsVMOperation force_op(&dev_null);
1866   VMThread::execute(&force_op);
1867 WB_END
1868 
1869 WB_ENTRY(jlong, WB_GetConstantPool(JNIEnv* env, jobject wb, jclass klass))
1870   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1871   return (jlong) ik->constants();
1872 WB_END
1873 
1874 WB_ENTRY(jobjectArray, WB_GetResolvedReferences(JNIEnv* env, jobject wb, jclass klass))
1875   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1876   objArrayOop resolved_refs= ik->constants()->resolved_references();
1877   return (jobjectArray)JNIHandles::make_local(THREAD, resolved_refs);
1878 WB_END
1879 
1880 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1881   return ConstantPool::encode_invokedynamic_index(index);
1882 WB_END
1883 
1884 WB_ENTRY(jobjectArray, WB_getObjectsViaKlassOopMaps(JNIEnv* env, jobject wb, jobject thing))
1885   oop aoop = JNIHandles::resolve(thing);
1886   if (!aoop->is_instance()) {
1887     return nullptr;
1888   }
1889   instanceHandle ih(THREAD, (instanceOop) aoop);
1890   InstanceKlass* klass = InstanceKlass::cast(ih->klass());
1891   if (klass->nonstatic_oop_map_count() == 0) {
1892     return nullptr;
1893   }
1894   const OopMapBlock* map = klass->start_of_nonstatic_oop_maps();
1895   const OopMapBlock* const end = map + klass->nonstatic_oop_map_count();
1896   int oop_count = 0;
1897   while (map < end) {
1898     oop_count += map->count();
1899     map++;
1900   }
1901 
1902   objArrayHandle result_array =
1903       oopFactory::new_objArray_handle(vmClasses::Object_klass(), oop_count, CHECK_NULL);
1904   map = klass->start_of_nonstatic_oop_maps();
1905   int index = 0;
1906   while (map < end) {
1907     int offset = map->offset();
1908     for (unsigned int j = 0; j < map->count(); j++) {
1909       result_array->obj_at_put(index++, ih->obj_field(offset));
1910       offset += heapOopSize;
1911     }
1912     map++;
1913   }
1914   return (jobjectArray)JNIHandles::make_local(THREAD, result_array());
1915 WB_END
1916 
1917 class CollectOops : public BasicOopIterateClosure {
1918  public:
1919   GrowableArray<Handle>* array;
1920 
1921   jobjectArray create_jni_result(JNIEnv* env, TRAPS) {
1922     objArrayHandle result_array =
1923         oopFactory::new_objArray_handle(vmClasses::Object_klass(), array->length(), CHECK_NULL);
1924     for (int i = 0 ; i < array->length(); i++) {
1925       result_array->obj_at_put(i, array->at(i)());
1926     }
1927     return (jobjectArray)JNIHandles::make_local(THREAD, result_array());
1928   }
1929 
1930   void add_oop(oop o) {
1931     Handle oh = Handle(Thread::current(), o);
1932     // Value might be oop, but JLS can't see as Object, just iterate through it...
1933     if (oh != nullptr && oh->is_inline_type()) {
1934       oh->oop_iterate(this);
1935     } else {
1936       array->append(oh);
1937     }
1938   }
1939 
1940   void do_oop(oop* o) { add_oop(HeapAccess<>::oop_load(o)); }
1941   void do_oop(narrowOop* v) { add_oop(HeapAccess<>::oop_load(v)); }
1942 };
1943 
1944 
1945 WB_ENTRY(jobjectArray, WB_getObjectsViaOopIterator(JNIEnv* env, jobject wb, jobject thing))
1946   ResourceMark rm(thread);
1947   Handle objh(thread, JNIHandles::resolve(thing));
1948   GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1949   CollectOops collectOops;
1950   collectOops.array = array;
1951   objh->oop_iterate(&collectOops);
1952   return collectOops.create_jni_result(env, THREAD);
1953 WB_END
1954 
1955 WB_ENTRY(jobjectArray, WB_getObjectsViaFrameOopIterator(JNIEnv* env, jobject wb, jint depth))
1956   ResourceMark rm(THREAD);
1957   GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1958   CollectOops collectOops;
1959   collectOops.array = array;
1960   StackFrameStream sfs(thread, false /* update */, true /* process_frames */);
1961   while (depth > 0) { // Skip the native WB API frame
1962     sfs.next();
1963     frame* f = sfs.current();
1964     f->oops_do(&collectOops, nullptr, sfs.register_map());
1965     depth--;
1966   }
1967   return collectOops.create_jni_result(env, THREAD);
1968 WB_END
1969 
1970 
1971 WB_ENTRY(jint, WB_getFieldEntriesLength(JNIEnv* env, jobject wb, jclass klass))
1972   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1973   ConstantPool* cp = ik->constants();
1974   if (cp->cache() == nullptr) {
1975     return -1;
1976   }
1977   return cp->resolved_field_entries_length();
1978 WB_END
1979 
1980 WB_ENTRY(jint, WB_getFieldCPIndex(JNIEnv* env, jobject wb, jclass klass, jint index))
1981   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1982   ConstantPool* cp = ik->constants();
1983   if (cp->cache() == NULL) {
1984       return -1;
1985   }
1986   return cp->resolved_field_entry_at(index)->constant_pool_index();
1987 WB_END
1988 
1989 WB_ENTRY(jint, WB_getMethodEntriesLength(JNIEnv* env, jobject wb, jclass klass))
1990   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));

2878   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
2879   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
2880   {CC"DefineModule",       CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2881                                                       (void*)&WB_DefineModule },
2882   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2883                                                       (void*)&WB_AddModuleExports },
2884   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2885                                                       (void*)&WB_AddReadsModule },
2886   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2887                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2888   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2889                                                       (void*)&WB_AddModuleExportsToAll },
2890   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2891   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2892   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2893   {CC"forceClassLoaderStatsSafepoint", CC"()V",       (void*)&WB_ForceClassLoaderStatsSafepoint },
2894   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2895   {CC"getResolvedReferences0", CC"(Ljava/lang/Class;)[Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
2896   {CC"encodeConstantPoolIndyIndex0",
2897       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},
2898   {CC"getObjectsViaKlassOopMaps0",
2899       CC"(Ljava/lang/Object;)[Ljava/lang/Object;",    (void*)&WB_getObjectsViaKlassOopMaps},
2900   {CC"getObjectsViaOopIterator0",
2901           CC"(Ljava/lang/Object;)[Ljava/lang/Object;",(void*)&WB_getObjectsViaOopIterator},
2902   {CC"getObjectsViaFrameOopIterator",
2903       CC"(I)[Ljava/lang/Object;",                     (void*)&WB_getObjectsViaFrameOopIterator},
2904   {CC"getFieldEntriesLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_getFieldEntriesLength},
2905   {CC"getFieldCPIndex0",    CC"(Ljava/lang/Class;I)I", (void*)&WB_getFieldCPIndex},
2906   {CC"getMethodEntriesLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_getMethodEntriesLength},
2907   {CC"getMethodCPIndex0",    CC"(Ljava/lang/Class;I)I", (void*)&WB_getMethodCPIndex},
2908   {CC"getIndyInfoLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_getIndyInfoLength},
2909   {CC"getIndyCPIndex0",    CC"(Ljava/lang/Class;I)I", (void*)&WB_getIndyCPIndex},
2910   {CC"printClasses0",      CC"(Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printClasses},
2911   {CC"printMethods0",      CC"(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printMethods},
2912   {CC"getMethodBooleanOption",
2913       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2914                                                       (void*)&WB_GetMethodBooleaneOption},
2915   {CC"getMethodIntxOption",
2916       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2917                                                       (void*)&WB_GetMethodIntxOption},
2918   {CC"getMethodUintxOption",
2919       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2920                                                       (void*)&WB_GetMethodUintxOption},
2921   {CC"getMethodDoubleOption",
2922       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2923                                                       (void*)&WB_GetMethodDoubleOption},
< prev index next >