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)));
2818 {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize },
2819 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
2820 {CC"DefineModule", CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2821 (void*)&WB_DefineModule },
2822 {CC"AddModuleExports", CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2823 (void*)&WB_AddModuleExports },
2824 {CC"AddReadsModule", CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2825 (void*)&WB_AddReadsModule },
2826 {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2827 (void*)&WB_AddModuleExportsToAllUnnamed },
2828 {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2829 (void*)&WB_AddModuleExportsToAll },
2830 {CC"deflateIdleMonitors", CC"()Z", (void*)&WB_DeflateIdleMonitors },
2831 {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
2832 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
2833 {CC"forceClassLoaderStatsSafepoint", CC"()V", (void*)&WB_ForceClassLoaderStatsSafepoint },
2834 {CC"getConstantPool0", CC"(Ljava/lang/Class;)J", (void*)&WB_GetConstantPool },
2835 {CC"getResolvedReferences0", CC"(Ljava/lang/Class;)[Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
2836 {CC"encodeConstantPoolIndyIndex0",
2837 CC"(I)I", (void*)&WB_ConstantPoolEncodeIndyIndex},
2838 {CC"getFieldEntriesLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_getFieldEntriesLength},
2839 {CC"getFieldCPIndex0", CC"(Ljava/lang/Class;I)I", (void*)&WB_getFieldCPIndex},
2840 {CC"getMethodEntriesLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_getMethodEntriesLength},
2841 {CC"getMethodCPIndex0", CC"(Ljava/lang/Class;I)I", (void*)&WB_getMethodCPIndex},
2842 {CC"getIndyInfoLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_getIndyInfoLength},
2843 {CC"getIndyCPIndex0", CC"(Ljava/lang/Class;I)I", (void*)&WB_getIndyCPIndex},
2844 {CC"printClasses0", CC"(Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printClasses},
2845 {CC"printMethods0", CC"(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printMethods},
2846 {CC"getMethodBooleanOption",
2847 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2848 (void*)&WB_GetMethodBooleaneOption},
2849 {CC"getMethodIntxOption",
2850 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2851 (void*)&WB_GetMethodIntxOption},
2852 {CC"getMethodUintxOption",
2853 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2854 (void*)&WB_GetMethodUintxOption},
2855 {CC"getMethodDoubleOption",
2856 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2857 (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)));
2908 {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize },
2909 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
2910 {CC"DefineModule", CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2911 (void*)&WB_DefineModule },
2912 {CC"AddModuleExports", CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2913 (void*)&WB_AddModuleExports },
2914 {CC"AddReadsModule", CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2915 (void*)&WB_AddReadsModule },
2916 {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2917 (void*)&WB_AddModuleExportsToAllUnnamed },
2918 {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2919 (void*)&WB_AddModuleExportsToAll },
2920 {CC"deflateIdleMonitors", CC"()Z", (void*)&WB_DeflateIdleMonitors },
2921 {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
2922 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
2923 {CC"forceClassLoaderStatsSafepoint", CC"()V", (void*)&WB_ForceClassLoaderStatsSafepoint },
2924 {CC"getConstantPool0", CC"(Ljava/lang/Class;)J", (void*)&WB_GetConstantPool },
2925 {CC"getResolvedReferences0", CC"(Ljava/lang/Class;)[Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
2926 {CC"encodeConstantPoolIndyIndex0",
2927 CC"(I)I", (void*)&WB_ConstantPoolEncodeIndyIndex},
2928 {CC"getObjectsViaKlassOopMaps0",
2929 CC"(Ljava/lang/Object;)[Ljava/lang/Object;", (void*)&WB_getObjectsViaKlassOopMaps},
2930 {CC"getObjectsViaOopIterator0",
2931 CC"(Ljava/lang/Object;)[Ljava/lang/Object;",(void*)&WB_getObjectsViaOopIterator},
2932 {CC"getObjectsViaFrameOopIterator",
2933 CC"(I)[Ljava/lang/Object;", (void*)&WB_getObjectsViaFrameOopIterator},
2934 {CC"getFieldEntriesLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_getFieldEntriesLength},
2935 {CC"getFieldCPIndex0", CC"(Ljava/lang/Class;I)I", (void*)&WB_getFieldCPIndex},
2936 {CC"getMethodEntriesLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_getMethodEntriesLength},
2937 {CC"getMethodCPIndex0", CC"(Ljava/lang/Class;I)I", (void*)&WB_getMethodCPIndex},
2938 {CC"getIndyInfoLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_getIndyInfoLength},
2939 {CC"getIndyCPIndex0", CC"(Ljava/lang/Class;I)I", (void*)&WB_getIndyCPIndex},
2940 {CC"printClasses0", CC"(Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printClasses},
2941 {CC"printMethods0", CC"(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printMethods},
2942 {CC"getMethodBooleanOption",
2943 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2944 (void*)&WB_GetMethodBooleaneOption},
2945 {CC"getMethodIntxOption",
2946 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2947 (void*)&WB_GetMethodIntxOption},
2948 {CC"getMethodUintxOption",
2949 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2950 (void*)&WB_GetMethodUintxOption},
2951 {CC"getMethodDoubleOption",
2952 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2953 (void*)&WB_GetMethodDoubleOption},
|