< prev index next >

src/hotspot/share/prims/jvmtiEnv.cpp

Print this page




1518   }
1519 
1520   return JVMTI_ERROR_NONE;
1521 } /* end GetThreadGroupChildren */
1522 
1523 
1524   //
1525   // Stack Frame functions
1526   //
1527 
1528 // Threads_lock NOT held, java_thread not protected by lock
1529 // java_thread - pre-checked
1530 // max_frame_count - pre-checked to be greater than or equal to 0
1531 // frame_buffer - pre-checked for NULL
1532 // count_ptr - pre-checked for NULL
1533 jvmtiError
1534 JvmtiEnv::GetStackTrace(JavaThread* java_thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
1535   jvmtiError err = JVMTI_ERROR_NONE;
1536 
1537   // It is only safe to perform the direct operation on the current
1538   // thread. All other usage needs to use a vm-safepoint-op for safety.
1539   if (java_thread == JavaThread::current()) {
1540     err = get_stack_trace(java_thread, start_depth, max_frame_count, frame_buffer, count_ptr);
1541   } else {
1542     // JVMTI get stack trace at safepoint. Do not require target thread to
1543     // be suspended.
1544     VM_GetStackTrace op(this, java_thread, start_depth, max_frame_count, frame_buffer, count_ptr);
1545     VMThread::execute(&op);
1546     err = op.result();
1547   }
1548 
1549   return err;
1550 } /* end GetStackTrace */
1551 
1552 
1553 // max_frame_count - pre-checked to be greater than or equal to 0
1554 // stack_info_ptr - pre-checked for NULL
1555 // thread_count_ptr - pre-checked for NULL
1556 jvmtiError
1557 JvmtiEnv::GetAllStackTraces(jint max_frame_count, jvmtiStackInfo** stack_info_ptr, jint* thread_count_ptr) {
1558   jvmtiError err = JVMTI_ERROR_NONE;
1559   JavaThread* calling_thread = JavaThread::current();
1560 
1561   // JVMTI get stack traces at safepoint.
1562   VM_GetAllStackTraces op(this, calling_thread, max_frame_count);
1563   VMThread::execute(&op);
1564   *thread_count_ptr = op.final_thread_count();
1565   *stack_info_ptr = op.stack_info();
1566   err = op.result();
1567   return err;
1568 } /* end GetAllStackTraces */
1569 
1570 
1571 // thread_count - pre-checked to be greater than or equal to 0
1572 // thread_list - pre-checked for NULL
1573 // max_frame_count - pre-checked to be greater than or equal to 0
1574 // stack_info_ptr - pre-checked for NULL
1575 jvmtiError
1576 JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list, jint max_frame_count, jvmtiStackInfo** stack_info_ptr) {
1577   jvmtiError err = JVMTI_ERROR_NONE;


















1578   // JVMTI get stack traces at safepoint.
1579   VM_GetThreadListStackTraces op(this, thread_count, thread_list, max_frame_count);
1580   VMThread::execute(&op);
1581   err = op.result();
1582   if (err == JVMTI_ERROR_NONE) {
1583     *stack_info_ptr = op.stack_info();

1584   }
1585   return err;
1586 } /* end GetThreadListStackTraces */
1587 
1588 
1589 // Threads_lock NOT held, java_thread not protected by lock
1590 // java_thread - pre-checked
1591 // count_ptr - pre-checked for NULL
1592 jvmtiError
1593 JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) {
1594   jvmtiError err = JVMTI_ERROR_NONE;
1595 
1596   // retrieve or create JvmtiThreadState.
1597   JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread);
1598   if (state == NULL) {
1599     return JVMTI_ERROR_THREAD_NOT_ALIVE;
1600   }
1601 
1602   // It is only safe to perform the direct operation on the current
1603   // thread. All other usage needs to use a vm-safepoint-op for safety.




