8341708: Optimize safepoint poll encoding with smaller poll data offset

Reviewed-by: kvn, qamai
This commit is contained in:
Aleksey Shipilev 2024-10-14 06:02:00 +00:00
parent 8d0975a27d
commit 037f11b864
4 changed files with 25 additions and 6 deletions

View File

@ -241,7 +241,6 @@
nonstatic_field(JavaThread, _jvmci_reserved_oop0, oop) \
nonstatic_field(JavaThread, _should_post_on_exceptions_flag, int) \
nonstatic_field(JavaThread, _jni_environment, JNIEnv) \
nonstatic_field(JavaThread, _poll_data, SafepointMechanism::ThreadData) \
nonstatic_field(JavaThread, _stack_overflow_state._reserved_stack_activation, address) \
nonstatic_field(JavaThread, _held_monitor_count, intx) \
nonstatic_field(JavaThread, _lock_stack, LockStack) \
@ -409,6 +408,7 @@
static_field(StubRoutines, _cont_thaw, address) \
static_field(StubRoutines, _lookup_secondary_supers_table_slow_path_stub, address) \
\
nonstatic_field(Thread, _poll_data, SafepointMechanism::ThreadData) \
nonstatic_field(Thread, _tlab, ThreadLocalAllocBuffer) \
nonstatic_field(Thread, _allocated_bytes, jlong) \
JFR_ONLY(nonstatic_field(Thread, _jfr_thread_local, JfrThreadLocal)) \

View File

@ -238,8 +238,6 @@ class JavaThread: public Thread {
// Safepoint support
public: // Expose _thread_state for SafeFetchInt()
volatile JavaThreadState _thread_state;
private:
SafepointMechanism::ThreadData _poll_data;
ThreadSafepointState* _safepoint_state; // Holds information about a thread during a safepoint
address _saved_exception_pc; // Saved pc of instruction where last implicit exception happened
NOT_PRODUCT(bool _requires_cross_modify_fence;) // State used by VerifyCrossModifyFence
@ -598,6 +596,22 @@ private:
SafepointMechanism::ThreadData* poll_data() { return &_poll_data; }
static ByteSize polling_word_offset() {
ByteSize offset = byte_offset_of(Thread, _poll_data) +
byte_offset_of(SafepointMechanism::ThreadData, _polling_word);
// At least on x86_64, safepoint polls encode the offset as disp8 imm.
assert(in_bytes(offset) < 128, "Offset >= 128");
return offset;
}
static ByteSize polling_page_offset() {
ByteSize offset = byte_offset_of(Thread, _poll_data) +
byte_offset_of(SafepointMechanism::ThreadData, _polling_page);
// At least on x86_64, safepoint polls encode the offset as disp8 imm.
assert(in_bytes(offset) < 128, "Offset >= 128");
return offset;
}
void set_requires_cross_modify_fence(bool val) PRODUCT_RETURN NOT_PRODUCT({ _requires_cross_modify_fence = val; })
// Continuation support
@ -787,8 +801,6 @@ private:
static ByteSize vm_result_offset() { return byte_offset_of(JavaThread, _vm_result); }
static ByteSize vm_result_2_offset() { return byte_offset_of(JavaThread, _vm_result_2); }
static ByteSize thread_state_offset() { return byte_offset_of(JavaThread, _thread_state); }
static ByteSize polling_word_offset() { return byte_offset_of(JavaThread, _poll_data) + byte_offset_of(SafepointMechanism::ThreadData, _polling_word);}
static ByteSize polling_page_offset() { return byte_offset_of(JavaThread, _poll_data) + byte_offset_of(SafepointMechanism::ThreadData, _polling_page);}
static ByteSize saved_exception_pc_offset() { return byte_offset_of(JavaThread, _saved_exception_pc); }
static ByteSize osthread_offset() { return byte_offset_of(JavaThread, _osthread); }
#if INCLUDE_JVMCI

View File

@ -33,6 +33,7 @@
#include "runtime/atomic.hpp"
#include "runtime/globals.hpp"
#include "runtime/os.hpp"
#include "runtime/safepointMechanism.hpp"
#include "runtime/threadHeapSampler.hpp"
#include "runtime/threadLocalStorage.hpp"
#include "runtime/threadStatisticalInfo.hpp"
@ -109,6 +110,7 @@ class Thread: public ThreadShadow {
friend class VMErrorCallbackMark;
friend class VMStructs;
friend class JVMCIVMStructs;
friend class JavaThread;
private:
#ifndef USE_LIBRARY_BASED_TLS_ONLY
@ -135,6 +137,11 @@ class Thread: public ThreadShadow {
}
private:
// Poll data is used in generated code for safepoint polls.
// It is important for performance to put this at lower offset
// in Thread. The accessors are in JavaThread.
SafepointMechanism::ThreadData _poll_data;
// Thread local data area available to the GC. The internal
// structure and contents of this data area is GC-specific.
// Only GC and GC barrier code should access this data area.

View File

@ -48,7 +48,7 @@ public class TestPadding {
}
@Test
@IR(counts = { IRNode.NOP, "1" })
@IR(counts = { IRNode.NOP, "<=1" })
static int test(int i) {
TestPadding tp = tpf;
if (tp.b1 > 42) { // Big 'cmpb' instruction at offset 0x30