Skip to content

Commit

Permalink
8341708: Optimize safepoint poll encoding with smaller poll data offset
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, qamai
  • Loading branch information
shipilev committed Oct 14, 2024
1 parent 8d0975a commit 037f11b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/share/jvmci/vmStructs_jvmci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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)) \
Expand Down
20 changes: 16 additions & 4 deletions src/hotspot/share/runtime/javaThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -598,6 +596,22 @@ class JavaThread: public Thread {

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
Expand Down Expand Up @@ -787,8 +801,6 @@ class JavaThread: public Thread {
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
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/runtime/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion test/hotspot/jtreg/compiler/c2/irTests/TestPadding.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void test_runner() {
}

@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
Expand Down

0 comments on commit 037f11b

Please sign in to comment.