29 #include "gc/parallel/objectStartArray.hpp"
30 #include "gc/parallel/psGenerationCounters.hpp"
31 #include "gc/parallel/psVirtualspace.hpp"
32 #include "gc/parallel/spaceCounters.hpp"
33
34 class PSYoungGen : public CHeapObj<mtGC> {
35 friend class VMStructs;
36 friend class ParallelScavengeHeap;
37 friend class AdjoiningGenerations;
38
39 private:
40 MemRegion _reserved;
41 PSVirtualSpace* _virtual_space;
42
43 // Spaces
44 MutableSpace* _eden_space;
45 MutableSpace* _from_space;
46 MutableSpace* _to_space;
47
48 // Sizing information, in bytes, set in constructor
49 const size_t _init_gen_size;
50 const size_t _min_gen_size;
51 const size_t _max_gen_size;
52
53 // Performance counters
54 PSGenerationCounters* _gen_counters;
55 SpaceCounters* _eden_counters;
56 SpaceCounters* _from_counters;
57 SpaceCounters* _to_counters;
58
59 // Initialize the space boundaries
60 void compute_initial_space_boundaries();
61
62 // Space boundary helper
63 void set_space_boundaries(size_t eden_size, size_t survivor_size);
64
65 bool resize_generation(size_t eden_size, size_t survivor_size);
66 void resize_spaces(size_t eden_size, size_t survivor_size);
67
68 // Adjust the spaces to be consistent with the virtual space.
69 void post_resize();
70
71 // Given a desired shrinkage in the size of the young generation,
72 // return the actual size available for shrinkage.
73 size_t limit_gen_shrink(size_t desired_change);
74 // returns the number of bytes available from the current size
75 // down to the minimum generation size.
76 size_t available_to_min_gen();
77 // Return the number of bytes available for shrinkage considering
78 // the location the live data in the generation.
79 size_t available_to_live();
80
81 void initialize(ReservedSpace rs, size_t alignment);
82 void initialize_work();
83 void initialize_virtual_space(ReservedSpace rs, size_t alignment);
84
85 public:
86 // Initialize the generation.
87 PSYoungGen(ReservedSpace rs,
88 size_t initial_byte_size,
89 size_t minimum_byte_size,
90 size_t maximum_byte_size);
91
92 MemRegion reserved() const { return _reserved; }
93
94 bool is_in(const void* p) const {
95 return _virtual_space->contains((void *)p);
96 }
97
98 bool is_in_reserved(const void* p) const {
99 return reserved().contains((void *)p);
100 }
101
102 MutableSpace* eden_space() const { return _eden_space; }
103 MutableSpace* from_space() const { return _from_space; }
104 MutableSpace* to_space() const { return _to_space; }
105 PSVirtualSpace* virtual_space() const { return _virtual_space; }
106
107 // For Adaptive size policy
108 size_t min_gen_size() { return _min_gen_size; }
109
110 // Called during/after GC
111 void swap_spaces();
112
113 // Resize generation using suggested free space size and survivor size
114 // NOTE: "eden_size" and "survivor_size" are suggestions only. Current
115 // heap layout (particularly, live objects in from space) might
116 // not allow us to use these values.
117 void resize(size_t eden_size, size_t survivor_size);
118
119 // Size info
120 size_t capacity_in_bytes() const;
121 size_t used_in_bytes() const;
122 size_t free_in_bytes() const;
123
124 size_t capacity_in_words() const;
125 size_t used_in_words() const;
126 size_t free_in_words() const;
127
128 // The max this generation can grow to
129 size_t max_size() const { return _reserved.byte_size(); }
130
131 // The max this generation can grow to
132 size_t gen_size_limit() const { return _max_gen_size; }
133
134 bool is_maximal_no_gc() const {
135 return true; // Never expands except at a GC
136 }
137
138 // Allocation
139 HeapWord* allocate(size_t word_size) {
140 HeapWord* result = eden_space()->cas_allocate(word_size);
141 return result;
142 }
143
144 HeapWord* volatile* top_addr() const { return eden_space()->top_addr(); }
145 HeapWord** end_addr() const { return eden_space()->end_addr(); }
146
147 // Iteration.
148 void oop_iterate(OopIterateClosure* cl);
149 void object_iterate(ObjectClosure* cl);
150
151 void reset_survivors_after_shrink();
152
|
29 #include "gc/parallel/objectStartArray.hpp"
30 #include "gc/parallel/psGenerationCounters.hpp"
31 #include "gc/parallel/psVirtualspace.hpp"
32 #include "gc/parallel/spaceCounters.hpp"
33
34 class PSYoungGen : public CHeapObj<mtGC> {
35 friend class VMStructs;
36 friend class ParallelScavengeHeap;
37 friend class AdjoiningGenerations;
38
39 private:
40 MemRegion _reserved;
41 PSVirtualSpace* _virtual_space;
42
43 // Spaces
44 MutableSpace* _eden_space;
45 MutableSpace* _from_space;
46 MutableSpace* _to_space;
47
48 // Sizing information, in bytes, set in constructor
49 const size_t _min_gen_size;
50 const size_t _max_gen_size;
51
52 // Performance counters
53 PSGenerationCounters* _gen_counters;
54 SpaceCounters* _eden_counters;
55 SpaceCounters* _from_counters;
56 SpaceCounters* _to_counters;
57
58 // Initialize the space boundaries
59 void compute_initial_space_boundaries();
60
61 // Space boundary helper
62 void set_space_boundaries(size_t eden_size, size_t survivor_size);
63
64 bool resize_generation(size_t eden_size, size_t survivor_size);
65 void resize_spaces(size_t eden_size, size_t survivor_size);
66
67 // Adjust the spaces to be consistent with the virtual space.
68 void post_resize();
69
70 // Given a desired shrinkage in the size of the young generation,
71 // return the actual size available for shrinkage.
72 size_t limit_gen_shrink(size_t desired_change);
73 // returns the number of bytes available from the current size
74 // down to the minimum generation size.
75 size_t available_to_min_gen();
76 // Return the number of bytes available for shrinkage considering
77 // the location the live data in the generation.
78 size_t available_to_live();
79
80 void initialize(ReservedSpace rs, size_t inital_size, size_t alignment);
81 void initialize_work();
82 void initialize_virtual_space(ReservedSpace rs, size_t initial_size, size_t alignment);
83
84 public:
85 // Initialize the generation.
86 PSYoungGen(ReservedSpace rs,
87 size_t initial_byte_size,
88 size_t minimum_byte_size,
89 size_t maximum_byte_size);
90
91 MemRegion reserved() const { return _reserved; }
92
93 bool is_in(const void* p) const {
94 return _virtual_space->contains((void *)p);
95 }
96
97 bool is_in_reserved(const void* p) const {
98 return reserved().contains((void *)p);
99 }
100
101 MutableSpace* eden_space() const { return _eden_space; }
102 MutableSpace* from_space() const { return _from_space; }
103 MutableSpace* to_space() const { return _to_space; }
104 PSVirtualSpace* virtual_space() const { return _virtual_space; }
105
106 // Called during/after GC
107 void swap_spaces();
108
109 // Resize generation using suggested free space size and survivor size
110 // NOTE: "eden_size" and "survivor_size" are suggestions only. Current
111 // heap layout (particularly, live objects in from space) might
112 // not allow us to use these values.
113 void resize(size_t eden_size, size_t survivor_size);
114
115 // Size info
116 size_t capacity_in_bytes() const;
117 size_t used_in_bytes() const;
118 size_t free_in_bytes() const;
119
120 size_t capacity_in_words() const;
121 size_t used_in_words() const;
122 size_t free_in_words() const;
123
124 size_t min_gen_size() const { return _min_gen_size; }
125 size_t max_gen_size() const { return _max_gen_size; }
126
127 bool is_maximal_no_gc() const {
128 return true; // Never expands except at a GC
129 }
130
131 // Allocation
132 HeapWord* allocate(size_t word_size) {
133 HeapWord* result = eden_space()->cas_allocate(word_size);
134 return result;
135 }
136
137 HeapWord* volatile* top_addr() const { return eden_space()->top_addr(); }
138 HeapWord** end_addr() const { return eden_space()->end_addr(); }
139
140 // Iteration.
141 void oop_iterate(OopIterateClosure* cl);
142 void object_iterate(ObjectClosure* cl);
143
144 void reset_survivors_after_shrink();
145
|