1.1 --- a/src/share/vm/runtime/safepoint.cpp Thu Jan 26 19:39:08 2012 -0800 1.2 +++ b/src/share/vm/runtime/safepoint.cpp Sun Jan 29 16:46:04 2012 -0800 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -95,6 +95,7 @@ 1.11 SafepointSynchronize::SynchronizeState volatile SafepointSynchronize::_state = SafepointSynchronize::_not_synchronized; 1.12 volatile int SafepointSynchronize::_waiting_to_block = 0; 1.13 volatile int SafepointSynchronize::_safepoint_counter = 0; 1.14 +int SafepointSynchronize::_current_jni_active_count = 0; 1.15 long SafepointSynchronize::_end_of_last_safepoint = 0; 1.16 static volatile int PageArmed = 0 ; // safepoint polling page is RO|RW vs PROT_NONE 1.17 static volatile int TryingToBlock = 0 ; // proximate value -- for advisory use only 1.18 @@ -138,6 +139,9 @@ 1.19 { 1.20 MutexLocker mu(Safepoint_lock); 1.21 1.22 + // Reset the count of active JNI critical threads 1.23 + _current_jni_active_count = 0; 1.24 + 1.25 // Set number of threads to wait for, before we initiate the callbacks 1.26 _waiting_to_block = nof_threads; 1.27 TryingToBlock = 0 ; 1.28 @@ -375,6 +379,9 @@ 1.29 1.30 OrderAccess::fence(); 1.31 1.32 + // Update the count of active JNI critical regions 1.33 + GC_locker::set_jni_lock_count(_current_jni_active_count); 1.34 + 1.35 if (TraceSafepoint) { 1.36 VM_Operation *op = VMThread::vm_operation(); 1.37 tty->print_cr("Entering safepoint region: %s", (op != NULL) ? op->name() : "no vm operation"); 1.38 @@ -585,6 +592,11 @@ 1.39 _waiting_to_block--; 1.40 thread->safepoint_state()->set_has_called_back(true); 1.41 1.42 + if (thread->in_critical()) { 1.43 + // Notice that this thread is in a critical section 1.44 + increment_jni_active_count(); 1.45 + } 1.46 + 1.47 // Consider (_waiting_to_block < 2) to pipeline the wakeup of the VM thread 1.48 if (_waiting_to_block == 0) { 1.49 Safepoint_lock->notify_all(); 1.50 @@ -861,8 +873,12 @@ 1.51 // running, but are actually at a safepoint. We will happily 1.52 // agree and update the safepoint state here. 1.53 if (SafepointSynchronize::safepoint_safe(_thread, state)) { 1.54 - roll_forward(_at_safepoint); 1.55 - return; 1.56 + roll_forward(_at_safepoint); 1.57 + if (_thread->in_critical()) { 1.58 + // Notice that this thread is in a critical section 1.59 + SafepointSynchronize::increment_jni_active_count(); 1.60 + } 1.61 + return; 1.62 } 1.63 1.64 if (state == _thread_in_vm) {