Skip to content

Commit 21dd004

Browse files
committed
Move code to os::current_thread_wx
1 parent 2af4f01 commit 21dd004

28 files changed

+86
-79
lines changed

src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ template<> struct BasicTypeToJni<T_DOUBLE> { static const jdouble jni_type; };
7575
template<int BType, typename JniType = decltype(BasicTypeToJni<BType>::jni_type)>
7676
JniType static_fast_get_field_wrapper(JNIEnv *env, jobject obj, jfieldID fieldID) {
7777
JavaThread* thread = JavaThread::thread_from_jni_environment(env);
78-
os::ThreadWXEnable wx(os::WXExec);
78+
os::current_thread_wx::Enable wx(os::current_thread_wx::Exec);
7979
address get_field_addr = generated_fast_get_field[BType - T_BOOLEAN];
8080
return ((JniType(*)(JNIEnv *env, jobject obj, jfieldID fieldID))get_field_addr)(env, obj, fieldID);
8181
}

src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,
205205
ucontext_t* uc, JavaThread* thread) {
206206
// Enable WXWrite: this function is called by the signal handler at arbitrary
207207
// point of execution.
208-
os::ThreadWXEnable wx(os::WXWrite);
208+
os::current_thread_wx::Enable wx(os::current_thread_wx::Write);
209209

210210
// decide if this trap can be handled by a stub
211211
address stub = NULL;
@@ -536,25 +536,25 @@ void os::verify_stack_alignment() {
536536

537537
#ifdef __APPLE__
538538

539-
static THREAD_LOCAL os::WXMode _wx_state = os::WXWrite;
539+
static THREAD_LOCAL os::current_thread_wx::WXMode _wx_state = os::current_thread_wx::Write;
540540

541541
int os::extra_bang_size_in_bytes() {
542542
// AArch64 does not require the additional stack bang.
543543
return 0;
544544
}
545545

546-
os::WXMode os::current_thread_change_wx(WXMode new_state) {
546+
os::current_thread_wx::WXMode os::current_thread_wx::change(WXMode new_state) {
547547
WXMode old = _wx_state;
548548
_wx_state = new_state;
549-
pthread_jit_write_protect_np(_wx_state == os::WXExec);
549+
pthread_jit_write_protect_np(_wx_state == os::current_thread_wx::Exec);
550550
return old;
551551
}
552552

553-
void os::current_thread_init_wx() {
554-
current_thread_change_wx(os::WXWrite);
553+
void os::current_thread_wx::init() {
554+
change(os::current_thread_wx::Write);
555555
}
556556

557-
void os::current_thread_assert_wx_state(WXMode expected) {
557+
void os::current_thread_wx::assert_wx(WXMode expected) {
558558
assert(_wx_state == expected, "wrong state");
559559
}
560560
#endif

src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.hpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,36 @@
4141
}
4242

4343
#ifdef __APPLE__
44-
enum WXMode {
45-
WXWrite,
46-
WXExec
47-
};
4844

49-
// Enables write or execute access to writeable and executable pages.
50-
// returns the previous state
51-
static WXMode current_thread_change_wx(WXMode new_state);
45+
class current_thread_wx {
46+
public:
5247

53-
// initializes the WXMode to WXWrite, as writeable pages are the default here
54-
static void current_thread_init_wx();
48+
enum WXMode {
49+
Write,
50+
Exec
51+
};
5552

56-
static void current_thread_assert_wx_state(WXMode expected);
53+
// Enables write or execute access to writeable and executable pages.
54+
// returns the previous state
55+
static WXMode change(WXMode new_state);
5756

58-
class ThreadWXEnable {
59-
WXMode _old_mode;
60-
public:
61-
ThreadWXEnable(WXMode new_mode) :
62-
_old_mode(os::current_thread_change_wx(new_mode))
63-
{ }
64-
~ThreadWXEnable() {
65-
os::current_thread_change_wx(_old_mode);
66-
}
57+
// initializes the WXMode to WXWrite, as writeable pages are the default here
58+
static void init();
59+
60+
static void assert_wx(WXMode expected);
61+
62+
// RAII object to set a specific WXMode and reset it to the previous mode
63+
// on destruction
64+
class Enable {
65+
WXMode _old_mode;
66+
public:
67+
Enable(WXMode new_mode) :
68+
_old_mode(change(new_mode))
69+
{ }
70+
~Enable() {
71+
change(_old_mode);
72+
}
73+
};
6774
};
6875
#endif // __APPLE__
6976
#endif // OS_CPU_BSD_AARCH64_OS_BSD_AARCH64_HPP

src/hotspot/share/c1/c1_Runtime1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1267,7 +1267,7 @@ void Runtime1::patch_code(JavaThread* current, Runtime1::StubID stub_id) {
12671267

12681268
// Enable WXWrite: the function is called by c1 stub as a runtime function
12691269
// (see another implementation above).
1270-
MACOS_AARCH64_ONLY(os::ThreadWXEnable wx(os::WXWrite));
1270+
MACOS_AARCH64_ONLY(os::current_thread_wx::Enable wx(os::current_thread_wx::Write));
12711271

12721272
if (TracePatching) {
12731273
tty->print_cr("Deoptimizing because patch is needed");

src/hotspot/share/code/nmethod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2880,7 +2880,7 @@ void nmethod::decode2(outputStream* ost) const {
28802880
#endif
28812881

28822882
// Decoding an nmethod can write to a PcDescCache (see PcDescCache::add_pc_desc)
2883-
MACOS_AARCH64_ONLY(os::ThreadWXEnable wx(os::WXWrite);)
2883+
MACOS_AARCH64_ONLY(os::current_thread_wx::Enable wx(os::current_thread_wx::Write);)
28842884

28852885
st->cr();
28862886
this->print(st);

src/hotspot/share/gc/shared/barrierSetNMethod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ bool BarrierSetNMethod::supports_entry_barrier(nmethod* nm) {
5252
int BarrierSetNMethod::nmethod_stub_entry_barrier(address* return_address_ptr) {
5353
// Enable WXWrite: the function is called directly from nmethod_entry_barrier
5454
// stub.
55-
MACOS_AARCH64_ONLY(os::ThreadWXEnable wx(os::WXWrite));
55+
MACOS_AARCH64_ONLY(os::current_thread_wx::Enable wx(os::current_thread_wx::Write));
5656

5757
address return_address = *return_address_ptr;
5858
AARCH64_PORT_ONLY(return_address = pauth_strip_pointer(return_address));

src/hotspot/share/gc/shenandoah/shenandoahBarrierSetNMethod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ bool ShenandoahBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) {
4646
return true;
4747
}
4848

49-
MACOS_AARCH64_ONLY(os::ThreadWXEnable wx(os::WXWrite);)
49+
MACOS_AARCH64_ONLY(os::current_thread_wx::Enable wx(os::current_thread_wx::Write);)
5050

5151
if (nm->is_unloading()) {
5252
// We don't need to take the lock when unlinking nmethods from

src/hotspot/share/gc/z/zBarrierSetNMethod.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ bool ZBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) {
4141
return true;
4242
}
4343

44-
MACOS_AARCH64_ONLY(os::ThreadWXEnable wx(os::WXWrite));
44+
MACOS_AARCH64_ONLY(os::current_thread_wx::Enable wx(os::current_thread_wx::Write));
4545

4646
if (nm->is_unloading()) {
4747
// We don't need to take the lock when unlinking nmethods from

src/hotspot/share/interpreter/interpreterRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ JRT_END
983983

984984
nmethod* InterpreterRuntime::frequency_counter_overflow(JavaThread* current, address branch_bcp) {
985985
// Enable WXWrite: the function is called directly by interpreter.
986-
MACOS_AARCH64_ONLY(os::ThreadWXEnable wx(os::WXWrite));
986+
MACOS_AARCH64_ONLY(os::current_thread_wx::Enable wx(os::current_thread_wx::Write));
987987

988988
// frequency_counter_overflow_inner can throw async exception.
989989
nmethod* nm = frequency_counter_overflow_inner(current, branch_bcp);

src/hotspot/share/jvmci/jvmciCompilerToVM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Handle JavaArgumentUnboxer::next_arg(BasicType expectedType) {
108108

109109
// Bring the JVMCI compiler thread into the VM state.
110110
#define JVMCI_VM_ENTRY_MARK \
111-
MACOS_AARCH64_ONLY(os::ThreadWXEnable __wx(os::WXWrite)); \
111+
MACOS_AARCH64_ONLY(os::current_thread_wx::Enable __wx(os::current_thread_wx::Write)); \
112112
ThreadInVMfromNative __tiv(thread); \
113113
HandleMarkCleaner __hm(thread); \
114114
JavaThread* THREAD = thread; \

0 commit comments

Comments
 (0)