Skip to content
Permalink
Browse files
8265932: Move safepoint related fields from class Thread to JavaThread
Reviewed-by: coleenp, dholmes
  • Loading branch information
pchilano committed Apr 27, 2021
1 parent b67b2b1 commit 5634f206e5698fc4ae30023714a78273d7df3ee0
Showing with 139 additions and 149 deletions.
  1. +2 −2 src/hotspot/cpu/aarch64/interp_masm_aarch64.cpp
  2. +3 −3 src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp
  3. +2 −2 src/hotspot/cpu/arm/interp_masm_arm.cpp
  4. +2 −2 src/hotspot/cpu/arm/macroAssembler_arm.cpp
  5. +1 −1 src/hotspot/cpu/ppc/c1_LIRAssembler_ppc.cpp
  6. +1 −1 src/hotspot/cpu/ppc/interp_masm_ppc_64.cpp
  7. +1 −1 src/hotspot/cpu/ppc/macroAssembler_ppc.cpp
  8. +1 −1 src/hotspot/cpu/ppc/templateTable_ppc_64.cpp
  9. +2 −2 src/hotspot/cpu/s390/c1_LIRAssembler_s390.cpp
  10. +2 −2 src/hotspot/cpu/s390/interp_masm_s390.cpp
  11. +2 −2 src/hotspot/cpu/s390/macroAssembler_s390.cpp
  12. +1 −1 src/hotspot/cpu/s390/s390.ad
  13. +1 −1 src/hotspot/cpu/s390/templateTable_s390.cpp
  14. +2 −2 src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp
  15. +3 −3 src/hotspot/cpu/x86/interp_masm_x86.cpp
  16. +2 −2 src/hotspot/cpu/x86/macroAssembler_x86.cpp
  17. +2 −2 src/hotspot/cpu/x86/templateTable_x86.cpp
  18. +1 −1 src/hotspot/share/gc/shared/memAllocator.cpp
  19. +1 −1 src/hotspot/share/interpreter/interpreterRuntime.cpp
  20. +1 −1 src/hotspot/share/jvmci/vmStructs_jvmci.cpp
  21. +1 −1 src/hotspot/share/oops/objArrayKlass.cpp
  22. +1 −1 src/hotspot/share/oops/typeArrayKlass.cpp
  23. +1 −1 src/hotspot/share/opto/parse1.cpp
  24. +1 −1 src/hotspot/share/prims/jvmtiTagMap.cpp
  25. +9 −20 src/hotspot/share/runtime/mutex.cpp
  26. +0 −1 src/hotspot/share/runtime/mutex.hpp
  27. +13 −5 src/hotspot/share/runtime/safepointVerifiers.cpp
  28. +34 −37 src/hotspot/share/runtime/thread.cpp
  29. +43 −48 src/hotspot/share/runtime/thread.hpp
  30. +3 −1 src/hotspot/share/runtime/vmThread.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -474,7 +474,7 @@ void InterpreterMacroAssembler::dispatch_base(TosState state,

if (needs_thread_local_poll) {
NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
ldr(rscratch2, Address(rthread, Thread::polling_word_offset()));
ldr(rscratch2, Address(rthread, JavaThread::polling_word_offset()));
tbnz(rscratch2, exact_log2(SafepointMechanism::poll_bit()), safepoint);
}

@@ -294,10 +294,10 @@ address MacroAssembler::target_addr_for_insn(address insn_addr, unsigned insn) {

void MacroAssembler::safepoint_poll(Label& slow_path, bool at_return, bool acquire, bool in_nmethod) {
if (acquire) {
lea(rscratch1, Address(rthread, Thread::polling_word_offset()));
lea(rscratch1, Address(rthread, JavaThread::polling_word_offset()));
ldar(rscratch1, rscratch1);
} else {
ldr(rscratch1, Address(rthread, Thread::polling_word_offset()));
ldr(rscratch1, Address(rthread, JavaThread::polling_word_offset()));
}
if (at_return) {
// Note that when in_nmethod is set, the stack pointer is incremented before the poll. Therefore,
@@ -4393,7 +4393,7 @@ void MacroAssembler::bang_stack_size(Register size, Register tmp) {

// Move the address of the polling page into dest.
void MacroAssembler::get_polling_page(Register dest, relocInfo::relocType rtype) {
ldr(dest, Address(rthread, Thread::polling_page_offset()));
ldr(dest, Address(rthread, JavaThread::polling_page_offset()));
}

// Read the polling page. The address of the polling page must
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. 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
@@ -580,7 +580,7 @@ void InterpreterMacroAssembler::dispatch_base(TosState state,

if (needs_thread_local_poll) {
NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
ldr(Rtemp, Address(Rthread, Thread::polling_word_offset()));
ldr(Rtemp, Address(Rthread, JavaThread::polling_word_offset()));
tbnz(Rtemp, exact_log2(SafepointMechanism::poll_bit()), safepoint);
}

@@ -1898,13 +1898,13 @@ void MacroAssembler::resolve(DecoratorSet decorators, Register obj) {
}

void MacroAssembler::safepoint_poll(Register tmp1, Label& slow_path) {
ldr_u32(tmp1, Address(Rthread, Thread::polling_word_offset()));
ldr_u32(tmp1, Address(Rthread, JavaThread::polling_word_offset()));
tst(tmp1, exact_log2(SafepointMechanism::poll_bit()));
b(slow_path, eq);
}

void MacroAssembler::get_polling_page(Register dest) {
ldr(dest, Address(Rthread, Thread::polling_page_offset()));
ldr(dest, Address(Rthread, JavaThread::polling_page_offset()));
}

void MacroAssembler::read_polling_page(Register dest, relocInfo::relocType rtype) {
@@ -1355,7 +1355,7 @@ void LIR_Assembler::return_op(LIR_Opr result, C1SafepointPollStub* code_stub) {

int LIR_Assembler::safepoint_poll(LIR_Opr tmp, CodeEmitInfo* info) {
const Register poll_addr = tmp->as_register();
__ ld(poll_addr, in_bytes(Thread::polling_page_offset()), R16_thread);
__ ld(poll_addr, in_bytes(JavaThread::polling_page_offset()), R16_thread);
if (info != NULL) {
add_debug_info_for_branch(info);
}
@@ -225,7 +225,7 @@ void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, Register byt
address *sfpt_tbl = Interpreter::safept_table(state);
if (table != sfpt_tbl) {
Label dispatch;
ld(R0, in_bytes(Thread::polling_word_offset()), R16_thread);
ld(R0, in_bytes(JavaThread::polling_word_offset()), R16_thread);
// Armed page has poll_bit set, if poll bit is cleared just continue.
andi_(R0, R0, SafepointMechanism::poll_bit());
beq(CCR0, dispatch);
@@ -3058,7 +3058,7 @@ void MacroAssembler::compiler_fast_unlock_object(ConditionRegister flag, Registe
}

void MacroAssembler::safepoint_poll(Label& slow_path, Register temp, bool at_return, bool in_nmethod) {
ld(temp, in_bytes(Thread::polling_word_offset()), R16_thread);
ld(temp, in_bytes(JavaThread::polling_word_offset()), R16_thread);

if (at_return) {
if (in_nmethod) {
@@ -2142,7 +2142,7 @@ void TemplateTable::_return(TosState state) {

if (_desc->bytecode() != Bytecodes::_return_register_finalizer) {
Label no_safepoint;
__ ld(R11_scratch1, in_bytes(Thread::polling_word_offset()), R16_thread);
__ ld(R11_scratch1, in_bytes(JavaThread::polling_word_offset()), R16_thread);
__ andi_(R11_scratch1, R11_scratch1, SafepointMechanism::poll_bit());
__ beq(CCR0, no_safepoint);
__ push(state);
@@ -1209,7 +1209,7 @@ void LIR_Assembler::return_op(LIR_Opr result, C1SafepointPollStub* code_stub) {
(result->is_single_fpu() && result->as_float_reg() == Z_F0) ||
(result->is_double_fpu() && result->as_double_reg() == Z_F0), "convention");

__ z_lg(Z_R1_scratch, Address(Z_thread, Thread::polling_page_offset()));
__ z_lg(Z_R1_scratch, Address(Z_thread, JavaThread::polling_page_offset()));

// Pop the frame before the safepoint code.
__ pop_frame_restore_retPC(initial_frame_size_in_bytes());
@@ -1228,7 +1228,7 @@ void LIR_Assembler::return_op(LIR_Opr result, C1SafepointPollStub* code_stub) {

int LIR_Assembler::safepoint_poll(LIR_Opr tmp, CodeEmitInfo* info) {
const Register poll_addr = tmp->as_register_lo();
__ z_lg(poll_addr, Address(Z_thread, Thread::polling_page_offset()));
__ z_lg(poll_addr, Address(Z_thread, JavaThread::polling_page_offset()));
guarantee(info != NULL, "Shouldn't be NULL");
add_debug_info_for_branch(info);
int offset = __ offset();
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -121,7 +121,7 @@ void InterpreterMacroAssembler::dispatch_base(TosState state, address* table, bo
address *sfpt_tbl = Interpreter::safept_table(state);
if (table != sfpt_tbl) {
Label dispatch;
const Address poll_byte_addr(Z_thread, in_bytes(Thread::polling_word_offset()) + 7 /* Big Endian */);
const Address poll_byte_addr(Z_thread, in_bytes(JavaThread::polling_word_offset()) + 7 /* Big Endian */);
// Armed page has poll_bit set, if poll bit is cleared just continue.
z_tm(poll_byte_addr, SafepointMechanism::poll_bit());
z_braz(dispatch);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2019 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
@@ -2652,7 +2652,7 @@ uint MacroAssembler::get_poll_register(address instr_loc) {
}

void MacroAssembler::safepoint_poll(Label& slow_path, Register temp_reg) {
const Address poll_byte_addr(Z_thread, in_bytes(Thread::polling_word_offset()) + 7 /* Big Endian */);
const Address poll_byte_addr(Z_thread, in_bytes(JavaThread::polling_word_offset()) + 7 /* Big Endian */);
// Armed page has poll_bit set.
z_tm(poll_byte_addr, SafepointMechanism::poll_bit());
z_brnaz(slow_path);
@@ -957,7 +957,7 @@ void MachEpilogNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const {

// Touch the polling page.
if (need_polling) {
__ z_lg(Z_R1_scratch, Address(Z_thread, Thread::polling_page_offset()));
__ z_lg(Z_R1_scratch, Address(Z_thread, JavaThread::polling_page_offset()));
// We need to mark the code position where the load from the safepoint
// polling page was emitted as relocInfo::poll_return_type here.
__ relocate(relocInfo::poll_return_type);
@@ -2319,7 +2319,7 @@ void TemplateTable::_return(TosState state) {

if (_desc->bytecode() != Bytecodes::_return_register_finalizer) {
Label no_safepoint;
const Address poll_byte_addr(Z_thread, in_bytes(Thread::polling_word_offset()) + 7 /* Big Endian */);
const Address poll_byte_addr(Z_thread, in_bytes(JavaThread::polling_word_offset()) + 7 /* Big Endian */);
__ z_tm(poll_byte_addr, SafepointMechanism::poll_bit());
__ z_braz(no_safepoint);
__ push(state);
@@ -555,12 +555,12 @@ int LIR_Assembler::safepoint_poll(LIR_Opr tmp, CodeEmitInfo* info) {
int offset = __ offset();
#ifdef _LP64
const Register poll_addr = rscratch1;
__ movptr(poll_addr, Address(r15_thread, Thread::polling_page_offset()));
__ movptr(poll_addr, Address(r15_thread, JavaThread::polling_page_offset()));
#else
assert(tmp->is_cpu_register(), "needed");
const Register poll_addr = tmp->as_register();
__ get_thread(poll_addr);
__ movptr(poll_addr, Address(poll_addr, in_bytes(Thread::polling_page_offset())));
__ movptr(poll_addr, Address(poll_addr, in_bytes(JavaThread::polling_page_offset())));
#endif
add_debug_info_for_branch(info);
__ relocate(relocInfo::poll_type);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. 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
@@ -858,7 +858,7 @@ void InterpreterMacroAssembler::dispatch_base(TosState state,
Label no_safepoint, dispatch;
if (table != safepoint_table && generate_poll) {
NOT_PRODUCT(block_comment("Thread-local Safepoint poll"));
testb(Address(r15_thread, Thread::polling_word_offset()), SafepointMechanism::poll_bit());
testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());

jccb(Assembler::zero, no_safepoint);
lea(rscratch1, ExternalAddress((address)safepoint_table));
@@ -877,7 +877,7 @@ void InterpreterMacroAssembler::dispatch_base(TosState state,
Label no_safepoint;
const Register thread = rcx;
get_thread(thread);
testb(Address(thread, Thread::polling_word_offset()), SafepointMechanism::poll_bit());
testb(Address(thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());

jccb(Assembler::zero, no_safepoint);
ArrayAddress dispatch_addr(ExternalAddress((address)safepoint_table), index);
@@ -2808,11 +2808,11 @@ void MacroAssembler::safepoint_poll(Label& slow_path, Register thread_reg, bool
if (at_return) {
// Note that when in_nmethod is set, the stack pointer is incremented before the poll. Therefore,
// we may safely use rsp instead to perform the stack watermark check.
cmpptr(in_nmethod ? rsp : rbp, Address(thread_reg, Thread::polling_word_offset()));
cmpptr(in_nmethod ? rsp : rbp, Address(thread_reg, JavaThread::polling_word_offset()));
jcc(Assembler::above, slow_path);
return;
}
testb(Address(thread_reg, Thread::polling_word_offset()), SafepointMechanism::poll_bit());
testb(Address(thread_reg, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
jcc(Assembler::notZero, slow_path); // handshake bit set implies poll
}

@@ -2605,11 +2605,11 @@ void TemplateTable::_return(TosState state) {
Label no_safepoint;
NOT_PRODUCT(__ block_comment("Thread-local Safepoint poll"));
#ifdef _LP64
__ testb(Address(r15_thread, Thread::polling_word_offset()), SafepointMechanism::poll_bit());
__ testb(Address(r15_thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
#else
const Register thread = rdi;
__ get_thread(thread);
__ testb(Address(thread, Thread::polling_word_offset()), SafepointMechanism::poll_bit());
__ testb(Address(thread, JavaThread::polling_word_offset()), SafepointMechanism::poll_bit());
#endif
__ jcc(Assembler::zero, no_safepoint);
__ push(state);
@@ -174,7 +174,7 @@ void MemAllocator::Allocation::check_for_valid_allocation_state() const {
"shouldn't be allocating with pending exception");
// Allocation of an oop can always invoke a safepoint.
assert(_thread->is_Java_thread(), "non Java threads shouldn't allocate on the Heap");
_thread->check_for_valid_safepoint_state();
_thread->as_Java_thread()->check_for_valid_safepoint_state();
}
#endif

@@ -1380,7 +1380,7 @@ void SignatureHandlerLibrary::add(const methodHandle& method) {
method->set_signature_handler(_handlers->at(handler_index));
}
} else {
DEBUG_ONLY(Thread::current()->check_possible_safepoint());
DEBUG_ONLY(JavaThread::current()->check_possible_safepoint());
// use generic signature handler
method->set_signature_handler(Interpreter::slow_signature_handler());
}
@@ -187,6 +187,7 @@
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) \
\
static_field(java_lang_Class, _klass_offset, int) \
@@ -332,7 +333,6 @@
\
nonstatic_field(Thread, _tlab, ThreadLocalAllocBuffer) \
nonstatic_field(Thread, _allocated_bytes, jlong) \
nonstatic_field(Thread, _poll_data, SafepointMechanism::ThreadData) \
\
nonstatic_field(ThreadLocalAllocBuffer, _start, HeapWord*) \
nonstatic_field(ThreadLocalAllocBuffer, _top, HeapWord*) \
@@ -344,7 +344,7 @@ Klass* ObjArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
if (or_null) {
return ak->array_klass_or_null(n);
}
THREAD->check_possible_safepoint();
THREAD->as_Java_thread()->check_possible_safepoint();
return ak->array_klass(n, THREAD);
}

@@ -203,7 +203,7 @@ Klass* TypeArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
if (or_null) {
return h_ak->array_klass_or_null(n);
}
THREAD->check_possible_safepoint();
THREAD->as_Java_thread()->check_possible_safepoint();
return h_ak->array_klass(n, THREAD);
}

@@ -2279,7 +2279,7 @@ void Parse::add_safepoint() {
// Create a node for the polling address
Node *polladr;
Node *thread = _gvn.transform(new ThreadLocalNode());
Node *polling_page_load_addr = _gvn.transform(basic_plus_adr(top(), thread, in_bytes(Thread::polling_page_offset())));
Node *polling_page_load_addr = _gvn.transform(basic_plus_adr(top(), thread, in_bytes(JavaThread::polling_page_offset())));
polladr = make_load(control(), polling_page_load_addr, TypeRawPtr::BOTTOM, T_ADDRESS, Compile::AliasIdxRaw, MemNode::unordered);
sfpnt->init_req(TypeFunc::Parms+0, _gvn.transform(polladr));

@@ -118,7 +118,7 @@ JvmtiTagMap* JvmtiTagMap::tag_map_for(JvmtiEnv* env) {
tag_map = new JvmtiTagMap(env);
}
} else {
DEBUG_ONLY(Thread::current()->check_possible_safepoint());
DEBUG_ONLY(JavaThread::current()->check_possible_safepoint());
}
return tag_map;
}
@@ -55,7 +55,7 @@ void Mutex::check_safepoint_state(Thread* thread) {
name());

// Also check NoSafepointVerifier, and thread state is _thread_in_vm
thread->check_for_valid_safepoint_state();
thread->as_Java_thread()->check_for_valid_safepoint_state();
} else {
// If initialized with safepoint_check_never, a NonJavaThread should never ask to safepoint check either.
assert(_safepoint_check_required != _safepoint_check_never,
@@ -419,23 +419,6 @@ bool Mutex::contains(Mutex* locks, Mutex* lock) {
return false;
}

// NSV implied with locking allow_vm_block or !safepoint_check locks.
void Mutex::no_safepoint_verifier(Thread* thread, bool enable) {
// The tty_lock is special because it is released for the safepoint by
// the safepoint mechanism.
if (this == tty_lock) {
return;
}

if (_allow_vm_block) {
if (enable) {
thread->_no_safepoint_count++;
} else {
thread->_no_safepoint_count--;
}
}
}

// Called immediately after lock acquisition or release as a diagnostic
// to track the lock-set of the thread.
// Rather like an EventListener for _owner (:>).
@@ -463,7 +446,11 @@ void Mutex::set_owner_implementation(Thread *new_owner) {
new_owner->_owned_locks = this;

// NSV implied with locking allow_vm_block flag.
no_safepoint_verifier(new_owner, true);
// The tty_lock is special because it is released for the safepoint by
// the safepoint mechanism.
if (new_owner->is_Java_thread() && _allow_vm_block && this != tty_lock) {
new_owner->as_Java_thread()->inc_no_safepoint_count();
}

} else {
// the thread is releasing this lock
@@ -498,7 +485,9 @@ void Mutex::set_owner_implementation(Thread *new_owner) {
_next = NULL;

// ~NSV implied with locking allow_vm_block flag.
no_safepoint_verifier(old_owner, false);
if (old_owner->is_Java_thread() && _allow_vm_block && this != tty_lock) {
old_owner->as_Java_thread()->dec_no_safepoint_count();
}
}
}
#endif // ASSERT
@@ -118,7 +118,6 @@ class Mutex : public CHeapObj<mtSynchronizer> {
void check_no_safepoint_state(Thread* thread) NOT_DEBUG_RETURN;
void check_rank (Thread* thread) NOT_DEBUG_RETURN;
void assert_owner (Thread* expected) NOT_DEBUG_RETURN;
void no_safepoint_verifier (Thread* thread, bool enable) NOT_DEBUG_RETURN;

public:
static const bool _allow_vm_block_flag = true;
Loading

1 comment on commit 5634f20

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 5634f20 Apr 27, 2021

Please sign in to comment.