Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 0 additions & 38 deletions src/hotspot/cpu/aarch64/jniFastGetField_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
#include "prims/jvmtiExport.hpp"
#include "runtime/javaThread.inline.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/threadWXSetters.inline.hpp"

#define __ masm->

Expand All @@ -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<int BType> struct BasicTypeToJni {};
template<> struct BasicTypeToJni<T_BOOLEAN> { static const jboolean jni_type; };
template<> struct BasicTypeToJni<T_BYTE> { static const jbyte jni_type; };
template<> struct BasicTypeToJni<T_CHAR> { static const jchar jni_type; };
template<> struct BasicTypeToJni<T_SHORT> { static const jshort jni_type; };
template<> struct BasicTypeToJni<T_INT> { static const jint jni_type; };
template<> struct BasicTypeToJni<T_LONG> { static const jlong jni_type; };
template<> struct BasicTypeToJni<T_FLOAT> { static const jfloat jni_type; };
template<> struct BasicTypeToJni<T_DOUBLE> { static const jdouble jni_type; };

template<int BType, typename JniType = decltype(BasicTypeToJni<BType>::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<int BType>
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<BType>;
}

#else // __APPLE__

template<int BType>
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) {
Expand Down
6 changes: 1 addition & 5 deletions src/hotspot/os/bsd/globals_bsd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/hotspot/os/posix/signals_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) ?
Expand Down
18 changes: 14 additions & 4 deletions src/hotspot/os_cpu/bsd_aarch64/os_bsd_aarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,25 @@ 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;

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);
Expand Down
4 changes: 0 additions & 4 deletions src/hotspot/share/c1/c1_Runtime1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
8 changes: 1 addition & 7 deletions src/hotspot/share/code/nmethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -2720,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");
Expand Down
6 changes: 0 additions & 6 deletions src/hotspot/share/gc/shared/barrierSetNMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/gc/x/xBarrierSetNMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<XReentrantLock> locker(XNMethod::lock_for_nmethod(nm));
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/gc/z/zBarrierSetNMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ZReentrantLock> locker(ZNMethod::lock_for_nmethod(nm));
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/interpreter/interpreterRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 0 additions & 2 deletions src/hotspot/share/jfr/instrumentation/jfrJvmtiAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/jfr/jni/jfrJniMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 0 additions & 1 deletion src/hotspot/share/jfr/recorder/storage/jfrStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/jfr/support/jfrIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/jfr/writers/jfrJavaEventWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/jvmci/jvmciCompilerToVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; \
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/memory/virtualspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
MACOS_AARCH64_ONLY(os::current_thread_enable_wx(WXWrite));
}
pretouch_expanded_memory(start, start + size);
}
return true;
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/opto/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 0 additions & 3 deletions src/hotspot/share/prims/forte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 0 additions & 13 deletions src/hotspot/share/prims/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/prims/jniCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/prims/jvmtiEnter.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ struct jvmtiInterface_1_ jvmti</xsl:text>
<xsl:if test="count(@impl)=0 or not(contains(@impl,'innative'))">
<xsl:text>JavaThread* current_thread = JavaThread::cast(this_thread);</xsl:text>
<xsl:value-of select="$space"/>
<xsl:text>MACOS_AARCH64_ONLY(ThreadWXEnable __wx(WXWrite, current_thread));</xsl:text>
<xsl:value-of select="$space"/>
<xsl:text>ThreadInVMfromNative __tiv(current_thread);</xsl:text>
<xsl:value-of select="$space"/>
Expand Down
Loading