1 /*
2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
218 return result;
219 } else {
220 // If there's not enough expansion space available, give up.
221 if (_virtual_space.uncommitted_size() < byte_size) {
222 return NULL;
223 }
224 // else try again
225 }
226 }
227 } else {
228 expand(word_size*HeapWordSize, _min_heap_delta_bytes);
229 return _the_space->allocate(word_size);
230 }
231 }
232
233 bool TenuredGeneration::expand(size_t bytes, size_t expand_bytes) {
234 GCMutexLocker x(ExpandHeap_lock);
235 return CardGeneration::expand(bytes, expand_bytes);
236 }
237
238
239 void TenuredGeneration::shrink(size_t bytes) {
240 assert_locked_or_safepoint(ExpandHeap_lock);
241 size_t size = ReservedSpace::page_align_size_down(bytes);
242 if (size > 0) {
243 shrink_by(size);
244 }
245 }
246
247
248 size_t TenuredGeneration::capacity() const {
249 return _the_space->capacity();
250 }
251
252
253 size_t TenuredGeneration::used() const {
254 return _the_space->used();
255 }
256
257
258 size_t TenuredGeneration::free() const {
259 return _the_space->free();
260 }
261
262 MemRegion TenuredGeneration::used_region() const {
263 return the_space()->used_region();
264 }
265
266 size_t TenuredGeneration::unsafe_max_alloc_nogc() const {
267 return _the_space->free();
268 }
269
270 size_t TenuredGeneration::contiguous_available() const {
271 return _the_space->free() + _virtual_space.uncommitted_size();
272 }
273
274 bool TenuredGeneration::grow_by(size_t bytes) {
275 assert_locked_or_safepoint(ExpandHeap_lock);
276 bool result = _virtual_space.expand_by(bytes);
277 if (result) {
278 size_t new_word_size =
279 heap_word_size(_virtual_space.committed_size());
280 MemRegion mr(_the_space->bottom(), new_word_size);
281 // Expand card table
282 Universe::heap()->barrier_set()->resize_covered_region(mr);
283 // Expand shared block offset array
284 _bts->resize(new_word_size);
285
286 // Fix for bug #4668531
287 if (ZapUnusedHeapArea) {
288 MemRegion mangle_region(_the_space->end(),
289 (HeapWord*)_virtual_space.high());
290 SpaceMangler::mangle_region(mangle_region);
291 }
292
293 // Expand space -- also expands space's BOT
294 // (which uses (part of) shared array above)
295 _the_space->set_end((HeapWord*)_virtual_space.high());
296
297 // update the space and generation capacity counters
298 update_counters();
299
300 if (Verbose && PrintGC) {
301 size_t new_mem_size = _virtual_space.committed_size();
302 size_t old_mem_size = new_mem_size - bytes;
303 gclog_or_tty->print_cr("Expanding %s from " SIZE_FORMAT "K by "
304 SIZE_FORMAT "K to " SIZE_FORMAT "K",
305 name(), old_mem_size/K, bytes/K, new_mem_size/K);
306 }
307 }
308 return result;
309 }
310
311
312 bool TenuredGeneration::grow_to_reserved() {
313 assert_locked_or_safepoint(ExpandHeap_lock);
314 bool success = true;
315 const size_t remaining_bytes = _virtual_space.uncommitted_size();
316 if (remaining_bytes > 0) {
317 success = grow_by(remaining_bytes);
318 DEBUG_ONLY(if (!success) warning("grow to reserved failed");)
319 }
320 return success;
321 }
322
323 void TenuredGeneration::shrink_by(size_t bytes) {
324 assert_locked_or_safepoint(ExpandHeap_lock);
325 // Shrink committed space
326 _virtual_space.shrink_by(bytes);
327 // Shrink space; this also shrinks the space's BOT
328 _the_space->set_end((HeapWord*) _virtual_space.high());
329 size_t new_word_size = heap_word_size(_the_space->capacity());
330 // Shrink the shared block offset array
331 _bts->resize(new_word_size);
332 MemRegion mr(_the_space->bottom(), new_word_size);
333 // Shrink the card table
334 Universe::heap()->barrier_set()->resize_covered_region(mr);
335
336 if (Verbose && PrintGC) {
337 size_t new_mem_size = _virtual_space.committed_size();
338 size_t old_mem_size = new_mem_size + bytes;
339 gclog_or_tty->print_cr("Shrinking %s from " SIZE_FORMAT "K to " SIZE_FORMAT "K",
340 name(), old_mem_size/K, new_mem_size/K);
341 }
342 }
343
344 // Currently nothing to do.
345 void TenuredGeneration::prepare_for_verify() {}
346
347 void TenuredGeneration::object_iterate(ObjectClosure* blk) {
348 _the_space->object_iterate(blk);
349 }
350
351 void TenuredGeneration::space_iterate(SpaceClosure* blk,
352 bool usedOnly) {
353 blk->do_space(_the_space);
354 }
355
356 void TenuredGeneration::younger_refs_iterate(OopsInGenClosure* blk) {
357 blk->set_generation(this);
358 younger_refs_in_space_iterate(_the_space, blk);
359 blk->reset_generation();
360 }
361
362 void TenuredGeneration::save_marks() {
363 _the_space->set_saved_mark();
364 }
365
366
367 void TenuredGeneration::reset_saved_marks() {
368 _the_space->reset_saved_mark();
369 }
370
371
372 bool TenuredGeneration::no_allocs_since_save_marks() {
373 return _the_space->saved_mark_at_top();
374 }
375
376 #define TenuredGen_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix) \
377 \
378 void TenuredGeneration:: \
379 oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \
380 blk->set_generation(this); \
381 _the_space->oop_since_save_marks_iterate##nv_suffix(blk); \
382 blk->reset_generation(); \
383 save_marks(); \
384 }
385
386 ALL_SINCE_SAVE_MARKS_CLOSURES(TenuredGen_SINCE_SAVE_MARKS_ITERATE_DEFN)
387
388 #undef TenuredGen_SINCE_SAVE_MARKS_ITERATE_DEFN
389
390
391 void TenuredGeneration::gc_epilogue(bool full) {
392 // update the generation and space performance counters
393 update_counters();
394 if (ZapUnusedHeapArea) {
395 the_space()->check_mangled_unused_area_complete();
396 }
397 }
398
399 void TenuredGeneration::record_spaces_top() {
400 assert(ZapUnusedHeapArea, "Not mangling unused space");
401 the_space()->set_top_for_allocations();
402 }
403
404 void TenuredGeneration::verify() {
405 the_space()->verify();
406 }
407
408 void TenuredGeneration::print_on(outputStream* st) const {
409 Generation::print_on(st);
410 st->print(" the");
411 the_space()->print_on(st);
412 }
|
1 /*
2 * Copyright (c) 2001, 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
218 return result;
219 } else {
220 // If there's not enough expansion space available, give up.
221 if (_virtual_space.uncommitted_size() < byte_size) {
222 return NULL;
223 }
224 // else try again
225 }
226 }
227 } else {
228 expand(word_size*HeapWordSize, _min_heap_delta_bytes);
229 return _the_space->allocate(word_size);
230 }
231 }
232
233 bool TenuredGeneration::expand(size_t bytes, size_t expand_bytes) {
234 GCMutexLocker x(ExpandHeap_lock);
235 return CardGeneration::expand(bytes, expand_bytes);
236 }
237
238 size_t TenuredGeneration::unsafe_max_alloc_nogc() const {
239 return _the_space->free();
240 }
241
242 size_t TenuredGeneration::contiguous_available() const {
243 return _the_space->free() + _virtual_space.uncommitted_size();
244 }
245
246 void TenuredGeneration::assert_correct_size_change_locking() {
247 assert_locked_or_safepoint(ExpandHeap_lock);
248 }
249
250 // Currently nothing to do.
251 void TenuredGeneration::prepare_for_verify() {}
252
253 void TenuredGeneration::object_iterate(ObjectClosure* blk) {
254 _the_space->object_iterate(blk);
255 }
256
257 void TenuredGeneration::save_marks() {
258 _the_space->set_saved_mark();
259 }
260
261
262 void TenuredGeneration::reset_saved_marks() {
263 _the_space->reset_saved_mark();
264 }
265
266
267 bool TenuredGeneration::no_allocs_since_save_marks() {
268 return _the_space->saved_mark_at_top();
269 }
270
271 #define TenuredGen_SINCE_SAVE_MARKS_ITERATE_DEFN(OopClosureType, nv_suffix) \
272 \
273 void TenuredGeneration:: \
274 oop_since_save_marks_iterate##nv_suffix(OopClosureType* blk) { \
275 blk->set_generation(this); \
276 _the_space->oop_since_save_marks_iterate##nv_suffix(blk); \
277 blk->reset_generation(); \
278 save_marks(); \
279 }
280
281 ALL_SINCE_SAVE_MARKS_CLOSURES(TenuredGen_SINCE_SAVE_MARKS_ITERATE_DEFN)
282
283 #undef TenuredGen_SINCE_SAVE_MARKS_ITERATE_DEFN
284
285
286 void TenuredGeneration::gc_epilogue(bool full) {
287 // update the generation and space performance counters
288 update_counters();
289 if (ZapUnusedHeapArea) {
290 _the_space->check_mangled_unused_area_complete();
291 }
292 }
293
294 void TenuredGeneration::record_spaces_top() {
295 assert(ZapUnusedHeapArea, "Not mangling unused space");
296 _the_space->set_top_for_allocations();
297 }
298
299 void TenuredGeneration::verify() {
300 _the_space->verify();
301 }
302
303 void TenuredGeneration::print_on(outputStream* st) const {
304 Generation::print_on(st);
305 st->print(" the");
306 _the_space->print_on(st);
307 }
|