< prev index next >

src/hotspot/share/prims/jvmtiEnv.cpp

Print this page
rev 50392 : JEP 331


  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


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


3621 JvmtiEnv::GetTimerInfo(jvmtiTimerInfo* info_ptr) {
3622   os::javaTimeNanos_info(info_ptr);
3623   return JVMTI_ERROR_NONE;
3624 } /* end GetTimerInfo */
3625 
3626 
3627 // nanos_ptr - pre-checked for NULL
3628 jvmtiError
3629 JvmtiEnv::GetTime(jlong* nanos_ptr) {
3630   *nanos_ptr = os::javaTimeNanos();
3631   return JVMTI_ERROR_NONE;
3632 } /* end GetTime */
3633 
3634 
3635 // processor_count_ptr - pre-checked for NULL
3636 jvmtiError
3637 JvmtiEnv::GetAvailableProcessors(jint* processor_count_ptr) {
3638   *processor_count_ptr = os::active_processor_count();
3639   return JVMTI_ERROR_NONE;
3640 } /* end GetAvailableProcessors */
3641 
3642 jvmtiError
3643 JvmtiEnv::SetHeapSamplingRate(jint sampling_rate) {
3644   if (sampling_rate < 0) {
3645     return JVMTI_ERROR_ILLEGAL_ARGUMENT;
3646   }
3647   ThreadHeapSampler::set_sampling_rate(sampling_rate);
3648   return JVMTI_ERROR_NONE;
3649 } /* end SetHeapSamplingRate */
3650 
3651   //
3652   // System Properties functions
3653   //
3654 
3655 // count_ptr - pre-checked for NULL
3656 // property_ptr - pre-checked for NULL
3657 jvmtiError
3658 JvmtiEnv::GetSystemProperties(jint* count_ptr, char*** property_ptr) {
3659   jvmtiError err = JVMTI_ERROR_NONE;
3660 
3661   // Get the number of readable properties.
3662   *count_ptr = Arguments::PropertyList_readable_count(Arguments::system_properties());
3663 
3664   // Allocate memory to hold the exact number of readable properties.
3665   err = allocate(*count_ptr * sizeof(char *), (unsigned char **)property_ptr);
3666   if (err != JVMTI_ERROR_NONE) {
3667     return err;
3668   }
3669   int readable_count = 0;


< prev index next >