Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.
/ lanai Public archive

Commit 431338b

Browse files
committedSep 29, 2020
8212107: VMThread issues and cleanup
Reviewed-by: shade, dcubed, coleenp, dholmes, redestad
1 parent 6bddeb7 commit 431338b

File tree

8 files changed

+221
-334
lines changed

8 files changed

+221
-334
lines changed
 

‎src/hotspot/share/jfr/recorder/repository/jfrEmergencyDump.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -454,12 +454,8 @@ static bool prepare_for_emergency_dump(Thread* thread) {
454454
Heap_lock->unlock();
455455
}
456456

457-
if (VMOperationQueue_lock->owned_by_self()) {
458-
VMOperationQueue_lock->unlock();
459-
}
460-
461-
if (VMOperationRequest_lock->owned_by_self()) {
462-
VMOperationRequest_lock->unlock();
457+
if (VMOperation_lock->owned_by_self()) {
458+
VMOperation_lock->unlock();
463459
}
464460

465461
if (Service_lock->owned_by_self()) {

‎src/hotspot/share/runtime/mutexLocker.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ Monitor* CodeSweeper_lock = NULL;
6565
Mutex* MethodData_lock = NULL;
6666
Mutex* TouchedMethodLog_lock = NULL;
6767
Mutex* RetData_lock = NULL;
68-
Monitor* VMOperationQueue_lock = NULL;
69-
Monitor* VMOperationRequest_lock = NULL;
68+
Monitor* VMOperation_lock = NULL;
7069
Monitor* Threads_lock = NULL;
7170
Mutex* NonJavaThreadsList_lock = NULL;
7271
Mutex* NonJavaThreadsListSync_lock = NULL;
@@ -280,8 +279,7 @@ void mutex_init() {
280279
def(NonJavaThreadsList_lock , PaddedMutex, barrier, true, _safepoint_check_never);
281280
def(NonJavaThreadsListSync_lock , PaddedMutex, leaf, true, _safepoint_check_never);
282281

283-
def(VMOperationQueue_lock , PaddedMonitor, nonleaf, true, _safepoint_check_never); // VM_thread allowed to block on these
284-
def(VMOperationRequest_lock , PaddedMonitor, nonleaf, true, _safepoint_check_always);
282+
def(VMOperation_lock , PaddedMonitor, nonleaf, true, _safepoint_check_always); // VM_thread allowed to block on these
285283
def(RetData_lock , PaddedMutex , nonleaf, false, _safepoint_check_always);
286284
def(Terminator_lock , PaddedMonitor, nonleaf, true, _safepoint_check_always);
287285
def(InitCompleted_lock , PaddedMonitor, leaf, true, _safepoint_check_never);

‎src/hotspot/share/runtime/mutexLocker.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ extern Monitor* CodeSweeper_lock; // a lock used by the sweeper o
5858
extern Mutex* MethodData_lock; // a lock on installation of method data
5959
extern Mutex* TouchedMethodLog_lock; // a lock on allocation of LogExecutedMethods info
6060
extern Mutex* RetData_lock; // a lock on installation of RetData inside method data
61-
extern Monitor* VMOperationQueue_lock; // a lock on queue of vm_operations waiting to execute
62-
extern Monitor* VMOperationRequest_lock; // a lock on Threads waiting for a vm_operation to terminate
61+
extern Monitor* VMOperation_lock; // a lock on queue of vm_operations waiting to execute
6362
extern Monitor* Threads_lock; // a lock on the Threads table of active Java threads
6463
// (also used by Safepoints too to block threads creation/destruction)
6564
extern Mutex* NonJavaThreadsList_lock; // a lock on the NonJavaThreads list

‎src/hotspot/share/runtime/thread.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ Thread::Thread() {
255255
NOT_PRODUCT(_skip_gcalot = false;)
256256
_jvmti_env_iteration_count = 0;
257257
set_allocated_bytes(0);
258-
_vm_operation_started_count = 0;
259-
_vm_operation_completed_count = 0;
260258
_current_pending_monitor = NULL;
261259
_current_pending_monitor_is_from_java = true;
262260
_current_waiting_monitor = NULL;

‎src/hotspot/share/runtime/thread.hpp

-8
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,6 @@ class Thread: public ThreadShadow {
401401

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

404-
int _vm_operation_started_count; // VM_Operation support
405-
int _vm_operation_completed_count; // VM_Operation support
406-
407404
ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread
408405
// is waiting to lock
409406
bool _current_pending_monitor_is_from_java; // locking is from Java code
@@ -621,11 +618,6 @@ class Thread: public ThreadShadow {
621618

622619
bool is_trace_suspend() { return (_suspend_flags & _trace_flag) != 0; }
623620

624-
// VM operation support
625-
int vm_operation_ticket() { return ++_vm_operation_started_count; }
626-
int vm_operation_completed_count() { return _vm_operation_completed_count; }
627-
void increment_vm_operation_completed_count() { _vm_operation_completed_count++; }
628-
629621
// For tracking the heavyweight monitor the thread is pending on.
630622
ObjectMonitor* current_pending_monitor() {
631623
return _current_pending_monitor;

‎src/hotspot/share/runtime/vmOperations.hpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,12 @@ class VM_Operation : public StackObj {
121121

122122
private:
123123
Thread* _calling_thread;
124-
VM_Operation* _next;
125-
VM_Operation* _prev;
126124

127125
// The VM operation name array
128126
static const char* _names[];
129127

130128
public:
131-
VM_Operation() : _calling_thread(NULL), _next(NULL), _prev(NULL) {}
129+
VM_Operation() : _calling_thread(NULL) {}
132130

133131
// VM operation support (used by VM thread)
134132
Thread* calling_thread() const { return _calling_thread; }
@@ -148,12 +146,6 @@ class VM_Operation : public StackObj {
148146
virtual bool doit_prologue() { return true; };
149147
virtual void doit_epilogue() {};
150148

151-
// Linking
152-
VM_Operation *next() const { return _next; }
153-
VM_Operation *prev() const { return _prev; }
154-
void set_next(VM_Operation *next) { _next = next; }
155-
void set_prev(VM_Operation *prev) { _prev = prev; }
156-
157149
// Configuration. Override these appropriately in subclasses.
158150
virtual VMOp_Type type() const = 0;
159151
virtual bool allow_nested_vm_operations() const { return false; }

‎src/hotspot/share/runtime/vmThread.cpp

+193-251
Large diffs are not rendered by default.

‎src/hotspot/share/runtime/vmThread.hpp

+22-52
Original file line numberDiff line numberDiff line change
@@ -30,53 +30,6 @@
3030
#include "runtime/task.hpp"
3131
#include "runtime/vmOperations.hpp"
3232

33-
class VM_QueueHead : public VM_None {
34-
public:
35-
VM_QueueHead() : VM_None("QueueHead") {}
36-
};
37-
38-
//
39-
// Prioritized queue of VM operations.
40-
//
41-
// Encapsulates both queue management and
42-
// and priority policy
43-
//
44-
class VMOperationQueue : public CHeapObj<mtInternal> {
45-
private:
46-
enum Priorities {
47-
SafepointPriority, // Highest priority (operation executed at a safepoint)
48-
MediumPriority, // Medium priority
49-
nof_priorities
50-
};
51-
52-
// We maintain a doubled linked list, with explicit count.
53-
int _queue_length[nof_priorities];
54-
int _queue_counter;
55-
VM_Operation* _queue [nof_priorities];
56-
57-
static VM_QueueHead _queue_head[nof_priorities];
58-
59-
// Double-linked non-empty list insert.
60-
void insert(VM_Operation* q,VM_Operation* n);
61-
void unlink(VM_Operation* q);
62-
63-
// Basic queue manipulation
64-
bool queue_empty (int prio);
65-
void queue_add (int prio, VM_Operation *op);
66-
VM_Operation* queue_remove_front(int prio);
67-
// lock-free query: may return the wrong answer but must not break
68-
bool queue_peek(int prio) { return _queue_length[prio] > 0; }
69-
70-
public:
71-
VMOperationQueue();
72-
73-
// Highlevel operations. Encapsulates policy
74-
void add(VM_Operation *op);
75-
VM_Operation* remove_next(); // Returns next or null
76-
bool peek_at_safepoint_priority() { return queue_peek(SafepointPriority); }
77-
};
78-
79-
8033
// VM operation timeout handling: warn or abort the VM when VM operation takes
8134
// too long. Periodic tasks do not participate in safepoint protocol, and therefore
8235
// can fire when application threads are stopped.
@@ -114,9 +67,12 @@ class VMThread: public NamedThread {
11467

11568
static VMOperationTimeoutTask* _timeout_task;
11669

117-
static VM_Operation* no_op_safepoint();
70+
static bool handshake_alot();
71+
static void setup_periodic_safepoint_if_needed();
11872

11973
void evaluate_operation(VM_Operation* op);
74+
void inner_execute(VM_Operation* op);
75+
void wait_for_operation();
12076

12177
public:
12278
// Constructor
@@ -143,16 +99,26 @@ class VMThread: public NamedThread {
14399
static void execute(VM_Operation* op);
144100

145101
// Returns the current vm operation if any.
146-
static VM_Operation* vm_operation() { return _cur_vm_operation; }
147-
static VM_Operation::VMOp_Type vm_op_type() { return _cur_vm_operation->type(); }
102+
static VM_Operation* vm_operation() {
103+
assert(Thread::current()->is_VM_thread(), "Must be");
104+
return _cur_vm_operation;
105+
}
106+
107+
static VM_Operation::VMOp_Type vm_op_type() {
108+
VM_Operation* op = vm_operation();
109+
assert(op != NULL, "sanity");
110+
return op->type();
111+
}
148112

149113
// Returns the single instance of VMThread.
150114
static VMThread* vm_thread() { return _vm_thread; }
151115

152116
void verify();
153117

154118
// Performance measurement
155-
static PerfCounter* perf_accumulated_vm_operation_time() { return _perf_accumulated_vm_operation_time; }
119+
static PerfCounter* perf_accumulated_vm_operation_time() {
120+
return _perf_accumulated_vm_operation_time;
121+
}
156122

157123
// Entry for starting vm thread
158124
virtual void run();
@@ -161,10 +127,14 @@ class VMThread: public NamedThread {
161127
static void create();
162128
static void destroy();
163129

130+
static void wait_until_executed(VM_Operation* op);
131+
164132
private:
165133
// VM_Operation support
166134
static VM_Operation* _cur_vm_operation; // Current VM operation
167-
static VMOperationQueue* _vm_queue; // Queue (w/ policy) of VM operations
135+
static VM_Operation* _next_vm_operation; // Next VM operation
136+
137+
bool set_next_operation(VM_Operation *op); // Set the _next_vm_operation if possible.
168138

169139
// Pointer to single-instance of VM thread
170140
static VMThread* _vm_thread;

0 commit comments

Comments
 (0)
This repository has been archived.