< prev index next >

src/hotspot/share/prims/jvmtiEnv.cpp

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


1189                                      jni_reference(context_class_loader);
1190   info_ptr->thread_group = jni_reference(thread_group);
1191 
1192   return JVMTI_ERROR_NONE;
1193 } /* end GetThreadInfo */
1194 
1195 
1196 // Threads_lock NOT held, java_thread not protected by lock
1197 // java_thread - pre-checked
1198 // owned_monitor_count_ptr - pre-checked for NULL
1199 // owned_monitors_ptr - pre-checked for NULL
1200 jvmtiError
1201 JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {
1202   jvmtiError err = JVMTI_ERROR_NONE;
1203   JavaThread* calling_thread = JavaThread::current();
1204 
1205   // growable array of jvmti monitors info on the C-heap
1206   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1207       new (ResourceObj::C_HEAP, mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1208 





1209   // It is only safe to perform the direct operation on the current
1210   // thread. All other usage needs to use a direct handshake for safety.
1211   if (java_thread == calling_thread) {
1212     err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1213   } else {
1214     // get owned monitors info with handshake
1215     GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1216     bool executed = Handshake::execute_direct(&op, java_thread);
1217     err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1218   }
1219   jint owned_monitor_count = owned_monitors_list->length();
1220   if (err == JVMTI_ERROR_NONE) {
1221     if ((err = allocate(owned_monitor_count * sizeof(jobject *),
1222                       (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) {
1223       // copy into the returned array
1224       for (int i = 0; i < owned_monitor_count; i++) {
1225         (*owned_monitors_ptr)[i] =
1226           ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1227       }
1228       *owned_monitor_count_ptr = owned_monitor_count;


1234   }
1235   delete owned_monitors_list;
1236 
1237   return err;
1238 } /* end GetOwnedMonitorInfo */
1239 
1240 
1241 // Threads_lock NOT held, java_thread not protected by lock
1242 // java_thread - pre-checked
1243 // monitor_info_count_ptr - pre-checked for NULL
1244 // monitor_info_ptr - pre-checked for NULL
1245 jvmtiError
1246 JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
1247   jvmtiError err = JVMTI_ERROR_NONE;
1248   JavaThread* calling_thread = JavaThread::current();
1249 
1250   // growable array of jvmti monitors info on the C-heap
1251   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1252          new (ResourceObj::C_HEAP, mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1253 





1254   // It is only safe to perform the direct operation on the current
1255   // thread. All other usage needs to use a direct handshake for safety.
1256   if (java_thread == calling_thread) {
1257     err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1258   } else {
1259     // get owned monitors info with handshake
1260     GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1261     bool executed = Handshake::execute_direct(&op, java_thread);
1262     err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1263   }
1264 
1265   jint owned_monitor_count = owned_monitors_list->length();
1266   if (err == JVMTI_ERROR_NONE) {
1267     if ((err = allocate(owned_monitor_count * sizeof(jvmtiMonitorStackDepthInfo),
1268                       (unsigned char**)monitor_info_ptr)) == JVMTI_ERROR_NONE) {
1269       // copy to output array.
1270       for (int i = 0; i < owned_monitor_count; i++) {
1271         (*monitor_info_ptr)[i].monitor =
1272           ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1273         (*monitor_info_ptr)[i].stack_depth =


1650     return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
1651   }
1652   // Check to see if a PopFrame was already in progress
1653   if (java_thread->popframe_condition() != JavaThread::popframe_inactive) {
1654     // Probably possible for JVMTI clients to trigger this, but the
1655     // JPDA backend shouldn't allow this to happen
1656     return JVMTI_ERROR_INTERNAL;
1657   }
1658 
1659   {
1660     // Was workaround bug
1661     //    4812902: popFrame hangs if the method is waiting at a synchronize
1662     // Catch this condition and return an error to avoid hanging.
1663     // Now JVMTI spec allows an implementation to bail out with an opaque frame error.
1664     OSThread* osThread = java_thread->osthread();
1665     if (osThread->get_state() == MONITOR_WAIT) {
1666       return JVMTI_ERROR_OPAQUE_FRAME;
1667     }
1668   }
1669 







1670   {
1671     ResourceMark rm(current_thread);
1672     // Check if there are more than one Java frame in this thread, that the top two frames
1673     // are Java (not native) frames, and that there is no intervening VM frame
1674     int frame_count = 0;
1675     bool is_interpreted[2];
1676     intptr_t *frame_sp[2];
1677     // The 2-nd arg of constructor is needed to stop iterating at java entry frame.
1678     for (vframeStream vfs(java_thread, true); !vfs.at_end(); vfs.next()) {
1679       methodHandle mh(current_thread, vfs.method());
1680       if (mh->is_native()) return(JVMTI_ERROR_OPAQUE_FRAME);
1681       is_interpreted[frame_count] = vfs.is_interpreted_frame();
1682       frame_sp[frame_count] = vfs.frame_id();
1683       if (++frame_count > 1) break;
1684     }
1685     if (frame_count < 2)  {
1686       // We haven't found two adjacent non-native Java frames on the top.
1687       // There can be two situations here:
1688       //  1. There are no more java frames
1689       //  2. Two top java frames are separated by non-java native frames
1690       if(vframeFor(java_thread, 1) == NULL) {
1691         return JVMTI_ERROR_NO_MORE_FRAMES;
1692       } else {
1693         // Intervening non-java native or VM frames separate java frames.
1694         // Current implementation does not support this. See bug #5031735.
1695         // In theory it is possible to pop frames in such cases.
1696         return JVMTI_ERROR_OPAQUE_FRAME;
1697       }
1698     }
1699 
1700     // If any of the top 2 frames is a compiled one, need to deoptimize it

1701     for (int i = 0; i < 2; i++) {
1702       if (!is_interpreted[i]) {
1703         Deoptimization::deoptimize_frame(java_thread, frame_sp[i]);





1704       }
1705     }
1706 
1707     // Update the thread state to reflect that the top frame is popped
1708     // so that cur_stack_depth is maintained properly and all frameIDs
1709     // are invalidated.
1710     // The current frame will be popped later when the suspended thread
1711     // is resumed and right before returning from VM to Java.
1712     // (see call_VM_base() in assembler_<cpu>.cpp).
1713 
1714     // It's fine to update the thread state here because no JVMTI events
1715     // shall be posted for this PopFrame.
1716 
1717     // It is only safe to perform the direct operation on the current
1718     // thread. All other usage needs to use a vm-safepoint-op for safety.
1719     if (java_thread == JavaThread::current()) {
1720       state->update_for_pop_top_frame();
1721     } else {
1722       VM_UpdateForPopTopFrame op(state);
1723       VMThread::execute(&op);




1189                                      jni_reference(context_class_loader);
1190   info_ptr->thread_group = jni_reference(thread_group);
1191 
1192   return JVMTI_ERROR_NONE;
1193 } /* end GetThreadInfo */
1194 
1195 
1196 // Threads_lock NOT held, java_thread not protected by lock
1197 // java_thread - pre-checked
1198 // owned_monitor_count_ptr - pre-checked for NULL
1199 // owned_monitors_ptr - pre-checked for NULL
1200 jvmtiError
1201 JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {
1202   jvmtiError err = JVMTI_ERROR_NONE;
1203   JavaThread* calling_thread = JavaThread::current();
1204 
1205   // growable array of jvmti monitors info on the C-heap
1206   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1207       new (ResourceObj::C_HEAP, mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1208 
1209   EscapeBarrier eb(calling_thread, java_thread, true);
1210   if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1211     return JVMTI_ERROR_OUT_OF_MEMORY;
1212   }
1213 
1214   // It is only safe to perform the direct operation on the current
1215   // thread. All other usage needs to use a direct handshake for safety.
1216   if (java_thread == calling_thread) {
1217     err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1218   } else {
1219     // get owned monitors info with handshake
1220     GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1221     bool executed = Handshake::execute_direct(&op, java_thread);
1222     err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1223   }
1224   jint owned_monitor_count = owned_monitors_list->length();
1225   if (err == JVMTI_ERROR_NONE) {
1226     if ((err = allocate(owned_monitor_count * sizeof(jobject *),
1227                       (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) {
1228       // copy into the returned array
1229       for (int i = 0; i < owned_monitor_count; i++) {
1230         (*owned_monitors_ptr)[i] =
1231           ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1232       }
1233       *owned_monitor_count_ptr = owned_monitor_count;


1239   }
1240   delete owned_monitors_list;
1241 
1242   return err;
1243 } /* end GetOwnedMonitorInfo */
1244 
1245 
1246 // Threads_lock NOT held, java_thread not protected by lock
1247 // java_thread - pre-checked
1248 // monitor_info_count_ptr - pre-checked for NULL
1249 // monitor_info_ptr - pre-checked for NULL
1250 jvmtiError
1251 JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
1252   jvmtiError err = JVMTI_ERROR_NONE;
1253   JavaThread* calling_thread = JavaThread::current();
1254 
1255   // growable array of jvmti monitors info on the C-heap
1256   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1257          new (ResourceObj::C_HEAP, mtServiceability) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, mtServiceability);
1258 
1259   EscapeBarrier eb(calling_thread, java_thread, true);
1260   if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1261     return JVMTI_ERROR_OUT_OF_MEMORY;
1262   }
1263 
1264   // It is only safe to perform the direct operation on the current
1265   // thread. All other usage needs to use a direct handshake for safety.
1266   if (java_thread == calling_thread) {
1267     err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1268   } else {
1269     // get owned monitors info with handshake
1270     GetOwnedMonitorInfoClosure op(calling_thread, this, owned_monitors_list);
1271     bool executed = Handshake::execute_direct(&op, java_thread);
1272     err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1273   }
1274 
1275   jint owned_monitor_count = owned_monitors_list->length();
1276   if (err == JVMTI_ERROR_NONE) {
1277     if ((err = allocate(owned_monitor_count * sizeof(jvmtiMonitorStackDepthInfo),
1278                       (unsigned char**)monitor_info_ptr)) == JVMTI_ERROR_NONE) {
1279       // copy to output array.
1280       for (int i = 0; i < owned_monitor_count; i++) {
1281         (*monitor_info_ptr)[i].monitor =
1282           ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1283         (*monitor_info_ptr)[i].stack_depth =


1660     return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
1661   }
1662   // Check to see if a PopFrame was already in progress
1663   if (java_thread->popframe_condition() != JavaThread::popframe_inactive) {
1664     // Probably possible for JVMTI clients to trigger this, but the
1665     // JPDA backend shouldn't allow this to happen
1666     return JVMTI_ERROR_INTERNAL;
1667   }
1668 
1669   {
1670     // Was workaround bug
1671     //    4812902: popFrame hangs if the method is waiting at a synchronize
1672     // Catch this condition and return an error to avoid hanging.
1673     // Now JVMTI spec allows an implementation to bail out with an opaque frame error.
1674     OSThread* osThread = java_thread->osthread();
1675     if (osThread->get_state() == MONITOR_WAIT) {
1676       return JVMTI_ERROR_OPAQUE_FRAME;
1677     }
1678   }
1679 
1680   if (java_thread->frames_to_pop_failed_realloc() > 0) {
1681     // VM is in the process of popping the top frame, because it has scalar replaced objects which
1682     // could not be reallocated on the heap.
1683     // Return JVMTI_ERROR_OUT_OF_MEMORY to avoid interfering with the VM.
1684     return JVMTI_ERROR_OUT_OF_MEMORY;
1685   }
1686 
1687   {
1688     ResourceMark rm(current_thread);
1689     // Check if there are more than one Java frame in this thread, that the top two frames
1690     // are Java (not native) frames, and that there is no intervening VM frame
1691     int frame_count = 0;
1692     bool is_interpreted[2];
1693     intptr_t *frame_sp[2];
1694     // The 2-nd arg of constructor is needed to stop iterating at java entry frame.
1695     for (vframeStream vfs(java_thread, true); !vfs.at_end(); vfs.next()) {
1696       methodHandle mh(current_thread, vfs.method());
1697       if (mh->is_native()) return(JVMTI_ERROR_OPAQUE_FRAME);
1698       is_interpreted[frame_count] = vfs.is_interpreted_frame();
1699       frame_sp[frame_count] = vfs.frame_id();
1700       if (++frame_count > 1) break;
1701     }
1702     if (frame_count < 2)  {
1703       // We haven't found two adjacent non-native Java frames on the top.
1704       // There can be two situations here:
1705       //  1. There are no more java frames
1706       //  2. Two top java frames are separated by non-java native frames
1707       if(vframeFor(java_thread, 1) == NULL) {
1708         return JVMTI_ERROR_NO_MORE_FRAMES;
1709       } else {
1710         // Intervening non-java native or VM frames separate java frames.
1711         // Current implementation does not support this. See bug #5031735.
1712         // In theory it is possible to pop frames in such cases.
1713         return JVMTI_ERROR_OPAQUE_FRAME;
1714       }
1715     }
1716 
1717     // If any of the top 2 frames is a compiled one, need to deoptimize it
1718     EscapeBarrier eb(current_thread, java_thread, !is_interpreted[0] || !is_interpreted[1]);
1719     for (int i = 0; i < 2; i++) {
1720       if (!is_interpreted[i]) {
1721         Deoptimization::deoptimize_frame(java_thread, frame_sp[i]);
1722         // eagerly reallocate scalar replaced objects
1723         if (!eb.deoptimize_objects(frame_sp[i])) {
1724           // reallocation of scalar replaced objects failed -> return with error
1725           return JVMTI_ERROR_OUT_OF_MEMORY;
1726         }
1727       }
1728     }
1729 
1730     // Update the thread state to reflect that the top frame is popped
1731     // so that cur_stack_depth is maintained properly and all frameIDs
1732     // are invalidated.
1733     // The current frame will be popped later when the suspended thread
1734     // is resumed and right before returning from VM to Java.
1735     // (see call_VM_base() in assembler_<cpu>.cpp).
1736 
1737     // It's fine to update the thread state here because no JVMTI events
1738     // shall be posted for this PopFrame.
1739 
1740     // It is only safe to perform the direct operation on the current
1741     // thread. All other usage needs to use a vm-safepoint-op for safety.
1742     if (java_thread == JavaThread::current()) {
1743       state->update_for_pop_top_frame();
1744     } else {
1745       VM_UpdateForPopTopFrame op(state);
1746       VMThread::execute(&op);


< prev index next >