Mercurial > hg > truffle
comparison src/share/vm/runtime/safepoint.cpp @ 4867:1a2723f7ad8e
7129164: JNI Get/ReleasePrimitiveArrayCritical doesn't scale
Reviewed-by: kvn, iveresov, dholmes
author | never |
---|---|
date | Sun, 29 Jan 2012 16:46:04 -0800 |
parents | f08d439fab8c |
children | 0382d2b469b2 |
comparison
equal
deleted
inserted
replaced
4826:072384a61312 | 4867:1a2723f7ad8e |
---|---|
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 |
135 | 136 |
136 RuntimeService::record_safepoint_begin(); | 137 RuntimeService::record_safepoint_begin(); |
137 | 138 |
138 { | 139 { |
139 MutexLocker mu(Safepoint_lock); | 140 MutexLocker mu(Safepoint_lock); |
141 | |
142 // Reset the count of active JNI critical threads | |
143 _current_jni_active_count = 0; | |
140 | 144 |
141 // Set number of threads to wait for, before we initiate the callbacks | 145 // Set number of threads to wait for, before we initiate the callbacks |
142 _waiting_to_block = nof_threads; | 146 _waiting_to_block = nof_threads; |
143 TryingToBlock = 0 ; | 147 TryingToBlock = 0 ; |
144 int still_running = nof_threads; | 148 int still_running = nof_threads; |
373 // Record state | 377 // Record state |
374 _state = _synchronized; | 378 _state = _synchronized; |
375 | 379 |
376 OrderAccess::fence(); | 380 OrderAccess::fence(); |
377 | 381 |
382 // Update the count of active JNI critical regions | |
383 GC_locker::set_jni_lock_count(_current_jni_active_count); | |
384 | |
378 if (TraceSafepoint) { | 385 if (TraceSafepoint) { |
379 VM_Operation *op = VMThread::vm_operation(); | 386 VM_Operation *op = VMThread::vm_operation(); |
380 tty->print_cr("Entering safepoint region: %s", (op != NULL) ? op->name() : "no vm operation"); | 387 tty->print_cr("Entering safepoint region: %s", (op != NULL) ? op->name() : "no vm operation"); |
381 } | 388 } |
382 | 389 |
582 if (is_synchronizing()) { | 589 if (is_synchronizing()) { |
583 // Decrement the number of threads to wait for and signal vm thread | 590 // Decrement the number of threads to wait for and signal vm thread |
584 assert(_waiting_to_block > 0, "sanity check"); | 591 assert(_waiting_to_block > 0, "sanity check"); |
585 _waiting_to_block--; | 592 _waiting_to_block--; |
586 thread->safepoint_state()->set_has_called_back(true); | 593 thread->safepoint_state()->set_has_called_back(true); |
594 | |
595 if (thread->in_critical()) { | |
596 // Notice that this thread is in a critical section | |
597 increment_jni_active_count(); | |
598 } | |
587 | 599 |
588 // Consider (_waiting_to_block < 2) to pipeline the wakeup of the VM thread | 600 // Consider (_waiting_to_block < 2) to pipeline the wakeup of the VM thread |
589 if (_waiting_to_block == 0) { | 601 if (_waiting_to_block == 0) { |
590 Safepoint_lock->notify_all(); | 602 Safepoint_lock->notify_all(); |
591 } | 603 } |
859 | 871 |
860 // Some JavaThread states have an initial safepoint state of | 872 // Some JavaThread states have an initial safepoint state of |
861 // running, but are actually at a safepoint. We will happily | 873 // running, but are actually at a safepoint. We will happily |
862 // agree and update the safepoint state here. | 874 // agree and update the safepoint state here. |
863 if (SafepointSynchronize::safepoint_safe(_thread, state)) { | 875 if (SafepointSynchronize::safepoint_safe(_thread, state)) { |
864 roll_forward(_at_safepoint); | 876 roll_forward(_at_safepoint); |
865 return; | 877 if (_thread->in_critical()) { |
878 // Notice that this thread is in a critical section | |
879 SafepointSynchronize::increment_jni_active_count(); | |
880 } | |
881 return; | |
866 } | 882 } |
867 | 883 |
868 if (state == _thread_in_vm) { | 884 if (state == _thread_in_vm) { |
869 roll_forward(_call_back); | 885 roll_forward(_call_back); |
870 return; | 886 return; |