0
|
1 /*
|
196
|
2 * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
|
0
|
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
|
|
25 # include "incls/_precompiled.incl"
|
|
26 # include "incls/_collectedHeap.cpp.incl"
|
|
27
|
|
28
|
|
29 #ifdef ASSERT
|
|
30 int CollectedHeap::_fire_out_of_memory_count = 0;
|
|
31 #endif
|
|
32
|
|
33 // Memory state functions.
|
|
34
|
|
35 CollectedHeap::CollectedHeap() :
|
|
36 _reserved(), _barrier_set(NULL), _is_gc_active(false),
|
|
37 _total_collections(0), _total_full_collections(0),
|
|
38 _gc_cause(GCCause::_no_gc), _gc_lastcause(GCCause::_no_gc) {
|
|
39 NOT_PRODUCT(_promotion_failure_alot_count = 0;)
|
|
40 NOT_PRODUCT(_promotion_failure_alot_gc_number = 0;)
|
|
41
|
|
42 if (UsePerfData) {
|
|
43 EXCEPTION_MARK;
|
|
44
|
|
45 // create the gc cause jvmstat counters
|
|
46 _perf_gc_cause = PerfDataManager::create_string_variable(SUN_GC, "cause",
|
|
47 80, GCCause::to_string(_gc_cause), CHECK);
|
|
48
|
|
49 _perf_gc_lastcause =
|
|
50 PerfDataManager::create_string_variable(SUN_GC, "lastCause",
|
|
51 80, GCCause::to_string(_gc_lastcause), CHECK);
|
|
52 }
|
|
53 }
|
|
54
|
|
55
|
|
56 #ifndef PRODUCT
|
|
57 void CollectedHeap::check_for_bad_heap_word_value(HeapWord* addr, size_t size) {
|
|
58 if (CheckMemoryInitialization && ZapUnusedHeapArea) {
|
|
59 for (size_t slot = 0; slot < size; slot += 1) {
|
|
60 assert((*(intptr_t*) (addr + slot)) != ((intptr_t) badHeapWordVal),
|
|
61 "Found badHeapWordValue in post-allocation check");
|
|
62 }
|
|
63 }
|
|
64 }
|
|
65
|
|
66 void CollectedHeap::check_for_non_bad_heap_word_value(HeapWord* addr, size_t size)
|
|
67 {
|
|
68 if (CheckMemoryInitialization && ZapUnusedHeapArea) {
|
|
69 for (size_t slot = 0; slot < size; slot += 1) {
|
|
70 assert((*(intptr_t*) (addr + slot)) == ((intptr_t) badHeapWordVal),
|
|
71 "Found non badHeapWordValue in pre-allocation check");
|
|
72 }
|
|
73 }
|
|
74 }
|
|
75 #endif // PRODUCT
|
|
76
|
|
77 #ifdef ASSERT
|
|
78 void CollectedHeap::check_for_valid_allocation_state() {
|
|
79 Thread *thread = Thread::current();
|
|
80 // How to choose between a pending exception and a potential
|
|
81 // OutOfMemoryError? Don't allow pending exceptions.
|
|
82 // This is a VM policy failure, so how do we exhaustively test it?
|
|
83 assert(!thread->has_pending_exception(),
|
|
84 "shouldn't be allocating with pending exception");
|
|
85 if (StrictSafepointChecks) {
|
|
86 assert(thread->allow_allocation(),
|
|
87 "Allocation done by thread for which allocation is blocked "
|
|
88 "by No_Allocation_Verifier!");
|
|
89 // Allocation of an oop can always invoke a safepoint,
|
|
90 // hence, the true argument
|
|
91 thread->check_for_valid_safepoint_state(true);
|
|
92 }
|
|
93 }
|
|
94 #endif
|
|
95
|
|
96 HeapWord* CollectedHeap::allocate_from_tlab_slow(Thread* thread, size_t size) {
|
|
97
|
|
98 // Retain tlab and allocate object in shared space if
|
|
99 // the amount free in the tlab is too large to discard.
|
|
100 if (thread->tlab().free() > thread->tlab().refill_waste_limit()) {
|
|
101 thread->tlab().record_slow_allocation(size);
|
|
102 return NULL;
|
|
103 }
|
|
104
|
|
105 // Discard tlab and allocate a new one.
|
|
106 // To minimize fragmentation, the last TLAB may be smaller than the rest.
|
|
107 size_t new_tlab_size = thread->tlab().compute_size(size);
|
|
108
|
|
109 thread->tlab().clear_before_allocation();
|
|
110
|
|
111 if (new_tlab_size == 0) {
|
|
112 return NULL;
|
|
113 }
|
|
114
|
|
115 // Allocate a new TLAB...
|
|
116 HeapWord* obj = Universe::heap()->allocate_new_tlab(new_tlab_size);
|
|
117 if (obj == NULL) {
|
|
118 return NULL;
|
|
119 }
|
|
120 if (ZeroTLAB) {
|
|
121 // ..and clear it.
|
|
122 Copy::zero_to_words(obj, new_tlab_size);
|
|
123 } else {
|
|
124 // ...and clear just the allocated object.
|
|
125 Copy::zero_to_words(obj, size);
|
|
126 }
|
|
127 thread->tlab().fill(obj, obj + size, new_tlab_size);
|
|
128 return obj;
|
|
129 }
|
|
130
|
|
131 oop CollectedHeap::new_store_barrier(oop new_obj) {
|
|
132 // %%% This needs refactoring. (It was imported from the server compiler.)
|
|
133 guarantee(can_elide_tlab_store_barriers(), "store barrier elision not supported");
|
|
134 BarrierSet* bs = this->barrier_set();
|
|
135 assert(bs->has_write_region_opt(), "Barrier set does not have write_region");
|
|
136 int new_size = new_obj->size();
|
|
137 bs->write_region(MemRegion((HeapWord*)new_obj, new_size));
|
|
138 return new_obj;
|
|
139 }
|
|
140
|
|
141 HeapWord* CollectedHeap::allocate_new_tlab(size_t size) {
|
|
142 guarantee(false, "thread-local allocation buffers not supported");
|
|
143 return NULL;
|
|
144 }
|
|
145
|
|
146 void CollectedHeap::fill_all_tlabs(bool retire) {
|
|
147 assert(UseTLAB, "should not reach here");
|
|
148 // See note in ensure_parsability() below.
|
|
149 assert(SafepointSynchronize::is_at_safepoint() ||
|
|
150 !is_init_completed(),
|
|
151 "should only fill tlabs at safepoint");
|
|
152 // The main thread starts allocating via a TLAB even before it
|
|
153 // has added itself to the threads list at vm boot-up.
|
|
154 assert(Threads::first() != NULL,
|
|
155 "Attempt to fill tlabs before main thread has been added"
|
|
156 " to threads list is doomed to failure!");
|
|
157 for(JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
|
|
158 thread->tlab().make_parsable(retire);
|
|
159 }
|
|
160 }
|
|
161
|
|
162 void CollectedHeap::ensure_parsability(bool retire_tlabs) {
|
|
163 // The second disjunct in the assertion below makes a concession
|
|
164 // for the start-up verification done while the VM is being
|
|
165 // created. Callers be careful that you know that mutators
|
|
166 // aren't going to interfere -- for instance, this is permissible
|
|
167 // if we are still single-threaded and have either not yet
|
|
168 // started allocating (nothing much to verify) or we have
|
|
169 // started allocating but are now a full-fledged JavaThread
|
|
170 // (and have thus made our TLAB's) available for filling.
|
|
171 assert(SafepointSynchronize::is_at_safepoint() ||
|
|
172 !is_init_completed(),
|
|
173 "Should only be called at a safepoint or at start-up"
|
|
174 " otherwise concurrent mutator activity may make heap "
|
|
175 " unparsable again");
|
|
176 if (UseTLAB) {
|
|
177 fill_all_tlabs(retire_tlabs);
|
|
178 }
|
|
179 }
|
|
180
|
|
181 void CollectedHeap::accumulate_statistics_all_tlabs() {
|
|
182 if (UseTLAB) {
|
|
183 assert(SafepointSynchronize::is_at_safepoint() ||
|
|
184 !is_init_completed(),
|
|
185 "should only accumulate statistics on tlabs at safepoint");
|
|
186
|
|
187 ThreadLocalAllocBuffer::accumulate_statistics_before_gc();
|
|
188 }
|
|
189 }
|
|
190
|
|
191 void CollectedHeap::resize_all_tlabs() {
|
|
192 if (UseTLAB) {
|
|
193 assert(SafepointSynchronize::is_at_safepoint() ||
|
|
194 !is_init_completed(),
|
|
195 "should only resize tlabs at safepoint");
|
|
196
|
|
197 ThreadLocalAllocBuffer::resize_all_tlabs();
|
|
198 }
|
|
199 }
|