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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/serial/genMarkSweep.hpp"
27 #include "gc/shared/blockOffsetTable.inline.hpp"
28 #include "gc/shared/cardTableRS.hpp"
29 #include "gc/shared/collectedHeap.inline.hpp"
30 #include "gc/shared/gcLocker.inline.hpp"
31 #include "gc/shared/gcTimer.hpp"
32 #include "gc/shared/gcTrace.hpp"
33 #include "gc/shared/genCollectedHeap.hpp"
34 #include "gc/shared/genOopClosures.hpp"
35 #include "gc/shared/genOopClosures.inline.hpp"
36 #include "gc/shared/generation.hpp"
37 #include "gc/shared/space.inline.hpp"
38 #include "gc/shared/spaceDecorator.hpp"
39 #include "memory/allocation.inline.hpp"
40 #include "oops/oop.inline.hpp"
41 #include "runtime/java.hpp"
42 #include "utilities/copy.hpp"
43 #include "utilities/events.hpp"
44
45 Generation::Generation(ReservedSpace rs, size_t initial_size) :
46 _ref_processor(NULL) {
47 if (!_virtual_space.initialize(rs, initial_size)) {
48 vm_exit_during_initialization("Could not reserve enough space for "
49 "object heap");
50 }
51 // Mangle all of the the initial generation.
52 if (ZapUnusedHeapArea) {
53 MemRegion mangle_region((HeapWord*)_virtual_space.low(),
54 (HeapWord*)_virtual_space.high());
55 SpaceMangler::mangle_region(mangle_region);
56 }
57 _reserved = MemRegion((HeapWord*)_virtual_space.low_boundary(),
58 (HeapWord*)_virtual_space.high_boundary());
59 }
60
61 size_t Generation::initial_size() {
62 GenCollectedHeap* gch = GenCollectedHeap::heap();
63 if (gch->is_young_gen(this)) {
64 return gch->gen_policy()->young_gen_spec()->init_size();
65 }
66 return gch->gen_policy()->old_gen_spec()->init_size();
67 }
68
69 size_t Generation::max_capacity() const {
70 return reserved().byte_size();
71 }
72
73 void Generation::print_heap_change(size_t prev_used) const {
74 if (PrintGCDetails && Verbose) {
75 gclog_or_tty->print(" " SIZE_FORMAT
76 "->" SIZE_FORMAT
77 "(" SIZE_FORMAT ")",
78 prev_used, used(), capacity());
79 } else {
80 gclog_or_tty->print(" " SIZE_FORMAT "K"
81 "->" SIZE_FORMAT "K"
82 "(" SIZE_FORMAT "K)",
83 prev_used / K, used() / K, capacity() / K);
84 }
85 }
86
87 // By default we get a single threaded default reference processor;
88 // generations needing multi-threaded refs processing or discovery override this method.
89 void Generation::ref_processor_init() {
90 assert(_ref_processor == NULL, "a reference processor already exists");
91 assert(!_reserved.is_empty(), "empty generation?");
92 _ref_processor = new ReferenceProcessor(_reserved); // a vanilla reference processor
93 if (_ref_processor == NULL) {
94 vm_exit_during_initialization("Could not allocate ReferenceProcessor object");
95 }
96 }
97
98 void Generation::print() const { print_on(tty); }
99
100 void Generation::print_on(outputStream* st) const {
101 st->print(" %-20s", name());
102 st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
103 capacity()/K, used()/K);
104 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
105 p2i(_virtual_space.low_boundary()),
106 p2i(_virtual_space.high()),
154
155 bool Generation::is_in(const void* p) const {
156 GenerationIsInClosure blk(p);
157 ((Generation*)this)->space_iterate(&blk);
158 return blk.sp != NULL;
159 }
160
161 size_t Generation::max_contiguous_available() const {
162 // The largest number of contiguous free words in this or any higher generation.
163 size_t avail = contiguous_available();
164 size_t old_avail = 0;
165 if (GenCollectedHeap::heap()->is_young_gen(this)) {
166 old_avail = GenCollectedHeap::heap()->old_gen()->contiguous_available();
167 }
168 return MAX2(avail, old_avail);
169 }
170
171 bool Generation::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const {
172 size_t available = max_contiguous_available();
173 bool res = (available >= max_promotion_in_bytes);
174 if (PrintGC && Verbose) {
175 gclog_or_tty->print_cr(
176 "Generation: promo attempt is%s safe: available(" SIZE_FORMAT ") %s max_promo(" SIZE_FORMAT ")",
177 res? "":" not", available, res? ">=":"<",
178 max_promotion_in_bytes);
179 }
180 return res;
181 }
182
183 // Ignores "ref" and calls allocate().
184 oop Generation::promote(oop obj, size_t obj_size) {
185 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in");
186
187 #ifndef PRODUCT
188 if (GenCollectedHeap::heap()->promotion_should_fail()) {
189 return NULL;
190 }
191 #endif // #ifndef PRODUCT
192
193 HeapWord* result = allocate(obj_size, false);
194 if (result != NULL) {
195 Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size);
196 return oop(result);
197 } else {
198 GenCollectedHeap* gch = GenCollectedHeap::heap();
199 return gch->handle_failed_promotion(this, obj, obj_size);
|
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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "gc/serial/genMarkSweep.hpp"
27 #include "gc/shared/blockOffsetTable.inline.hpp"
28 #include "gc/shared/cardTableRS.hpp"
29 #include "gc/shared/collectedHeap.inline.hpp"
30 #include "gc/shared/gcLocker.inline.hpp"
31 #include "gc/shared/gcTimer.hpp"
32 #include "gc/shared/gcTrace.hpp"
33 #include "gc/shared/genCollectedHeap.hpp"
34 #include "gc/shared/genOopClosures.hpp"
35 #include "gc/shared/genOopClosures.inline.hpp"
36 #include "gc/shared/generation.hpp"
37 #include "gc/shared/space.inline.hpp"
38 #include "gc/shared/spaceDecorator.hpp"
39 #include "logging/log.hpp"
40 #include "memory/allocation.inline.hpp"
41 #include "oops/oop.inline.hpp"
42 #include "runtime/java.hpp"
43 #include "utilities/copy.hpp"
44 #include "utilities/events.hpp"
45
46 Generation::Generation(ReservedSpace rs, size_t initial_size) :
47 _ref_processor(NULL) {
48 if (!_virtual_space.initialize(rs, initial_size)) {
49 vm_exit_during_initialization("Could not reserve enough space for "
50 "object heap");
51 }
52 // Mangle all of the the initial generation.
53 if (ZapUnusedHeapArea) {
54 MemRegion mangle_region((HeapWord*)_virtual_space.low(),
55 (HeapWord*)_virtual_space.high());
56 SpaceMangler::mangle_region(mangle_region);
57 }
58 _reserved = MemRegion((HeapWord*)_virtual_space.low_boundary(),
59 (HeapWord*)_virtual_space.high_boundary());
60 }
61
62 size_t Generation::initial_size() {
63 GenCollectedHeap* gch = GenCollectedHeap::heap();
64 if (gch->is_young_gen(this)) {
65 return gch->gen_policy()->young_gen_spec()->init_size();
66 }
67 return gch->gen_policy()->old_gen_spec()->init_size();
68 }
69
70 size_t Generation::max_capacity() const {
71 return reserved().byte_size();
72 }
73
74 // By default we get a single threaded default reference processor;
75 // generations needing multi-threaded refs processing or discovery override this method.
76 void Generation::ref_processor_init() {
77 assert(_ref_processor == NULL, "a reference processor already exists");
78 assert(!_reserved.is_empty(), "empty generation?");
79 _ref_processor = new ReferenceProcessor(_reserved); // a vanilla reference processor
80 if (_ref_processor == NULL) {
81 vm_exit_during_initialization("Could not allocate ReferenceProcessor object");
82 }
83 }
84
85 void Generation::print() const { print_on(tty); }
86
87 void Generation::print_on(outputStream* st) const {
88 st->print(" %-20s", name());
89 st->print(" total " SIZE_FORMAT "K, used " SIZE_FORMAT "K",
90 capacity()/K, used()/K);
91 st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
92 p2i(_virtual_space.low_boundary()),
93 p2i(_virtual_space.high()),
141
142 bool Generation::is_in(const void* p) const {
143 GenerationIsInClosure blk(p);
144 ((Generation*)this)->space_iterate(&blk);
145 return blk.sp != NULL;
146 }
147
148 size_t Generation::max_contiguous_available() const {
149 // The largest number of contiguous free words in this or any higher generation.
150 size_t avail = contiguous_available();
151 size_t old_avail = 0;
152 if (GenCollectedHeap::heap()->is_young_gen(this)) {
153 old_avail = GenCollectedHeap::heap()->old_gen()->contiguous_available();
154 }
155 return MAX2(avail, old_avail);
156 }
157
158 bool Generation::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const {
159 size_t available = max_contiguous_available();
160 bool res = (available >= max_promotion_in_bytes);
161 log_trace(gc)("Generation: promo attempt is%s safe: available(" SIZE_FORMAT ") %s max_promo(" SIZE_FORMAT ")",
162 res? "":" not", available, res? ">=":"<", max_promotion_in_bytes);
163 return res;
164 }
165
166 // Ignores "ref" and calls allocate().
167 oop Generation::promote(oop obj, size_t obj_size) {
168 assert(obj_size == (size_t)obj->size(), "bad obj_size passed in");
169
170 #ifndef PRODUCT
171 if (GenCollectedHeap::heap()->promotion_should_fail()) {
172 return NULL;
173 }
174 #endif // #ifndef PRODUCT
175
176 HeapWord* result = allocate(obj_size, false);
177 if (result != NULL) {
178 Copy::aligned_disjoint_words((HeapWord*)obj, result, obj_size);
179 return oop(result);
180 } else {
181 GenCollectedHeap* gch = GenCollectedHeap::heap();
182 return gch->handle_failed_promotion(this, obj, obj_size);
|