diff --git a/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp b/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp index f2007231c2240..882d468a4a3ae 100644 --- a/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp +++ b/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp @@ -156,6 +156,8 @@ void JfrJvmtiAgent::retransform_classes(JNIEnv* env, jobjectArray classes_array, return; } ResourceMark rm(THREAD); + // WXWrite is needed before entering the vm below and in callee methods. + MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, THREAD)); jclass* const classes = create_classes_array(classes_count, CHECK); assert(classes != nullptr, "invariant"); for (jint i = 0; i < classes_count; i++) { diff --git a/src/hotspot/share/jfr/jni/jfrJniMethod.cpp b/src/hotspot/share/jfr/jni/jfrJniMethod.cpp index f087e92f52705..8953976cd0c7a 100644 --- a/src/hotspot/share/jfr/jni/jfrJniMethod.cpp +++ b/src/hotspot/share/jfr/jni/jfrJniMethod.cpp @@ -104,7 +104,9 @@ NO_TRANSITION_END NO_TRANSITION(void, jfr_set_enabled(JNIEnv* env, jclass jvm, jlong event_type_id, jboolean enabled)) JfrEventSetting::set_enabled(event_type_id, JNI_TRUE == enabled); if (EventOldObjectSample::eventId == event_type_id) { - ThreadInVMfromNative transition(JavaThread::thread_from_jni_environment(env)); + JavaThread* thread = JavaThread::thread_from_jni_environment(env); + MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); + ThreadInVMfromNative transition(thread); if (JNI_TRUE == enabled) { LeakProfiler::start(JfrOptionSet::old_object_queue_size()); } else { diff --git a/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp b/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp index 4f87916248345..fc2043a4d921d 100644 --- a/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp +++ b/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp @@ -699,6 +699,8 @@ void JfrRecorderService::emit_leakprofiler_events(int64_t cutoff_ticks, bool emi // and serializes all event emit checkpoint events to the same segment. JfrRotationLock lock; // Take the rotation lock before the transition. - ThreadInVMfromNative transition(JavaThread::current()); + JavaThread* current_thread = JavaThread::current(); + MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current_thread)); + ThreadInVMfromNative transition(current_thread); LeakProfiler::emit_events(cutoff_ticks, emit_all, skip_bfs); } diff --git a/src/hotspot/share/jfr/recorder/storage/jfrStorage.cpp b/src/hotspot/share/jfr/recorder/storage/jfrStorage.cpp index 49f7719d00d72..d9f90ee115306 100644 --- a/src/hotspot/share/jfr/recorder/storage/jfrStorage.cpp +++ b/src/hotspot/share/jfr/recorder/storage/jfrStorage.cpp @@ -291,6 +291,7 @@ void JfrStorage::register_full(BufferPtr buffer, Thread* thread) { JavaThread* jt = JavaThread::cast(thread); if (jt->thread_state() == _thread_in_native) { // Transition java thread to vm so it can issue a notify. + MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, jt)); ThreadInVMfromNative transition(jt); _post_box.post(MSG_FULLBUFFER); return; diff --git a/src/hotspot/share/jfr/support/jfrIntrinsics.cpp b/src/hotspot/share/jfr/support/jfrIntrinsics.cpp index acc640077d46e..4b7c6c8aee9ce 100644 --- a/src/hotspot/share/jfr/support/jfrIntrinsics.cpp +++ b/src/hotspot/share/jfr/support/jfrIntrinsics.cpp @@ -56,6 +56,7 @@ void* JfrIntrinsicSupport::write_checkpoint(JavaThread* jt) { assert(JfrThreadLocal::is_vthread(jt), "invariant"); const u2 vthread_thread_local_epoch = JfrThreadLocal::vthread_epoch(jt); const u2 current_epoch = ThreadIdAccess::current_epoch(); + MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, jt)); if (vthread_thread_local_epoch == current_epoch) { // After the epoch test in the intrinsic, the thread sampler interleaved // and suspended the thread. As part of taking a sample, it updated diff --git a/src/hotspot/share/jfr/writers/jfrJavaEventWriter.cpp b/src/hotspot/share/jfr/writers/jfrJavaEventWriter.cpp index 9b27f06df7a12..2bd66ce7c1cc4 100644 --- a/src/hotspot/share/jfr/writers/jfrJavaEventWriter.cpp +++ b/src/hotspot/share/jfr/writers/jfrJavaEventWriter.cpp @@ -123,6 +123,7 @@ void JfrJavaEventWriter::flush(jobject writer, jint used, jint requested, JavaTh u1* const new_current_position = is_valid ? buffer->pos() + used : buffer->pos(); assert(start_pos_offset != invalid_offset, "invariant"); // can safepoint here + MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, jt)); ThreadInVMfromNative transition(jt); oop const w = JNIHandles::resolve_non_null(writer); assert(w != nullptr, "invariant"); diff --git a/src/hotspot/share/prims/jvmtiExport.cpp b/src/hotspot/share/prims/jvmtiExport.cpp index 2afbe72073289..5a87e16c855b2 100644 --- a/src/hotspot/share/prims/jvmtiExport.cpp +++ b/src/hotspot/share/prims/jvmtiExport.cpp @@ -382,6 +382,7 @@ JvmtiExport::get_jvmti_interface(JavaVM *jvm, void **penv, jint version) { if (JvmtiEnv::get_phase() == JVMTI_PHASE_LIVE) { JavaThread* current_thread = JavaThread::current(); // transition code: native to VM + MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current_thread)); ThreadInVMfromNative __tiv(current_thread); VM_ENTRY_BASE(jvmtiEnv*, JvmtiExport::get_jvmti_interface, current_thread) debug_only(VMNativeEntryWrapper __vew;) diff --git a/src/hotspot/share/prims/jvmtiExtensions.cpp b/src/hotspot/share/prims/jvmtiExtensions.cpp index b40ad7ddbd108..c17674542270f 100644 --- a/src/hotspot/share/prims/jvmtiExtensions.cpp +++ b/src/hotspot/share/prims/jvmtiExtensions.cpp @@ -130,6 +130,7 @@ static jvmtiError JNICALL GetCarrierThread(const jvmtiEnv* env, ...) { thread_ptr = va_arg(ap, jthread*); va_end(ap); + MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current_thread)); ThreadInVMfromNative tiv(current_thread); JvmtiVTMSTransitionDisabler disabler;