133 while (cur != _queue[queue]) {
134 cur->oops_do(f);
135 cur = cur->next();
136 }
137 }
138
139 void VMOperationQueue::drain_list_oops_do(OopClosure* f) {
140 VM_Operation* cur = _drain_list;
141 while (cur != NULL) {
142 cur->oops_do(f);
143 cur = cur->next();
144 }
145 }
146
147 //-----------------------------------------------------------------
148 // High-level interface
149 void VMOperationQueue::add(VM_Operation *op) {
150
151 HOTSPOT_VMOPS_REQUEST(
152 (char *) op->name(), strlen(op->name()),
153 op->evaluation_mode());
154
155 // Encapsulates VM queue policy. Currently, that
156 // only involves putting them on the right list
157 queue_add(op->evaluate_at_safepoint() ? SafepointPriority : MediumPriority, op);
158 }
159
160 VM_Operation* VMOperationQueue::remove_next() {
161 // Assuming VMOperation queue is two-level priority queue. If there are
162 // more than two priorities, we need a different scheduling algorithm.
163 assert(SafepointPriority == 0 && MediumPriority == 1 && nof_priorities == 2,
164 "current algorithm does not work");
165
166 // simple counter based scheduling to prevent starvation of lower priority
167 // queue. -- see 4390175
168 int high_prio, low_prio;
169 if (_queue_counter++ < 10) {
170 high_prio = SafepointPriority;
171 low_prio = MediumPriority;
172 } else {
173 _queue_counter = 0;
375 static void post_vm_operation_event(EventExecuteVMOperation* event, VM_Operation* op) {
376 assert(event != NULL, "invariant");
377 assert(event->should_commit(), "invariant");
378 assert(op != NULL, "invariant");
379 const bool evaluate_at_safepoint = op->evaluate_at_safepoint();
380 event->set_operation(op->type());
381 event->set_safepoint(evaluate_at_safepoint);
382 event->set_blocking(true);
383 event->set_caller(JFR_THREAD_ID(op->calling_thread()));
384 event->set_safepointId(evaluate_at_safepoint ? SafepointSynchronize::safepoint_id() : 0);
385 event->commit();
386 }
387
388 void VMThread::evaluate_operation(VM_Operation* op) {
389 ResourceMark rm;
390
391 {
392 PerfTraceTime vm_op_timer(perf_accumulated_vm_operation_time());
393 HOTSPOT_VMOPS_BEGIN(
394 (char *) op->name(), strlen(op->name()),
395 op->evaluation_mode());
396
397 EventExecuteVMOperation event;
398 op->evaluate();
399 if (event.should_commit()) {
400 post_vm_operation_event(&event, op);
401 }
402
403 HOTSPOT_VMOPS_END(
404 (char *) op->name(), strlen(op->name()),
405 op->evaluation_mode());
406 }
407
408 // Mark as completed
409 op->calling_thread()->increment_vm_operation_completed_count();
410 }
411
412 static VM_None safepointALot_op("SafepointALot");
413 static VM_Cleanup cleanup_op;
414
415 class HandshakeALotTC : public ThreadClosure {
416 public:
417 virtual void do_thread(Thread* thread) {
418 #ifdef ASSERT
419 assert(thread->is_Java_thread(), "must be");
420 JavaThread* jt = (JavaThread*)thread;
421 jt->verify_states_for_handshake();
422 #endif
423 }
424 };
425
|
133 while (cur != _queue[queue]) {
134 cur->oops_do(f);
135 cur = cur->next();
136 }
137 }
138
139 void VMOperationQueue::drain_list_oops_do(OopClosure* f) {
140 VM_Operation* cur = _drain_list;
141 while (cur != NULL) {
142 cur->oops_do(f);
143 cur = cur->next();
144 }
145 }
146
147 //-----------------------------------------------------------------
148 // High-level interface
149 void VMOperationQueue::add(VM_Operation *op) {
150
151 HOTSPOT_VMOPS_REQUEST(
152 (char *) op->name(), strlen(op->name()),
153 op->evaluate_at_safepoint() ? 0 : 1);
154
155 // Encapsulates VM queue policy. Currently, that
156 // only involves putting them on the right list
157 queue_add(op->evaluate_at_safepoint() ? SafepointPriority : MediumPriority, op);
158 }
159
160 VM_Operation* VMOperationQueue::remove_next() {
161 // Assuming VMOperation queue is two-level priority queue. If there are
162 // more than two priorities, we need a different scheduling algorithm.
163 assert(SafepointPriority == 0 && MediumPriority == 1 && nof_priorities == 2,
164 "current algorithm does not work");
165
166 // simple counter based scheduling to prevent starvation of lower priority
167 // queue. -- see 4390175
168 int high_prio, low_prio;
169 if (_queue_counter++ < 10) {
170 high_prio = SafepointPriority;
171 low_prio = MediumPriority;
172 } else {
173 _queue_counter = 0;
375 static void post_vm_operation_event(EventExecuteVMOperation* event, VM_Operation* op) {
376 assert(event != NULL, "invariant");
377 assert(event->should_commit(), "invariant");
378 assert(op != NULL, "invariant");
379 const bool evaluate_at_safepoint = op->evaluate_at_safepoint();
380 event->set_operation(op->type());
381 event->set_safepoint(evaluate_at_safepoint);
382 event->set_blocking(true);
383 event->set_caller(JFR_THREAD_ID(op->calling_thread()));
384 event->set_safepointId(evaluate_at_safepoint ? SafepointSynchronize::safepoint_id() : 0);
385 event->commit();
386 }
387
388 void VMThread::evaluate_operation(VM_Operation* op) {
389 ResourceMark rm;
390
391 {
392 PerfTraceTime vm_op_timer(perf_accumulated_vm_operation_time());
393 HOTSPOT_VMOPS_BEGIN(
394 (char *) op->name(), strlen(op->name()),
395 op->evaluate_at_safepoint() ? 0 : 1);
396
397 EventExecuteVMOperation event;
398 op->evaluate();
399 if (event.should_commit()) {
400 post_vm_operation_event(&event, op);
401 }
402
403 HOTSPOT_VMOPS_END(
404 (char *) op->name(), strlen(op->name()),
405 op->evaluate_at_safepoint() ? 0 : 1);
406 }
407
408 // Mark as completed
409 op->calling_thread()->increment_vm_operation_completed_count();
410 }
411
412 static VM_None safepointALot_op("SafepointALot");
413 static VM_Cleanup cleanup_op;
414
415 class HandshakeALotTC : public ThreadClosure {
416 public:
417 virtual void do_thread(Thread* thread) {
418 #ifdef ASSERT
419 assert(thread->is_Java_thread(), "must be");
420 JavaThread* jt = (JavaThread*)thread;
421 jt->verify_states_for_handshake();
422 #endif
423 }
424 };
425
|