263 JvmtiTagMap* tag_map() {
264 return _tag_map;
265 }
266
267
268 // return true if event is enabled globally or for any thread
269 // True only if there is a callback for it.
270 bool is_enabled(jvmtiEvent event_type) {
271 return _env_event_enable.is_enabled(event_type);
272 }
273
274 // Random Utilities
275
276 protected:
277 // helper methods for creating arrays of global JNI Handles from local Handles
278 // allocated into environment specific storage
279 jobject * new_jobjectArray(int length, Handle *handles);
280 jthread * new_jthreadArray(int length, Handle *handles);
281 jthreadGroup * new_jthreadGroupArray(int length, Handle *handles);
282
283 // convert from JNIHandle to JavaThread *
284 JavaThread * get_JavaThread(jthread jni_thread);
285
286 // convert to a jni jclass from a non-null Klass*
287 jclass get_jni_class_non_null(Klass* k);
288
289 jint count_locked_objects(JavaThread *java_thread, Handle hobj);
290 jvmtiError get_locked_objects_in_frame(JavaThread *calling_thread,
291 JavaThread* java_thread,
292 javaVFrame *jvf,
293 GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list,
294 jint depth);
295 vframe* vframeFor(JavaThread* java_thread, jint depth);
296
297 public:
298 // get a field descriptor for the specified class and field
299 static bool get_field_descriptor(Klass* k, jfieldID field, fieldDescriptor* fd);
300 // test for suspend - most (all?) of these should go away
301 static bool is_thread_fully_suspended(JavaThread *thread,
302 bool wait_for_suspend,
303 uint32_t *bits);
304
305
306 // JVMTI API helper functions which are called at safepoint or thread is suspended.
307 jvmtiError get_frame_count(JvmtiThreadState *state, jint *count_ptr);
308 jvmtiError get_frame_location(JavaThread* java_thread, jint depth,
309 jmethodID* method_ptr, jlocation* location_ptr);
310 jvmtiError get_object_monitor_usage(JavaThread *calling_thread,
311 jobject object, jvmtiMonitorUsage* info_ptr);
312 jvmtiError get_stack_trace(JavaThread *java_thread,
313 jint stack_depth, jint max_count,
314 jvmtiFrameInfo* frame_buffer, jint* count_ptr);
315 jvmtiError get_current_contended_monitor(JavaThread *calling_thread,
316 JavaThread *java_thread,
317 jobject *monitor_ptr);
318 jvmtiError get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
319 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list);
320 jvmtiError check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
321 jvalue value, TosState tos, Handle* ret_ob_h);
322 jvmtiError force_early_return(JavaThread* java_thread, jvalue value, TosState tos);
323 };
324
325 // This class is the only safe means of iterating through environments.
343 Thread::current()->leaving_jvmti_env_iteration();
344 }
345 }
346 JvmtiEnv* first() { return JvmtiEnvBase::head_environment(); }
347 JvmtiEnv* next(JvmtiEnvBase* env) { return env->next_environment(); }
348 };
349
350 // VM operation to update for pop top frame.
351 class VM_UpdateForPopTopFrame : public VM_Operation {
352 private:
353 JvmtiThreadState* _state;
354 jvmtiError _result;
355
356 public:
357 VM_UpdateForPopTopFrame(JvmtiThreadState* state) {
358 _state = state;
359 _result = JVMTI_ERROR_NONE;
360 }
361 VMOp_Type type() const { return VMOp_UpdateForPopTopFrame; }
362 jvmtiError result() { return _result; }
363 void doit() {
364 JavaThread* jt = _state->get_thread();
365 if (Threads::includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) {
366 _state->update_for_pop_top_frame();
367 } else {
368 _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
369 }
370 }
371 };
372
373 // VM operation to set frame pop.
374 class VM_SetFramePop : public VM_Operation {
375 private:
376 JvmtiEnv *_env;
377 JvmtiThreadState* _state;
378 jint _depth;
379 jvmtiError _result;
380
381 public:
382 VM_SetFramePop(JvmtiEnv *env, JvmtiThreadState* state, jint depth) {
383 _env = env;
384 _state = state;
385 _depth = depth;
386 _result = JVMTI_ERROR_NONE;
387 }
388 // Nested operation must be allowed for the VM_EnterInterpOnlyMode that is
389 // called from the JvmtiEventControllerPrivate::recompute_thread_enabled.
390 bool allow_nested_vm_operations() const { return true; }
391 VMOp_Type type() const { return VMOp_SetFramePop; }
392 jvmtiError result() { return _result; }
393 void doit() {
394 JavaThread* jt = _state->get_thread();
395 if (Threads::includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) {
396 int frame_number = _state->count_frames() - _depth;
397 _state->env_thread_state((JvmtiEnvBase*)_env)->set_frame_pop(frame_number);
398 } else {
399 _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
400 }
401 }
402 };
403
404
405 // VM operation to get monitor information with stack depth.
406 class VM_GetOwnedMonitorInfo : public VM_Operation {
407 private:
408 JvmtiEnv *_env;
409 JavaThread* _calling_thread;
410 JavaThread *_java_thread;
411 jvmtiError _result;
412 GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
413
414 public:
415 VM_GetOwnedMonitorInfo(JvmtiEnv* env, JavaThread* calling_thread,
416 JavaThread* java_thread,
417 GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitor_list) {
418 _env = env;
419 _calling_thread = calling_thread;
420 _java_thread = java_thread;
421 _owned_monitors_list = owned_monitor_list;
422 _result = JVMTI_ERROR_NONE;
423 }
424 VMOp_Type type() const { return VMOp_GetOwnedMonitorInfo; }
425 void doit() {
426 _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
427 if (Threads::includes(_java_thread) && !_java_thread->is_exiting()
428 && _java_thread->threadObj() != NULL) {
429 _result = ((JvmtiEnvBase *)_env)->get_owned_monitors(_calling_thread, _java_thread,
430 _owned_monitors_list);
431 }
432 }
433 jvmtiError result() { return _result; }
434 };
435
436
437 // VM operation to get object monitor usage.
438 class VM_GetObjectMonitorUsage : public VM_Operation {
439 private:
440 JvmtiEnv *_env;
441 jobject _object;
442 JavaThread* _calling_thread;
443 jvmtiMonitorUsage* _info_ptr;
444 jvmtiError _result;
445
446 public:
447 VM_GetObjectMonitorUsage(JvmtiEnv *env, JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
448 _env = env;
449 _object = object;
450 _calling_thread = calling_thread;
451 _info_ptr = info_ptr;
452 }
459 };
460
461 // VM operation to get current contended monitor.
462 class VM_GetCurrentContendedMonitor : public VM_Operation {
463 private:
464 JvmtiEnv *_env;
465 JavaThread *_calling_thread;
466 JavaThread *_java_thread;
467 jobject *_owned_monitor_ptr;
468 jvmtiError _result;
469
470 public:
471 VM_GetCurrentContendedMonitor(JvmtiEnv *env, JavaThread *calling_thread, JavaThread *java_thread, jobject *mon_ptr) {
472 _env = env;
473 _calling_thread = calling_thread;
474 _java_thread = java_thread;
475 _owned_monitor_ptr = mon_ptr;
476 }
477 VMOp_Type type() const { return VMOp_GetCurrentContendedMonitor; }
478 jvmtiError result() { return _result; }
479 void doit() {
480 _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
481 if (Threads::includes(_java_thread) && !_java_thread->is_exiting() &&
482 _java_thread->threadObj() != NULL) {
483 _result = ((JvmtiEnvBase *)_env)->get_current_contended_monitor(_calling_thread,_java_thread,_owned_monitor_ptr);
484 }
485 }
486 };
487
488 // VM operation to get stack trace at safepoint.
489 class VM_GetStackTrace : public VM_Operation {
490 private:
491 JvmtiEnv *_env;
492 JavaThread *_java_thread;
493 jint _start_depth;
494 jint _max_count;
495 jvmtiFrameInfo *_frame_buffer;
496 jint *_count_ptr;
497 jvmtiError _result;
498
499 public:
500 VM_GetStackTrace(JvmtiEnv *env, JavaThread *java_thread,
501 jint start_depth, jint max_count,
502 jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
503 _env = env;
504 _java_thread = java_thread;
505 _start_depth = start_depth;
506 _max_count = max_count;
507 _frame_buffer = frame_buffer;
508 _count_ptr = count_ptr;
509 }
510 jvmtiError result() { return _result; }
511 VMOp_Type type() const { return VMOp_GetStackTrace; }
512 void doit() {
513 _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
514 if (Threads::includes(_java_thread) && !_java_thread->is_exiting()
515 && _java_thread->threadObj() != NULL) {
516 _result = ((JvmtiEnvBase *)_env)->get_stack_trace(_java_thread,
517 _start_depth, _max_count,
518 _frame_buffer, _count_ptr);
519 }
520 }
521 };
522
523 // forward declaration
524 struct StackInfoNode;
525
526 // VM operation to get stack trace at safepoint.
527 class VM_GetMultipleStackTraces : public VM_Operation {
528 private:
529 JvmtiEnv *_env;
530 jint _max_frame_count;
531 jvmtiStackInfo *_stack_info;
532 jvmtiError _result;
533 int _frame_count_total;
534 struct StackInfoNode *_head;
535
536 JvmtiEnvBase *env() { return (JvmtiEnvBase *)_env; }
537 jint max_frame_count() { return _max_frame_count; }
538 struct StackInfoNode *head() { return _head; }
539 void set_head(StackInfoNode *head) { _head = head; }
540
590 void doit();
591 };
592
593
594 // VM operation to count stack frames at safepoint.
595 class VM_GetFrameCount : public VM_Operation {
596 private:
597 JvmtiEnv *_env;
598 JvmtiThreadState *_state;
599 jint *_count_ptr;
600 jvmtiError _result;
601
602 public:
603 VM_GetFrameCount(JvmtiEnv *env, JvmtiThreadState *state, jint *count_ptr) {
604 _env = env;
605 _state = state;
606 _count_ptr = count_ptr;
607 }
608 VMOp_Type type() const { return VMOp_GetFrameCount; }
609 jvmtiError result() { return _result; }
610 void doit() {
611 _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
612 JavaThread* jt = _state->get_thread();
613 if (Threads::includes(jt) && !jt->is_exiting() && jt->threadObj() != NULL) {
614 _result = ((JvmtiEnvBase*)_env)->get_frame_count(_state, _count_ptr);
615 }
616 }
617 };
618
619 // VM operation to frame location at safepoint.
620 class VM_GetFrameLocation : public VM_Operation {
621 private:
622 JvmtiEnv *_env;
623 JavaThread* _java_thread;
624 jint _depth;
625 jmethodID* _method_ptr;
626 jlocation* _location_ptr;
627 jvmtiError _result;
628
629 public:
630 VM_GetFrameLocation(JvmtiEnv *env, JavaThread* java_thread, jint depth,
631 jmethodID* method_ptr, jlocation* location_ptr) {
632 _env = env;
633 _java_thread = java_thread;
634 _depth = depth;
635 _method_ptr = method_ptr;
636 _location_ptr = location_ptr;
637 }
638 VMOp_Type type() const { return VMOp_GetFrameLocation; }
639 jvmtiError result() { return _result; }
640 void doit() {
641 _result = JVMTI_ERROR_THREAD_NOT_ALIVE;
642 if (Threads::includes(_java_thread) && !_java_thread->is_exiting() &&
643 _java_thread->threadObj() != NULL) {
644 _result = ((JvmtiEnvBase*)_env)->get_frame_location(_java_thread, _depth,
645 _method_ptr, _location_ptr);
646 }
647 }
648 };
649
650
651 // ResourceTracker
652 //
653 // ResourceTracker works a little like a ResourceMark. All allocates
654 // using the resource tracker are recorded. If an allocate using the
655 // resource tracker fails the destructor will free any resources
656 // that were allocated using the tracker.
657 // The motive for this class is to avoid messy error recovery code
658 // in situations where multiple allocations are done in sequence. If
659 // the second or subsequent allocation fails it avoids any code to
660 // release memory allocated in the previous calls.
661 //
662 // Usage :-
663 // ResourceTracker rt(env);
664 // :
665 // err = rt.allocate(1024, &ptr);
666
667 class ResourceTracker : public StackObj {
|
263 JvmtiTagMap* tag_map() {
264 return _tag_map;
265 }
266
267
268 // return true if event is enabled globally or for any thread
269 // True only if there is a callback for it.
270 bool is_enabled(jvmtiEvent event_type) {
271 return _env_event_enable.is_enabled(event_type);
272 }
273
274 // Random Utilities
275
276 protected:
277 // helper methods for creating arrays of global JNI Handles from local Handles
278 // allocated into environment specific storage
279 jobject * new_jobjectArray(int length, Handle *handles);
280 jthread * new_jthreadArray(int length, Handle *handles);
281 jthreadGroup * new_jthreadGroupArray(int length, Handle *handles);
282
283 // convert to a jni jclass from a non-null Klass*
284 jclass get_jni_class_non_null(Klass* k);
285
286 jint count_locked_objects(JavaThread *java_thread, Handle hobj);
287 jvmtiError get_locked_objects_in_frame(JavaThread *calling_thread,
288 JavaThread* java_thread,
289 javaVFrame *jvf,
290 GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitors_list,
291 jint depth);
292 vframe* vframeFor(JavaThread* java_thread, jint depth);
293
294 public:
295 // get a field descriptor for the specified class and field
296 static bool get_field_descriptor(Klass* k, jfieldID field, fieldDescriptor* fd);
297
298 // JVMTI API helper functions which are called at safepoint or thread is suspended.
299 jvmtiError get_frame_count(JvmtiThreadState *state, jint *count_ptr);
300 jvmtiError get_frame_location(JavaThread* java_thread, jint depth,
301 jmethodID* method_ptr, jlocation* location_ptr);
302 jvmtiError get_object_monitor_usage(JavaThread *calling_thread,
303 jobject object, jvmtiMonitorUsage* info_ptr);
304 jvmtiError get_stack_trace(JavaThread *java_thread,
305 jint stack_depth, jint max_count,
306 jvmtiFrameInfo* frame_buffer, jint* count_ptr);
307 jvmtiError get_current_contended_monitor(JavaThread *calling_thread,
308 JavaThread *java_thread,
309 jobject *monitor_ptr);
310 jvmtiError get_owned_monitors(JavaThread *calling_thread, JavaThread* java_thread,
311 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list);
312 jvmtiError check_top_frame(JavaThread* current_thread, JavaThread* java_thread,
313 jvalue value, TosState tos, Handle* ret_ob_h);
314 jvmtiError force_early_return(JavaThread* java_thread, jvalue value, TosState tos);
315 };
316
317 // This class is the only safe means of iterating through environments.
335 Thread::current()->leaving_jvmti_env_iteration();
336 }
337 }
338 JvmtiEnv* first() { return JvmtiEnvBase::head_environment(); }
339 JvmtiEnv* next(JvmtiEnvBase* env) { return env->next_environment(); }
340 };
341
342 // VM operation to update for pop top frame.
343 class VM_UpdateForPopTopFrame : public VM_Operation {
344 private:
345 JvmtiThreadState* _state;
346 jvmtiError _result;
347
348 public:
349 VM_UpdateForPopTopFrame(JvmtiThreadState* state) {
350 _state = state;
351 _result = JVMTI_ERROR_NONE;
352 }
353 VMOp_Type type() const { return VMOp_UpdateForPopTopFrame; }
354 jvmtiError result() { return _result; }
355 void doit();
356 };
357
358 // VM operation to set frame pop.
359 class VM_SetFramePop : public VM_Operation {
360 private:
361 JvmtiEnv *_env;
362 JvmtiThreadState* _state;
363 jint _depth;
364 jvmtiError _result;
365
366 public:
367 VM_SetFramePop(JvmtiEnv *env, JvmtiThreadState* state, jint depth) {
368 _env = env;
369 _state = state;
370 _depth = depth;
371 _result = JVMTI_ERROR_NONE;
372 }
373 // Nested operation must be allowed for the VM_EnterInterpOnlyMode that is
374 // called from the JvmtiEventControllerPrivate::recompute_thread_enabled.
375 bool allow_nested_vm_operations() const { return true; }
376 VMOp_Type type() const { return VMOp_SetFramePop; }
377 jvmtiError result() { return _result; }
378 void doit();
379 };
380
381
382 // VM operation to get monitor information with stack depth.
383 class VM_GetOwnedMonitorInfo : public VM_Operation {
384 private:
385 JvmtiEnv *_env;
386 JavaThread* _calling_thread;
387 JavaThread *_java_thread;
388 jvmtiError _result;
389 GrowableArray<jvmtiMonitorStackDepthInfo*> *_owned_monitors_list;
390
391 public:
392 VM_GetOwnedMonitorInfo(JvmtiEnv* env, JavaThread* calling_thread,
393 JavaThread* java_thread,
394 GrowableArray<jvmtiMonitorStackDepthInfo*>* owned_monitor_list) {
395 _env = env;
396 _calling_thread = calling_thread;
397 _java_thread = java_thread;
398 _owned_monitors_list = owned_monitor_list;
399 _result = JVMTI_ERROR_NONE;
400 }
401 VMOp_Type type() const { return VMOp_GetOwnedMonitorInfo; }
402 void doit();
403 jvmtiError result() { return _result; }
404 };
405
406
407 // VM operation to get object monitor usage.
408 class VM_GetObjectMonitorUsage : public VM_Operation {
409 private:
410 JvmtiEnv *_env;
411 jobject _object;
412 JavaThread* _calling_thread;
413 jvmtiMonitorUsage* _info_ptr;
414 jvmtiError _result;
415
416 public:
417 VM_GetObjectMonitorUsage(JvmtiEnv *env, JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) {
418 _env = env;
419 _object = object;
420 _calling_thread = calling_thread;
421 _info_ptr = info_ptr;
422 }
429 };
430
431 // VM operation to get current contended monitor.
432 class VM_GetCurrentContendedMonitor : public VM_Operation {
433 private:
434 JvmtiEnv *_env;
435 JavaThread *_calling_thread;
436 JavaThread *_java_thread;
437 jobject *_owned_monitor_ptr;
438 jvmtiError _result;
439
440 public:
441 VM_GetCurrentContendedMonitor(JvmtiEnv *env, JavaThread *calling_thread, JavaThread *java_thread, jobject *mon_ptr) {
442 _env = env;
443 _calling_thread = calling_thread;
444 _java_thread = java_thread;
445 _owned_monitor_ptr = mon_ptr;
446 }
447 VMOp_Type type() const { return VMOp_GetCurrentContendedMonitor; }
448 jvmtiError result() { return _result; }
449 void doit();
450 };
451
452 // VM operation to get stack trace at safepoint.
453 class VM_GetStackTrace : public VM_Operation {
454 private:
455 JvmtiEnv *_env;
456 JavaThread *_java_thread;
457 jint _start_depth;
458 jint _max_count;
459 jvmtiFrameInfo *_frame_buffer;
460 jint *_count_ptr;
461 jvmtiError _result;
462
463 public:
464 VM_GetStackTrace(JvmtiEnv *env, JavaThread *java_thread,
465 jint start_depth, jint max_count,
466 jvmtiFrameInfo* frame_buffer, jint* count_ptr) {
467 _env = env;
468 _java_thread = java_thread;
469 _start_depth = start_depth;
470 _max_count = max_count;
471 _frame_buffer = frame_buffer;
472 _count_ptr = count_ptr;
473 }
474 jvmtiError result() { return _result; }
475 VMOp_Type type() const { return VMOp_GetStackTrace; }
476 void doit();
477 };
478
479 // forward declaration
480 struct StackInfoNode;
481
482 // VM operation to get stack trace at safepoint.
483 class VM_GetMultipleStackTraces : public VM_Operation {
484 private:
485 JvmtiEnv *_env;
486 jint _max_frame_count;
487 jvmtiStackInfo *_stack_info;
488 jvmtiError _result;
489 int _frame_count_total;
490 struct StackInfoNode *_head;
491
492 JvmtiEnvBase *env() { return (JvmtiEnvBase *)_env; }
493 jint max_frame_count() { return _max_frame_count; }
494 struct StackInfoNode *head() { return _head; }
495 void set_head(StackInfoNode *head) { _head = head; }
496
546 void doit();
547 };
548
549
550 // VM operation to count stack frames at safepoint.
551 class VM_GetFrameCount : public VM_Operation {
552 private:
553 JvmtiEnv *_env;
554 JvmtiThreadState *_state;
555 jint *_count_ptr;
556 jvmtiError _result;
557
558 public:
559 VM_GetFrameCount(JvmtiEnv *env, JvmtiThreadState *state, jint *count_ptr) {
560 _env = env;
561 _state = state;
562 _count_ptr = count_ptr;
563 }
564 VMOp_Type type() const { return VMOp_GetFrameCount; }
565 jvmtiError result() { return _result; }
566 void doit();
567 };
568
569 // VM operation to frame location at safepoint.
570 class VM_GetFrameLocation : public VM_Operation {
571 private:
572 JvmtiEnv *_env;
573 JavaThread* _java_thread;
574 jint _depth;
575 jmethodID* _method_ptr;
576 jlocation* _location_ptr;
577 jvmtiError _result;
578
579 public:
580 VM_GetFrameLocation(JvmtiEnv *env, JavaThread* java_thread, jint depth,
581 jmethodID* method_ptr, jlocation* location_ptr) {
582 _env = env;
583 _java_thread = java_thread;
584 _depth = depth;
585 _method_ptr = method_ptr;
586 _location_ptr = location_ptr;
587 }
588 VMOp_Type type() const { return VMOp_GetFrameLocation; }
589 jvmtiError result() { return _result; }
590 void doit();
591 };
592
593
594 // ResourceTracker
595 //
596 // ResourceTracker works a little like a ResourceMark. All allocates
597 // using the resource tracker are recorded. If an allocate using the
598 // resource tracker fails the destructor will free any resources
599 // that were allocated using the tracker.
600 // The motive for this class is to avoid messy error recovery code
601 // in situations where multiple allocations are done in sequence. If
602 // the second or subsequent allocation fails it avoids any code to
603 // release memory allocated in the previous calls.
604 //
605 // Usage :-
606 // ResourceTracker rt(env);
607 // :
608 // err = rt.allocate(1024, &ptr);
609
610 class ResourceTracker : public StackObj {
|