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 JavaThread* java_thread = NULL;
553 ThreadsListHandle tlh;
554 jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), event_thread, &java_thread, NULL);
555 if (err != JVMTI_ERROR_NONE) {
556 return err;
557 }
558
559 // event_type must be valid
560 if (!JvmtiEventController::is_valid_event_type(event_type)) {
561 return JVMTI_ERROR_INVALID_EVENT_TYPE;
562 }
563
564 // global events cannot be controlled at thread level.
565 if (JvmtiEventController::is_global_event(event_type)) {
566 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
567 }
568
569 bool enabled = (mode == JVMTI_ENABLE);
570
571 // assure that needed capabilities are present
572 if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) {
573 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
574 }
575
576 if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) {
577 record_class_file_load_hook_enabled();
578 }
579
580 if (event_type == JVMTI_EVENT_SAMPLED_OBJECT_ALLOC) {
581 if (enabled) {
582 ThreadHeapSampler::enable();
583 } else {
584 ThreadHeapSampler::disable();
585 }
586 }
587 JvmtiEventController::set_user_enabled(this, java_thread, event_type, enabled);
588 }
589
590 return JVMTI_ERROR_NONE;
591 } /* end SetEventNotificationMode */
592
593 //
594 // Capability functions
595 //
596
597 // capabilities_ptr - pre-checked for NULL
598 jvmtiError
599 JvmtiEnv::GetPotentialCapabilities(jvmtiCapabilities* capabilities_ptr) {
600 JvmtiManageCapabilities::get_potential_capabilities(get_capabilities(),
601 get_prohibited_capabilities(),
602 capabilities_ptr);
603 return JVMTI_ERROR_NONE;
604 } /* end GetPotentialCapabilities */
605
606
3629 JvmtiEnv::GetTimerInfo(jvmtiTimerInfo* info_ptr) {
3630 os::javaTimeNanos_info(info_ptr);
3631 return JVMTI_ERROR_NONE;
3632 } /* end GetTimerInfo */
3633
3634
3635 // nanos_ptr - pre-checked for NULL
3636 jvmtiError
3637 JvmtiEnv::GetTime(jlong* nanos_ptr) {
3638 *nanos_ptr = os::javaTimeNanos();
3639 return JVMTI_ERROR_NONE;
3640 } /* end GetTime */
3641
3642
3643 // processor_count_ptr - pre-checked for NULL
3644 jvmtiError
3645 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) {
3646 *processor_count_ptr = os::active_processor_count();
3647 return JVMTI_ERROR_NONE;
3648 } /* end GetAvailableProcessors */
3649
3650 jvmtiError
3651 JvmtiEnv::SetHeapSamplingRate(jint sampling_rate) {
3652 if (sampling_rate < 0) {
3653 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
3654 }
3655 ThreadHeapSampler::set_sampling_rate(sampling_rate);
3656 return JVMTI_ERROR_NONE;
3657 } /* end SetHeapSamplingRate */
3658
3659 //
3660 // System Properties functions
3661 //
3662
3663 // count_ptr - pre-checked for NULL
3664 // property_ptr - pre-checked for NULL
3665 jvmtiError
3666 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) {
3667 jvmtiError err = JVMTI_ERROR_NONE;
3668
3669 // Get the number of readable properties.
3670 *count_ptr = Arguments::PropertyList_readable_count(Arguments::system_properties());
3671
3672 // Allocate memory to hold the exact number of readable properties.
3673 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr);
3674 if (err != JVMTI_ERROR_NONE) {
3675 return err;
3676 }
3677 int readable_count = 0;
|