comparison src/share/vm/runtime/safepoint.cpp @ 4875:379b22e03c32

Merge
author jcoomes
date Fri, 03 Feb 2012 12:08:55 -0800
parents 0382d2b469b2
children 0ebca2e35ca5 541c4a5e7b88
comparison
equal deleted inserted replaced
4866:527cf36f4a20 4875:379b22e03c32
1 /* 1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
93 // Implementation of Safepoint begin/end 93 // Implementation of Safepoint begin/end
94 94
95 SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized; 95 SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized;
96 volatile int SafepointSynchronize::_waiting_to_block = 0; 96 volatile int SafepointSynchronize::_waiting_to_block = 0;
97 volatile int SafepointSynchronize::_safepoint_counter = 0; 97 volatile int SafepointSynchronize::_safepoint_counter = 0;
98 int SafepointSynchronize::_current_jni_active_count = 0;
98 long SafepointSynchronize::_end_of_last_safepoint = 0; 99 long SafepointSynchronize::_end_of_last_safepoint = 0;
99 static volatile int PageArmed = 0 ; // safepoint polling page is RO|RW vs PROT_NONE 100 static volatile int PageArmed = 0 ; // safepoint polling page is RO|RW vs PROT_NONE
100 static volatile int TryingToBlock = 0 ; // proximate value -- for advisory use only 101 static volatile int TryingToBlock = 0 ; // proximate value -- for advisory use only
101 static bool timeout_error_printed = false; 102 static bool timeout_error_printed = false;
102 103
133 tty->print_cr("Safepoint synchronization initiated. (%d)", nof_threads); 134 tty->print_cr("Safepoint synchronization initiated. (%d)", nof_threads);
134 } 135 }
135 136
136 RuntimeService::record_safepoint_begin(); 137 RuntimeService::record_safepoint_begin();
137 138
138 {
139 MutexLocker mu(Safepoint_lock); 139 MutexLocker mu(Safepoint_lock);
140
141 // Reset the count of active JNI critical threads
142 _current_jni_active_count = 0;
140 143
141 // Set number of threads to wait for, before we initiate the callbacks 144 // Set number of threads to wait for, before we initiate the callbacks
142 _waiting_to_block = nof_threads; 145 _waiting_to_block = nof_threads;
143 TryingToBlock = 0 ; 146 TryingToBlock = 0 ;
144 int still_running = nof_threads; 147 int still_running = nof_threads;
373 // Record state 376 // Record state
374 _state = _synchronized; 377 _state = _synchronized;
375 378
376 OrderAccess::fence(); 379 OrderAccess::fence();
377 380
381 // Update the count of active JNI critical regions
382 GC_locker::set_jni_lock_count(_current_jni_active_count);
383
378 if (TraceSafepoint) { 384 if (TraceSafepoint) {
379 VM_Operation *op = VMThread::vm_operation(); 385 VM_Operation *op = VMThread::vm_operation();
380 tty->print_cr("Entering safepoint region: %s", (op != NULL) ? op->name() : "no vm operation"); 386 tty->print_cr("Entering safepoint region: %s", (op != NULL) ? op->name() : "no vm operation");
381 } 387 }
382 388
389 do_cleanup_tasks(); 395 do_cleanup_tasks();
390 396
391 if (PrintSafepointStatistics) { 397 if (PrintSafepointStatistics) {
392 // Record how much time spend on the above cleanup tasks 398 // Record how much time spend on the above cleanup tasks
393 update_statistics_on_cleanup_end(os::javaTimeNanos()); 399 update_statistics_on_cleanup_end(os::javaTimeNanos());
394 }
395 } 400 }
396 } 401 }
397 402
398 // Wake up all threads, so they are ready to resume execution after the safepoint 403 // Wake up all threads, so they are ready to resume execution after the safepoint
399 // operation has been carried out 404 // operation has been carried out
537 return false; 542 return false;
538 } 543 }
539 } 544 }
540 545
541 546
547 // See if the thread is running inside a lazy critical native and
548 // update the thread critical count if so. Also set a suspend flag to
549 // cause the native wrapper to return into the JVM to do the unlock
550 // once the native finishes.
551 void SafepointSynchronize::check_for_lazy_critical_native(JavaThread *thread, JavaThreadState state) {
552 if (state == _thread_in_native &&
553 thread->has_last_Java_frame() &&
554 thread->frame_anchor()->walkable()) {
555 // This thread might be in a critical native nmethod so look at
556 // the top of the stack and increment the critical count if it
557 // is.
558 frame wrapper_frame = thread->last_frame();
559 CodeBlob* stub_cb = wrapper_frame.cb();
560 if (stub_cb != NULL &&
561 stub_cb->is_nmethod() &&
562 stub_cb->as_nmethod_or_null()->is_lazy_critical_native()) {
563 // A thread could potentially be in a critical native across
564 // more than one safepoint, so only update the critical state on
565 // the first one. When it returns it will perform the unlock.
566 if (!thread->do_critical_native_unlock()) {
567 #ifdef ASSERT
568 if (!thread->in_critical()) {
569 GC_locker::increment_debug_jni_lock_count();
570 }
571 #endif
572 thread->enter_critical();
573 // Make sure the native wrapper calls back on return to
574 // perform the needed critical unlock.
575 thread->set_critical_native_unlock();
576 }
577 }
578 }
579 }
580
581
582
542 // ------------------------------------------------------------------------------------------------------- 583 // -------------------------------------------------------------------------------------------------------
543 // Implementation of Safepoint callback point 584 // Implementation of Safepoint callback point
544 585
545 void SafepointSynchronize::block(JavaThread *thread) { 586 void SafepointSynchronize::block(JavaThread *thread) {
546 assert(thread != NULL, "thread must be set"); 587 assert(thread != NULL, "thread must be set");
582 if (is_synchronizing()) { 623 if (is_synchronizing()) {
583 // Decrement the number of threads to wait for and signal vm thread 624 // Decrement the number of threads to wait for and signal vm thread
584 assert(_waiting_to_block > 0, "sanity check"); 625 assert(_waiting_to_block > 0, "sanity check");
585 _waiting_to_block--; 626 _waiting_to_block--;
586 thread->safepoint_state()->set_has_called_back(true); 627 thread->safepoint_state()->set_has_called_back(true);
628
629 if (thread->in_critical()) {
630 // Notice that this thread is in a critical section
631 increment_jni_active_count();
632 }
587 633
588 // Consider (_waiting_to_block < 2) to pipeline the wakeup of the VM thread 634 // Consider (_waiting_to_block < 2) to pipeline the wakeup of the VM thread
589 if (_waiting_to_block == 0) { 635 if (_waiting_to_block == 0) {
590 Safepoint_lock->notify_all(); 636 Safepoint_lock->notify_all();
591 } 637 }
859 905
860 // Some JavaThread states have an initial safepoint state of 906 // Some JavaThread states have an initial safepoint state of
861 // running, but are actually at a safepoint. We will happily 907 // running, but are actually at a safepoint. We will happily
862 // agree and update the safepoint state here. 908 // agree and update the safepoint state here.
863 if (SafepointSynchronize::safepoint_safe(_thread, state)) { 909 if (SafepointSynchronize::safepoint_safe(_thread, state)) {
864 roll_forward(_at_safepoint); 910 roll_forward(_at_safepoint);
865 return; 911 SafepointSynchronize::check_for_lazy_critical_native(_thread, state);
912 if (_thread->in_critical()) {
913 // Notice that this thread is in a critical section
914 SafepointSynchronize::increment_jni_active_count();
915 }
916 return;
866 } 917 }
867 918
868 if (state == _thread_in_vm) { 919 if (state == _thread_in_vm) {
869 roll_forward(_call_back); 920 roll_forward(_call_back);
870 return; 921 return;