src/share/vm/gc_implementation/shared/mutableSpace.cpp

Mon, 09 Jun 2008 07:18:59 -0700

author
iveresov
date
Mon, 09 Jun 2008 07:18:59 -0700
changeset 625
d1635bf93939
parent 435
a61af66fc99e
child 631
d1605aabd0a1
child 698
12eea04c8b06
permissions
-rw-r--r--

6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
Summary: The fix takes care of three issues that can create a hole less a minimal object in the lgrp chunk
Reviewed-by: ysr, apetrusenko

duke@435 1 /*
duke@435 2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 # include "incls/_precompiled.incl"
duke@435 26 # include "incls/_mutableSpace.cpp.incl"
duke@435 27
duke@435 28 void MutableSpace::initialize(MemRegion mr, bool clear_space) {
duke@435 29 HeapWord* bottom = mr.start();
duke@435 30 HeapWord* end = mr.end();
duke@435 31
duke@435 32 assert(Universe::on_page_boundary(bottom) && Universe::on_page_boundary(end),
duke@435 33 "invalid space boundaries");
duke@435 34 set_bottom(bottom);
duke@435 35 set_end(end);
duke@435 36
duke@435 37 if (clear_space) clear();
duke@435 38 }
duke@435 39
duke@435 40 void MutableSpace::clear() {
duke@435 41 set_top(bottom());
duke@435 42 if (ZapUnusedHeapArea) mangle_unused_area();
duke@435 43 }
duke@435 44
duke@435 45 // This version requires locking. */
duke@435 46 HeapWord* MutableSpace::allocate(size_t size) {
duke@435 47 assert(Heap_lock->owned_by_self() ||
duke@435 48 (SafepointSynchronize::is_at_safepoint() &&
duke@435 49 Thread::current()->is_VM_thread()),
duke@435 50 "not locked");
duke@435 51 HeapWord* obj = top();
duke@435 52 if (pointer_delta(end(), obj) >= size) {
duke@435 53 HeapWord* new_top = obj + size;
duke@435 54 set_top(new_top);
duke@435 55 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
duke@435 56 "checking alignment");
duke@435 57 return obj;
duke@435 58 } else {
duke@435 59 return NULL;
duke@435 60 }
duke@435 61 }
duke@435 62
duke@435 63 // This version is lock-free.
duke@435 64 HeapWord* MutableSpace::cas_allocate(size_t size) {
duke@435 65 do {
duke@435 66 HeapWord* obj = top();
duke@435 67 if (pointer_delta(end(), obj) >= size) {
duke@435 68 HeapWord* new_top = obj + size;
duke@435 69 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
duke@435 70 // result can be one of two:
duke@435 71 // the old top value: the exchange succeeded
duke@435 72 // otherwise: the new value of the top is returned.
duke@435 73 if (result != obj) {
duke@435 74 continue; // another thread beat us to the allocation, try again
duke@435 75 }
duke@435 76 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
duke@435 77 "checking alignment");
duke@435 78 return obj;
duke@435 79 } else {
duke@435 80 return NULL;
duke@435 81 }
duke@435 82 } while (true);
duke@435 83 }
duke@435 84
duke@435 85 // Try to deallocate previous allocation. Returns true upon success.
duke@435 86 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
duke@435 87 HeapWord* expected_top = obj + size;
duke@435 88 return (HeapWord*)Atomic::cmpxchg_ptr(obj, top_addr(), expected_top) == expected_top;
duke@435 89 }
duke@435 90
duke@435 91 void MutableSpace::oop_iterate(OopClosure* cl) {
duke@435 92 HeapWord* obj_addr = bottom();
duke@435 93 HeapWord* t = top();
duke@435 94 // Could call objects iterate, but this is easier.
duke@435 95 while (obj_addr < t) {
duke@435 96 obj_addr += oop(obj_addr)->oop_iterate(cl);
duke@435 97 }
duke@435 98 }
duke@435 99
duke@435 100 void MutableSpace::object_iterate(ObjectClosure* cl) {
duke@435 101 HeapWord* p = bottom();
duke@435 102 while (p < top()) {
duke@435 103 cl->do_object(oop(p));
duke@435 104 p += oop(p)->size();
duke@435 105 }
duke@435 106 }
duke@435 107
duke@435 108 void MutableSpace::print_short() const { print_short_on(tty); }
duke@435 109 void MutableSpace::print_short_on( outputStream* st) const {
duke@435 110 st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K,
duke@435 111 (int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
duke@435 112 }
duke@435 113
duke@435 114 void MutableSpace::print() const { print_on(tty); }
duke@435 115 void MutableSpace::print_on(outputStream* st) const {
duke@435 116 MutableSpace::print_short_on(st);
duke@435 117 st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")",
duke@435 118 bottom(), top(), end());
duke@435 119 }
duke@435 120
iveresov@625 121 void MutableSpace::verify(bool allow_dirty) {
duke@435 122 HeapWord* p = bottom();
duke@435 123 HeapWord* t = top();
duke@435 124 HeapWord* prev_p = NULL;
duke@435 125 while (p < t) {
duke@435 126 oop(p)->verify();
duke@435 127 prev_p = p;
duke@435 128 p += oop(p)->size();
duke@435 129 }
duke@435 130 guarantee(p == top(), "end of last object must match end of space");
duke@435 131 }

mercurial