40 #include "oops/oop.inline.hpp" |
40 #include "oops/oop.inline.hpp" |
41 #include "runtime/java.hpp" |
41 #include "runtime/java.hpp" |
42 #include "utilities/copy.hpp" |
42 #include "utilities/copy.hpp" |
43 #include "utilities/events.hpp" |
43 #include "utilities/events.hpp" |
44 |
44 |
45 Generation::Generation(ReservedSpace rs, size_t initial_size, int level) : |
45 Generation::Generation(ReservedSpace rs, size_t initial_size) : |
46 _level(level), |
|
47 _ref_processor(NULL) { |
46 _ref_processor(NULL) { |
48 if (!_virtual_space.initialize(rs, initial_size)) { |
47 if (!_virtual_space.initialize(rs, initial_size)) { |
49 vm_exit_during_initialization("Could not reserve enough space for " |
48 vm_exit_during_initialization("Could not reserve enough space for " |
50 "object heap"); |
49 "object heap"); |
51 } |
50 } |
59 (HeapWord*)_virtual_space.high_boundary()); |
58 (HeapWord*)_virtual_space.high_boundary()); |
60 } |
59 } |
61 |
60 |
62 GenerationSpec* Generation::spec() { |
61 GenerationSpec* Generation::spec() { |
63 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
62 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
64 assert(level() == 0 || level() == 1, "Bad gen level"); |
63 if (gch->is_young_gen(this)) { |
65 return level() == 0 ? gch->gen_policy()->young_gen_spec() : gch->gen_policy()->old_gen_spec(); |
64 return gch->gen_policy()->young_gen_spec(); |
|
65 } |
|
66 return gch->gen_policy()->old_gen_spec(); |
66 } |
67 } |
67 |
68 |
68 size_t Generation::max_capacity() const { |
69 size_t Generation::max_capacity() const { |
69 return reserved().byte_size(); |
70 return reserved().byte_size(); |
70 } |
71 } |
109 void Generation::print_summary_info() { print_summary_info_on(tty); } |
110 void Generation::print_summary_info() { print_summary_info_on(tty); } |
110 |
111 |
111 void Generation::print_summary_info_on(outputStream* st) { |
112 void Generation::print_summary_info_on(outputStream* st) { |
112 StatRecord* sr = stat_record(); |
113 StatRecord* sr = stat_record(); |
113 double time = sr->accumulated_time.seconds(); |
114 double time = sr->accumulated_time.seconds(); |
|
115 // I didn't want to change the logging when removing the level concept, |
|
116 // but I guess this logging could say young/old or something instead of 0/1. |
|
117 uint level; |
|
118 if (GenCollectedHeap::heap()->is_young_gen(this)) { |
|
119 level = 0; |
|
120 } else { |
|
121 level = 1; |
|
122 } |
114 st->print_cr("[Accumulated GC generation %d time %3.7f secs, " |
123 st->print_cr("[Accumulated GC generation %d time %3.7f secs, " |
115 "%d GC's, avg GC time %3.7f]", |
124 "%u GC's, avg GC time %3.7f]", |
116 level(), time, sr->invocations, |
125 level, time, sr->invocations, |
117 sr->invocations > 0 ? time / sr->invocations : 0.0); |
126 sr->invocations > 0 ? time / sr->invocations : 0.0); |
118 } |
127 } |
119 |
128 |
120 // Utility iterator classes |
129 // Utility iterator classes |
121 |
130 |
147 GenerationIsInClosure blk(p); |
156 GenerationIsInClosure blk(p); |
148 ((Generation*)this)->space_iterate(&blk); |
157 ((Generation*)this)->space_iterate(&blk); |
149 return blk.sp != NULL; |
158 return blk.sp != NULL; |
150 } |
159 } |
151 |
160 |
152 Generation* Generation::next_gen() const { |
|
153 GenCollectedHeap* gch = GenCollectedHeap::heap(); |
|
154 if (level() == 0) { |
|
155 return gch->old_gen(); |
|
156 } else { |
|
157 return NULL; |
|
158 } |
|
159 } |
|
160 |
|
161 size_t Generation::max_contiguous_available() const { |
161 size_t Generation::max_contiguous_available() const { |
162 // The largest number of contiguous free words in this or any higher generation. |
162 // The largest number of contiguous free words in this or any higher generation. |
163 size_t max = 0; |
163 size_t avail = contiguous_available(); |
164 for (const Generation* gen = this; gen != NULL; gen = gen->next_gen()) { |
164 size_t old_avail = 0; |
165 size_t avail = gen->contiguous_available(); |
165 if (GenCollectedHeap::heap()->is_young_gen(this)) { |
166 if (avail > max) { |
166 old_avail = GenCollectedHeap::heap()->old_gen()->contiguous_available(); |
167 max = avail; |
167 } |
168 } |
168 return MAX2(avail, old_avail); |
169 } |
|
170 return max; |
|
171 } |
169 } |
172 |
170 |
173 bool Generation::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const { |
171 bool Generation::promotion_attempt_is_safe(size_t max_promotion_in_bytes) const { |
174 size_t available = max_contiguous_available(); |
172 size_t available = max_contiguous_available(); |
175 bool res = (available >= max_promotion_in_bytes); |
173 bool res = (available >= max_promotion_in_bytes); |