1008 env->SetObjectArrayElement(result, 2, obj);
1009
1010 return result;
1011 }
1012
1013 WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
1014 ResourceMark rm(THREAD);
1015 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1016 CHECK_JNI_EXCEPTION_(env, NULL);
1017 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1018 nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
1019 jobjectArray result = NULL;
1020 if (code == NULL) {
1021 return result;
1022 }
1023 int insts_size = code->insts_size();
1024
1025 ThreadToNativeFromVM ttn(thread);
1026 jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1027 CHECK_JNI_EXCEPTION_(env, NULL);
1028 result = env->NewObjectArray(4, clazz, NULL);
1029 if (result == NULL) {
1030 return result;
1031 }
1032
1033 CodeBlobStub stub(code);
1034 jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub);
1035 env->SetObjectArrayElement(result, 0, codeBlob);
1036
1037 jobject level = integerBox(thread, env, code->comp_level());
1038 CHECK_JNI_EXCEPTION_(env, NULL);
1039 env->SetObjectArrayElement(result, 1, level);
1040
1041 jbyteArray insts = env->NewByteArray(insts_size);
1042 CHECK_JNI_EXCEPTION_(env, NULL);
1043 env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
1044 env->SetObjectArrayElement(result, 2, insts);
1045
1046 jobject id = integerBox(thread, env, code->compile_id());
1047 CHECK_JNI_EXCEPTION_(env, NULL);
1048 env->SetObjectArrayElement(result, 3, id);
1049
1050 return result;
1051 WB_END
1052
1053 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) {
1054 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1055 BufferBlob* blob;
1056 int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob));
1057 if (full_size < size) {
1058 full_size += round_to(size - full_size, oopSize);
1059 }
1060 {
1061 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1062 blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type);
1063 ::new (blob) BufferBlob("WB::DummyBlob", full_size);
1064 }
1065 // Track memory usage statistic after releasing CodeCache_lock
1066 MemoryService::track_code_cache_memory_usage();
1067 return blob;
1068 }
1069
1116 env->SetObjectArrayElement(result, i, obj);
1117 ++i;
1118 }
1119 return result;
1120 WB_END
1121
1122 WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o))
1123 return CompileBroker::get_compilation_activity_mode();
1124 WB_END
1125
1126 WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr))
1127 if (addr == 0) {
1128 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
1129 "WB_GetCodeBlob: addr is null");
1130 }
1131 ThreadToNativeFromVM ttn(thread);
1132 CodeBlobStub stub((CodeBlob*) addr);
1133 return codeBlob2objectArray(thread, env, &stub);
1134 WB_END
1135
1136 WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o))
1137 return (jlong) Thread::current()->stack_size();
1138 WB_END
1139
1140 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o))
1141 JavaThread* t = JavaThread::current();
1142 return (jlong) t->stack_available(os::current_stack_pointer()) - (jlong) StackShadowPages * os::vm_page_size();
1143 WB_END
1144
1145 int WhiteBox::array_bytes_to_length(size_t bytes) {
1146 return Array<u1>::bytes_to_length(bytes);
1147 }
1148
1149 WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size))
1150 if (size < 0) {
1151 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1152 err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size));
1153 }
1154
1155 oop class_loader_oop = JNIHandles::resolve(class_loader);
1156 ClassLoaderData* cld = class_loader_oop != NULL
1157 ? java_lang_ClassLoader::loader_data(class_loader_oop)
1158 : ClassLoaderData::the_null_class_loader_data();
1159
1160 void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread);
1161
1162 return (jlong)(uintptr_t)metadata;
1163 WB_END
1164
1201
1202
1203 WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
1204 Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
1205 Monitor::_safepoint_check_always :
1206 Monitor::_safepoint_check_never;
1207 MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required),
1208 attemptedNoSafepointValue == JNI_TRUE);
1209 WB_END
1210
1211 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
1212 oop obj_oop = JNIHandles::resolve(obj);
1213 return (jboolean) obj_oop->mark()->has_monitor();
1214 WB_END
1215
1216 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
1217 VM_ForceSafepoint force_safepoint_op;
1218 VMThread::execute(&force_safepoint_op);
1219 WB_END
1220
1221 template <typename T>
1222 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1223 assert(value != NULL, "sanity");
1224 if (method == NULL || name == NULL) {
1225 return false;
1226 }
1227 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1228 CHECK_JNI_EXCEPTION_(env, false);
1229 methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1230 // can't be in VM when we call JNI
1231 ThreadToNativeFromVM ttnfv(thread);
1232 const char* flag_name = env->GetStringUTFChars(name, NULL);
1233 bool result = CompilerOracle::has_option_value(mh, flag_name, *value);
1234 env->ReleaseStringUTFChars(name, flag_name);
1235 return result;
1236 }
1237
1238 WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1239 bool result;
1240 if (GetMethodOption<bool> (thread, env, method, name, &result)) {
1492 (void*)&WB_GetStringVMFlag},
1493 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
1494 {CC"fullGC", CC"()V", (void*)&WB_FullGC },
1495 {CC"youngGC", CC"()V", (void*)&WB_YoungGC },
1496 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
1497 {CC"allocateMetaspace",
1498 CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace },
1499 {CC"freeMetaspace",
1500 CC"(Ljava/lang/ClassLoader;JJ)V", (void*)&WB_FreeMetaspace },
1501 {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC },
1502 {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC },
1503 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
1504 {CC"getNMethod0", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
1505 (void*)&WB_GetNMethod },
1506 {CC"forceNMethodSweep", CC"()V", (void*)&WB_ForceNMethodSweep },
1507 {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob },
1508 {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob },
1509 {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
1510 {CC"getCompilationActivityMode",
1511 CC"()I", (void*)&WB_GetCompilationActivityMode},
1512 {CC"getCodeBlob", CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob },
1513 {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize },
1514 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
1515 {CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls },
1516 {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
1517 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
1518 {CC"getMethodBooleanOption",
1519 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1520 (void*)&WB_GetMethodBooleaneOption},
1521 {CC"getMethodIntxOption",
1522 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1523 (void*)&WB_GetMethodIntxOption},
1524 {CC"getMethodUintxOption",
1525 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1526 (void*)&WB_GetMethodUintxOption},
1527 {CC"getMethodDoubleOption",
1528 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1529 (void*)&WB_GetMethodDoubleOption},
1530 {CC"getMethodStringOption",
1531 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1532 (void*)&WB_GetMethodStringOption},
1533 {CC"isShared", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
1534 {CC"areSharedStringsIgnored", CC"()Z", (void*)&WB_AreSharedStringsIgnored },
1535 };
1536
1537 #undef CC
|
1008 env->SetObjectArrayElement(result, 2, obj);
1009
1010 return result;
1011 }
1012
1013 WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
1014 ResourceMark rm(THREAD);
1015 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1016 CHECK_JNI_EXCEPTION_(env, NULL);
1017 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1018 nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
1019 jobjectArray result = NULL;
1020 if (code == NULL) {
1021 return result;
1022 }
1023 int insts_size = code->insts_size();
1024
1025 ThreadToNativeFromVM ttn(thread);
1026 jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1027 CHECK_JNI_EXCEPTION_(env, NULL);
1028 result = env->NewObjectArray(5, clazz, NULL);
1029 if (result == NULL) {
1030 return result;
1031 }
1032
1033 CodeBlobStub stub(code);
1034 jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub);
1035 env->SetObjectArrayElement(result, 0, codeBlob);
1036
1037 jobject level = integerBox(thread, env, code->comp_level());
1038 CHECK_JNI_EXCEPTION_(env, NULL);
1039 env->SetObjectArrayElement(result, 1, level);
1040
1041 jbyteArray insts = env->NewByteArray(insts_size);
1042 CHECK_JNI_EXCEPTION_(env, NULL);
1043 env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
1044 env->SetObjectArrayElement(result, 2, insts);
1045
1046 jobject id = integerBox(thread, env, code->compile_id());
1047 CHECK_JNI_EXCEPTION_(env, NULL);
1048 env->SetObjectArrayElement(result, 3, id);
1049
1050 jobject address = longBox(thread, env, (jlong) code);
1051 CHECK_JNI_EXCEPTION_(env, NULL);
1052 env->SetObjectArrayElement(result, 4, address);
1053
1054 return result;
1055 WB_END
1056
1057 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) {
1058 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1059 BufferBlob* blob;
1060 int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob));
1061 if (full_size < size) {
1062 full_size += round_to(size - full_size, oopSize);
1063 }
1064 {
1065 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1066 blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type);
1067 ::new (blob) BufferBlob("WB::DummyBlob", full_size);
1068 }
1069 // Track memory usage statistic after releasing CodeCache_lock
1070 MemoryService::track_code_cache_memory_usage();
1071 return blob;
1072 }
1073
1120 env->SetObjectArrayElement(result, i, obj);
1121 ++i;
1122 }
1123 return result;
1124 WB_END
1125
1126 WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o))
1127 return CompileBroker::get_compilation_activity_mode();
1128 WB_END
1129
1130 WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr))
1131 if (addr == 0) {
1132 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
1133 "WB_GetCodeBlob: addr is null");
1134 }
1135 ThreadToNativeFromVM ttn(thread);
1136 CodeBlobStub stub((CodeBlob*) addr);
1137 return codeBlob2objectArray(thread, env, &stub);
1138 WB_END
1139
1140 WB_ENTRY(jlong, WB_GetMethodData(JNIEnv* env, jobject wv, jobject method))
1141 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1142 CHECK_JNI_EXCEPTION_(env, 0);
1143 methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1144 return (jlong) mh->method_data();
1145 WB_END
1146
1147 WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o))
1148 return (jlong) Thread::current()->stack_size();
1149 WB_END
1150
1151 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o))
1152 JavaThread* t = JavaThread::current();
1153 return (jlong) t->stack_available(os::current_stack_pointer()) - (jlong) StackShadowPages * os::vm_page_size();
1154 WB_END
1155
1156
1157 int WhiteBox::array_bytes_to_length(size_t bytes) {
1158 return Array<u1>::bytes_to_length(bytes);
1159 }
1160
1161 WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size))
1162 if (size < 0) {
1163 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1164 err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size));
1165 }
1166
1167 oop class_loader_oop = JNIHandles::resolve(class_loader);
1168 ClassLoaderData* cld = class_loader_oop != NULL
1169 ? java_lang_ClassLoader::loader_data(class_loader_oop)
1170 : ClassLoaderData::the_null_class_loader_data();
1171
1172 void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread);
1173
1174 return (jlong)(uintptr_t)metadata;
1175 WB_END
1176
1213
1214
1215 WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
1216 Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
1217 Monitor::_safepoint_check_always :
1218 Monitor::_safepoint_check_never;
1219 MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required),
1220 attemptedNoSafepointValue == JNI_TRUE);
1221 WB_END
1222
1223 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
1224 oop obj_oop = JNIHandles::resolve(obj);
1225 return (jboolean) obj_oop->mark()->has_monitor();
1226 WB_END
1227
1228 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
1229 VM_ForceSafepoint force_safepoint_op;
1230 VMThread::execute(&force_safepoint_op);
1231 WB_END
1232
1233 WB_ENTRY(long, WB_GetConstantPool(JNIEnv* env, jobject wb, jclass klass))
1234 instanceKlassHandle ikh(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1235 return (long) ikh->constants();
1236 WB_END
1237
1238 template <typename T>
1239 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1240 assert(value != NULL, "sanity");
1241 if (method == NULL || name == NULL) {
1242 return false;
1243 }
1244 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1245 CHECK_JNI_EXCEPTION_(env, false);
1246 methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1247 // can't be in VM when we call JNI
1248 ThreadToNativeFromVM ttnfv(thread);
1249 const char* flag_name = env->GetStringUTFChars(name, NULL);
1250 bool result = CompilerOracle::has_option_value(mh, flag_name, *value);
1251 env->ReleaseStringUTFChars(name, flag_name);
1252 return result;
1253 }
1254
1255 WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1256 bool result;
1257 if (GetMethodOption<bool> (thread, env, method, name, &result)) {
1509 (void*)&WB_GetStringVMFlag},
1510 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
1511 {CC"fullGC", CC"()V", (void*)&WB_FullGC },
1512 {CC"youngGC", CC"()V", (void*)&WB_YoungGC },
1513 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
1514 {CC"allocateMetaspace",
1515 CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace },
1516 {CC"freeMetaspace",
1517 CC"(Ljava/lang/ClassLoader;JJ)V", (void*)&WB_FreeMetaspace },
1518 {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC },
1519 {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC },
1520 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
1521 {CC"getNMethod0", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
1522 (void*)&WB_GetNMethod },
1523 {CC"forceNMethodSweep", CC"()V", (void*)&WB_ForceNMethodSweep },
1524 {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob },
1525 {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob },
1526 {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
1527 {CC"getCompilationActivityMode",
1528 CC"()I", (void*)&WB_GetCompilationActivityMode},
1529 {CC"getMethodData0", CC"(Ljava/lang/reflect/Executable;)J",
1530 (void*)&WB_GetMethodData },
1531 {CC"getCodeBlob", CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob },
1532 {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize },
1533 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
1534 {CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls },
1535 {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
1536 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
1537 {CC"getConstantPool0", CC"(Ljava/lang/Class;)J", (void*)&WB_GetConstantPool },
1538 {CC"getMethodBooleanOption",
1539 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1540 (void*)&WB_GetMethodBooleaneOption},
1541 {CC"getMethodIntxOption",
1542 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1543 (void*)&WB_GetMethodIntxOption},
1544 {CC"getMethodUintxOption",
1545 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1546 (void*)&WB_GetMethodUintxOption},
1547 {CC"getMethodDoubleOption",
1548 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1549 (void*)&WB_GetMethodDoubleOption},
1550 {CC"getMethodStringOption",
1551 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1552 (void*)&WB_GetMethodStringOption},
1553 {CC"isShared", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
1554 {CC"areSharedStringsIgnored", CC"()Z", (void*)&WB_AreSharedStringsIgnored },
1555 };
1556
1557 #undef CC
|