From a4836678b87788f23cdfa7f144401fcaf9c50bbf Mon Sep 17 00:00:00 2001 From: Sergey Nazarkin Date: Thu, 11 Apr 2024 13:32:23 +0300 Subject: [PATCH 1/4] Lazy W^X state switch --- .../os_cpu/bsd_aarch64/os_bsd_aarch64.cpp | 14 +++++ src/hotspot/share/memory/virtualspace.cpp | 3 ++ .../share/runtime/threadWXSetters.inline.hpp | 52 ------------------- 3 files changed, 17 insertions(+), 52 deletions(-) delete mode 100644 src/hotspot/share/runtime/threadWXSetters.inline.hpp diff --git a/src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp b/src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp index 3dfe9e30f7904..f92ffc24f3e43 100644 --- a/src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp +++ b/src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp @@ -203,6 +203,20 @@ bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info, address pc = nullptr; + #if defined(__APPLE__) && defined(AARCH64) + if (nullptr != uc && nullptr != info && CodeCache::contains(info->si_addr) && sig == SIGBUS){ + // we can get here from non-java thread + pc = (address) os::Posix::ucontext_get_pc(uc); + if (pc == info->si_addr){ + os::current_thread_enable_wx(WXExec); + } + else{ + os::current_thread_enable_wx(WXWrite); + } + return true; + } + #endif + //%note os_trap_1 if (info != nullptr && uc != nullptr && thread != nullptr) { pc = (address) os::Posix::ucontext_get_pc(uc); diff --git a/src/hotspot/share/memory/virtualspace.cpp b/src/hotspot/share/memory/virtualspace.cpp index a75d9f076ad22..007115e3ac46d 100644 --- a/src/hotspot/share/memory/virtualspace.cpp +++ b/src/hotspot/share/memory/virtualspace.cpp @@ -839,6 +839,9 @@ static void pretouch_expanded_memory(void* start, void* end) { static bool commit_expanded(char* start, size_t size, size_t alignment, bool pre_touch, bool executable) { if (os::commit_memory(start, size, alignment, executable)) { if (pre_touch || AlwaysPreTouch) { + if (executable){ + os::current_thread_enable_wx(WXWrite); + } pretouch_expanded_memory(start, start + size); } return true; diff --git a/src/hotspot/share/runtime/threadWXSetters.inline.hpp b/src/hotspot/share/runtime/threadWXSetters.inline.hpp deleted file mode 100644 index 121584b81be85..0000000000000 --- a/src/hotspot/share/runtime/threadWXSetters.inline.hpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2021, Azul Systems, Inc. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#ifndef SHARE_RUNTIME_THREADWXSETTERS_INLINE_HPP -#define SHARE_RUNTIME_THREADWXSETTERS_INLINE_HPP - -// No threadWXSetters.hpp - -#if defined(__APPLE__) && defined(AARCH64) - -#include "runtime/thread.inline.hpp" - -class ThreadWXEnable { - Thread* _thread; - WXMode _old_mode; -public: - ThreadWXEnable(WXMode new_mode, Thread* thread) : - _thread(thread), - _old_mode(_thread ? _thread->enable_wx(new_mode) : WXWrite) - { } - ~ThreadWXEnable() { - if (_thread) { - _thread->enable_wx(_old_mode); - } - } -}; -#endif // __APPLE__ && AARCH64 - -#endif // SHARE_RUNTIME_THREADWXSETTERS_INLINE_HPP - From ba5932b2c055ffa6e9083679938f101870853dcb Mon Sep 17 00:00:00 2001 From: Sergey Nazarkin Date: Thu, 11 Apr 2024 17:42:09 +0300 Subject: [PATCH 2/4] Remove ThreadWXEnable guard --- .../cpu/aarch64/jniFastGetField_aarch64.cpp | 38 ------------------- src/hotspot/os/bsd/globals_bsd.hpp | 6 +-- src/hotspot/os/posix/signals_posix.cpp | 1 - .../os_cpu/bsd_aarch64/os_bsd_aarch64.cpp | 4 -- src/hotspot/share/c1/c1_Runtime1.cpp | 4 -- src/hotspot/share/code/nmethod.cpp | 2 - .../share/gc/shared/barrierSetNMethod.cpp | 6 --- .../shenandoahBarrierSetNMethod.cpp | 3 -- src/hotspot/share/gc/x/xBarrierSetNMethod.cpp | 3 -- src/hotspot/share/gc/z/zBarrierSetNMethod.cpp | 3 -- .../share/interpreter/interpreterRuntime.cpp | 3 -- .../jfr/instrumentation/jfrJvmtiAgent.cpp | 2 - src/hotspot/share/jfr/jni/jfrJniMethod.cpp | 1 - .../recorder/service/jfrRecorderService.cpp | 1 - .../share/jfr/recorder/storage/jfrStorage.cpp | 1 - .../share/jfr/support/jfrIntrinsics.cpp | 1 - .../share/jfr/writers/jfrJavaEventWriter.cpp | 1 - src/hotspot/share/jvmci/jvmciCompilerToVM.cpp | 1 - src/hotspot/share/opto/runtime.cpp | 1 - src/hotspot/share/prims/jni.cpp | 13 ------- src/hotspot/share/prims/jniCheck.cpp | 1 - src/hotspot/share/prims/jvmtiEnter.xsl | 1 - src/hotspot/share/prims/jvmtiEnv.cpp | 5 --- src/hotspot/share/prims/jvmtiExport.cpp | 2 - src/hotspot/share/prims/jvmtiExtensions.cpp | 1 - src/hotspot/share/prims/unsafe.cpp | 3 -- src/hotspot/share/prims/upcallLinker.cpp | 4 -- src/hotspot/share/prims/whitebox.inline.hpp | 3 +- .../share/runtime/continuationFreezeThaw.cpp | 2 - src/hotspot/share/runtime/deoptimization.cpp | 4 -- .../share/runtime/interfaceSupport.inline.hpp | 15 -------- src/hotspot/share/runtime/javaCalls.cpp | 3 -- src/hotspot/share/runtime/javaThread.cpp | 13 ------- src/hotspot/share/runtime/safepoint.cpp | 4 -- src/hotspot/share/runtime/sharedRuntime.cpp | 6 --- src/hotspot/share/runtime/stubRoutines.hpp | 3 -- src/hotspot/share/runtime/thread.cpp | 4 -- src/hotspot/share/runtime/thread.hpp | 13 ------- src/hotspot/share/runtime/thread.inline.hpp | 25 ------------ src/hotspot/share/runtime/threads.cpp | 3 -- test/hotspot/gtest/gtestMain.cpp | 6 --- .../gtest/runtime/test_stubRoutines.cpp | 6 --- test/hotspot/gtest/runtime/test_threads.cpp | 1 - 43 files changed, 2 insertions(+), 221 deletions(-) diff --git a/src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp b/src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp index e79b93651b072..fbcde0293a168 100644 --- a/src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp @@ -33,7 +33,6 @@ #include "prims/jvmtiExport.hpp" #include "runtime/javaThread.inline.hpp" #include "runtime/safepoint.hpp" -#include "runtime/threadWXSetters.inline.hpp" #define __ masm-> @@ -54,48 +53,11 @@ static const Register roffset = r5; static const Register rcounter_addr = r6; static const Register result = r7; -// On macos/aarch64 we need to ensure WXExec mode when running generated -// FastGetXXXField, as these functions can be called from WXWrite context -// (8262896). So each FastGetXXXField is wrapped into a C++ statically -// compiled template function that optionally switches to WXExec if necessary. - -#ifdef __APPLE__ - -static address generated_fast_get_field[T_LONG + 1 - T_BOOLEAN]; - -template struct BasicTypeToJni {}; -template<> struct BasicTypeToJni { static const jboolean jni_type; }; -template<> struct BasicTypeToJni { static const jbyte jni_type; }; -template<> struct BasicTypeToJni { static const jchar jni_type; }; -template<> struct BasicTypeToJni { static const jshort jni_type; }; -template<> struct BasicTypeToJni { static const jint jni_type; }; -template<> struct BasicTypeToJni { static const jlong jni_type; }; -template<> struct BasicTypeToJni { static const jfloat jni_type; }; -template<> struct BasicTypeToJni { static const jdouble jni_type; }; - -template::jni_type)> -JniType static_fast_get_field_wrapper(JNIEnv *env, jobject obj, jfieldID fieldID) { - JavaThread* thread = JavaThread::thread_from_jni_environment(env); - ThreadWXEnable wx(WXExec, thread); - address get_field_addr = generated_fast_get_field[BType - T_BOOLEAN]; - return ((JniType(*)(JNIEnv *env, jobject obj, jfieldID fieldID))get_field_addr)(env, obj, fieldID); -} - -template -address JNI_FastGetField::generate_fast_get_int_field1() { - generated_fast_get_field[BType - T_BOOLEAN] = generate_fast_get_int_field0((BasicType)BType); - return (address)static_fast_get_field_wrapper; -} - -#else // __APPLE__ - template address JNI_FastGetField::generate_fast_get_int_field1() { return generate_fast_get_int_field0((BasicType)BType); } -#endif // __APPLE__ - address JNI_FastGetField::generate_fast_get_int_field0(BasicType type) { const char *name; switch (type) { diff --git a/src/hotspot/os/bsd/globals_bsd.hpp b/src/hotspot/os/bsd/globals_bsd.hpp index 66fae6a49d239..407b1f5adf63c 100644 --- a/src/hotspot/os/bsd/globals_bsd.hpp +++ b/src/hotspot/os/bsd/globals_bsd.hpp @@ -33,11 +33,7 @@ product, \ product_pd, \ range, \ - constraint) \ - \ - AARCH64_ONLY(develop(bool, AssertWXAtThreadSync, false, \ - "Conservatively check W^X thread state at possible safepoint" \ - "or handshake")) + constraint) // end of RUNTIME_OS_FLAGS diff --git a/src/hotspot/os/posix/signals_posix.cpp b/src/hotspot/os/posix/signals_posix.cpp index 5172853ecd5c2..a9d3bb9284c49 100644 --- a/src/hotspot/os/posix/signals_posix.cpp +++ b/src/hotspot/os/posix/signals_posix.cpp @@ -614,7 +614,6 @@ int JVM_HANDLE_XXX_SIGNAL(int sig, siginfo_t* info, if (NativeDeoptInstruction::is_deopt_at(pc)) { CodeBlob* cb = CodeCache::find_blob(pc); if (cb != nullptr && cb->is_nmethod()) { - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, t);) // can call PcDescCache::add_pc_desc nmethod* nm = cb->as_nmethod(); assert(nm->insts_contains_inclusive(pc), ""); address deopt = nm->is_method_handle_return(pc) ? diff --git a/src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp b/src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp index f92ffc24f3e43..b0332a1a04992 100644 --- a/src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp +++ b/src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp @@ -194,10 +194,6 @@ NOINLINE frame os::current_frame() { bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info, ucontext_t* uc, JavaThread* thread) { - // Enable WXWrite: this function is called by the signal handler at arbitrary - // point of execution. - ThreadWXEnable wx(WXWrite, thread); - // decide if this trap can be handled by a stub address stub = nullptr; diff --git a/src/hotspot/share/c1/c1_Runtime1.cpp b/src/hotspot/share/c1/c1_Runtime1.cpp index ffebe38964495..7ba1c5c47575f 100644 --- a/src/hotspot/share/c1/c1_Runtime1.cpp +++ b/src/hotspot/share/c1/c1_Runtime1.cpp @@ -1317,10 +1317,6 @@ void Runtime1::patch_code(JavaThread* current, Runtime1::StubID stub_id) { } #endif - // Enable WXWrite: the function is called by c1 stub as a runtime function - // (see another implementation above). - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current)); - if (TracePatching) { tty->print_cr("Deoptimizing because patch is needed"); } diff --git a/src/hotspot/share/code/nmethod.cpp b/src/hotspot/share/code/nmethod.cpp index 51ba872b3ac66..3ef65d5946c96 100644 --- a/src/hotspot/share/code/nmethod.cpp +++ b/src/hotspot/share/code/nmethod.cpp @@ -72,7 +72,6 @@ #include "runtime/serviceThread.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/signature.hpp" -#include "runtime/threadWXSetters.inline.hpp" #include "runtime/vmThread.hpp" #include "utilities/align.hpp" #include "utilities/copy.hpp" @@ -403,7 +402,6 @@ PcDesc* PcDescCache::find_pc_desc(int pc_offset, bool approximate) { } void PcDescCache::add_pc_desc(PcDesc* pc_desc) { - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, Thread::current());) NOT_PRODUCT(++pc_nmethod_stats.pc_desc_adds); // Update the LRU cache by shifting pc_desc forward. for (int i = 0; i < cache_size; i++) { diff --git a/src/hotspot/share/gc/shared/barrierSetNMethod.cpp b/src/hotspot/share/gc/shared/barrierSetNMethod.cpp index adf0527681b5e..adec3417ac3d9 100644 --- a/src/hotspot/share/gc/shared/barrierSetNMethod.cpp +++ b/src/hotspot/share/gc/shared/barrierSetNMethod.cpp @@ -36,7 +36,6 @@ #include "oops/method.inline.hpp" #include "runtime/frame.inline.hpp" #include "runtime/javaThread.hpp" -#include "runtime/threadWXSetters.inline.hpp" #include "runtime/threads.hpp" #include "utilities/debug.hpp" #if INCLUDE_JVMCI @@ -166,12 +165,7 @@ void BarrierSetNMethod::arm_all_nmethods() { } int BarrierSetNMethod::nmethod_stub_entry_barrier(address* return_address_ptr) { - // Enable WXWrite: the function is called directly from nmethod_entry_barrier - // stub. - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, Thread::current())); - address return_address = *return_address_ptr; - AARCH64_PORT_ONLY(return_address = pauth_strip_pointer(return_address)); CodeBlob* cb = CodeCache::find_blob(return_address); assert(cb != nullptr, "invariant"); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSetNMethod.cpp b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSetNMethod.cpp index 20954156b9e4a..9c27a2e1084e4 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahBarrierSetNMethod.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahBarrierSetNMethod.cpp @@ -33,7 +33,6 @@ #include "gc/shenandoah/shenandoahThreadLocalData.hpp" #include "memory/iterator.hpp" #include "memory/resourceArea.hpp" -#include "runtime/threadWXSetters.inline.hpp" bool ShenandoahBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) { ShenandoahReentrantLock* lock = ShenandoahNMethod::lock_for_nmethod(nm); @@ -46,8 +45,6 @@ bool ShenandoahBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) { return true; } - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, Thread::current());) - if (nm->is_unloading()) { // We don't need to take the lock when unlinking nmethods from // the Method, because it is only concurrently unlinked by diff --git a/src/hotspot/share/gc/x/xBarrierSetNMethod.cpp b/src/hotspot/share/gc/x/xBarrierSetNMethod.cpp index 002d6bc00c5d7..146a5dd8c7346 100644 --- a/src/hotspot/share/gc/x/xBarrierSetNMethod.cpp +++ b/src/hotspot/share/gc/x/xBarrierSetNMethod.cpp @@ -29,7 +29,6 @@ #include "gc/x/xNMethod.hpp" #include "gc/x/xThreadLocalData.hpp" #include "logging/log.hpp" -#include "runtime/threadWXSetters.inline.hpp" bool XBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) { XLocker locker(XNMethod::lock_for_nmethod(nm)); @@ -41,8 +40,6 @@ bool XBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) { return true; } - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, Thread::current())); - if (nm->is_unloading()) { // We don't need to take the lock when unlinking nmethods from // the Method, because it is only concurrently unlinked by diff --git a/src/hotspot/share/gc/z/zBarrierSetNMethod.cpp b/src/hotspot/share/gc/z/zBarrierSetNMethod.cpp index 2c58b0155648a..7542401226f54 100644 --- a/src/hotspot/share/gc/z/zBarrierSetNMethod.cpp +++ b/src/hotspot/share/gc/z/zBarrierSetNMethod.cpp @@ -34,7 +34,6 @@ #include "gc/z/zThreadLocalData.hpp" #include "gc/z/zUncoloredRoot.inline.hpp" #include "logging/log.hpp" -#include "runtime/threadWXSetters.inline.hpp" bool ZBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) { ZLocker locker(ZNMethod::lock_for_nmethod(nm)); @@ -49,8 +48,6 @@ bool ZBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) { return true; } - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, Thread::current())); - if (nm->is_unloading()) { log_develop_trace(gc, nmethod)("nmethod: " PTR_FORMAT " visited by entry (unloading)", p2i(nm)); // We don't need to take the lock when unlinking nmethods from diff --git a/src/hotspot/share/interpreter/interpreterRuntime.cpp b/src/hotspot/share/interpreter/interpreterRuntime.cpp index ff7c453e01e0c..4fdfa0e3630ae 100644 --- a/src/hotspot/share/interpreter/interpreterRuntime.cpp +++ b/src/hotspot/share/interpreter/interpreterRuntime.cpp @@ -998,9 +998,6 @@ JRT_END nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) { - // Enable WXWrite: the function is called directly by interpreter. - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current)); - // frequency_counter_overflow_inner can throw async exception. nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp); assert(branch_bcp != nullptr || nm == nullptr, "always returns null for non OSR requests"); diff --git a/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp b/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp index 882d468a4a3ae..f2007231c2240 100644 --- a/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp +++ b/src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp @@ -156,8 +156,6 @@ 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 8953976cd0c7a..76fb932e45b57 100644 --- a/src/hotspot/share/jfr/jni/jfrJniMethod.cpp +++ b/src/hotspot/share/jfr/jni/jfrJniMethod.cpp @@ -105,7 +105,6 @@ NO_TRANSITION(void, jfr_set_enabled(JNIEnv* env, jclass jvm, jlong event_type_id JfrEventSetting::set_enabled(event_type_id, JNI_TRUE == enabled); if (EventOldObjectSample::eventId == event_type_id) { 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()); diff --git a/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp b/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp index fc2043a4d921d..35b543be91ac6 100644 --- a/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp +++ b/src/hotspot/share/jfr/recorder/service/jfrRecorderService.cpp @@ -700,7 +700,6 @@ void JfrRecorderService::emit_leakprofiler_events(int64_t cutoff_ticks, bool emi JfrRotationLock lock; // Take the rotation lock before the transition. 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 d9f90ee115306..49f7719d00d72 100644 --- a/src/hotspot/share/jfr/recorder/storage/jfrStorage.cpp +++ b/src/hotspot/share/jfr/recorder/storage/jfrStorage.cpp @@ -291,7 +291,6 @@ 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 4b7c6c8aee9ce..acc640077d46e 100644 --- a/src/hotspot/share/jfr/support/jfrIntrinsics.cpp +++ b/src/hotspot/share/jfr/support/jfrIntrinsics.cpp @@ -56,7 +56,6 @@ 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 2bd66ce7c1cc4..9b27f06df7a12 100644 --- a/src/hotspot/share/jfr/writers/jfrJavaEventWriter.cpp +++ b/src/hotspot/share/jfr/writers/jfrJavaEventWriter.cpp @@ -123,7 +123,6 @@ 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/jvmci/jvmciCompilerToVM.cpp b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp index 8a033492bbba2..ae48e5bb09d54 100644 --- a/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp +++ b/src/hotspot/share/jvmci/jvmciCompilerToVM.cpp @@ -162,7 +162,6 @@ Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) { // Bring the JVMCI compiler thread into the VM state. #define JVMCI_VM_ENTRY_MARK \ - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); \ ThreadInVMfromNative __tiv(thread); \ HandleMarkCleaner __hm(thread); \ JavaThread* THREAD = thread; \ diff --git a/src/hotspot/share/opto/runtime.cpp b/src/hotspot/share/opto/runtime.cpp index 605c95316e24b..d88d86abb86d6 100644 --- a/src/hotspot/share/opto/runtime.cpp +++ b/src/hotspot/share/opto/runtime.cpp @@ -71,7 +71,6 @@ #include "runtime/stackWatermarkSet.hpp" #include "runtime/synchronizer.hpp" #include "runtime/threadCritical.hpp" -#include "runtime/threadWXSetters.inline.hpp" #include "runtime/vframe.hpp" #include "runtime/vframeArray.hpp" #include "runtime/vframe_hp.hpp" diff --git a/src/hotspot/share/prims/jni.cpp b/src/hotspot/share/prims/jni.cpp index b6a4443a8c763..ba95b4b8fa2e5 100644 --- a/src/hotspot/share/prims/jni.cpp +++ b/src/hotspot/share/prims/jni.cpp @@ -3624,7 +3624,6 @@ static jint JNI_CreateJavaVM_inner(JavaVM **vm, void **penv, void *args) { // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving. ThreadStateTransition::transition_from_vm(thread, _thread_in_native); - MACOS_AARCH64_ONLY(thread->enable_wx(WXExec)); } else { // If create_vm exits because of a pending exception, exit with that // exception. In the future when we figure out how to reclaim memory, @@ -3726,9 +3725,6 @@ static jint JNICALL jni_DestroyJavaVM_inner(JavaVM *vm) { // Since this is not a JVM_ENTRY we have to set the thread state manually before entering. - // We are going to VM, change W^X state to the expected one. - MACOS_AARCH64_ONLY(WXMode oldmode = thread->enable_wx(WXWrite)); - ThreadStateTransition::transition_from_native(thread, _thread_in_vm); Threads::destroy_vm(); // Don't bother restoring thread state, VM is gone. @@ -3784,7 +3780,6 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae thread->record_stack_base_and_size(); thread->register_thread_stack_with_NMT(); thread->initialize_thread_current(); - MACOS_AARCH64_ONLY(thread->init_wx()); if (!os::create_attached_thread(thread)) { thread->smr_delete(); @@ -3855,7 +3850,6 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae // Now leaving the VM, so change thread_state. This is normally automatically taken care // of in the JVM_ENTRY. But in this situation we have to do it manually. ThreadStateTransition::transition_from_vm(thread, _thread_in_native); - MACOS_AARCH64_ONLY(thread->enable_wx(WXExec)); // Perform any platform dependent FPU setup os::setup_fpu(); @@ -3909,9 +3903,6 @@ jint JNICALL jni_DetachCurrentThread(JavaVM *vm) { return JNI_ERR; } - // We are going to VM, change W^X state to the expected one. - MACOS_AARCH64_ONLY(thread->enable_wx(WXWrite)); - // Safepoint support. Have to do call-back to safepoint code, if in the // middle of a safepoint operation ThreadStateTransition::transition_from_native(thread, _thread_in_vm); @@ -3928,10 +3919,6 @@ jint JNICALL jni_DetachCurrentThread(JavaVM *vm) { thread->exit(false, JavaThread::jni_detach); thread->smr_delete(); - // Go to the execute mode, the initial state of the thread on creation. - // Use os interface as the thread is not a JavaThread anymore. - MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXExec)); - HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK); return JNI_OK; } diff --git a/src/hotspot/share/prims/jniCheck.cpp b/src/hotspot/share/prims/jniCheck.cpp index 70598dc7eb7c1..4bd89453a8517 100644 --- a/src/hotspot/share/prims/jniCheck.cpp +++ b/src/hotspot/share/prims/jniCheck.cpp @@ -101,7 +101,6 @@ extern "C" { \ if (env != xenv) { \ NativeReportJNIFatalError(thr, warn_wrong_jnienv); \ } \ - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thr)); \ VM_ENTRY_BASE(result_type, header, thr) diff --git a/src/hotspot/share/prims/jvmtiEnter.xsl b/src/hotspot/share/prims/jvmtiEnter.xsl index f275da0cc8640..a5d03cc551243 100644 --- a/src/hotspot/share/prims/jvmtiEnter.xsl +++ b/src/hotspot/share/prims/jvmtiEnter.xsl @@ -437,7 +437,6 @@ struct jvmtiInterface_1_ jvmti JavaThread* current_thread = JavaThread::cast(this_thread); - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current_thread)); ThreadInVMfromNative __tiv(current_thread); diff --git a/src/hotspot/share/prims/jvmtiEnv.cpp b/src/hotspot/share/prims/jvmtiEnv.cpp index 14030c1f8d31f..73637528dd2bf 100644 --- a/src/hotspot/share/prims/jvmtiEnv.cpp +++ b/src/hotspot/share/prims/jvmtiEnv.cpp @@ -197,7 +197,6 @@ JvmtiEnv::GetThreadLocalStorage(jthread thread, void** data_ptr) { // other than the current thread is required we need to transition // from native so as to resolve the jthread. - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current_thread)); ThreadInVMfromNative __tiv(current_thread); VM_ENTRY_BASE(jvmtiError, JvmtiEnv::GetThreadLocalStorage , current_thread) debug_only(VMNativeEntryWrapper __vew;) @@ -3515,8 +3514,6 @@ JvmtiEnv::RawMonitorEnter(JvmtiRawMonitor * rmonitor) { JvmtiPendingMonitors::enter(rmonitor); } else { Thread* thread = Thread::current(); - // 8266889: raw_enter changes Java thread state, needs WXWrite - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); rmonitor->raw_enter(thread); } return JVMTI_ERROR_NONE; @@ -3549,8 +3546,6 @@ JvmtiEnv::RawMonitorExit(JvmtiRawMonitor * rmonitor) { jvmtiError JvmtiEnv::RawMonitorWait(JvmtiRawMonitor * rmonitor, jlong millis) { Thread* thread = Thread::current(); - // 8266889: raw_wait changes Java thread state, needs WXWrite - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); int r = rmonitor->raw_wait(millis, thread); switch (r) { diff --git a/src/hotspot/share/prims/jvmtiExport.cpp b/src/hotspot/share/prims/jvmtiExport.cpp index 5a87e16c855b2..a70a2bc7020df 100644 --- a/src/hotspot/share/prims/jvmtiExport.cpp +++ b/src/hotspot/share/prims/jvmtiExport.cpp @@ -381,8 +381,6 @@ 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 c17674542270f..b40ad7ddbd108 100644 --- a/src/hotspot/share/prims/jvmtiExtensions.cpp +++ b/src/hotspot/share/prims/jvmtiExtensions.cpp @@ -130,7 +130,6 @@ 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; diff --git a/src/hotspot/share/prims/unsafe.cpp b/src/hotspot/share/prims/unsafe.cpp index dcc47f0f64e95..04843581e5465 100644 --- a/src/hotspot/share/prims/unsafe.cpp +++ b/src/hotspot/share/prims/unsafe.cpp @@ -408,7 +408,6 @@ UNSAFE_ENTRY_SCOPED(void, Unsafe_CopyMemory0(JNIEnv *env, jobject unsafe, jobjec { GuardUnsafeAccess guard(thread); if (StubRoutines::unsafe_arraycopy() != nullptr) { - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXExec, thread)); StubRoutines::UnsafeArrayCopy_stub()(src, dst, sz); } else { Copy::conjoint_memory_atomic(src, dst, sz); @@ -440,14 +439,12 @@ UNSAFE_LEAF (void, Unsafe_WriteBack0(JNIEnv *env, jobject unsafe, jlong line)) { } #endif - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXExec, Thread::current())); assert(StubRoutines::data_cache_writeback() != nullptr, "sanity"); (StubRoutines::DataCacheWriteback_stub())(addr_from_java(line)); } UNSAFE_END static void doWriteBackSync0(bool is_pre) { - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXExec, Thread::current())); assert(StubRoutines::data_cache_writeback_sync() != nullptr, "sanity"); (StubRoutines::DataCacheWritebackSync_stub())(is_pre); } diff --git a/src/hotspot/share/prims/upcallLinker.cpp b/src/hotspot/share/prims/upcallLinker.cpp index 4b924b5302d1b..d60155a8ae877 100644 --- a/src/hotspot/share/prims/upcallLinker.cpp +++ b/src/hotspot/share/prims/upcallLinker.cpp @@ -88,10 +88,6 @@ JavaThread* UpcallLinker::on_entry(UpcallStub::FrameData* context, jobject recei // clear any pending exception in thread (native calls start with no exception pending) thread->clear_pending_exception(); - // The call to transition_from_native below contains a safepoint check - // which needs the code cache to be writable. - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, thread)); - // After this, we are officially in Java Code. This needs to be done before we change any of the thread local // info, since we cannot find oops before the new information is set up completely. ThreadStateTransition::transition_from_native(thread, _thread_in_Java, true /* check_asyncs */); diff --git a/src/hotspot/share/prims/whitebox.inline.hpp b/src/hotspot/share/prims/whitebox.inline.hpp index f46b36b84eee0..91c9b19d8c572 100644 --- a/src/hotspot/share/prims/whitebox.inline.hpp +++ b/src/hotspot/share/prims/whitebox.inline.hpp @@ -32,8 +32,7 @@ // Entry macro to transition from JNI to VM state. #define WB_ENTRY(result_type, header) JNI_ENTRY(result_type, header) \ - ClearPendingJniExcCheck _clearCheck(env); \ - MACOS_AARCH64_ONLY(ThreadWXEnable _wx(WXWrite, thread)); + ClearPendingJniExcCheck _clearCheck(env); #define WB_END JNI_END diff --git a/src/hotspot/share/runtime/continuationFreezeThaw.cpp b/src/hotspot/share/runtime/continuationFreezeThaw.cpp index d3375d1dfbbbb..d4a1129bbe754 100644 --- a/src/hotspot/share/runtime/continuationFreezeThaw.cpp +++ b/src/hotspot/share/runtime/continuationFreezeThaw.cpp @@ -248,8 +248,6 @@ static JRT_LEAF(intptr_t*, thaw(JavaThread* thread, int kind)) // JRT_ENTRY instead? ResetNoHandleMark rnhm; - // we might modify the code cache via BarrierSetNMethod::nmethod_entry_barrier - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); return ConfigT::thaw(thread, (Continuation::thaw_kind)kind); JRT_END diff --git a/src/hotspot/share/runtime/deoptimization.cpp b/src/hotspot/share/runtime/deoptimization.cpp index 1bdc597e4ce97..2a3341ef10357 100644 --- a/src/hotspot/share/runtime/deoptimization.cpp +++ b/src/hotspot/share/runtime/deoptimization.cpp @@ -85,7 +85,6 @@ #include "runtime/stubRoutines.hpp" #include "runtime/synchronizer.hpp" #include "runtime/threadSMR.hpp" -#include "runtime/threadWXSetters.inline.hpp" #include "runtime/vframe.hpp" #include "runtime/vframeArray.hpp" #include "runtime/vframe_hp.hpp" @@ -2599,9 +2598,6 @@ Deoptimization::update_method_data_from_interpreter(MethodData* trap_mdo, int tr } Deoptimization::UnrollBlock* Deoptimization::uncommon_trap(JavaThread* current, jint trap_request, jint exec_mode) { - // Enable WXWrite: current function is called from methods compiled by C2 directly - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current)); - // Still in Java no safepoints { // This enters VM and may safepoint diff --git a/src/hotspot/share/runtime/interfaceSupport.inline.hpp b/src/hotspot/share/runtime/interfaceSupport.inline.hpp index 403ff1d9ea292..d5ad799fab62a 100644 --- a/src/hotspot/share/runtime/interfaceSupport.inline.hpp +++ b/src/hotspot/share/runtime/interfaceSupport.inline.hpp @@ -37,7 +37,6 @@ #include "runtime/os.hpp" #include "runtime/safepointMechanism.inline.hpp" #include "runtime/safepointVerifiers.hpp" -#include "runtime/threadWXSetters.inline.hpp" #include "runtime/vmOperations.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/macros.hpp" @@ -250,14 +249,6 @@ class VMNativeEntryWrapper { // LEAF routines do not lock, GC or throw exceptions -// On macos/aarch64 we need to maintain the W^X state of the thread. So we -// take WXWrite on the enter to VM from the "outside" world, so the rest of JVM -// code can assume writing (but not executing) codecache is always possible -// without preliminary actions. -// JavaThread state should be changed only after taking WXWrite. The state -// change may trigger a safepoint, that would need WXWrite to do bookkeeping -// in the codecache. - #define VM_LEAF_BASE(result_type, header) \ debug_only(NoHandleMark __hm;) \ os::verify_stack_alignment(); \ @@ -283,7 +274,6 @@ class VMNativeEntryWrapper { #define JRT_ENTRY(result_type, header) \ result_type header { \ assert(current == JavaThread::current(), "Must be"); \ - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current)); \ ThreadInVMfromJava __tiv(current); \ VM_ENTRY_BASE(result_type, header, current) \ debug_only(VMEntryWrapper __vew;) @@ -311,7 +301,6 @@ class VMNativeEntryWrapper { #define JRT_ENTRY_NO_ASYNC(result_type, header) \ result_type header { \ assert(current == JavaThread::current(), "Must be"); \ - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current)); \ ThreadInVMfromJava __tiv(current, false /* check asyncs */); \ VM_ENTRY_BASE(result_type, header, current) \ debug_only(VMEntryWrapper __vew;) @@ -321,7 +310,6 @@ class VMNativeEntryWrapper { #define JRT_BLOCK_ENTRY(result_type, header) \ result_type header { \ assert(current == JavaThread::current(), "Must be"); \ - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current)); \ HandleMarkCleaner __hm(current); #define JRT_BLOCK \ @@ -358,7 +346,6 @@ extern "C" { \ result_type JNICALL header { \ JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ assert(thread == Thread::current(), "JNIEnv is only valid in same thread"); \ - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); \ ThreadInVMfromNative __tiv(thread); \ debug_only(VMNativeEntryWrapper __vew;) \ VM_ENTRY_BASE(result_type, header, thread) @@ -383,7 +370,6 @@ extern "C" { \ extern "C" { \ result_type JNICALL header { \ JavaThread* thread=JavaThread::thread_from_jni_environment(env); \ - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); \ ThreadInVMfromNative __tiv(thread); \ debug_only(VMNativeEntryWrapper __vew;) \ VM_ENTRY_BASE(result_type, header, thread) @@ -393,7 +379,6 @@ extern "C" { \ extern "C" { \ result_type JNICALL header { \ JavaThread* thread = JavaThread::current(); \ - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, thread)); \ ThreadInVMfromNative __tiv(thread); \ debug_only(VMNativeEntryWrapper __vew;) \ VM_ENTRY_BASE(result_type, header, thread) diff --git a/src/hotspot/share/runtime/javaCalls.cpp b/src/hotspot/share/runtime/javaCalls.cpp index 0ae0d4540e417..312639e3cd1e3 100644 --- a/src/hotspot/share/runtime/javaCalls.cpp +++ b/src/hotspot/share/runtime/javaCalls.cpp @@ -95,15 +95,12 @@ JavaCallWrapper::JavaCallWrapper(const methodHandle& callee_method, Handle recei debug_only(_thread->inc_java_call_counter()); _thread->set_active_handles(new_handles); // install new handle block and reset Java frame linkage - MACOS_AARCH64_ONLY(_thread->enable_wx(WXExec)); } JavaCallWrapper::~JavaCallWrapper() { assert(_thread == JavaThread::current(), "must still be the same thread"); - MACOS_AARCH64_ONLY(_thread->enable_wx(WXWrite)); - // restore previous handle block & Java frame linkage JNIHandleBlock *_old_handles = _thread->active_handles(); _thread->set_active_handles(_handles); diff --git a/src/hotspot/share/runtime/javaThread.cpp b/src/hotspot/share/runtime/javaThread.cpp index 8fe8e368f09b2..8f407a0a96e94 100644 --- a/src/hotspot/share/runtime/javaThread.cpp +++ b/src/hotspot/share/runtime/javaThread.cpp @@ -85,7 +85,6 @@ #include "runtime/threadCritical.hpp" #include "runtime/threadSMR.inline.hpp" #include "runtime/threadStatisticalInfo.hpp" -#include "runtime/threadWXSetters.inline.hpp" #include "runtime/timer.hpp" #include "runtime/timerTrace.hpp" #include "runtime/vframe.inline.hpp" @@ -377,14 +376,6 @@ void JavaThread::check_possible_safepoint() { clear_unhandled_oops(); #endif // CHECK_UNHANDLED_OOPS - // Macos/aarch64 should be in the right state for safepoint (e.g. - // deoptimization needs WXWrite). Crashes caused by the wrong state rarely - // happens in practice, making such issues hard to find and reproduce. -#if defined(__APPLE__) && defined(AARCH64) - if (AssertWXAtThreadSync) { - assert_wx_state(WXWrite); - } -#endif } void JavaThread::check_for_valid_safepoint_state() { @@ -1264,9 +1255,6 @@ void JavaThread::check_special_condition_for_native_trans(JavaThread *thread) { thread->set_thread_state(_thread_in_vm); - // Enable WXWrite: called directly from interpreter native wrapper. - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, thread)); - SafepointMechanism::process_if_requested_with_exit_check(thread, true /* check asyncs */); // After returning from native, it could be that the stack frames are not @@ -1461,7 +1449,6 @@ void JavaThread::verify_states_for_handshake() { void JavaThread::nmethods_do(NMethodClosure* cf) { DEBUG_ONLY(verify_frame_info();) - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, Thread::current());) if (has_last_Java_frame()) { // Traverse the execution stack diff --git a/src/hotspot/share/runtime/safepoint.cpp b/src/hotspot/share/runtime/safepoint.cpp index 935c1beee40e0..dabb51a19bc1b 100644 --- a/src/hotspot/share/runtime/safepoint.cpp +++ b/src/hotspot/share/runtime/safepoint.cpp @@ -61,7 +61,6 @@ #include "runtime/synchronizer.hpp" #include "runtime/threads.hpp" #include "runtime/threadSMR.hpp" -#include "runtime/threadWXSetters.inline.hpp" #include "runtime/timerTrace.hpp" #include "services/runtimeService.hpp" #include "utilities/events.hpp" @@ -693,9 +692,6 @@ void SafepointSynchronize::handle_polling_page_exception(JavaThread *thread) { assert(thread->thread_state() == _thread_in_Java, "should come from Java code"); thread->set_thread_state(_thread_in_vm); - // Enable WXWrite: the function is called implicitly from java code. - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, thread)); - if (log_is_enabled(Info, safepoint, stats)) { Atomic::inc(&_nof_threads_hit_polling_page); } diff --git a/src/hotspot/share/runtime/sharedRuntime.cpp b/src/hotspot/share/runtime/sharedRuntime.cpp index a4ee1a3173461..90bc8efd9aa54 100644 --- a/src/hotspot/share/runtime/sharedRuntime.cpp +++ b/src/hotspot/share/runtime/sharedRuntime.cpp @@ -480,9 +480,6 @@ address SharedRuntime::raw_exception_handler_for_return_address(JavaThread* curr return StubRoutines::cont_returnBarrierExc(); } - // write lock needed because we might update the pc desc cache via PcDescCache::add_pc_desc - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current)); - // The fastest case first CodeBlob* blob = CodeCache::find_blob(return_address); nmethod* nm = (blob != nullptr) ? blob->as_nmethod_or_null() : nullptr; @@ -1771,9 +1768,6 @@ JRT_LEAF(void, SharedRuntime::fixup_callers_callsite(Method* method, address cal return; } - // write lock needed because we might update the pc desc cache via PcDescCache::add_pc_desc - MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, JavaThread::current())); - CodeBlob* cb = CodeCache::find_blob(caller_pc); if (cb == nullptr || !cb->is_nmethod() || !callee->is_in_use() || callee->is_unloading()) { return; diff --git a/src/hotspot/share/runtime/stubRoutines.hpp b/src/hotspot/share/runtime/stubRoutines.hpp index 03756f92d1c12..a8cfef0b3154e 100644 --- a/src/hotspot/share/runtime/stubRoutines.hpp +++ b/src/hotspot/share/runtime/stubRoutines.hpp @@ -31,7 +31,6 @@ #include "runtime/frame.hpp" #include "runtime/mutexLocker.hpp" #include "runtime/stubCodeGenerator.hpp" -#include "runtime/threadWXSetters.inline.hpp" #include "utilities/macros.hpp" // StubRoutines provides entry points to assembly routines used by @@ -454,13 +453,11 @@ class StubRoutines: AllStatic { static jshort f2hf(jfloat x) { assert(_f2hf != nullptr, "stub is not implemented on this platform"); - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXExec, Thread::current());) // About to call into code cache typedef jshort (*f2hf_stub_t)(jfloat x); return ((f2hf_stub_t)_f2hf)(x); } static jfloat hf2f(jshort x) { assert(_hf2f != nullptr, "stub is not implemented on this platform"); - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXExec, Thread::current());) // About to call into code cache typedef jfloat (*hf2f_stub_t)(jshort x); return ((hf2f_stub_t)_hf2f)(x); } diff --git a/src/hotspot/share/runtime/thread.cpp b/src/hotspot/share/runtime/thread.cpp index 396f349a8856b..74782a949291d 100644 --- a/src/hotspot/share/runtime/thread.cpp +++ b/src/hotspot/share/runtime/thread.cpp @@ -137,8 +137,6 @@ Thread::Thread() { // If the main thread creates other threads before the barrier set that is an error. assert(Thread::current_or_null() == nullptr, "creating thread before barrier set"); } - - MACOS_AARCH64_ONLY(DEBUG_ONLY(_wx_init = false)); } void Thread::initialize_tlab() { @@ -201,8 +199,6 @@ void Thread::call_run() { // Perform common initialization actions - MACOS_AARCH64_ONLY(this->init_wx()); - register_thread_stack_with_NMT(); JFR_ONLY(Jfr::on_thread_start(this);) diff --git a/src/hotspot/share/runtime/thread.hpp b/src/hotspot/share/runtime/thread.hpp index a3d6e091d28fa..249acbfc01ebb 100644 --- a/src/hotspot/share/runtime/thread.hpp +++ b/src/hotspot/share/runtime/thread.hpp @@ -627,19 +627,6 @@ class Thread: public ThreadShadow { static void SpinAcquire(volatile int * Lock, const char * Name); static void SpinRelease(volatile int * Lock); -#if defined(__APPLE__) && defined(AARCH64) - private: - DEBUG_ONLY(bool _wx_init); - WXMode _wx_state; - public: - void init_wx(); - WXMode enable_wx(WXMode new_state); - - void assert_wx_state(WXMode expected) { - assert(_wx_state == expected, "wrong state"); - } -#endif // __APPLE__ && AARCH64 - private: bool _in_asgct = false; public: diff --git a/src/hotspot/share/runtime/thread.inline.hpp b/src/hotspot/share/runtime/thread.inline.hpp index 756a4702159d2..990dbab92b996 100644 --- a/src/hotspot/share/runtime/thread.inline.hpp +++ b/src/hotspot/share/runtime/thread.inline.hpp @@ -31,10 +31,6 @@ #include "gc/shared/tlab_globals.hpp" #include "runtime/atomic.hpp" -#if defined(__APPLE__) && defined(AARCH64) -#include "runtime/os.hpp" -#endif - inline jlong Thread::cooked_allocated_bytes() { jlong allocated_bytes = Atomic::load_acquire(&_allocated_bytes); if (UseTLAB) { @@ -70,25 +66,4 @@ inline void Thread::set_threads_hazard_ptr(ThreadsList* new_list) { Atomic::release_store_fence(&_threads_hazard_ptr, new_list); } -#if defined(__APPLE__) && defined(AARCH64) -inline void Thread::init_wx() { - assert(this == Thread::current(), "should only be called for current thread"); - assert(!_wx_init, "second init"); - _wx_state = WXWrite; - os::current_thread_enable_wx(_wx_state); - DEBUG_ONLY(_wx_init = true); -} - -inline WXMode Thread::enable_wx(WXMode new_state) { - assert(this == Thread::current(), "should only be called for current thread"); - assert(_wx_init, "should be inited"); - WXMode old = _wx_state; - if (_wx_state != new_state) { - _wx_state = new_state; - os::current_thread_enable_wx(new_state); - } - return old; -} -#endif // __APPLE__ && AARCH64 - #endif // SHARE_RUNTIME_THREAD_INLINE_HPP diff --git a/src/hotspot/share/runtime/threads.cpp b/src/hotspot/share/runtime/threads.cpp index e3bb67bfee52f..d3c44c2f5e716 100644 --- a/src/hotspot/share/runtime/threads.cpp +++ b/src/hotspot/share/runtime/threads.cpp @@ -431,8 +431,6 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { // Initialize the os module os::init(); - MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXWrite)); - // Record VM creation timing statistics TraceVmCreationTime create_vm_timer; create_vm_timer.start(); @@ -531,7 +529,6 @@ jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { main_thread->record_stack_base_and_size(); main_thread->register_thread_stack_with_NMT(); main_thread->set_active_handles(JNIHandleBlock::allocate_block()); - MACOS_AARCH64_ONLY(main_thread->init_wx()); if (!main_thread->set_as_starting_thread()) { vm_shutdown_during_initialization( diff --git a/test/hotspot/gtest/gtestMain.cpp b/test/hotspot/gtest/gtestMain.cpp index bc8ca29f72d45..482c43d417f24 100644 --- a/test/hotspot/gtest/gtestMain.cpp +++ b/test/hotspot/gtest/gtestMain.cpp @@ -93,12 +93,6 @@ static int init_jvm(int argc, char **argv, bool disable_error_handling, JavaVM** int ret = JNI_CreateJavaVM(jvm_ptr, (void**)&env, &args); delete[] options; - if (ret == JNI_OK) { - // CreateJavaVM leaves WXExec context, while gtests - // calls internal functions assuming running in WXWwrite. - // Switch to WXWrite once for all test cases. - MACOS_AARCH64_ONLY(Thread::current()->enable_wx(WXWrite)); - } return ret; } diff --git a/test/hotspot/gtest/runtime/test_stubRoutines.cpp b/test/hotspot/gtest/runtime/test_stubRoutines.cpp index 14673046b9b54..6f5425121768e 100644 --- a/test/hotspot/gtest/runtime/test_stubRoutines.cpp +++ b/test/hotspot/gtest/runtime/test_stubRoutines.cpp @@ -62,7 +62,6 @@ static void test_arraycopy_func(address func, int alignment) { } TEST_VM(StubRoutines, array_copy_routine) { - MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXExec)); #define TEST_ARRAYCOPY(type) \ test_arraycopy_func( StubRoutines::type##_arraycopy(), sizeof(type)); \ @@ -78,11 +77,9 @@ TEST_VM(StubRoutines, array_copy_routine) { #undef TEST_ARRAYCOPY - MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXWrite)); } TEST_VM(StubRoutines, copy_routine) { - MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXExec)); #define TEST_COPYRTN(type) \ test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::conjoint_##type##s_atomic), sizeof(type)); \ @@ -103,11 +100,9 @@ TEST_VM(StubRoutines, copy_routine) { test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_conjoint_words), sizeof(jlong)); test_arraycopy_func(CAST_FROM_FN_PTR(address, Copy::aligned_disjoint_words), sizeof(jlong)); - MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXWrite)); } TEST_VM(StubRoutines, array_fill_routine) { - MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXExec)); #define TEST_FILL(type) \ if (StubRoutines::_##type##_fill != nullptr) { \ @@ -149,5 +144,4 @@ TEST_VM(StubRoutines, array_fill_routine) { #undef TEST_FILL - MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXWrite)); } diff --git a/test/hotspot/gtest/runtime/test_threads.cpp b/test/hotspot/gtest/runtime/test_threads.cpp index 7589033464644..69ad2489cacf2 100644 --- a/test/hotspot/gtest/runtime/test_threads.cpp +++ b/test/hotspot/gtest/runtime/test_threads.cpp @@ -180,7 +180,6 @@ TEST_VM(ThreadsTest, claim_overflow) { TEST_VM(ThreadsTest, fast_jni_in_vm) { JavaThread* current = JavaThread::current(); JNIEnv* env = current->jni_environment(); - MACOS_AARCH64_ONLY(ThreadWXEnable wx(WXWrite, current)); // DirectByteBuffer is an easy way to trigger GetIntField, // see JDK-8262896 From 9e3da01d734638608a8552e5b2763c177ae65169 Mon Sep 17 00:00:00 2001 From: Sergey Nazarkin Date: Thu, 11 Apr 2024 17:45:27 +0300 Subject: [PATCH 3/4] Revert "8304725: AsyncGetCallTrace can cause SIGBUS on M1" This reverts commit d8af7a6014055295355a1242db6c2872299c6398. --- src/hotspot/share/code/nmethod.cpp | 6 +----- src/hotspot/share/prims/forte.cpp | 3 --- src/hotspot/share/runtime/thread.hpp | 27 --------------------------- 3 files changed, 1 insertion(+), 35 deletions(-) diff --git a/src/hotspot/share/code/nmethod.cpp b/src/hotspot/share/code/nmethod.cpp index 3ef65d5946c96..1df0e5235d5f9 100644 --- a/src/hotspot/share/code/nmethod.cpp +++ b/src/hotspot/share/code/nmethod.cpp @@ -2718,11 +2718,7 @@ PcDesc* PcDescContainer::find_pc_desc_internal(address pc, bool approximate, con if (match_desc(upper, pc_offset, approximate)) { assert(upper == linear_search(search, pc_offset, approximate), "search ok"); - if (!Thread::current_in_asgct()) { - // we don't want to modify the cache if we're in ASGCT - // which is typically called in a signal handler - _pc_desc_cache.add_pc_desc(upper); - } + _pc_desc_cache.add_pc_desc(upper); return upper; } else { assert(nullptr == linear_search(search, pc_offset, approximate), "search ok"); diff --git a/src/hotspot/share/prims/forte.cpp b/src/hotspot/share/prims/forte.cpp index b5973d4ad0277..b996c046c6d26 100644 --- a/src/hotspot/share/prims/forte.cpp +++ b/src/hotspot/share/prims/forte.cpp @@ -607,9 +607,6 @@ void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) { return; } - // signify to other code in the VM that we're in ASGCT - ThreadInAsgct tia(thread); - switch (thread->thread_state()) { case _thread_new: case _thread_uninitialized: diff --git a/src/hotspot/share/runtime/thread.hpp b/src/hotspot/share/runtime/thread.hpp index 249acbfc01ebb..d89e41f877f14 100644 --- a/src/hotspot/share/runtime/thread.hpp +++ b/src/hotspot/share/runtime/thread.hpp @@ -627,37 +627,10 @@ class Thread: public ThreadShadow { static void SpinAcquire(volatile int * Lock, const char * Name); static void SpinRelease(volatile int * Lock); - private: - bool _in_asgct = false; - public: - bool in_asgct() const { return _in_asgct; } - void set_in_asgct(bool value) { _in_asgct = value; } - static bool current_in_asgct() { - Thread *cur = Thread::current_or_null_safe(); - return cur != nullptr && cur->in_asgct(); - } - private: VMErrorCallback* _vm_error_callbacks; }; -class ThreadInAsgct { - private: - Thread* _thread; - bool _saved_in_asgct; - public: - ThreadInAsgct(Thread* thread) : _thread(thread) { - assert(thread != nullptr, "invariant"); - // Allow AsyncGetCallTrace to be reentrant - save the previous state. - _saved_in_asgct = thread->in_asgct(); - thread->set_in_asgct(true); - } - ~ThreadInAsgct() { - assert(_thread->in_asgct(), "invariant"); - _thread->set_in_asgct(_saved_in_asgct); - } -}; - // Inline implementation of Thread::current() inline Thread* Thread::current() { Thread* current = current_or_null(); From e46f51d093d1f4cd7afbe52811403fcd3612d54f Mon Sep 17 00:00:00 2001 From: Sergey Nazarkin Date: Fri, 12 Apr 2024 16:53:22 +0300 Subject: [PATCH 4/4] Fix non-macos builds --- src/hotspot/share/memory/virtualspace.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/memory/virtualspace.cpp b/src/hotspot/share/memory/virtualspace.cpp index 007115e3ac46d..a419d28111a3f 100644 --- a/src/hotspot/share/memory/virtualspace.cpp +++ b/src/hotspot/share/memory/virtualspace.cpp @@ -840,7 +840,7 @@ static bool commit_expanded(char* start, size_t size, size_t alignment, bool pre if (os::commit_memory(start, size, alignment, executable)) { if (pre_touch || AlwaysPreTouch) { if (executable){ - os::current_thread_enable_wx(WXWrite); + MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXWrite)); } pretouch_expanded_memory(start, start + size); }