420 421 // HandshakeClosure to get current contended monitor. 422 class GetCurrentContendedMonitorClosure : public HandshakeClosure { 423 private: 424 JavaThread *_calling_thread; 425 JvmtiEnv *_env; 426 jobject *_owned_monitor_ptr; 427 jvmtiError _result; 428 429 public: 430 GetCurrentContendedMonitorClosure(JavaThread* calling_thread, JvmtiEnv *env, jobject *mon_ptr) 431 : HandshakeClosure("GetCurrentContendedMonitor"), 432 _calling_thread(calling_thread), 433 _env(env), 434 _owned_monitor_ptr(mon_ptr), 435 _result(JVMTI_ERROR_THREAD_NOT_ALIVE) {} 436 jvmtiError result() { return _result; } 437 void do_thread(Thread *target); 438 }; 439 440 // VM operation to get stack trace at safepoint. 441 class VM_GetStackTrace : public VM_Operation { 442 private: 443 JvmtiEnv *_env; 444 JavaThread *_java_thread; 445 jint _start_depth; 446 jint _max_count; 447 jvmtiFrameInfo *_frame_buffer; 448 jint *_count_ptr; 449 jvmtiError _result; 450 451 public: 452 VM_GetStackTrace(JvmtiEnv *env, JavaThread *java_thread, 453 jint start_depth, jint max_count, 454 jvmtiFrameInfo* frame_buffer, jint* count_ptr) { 455 _env = env; 456 _java_thread = java_thread; 457 _start_depth = start_depth; 458 _max_count = max_count; 459 _frame_buffer = frame_buffer; 460 _count_ptr = count_ptr; 461 } 462 jvmtiError result() { return _result; } 463 VMOp_Type type() const { return VMOp_GetStackTrace; } 464 void doit(); 465 }; 466 467 // forward declaration 468 struct StackInfoNode; 469 470 // VM operation to get stack trace at safepoint. 471 class VM_GetMultipleStackTraces : public VM_Operation { 472 private: 473 JvmtiEnv *_env; 474 jint _max_frame_count; 475 jvmtiStackInfo *_stack_info; 476 jvmtiError _result; 477 int _frame_count_total; 478 struct StackInfoNode *_head; 479 480 JvmtiEnvBase *env() { return (JvmtiEnvBase *)_env; } 481 jint max_frame_count() { return _max_frame_count; } 482 struct StackInfoNode *head() { return _head; } 483 void set_head(StackInfoNode *head) { _head = head; } 484 485 protected: 486 void set_result(jvmtiError result) { _result = result; } 487 void fill_frames(jthread jt, JavaThread *thr, oop thread_oop); 488 void allocate_and_fill_stacks(jint thread_count); 489 490 public: 491 VM_GetMultipleStackTraces(JvmtiEnv *env, jint max_frame_count) { 492 _env = env; 493 _max_frame_count = max_frame_count; 494 _frame_count_total = 0; 495 _head = NULL; 496 _result = JVMTI_ERROR_NONE; 497 } 498 VMOp_Type type() const { return VMOp_GetMultipleStackTraces; } 499 jvmtiStackInfo *stack_info() { return _stack_info; } 500 jvmtiError result() { return _result; } 501 }; 502 503 504 // VM operation to get stack trace at safepoint. 505 class VM_GetAllStackTraces : public VM_GetMultipleStackTraces { 506 private: 507 JavaThread *_calling_thread; 508 jint _final_thread_count; 509 510 public: 511 VM_GetAllStackTraces(JvmtiEnv *env, JavaThread *calling_thread, 512 jint max_frame_count) 513 : VM_GetMultipleStackTraces(env, max_frame_count) { 514 _calling_thread = calling_thread; 515 } 516 VMOp_Type type() const { return VMOp_GetAllStackTraces; } 517 void doit(); 518 jint final_thread_count() { return _final_thread_count; } 519 }; 520 521 // VM operation to get stack trace at safepoint. 522 class VM_GetThreadListStackTraces : public VM_GetMultipleStackTraces { 523 private: 524 jint _thread_count; 525 const jthread* _thread_list; 526 527 public: 528 VM_GetThreadListStackTraces(JvmtiEnv *env, jint thread_count, const jthread* thread_list, jint max_frame_count) 529 : VM_GetMultipleStackTraces(env, max_frame_count) { 530 _thread_count = thread_count; 531 _thread_list = thread_list; 532 } 533 VMOp_Type type() const { return VMOp_GetThreadListStackTraces; } 534 void doit(); 535 }; 536 537 538 // VM operation to count stack frames at safepoint. 539 class VM_GetFrameCount : public VM_Operation { 540 private: 541 JvmtiEnv *_env; 542 JvmtiThreadState *_state; 543 jint *_count_ptr; 544 jvmtiError _result; 545 546 public: 547 VM_GetFrameCount(JvmtiEnv *env, JvmtiThreadState *state, jint *count_ptr) { 548 _env = env; 549 _state = state; 550 _count_ptr = count_ptr; 551 } 552 VMOp_Type type() const { return VMOp_GetFrameCount; } 553 jvmtiError result() { return _result; } 554 void doit(); 555 }; 556 | 420 421 // HandshakeClosure to get current contended monitor. 422 class GetCurrentContendedMonitorClosure : public HandshakeClosure { 423 private: 424 JavaThread *_calling_thread; 425 JvmtiEnv *_env; 426 jobject *_owned_monitor_ptr; 427 jvmtiError _result; 428 429 public: 430 GetCurrentContendedMonitorClosure(JavaThread* calling_thread, JvmtiEnv *env, jobject *mon_ptr) 431 : HandshakeClosure("GetCurrentContendedMonitor"), 432 _calling_thread(calling_thread), 433 _env(env), 434 _owned_monitor_ptr(mon_ptr), 435 _result(JVMTI_ERROR_THREAD_NOT_ALIVE) {} 436 jvmtiError result() { return _result; } 437 void do_thread(Thread *target); 438 }; 439 440 // HandshakeClosure to get stack trace. 441 class GetStackTraceClosure : public HandshakeClosure { 442 private: 443 JvmtiEnv *_env; 444 jint _start_depth; 445 jint _max_count; 446 jvmtiFrameInfo *_frame_buffer; 447 jint *_count_ptr; 448 jvmtiError _result; 449 450 public: 451 GetStackTraceClosure(JvmtiEnv *env, jint start_depth, jint max_count, 452 jvmtiFrameInfo* frame_buffer, jint* count_ptr) 453 : HandshakeClosure("GetStackTrace"), 454 _env(env), 455 _start_depth(start_depth), 456 _max_count(max_count), 457 _frame_buffer(frame_buffer), 458 _count_ptr(count_ptr), 459 _result(JVMTI_ERROR_THREAD_NOT_ALIVE) { 460 } 461 jvmtiError result() { return _result; } 462 void do_thread(Thread *target); 463 }; 464 465 // forward declaration 466 struct StackInfoNode; 467 468 // Get stack trace at safepoint or at direct handshake. 469 class MultipleStackTracesCollector { 470 private: 471 JvmtiEnv *_env; 472 jint _max_frame_count; 473 jvmtiStackInfo *_stack_info; 474 jvmtiError _result; 475 int _frame_count_total; 476 struct StackInfoNode *_head; 477 478 JvmtiEnvBase *env() { return (JvmtiEnvBase *)_env; } 479 jint max_frame_count() { return _max_frame_count; } 480 struct StackInfoNode *head() { return _head; } 481 void set_head(StackInfoNode *head) { _head = head; } 482 483 public: 484 MultipleStackTracesCollector(JvmtiEnv *env, jint max_frame_count) 485 : _env(env), 486 _max_frame_count(max_frame_count), 487 _stack_info(NULL), 488 _result(JVMTI_ERROR_NONE), 489 _frame_count_total(0), 490 _head(NULL) { 491 } 492 void set_result(jvmtiError result) { _result = result; } 493 void fill_frames(jthread jt, JavaThread *thr, oop thread_oop); 494 void allocate_and_fill_stacks(jint thread_count); 495 jvmtiStackInfo *stack_info() { return _stack_info; } 496 jvmtiError result() { return _result; } 497 }; 498 499 500 // VM operation to get stack trace at safepoint. 501 class VM_GetAllStackTraces : public VM_Operation { 502 private: 503 JavaThread *_calling_thread; 504 jint _final_thread_count; 505 MultipleStackTracesCollector _collector; 506 507 public: 508 VM_GetAllStackTraces(JvmtiEnv *env, JavaThread *calling_thread, 509 jint max_frame_count) 510 : _calling_thread(calling_thread), 511 _final_thread_count(0), 512 _collector(env, max_frame_count) { 513 } 514 VMOp_Type type() const { return VMOp_GetAllStackTraces; } 515 void doit(); 516 jint final_thread_count() { return _final_thread_count; } 517 jvmtiStackInfo *stack_info() { return _collector.stack_info(); } 518 jvmtiError result() { return _collector.result(); } 519 }; 520 521 // VM operation to get stack trace at safepoint. 522 class VM_GetThreadListStackTraces : public VM_Operation { 523 private: 524 jint _thread_count; 525 const jthread* _thread_list; 526 MultipleStackTracesCollector _collector; 527 528 public: 529 VM_GetThreadListStackTraces(JvmtiEnv *env, jint thread_count, const jthread* thread_list, jint max_frame_count) 530 : _thread_count(thread_count), 531 _thread_list(thread_list), 532 _collector(env, max_frame_count) { 533 } 534 VMOp_Type type() const { return VMOp_GetThreadListStackTraces; } 535 void doit(); 536 jvmtiStackInfo *stack_info() { return _collector.stack_info(); } 537 jvmtiError result() { return _collector.result(); } 538 }; 539 540 // HandshakeClosure to get single stack trace. 541 class GetSingleStackTraceClosure : public HandshakeClosure { 542 private: 543 JavaThread *_calling_thread; 544 MultipleStackTracesCollector _collector; 545 546 public: 547 GetSingleStackTraceClosure(JvmtiEnv *env, JavaThread *calling_thread, 548 jint max_frame_count) 549 : HandshakeClosure("GetSingleStackTrace"), 550 _calling_thread(calling_thread), 551 _collector(env, max_frame_count) { 552 } 553 void do_thread(Thread *target); 554 jvmtiStackInfo *stack_info() { return _collector.stack_info(); } 555 jvmtiError result() { return _collector.result(); } 556 }; 557 558 // VM operation to count stack frames at safepoint. 559 class VM_GetFrameCount : public VM_Operation { 560 private: 561 JvmtiEnv *_env; 562 JvmtiThreadState *_state; 563 jint *_count_ptr; 564 jvmtiError _result; 565 566 public: 567 VM_GetFrameCount(JvmtiEnv *env, JvmtiThreadState *state, jint *count_ptr) { 568 _env = env; 569 _state = state; 570 _count_ptr = count_ptr; 571 } 572 VMOp_Type type() const { return VMOp_GetFrameCount; } 573 jvmtiError result() { return _result; } 574 void doit(); 575 }; 576 |