476 // Execute VM operation
477 //
478 { HandleMark hm(VMThread::vm_thread());
479
480 EventMark em("Executing VM operation: %s", vm_operation()->name());
481 assert(_cur_vm_operation != NULL, "we should have found an operation to execute");
482
483 // Give the VM thread an extra quantum. Jobs tend to be bursty and this
484 // helps the VM thread to finish up the job.
485 // FIXME: When this is enabled and there are many threads, this can degrade
486 // performance significantly.
487 if( VMThreadHintNoPreempt )
488 os::hint_no_preempt();
489
490 // If we are at a safepoint we will evaluate all the operations that
491 // follow that also require a safepoint
492 if (_cur_vm_operation->evaluate_at_safepoint()) {
493
494 _vm_queue->set_drain_list(safepoint_ops); // ensure ops can be scanned
495
496 SafepointSynchronize::begin();
497 evaluate_operation(_cur_vm_operation);
498 // now process all queued safepoint ops, iteratively draining
499 // the queue until there are none left
500 do {
501 _cur_vm_operation = safepoint_ops;
502 if (_cur_vm_operation != NULL) {
503 do {
504 // evaluate_operation deletes the op object so we have
505 // to grab the next op now
506 VM_Operation* next = _cur_vm_operation->next();
507 _vm_queue->set_drain_list(next);
508 evaluate_operation(_cur_vm_operation);
509 _cur_vm_operation = next;
510 if (PrintSafepointStatistics) {
511 SafepointSynchronize::inc_vmop_coalesced_count();
512 }
513 } while (_cur_vm_operation != NULL);
514 }
515 // There is a chance that a thread enqueued a safepoint op
516 // since we released the op-queue lock and initiated the safepoint.
518 // optimization to try and reduce the number of safepoints.
519 // As the safepoint synchronizes us with JavaThreads we will see
520 // any enqueue made by a JavaThread, but the peek will not
521 // necessarily detect a concurrent enqueue by a GC thread, but
522 // that simply means the op will wait for the next major cycle of the
523 // VMThread - just as it would if the GC thread lost the race for
524 // the lock.
525 if (_vm_queue->peek_at_safepoint_priority()) {
526 // must hold lock while draining queue
527 MutexLockerEx mu_queue(VMOperationQueue_lock,
528 Mutex::_no_safepoint_check_flag);
529 safepoint_ops = _vm_queue->drain_at_safepoint_priority();
530 } else {
531 safepoint_ops = NULL;
532 }
533 } while(safepoint_ops != NULL);
534
535 _vm_queue->set_drain_list(NULL);
536
537 // Complete safepoint synchronization
538 SafepointSynchronize::end();
539
540 } else { // not a safepoint operation
541 if (TraceLongCompiles) {
542 elapsedTimer t;
543 t.start();
544 evaluate_operation(_cur_vm_operation);
545 t.stop();
546 double secs = t.seconds();
547 if (secs * 1e3 > LongCompileThreshold) {
548 // XXX - _cur_vm_operation should not be accessed after
549 // the completed count has been incremented; the waiting
550 // thread may have already freed this memory.
551 tty->print_cr("vm %s: %3.7f secs]", _cur_vm_operation->name(), secs);
552 }
553 } else {
554 evaluate_operation(_cur_vm_operation);
555 }
556
557 _cur_vm_operation = NULL;
558 }
|
476 // Execute VM operation
477 //
478 { HandleMark hm(VMThread::vm_thread());
479
480 EventMark em("Executing VM operation: %s", vm_operation()->name());
481 assert(_cur_vm_operation != NULL, "we should have found an operation to execute");
482
483 // Give the VM thread an extra quantum. Jobs tend to be bursty and this
484 // helps the VM thread to finish up the job.
485 // FIXME: When this is enabled and there are many threads, this can degrade
486 // performance significantly.
487 if( VMThreadHintNoPreempt )
488 os::hint_no_preempt();
489
490 // If we are at a safepoint we will evaluate all the operations that
491 // follow that also require a safepoint
492 if (_cur_vm_operation->evaluate_at_safepoint()) {
493
494 _vm_queue->set_drain_list(safepoint_ops); // ensure ops can be scanned
495
496 SafepointSynchronize::begin(); {
497 NonGCSafepointMark gc_safepoint_detector(Universe::heap());
498
499 evaluate_operation(_cur_vm_operation);
500 // now process all queued safepoint ops, iteratively draining
501 // the queue until there are none left
502 do {
503 _cur_vm_operation = safepoint_ops;
504 if (_cur_vm_operation != NULL) {
505 do {
506 // evaluate_operation deletes the op object so we have
507 // to grab the next op now
508 VM_Operation* next = _cur_vm_operation->next();
509 _vm_queue->set_drain_list(next);
510 evaluate_operation(_cur_vm_operation);
511 _cur_vm_operation = next;
512 if (PrintSafepointStatistics) {
513 SafepointSynchronize::inc_vmop_coalesced_count();
514 }
515 } while (_cur_vm_operation != NULL);
516 }
517 // There is a chance that a thread enqueued a safepoint op
518 // since we released the op-queue lock and initiated the safepoint.
520 // optimization to try and reduce the number of safepoints.
521 // As the safepoint synchronizes us with JavaThreads we will see
522 // any enqueue made by a JavaThread, but the peek will not
523 // necessarily detect a concurrent enqueue by a GC thread, but
524 // that simply means the op will wait for the next major cycle of the
525 // VMThread - just as it would if the GC thread lost the race for
526 // the lock.
527 if (_vm_queue->peek_at_safepoint_priority()) {
528 // must hold lock while draining queue
529 MutexLockerEx mu_queue(VMOperationQueue_lock,
530 Mutex::_no_safepoint_check_flag);
531 safepoint_ops = _vm_queue->drain_at_safepoint_priority();
532 } else {
533 safepoint_ops = NULL;
534 }
535 } while(safepoint_ops != NULL);
536
537 _vm_queue->set_drain_list(NULL);
538
539 // Complete safepoint synchronization
540 } SafepointSynchronize::end();
541
542 } else { // not a safepoint operation
543 if (TraceLongCompiles) {
544 elapsedTimer t;
545 t.start();
546 evaluate_operation(_cur_vm_operation);
547 t.stop();
548 double secs = t.seconds();
549 if (secs * 1e3 > LongCompileThreshold) {
550 // XXX - _cur_vm_operation should not be accessed after
551 // the completed count has been incremented; the waiting
552 // thread may have already freed this memory.
553 tty->print_cr("vm %s: %3.7f secs]", _cur_vm_operation->name(), secs);
554 }
555 } else {
556 evaluate_operation(_cur_vm_operation);
557 }
558
559 _cur_vm_operation = NULL;
560 }
|