22 *
23 */
24
25 #include "precompiled.hpp"
26
27 #include <new>
28
29 #include "classfile/classLoaderDataGraph.hpp"
30 #include "classfile/modules.hpp"
31 #include "classfile/protectionDomainCache.hpp"
32 #include "classfile/stringTable.hpp"
33 #include "code/codeCache.hpp"
34 #include "compiler/methodMatcher.hpp"
35 #include "compiler/directivesParser.hpp"
36 #include "gc/shared/gcConfig.hpp"
37 #include "gc/shared/genCollectedHeap.hpp"
38 #include "jvmtifiles/jvmtiEnv.hpp"
39 #include "memory/heapShared.inline.hpp"
40 #include "memory/metaspaceShared.hpp"
41 #include "memory/metadataFactory.hpp"
42 #include "memory/iterator.hpp"
43 #include "memory/resourceArea.hpp"
44 #include "memory/universe.hpp"
45 #include "memory/oopFactory.hpp"
46 #include "oops/array.hpp"
47 #include "oops/constantPool.inline.hpp"
48 #include "oops/method.inline.hpp"
49 #include "oops/objArrayKlass.hpp"
50 #include "oops/objArrayOop.inline.hpp"
51 #include "oops/oop.inline.hpp"
52 #include "oops/typeArrayOop.inline.hpp"
53 #include "prims/resolvedMethodTable.hpp"
54 #include "prims/wbtestmethods/parserTests.hpp"
55 #include "prims/whitebox.inline.hpp"
56 #include "runtime/arguments.hpp"
57 #include "runtime/compilationPolicy.hpp"
58 #include "runtime/deoptimization.hpp"
59 #include "runtime/fieldDescriptor.inline.hpp"
60 #include "runtime/flags/jvmFlag.hpp"
61 #include "runtime/frame.inline.hpp"
62 #include "runtime/handles.inline.hpp"
63 #include "runtime/handshake.hpp"
64 #include "runtime/interfaceSupport.inline.hpp"
65 #include "runtime/javaCalls.hpp"
66 #include "runtime/jniHandles.inline.hpp"
67 #include "runtime/os.hpp"
68 #include "runtime/sweeper.hpp"
69 #include "runtime/thread.hpp"
70 #include "runtime/threadSMR.hpp"
71 #include "runtime/vm_version.hpp"
1752
1753 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
1754 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1755 ConstantPool* cp = ik->constants();
1756 if (cp->cache() == NULL) {
1757 THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
1758 }
1759 jint cpci = index;
1760 jint cpciTag = ConstantPool::CPCACHE_INDEX_TAG;
1761 if (cpciTag > cpci || cpci >= cp->cache()->length() + cpciTag) {
1762 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool cache index is out of range");
1763 }
1764 jint cpi = cp->remap_instruction_operand_from_cache(cpci);
1765 return cpi;
1766 WB_END
1767
1768 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1769 return ConstantPool::encode_invokedynamic_index(index);
1770 WB_END
1771
1772 WB_ENTRY(void, WB_ClearInlineCaches(JNIEnv* env, jobject wb, jboolean preserve_static_stubs))
1773 VM_ClearICs clear_ics(preserve_static_stubs == JNI_TRUE);
1774 VMThread::execute(&clear_ics);
1775 WB_END
1776
1777 template <typename T>
1778 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1779 assert(value != NULL, "sanity");
1780 if (method == NULL || name == NULL) {
1781 return false;
1782 }
1783 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1784 CHECK_JNI_EXCEPTION_(env, false);
1785 methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1786 // can't be in VM when we call JNI
1787 ThreadToNativeFromVM ttnfv(thread);
1788 const char* flag_name = env->GetStringUTFChars(name, NULL);
1789 CHECK_JNI_EXCEPTION_(env, false);
1790 bool result = CompilerOracle::has_option_value(mh, flag_name, *value);
1791 env->ReleaseStringUTFChars(name, flag_name);
2277 {CC"DefineModule", CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2278 (void*)&WB_DefineModule },
2279 {CC"AddModuleExports", CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2280 (void*)&WB_AddModuleExports },
2281 {CC"AddReadsModule", CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2282 (void*)&WB_AddReadsModule },
2283 {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2284 (void*)&WB_AddModuleExportsToAllUnnamed },
2285 {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2286 (void*)&WB_AddModuleExportsToAll },
2287 {CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls },
2288 {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
2289 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
2290 {CC"getConstantPool0", CC"(Ljava/lang/Class;)J", (void*)&WB_GetConstantPool },
2291 {CC"getConstantPoolCacheIndexTag0", CC"()I", (void*)&WB_GetConstantPoolCacheIndexTag},
2292 {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_GetConstantPoolCacheLength},
2293 {CC"remapInstructionOperandFromCPCache0",
2294 CC"(Ljava/lang/Class;I)I", (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2295 {CC"encodeConstantPoolIndyIndex0",
2296 CC"(I)I", (void*)&WB_ConstantPoolEncodeIndyIndex},
2297 {CC"getMethodBooleanOption",
2298 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2299 (void*)&WB_GetMethodBooleaneOption},
2300 {CC"getMethodIntxOption",
2301 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2302 (void*)&WB_GetMethodIntxOption},
2303 {CC"getMethodUintxOption",
2304 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2305 (void*)&WB_GetMethodUintxOption},
2306 {CC"getMethodDoubleOption",
2307 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2308 (void*)&WB_GetMethodDoubleOption},
2309 {CC"getMethodStringOption",
2310 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2311 (void*)&WB_GetMethodStringOption},
2312 {CC"getDefaultArchivePath", CC"()Ljava/lang/String;",
2313 (void*)&WB_GetDefaultArchivePath},
2314 {CC"isSharingEnabled", CC"()Z", (void*)&WB_IsSharingEnabled},
2315 {CC"isShared", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
2316 {CC"isSharedClass", CC"(Ljava/lang/Class;)Z", (void*)&WB_IsSharedClass },
|
22 *
23 */
24
25 #include "precompiled.hpp"
26
27 #include <new>
28
29 #include "classfile/classLoaderDataGraph.hpp"
30 #include "classfile/modules.hpp"
31 #include "classfile/protectionDomainCache.hpp"
32 #include "classfile/stringTable.hpp"
33 #include "code/codeCache.hpp"
34 #include "compiler/methodMatcher.hpp"
35 #include "compiler/directivesParser.hpp"
36 #include "gc/shared/gcConfig.hpp"
37 #include "gc/shared/genCollectedHeap.hpp"
38 #include "jvmtifiles/jvmtiEnv.hpp"
39 #include "memory/heapShared.inline.hpp"
40 #include "memory/metaspaceShared.hpp"
41 #include "memory/metadataFactory.hpp"
42 #include "memory/iterator.inline.hpp"
43 #include "memory/resourceArea.hpp"
44 #include "memory/universe.hpp"
45 #include "memory/oopFactory.hpp"
46 #include "oops/array.hpp"
47 #include "oops/compressedOops.inline.hpp"
48 #include "oops/constantPool.inline.hpp"
49 #include "oops/method.inline.hpp"
50 #include "oops/objArrayKlass.hpp"
51 #include "oops/objArrayOop.inline.hpp"
52 #include "oops/oop.inline.hpp"
53 #include "oops/objArrayOop.inline.hpp"
54 #include "oops/typeArrayOop.inline.hpp"
55 #include "prims/resolvedMethodTable.hpp"
56 #include "prims/wbtestmethods/parserTests.hpp"
57 #include "prims/whitebox.inline.hpp"
58 #include "runtime/arguments.hpp"
59 #include "runtime/compilationPolicy.hpp"
60 #include "runtime/deoptimization.hpp"
61 #include "runtime/fieldDescriptor.inline.hpp"
62 #include "runtime/flags/jvmFlag.hpp"
63 #include "runtime/frame.inline.hpp"
64 #include "runtime/handles.inline.hpp"
65 #include "runtime/handshake.hpp"
66 #include "runtime/interfaceSupport.inline.hpp"
67 #include "runtime/javaCalls.hpp"
68 #include "runtime/jniHandles.inline.hpp"
69 #include "runtime/os.hpp"
70 #include "runtime/sweeper.hpp"
71 #include "runtime/thread.hpp"
72 #include "runtime/threadSMR.hpp"
73 #include "runtime/vm_version.hpp"
1754
1755 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
1756 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1757 ConstantPool* cp = ik->constants();
1758 if (cp->cache() == NULL) {
1759 THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
1760 }
1761 jint cpci = index;
1762 jint cpciTag = ConstantPool::CPCACHE_INDEX_TAG;
1763 if (cpciTag > cpci || cpci >= cp->cache()->length() + cpciTag) {
1764 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool cache index is out of range");
1765 }
1766 jint cpi = cp->remap_instruction_operand_from_cache(cpci);
1767 return cpi;
1768 WB_END
1769
1770 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1771 return ConstantPool::encode_invokedynamic_index(index);
1772 WB_END
1773
1774 WB_ENTRY(jobjectArray, WB_getObjectsViaKlassOopMaps(JNIEnv* env, jobject wb, jobject thing))
1775 oop aoop = JNIHandles::resolve(thing);
1776 if (!aoop->is_instance()) {
1777 return NULL;
1778 }
1779 instanceHandle ih(THREAD, (instanceOop) aoop);
1780 InstanceKlass* klass = InstanceKlass::cast(aoop->klass());
1781 if (klass->nonstatic_oop_map_count() == 0) {
1782 return NULL;
1783 }
1784 const OopMapBlock* map = klass->start_of_nonstatic_oop_maps();
1785 const OopMapBlock* const end = map + klass->nonstatic_oop_map_count();
1786 int oop_count = 0;
1787 while (map < end) {
1788 oop_count += map->count();
1789 map++;
1790 }
1791
1792 objArrayOop result_array =
1793 oopFactory::new_objArray(SystemDictionary::Object_klass(), oop_count, CHECK_NULL);
1794 map = klass->start_of_nonstatic_oop_maps();
1795 instanceOop ioop = ih();
1796 int index = 0;
1797 while (map < end) {
1798 int offset = map->offset();
1799 for (unsigned int j = 0; j < map->count(); j++) {
1800 result_array->obj_at_put(index++, ioop->obj_field(offset));
1801 offset += heapOopSize;
1802 }
1803 map++;
1804 }
1805 return (jobjectArray)JNIHandles::make_local(env, result_array);
1806 WB_END
1807
1808 class CollectOops : public BasicOopIterateClosure {
1809 public:
1810 GrowableArray<Handle>* array;
1811
1812 objArrayOop create_results(TRAPS) {
1813 objArrayOop result_array =
1814 oopFactory::new_objArray(SystemDictionary::Object_klass(), array->length(), CHECK_NULL);
1815 for (int i = 0 ; i < array->length(); i++) {
1816 result_array->obj_at_put(i, array->at(i)());
1817 }
1818 return result_array;
1819 }
1820
1821 jobjectArray create_jni_result(JNIEnv* env, TRAPS) {
1822 return (jobjectArray)JNIHandles::make_local(env, create_results(THREAD));
1823 }
1824
1825 void add_oop(oop o) {
1826 // Value might be oop, but JLS can't see as Object, just iterate through it...
1827 if (o != NULL && o->is_value()) {
1828 o->oop_iterate(this);
1829 } else {
1830 array->append(Handle(Thread::current(), o));
1831 }
1832 }
1833
1834 void do_oop(oop* o) { add_oop(*o); }
1835 void do_oop(narrowOop* v) { add_oop(CompressedOops::decode(*v)); }
1836 };
1837
1838
1839 WB_ENTRY(jobjectArray, WB_getObjectsViaOopIterator(JNIEnv* env, jobject wb, jobject thing))
1840 ResourceMark rm(THREAD);
1841 GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1842 CollectOops collectOops;
1843 collectOops.array = array;
1844
1845 JNIHandles::resolve(thing)->oop_iterate(&collectOops);
1846
1847 return collectOops.create_jni_result(env, THREAD);
1848 WB_END
1849
1850 WB_ENTRY(jobjectArray, WB_getObjectsViaFrameOopIterator(JNIEnv* env, jobject wb, jint depth))
1851 ResourceMark rm(THREAD);
1852 GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1853 CollectOops collectOops;
1854 collectOops.array = array;
1855 StackFrameStream sfs(thread);
1856 while (depth > 0) { // Skip the native WB API frame
1857 sfs.next();
1858 frame* f = sfs.current();
1859 f->oops_do(&collectOops, NULL, sfs.register_map());
1860 depth--;
1861 }
1862 return collectOops.create_jni_result(env, THREAD);
1863 WB_END
1864
1865
1866 WB_ENTRY(void, WB_ClearInlineCaches(JNIEnv* env, jobject wb, jboolean preserve_static_stubs))
1867 VM_ClearICs clear_ics(preserve_static_stubs == JNI_TRUE);
1868 VMThread::execute(&clear_ics);
1869 WB_END
1870
1871 template <typename T>
1872 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1873 assert(value != NULL, "sanity");
1874 if (method == NULL || name == NULL) {
1875 return false;
1876 }
1877 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1878 CHECK_JNI_EXCEPTION_(env, false);
1879 methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1880 // can't be in VM when we call JNI
1881 ThreadToNativeFromVM ttnfv(thread);
1882 const char* flag_name = env->GetStringUTFChars(name, NULL);
1883 CHECK_JNI_EXCEPTION_(env, false);
1884 bool result = CompilerOracle::has_option_value(mh, flag_name, *value);
1885 env->ReleaseStringUTFChars(name, flag_name);
2371 {CC"DefineModule", CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2372 (void*)&WB_DefineModule },
2373 {CC"AddModuleExports", CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2374 (void*)&WB_AddModuleExports },
2375 {CC"AddReadsModule", CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2376 (void*)&WB_AddReadsModule },
2377 {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2378 (void*)&WB_AddModuleExportsToAllUnnamed },
2379 {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2380 (void*)&WB_AddModuleExportsToAll },
2381 {CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls },
2382 {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
2383 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
2384 {CC"getConstantPool0", CC"(Ljava/lang/Class;)J", (void*)&WB_GetConstantPool },
2385 {CC"getConstantPoolCacheIndexTag0", CC"()I", (void*)&WB_GetConstantPoolCacheIndexTag},
2386 {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_GetConstantPoolCacheLength},
2387 {CC"remapInstructionOperandFromCPCache0",
2388 CC"(Ljava/lang/Class;I)I", (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2389 {CC"encodeConstantPoolIndyIndex0",
2390 CC"(I)I", (void*)&WB_ConstantPoolEncodeIndyIndex},
2391 {CC"getObjectsViaKlassOopMaps0",
2392 CC"(Ljava/lang/Object;)[Ljava/lang/Object;", (void*)&WB_getObjectsViaKlassOopMaps},
2393 {CC"getObjectsViaOopIterator0",
2394 CC"(Ljava/lang/Object;)[Ljava/lang/Object;",(void*)&WB_getObjectsViaOopIterator},
2395 {CC"getObjectsViaFrameOopIterator",
2396 CC"(I)[Ljava/lang/Object;", (void*)&WB_getObjectsViaFrameOopIterator},
2397 {CC"getMethodBooleanOption",
2398 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2399 (void*)&WB_GetMethodBooleaneOption},
2400 {CC"getMethodIntxOption",
2401 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2402 (void*)&WB_GetMethodIntxOption},
2403 {CC"getMethodUintxOption",
2404 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2405 (void*)&WB_GetMethodUintxOption},
2406 {CC"getMethodDoubleOption",
2407 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2408 (void*)&WB_GetMethodDoubleOption},
2409 {CC"getMethodStringOption",
2410 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2411 (void*)&WB_GetMethodStringOption},
2412 {CC"getDefaultArchivePath", CC"()Ljava/lang/String;",
2413 (void*)&WB_GetDefaultArchivePath},
2414 {CC"isSharingEnabled", CC"()Z", (void*)&WB_IsSharingEnabled},
2415 {CC"isShared", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
2416 {CC"isSharedClass", CC"(Ljava/lang/Class;)Z", (void*)&WB_IsSharedClass },
|