47 #include "prims/jvmtiExtensions.hpp"
48 #include "prims/jvmtiGetLoadedClasses.hpp"
49 #include "prims/jvmtiImpl.hpp"
50 #include "prims/jvmtiManageCapabilities.hpp"
51 #include "prims/jvmtiRawMonitor.hpp"
52 #include "prims/jvmtiRedefineClasses.hpp"
53 #include "prims/jvmtiTagMap.hpp"
54 #include "prims/jvmtiThreadState.inline.hpp"
55 #include "prims/jvmtiUtil.hpp"
56 #include "runtime/arguments.hpp"
57 #include "runtime/deoptimization.hpp"
58 #include "runtime/interfaceSupport.inline.hpp"
59 #include "runtime/javaCalls.hpp"
60 #include "runtime/jfieldIDWorkaround.hpp"
61 #include "runtime/jniHandles.inline.hpp"
62 #include "runtime/objectMonitor.inline.hpp"
63 #include "runtime/osThread.hpp"
64 #include "runtime/reflectionUtils.hpp"
65 #include "runtime/signature.hpp"
66 #include "runtime/thread.inline.hpp"
67 #include "runtime/threadSMR.hpp"
68 #include "runtime/timerTrace.hpp"
69 #include "runtime/vframe.inline.hpp"
70 #include "runtime/vmThread.hpp"
71 #include "services/threadService.hpp"
72 #include "utilities/exceptions.hpp"
73 #include "utilities/preserveException.hpp"
74
75
76 #define FIXLATER 0 // REMOVE this when completed.
77
78 // FIXLATER: hook into JvmtiTrace
79 #define TraceJVMTICalls false
80
81 JvmtiEnv::JvmtiEnv(jint version) : JvmtiEnvBase(version) {
82 }
83
84 JvmtiEnv::~JvmtiEnv() {
85 }
86
520 // Can be called at Agent_OnLoad() time with event_thread == NULL
521 // when Thread::current() does not work yet so we cannot create a
522 // ThreadsListHandle that is common to both thread-specific and
523 // global code paths.
524
525 // event_type must be valid
526 if (!JvmtiEventController::is_valid_event_type(event_type)) {
527 return JVMTI_ERROR_INVALID_EVENT_TYPE;
528 }
529
530 bool enabled = (mode == JVMTI_ENABLE);
531
532 // assure that needed capabilities are present
533 if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) {
534 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
535 }
536
537 if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) {
538 record_class_file_load_hook_enabled();
539 }
540 JvmtiEventController::set_user_enabled(this, (JavaThread*) NULL, event_type, enabled);
541 } else {
542 // We have a specified event_thread.
543
544 JavaThread* java_thread = NULL;
545 ThreadsListHandle tlh;
546 jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), event_thread, &java_thread, NULL);
547 if (err != JVMTI_ERROR_NONE) {
548 return err;
549 }
550
551 // event_type must be valid
552 if (!JvmtiEventController::is_valid_event_type(event_type)) {
553 return JVMTI_ERROR_INVALID_EVENT_TYPE;
554 }
555
556 // global events cannot be controlled at thread level.
557 if (JvmtiEventController::is_global_event(event_type)) {
558 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
559 }
560
561 bool enabled = (mode == JVMTI_ENABLE);
562
563 // assure that needed capabilities are present
564 if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) {
565 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
566 }
567
568 if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) {
569 record_class_file_load_hook_enabled();
570 }
571 JvmtiEventController::set_user_enabled(this, java_thread, event_type, enabled);
572 }
573
574 return JVMTI_ERROR_NONE;
575 } /* end SetEventNotificationMode */
576
577 //
578 // Capability functions
579 //
580
581 // capabilities_ptr - pre-checked for NULL
582 jvmtiError
583 JvmtiEnv::GetPotentialCapabilities(jvmtiCapabilities* capabilities_ptr) {
584 JvmtiManageCapabilities::get_potential_capabilities(get_capabilities(),
585 get_prohibited_capabilities(),
586 capabilities_ptr);
587 return JVMTI_ERROR_NONE;
588 } /* end GetPotentialCapabilities */
589
590
3613 JvmtiEnv::GetTimerInfo(jvmtiTimerInfo* info_ptr) {
3614 os::javaTimeNanos_info(info_ptr);
3615 return JVMTI_ERROR_NONE;
3616 } /* end GetTimerInfo */
3617
3618
3619 // nanos_ptr - pre-checked for NULL
3620 jvmtiError
3621 JvmtiEnv::GetTime(jlong* nanos_ptr) {
3622 *nanos_ptr = os::javaTimeNanos();
3623 return JVMTI_ERROR_NONE;
3624 } /* end GetTime */
3625
3626
3627 // processor_count_ptr - pre-checked for NULL
3628 jvmtiError
3629 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) {
3630 *processor_count_ptr = os::active_processor_count();
3631 return JVMTI_ERROR_NONE;
3632 } /* end GetAvailableProcessors */
3633
3634 //
3635 // System Properties functions
3636 //
3637
3638 // count_ptr - pre-checked for NULL
3639 // property_ptr - pre-checked for NULL
3640 jvmtiError
3641 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) {
3642 jvmtiError err = JVMTI_ERROR_NONE;
3643
3644 // Get the number of readable properties.
3645 *count_ptr = Arguments::PropertyList_readable_count(Arguments::system_properties());
3646
3647 // Allocate memory to hold the exact number of readable properties.
3648 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr);
3649 if (err != JVMTI_ERROR_NONE) {
3650 return err;
3651 }
3652 int readable_count = 0;
|
47 #include "prims/jvmtiExtensions.hpp"
48 #include "prims/jvmtiGetLoadedClasses.hpp"
49 #include "prims/jvmtiImpl.hpp"
50 #include "prims/jvmtiManageCapabilities.hpp"
51 #include "prims/jvmtiRawMonitor.hpp"
52 #include "prims/jvmtiRedefineClasses.hpp"
53 #include "prims/jvmtiTagMap.hpp"
54 #include "prims/jvmtiThreadState.inline.hpp"
55 #include "prims/jvmtiUtil.hpp"
56 #include "runtime/arguments.hpp"
57 #include "runtime/deoptimization.hpp"
58 #include "runtime/interfaceSupport.inline.hpp"
59 #include "runtime/javaCalls.hpp"
60 #include "runtime/jfieldIDWorkaround.hpp"
61 #include "runtime/jniHandles.inline.hpp"
62 #include "runtime/objectMonitor.inline.hpp"
63 #include "runtime/osThread.hpp"
64 #include "runtime/reflectionUtils.hpp"
65 #include "runtime/signature.hpp"
66 #include "runtime/thread.inline.hpp"
67 #include "runtime/threadHeapSampler.hpp"
68 #include "runtime/threadSMR.hpp"
69 #include "runtime/timerTrace.hpp"
70 #include "runtime/vframe.inline.hpp"
71 #include "runtime/vmThread.hpp"
72 #include "services/threadService.hpp"
73 #include "utilities/exceptions.hpp"
74 #include "utilities/preserveException.hpp"
75
76
77 #define FIXLATER 0 // REMOVE this when completed.
78
79 // FIXLATER: hook into JvmtiTrace
80 #define TraceJVMTICalls false
81
82 JvmtiEnv::JvmtiEnv(jint version) : JvmtiEnvBase(version) {
83 }
84
85 JvmtiEnv::~JvmtiEnv() {
86 }
87
521 // Can be called at Agent_OnLoad() time with event_thread == NULL
522 // when Thread::current() does not work yet so we cannot create a
523 // ThreadsListHandle that is common to both thread-specific and
524 // global code paths.
525
526 // event_type must be valid
527 if (!JvmtiEventController::is_valid_event_type(event_type)) {
528 return JVMTI_ERROR_INVALID_EVENT_TYPE;
529 }
530
531 bool enabled = (mode == JVMTI_ENABLE);
532
533 // assure that needed capabilities are present
534 if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) {
535 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
536 }
537
538 if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) {
539 record_class_file_load_hook_enabled();
540 }
541
542 if (event_type == JVMTI_EVENT_SAMPLED_OBJECT_ALLOC) {
543 if (enabled) {
544 ThreadHeapSampler::enable();
545 } else {
546 ThreadHeapSampler::disable();
547 }
548 }
549 JvmtiEventController::set_user_enabled(this, (JavaThread*) NULL, event_type, enabled);
550 } else {
551 // We have a specified event_thread.
552
553 JavaThread* java_thread = NULL;
554 ThreadsListHandle tlh;
555 jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), event_thread, &java_thread, NULL);
556 if (err != JVMTI_ERROR_NONE) {
557 return err;
558 }
559
560 // event_type must be valid
561 if (!JvmtiEventController::is_valid_event_type(event_type)) {
562 return JVMTI_ERROR_INVALID_EVENT_TYPE;
563 }
564
565 // global events cannot be controlled at thread level.
566 if (JvmtiEventController::is_global_event(event_type)) {
567 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
568 }
569
570 bool enabled = (mode == JVMTI_ENABLE);
571
572 // assure that needed capabilities are present
573 if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) {
574 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
575 }
576
577 if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) {
578 record_class_file_load_hook_enabled();
579 }
580
581 if (event_type == JVMTI_EVENT_SAMPLED_OBJECT_ALLOC) {
582 if (enabled) {
583 ThreadHeapSampler::enable();
584 } else {
585 ThreadHeapSampler::disable();
586 }
587 }
588 JvmtiEventController::set_user_enabled(this, java_thread, event_type, enabled);
589 }
590
591 return JVMTI_ERROR_NONE;
592 } /* end SetEventNotificationMode */
593
594 //
595 // Capability functions
596 //
597
598 // capabilities_ptr - pre-checked for NULL
599 jvmtiError
600 JvmtiEnv::GetPotentialCapabilities(jvmtiCapabilities* capabilities_ptr) {
601 JvmtiManageCapabilities::get_potential_capabilities(get_capabilities(),
602 get_prohibited_capabilities(),
603 capabilities_ptr);
604 return JVMTI_ERROR_NONE;
605 } /* end GetPotentialCapabilities */
606
607
3630 JvmtiEnv::GetTimerInfo(jvmtiTimerInfo* info_ptr) {
3631 os::javaTimeNanos_info(info_ptr);
3632 return JVMTI_ERROR_NONE;
3633 } /* end GetTimerInfo */
3634
3635
3636 // nanos_ptr - pre-checked for NULL
3637 jvmtiError
3638 JvmtiEnv::GetTime(jlong* nanos_ptr) {
3639 *nanos_ptr = os::javaTimeNanos();
3640 return JVMTI_ERROR_NONE;
3641 } /* end GetTime */
3642
3643
3644 // processor_count_ptr - pre-checked for NULL
3645 jvmtiError
3646 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) {
3647 *processor_count_ptr = os::active_processor_count();
3648 return JVMTI_ERROR_NONE;
3649 } /* end GetAvailableProcessors */
3650
3651 jvmtiError
3652 JvmtiEnv::SetHeapSamplingRate(jint sampling_rate) {
3653 if (sampling_rate < 0) {
3654 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
3655 }
3656 ThreadHeapSampler::set_tlab_heap_sampling(sampling_rate);
3657 return JVMTI_ERROR_NONE;
3658 } /* end SetHeapSamplingRate */
3659
3660 //
3661 // System Properties functions
3662 //
3663
3664 // count_ptr - pre-checked for NULL
3665 // property_ptr - pre-checked for NULL
3666 jvmtiError
3667 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) {
3668 jvmtiError err = JVMTI_ERROR_NONE;
3669
3670 // Get the number of readable properties.
3671 *count_ptr = Arguments::PropertyList_readable_count(Arguments::system_properties());
3672
3673 // Allocate memory to hold the exact number of readable properties.
3674 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr);
3675 if (err != JVMTI_ERROR_NONE) {
3676 return err;
3677 }
3678 int readable_count = 0;
|