1
|
1 |
/*
|
|
2 |
* Copyright 2005-2006 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
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
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
# include "incls/_precompiled.incl"
|
|
25 |
# include "incls/_vmGCOperations.cpp.incl"
|
|
26 |
|
|
27 |
HS_DTRACE_PROBE_DECL1(hotspot, gc__begin, bool);
|
|
28 |
HS_DTRACE_PROBE_DECL(hotspot, gc__end);
|
|
29 |
|
|
30 |
// The same dtrace probe can't be inserted in two different files, so we
|
|
31 |
// have to call it here, so it's only in one file. Can't create new probes
|
|
32 |
// for the other file anymore. The dtrace probes have to remain stable.
|
|
33 |
void VM_GC_Operation::notify_gc_begin(bool full) {
|
|
34 |
HS_DTRACE_PROBE1(hotspot, gc__begin, full);
|
|
35 |
}
|
|
36 |
|
|
37 |
void VM_GC_Operation::notify_gc_end() {
|
|
38 |
HS_DTRACE_PROBE(hotspot, gc__end);
|
|
39 |
}
|
|
40 |
|
|
41 |
void VM_GC_Operation::acquire_pending_list_lock() {
|
|
42 |
// we may enter this with pending exception set
|
|
43 |
instanceRefKlass::acquire_pending_list_lock(&_pending_list_basic_lock);
|
|
44 |
}
|
|
45 |
|
|
46 |
|
|
47 |
void VM_GC_Operation::release_and_notify_pending_list_lock() {
|
|
48 |
|
|
49 |
instanceRefKlass::release_and_notify_pending_list_lock(&_pending_list_basic_lock);
|
|
50 |
}
|
|
51 |
|
|
52 |
// Allocations may fail in several threads at about the same time,
|
|
53 |
// resulting in multiple gc requests. We only want to do one of them.
|
|
54 |
// In case a GC locker is active and the need for a GC is already signalled,
|
|
55 |
// we want to skip this GC attempt altogether, without doing a futile
|
|
56 |
// safepoint operation.
|
|
57 |
bool VM_GC_Operation::skip_operation() const {
|
|
58 |
bool skip = (_gc_count_before != Universe::heap()->total_collections());
|
|
59 |
if (_full && skip) {
|
|
60 |
skip = (_full_gc_count_before != Universe::heap()->total_full_collections());
|
|
61 |
}
|
|
62 |
if (!skip && GC_locker::is_active_and_needs_gc()) {
|
|
63 |
skip = Universe::heap()->is_maximal_no_gc();
|
|
64 |
assert(!(skip && (_gc_cause == GCCause::_gc_locker)),
|
|
65 |
"GC_locker cannot be active when initiating GC");
|
|
66 |
}
|
|
67 |
return skip;
|
|
68 |
}
|
|
69 |
|
|
70 |
bool VM_GC_Operation::doit_prologue() {
|
|
71 |
assert(Thread::current()->is_Java_thread(), "just checking");
|
|
72 |
|
|
73 |
acquire_pending_list_lock();
|
|
74 |
// If the GC count has changed someone beat us to the collection
|
|
75 |
// Get the Heap_lock after the pending_list_lock.
|
|
76 |
Heap_lock->lock();
|
|
77 |
// Check invocations
|
|
78 |
if (skip_operation()) {
|
|
79 |
// skip collection
|
|
80 |
Heap_lock->unlock();
|
|
81 |
release_and_notify_pending_list_lock();
|
|
82 |
_prologue_succeeded = false;
|
|
83 |
} else {
|
|
84 |
_prologue_succeeded = true;
|
|
85 |
}
|
|
86 |
return _prologue_succeeded;
|
|
87 |
}
|
|
88 |
|
|
89 |
|
|
90 |
void VM_GC_Operation::doit_epilogue() {
|
|
91 |
assert(Thread::current()->is_Java_thread(), "just checking");
|
|
92 |
// Release the Heap_lock first.
|
|
93 |
Heap_lock->unlock();
|
|
94 |
release_and_notify_pending_list_lock();
|
|
95 |
}
|
|
96 |
|
|
97 |
bool VM_GC_HeapInspection::doit_prologue() {
|
|
98 |
if (Universe::heap()->supports_heap_inspection()) {
|
|
99 |
return VM_GC_Operation::doit_prologue();
|
|
100 |
} else {
|
|
101 |
return false;
|
|
102 |
}
|
|
103 |
}
|
|
104 |
|
|
105 |
bool VM_GC_HeapInspection::skip_operation() const {
|
|
106 |
assert(Universe::heap()->supports_heap_inspection(), "huh?");
|
|
107 |
return false;
|
|
108 |
}
|
|
109 |
|
|
110 |
void VM_GC_HeapInspection::doit() {
|
|
111 |
HandleMark hm;
|
|
112 |
CollectedHeap* ch = Universe::heap();
|
|
113 |
if (_full_gc) {
|
|
114 |
ch->collect_as_vm_thread(GCCause::_heap_inspection);
|
|
115 |
} else {
|
|
116 |
// make the heap parsable (no need to retire TLABs)
|
|
117 |
ch->ensure_parsability(false);
|
|
118 |
}
|
|
119 |
HeapInspection::heap_inspection(_out);
|
|
120 |
}
|
|
121 |
|
|
122 |
|
|
123 |
void VM_GenCollectForAllocation::doit() {
|
|
124 |
JvmtiGCForAllocationMarker jgcm;
|
|
125 |
notify_gc_begin(false);
|
|
126 |
|
|
127 |
GenCollectedHeap* gch = GenCollectedHeap::heap();
|
|
128 |
GCCauseSetter gccs(gch, _gc_cause);
|
|
129 |
_res = gch->satisfy_failed_allocation(_size, _tlab);
|
|
130 |
assert(gch->is_in_reserved_or_null(_res), "result not in heap");
|
|
131 |
|
|
132 |
if (_res == NULL && GC_locker::is_active_and_needs_gc()) {
|
|
133 |
set_gc_locked();
|
|
134 |
}
|
|
135 |
notify_gc_end();
|
|
136 |
}
|
|
137 |
|
|
138 |
void VM_GenCollectFull::doit() {
|
|
139 |
JvmtiGCFullMarker jgcm;
|
|
140 |
notify_gc_begin(true);
|
|
141 |
|
|
142 |
GenCollectedHeap* gch = GenCollectedHeap::heap();
|
|
143 |
GCCauseSetter gccs(gch, _gc_cause);
|
|
144 |
gch->do_full_collection(gch->must_clear_all_soft_refs(), _max_level);
|
|
145 |
notify_gc_end();
|
|
146 |
}
|