1518   }
1519 
1520   return JVMTI_ERROR_NONE;
1521 } /* end GetThreadGroupChildren */
1522 
1523 
1524   //
1525   // Stack Frame functions
1526   //
1527 
1528 // Threads_lock NOT held, java_thread not protected by lock
1529 // java_thread - pre-checked
1530 // max_frame_count - pre-checked to be greater than or equal to 0
1531 // frame_buffer - pre-checked for NULL
1532 // count_ptr - pre-checked for NULL
1533 jvmtiError
1534 JvmtiEnv::GetStackTrace(JavaThread* java_thread, jint start_depth, jint max_frame_count, jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
1535   jvmtiError err = JVMTI_ERROR_NONE;
1536 
1537   // It is only safe to perform the direct operation on the current
1538   // thread. All other usage needs to use a direct handshake for safety.
1539   if (java_thread == JavaThread::current()) {
1540     err = get_stack_trace(java_thread, start_depth, max_frame_count, frame_buffer, count_ptr);
1541   } else {
1542     // Get stack trace with handshake.
1543     GetStackTraceClosure op(this, start_depth, max_frame_count, frame_buffer, count_ptr);
1544     bool executed = Handshake::execute_direct(&op, java_thread);
1545     err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;

1546   }
1547 
1548   return err;
1549 } /* end GetStackTrace */
1550 
1551 
1552 // max_frame_count - pre-checked to be greater than or equal to 0
1553 // stack_info_ptr - pre-checked for NULL
1554 // thread_count_ptr - pre-checked for NULL
1555 jvmtiError
1556 JvmtiEnv::GetAllStackTraces(jint max_frame_count, jvmtiStackInfo** stack_info_ptr, jint* thread_count_ptr) {
1557   jvmtiError err = JVMTI_ERROR_NONE;
1558   JavaThread* calling_thread = JavaThread::current();
1559 
1560   // JVMTI get stack traces at safepoint.
1561   VM_GetAllStackTraces op(this, calling_thread, max_frame_count);
1562   VMThread::execute(&op);
1563   *thread_count_ptr = op.final_thread_count();
1564   *stack_info_ptr = op.stack_info();
1565   err = op.result();
1566   return err;
1567 } /* end GetAllStackTraces */
1568 
1569 
1570 // thread_count - pre-checked to be greater than or equal to 0
1571 // thread_list - pre-checked for NULL
1572 // max_frame_count - pre-checked to be greater than or equal to 0
1573 // stack_info_ptr - pre-checked for NULL
1574 jvmtiError
1575 JvmtiEnv::GetThreadListStackTraces(jint thread_count, const jthread* thread_list, jint max_frame_count, jvmtiStackInfo** stack_info_ptr) {
1576   jvmtiError err = JVMTI_ERROR_NONE;
1577 
1578   if (thread_count == 1) {
1579     // Use direct handshake if we need to get only one stack trace.
1580     JavaThread *current_thread = JavaThread::current();
1581     ThreadsListHandle tlh(current_thread);
1582     JavaThread *java_thread;
1583     err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), *thread_list, &java_thread, NULL);
1584     if (err != JVMTI_ERROR_NONE) {
1585       return err;
1586     }
1587 
1588     GetSingleStackTraceClosure op(this, current_thread, *thread_list, max_frame_count);
1589     bool executed = Handshake::execute_direct(&op, java_thread);
1590     err = executed ? op.result() : JVMTI_ERROR_THREAD_NOT_ALIVE;
1591     if (err == JVMTI_ERROR_NONE) {
1592       *stack_info_ptr = op.stack_info();
1593     }
1594   } else {
1595     // JVMTI get stack traces at safepoint.
1596     VM_GetThreadListStackTraces op(this, thread_count, thread_list, max_frame_count);
1597     VMThread::execute(&op);
1598     err = op.result();
1599     if (err == JVMTI_ERROR_NONE) {
1600       *stack_info_ptr = op.stack_info();
1601     }
1602   }
1603   return err;
1604 } /* end GetThreadListStackTraces */
1605 
1606 
1607 // Threads_lock NOT held, java_thread not protected by lock
1608 // java_thread - pre-checked
1609 // count_ptr - pre-checked for NULL
1610 jvmtiError
1611 JvmtiEnv::GetFrameCount(JavaThread* java_thread, jint* count_ptr) {
1612   jvmtiError err = JVMTI_ERROR_NONE;
1613 
1614   // retrieve or create JvmtiThreadState.
1615   JvmtiThreadState* state = JvmtiThreadState::state_for(java_thread);
1616   if (state == NULL) {
1617     return JVMTI_ERROR_THREAD_NOT_ALIVE;
1618   }
1619 
1620   // It is only safe to perform the direct operation on the current
1621   // thread. All other usage needs to use a vm-safepoint-op for safety.


< prev index next >