@@ -435,7 +435,6 @@ void VMThread::loop() {
435
435
SafepointSynchronize::init (_vm_thread);
436
436
437
437
while (true ) {
438
- VM_Operation* safepoint_ops = NULL ;
439
438
//
440
439
// Wait for VM operation
441
440
//
@@ -487,13 +486,6 @@ void VMThread::loop() {
487
486
}
488
487
}
489
488
_cur_vm_operation = _vm_queue->remove_next ();
490
-
491
- // If we are at a safepoint we will evaluate all the operations that
492
- // follow that also require a safepoint
493
- if (_cur_vm_operation != NULL &&
494
- _cur_vm_operation->evaluate_at_safepoint ()) {
495
- safepoint_ops = _vm_queue->drain_at_safepoint_priority ();
496
- }
497
489
}
498
490
499
491
if (should_terminate ()) break ;
@@ -518,42 +510,38 @@ void VMThread::loop() {
518
510
_timeout_task->arm ();
519
511
}
520
512
521
- evaluate_operation (_cur_vm_operation);
522
- // now process all queued safepoint ops, iteratively draining
523
- // the queue until there are none left
513
+ VM_Operation* safepoint_ops = NULL ;
514
+ if (_vm_queue->peek_at_safepoint_priority ()) {
515
+ // must hold lock while draining queue
516
+ MutexLocker mu_queue (VMOperationQueue_lock,
517
+ Mutex::_no_safepoint_check_flag);
518
+ safepoint_ops = _vm_queue->drain_at_safepoint_priority ();
519
+ }
520
+ VM_Operation* next = safepoint_ops;
524
521
do {
525
- _cur_vm_operation = safepoint_ops;
526
- if (_cur_vm_operation != NULL ) {
527
- do {
528
- EventMark em (" Executing coalesced safepoint VM operation: %s" , _cur_vm_operation->name ());
529
- log_debug (vmthread)(" Evaluating coalesced safepoint VM operation: %s" , _cur_vm_operation->name ());
530
- // evaluate_operation deletes the op object so we have
531
- // to grab the next op now
532
- VM_Operation* next = _cur_vm_operation->next ();
533
- evaluate_operation (_cur_vm_operation);
534
- _cur_vm_operation = next;
535
- _coalesced_count++;
536
- } while (_cur_vm_operation != NULL );
537
- }
538
- // There is a chance that a thread enqueued a safepoint op
539
- // since we released the op-queue lock and initiated the safepoint.
540
- // So we drain the queue again if there is anything there, as an
541
- // optimization to try and reduce the number of safepoints.
542
- // As the safepoint synchronizes us with JavaThreads we will see
543
- // any enqueue made by a JavaThread, but the peek will not
544
- // necessarily detect a concurrent enqueue by a GC thread, but
545
- // that simply means the op will wait for the next major cycle of the
546
- // VMThread - just as it would if the GC thread lost the race for
547
- // the lock.
548
- if (_vm_queue->peek_at_safepoint_priority ()) {
549
- // must hold lock while draining queue
550
- MutexLocker mu_queue (VMOperationQueue_lock,
551
- Mutex::_no_safepoint_check_flag);
552
- safepoint_ops = _vm_queue->drain_at_safepoint_priority ();
553
- } else {
554
- safepoint_ops = NULL ;
522
+ evaluate_operation (_cur_vm_operation);
523
+ bool next_cant_coalesce = next != NULL && (!next->allow_coalesced_vm_operations () ||
524
+ !_cur_vm_operation->allow_coalesced_vm_operations ());
525
+ _cur_vm_operation = next;
526
+ if (next_cant_coalesce) {
527
+ // Safepoint coalescing fence for operations that may not be
528
+ // coalesced with other safepoint operations.
529
+ if (_timeout_task != NULL ) {
530
+ _timeout_task->disarm ();
531
+ }
532
+ SafepointSynchronize::end ();
533
+ SafepointSynchronize::begin ();
534
+ if (_timeout_task != NULL ) {
535
+ _timeout_task->arm ();
536
+ }
537
+ next = _cur_vm_operation->next ();
538
+ } else if (_cur_vm_operation != NULL ) {
539
+ EventMark em (" Executing coalesced safepoint VM operation: %s" , _cur_vm_operation->name ());
540
+ log_debug (vmthread)(" Evaluating coalesced safepoint VM operation: %s" , _cur_vm_operation->name ());
541
+ _coalesced_count++;
542
+ next = _cur_vm_operation->next ();
555
543
}
556
- } while (safepoint_ops != NULL );
544
+ } while (_cur_vm_operation != NULL );
557
545
558
546
if (_timeout_task != NULL ) {
559
547
_timeout_task->disarm ();
0 commit comments