11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP
27
28 #include "gc_implementation/parallelScavenge/objectStartArray.hpp"
29 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
30 #include "gc_implementation/parallelScavenge/parMarkBitMap.hpp"
31 #include "gc_implementation/parallelScavenge/psCompactionManager.hpp"
32 #include "gc_implementation/shared/collectorCounters.hpp"
33 #include "gc_implementation/shared/mutableSpace.hpp"
34 #include "gc_interface/collectedHeap.hpp"
35 #include "oops/oop.hpp"
36
37 class ParallelScavengeHeap;
38 class PSAdaptiveSizePolicy;
39 class PSYoungGen;
40 class PSOldGen;
41 class ParCompactionManager;
42 class ParallelTaskTerminator;
43 class PSParallelCompact;
44 class GCTaskManager;
45 class GCTaskQueue;
46 class PreGCValues;
47 class MoveAndUpdateClosure;
48 class RefProcTaskExecutor;
49 class ParallelOldTracer;
50 class STWGCTimer;
51
916 class PSParallelCompact : AllStatic {
917 public:
918 // Convenient access to type names.
919 typedef ParMarkBitMap::idx_t idx_t;
920 typedef ParallelCompactData::RegionData RegionData;
921 typedef ParallelCompactData::BlockData BlockData;
922
923 typedef enum {
924 old_space_id, eden_space_id,
925 from_space_id, to_space_id, last_space_id
926 } SpaceId;
927
928 public:
929 // Inline closure decls
930 //
931 class IsAliveClosure: public BoolObjectClosure {
932 public:
933 virtual bool do_object_b(oop p);
934 };
935
936 class FollowStackClosure: public VoidClosure {
937 private:
938 ParCompactionManager* _compaction_manager;
939 public:
940 FollowStackClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
941 virtual void do_void();
942 };
943
944 class AdjustPointerClosure: public ExtendedOopClosure {
945 public:
946 template <typename T> void do_oop_nv(T* p);
947 virtual void do_oop(oop* p);
948 virtual void do_oop(narrowOop* p);
949
950 // This closure provides its own oop verification code.
951 debug_only(virtual bool should_verify_oops() { return false; })
952 };
953
954 class AdjustKlassClosure : public KlassClosure {
955 public:
956 void do_klass(Klass* klass);
957 };
958
959 friend class FollowStackClosure;
960 friend class AdjustPointerClosure;
961 friend class AdjustKlassClosure;
962 friend class FollowKlassClosure;
963 friend class InstanceClassLoaderKlass;
964 friend class RefProcTaskProxy;
965
966 private:
967 static STWGCTimer _gc_timer;
968 static ParallelOldTracer _gc_tracer;
969 static elapsedTimer _accumulated_time;
970 static unsigned int _total_invocations;
971 static unsigned int _maximum_compaction_gc_num;
972 static jlong _time_of_last_gc; // ms
973 static CollectorCounters* _counters;
974 static ParMarkBitMap _mark_bitmap;
975 static ParallelCompactData _summary_data;
976 static IsAliveClosure _is_alive_closure;
977 static SpaceInfo _space_info[last_space_id];
978 static bool _print_phases;
979 static AdjustPointerClosure _adjust_pointer_closure;
980 static AdjustKlassClosure _adjust_klass_closure;
981
982 // Reference processing (used in ...follow_contents)
983 static ReferenceProcessor* _ref_processor;
1110 // Add dense prefix update tasks to the task queue.
1111 static void enqueue_dense_prefix_tasks(GCTaskQueue* q,
1112 uint parallel_gc_threads);
1113
1114 // Add region stealing tasks to the task queue.
1115 static void enqueue_region_stealing_tasks(
1116 GCTaskQueue* q,
1117 ParallelTaskTerminator* terminator_ptr,
1118 uint parallel_gc_threads);
1119
1120 // If objects are left in eden after a collection, try to move the boundary
1121 // and absorb them into the old gen. Returns true if eden was emptied.
1122 static bool absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
1123 PSYoungGen* young_gen,
1124 PSOldGen* old_gen);
1125
1126 // Reset time since last full gc
1127 static void reset_millis_since_last_gc();
1128
1129 public:
1130 class MarkAndPushClosure: public ExtendedOopClosure {
1131 private:
1132 ParCompactionManager* _compaction_manager;
1133 public:
1134 MarkAndPushClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
1135
1136 template <typename T> void do_oop_nv(T* p);
1137 virtual void do_oop(oop* p);
1138 virtual void do_oop(narrowOop* p);
1139
1140 // This closure provides its own oop verification code.
1141 debug_only(virtual bool should_verify_oops() { return false; })
1142 };
1143
1144 // The one and only place to start following the classes.
1145 // Should only be applied to the ClassLoaderData klasses list.
1146 class FollowKlassClosure : public KlassClosure {
1147 private:
1148 MarkAndPushClosure* _mark_and_push_closure;
1149 public:
1150 FollowKlassClosure(MarkAndPushClosure* mark_and_push_closure) :
1151 _mark_and_push_closure(mark_and_push_closure) { }
1152 void do_klass(Klass* klass);
1153 };
1154
1155 PSParallelCompact();
1156
1157 static void invoke(bool maximum_heap_compaction);
1158 static bool invoke_no_policy(bool maximum_heap_compaction);
1159
1160 static void post_initialize();
1161 // Perform initialization for PSParallelCompact that requires
1162 // allocations. This should be called during the VM initialization
1163 // at a pointer where it would be appropriate to return a JNI_ENOMEM
1164 // in the event of a failure.
1165 static bool initialize();
1166
1167 // Closure accessors
1168 static PSParallelCompact::AdjustPointerClosure* adjust_pointer_closure() {
1169 return &_adjust_pointer_closure;
1170 }
1171 static KlassClosure* adjust_klass_closure() { return (KlassClosure*)&_adjust_klass_closure; }
1172 static BoolObjectClosure* is_alive_closure() { return (BoolObjectClosure*)&_is_alive_closure; }
1173
1174 // Public accessors
1175 static elapsedTimer* accumulated_time() { return &_accumulated_time; }
1176 static unsigned int total_invocations() { return _total_invocations; }
1177 static CollectorCounters* counters() { return _counters; }
1178
1179 // Used to add tasks
1180 static GCTaskManager* const gc_task_manager();
1181
1182 // Marking support
1183 static inline bool mark_obj(oop obj);
1184 static inline bool is_marked(oop obj);
1185 // Check mark and maybe push on marking stack
1186 template <class T> static inline void mark_and_push(ParCompactionManager* cm,
1187 T* p);
1188 template <class T> static inline void adjust_pointer(T* p);
1189
1190 static inline void follow_klass(ParCompactionManager* cm, Klass* klass);
1191
1192 static void follow_class_loader(ParCompactionManager* cm,
1193 ClassLoaderData* klass);
1194
1195 // Compaction support.
1196 // Return true if p is in the range [beg_addr, end_addr).
1197 static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);
1198 static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);
1199
1200 // Convenience wrappers for per-space data kept in _space_info.
1201 static inline MutableSpace* space(SpaceId space_id);
1202 static inline HeapWord* new_top(SpaceId space_id);
1203 static inline HeapWord* dense_prefix(SpaceId space_id);
1204 static inline ObjectStartArray* start_array(SpaceId space_id);
1205
1206 // Move and update the live objects in the specified space.
1207 static void move_and_update(ParCompactionManager* cm, SpaceId space_id);
1208
1209 // Process the end of the given region range in the dense prefix.
1210 // This includes saving any object not updated.
1211 static void dense_prefix_regions_epilogue(ParCompactionManager* cm,
1212 size_t region_start_index,
1213 size_t region_end_index,
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
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 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP
26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP
27
28 #include "gc_implementation/parallelScavenge/objectStartArray.hpp"
29 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.hpp"
30 #include "gc_implementation/parallelScavenge/parMarkBitMap.hpp"
31 #include "gc_implementation/shared/collectorCounters.hpp"
32 #include "gc_implementation/shared/mutableSpace.hpp"
33 #include "gc_interface/collectedHeap.hpp"
34 #include "oops/oop.hpp"
35
36 class ParallelScavengeHeap;
37 class PSAdaptiveSizePolicy;
38 class PSYoungGen;
39 class PSOldGen;
40 class ParCompactionManager;
41 class ParallelTaskTerminator;
42 class PSParallelCompact;
43 class GCTaskManager;
44 class GCTaskQueue;
45 class PreGCValues;
46 class MoveAndUpdateClosure;
47 class RefProcTaskExecutor;
48 class ParallelOldTracer;
49 class STWGCTimer;
50
915 class PSParallelCompact : AllStatic {
916 public:
917 // Convenient access to type names.
918 typedef ParMarkBitMap::idx_t idx_t;
919 typedef ParallelCompactData::RegionData RegionData;
920 typedef ParallelCompactData::BlockData BlockData;
921
922 typedef enum {
923 old_space_id, eden_space_id,
924 from_space_id, to_space_id, last_space_id
925 } SpaceId;
926
927 public:
928 // Inline closure decls
929 //
930 class IsAliveClosure: public BoolObjectClosure {
931 public:
932 virtual bool do_object_b(oop p);
933 };
934
935 class AdjustPointerClosure: public ExtendedOopClosure {
936 public:
937 template <typename T> void do_oop_nv(T* p);
938 virtual void do_oop(oop* p);
939 virtual void do_oop(narrowOop* p);
940
941 // This closure provides its own oop verification code.
942 debug_only(virtual bool should_verify_oops() { return false; })
943 };
944
945 class AdjustKlassClosure : public KlassClosure {
946 public:
947 void do_klass(Klass* klass);
948 };
949
950 friend class AdjustPointerClosure;
951 friend class AdjustKlassClosure;
952 friend class RefProcTaskProxy;
953
954 private:
955 static STWGCTimer _gc_timer;
956 static ParallelOldTracer _gc_tracer;
957 static elapsedTimer _accumulated_time;
958 static unsigned int _total_invocations;
959 static unsigned int _maximum_compaction_gc_num;
960 static jlong _time_of_last_gc; // ms
961 static CollectorCounters* _counters;
962 static ParMarkBitMap _mark_bitmap;
963 static ParallelCompactData _summary_data;
964 static IsAliveClosure _is_alive_closure;
965 static SpaceInfo _space_info[last_space_id];
966 static bool _print_phases;
967 static AdjustPointerClosure _adjust_pointer_closure;
968 static AdjustKlassClosure _adjust_klass_closure;
969
970 // Reference processing (used in ...follow_contents)
971 static ReferenceProcessor* _ref_processor;
1098 // Add dense prefix update tasks to the task queue.
1099 static void enqueue_dense_prefix_tasks(GCTaskQueue* q,
1100 uint parallel_gc_threads);
1101
1102 // Add region stealing tasks to the task queue.
1103 static void enqueue_region_stealing_tasks(
1104 GCTaskQueue* q,
1105 ParallelTaskTerminator* terminator_ptr,
1106 uint parallel_gc_threads);
1107
1108 // If objects are left in eden after a collection, try to move the boundary
1109 // and absorb them into the old gen. Returns true if eden was emptied.
1110 static bool absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
1111 PSYoungGen* young_gen,
1112 PSOldGen* old_gen);
1113
1114 // Reset time since last full gc
1115 static void reset_millis_since_last_gc();
1116
1117 public:
1118
1119 PSParallelCompact();
1120
1121 static void invoke(bool maximum_heap_compaction);
1122 static bool invoke_no_policy(bool maximum_heap_compaction);
1123
1124 static void post_initialize();
1125 // Perform initialization for PSParallelCompact that requires
1126 // allocations. This should be called during the VM initialization
1127 // at a pointer where it would be appropriate to return a JNI_ENOMEM
1128 // in the event of a failure.
1129 static bool initialize();
1130
1131 // Closure accessors
1132 static PSParallelCompact::AdjustPointerClosure* adjust_pointer_closure() {
1133 return &_adjust_pointer_closure;
1134 }
1135 static KlassClosure* adjust_klass_closure() { return (KlassClosure*)&_adjust_klass_closure; }
1136 static BoolObjectClosure* is_alive_closure() { return (BoolObjectClosure*)&_is_alive_closure; }
1137
1138 // Public accessors
1139 static elapsedTimer* accumulated_time() { return &_accumulated_time; }
1140 static unsigned int total_invocations() { return _total_invocations; }
1141 static CollectorCounters* counters() { return _counters; }
1142
1143 // Used to add tasks
1144 static GCTaskManager* const gc_task_manager();
1145
1146 // Marking support
1147 static inline bool mark_obj(oop obj);
1148 static inline bool is_marked(oop obj);
1149
1150 template <class T> static inline void adjust_pointer(T* p);
1151
1152 // Compaction support.
1153 // Return true if p is in the range [beg_addr, end_addr).
1154 static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);
1155 static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);
1156
1157 // Convenience wrappers for per-space data kept in _space_info.
1158 static inline MutableSpace* space(SpaceId space_id);
1159 static inline HeapWord* new_top(SpaceId space_id);
1160 static inline HeapWord* dense_prefix(SpaceId space_id);
1161 static inline ObjectStartArray* start_array(SpaceId space_id);
1162
1163 // Move and update the live objects in the specified space.
1164 static void move_and_update(ParCompactionManager* cm, SpaceId space_id);
1165
1166 // Process the end of the given region range in the dense prefix.
1167 // This includes saving any object not updated.
1168 static void dense_prefix_regions_epilogue(ParCompactionManager* cm,
1169 size_t region_start_index,
1170 size_t region_end_index,
|