annotate src/share/vm/gc_implementation/shared/mutableSpace.cpp @ 196:d1605aabd0a1 jdk7-b30

6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
author xdono
date Wed, 02 Jul 2008 12:55:16 -0700
parents d1635bf93939
children 850fdf70db2b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
196
d1605aabd0a1 6719955: Update copyright year
xdono
parents: 190
diff changeset
2 * Copyright 2001-2008 Sun Microsystems, Inc. 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 *
a61af66fc99e Initial load
duke
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
a61af66fc99e Initial load
duke
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
a61af66fc99e Initial load
duke
parents:
diff changeset
21 * have any questions.
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_mutableSpace.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28 void MutableSpace::initialize(MemRegion mr, bool clear_space) {
a61af66fc99e Initial load
duke
parents:
diff changeset
29 HeapWord* bottom = mr.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
30 HeapWord* end = mr.end();
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 assert(Universe::on_page_boundary(bottom) && Universe::on_page_boundary(end),
a61af66fc99e Initial load
duke
parents:
diff changeset
33 "invalid space boundaries");
a61af66fc99e Initial load
duke
parents:
diff changeset
34 set_bottom(bottom);
a61af66fc99e Initial load
duke
parents:
diff changeset
35 set_end(end);
a61af66fc99e Initial load
duke
parents:
diff changeset
36
a61af66fc99e Initial load
duke
parents:
diff changeset
37 if (clear_space) clear();
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 void MutableSpace::clear() {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 set_top(bottom());
a61af66fc99e Initial load
duke
parents:
diff changeset
42 if (ZapUnusedHeapArea) mangle_unused_area();
a61af66fc99e Initial load
duke
parents:
diff changeset
43 }
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 // This version requires locking. */
a61af66fc99e Initial load
duke
parents:
diff changeset
46 HeapWord* MutableSpace::allocate(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
47 assert(Heap_lock->owned_by_self() ||
a61af66fc99e Initial load
duke
parents:
diff changeset
48 (SafepointSynchronize::is_at_safepoint() &&
a61af66fc99e Initial load
duke
parents:
diff changeset
49 Thread::current()->is_VM_thread()),
a61af66fc99e Initial load
duke
parents:
diff changeset
50 "not locked");
a61af66fc99e Initial load
duke
parents:
diff changeset
51 HeapWord* obj = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
52 if (pointer_delta(end(), obj) >= size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 HeapWord* new_top = obj + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 set_top(new_top);
a61af66fc99e Initial load
duke
parents:
diff changeset
55 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
a61af66fc99e Initial load
duke
parents:
diff changeset
56 "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
57 return obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
58 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 }
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62
a61af66fc99e Initial load
duke
parents:
diff changeset
63 // This version is lock-free.
a61af66fc99e Initial load
duke
parents:
diff changeset
64 HeapWord* MutableSpace::cas_allocate(size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
65 do {
a61af66fc99e Initial load
duke
parents:
diff changeset
66 HeapWord* obj = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 if (pointer_delta(end(), obj) >= size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
68 HeapWord* new_top = obj + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 HeapWord* result = (HeapWord*)Atomic::cmpxchg_ptr(new_top, top_addr(), obj);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 // result can be one of two:
a61af66fc99e Initial load
duke
parents:
diff changeset
71 // the old top value: the exchange succeeded
a61af66fc99e Initial load
duke
parents:
diff changeset
72 // otherwise: the new value of the top is returned.
a61af66fc99e Initial load
duke
parents:
diff changeset
73 if (result != obj) {
a61af66fc99e Initial load
duke
parents:
diff changeset
74 continue; // another thread beat us to the allocation, try again
a61af66fc99e Initial load
duke
parents:
diff changeset
75 }
a61af66fc99e Initial load
duke
parents:
diff changeset
76 assert(is_object_aligned((intptr_t)obj) && is_object_aligned((intptr_t)new_top),
a61af66fc99e Initial load
duke
parents:
diff changeset
77 "checking alignment");
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return obj;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
80 return NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
81 }
a61af66fc99e Initial load
duke
parents:
diff changeset
82 } while (true);
a61af66fc99e Initial load
duke
parents:
diff changeset
83 }
a61af66fc99e Initial load
duke
parents:
diff changeset
84
a61af66fc99e Initial load
duke
parents:
diff changeset
85 // Try to deallocate previous allocation. Returns true upon success.
a61af66fc99e Initial load
duke
parents:
diff changeset
86 bool MutableSpace::cas_deallocate(HeapWord *obj, size_t size) {
a61af66fc99e Initial load
duke
parents:
diff changeset
87 HeapWord* expected_top = obj + size;
a61af66fc99e Initial load
duke
parents:
diff changeset
88 return (HeapWord*)Atomic::cmpxchg_ptr(obj, top_addr(), expected_top) == expected_top;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 }
a61af66fc99e Initial load
duke
parents:
diff changeset
90
a61af66fc99e Initial load
duke
parents:
diff changeset
91 void MutableSpace::oop_iterate(OopClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
92 HeapWord* obj_addr = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
93 HeapWord* t = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
94 // Could call objects iterate, but this is easier.
a61af66fc99e Initial load
duke
parents:
diff changeset
95 while (obj_addr < t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
96 obj_addr += oop(obj_addr)->oop_iterate(cl);
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 void MutableSpace::object_iterate(ObjectClosure* cl) {
a61af66fc99e Initial load
duke
parents:
diff changeset
101 HeapWord* p = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
102 while (p < top()) {
a61af66fc99e Initial load
duke
parents:
diff changeset
103 cl->do_object(oop(p));
a61af66fc99e Initial load
duke
parents:
diff changeset
104 p += oop(p)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 }
a61af66fc99e Initial load
duke
parents:
diff changeset
106 }
a61af66fc99e Initial load
duke
parents:
diff changeset
107
a61af66fc99e Initial load
duke
parents:
diff changeset
108 void MutableSpace::print_short() const { print_short_on(tty); }
a61af66fc99e Initial load
duke
parents:
diff changeset
109 void MutableSpace::print_short_on( outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 st->print(" space " SIZE_FORMAT "K, %d%% used", capacity_in_bytes() / K,
a61af66fc99e Initial load
duke
parents:
diff changeset
111 (int) ((double) used_in_bytes() * 100 / capacity_in_bytes()));
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113
a61af66fc99e Initial load
duke
parents:
diff changeset
114 void MutableSpace::print() const { print_on(tty); }
a61af66fc99e Initial load
duke
parents:
diff changeset
115 void MutableSpace::print_on(outputStream* st) const {
a61af66fc99e Initial load
duke
parents:
diff changeset
116 MutableSpace::print_short_on(st);
a61af66fc99e Initial load
duke
parents:
diff changeset
117 st->print_cr(" [" INTPTR_FORMAT "," INTPTR_FORMAT "," INTPTR_FORMAT ")",
a61af66fc99e Initial load
duke
parents:
diff changeset
118 bottom(), top(), end());
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120
190
d1635bf93939 6711930: NUMA allocator: ParOld can create a hole less than minimal object size in the lgrp chunk
iveresov
parents: 0
diff changeset
121 void MutableSpace::verify(bool allow_dirty) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
122 HeapWord* p = bottom();
a61af66fc99e Initial load
duke
parents:
diff changeset
123 HeapWord* t = top();
a61af66fc99e Initial load
duke
parents:
diff changeset
124 HeapWord* prev_p = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 while (p < t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 oop(p)->verify();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 prev_p = p;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 p += oop(p)->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 }
a61af66fc99e Initial load
duke
parents:
diff changeset
130 guarantee(p == top(), "end of last object must match end of space");
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }