< prev index next >

src/hotspot/share/prims/jvmtiEnvBase.cpp

Print this page
rev 60137 : 8227745: Enable Escape Analysis for Better Performance in the Presence of JVMTI Agents
Reviewed-by: mdoerr, goetz


1292         !jt->is_hidden_from_external_view()) {
1293       ++_final_thread_count;
1294       // Handle block of the calling thread is used to create local refs.
1295       _collector.fill_frames((jthread)JNIHandles::make_local(_calling_thread, thread_oop),
1296                              jt, thread_oop);
1297     }
1298   }
1299   _collector.allocate_and_fill_stacks(_final_thread_count);
1300 }
1301 
1302 // Verifies that the top frame is a java frame in an expected state.
1303 // Deoptimizes frame if needed.
1304 // Checks that the frame method signature matches the return type (tos).
1305 // HandleMark must be defined in the caller only.
1306 // It is to keep a ret_ob_h handle alive after return to the caller.
1307 jvmtiError
1308 JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
1309                               jvalue value, TosState tos, Handle* ret_ob_h) {
1310   ResourceMark rm(current_thread);
1311 







1312   vframe *vf = vframeFor(java_thread, 0);
1313   NULL_CHECK(vf, JVMTI_ERROR_NO_MORE_FRAMES);
1314 
1315   javaVFrame *jvf = (javaVFrame*) vf;
1316   if (!vf->is_java_frame() || jvf->method()->is_native()) {
1317     return JVMTI_ERROR_OPAQUE_FRAME;
1318   }
1319 
1320   // If the frame is a compiled one, need to deoptimize it.
1321   if (vf->is_compiled_frame()) {
1322     if (!vf->fr().can_be_deoptimized()) {
1323       return JVMTI_ERROR_OPAQUE_FRAME;
1324     }
1325     Deoptimization::deoptimize_frame(java_thread, jvf->fr().id());






1326   }
1327 
1328   // Get information about method return type
1329   Symbol* signature = jvf->method()->signature();
1330 
1331   ResultTypeFinder rtf(signature);
1332   TosState fr_tos = as_TosState(rtf.type());
1333   if (fr_tos != tos) {
1334     if (tos != itos || (fr_tos != btos && fr_tos != ztos && fr_tos != ctos && fr_tos != stos)) {
1335       return JVMTI_ERROR_TYPE_MISMATCH;
1336     }
1337   }
1338 
1339   // Check that the jobject class matches the return type signature.
1340   jobject jobj = value.l;
1341   if (tos == atos && jobj != NULL) { // NULL reference is allowed
1342     Handle ob_h(current_thread, JNIHandles::resolve_external_guard(jobj));
1343     NULL_CHECK(ob_h, JVMTI_ERROR_INVALID_OBJECT);
1344     Klass* ob_k = ob_h()->klass();
1345     NULL_CHECK(ob_k, JVMTI_ERROR_INVALID_OBJECT);




1292         !jt->is_hidden_from_external_view()) {
1293       ++_final_thread_count;
1294       // Handle block of the calling thread is used to create local refs.
1295       _collector.fill_frames((jthread)JNIHandles::make_local(_calling_thread, thread_oop),
1296                              jt, thread_oop);
1297     }
1298   }
1299   _collector.allocate_and_fill_stacks(_final_thread_count);
1300 }
1301 
1302 // Verifies that the top frame is a java frame in an expected state.
1303 // Deoptimizes frame if needed.
1304 // Checks that the frame method signature matches the return type (tos).
1305 // HandleMark must be defined in the caller only.
1306 // It is to keep a ret_ob_h handle alive after return to the caller.
1307 jvmtiError
1308 JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
1309                               jvalue value, TosState tos, Handle* ret_ob_h) {
1310   ResourceMark rm(current_thread);
1311 
1312   if (java_thread->frames_to_pop_failed_realloc() > 0) {
1313     // VM is in the process of popping the top frame, because it has scalar replaced objects
1314     // which could not be reallocated on the heap.
1315     // Return JVMTI_ERROR_OUT_OF_MEMORY to avoid interfering with the VM.
1316     return JVMTI_ERROR_OUT_OF_MEMORY;
1317   }
1318 
1319   vframe *vf = vframeFor(java_thread, 0);
1320   NULL_CHECK(vf, JVMTI_ERROR_NO_MORE_FRAMES);
1321 
1322   javaVFrame *jvf = (javaVFrame*) vf;
1323   if (!vf->is_java_frame() || jvf->method()->is_native()) {
1324     return JVMTI_ERROR_OPAQUE_FRAME;
1325   }
1326 
1327   // If the frame is a compiled one, need to deoptimize it.
1328   if (vf->is_compiled_frame()) {
1329     if (!vf->fr().can_be_deoptimized()) {
1330       return JVMTI_ERROR_OPAQUE_FRAME;
1331     }
1332     Deoptimization::deoptimize_frame(java_thread, jvf->fr().id());
1333     // eagerly reallocate scalar replaced objects
1334     EscapeBarrier eb(current_thread, java_thread, true);
1335     if (!eb.deoptimize_objects(jvf->fr().id())) {
1336       // reallocation of scalar replaced objects failed -> return with error
1337       return JVMTI_ERROR_OUT_OF_MEMORY;
1338     }
1339   }
1340 
1341   // Get information about method return type
1342   Symbol* signature = jvf->method()->signature();
1343 
1344   ResultTypeFinder rtf(signature);
1345   TosState fr_tos = as_TosState(rtf.type());
1346   if (fr_tos != tos) {
1347     if (tos != itos || (fr_tos != btos && fr_tos != ztos && fr_tos != ctos && fr_tos != stos)) {
1348       return JVMTI_ERROR_TYPE_MISMATCH;
1349     }
1350   }
1351 
1352   // Check that the jobject class matches the return type signature.
1353   jobject jobj = value.l;
1354   if (tos == atos && jobj != NULL) { // NULL reference is allowed
1355     Handle ob_h(current_thread, JNIHandles::resolve_external_guard(jobj));
1356     NULL_CHECK(ob_h, JVMTI_ERROR_INVALID_OBJECT);
1357     Klass* ob_k = ob_h()->klass();
1358     NULL_CHECK(ob_k, JVMTI_ERROR_INVALID_OBJECT);


< prev index next >