< prev index next >

src/hotspot/share/prims/jvmtiEnv.cpp

Print this page
rev 56101 : 8227745: Enable Escape Analysis for better performance when debugging
Reviewed-by: ???


1176                                      jni_reference(context_class_loader);
1177   info_ptr->thread_group = jni_reference(thread_group);
1178 
1179   return JVMTI_ERROR_NONE;
1180 } /* end GetThreadInfo */
1181 
1182 
1183 // Threads_lock NOT held, java_thread not protected by lock
1184 // java_thread - pre-checked
1185 // owned_monitor_count_ptr - pre-checked for NULL
1186 // owned_monitors_ptr - pre-checked for NULL
1187 jvmtiError
1188 JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {
1189   jvmtiError err = JVMTI_ERROR_NONE;
1190   JavaThread* calling_thread = JavaThread::current();
1191 
1192   // growable array of jvmti monitors info on the C-heap
1193   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1194       new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true);
1195 





1196   // It is only safe to perform the direct operation on the current
1197   // thread. All other usage needs to use a vm-safepoint-op for safety.
1198   if (java_thread == calling_thread) {
1199     err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1200   } else {
1201     // JVMTI get monitors info at safepoint. Do not require target thread to
1202     // be suspended.
1203     VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list);
1204     VMThread::execute(&op);
1205     err = op.result();
1206   }
1207   jint owned_monitor_count = owned_monitors_list->length();
1208   if (err == JVMTI_ERROR_NONE) {
1209     if ((err = allocate(owned_monitor_count * sizeof(jobject *),
1210                       (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) {
1211       // copy into the returned array
1212       for (int i = 0; i < owned_monitor_count; i++) {
1213         (*owned_monitors_ptr)[i] =
1214           ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1215       }


1222   }
1223   delete owned_monitors_list;
1224 
1225   return err;
1226 } /* end GetOwnedMonitorInfo */
1227 
1228 
1229 // Threads_lock NOT held, java_thread not protected by lock
1230 // java_thread - pre-checked
1231 // monitor_info_count_ptr - pre-checked for NULL
1232 // monitor_info_ptr - pre-checked for NULL
1233 jvmtiError
1234 JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
1235   jvmtiError err = JVMTI_ERROR_NONE;
1236   JavaThread* calling_thread  = JavaThread::current();
1237 
1238   // growable array of jvmti monitors info on the C-heap
1239   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1240          new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true);
1241 





1242   // It is only safe to perform the direct operation on the current
1243   // thread. All other usage needs to use a vm-safepoint-op for safety.
1244   if (java_thread == calling_thread) {
1245     err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1246   } else {
1247     // JVMTI get owned monitors info at safepoint. Do not require target thread to
1248     // be suspended.
1249     VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list);
1250     VMThread::execute(&op);
1251     err = op.result();
1252   }
1253 
1254   jint owned_monitor_count = owned_monitors_list->length();
1255   if (err == JVMTI_ERROR_NONE) {
1256     if ((err = allocate(owned_monitor_count * sizeof(jvmtiMonitorStackDepthInfo),
1257                       (unsigned char**)monitor_info_ptr)) == JVMTI_ERROR_NONE) {
1258       // copy to output array.
1259       for (int i = 0; i < owned_monitor_count; i++) {
1260         (*monitor_info_ptr)[i].monitor =
1261           ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;


1316     // thread_oop.
1317     if (thread_oop == NULL) {
1318       return err;
1319     }
1320     // We have a valid thread_oop.
1321   }
1322 
1323   if (java_thread != NULL) {
1324     // 'thread' refers to an existing JavaThread.
1325     return JVMTI_ERROR_INVALID_THREAD;
1326   }
1327 
1328   if (priority < JVMTI_THREAD_MIN_PRIORITY || priority > JVMTI_THREAD_MAX_PRIORITY) {
1329     return JVMTI_ERROR_INVALID_PRIORITY;
1330   }
1331 
1332   Handle thread_hndl(current_thread, thread_oop);
1333   {
1334     MutexLocker mu(Threads_lock); // grab Threads_lock
1335 





1336     JvmtiAgentThread *new_thread = new JvmtiAgentThread(this, proc, arg);
1337 
1338     // At this point it may be possible that no osthread was created for the
1339     // JavaThread due to lack of memory.
1340     if (new_thread == NULL || new_thread->osthread() == NULL) {
1341       if (new_thread != NULL) {
1342         new_thread->smr_delete();
1343       }
1344       return JVMTI_ERROR_OUT_OF_MEMORY;
1345     }
1346 
1347     java_lang_Thread::set_thread(thread_hndl(), new_thread);
1348     java_lang_Thread::set_priority(thread_hndl(), (ThreadPriority)priority);
1349     java_lang_Thread::set_daemon(thread_hndl());
1350 
1351     new_thread->set_threadObj(thread_hndl());
1352     Threads::add(new_thread);
1353     Thread::start(new_thread);
1354   } // unlock Threads_lock
1355 


1621     return JVMTI_ERROR_THREAD_NOT_SUSPENDED;
1622   }
1623   // Check to see if a PopFrame was already in progress
1624   if (java_thread->popframe_condition() != JavaThread::popframe_inactive) {
1625     // Probably possible for JVMTI clients to trigger this, but the
1626     // JPDA backend shouldn't allow this to happen
1627     return JVMTI_ERROR_INTERNAL;
1628   }
1629 
1630   {
1631     // Was workaround bug
1632     //    4812902: popFrame hangs if the method is waiting at a synchronize
1633     // Catch this condition and return an error to avoid hanging.
1634     // Now JVMTI spec allows an implementation to bail out with an opaque frame error.
1635     OSThread* osThread = java_thread->osthread();
1636     if (osThread->get_state() == MONITOR_WAIT) {
1637       return JVMTI_ERROR_OPAQUE_FRAME;
1638     }
1639   }
1640 







1641   {
1642     ResourceMark rm(current_thread);
1643     // Check if there are more than one Java frame in this thread, that the top two frames
1644     // are Java (not native) frames, and that there is no intervening VM frame
1645     int frame_count = 0;
1646     bool is_interpreted[2];
1647     intptr_t *frame_sp[2];
1648     // The 2-nd arg of constructor is needed to stop iterating at java entry frame.
1649     for (vframeStream vfs(java_thread, true); !vfs.at_end(); vfs.next()) {
1650       methodHandle mh(current_thread, vfs.method());
1651       if (mh->is_native()) return(JVMTI_ERROR_OPAQUE_FRAME);
1652       is_interpreted[frame_count] = vfs.is_interpreted_frame();
1653       frame_sp[frame_count] = vfs.frame_id();
1654       if (++frame_count > 1) break;
1655     }
1656     if (frame_count < 2)  {
1657       // We haven't found two adjacent non-native Java frames on the top.
1658       // There can be two situations here:
1659       //  1. There are no more java frames
1660       //  2. Two top java frames are separated by non-java native frames
1661       if(vframeFor(java_thread, 1) == NULL) {
1662         return JVMTI_ERROR_NO_MORE_FRAMES;
1663       } else {
1664         // Intervening non-java native or VM frames separate java frames.
1665         // Current implementation does not support this. See bug #5031735.
1666         // In theory it is possible to pop frames in such cases.
1667         return JVMTI_ERROR_OPAQUE_FRAME;
1668       }
1669     }
1670 
1671     // If any of the top 2 frames is a compiled one, need to deoptimize it

1672     for (int i = 0; i < 2; i++) {
1673       if (!is_interpreted[i]) {
1674         Deoptimization::deoptimize_frame(java_thread, frame_sp[i]);





1675       }
1676     }
1677 
1678     // Update the thread state to reflect that the top frame is popped
1679     // so that cur_stack_depth is maintained properly and all frameIDs
1680     // are invalidated.
1681     // The current frame will be popped later when the suspended thread
1682     // is resumed and right before returning from VM to Java.
1683     // (see call_VM_base() in assembler_<cpu>.cpp).
1684 
1685     // It's fine to update the thread state here because no JVMTI events
1686     // shall be posted for this PopFrame.
1687 
1688     // It is only safe to perform the direct operation on the current
1689     // thread. All other usage needs to use a vm-safepoint-op for safety.
1690     if (java_thread == JavaThread::current()) {
1691       state->update_for_pop_top_frame();
1692     } else {
1693       VM_UpdateForPopTopFrame op(state);
1694       VMThread::execute(&op);




1176                                      jni_reference(context_class_loader);
1177   info_ptr->thread_group = jni_reference(thread_group);
1178 
1179   return JVMTI_ERROR_NONE;
1180 } /* end GetThreadInfo */
1181 
1182 
1183 // Threads_lock NOT held, java_thread not protected by lock
1184 // java_thread - pre-checked
1185 // owned_monitor_count_ptr - pre-checked for NULL
1186 // owned_monitors_ptr - pre-checked for NULL
1187 jvmtiError
1188 JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) {
1189   jvmtiError err = JVMTI_ERROR_NONE;
1190   JavaThread* calling_thread = JavaThread::current();
1191 
1192   // growable array of jvmti monitors info on the C-heap
1193   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1194       new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true);
1195 
1196   JVMTIEscapeBarrier eb(calling_thread, java_thread, true);
1197   if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1198     return JVMTI_ERROR_OUT_OF_MEMORY;
1199   }
1200 
1201   // It is only safe to perform the direct operation on the current
1202   // thread. All other usage needs to use a vm-safepoint-op for safety.
1203   if (java_thread == calling_thread) {
1204     err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1205   } else {
1206     // JVMTI get monitors info at safepoint. Do not require target thread to
1207     // be suspended.
1208     VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list);
1209     VMThread::execute(&op);
1210     err = op.result();
1211   }
1212   jint owned_monitor_count = owned_monitors_list->length();
1213   if (err == JVMTI_ERROR_NONE) {
1214     if ((err = allocate(owned_monitor_count * sizeof(jobject *),
1215                       (unsigned char**)owned_monitors_ptr)) == JVMTI_ERROR_NONE) {
1216       // copy into the returned array
1217       for (int i = 0; i < owned_monitor_count; i++) {
1218         (*owned_monitors_ptr)[i] =
1219           ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;
1220       }


1227   }
1228   delete owned_monitors_list;
1229 
1230   return err;
1231 } /* end GetOwnedMonitorInfo */
1232 
1233 
1234 // Threads_lock NOT held, java_thread not protected by lock
1235 // java_thread - pre-checked
1236 // monitor_info_count_ptr - pre-checked for NULL
1237 // monitor_info_ptr - pre-checked for NULL
1238 jvmtiError
1239 JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) {
1240   jvmtiError err = JVMTI_ERROR_NONE;
1241   JavaThread* calling_thread  = JavaThread::current();
1242 
1243   // growable array of jvmti monitors info on the C-heap
1244   GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list =
1245          new (ResourceObj::C_HEAP, mtInternal) GrowableArray<jvmtiMonitorStackDepthInfo*>(1, true);
1246 
1247   JVMTIEscapeBarrier eb(calling_thread, java_thread, true);
1248   if (!eb.deoptimize_objects(MaxJavaStackTraceDepth)) {
1249     return JVMTI_ERROR_OUT_OF_MEMORY;
1250   }
1251 
1252   // It is only safe to perform the direct operation on the current
1253   // thread. All other usage needs to use a vm-safepoint-op for safety.
1254   if (java_thread == calling_thread) {
1255     err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list);
1256   } else {
1257     // JVMTI get owned monitors info at safepoint. Do not require target thread to
1258     // be suspended.
1259     VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list);
1260     VMThread::execute(&op);
1261     err = op.result();
1262   }
1263 
1264   jint owned_monitor_count = owned_monitors_list->length();
1265   if (err == JVMTI_ERROR_NONE) {
1266     if ((err = allocate(owned_monitor_count * sizeof(jvmtiMonitorStackDepthInfo),
1267                       (unsigned char**)monitor_info_ptr)) == JVMTI_ERROR_NONE) {
1268       // copy to output array.
1269       for (int i = 0; i < owned_monitor_count; i++) {
1270         (*monitor_info_ptr)[i].monitor =
1271           ((jvmtiMonitorStackDepthInfo*)owned_monitors_list->at(i))->monitor;


1326     // thread_oop.
1327     if (thread_oop == NULL) {
1328       return err;
1329     }
1330     // We have a valid thread_oop.
1331   }
1332 
1333   if (java_thread != NULL) {
1334     // 'thread' refers to an existing JavaThread.
1335     return JVMTI_ERROR_INVALID_THREAD;
1336   }
1337 
1338   if (priority < JVMTI_THREAD_MIN_PRIORITY || priority > JVMTI_THREAD_MAX_PRIORITY) {
1339     return JVMTI_ERROR_INVALID_PRIORITY;
1340   }
1341 
1342   Handle thread_hndl(current_thread, thread_oop);
1343   {
1344     MutexLocker mu(Threads_lock); // grab Threads_lock
1345 
1346     while (JVMTIEscapeBarrier::deoptimizing_objects_for_all_threads()) {
1347       // Must not add new threads that push frames with ea based optimizations
1348       Threads_lock->wait(0, Monitor::_as_suspend_equivalent_flag);
1349     }
1350 
1351     JvmtiAgentThread *new_thread = new JvmtiAgentThread(this, proc, arg);
1352 
1353     // At this point it may be possible that no osthread was created for the
1354     // JavaThread due to lack of memory.
1355     if (new_thread == NULL || new_thread->osthread() == NULL) {
1356       if (new_thread != NULL) {
1357         new_thread->smr_delete();
1358       }
1359       return JVMTI_ERROR_OUT_OF_MEMORY;
1360     }
1361 
1362     java_lang_Thread::set_thread(thread_hndl(), new_thread);
1363     java_lang_Thread::set_priority(thread_hndl(), (ThreadPriority)priority);
1364     java_lang_Thread::set_daemon(thread_hndl());
1365 
1366     new_thread->set_threadObj(thread_hndl());
1367     Threads::add(new_thread);
1368     Thread::start(new_thread);
1369   } // unlock Threads_lock
1370 


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


< prev index next >