annotate src/share/vm/gc_implementation/g1/g1AllocRegion.cpp @ 2433:abdfc822206f

7023069: G1: Introduce symmetric locking in the slow allocation path 7023151: G1: refactor the code that operates on _cur_alloc_region to be re-used for allocs by the GC threads 7018286: G1: humongous allocation attempts should take the GC locker into account Summary: First, this change replaces the asymmetric locking scheme in the G1 slow alloc path by a summetric one. Second, it factors out the code that operates on _cur_alloc_region so that it can be re-used for allocations by the GC threads in the future. Reviewed-by: stefank, brutisso, johnc
author tonyp
date Wed, 30 Mar 2011 10:26:59 -0400
parents
children f44782f04dd4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2433
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
1 /*
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
4 *
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
7 * published by the Free Software Foundation.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
8 *
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
13 * accompanied this code).
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
14 *
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
18 *
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
21 * questions.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
22 *
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
23 */
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
24
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
25 #include "precompiled.hpp"
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
26 #include "gc_implementation/g1/g1AllocRegion.inline.hpp"
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
27 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
28
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
29 G1CollectedHeap* G1AllocRegion::_g1h = NULL;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
30 HeapRegion* G1AllocRegion::_dummy_region = NULL;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
31
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
32 void G1AllocRegion::setup(G1CollectedHeap* g1h, HeapRegion* dummy_region) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
33 assert(_dummy_region == NULL, "should be set once");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
34 assert(dummy_region != NULL, "pre-condition");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
35 assert(dummy_region->free() == 0, "pre-condition");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
36
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
37 // Make sure that any allocation attempt on this region will fail
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
38 // and will not trigger any asserts.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
39 assert(allocate(dummy_region, 1, false) == NULL, "should fail");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
40 assert(par_allocate(dummy_region, 1, false) == NULL, "should fail");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
41 assert(allocate(dummy_region, 1, true) == NULL, "should fail");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
42 assert(par_allocate(dummy_region, 1, true) == NULL, "should fail");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
43
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
44 _g1h = g1h;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
45 _dummy_region = dummy_region;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
46 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
47
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
48 void G1AllocRegion::fill_up_remaining_space(HeapRegion* alloc_region,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
49 bool bot_updates) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
50 assert(alloc_region != NULL && alloc_region != _dummy_region,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
51 "pre-condition");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
52
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
53 // Other threads might still be trying to allocate using a CAS out
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
54 // of the region we are trying to retire, as they can do so without
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
55 // holding the lock. So, we first have to make sure that noone else
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
56 // can allocate out of it by doing a maximal allocation. Even if our
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
57 // CAS attempt fails a few times, we'll succeed sooner or later
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
58 // given that failed CAS attempts mean that the region is getting
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
59 // closed to being full.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
60 size_t free_word_size = alloc_region->free() / HeapWordSize;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
61
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
62 // This is the minimum free chunk we can turn into a dummy
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
63 // object. If the free space falls below this, then noone can
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
64 // allocate in this region anyway (all allocation requests will be
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
65 // of a size larger than this) so we won't have to perform the dummy
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
66 // allocation.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
67 size_t min_word_size_to_fill = CollectedHeap::min_fill_size();
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
68
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
69 while (free_word_size >= min_word_size_to_fill) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
70 HeapWord* dummy = par_allocate(alloc_region, free_word_size, bot_updates);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
71 if (dummy != NULL) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
72 // If the allocation was successful we should fill in the space.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
73 CollectedHeap::fill_with_object(dummy, free_word_size);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
74 alloc_region->set_pre_dummy_top(dummy);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
75 break;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
76 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
77
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
78 free_word_size = alloc_region->free() / HeapWordSize;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
79 // It's also possible that someone else beats us to the
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
80 // allocation and they fill up the region. In that case, we can
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
81 // just get out of the loop.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
82 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
83 assert(alloc_region->free() / HeapWordSize < min_word_size_to_fill,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
84 "post-condition");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
85 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
86
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
87 void G1AllocRegion::retire(bool fill_up) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
88 assert(_alloc_region != NULL, ar_ext_msg(this, "not initialized properly"));
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
89
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
90 trace("retiring");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
91 HeapRegion* alloc_region = _alloc_region;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
92 if (alloc_region != _dummy_region) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
93 // We never have to check whether the active region is empty or not,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
94 // and potentially free it if it is, given that it's guaranteed that
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
95 // it will never be empty.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
96 assert(!alloc_region->is_empty(),
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
97 ar_ext_msg(this, "the alloc region should never be empty"));
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
98
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
99 if (fill_up) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
100 fill_up_remaining_space(alloc_region, _bot_updates);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
101 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
102
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
103 assert(alloc_region->used() >= _used_bytes_before,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
104 ar_ext_msg(this, "invariant"));
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
105 size_t allocated_bytes = alloc_region->used() - _used_bytes_before;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
106 retire_region(alloc_region, allocated_bytes);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
107 _used_bytes_before = 0;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
108 _alloc_region = _dummy_region;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
109 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
110 trace("retired");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
111 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
112
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
113 HeapWord* G1AllocRegion::new_alloc_region_and_allocate(size_t word_size,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
114 bool force) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
115 assert(_alloc_region == _dummy_region, ar_ext_msg(this, "pre-condition"));
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
116 assert(_used_bytes_before == 0, ar_ext_msg(this, "pre-condition"));
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
117
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
118 trace("attempting region allocation");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
119 HeapRegion* new_alloc_region = allocate_new_region(word_size, force);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
120 if (new_alloc_region != NULL) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
121 new_alloc_region->reset_pre_dummy_top();
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
122 // Need to do this before the allocation
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
123 _used_bytes_before = new_alloc_region->used();
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
124 HeapWord* result = allocate(new_alloc_region, word_size, _bot_updates);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
125 assert(result != NULL, ar_ext_msg(this, "the allocation should succeeded"));
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
126
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
127 OrderAccess::storestore();
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
128 // Note that we first perform the allocation and then we store the
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
129 // region in _alloc_region. This is the reason why an active region
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
130 // can never be empty.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
131 _alloc_region = new_alloc_region;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
132 trace("region allocation successful");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
133 return result;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
134 } else {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
135 trace("region allocation failed");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
136 return NULL;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
137 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
138 ShouldNotReachHere();
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
139 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
140
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
141 void G1AllocRegion::fill_in_ext_msg(ar_ext_msg* msg, const char* message) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
142 msg->append("[%s] %s b: %s r: "PTR_FORMAT" u: "SIZE_FORMAT,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
143 _name, message, BOOL_TO_STR(_bot_updates),
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
144 _alloc_region, _used_bytes_before);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
145 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
146
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
147 void G1AllocRegion::init() {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
148 trace("initializing");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
149 assert(_alloc_region == NULL && _used_bytes_before == 0,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
150 ar_ext_msg(this, "pre-condition"));
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
151 assert(_dummy_region != NULL, "should have been set");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
152 _alloc_region = _dummy_region;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
153 trace("initialized");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
154 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
155
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
156 HeapRegion* G1AllocRegion::release() {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
157 trace("releasing");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
158 HeapRegion* alloc_region = _alloc_region;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
159 retire(false /* fill_up */);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
160 assert(_alloc_region == _dummy_region, "post-condition of retire()");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
161 _alloc_region = NULL;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
162 trace("released");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
163 return (alloc_region == _dummy_region) ? NULL : alloc_region;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
164 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
165
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
166 #if G1_ALLOC_REGION_TRACING
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
167 void G1AllocRegion::trace(const char* str, size_t word_size, HeapWord* result) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
168 // All the calls to trace that set either just the size or the size
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
169 // and the result are considered part of level 2 tracing and are
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
170 // skipped during level 1 tracing.
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
171 if ((word_size == 0 && result == NULL) || (G1_ALLOC_REGION_TRACING > 1)) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
172 const size_t buffer_length = 128;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
173 char hr_buffer[buffer_length];
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
174 char rest_buffer[buffer_length];
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
175
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
176 HeapRegion* alloc_region = _alloc_region;
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
177 if (alloc_region == NULL) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
178 jio_snprintf(hr_buffer, buffer_length, "NULL");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
179 } else if (alloc_region == _dummy_region) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
180 jio_snprintf(hr_buffer, buffer_length, "DUMMY");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
181 } else {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
182 jio_snprintf(hr_buffer, buffer_length,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
183 HR_FORMAT, HR_FORMAT_PARAMS(alloc_region));
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
184 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
185
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
186 if (G1_ALLOC_REGION_TRACING > 1) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
187 if (result != NULL) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
188 jio_snprintf(rest_buffer, buffer_length, SIZE_FORMAT" "PTR_FORMAT,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
189 word_size, result);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
190 } else if (word_size != 0) {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
191 jio_snprintf(rest_buffer, buffer_length, SIZE_FORMAT, word_size);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
192 } else {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
193 jio_snprintf(rest_buffer, buffer_length, "");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
194 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
195 } else {
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
196 jio_snprintf(rest_buffer, buffer_length, "");
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
197 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
198
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
199 tty->print_cr("[%s] %s : %s %s", _name, hr_buffer, str, rest_buffer);
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
200 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
201 }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
202 #endif // G1_ALLOC_REGION_TRACING
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
203
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
204 G1AllocRegion::G1AllocRegion(const char* name,
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
205 bool bot_updates)
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
206 : _name(name), _bot_updates(bot_updates),
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
207 _alloc_region(NULL), _used_bytes_before(0) { }
abdfc822206f 7023069: G1: Introduce symmetric locking in the slow allocation path
tonyp
parents:
diff changeset
208