46 #include "prims/jvmtiCodeBlobEvents.hpp"
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/osThread.hpp"
63 #include "runtime/reflectionUtils.hpp"
64 #include "runtime/signature.hpp"
65 #include "runtime/thread.inline.hpp"
66 #include "runtime/threadSMR.hpp"
67 #include "runtime/timerTrace.hpp"
68 #include "runtime/vframe.hpp"
69 #include "runtime/vmThread.hpp"
70 #include "services/threadService.hpp"
71 #include "utilities/exceptions.hpp"
72 #include "utilities/preserveException.hpp"
73
74
75 #define FIXLATER 0 // REMOVE this when completed.
76
77 // FIXLATER: hook into JvmtiTrace
78 #define TraceJVMTICalls false
79
80 JvmtiEnv::JvmtiEnv(jint version) : JvmtiEnvBase(version) {
81 }
82
83 JvmtiEnv::~JvmtiEnv() {
84 }
85
519 // Can be called at Agent_OnLoad() time with event_thread == NULL
520 // when Thread::current() does not work yet so we cannot create a
521 // ThreadsListHandle that is common to both thread-specific and
522 // global code paths.
523
524 // event_type must be valid
525 if (!JvmtiEventController::is_valid_event_type(event_type)) {
526 return JVMTI_ERROR_INVALID_EVENT_TYPE;
527 }
528
529 bool enabled = (mode == JVMTI_ENABLE);
530
531 // assure that needed capabilities are present
532 if (enabled && !JvmtiUtil::has_event_capability(event_type, get_capabilities())) {
533 return JVMTI_ERROR_MUST_POSSESS_CAPABILITY;
534 }
535
536 if (event_type == JVMTI_EVENT_CLASS_FILE_LOAD_HOOK && enabled) {
537 record_class_file_load_hook_enabled();
538 }
539 JvmtiEventController::set_user_enabled(this, (JavaThread*) NULL, event_type, enabled);
540 } else {
541 // We have a specified event_thread.
542
543 JavaThread* java_thread = NULL;
544 ThreadsListHandle tlh;
545 jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), event_thread, &java_thread, NULL);
546 if (err != JVMTI_ERROR_NONE) {
547 return err;
548 }
549
550 // event_type must be valid
551 if (!JvmtiEventController::is_valid_event_type(event_type)) {
552 return JVMTI_ERROR_INVALID_EVENT_TYPE;
553 }
554
555 // global events cannot be controlled at thread level.
556 if (JvmtiEventController::is_global_event(event_type)) {
557 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
558 }
3612 JvmtiEnv::GetTimerInfo(jvmtiTimerInfo* info_ptr) {
3613 os::javaTimeNanos_info(info_ptr);
3614 return JVMTI_ERROR_NONE;
3615 } /* end GetTimerInfo */
3616
3617
3618 // nanos_ptr - pre-checked for NULL
3619 jvmtiError
3620 JvmtiEnv::GetTime(jlong* nanos_ptr) {
3621 *nanos_ptr = os::javaTimeNanos();
3622 return JVMTI_ERROR_NONE;
3623 } /* end GetTime */
3624
3625
3626 // processor_count_ptr - pre-checked for NULL
3627 jvmtiError
3628 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) {
3629 *processor_count_ptr = os::active_processor_count();
3630 return JVMTI_ERROR_NONE;
3631 } /* end GetAvailableProcessors */
3632
3633 //
3634 // System Properties functions
3635 //
3636
3637 // count_ptr - pre-checked for NULL
3638 // property_ptr - pre-checked for NULL
3639 jvmtiError
3640 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) {
3641 jvmtiError err = JVMTI_ERROR_NONE;
3642
3643 // Get the number of readable properties.
3644 *count_ptr = Arguments::PropertyList_readable_count(Arguments::system_properties());
3645
3646 // Allocate memory to hold the exact number of readable properties.
3647 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr);
3648 if (err != JVMTI_ERROR_NONE) {
3649 return err;
3650 }
3651 int readable_count = 0;
|
46 #include "prims/jvmtiCodeBlobEvents.hpp"
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/osThread.hpp"
63 #include "runtime/reflectionUtils.hpp"
64 #include "runtime/signature.hpp"
65 #include "runtime/thread.inline.hpp"
66 #include "runtime/threadHeapSampler.hpp"
67 #include "runtime/threadSMR.hpp"
68 #include "runtime/timerTrace.hpp"
69 #include "runtime/vframe.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 if (event_type == JVMTI_EVENT_SAMPLED_OBJECT_ALLOC) {
541 if (enabled) {
542 ThreadHeapSampler::enable();
543 } else {
544 ThreadHeapSampler::disable();
545 }
546 }
547 JvmtiEventController::set_user_enabled(this, (JavaThread*) NULL, event_type, enabled);
548 } else {
549 // We have a specified event_thread.
550
551 JavaThread* java_thread = NULL;
552 ThreadsListHandle tlh;
553 jvmtiError err = JvmtiExport::cv_external_thread_to_JavaThread(tlh.list(), event_thread, &java_thread, NULL);
554 if (err != JVMTI_ERROR_NONE) {
555 return err;
556 }
557
558 // event_type must be valid
559 if (!JvmtiEventController::is_valid_event_type(event_type)) {
560 return JVMTI_ERROR_INVALID_EVENT_TYPE;
561 }
562
563 // global events cannot be controlled at thread level.
564 if (JvmtiEventController::is_global_event(event_type)) {
565 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
566 }
3620 JvmtiEnv::GetTimerInfo(jvmtiTimerInfo* info_ptr) {
3621 os::javaTimeNanos_info(info_ptr);
3622 return JVMTI_ERROR_NONE;
3623 } /* end GetTimerInfo */
3624
3625
3626 // nanos_ptr - pre-checked for NULL
3627 jvmtiError
3628 JvmtiEnv::GetTime(jlong* nanos_ptr) {
3629 *nanos_ptr = os::javaTimeNanos();
3630 return JVMTI_ERROR_NONE;
3631 } /* end GetTime */
3632
3633
3634 // processor_count_ptr - pre-checked for NULL
3635 jvmtiError
3636 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) {
3637 *processor_count_ptr = os::active_processor_count();
3638 return JVMTI_ERROR_NONE;
3639 } /* end GetAvailableProcessors */
3640
3641 jvmtiError
3642 JvmtiEnv::SetHeapSamplingRate(jint sampling_rate) {
3643 if (sampling_rate < 0) {
3644 return JVMTI_ERROR_ILLEGAL_ARGUMENT;
3645 }
3646 ThreadHeapSampler::set_tlab_heap_sampling(sampling_rate);
3647 return JVMTI_ERROR_NONE;
3648 } /* end SetHeapSamplingRate */
3649
3650 //
3651 // System Properties functions
3652 //
3653
3654 // count_ptr - pre-checked for NULL
3655 // property_ptr - pre-checked for NULL
3656 jvmtiError
3657 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) {
3658 jvmtiError err = JVMTI_ERROR_NONE;
3659
3660 // Get the number of readable properties.
3661 *count_ptr = Arguments::PropertyList_readable_count(Arguments::system_properties());
3662
3663 // Allocate memory to hold the exact number of readable properties.
3664 err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr);
3665 if (err != JVMTI_ERROR_NONE) {
3666 return err;
3667 }
3668 int readable_count = 0;
|