annotate src/share/vm/memory/gcLocker.cpp @ 1972:f95d63e2154a

6989984: Use standard include model for Hospot Summary: Replaced MakeDeps and the includeDB files with more standardized solutions. Reviewed-by: coleenp, kvn, kamg
author stefank
date Tue, 23 Nov 2010 13:22:55 -0800
parents c18cbe5936b8
children 1a2723f7ad8e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 196
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
25 #include "precompiled.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
26 #include "memory/gcLocker.inline.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27 #include "memory/resourceArea.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "memory/sharedHeap.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
29
a61af66fc99e Initial load
duke
parents:
diff changeset
30 volatile jint GC_locker::_jni_lock_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 volatile jint GC_locker::_lock_count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
32 volatile bool GC_locker::_needs_gc = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 volatile bool GC_locker::_doing_gc = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
34
a61af66fc99e Initial load
duke
parents:
diff changeset
35 void GC_locker::stall_until_clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
36 assert(!JavaThread::current()->in_critical(), "Would deadlock");
139
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
37 if (PrintJNIGCStalls && PrintGCDetails) {
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
38 ResourceMark rm; // JavaThread::name() allocates to convert to UTF8
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
39 gclog_or_tty->print_cr(
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
40 "Allocation failed. Thread \"%s\" is stalled by JNI critical section.",
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
41 JavaThread::current()->name());
c0492d52d55b 6539517: CR 6186200 should be extended to perm gen allocation to prevent spurious OOM's from perm gen
apetrusenko
parents: 0
diff changeset
42 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
43 MutexLocker ml(JNICritical_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // Wait for _needs_gc to be cleared
a61af66fc99e Initial load
duke
parents:
diff changeset
45 while (GC_locker::needs_gc()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 JNICritical_lock->wait();
a61af66fc99e Initial load
duke
parents:
diff changeset
47 }
a61af66fc99e Initial load
duke
parents:
diff changeset
48 }
a61af66fc99e Initial load
duke
parents:
diff changeset
49
a61af66fc99e Initial load
duke
parents:
diff changeset
50 void GC_locker::jni_lock_slow() {
a61af66fc99e Initial load
duke
parents:
diff changeset
51 MutexLocker mu(JNICritical_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
52 // Block entering threads if we know at least one thread is in a
a61af66fc99e Initial load
duke
parents:
diff changeset
53 // JNI critical region and we need a GC.
a61af66fc99e Initial load
duke
parents:
diff changeset
54 // We check that at least one thread is in a critical region before
a61af66fc99e Initial load
duke
parents:
diff changeset
55 // blocking because blocked threads are woken up by a thread exiting
a61af66fc99e Initial load
duke
parents:
diff changeset
56 // a JNI critical region.
a61af66fc99e Initial load
duke
parents:
diff changeset
57 while ((is_jni_active() && needs_gc()) || _doing_gc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 JNICritical_lock->wait();
a61af66fc99e Initial load
duke
parents:
diff changeset
59 }
a61af66fc99e Initial load
duke
parents:
diff changeset
60 jni_lock();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 void GC_locker::jni_unlock_slow() {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 MutexLocker mu(JNICritical_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
65 jni_unlock();
a61af66fc99e Initial load
duke
parents:
diff changeset
66 if (needs_gc() && !is_jni_active()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 // We're the last thread out. Cause a GC to occur.
a61af66fc99e Initial load
duke
parents:
diff changeset
68 // GC will also check is_active, so this check is not
a61af66fc99e Initial load
duke
parents:
diff changeset
69 // strictly needed. It's added here to make it clear that
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // the GC will NOT be performed if any other caller
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // of GC_locker::lock() still needs GC locked.
a61af66fc99e Initial load
duke
parents:
diff changeset
72 if (!is_active()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 _doing_gc = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
74 {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 // Must give up the lock while at a safepoint
a61af66fc99e Initial load
duke
parents:
diff changeset
76 MutexUnlocker munlock(JNICritical_lock);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 Universe::heap()->collect(GCCause::_gc_locker);
a61af66fc99e Initial load
duke
parents:
diff changeset
78 }
a61af66fc99e Initial load
duke
parents:
diff changeset
79 _doing_gc = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 }
a61af66fc99e Initial load
duke
parents:
diff changeset
81 clear_needs_gc();
a61af66fc99e Initial load
duke
parents:
diff changeset
82 JNICritical_lock->notify_all();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84 }
a61af66fc99e Initial load
duke
parents:
diff changeset
85
a61af66fc99e Initial load
duke
parents:
diff changeset
86 // Implementation of No_GC_Verifier
a61af66fc99e Initial load
duke
parents:
diff changeset
87
a61af66fc99e Initial load
duke
parents:
diff changeset
88 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
89
a61af66fc99e Initial load
duke
parents:
diff changeset
90 No_GC_Verifier::No_GC_Verifier(bool verifygc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 _verifygc = verifygc;
a61af66fc99e Initial load
duke
parents:
diff changeset
92 if (_verifygc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
93 CollectedHeap* h = Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 assert(!h->is_gc_active(), "GC active during No_GC_Verifier");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 _old_invocations = h->total_collections();
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 No_GC_Verifier::~No_GC_Verifier() {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 if (_verifygc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 CollectedHeap* h = Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 assert(!h->is_gc_active(), "GC active during No_GC_Verifier");
a61af66fc99e Initial load
duke
parents:
diff changeset
104 if (_old_invocations != h->total_collections()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
105 fatal("collection in a No_GC_Verifier secured function");
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107 }
a61af66fc99e Initial load
duke
parents:
diff changeset
108 }
a61af66fc99e Initial load
duke
parents:
diff changeset
109
a61af66fc99e Initial load
duke
parents:
diff changeset
110 Pause_No_GC_Verifier::Pause_No_GC_Verifier(No_GC_Verifier * ngcv) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 _ngcv = ngcv;
a61af66fc99e Initial load
duke
parents:
diff changeset
112 if (_ngcv->_verifygc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
113 // if we were verifying, then make sure that nothing is
a61af66fc99e Initial load
duke
parents:
diff changeset
114 // wrong before we "pause" verification
a61af66fc99e Initial load
duke
parents:
diff changeset
115 CollectedHeap* h = Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 assert(!h->is_gc_active(), "GC active during No_GC_Verifier");
a61af66fc99e Initial load
duke
parents:
diff changeset
117 if (_ngcv->_old_invocations != h->total_collections()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
118 fatal("collection in a No_GC_Verifier secured function");
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 }
a61af66fc99e Initial load
duke
parents:
diff changeset
121 }
a61af66fc99e Initial load
duke
parents:
diff changeset
122
a61af66fc99e Initial load
duke
parents:
diff changeset
123
a61af66fc99e Initial load
duke
parents:
diff changeset
124 Pause_No_GC_Verifier::~Pause_No_GC_Verifier() {
a61af66fc99e Initial load
duke
parents:
diff changeset
125 if (_ngcv->_verifygc) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 // if we were verifying before, then reenable verification
a61af66fc99e Initial load
duke
parents:
diff changeset
127 CollectedHeap* h = Universe::heap();
a61af66fc99e Initial load
duke
parents:
diff changeset
128 assert(!h->is_gc_active(), "GC active during No_GC_Verifier");
a61af66fc99e Initial load
duke
parents:
diff changeset
129 _ngcv->_old_invocations = h->total_collections();
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // JRT_LEAF rules:
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // A JRT_LEAF method may not interfere with safepointing by
a61af66fc99e Initial load
duke
parents:
diff changeset
136 // 1) acquiring or blocking on a Mutex or JavaLock - checked
a61af66fc99e Initial load
duke
parents:
diff changeset
137 // 2) allocating heap memory - checked
a61af66fc99e Initial load
duke
parents:
diff changeset
138 // 3) executing a VM operation - checked
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // 4) executing a system call (including malloc) that could block or grab a lock
a61af66fc99e Initial load
duke
parents:
diff changeset
140 // 5) invoking GC
a61af66fc99e Initial load
duke
parents:
diff changeset
141 // 6) reaching a safepoint
a61af66fc99e Initial load
duke
parents:
diff changeset
142 // 7) running too long
a61af66fc99e Initial load
duke
parents:
diff changeset
143 // Nor may any method it calls.
a61af66fc99e Initial load
duke
parents:
diff changeset
144 JRT_Leaf_Verifier::JRT_Leaf_Verifier()
a61af66fc99e Initial load
duke
parents:
diff changeset
145 : No_Safepoint_Verifier(true, JRT_Leaf_Verifier::should_verify_GC())
a61af66fc99e Initial load
duke
parents:
diff changeset
146 {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148
a61af66fc99e Initial load
duke
parents:
diff changeset
149 JRT_Leaf_Verifier::~JRT_Leaf_Verifier()
a61af66fc99e Initial load
duke
parents:
diff changeset
150 {
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152
a61af66fc99e Initial load
duke
parents:
diff changeset
153 bool JRT_Leaf_Verifier::should_verify_GC() {
a61af66fc99e Initial load
duke
parents:
diff changeset
154 switch (JavaThread::current()->thread_state()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
155 case _thread_in_Java:
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // is in a leaf routine, there must be no safepoint.
a61af66fc99e Initial load
duke
parents:
diff changeset
157 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
158 case _thread_in_native:
a61af66fc99e Initial load
duke
parents:
diff changeset
159 // A native thread is not subject to safepoints.
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Even while it is in a leaf routine, GC is ok
a61af66fc99e Initial load
duke
parents:
diff changeset
161 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Leaf routines cannot be called from other contexts.
a61af66fc99e Initial load
duke
parents:
diff changeset
164 ShouldNotReachHere();
a61af66fc99e Initial load
duke
parents:
diff changeset
165 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
166 }
a61af66fc99e Initial load
duke
parents:
diff changeset
167 }
a61af66fc99e Initial load
duke
parents:
diff changeset
168 #endif