1116 WB_END
1117
1118 WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
1119 Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
1120 Monitor::_safepoint_check_always :
1121 Monitor::_safepoint_check_never;
1122 MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required),
1123 attemptedNoSafepointValue == JNI_TRUE);
1124 WB_END
1125
1126 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
1127 oop obj_oop = JNIHandles::resolve(obj);
1128 return (jboolean) obj_oop->mark()->has_monitor();
1129 WB_END
1130
1131 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
1132 VM_ForceSafepoint force_safepoint_op;
1133 VMThread::execute(&force_safepoint_op);
1134 WB_END
1135
1136 //Some convenience methods to deal with objects from java
1137 int WhiteBox::offset_for_field(const char* field_name, oop object,
1138 Symbol* signature_symbol) {
1139 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1140 Thread* THREAD = Thread::current();
1141
1142 //Get the class of our object
1143 Klass* arg_klass = object->klass();
1144 //Turn it into an instance-klass
1145 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1146
1147 //Create symbols to look for in the class
1148 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1149 THREAD);
1150
1151 //To be filled in with an offset of the field we're looking for
1152 fieldDescriptor fd;
1153
1154 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1155 if (res == NULL) {
1316 CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace },
1317 {CC"freeMetaspace",
1318 CC"(Ljava/lang/ClassLoader;JJ)V", (void*)&WB_FreeMetaspace },
1319 {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC },
1320 {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC },
1321 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
1322 {CC"getNMethod", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
1323 (void*)&WB_GetNMethod },
1324 {CC"forceNMethodSweep0", CC"()Ljava/lang/Thread;", (void*)&WB_ForceNMethodSweep },
1325 {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob },
1326 {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob },
1327 {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
1328 {CC"getCompilationActivityMode",
1329 CC"()I", (void*)&WB_GetCompilationActivityMode},
1330 {CC"getCodeBlob", CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob },
1331 {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize },
1332 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
1333 {CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls },
1334 {CC"isMonitorInflated", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
1335 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
1336 };
1337
1338 #undef CC
1339
1340 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1341 {
1342 if (WhiteBoxAPI) {
1343 // Make sure that wbclass is loaded by the null classloader
1344 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1345 Handle loader(ikh->class_loader());
1346 if (loader.is_null()) {
1347 WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1348 WhiteBox::register_extended(env, wbclass, thread);
1349 WhiteBox::set_used();
1350 }
1351 }
1352 }
1353 JVM_END
|
1116 WB_END
1117
1118 WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
1119 Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
1120 Monitor::_safepoint_check_always :
1121 Monitor::_safepoint_check_never;
1122 MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required),
1123 attemptedNoSafepointValue == JNI_TRUE);
1124 WB_END
1125
1126 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
1127 oop obj_oop = JNIHandles::resolve(obj);
1128 return (jboolean) obj_oop->mark()->has_monitor();
1129 WB_END
1130
1131 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
1132 VM_ForceSafepoint force_safepoint_op;
1133 VMThread::execute(&force_safepoint_op);
1134 WB_END
1135
1136 template <typename T>
1137 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, methodHandle* mh, jstring name, T* value) {
1138 assert(mh != NULL, "sanity");
1139 assert(value != NULL, "sanity");
1140 if (name == NULL) {
1141 return false;
1142 }
1143 // can't be in VM when we call JNI
1144 ThreadToNativeFromVM ttnfv(thread);
1145 const char* flag_name = env->GetStringUTFChars(name, NULL);
1146 bool result = CompilerOracle::has_option_value(*mh, flag_name, *value);
1147 env->ReleaseStringUTFChars(name, flag_name);
1148 return result;
1149 }
1150
1151 WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1152 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1153 CHECK_JNI_EXCEPTION_(env, NULL);
1154 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1155 bool result;
1156 if (GetMethodOption<bool> (thread, env, &mh, name, &result)) {
1157 // can't be in VM when we call JNI
1158 ThreadToNativeFromVM ttnfv(thread);
1159 return booleanBox(thread, env, result);
1160 }
1161 return NULL;
1162 WB_END
1163
1164 WB_ENTRY(jobject, WB_GetMethodIntxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1165 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1166 CHECK_JNI_EXCEPTION_(env, NULL);
1167 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1168 intx result;
1169 if (GetMethodOption <intx> (thread, env, &mh, name, &result)) {
1170 // can't be in VM when we call JNI
1171 ThreadToNativeFromVM ttnfv(thread);
1172 return longBox(thread, env, result);
1173 }
1174 return NULL;
1175 WB_END
1176
1177 WB_ENTRY(jobject, WB_GetMethodUintxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1178 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1179 CHECK_JNI_EXCEPTION_(env, NULL);
1180 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1181 uintx result;
1182 if (GetMethodOption <uintx> (thread, env, &mh, name, &result)) {
1183 // can't be in VM when we call JNI
1184 ThreadToNativeFromVM ttnfv(thread);
1185 return longBox(thread, env, result);
1186 }
1187 return NULL;
1188 WB_END
1189
1190 WB_ENTRY(jobject, WB_GetMethodDoubleOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1191 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1192 CHECK_JNI_EXCEPTION_(env, NULL);
1193 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1194 double result;
1195 if (GetMethodOption <double> (thread, env, &mh, name, &result)) {
1196 // can't be in VM when we call JNI
1197 ThreadToNativeFromVM ttnfv(thread);
1198 return doubleBox(thread, env, result);
1199 }
1200 return NULL;
1201 WB_END
1202
1203 WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1204 jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1205 CHECK_JNI_EXCEPTION_(env, NULL);
1206 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1207 ccstr ccstrResult;
1208 if (GetMethodOption <ccstr> (thread, env, &mh, name, &ccstrResult)) {
1209 // can't be in VM when we call JNI
1210 ThreadToNativeFromVM ttnfv(thread);
1211 jstring result = env->NewStringUTF(ccstrResult);
1212 CHECK_JNI_EXCEPTION_(env, NULL);
1213 return result;
1214 }
1215 return NULL;
1216 WB_END
1217
1218 //Some convenience methods to deal with objects from java
1219 int WhiteBox::offset_for_field(const char* field_name, oop object,
1220 Symbol* signature_symbol) {
1221 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1222 Thread* THREAD = Thread::current();
1223
1224 //Get the class of our object
1225 Klass* arg_klass = object->klass();
1226 //Turn it into an instance-klass
1227 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1228
1229 //Create symbols to look for in the class
1230 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1231 THREAD);
1232
1233 //To be filled in with an offset of the field we're looking for
1234 fieldDescriptor fd;
1235
1236 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1237 if (res == NULL) {
1398 CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace },
1399 {CC"freeMetaspace",
1400 CC"(Ljava/lang/ClassLoader;JJ)V", (void*)&WB_FreeMetaspace },
1401 {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC },
1402 {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC },
1403 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
1404 {CC"getNMethod", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
1405 (void*)&WB_GetNMethod },
1406 {CC"forceNMethodSweep0", CC"()Ljava/lang/Thread;", (void*)&WB_ForceNMethodSweep },
1407 {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob },
1408 {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob },
1409 {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
1410 {CC"getCompilationActivityMode",
1411 CC"()I", (void*)&WB_GetCompilationActivityMode},
1412 {CC"getCodeBlob", CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob },
1413 {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize },
1414 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
1415 {CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls },
1416 {CC"isMonitorInflated", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated },
1417 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint },
1418 {CC"getMethodBooleanOption",
1419 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1420 (void*)&WB_GetMethodBooleaneOption},
1421 {CC"getMethodIntxOption",
1422 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1423 (void*)&WB_GetMethodIntxOption},
1424 {CC"getMethodUintxOption",
1425 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1426 (void*)&WB_GetMethodUintxOption},
1427 {CC"getMethodDoubleOption",
1428 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1429 (void*)&WB_GetMethodDoubleOption},
1430 {CC"getMethodStringOption",
1431 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1432 (void*)&WB_GetMethodStringOption},
1433 };
1434
1435 #undef CC
1436
1437 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1438 {
1439 if (WhiteBoxAPI) {
1440 // Make sure that wbclass is loaded by the null classloader
1441 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1442 Handle loader(ikh->class_loader());
1443 if (loader.is_null()) {
1444 WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1445 WhiteBox::register_extended(env, wbclass, thread);
1446 WhiteBox::set_used();
1447 }
1448 }
1449 }
1450 JVM_END
|