Skip to content
Permalink
Browse files
8265933: Move Java monitor related fields from class Thread to JavaTh…
…read

Reviewed-by: rehn, dcubed, coleenp, dholmes
  • Loading branch information
pchilano committed Apr 29, 2021
1 parent 1afbab6 commit 42af7da94d9ed588a1c526202f6b77773e4e3f95
@@ -263,9 +263,6 @@ Thread::Thread() {
NOT_PRODUCT(_skip_gcalot = false;)
_jvmti_env_iteration_count = 0;
set_allocated_bytes(0);
_current_pending_monitor = NULL;
_current_pending_monitor_is_from_java = true;
_current_waiting_monitor = NULL;
_current_pending_raw_monitor = NULL;

_suspend_flags = 0;
@@ -276,10 +273,6 @@ Thread::Thread() {
_hashStateZ = 0x8767; // (int)(3579807591LL & 0xffff) ;
_hashStateW = 273326509;

_OnTrap = 0;
_Stalled = 0;
_TypeTag = 0x2BAD;

// Many of the following fields are effectively final - immutable
// Note that nascent threads can't use the Native Monitor-Mutex
// construct until the _MutexEvent is initialized ...
@@ -1053,6 +1046,11 @@ JavaThread::JavaThread() :
_vm_result(nullptr),
_vm_result_2(nullptr),

_current_pending_monitor(NULL),
_current_pending_monitor_is_from_java(true),
_current_waiting_monitor(NULL),
_Stalled(0),

_monitor_chunks(nullptr),
_special_runtime_exit_condition(_no_async_condition),
_pending_async_exception(nullptr),
@@ -308,16 +308,8 @@ class Thread: public ThreadShadow {

JFR_ONLY(DEFINE_THREAD_LOCAL_FIELD_JFR;) // Thread-local data for jfr

ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
// is waiting to lock
bool _current_pending_monitor_is_from_java; // locking is from Java code
JvmtiRawMonitor* _current_pending_raw_monitor; // JvmtiRawMonitor this thread
// is waiting to lock


// ObjectMonitor on which this thread called Object.wait()
ObjectMonitor* _current_waiting_monitor;

public:
// Constructor
Thread();
@@ -490,28 +482,6 @@ class Thread: public ThreadShadow {

bool is_obj_deopt_suspend() { return (_suspend_flags & _obj_deopt) != 0; }

// For tracking the heavyweight monitor the thread is pending on.
ObjectMonitor* current_pending_monitor() {
return _current_pending_monitor;
}
void set_current_pending_monitor(ObjectMonitor* monitor) {
_current_pending_monitor = monitor;
}
void set_current_pending_monitor_is_from_java(bool from_java) {
_current_pending_monitor_is_from_java = from_java;
}
bool current_pending_monitor_is_from_java() {
return _current_pending_monitor_is_from_java;
}

// For tracking the ObjectMonitor on which this thread called Object.wait()
ObjectMonitor* current_waiting_monitor() {
return _current_waiting_monitor;
}
void set_current_waiting_monitor(ObjectMonitor* monitor) {
_current_waiting_monitor = monitor;
}

// For tracking the Jvmti raw monitor the thread is pending on.
JvmtiRawMonitor* current_pending_raw_monitor() {
return _current_pending_raw_monitor;
@@ -689,8 +659,6 @@ class Thread: public ThreadShadow {
JFR_ONLY(DEFINE_THREAD_LOCAL_OFFSET_JFR;)

public:
volatile intptr_t _Stalled;
volatile int _TypeTag;
ParkEvent * volatile _ParkEvent; // for Object monitors, JVMTI raw monitors,
// and ObjectSynchronizer::read_stable_mark

@@ -699,7 +667,6 @@ class Thread: public ThreadShadow {
// (which can't itself be read from the signal handler if a signal hits during the Thread destructor).
bool has_terminated() { return Atomic::load(&_ParkEvent) == NULL; };

volatile int _OnTrap; // Resume-at IP delta
jint _hashStateW; // Marsaglia Shift-XOR thread-local RNG
jint _hashStateX; // thread-specific hashCode generator state
jint _hashStateY;
@@ -809,9 +776,36 @@ class JavaThread: public Thread {
// elided card-marks for performance along the fast-path.
MemRegion _deferred_card_mark;

MonitorChunk* _monitor_chunks; // Contains the off stack monitors
// allocated during deoptimization
// and by JNI_MonitorEnter/Exit
ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread is waiting to lock
bool _current_pending_monitor_is_from_java; // locking is from Java code
ObjectMonitor* _current_waiting_monitor; // ObjectMonitor on which this thread called Object.wait()
public:
volatile intptr_t _Stalled;

// For tracking the heavyweight monitor the thread is pending on.
ObjectMonitor* current_pending_monitor() {
return _current_pending_monitor;
}
void set_current_pending_monitor(ObjectMonitor* monitor) {
_current_pending_monitor = monitor;
}
void set_current_pending_monitor_is_from_java(bool from_java) {
_current_pending_monitor_is_from_java = from_java;
}
bool current_pending_monitor_is_from_java() {
return _current_pending_monitor_is_from_java;
}
ObjectMonitor* current_waiting_monitor() {
return _current_waiting_monitor;
}
void set_current_waiting_monitor(ObjectMonitor* monitor) {
_current_waiting_monitor = monitor;
}

private:
MonitorChunk* _monitor_chunks; // Contains the off stack monitors
// allocated during deoptimization
// and by JNI_MonitorEnter/Exit

// Async. requests support
enum AsyncRequests {
@@ -734,15 +734,15 @@ typedef HashtableEntry<InstanceKlass*, mtClass> KlassHashtableEntry;
nonstatic_field(Thread, _active_handles, JNIHandleBlock*) \
nonstatic_field(Thread, _tlab, ThreadLocalAllocBuffer) \
nonstatic_field(Thread, _allocated_bytes, jlong) \
nonstatic_field(Thread, _current_pending_monitor, ObjectMonitor*) \
nonstatic_field(Thread, _current_pending_monitor_is_from_java, bool) \
nonstatic_field(Thread, _current_waiting_monitor, ObjectMonitor*) \
nonstatic_field(NamedThread, _name, char*) \
nonstatic_field(NamedThread, _processed_thread, Thread*) \
nonstatic_field(JavaThread, _threadObj, OopHandle) \
nonstatic_field(JavaThread, _anchor, JavaFrameAnchor) \
nonstatic_field(JavaThread, _vm_result, oop) \
nonstatic_field(JavaThread, _vm_result_2, Metadata*) \
nonstatic_field(JavaThread, _current_pending_monitor, ObjectMonitor*) \
nonstatic_field(JavaThread, _current_pending_monitor_is_from_java, bool) \
nonstatic_field(JavaThread, _current_waiting_monitor, ObjectMonitor*) \
nonstatic_field(JavaThread, _pending_async_exception, oop) \
volatile_nonstatic_field(JavaThread, _exception_oop, oop) \
volatile_nonstatic_field(JavaThread, _exception_pc, address) \
@@ -52,16 +52,17 @@ public void update(Observable o, Object data) {
}

private static synchronized void initialize(TypeDataBase db) {
Type type = db.lookupType("Thread");
Type typeThread = db.lookupType("Thread");
Type typeJavaThread = db.lookupType("JavaThread");

suspendFlagsField = type.getCIntegerField("_suspend_flags");
suspendFlagsField = typeThread.getCIntegerField("_suspend_flags");
HAS_ASYNC_EXCEPTION = db.lookupIntConstant("Thread::_has_async_exception").intValue();

tlabFieldOffset = type.getField("_tlab").getOffset();
activeHandlesField = type.getAddressField("_active_handles");
currentPendingMonitorField = type.getAddressField("_current_pending_monitor");
currentWaitingMonitorField = type.getAddressField("_current_waiting_monitor");
allocatedBytesField = type.getJLongField("_allocated_bytes");
tlabFieldOffset = typeThread.getField("_tlab").getOffset();
activeHandlesField = typeThread.getAddressField("_active_handles");
currentPendingMonitorField = typeJavaThread.getAddressField("_current_pending_monitor");
currentWaitingMonitorField = typeJavaThread.getAddressField("_current_waiting_monitor");
allocatedBytesField = typeThread.getJLongField("_allocated_bytes");
}

public Thread(Address addr) {

1 comment on commit 42af7da

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 42af7da Apr 29, 2021

Please sign in to comment.