diff --git a/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp b/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp index a9a194b7460..481f55adc38 100644 --- a/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp +++ b/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp @@ -118,6 +118,7 @@ static void log_and_throw(jvmtiError error, TRAPS) { ThreadInVMfromNative tvmfn(THREAD); const char base_error_msg[] = "JfrJvmtiAgent::retransformClasses failed: "; size_t length = sizeof base_error_msg; // includes terminating null +#if INCLUDE_JVMTI const char* const jvmti_error_name = JvmtiUtil::error_name(error); assert(jvmti_error_name != NULL, "invariant"); length += strlen(jvmti_error_name); @@ -128,6 +129,7 @@ static void log_and_throw(jvmtiError error, TRAPS) { } else { JfrJavaSupport::throw_runtime_exception(error_msg, THREAD); } +#endif // INCLUDE_JVMTI } } @@ -142,14 +144,18 @@ static void check_exception_and_log(JNIEnv* env, TRAPS) { } } +#if INCLUDE_JVMTI static bool is_valid_jvmti_phase() { return JvmtiEnvBase::get_phase() == JVMTI_PHASE_LIVE; } +#endif // INCLUDE_JVMTI void JfrJvmtiAgent::retransform_classes(JNIEnv* env, jobjectArray classes_array, TRAPS) { assert(env != NULL, "invariant"); assert(classes_array != NULL, "invariant"); +#if INCLUDE_JVMTI assert(is_valid_jvmti_phase(), "invariant"); +#endif // INCLUDE_JVMTI DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_native(THREAD)); const jint classes_count = env->GetArrayLength(classes_array); if (classes_count <= 0) { @@ -256,6 +262,7 @@ static bool initialize(JavaThread* jt) { return update_class_file_load_hook_event(JVMTI_ENABLE); } +#if INCLUDE_JVMTI static void log_and_throw_illegal_state_exception(TRAPS) { DEBUG_ONLY(JfrJavaSupport::check_java_thread_in_vm(THREAD)); const char* const illegal_state_msg = "An attempt was made to start JFR too early in the VM initialization sequence."; @@ -264,14 +271,17 @@ static void log_and_throw_illegal_state_exception(TRAPS) { log_error(jfr, system)("Please initialize JFR in response to event JVMTI_EVENT_VM_INIT instead of JVMTI_EVENT_VM_START."); JfrJavaSupport::throw_illegal_state_exception(illegal_state_msg, THREAD); } +#endif // INCLUDE_JVMTI bool JfrJvmtiAgent::create() { assert(agent == NULL, "invariant"); JavaThread* const jt = JavaThread::current(); +#if INCLUDE_JVMTI if (!is_valid_jvmti_phase()) { log_and_throw_illegal_state_exception(jt); return false; } +#endif // INCLUDE_JVMTI agent = new JfrJvmtiAgent(); if (agent == NULL) { return false; diff --git a/src/hotspot/share/prims/jvmtiEnvBase.cpp b/src/hotspot/share/prims/jvmtiEnvBase.cpp index 747574689b9..89ba3f3621c 100644 --- a/src/hotspot/share/prims/jvmtiEnvBase.cpp +++ b/src/hotspot/share/prims/jvmtiEnvBase.cpp @@ -69,7 +69,9 @@ JvmtiEnvBase* JvmtiEnvBase::_head_environment = NULL; bool JvmtiEnvBase::_globally_initialized = false; volatile bool JvmtiEnvBase::_needs_clean_up = false; +#if INCLUDE_JVMTI jvmtiPhase JvmtiEnvBase::_phase = JVMTI_PHASE_PRIMORDIAL; +#endif // INCLUDE_JVMTI volatile int JvmtiEnvBase::_dying_thread_env_iteration_count = 0; diff --git a/src/hotspot/share/prims/jvmtiEnvBase.hpp b/src/hotspot/share/prims/jvmtiEnvBase.hpp index ad29077f9ba..cd31bb50097 100644 --- a/src/hotspot/share/prims/jvmtiEnvBase.hpp +++ b/src/hotspot/share/prims/jvmtiEnvBase.hpp @@ -73,9 +73,12 @@ class JvmtiEnvBase : public CHeapObj { JDK17_JVMTI_VERSION = JVMTI_VERSION_1_2 + 2 /* version: 1.2.2 */ }; +#if INCLUDE_JVMTI static jvmtiPhase get_phase() { return _phase; } static jvmtiPhase get_phase(jvmtiEnv* env) { return ((JvmtiEnvBase*)JvmtiEnv_from_jvmti_env(env))->phase(); } static void set_phase(jvmtiPhase phase) { _phase = phase; } +#endif // INCLUDE_JVMTI + static bool is_vm_live() { return _phase == JVMTI_PHASE_LIVE; } static void entering_dying_thread_env_iteration() { ++_dying_thread_env_iteration_count; }