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 KeepAliveClosure: public OopClosure {
937 private:
938 ParCompactionManager* _compaction_manager;
939 protected:
940 template <class T> inline void do_oop_work(T* p);
941 public:
942 KeepAliveClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
943 virtual void do_oop(oop* p);
944 virtual void do_oop(narrowOop* p);
945 };
946
947 class FollowStackClosure: public VoidClosure {
948 private:
949 ParCompactionManager* _compaction_manager;
950 public:
951 FollowStackClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
952 virtual void do_void();
953 };
954
955 class AdjustPointerClosure: public ExtendedOopClosure {
956 public:
957 template <typename T> void do_oop_nv(T* p);
958 virtual void do_oop(oop* p);
959 virtual void do_oop(narrowOop* p);
960
961 // This closure provides its own oop verification code.
962 debug_only(virtual bool should_verify_oops() { return false; })
963 };
964
965 class AdjustKlassClosure : public KlassClosure {
966 public:
967 void do_klass(Klass* klass);
968 };
969
970 friend class KeepAliveClosure;
971 friend class FollowStackClosure;
972 friend class AdjustPointerClosure;
973 friend class AdjustKlassClosure;
974 friend class FollowKlassClosure;
975 friend class InstanceClassLoaderKlass;
976 friend class RefProcTaskProxy;
977
978 private:
979 static STWGCTimer _gc_timer;
980 static ParallelOldTracer _gc_tracer;
981 static elapsedTimer _accumulated_time;
982 static unsigned int _total_invocations;
983 static unsigned int _maximum_compaction_gc_num;
984 static jlong _time_of_last_gc; // ms
985 static CollectorCounters* _counters;
986 static ParMarkBitMap _mark_bitmap;
987 static ParallelCompactData _summary_data;
988 static IsAliveClosure _is_alive_closure;
989 static SpaceInfo _space_info[last_space_id];
990 static bool _print_phases;
1125 // Add dense prefix update tasks to the task queue.
1126 static void enqueue_dense_prefix_tasks(GCTaskQueue* q,
1127 uint parallel_gc_threads);
1128
1129 // Add region stealing tasks to the task queue.
1130 static void enqueue_region_stealing_tasks(
1131 GCTaskQueue* q,
1132 ParallelTaskTerminator* terminator_ptr,
1133 uint parallel_gc_threads);
1134
1135 // If objects are left in eden after a collection, try to move the boundary
1136 // and absorb them into the old gen. Returns true if eden was emptied.
1137 static bool absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
1138 PSYoungGen* young_gen,
1139 PSOldGen* old_gen);
1140
1141 // Reset time since last full gc
1142 static void reset_millis_since_last_gc();
1143
1144 public:
1145 class MarkAndPushClosure: public ExtendedOopClosure {
1146 private:
1147 ParCompactionManager* _compaction_manager;
1148 public:
1149 MarkAndPushClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
1150
1151 template <typename T> void do_oop_nv(T* p);
1152 virtual void do_oop(oop* p);
1153 virtual void do_oop(narrowOop* p);
1154
1155 // This closure provides its own oop verification code.
1156 debug_only(virtual bool should_verify_oops() { return false; })
1157 };
1158
1159 // The one and only place to start following the classes.
1160 // Should only be applied to the ClassLoaderData klasses list.
1161 class FollowKlassClosure : public KlassClosure {
1162 private:
1163 MarkAndPushClosure* _mark_and_push_closure;
1164 public:
1165 FollowKlassClosure(MarkAndPushClosure* mark_and_push_closure) :
1166 _mark_and_push_closure(mark_and_push_closure) { }
1167 void do_klass(Klass* klass);
1168 };
1169
1170 PSParallelCompact();
1171
1172 static void invoke(bool maximum_heap_compaction);
1173 static bool invoke_no_policy(bool maximum_heap_compaction);
1174
1175 static void post_initialize();
1176 // Perform initialization for PSParallelCompact that requires
1177 // allocations. This should be called during the VM initialization
1178 // at a pointer where it would be appropriate to return a JNI_ENOMEM
1179 // in the event of a failure.
1180 static bool initialize();
1181
1182 // Closure accessors
1183 static PSParallelCompact::AdjustPointerClosure* adjust_pointer_closure() {
1184 return &_adjust_pointer_closure;
1185 }
1186 static KlassClosure* adjust_klass_closure() { return (KlassClosure*)&_adjust_klass_closure; }
1187 static BoolObjectClosure* is_alive_closure() { return (BoolObjectClosure*)&_is_alive_closure; }
1188
1189 // Public accessors
1190 static elapsedTimer* accumulated_time() { return &_accumulated_time; }
1191 static unsigned int total_invocations() { return _total_invocations; }
1192 static CollectorCounters* counters() { return _counters; }
1193
1194 // Used to add tasks
1195 static GCTaskManager* const gc_task_manager();
1196 static Klass* updated_int_array_klass_obj() {
1197 return _updated_int_array_klass_obj;
1198 }
1199
1200 // Marking support
1201 static inline bool mark_obj(oop obj);
1202 static inline bool is_marked(oop obj);
1203 // Check mark and maybe push on marking stack
1204 template <class T> static inline void mark_and_push(ParCompactionManager* cm,
1205 T* p);
1206 template <class T> static inline void adjust_pointer(T* p);
1207
1208 static inline void follow_klass(ParCompactionManager* cm, Klass* klass);
1209
1210 static void follow_class_loader(ParCompactionManager* cm,
1211 ClassLoaderData* klass);
1212
1213 // Compaction support.
1214 // Return true if p is in the range [beg_addr, end_addr).
1215 static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);
1216 static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);
1217
1218 // Convenience wrappers for per-space data kept in _space_info.
1219 static inline MutableSpace* space(SpaceId space_id);
1220 static inline HeapWord* new_top(SpaceId space_id);
1221 static inline HeapWord* dense_prefix(SpaceId space_id);
1222 static inline ObjectStartArray* start_array(SpaceId space_id);
1223
1224 // Move and update the live objects in the specified space.
1225 static void move_and_update(ParCompactionManager* cm, SpaceId space_id);
1226
1227 // Process the end of the given region range in the dense prefix.
1228 // This includes saving any object not updated.
1318 #ifdef ASSERT
1319 // Sanity check the new location of a word in the heap.
1320 static inline void check_new_location(HeapWord* old_addr, HeapWord* new_addr);
1321 // Verify that all the regions have been emptied.
1322 static void verify_complete(SpaceId space_id);
1323 #endif // #ifdef ASSERT
1324 };
1325
1326 inline bool PSParallelCompact::mark_obj(oop obj) {
1327 const int obj_size = obj->size();
1328 if (mark_bitmap()->mark_obj(obj, obj_size)) {
1329 _summary_data.add_obj(obj, obj_size);
1330 return true;
1331 } else {
1332 return false;
1333 }
1334 }
1335
1336 inline bool PSParallelCompact::is_marked(oop obj) {
1337 return mark_bitmap()->is_marked(obj);
1338 }
1339
1340 template <class T>
1341 inline void PSParallelCompact::KeepAliveClosure::do_oop_work(T* p) {
1342 mark_and_push(_compaction_manager, p);
1343 }
1344
1345 inline bool PSParallelCompact::print_phases() {
1346 return _print_phases;
1347 }
1348
1349 inline double PSParallelCompact::normal_distribution(double density) {
1350 assert(_dwl_initialized, "uninitialized");
1351 const double squared_term = (density - _dwl_mean) / _dwl_std_dev;
1352 return _dwl_first_term * exp(-0.5 * squared_term * squared_term);
1353 }
1354
1355 inline bool
1356 PSParallelCompact::dead_space_crosses_boundary(const RegionData* region,
1357 idx_t bit)
1358 {
1359 assert(bit > 0, "cannot call this for the first bit/region");
1360 assert(_summary_data.region_to_addr(region) == _mark_bitmap.bit_to_addr(bit),
1361 "sanity check");
1362
|
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 AdjustPointerClosure: public ExtendedOopClosure {
937 public:
938 template <typename T> void do_oop_nv(T* p);
939 virtual void do_oop(oop* p);
940 virtual void do_oop(narrowOop* p);
941
942 // This closure provides its own oop verification code.
943 debug_only(virtual bool should_verify_oops() { return false; })
944 };
945
946 class AdjustKlassClosure : public KlassClosure {
947 public:
948 void do_klass(Klass* klass);
949 };
950
951 friend class FollowStackClosure;
952 friend class AdjustPointerClosure;
953 friend class AdjustKlassClosure;
954 friend class FollowKlassClosure;
955 friend class InstanceClassLoaderKlass;
956 friend class RefProcTaskProxy;
957
958 private:
959 static STWGCTimer _gc_timer;
960 static ParallelOldTracer _gc_tracer;
961 static elapsedTimer _accumulated_time;
962 static unsigned int _total_invocations;
963 static unsigned int _maximum_compaction_gc_num;
964 static jlong _time_of_last_gc; // ms
965 static CollectorCounters* _counters;
966 static ParMarkBitMap _mark_bitmap;
967 static ParallelCompactData _summary_data;
968 static IsAliveClosure _is_alive_closure;
969 static SpaceInfo _space_info[last_space_id];
970 static bool _print_phases;
1105 // Add dense prefix update tasks to the task queue.
1106 static void enqueue_dense_prefix_tasks(GCTaskQueue* q,
1107 uint parallel_gc_threads);
1108
1109 // Add region stealing tasks to the task queue.
1110 static void enqueue_region_stealing_tasks(
1111 GCTaskQueue* q,
1112 ParallelTaskTerminator* terminator_ptr,
1113 uint parallel_gc_threads);
1114
1115 // If objects are left in eden after a collection, try to move the boundary
1116 // and absorb them into the old gen. Returns true if eden was emptied.
1117 static bool absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
1118 PSYoungGen* young_gen,
1119 PSOldGen* old_gen);
1120
1121 // Reset time since last full gc
1122 static void reset_millis_since_last_gc();
1123
1124 public:
1125
1126 PSParallelCompact();
1127
1128 static void invoke(bool maximum_heap_compaction);
1129 static bool invoke_no_policy(bool maximum_heap_compaction);
1130
1131 static void post_initialize();
1132 // Perform initialization for PSParallelCompact that requires
1133 // allocations. This should be called during the VM initialization
1134 // at a pointer where it would be appropriate to return a JNI_ENOMEM
1135 // in the event of a failure.
1136 static bool initialize();
1137
1138 // Closure accessors
1139 static PSParallelCompact::AdjustPointerClosure* adjust_pointer_closure() {
1140 return &_adjust_pointer_closure;
1141 }
1142 static KlassClosure* adjust_klass_closure() { return (KlassClosure*)&_adjust_klass_closure; }
1143 static BoolObjectClosure* is_alive_closure() { return (BoolObjectClosure*)&_is_alive_closure; }
1144
1145 // Public accessors
1146 static elapsedTimer* accumulated_time() { return &_accumulated_time; }
1147 static unsigned int total_invocations() { return _total_invocations; }
1148 static CollectorCounters* counters() { return _counters; }
1149
1150 // Used to add tasks
1151 static GCTaskManager* const gc_task_manager();
1152 static Klass* updated_int_array_klass_obj() {
1153 return _updated_int_array_klass_obj;
1154 }
1155
1156 // Marking support
1157 static inline bool mark_obj(oop obj);
1158 static inline bool is_marked(oop obj);
1159
1160 template <class T> static inline void adjust_pointer(T* p);
1161
1162 static void follow_class_loader(ParCompactionManager* cm,
1163 ClassLoaderData* klass);
1164
1165 // Compaction support.
1166 // Return true if p is in the range [beg_addr, end_addr).
1167 static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);
1168 static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);
1169
1170 // Convenience wrappers for per-space data kept in _space_info.
1171 static inline MutableSpace* space(SpaceId space_id);
1172 static inline HeapWord* new_top(SpaceId space_id);
1173 static inline HeapWord* dense_prefix(SpaceId space_id);
1174 static inline ObjectStartArray* start_array(SpaceId space_id);
1175
1176 // Move and update the live objects in the specified space.
1177 static void move_and_update(ParCompactionManager* cm, SpaceId space_id);
1178
1179 // Process the end of the given region range in the dense prefix.
1180 // This includes saving any object not updated.
1270 #ifdef ASSERT
1271 // Sanity check the new location of a word in the heap.
1272 static inline void check_new_location(HeapWord* old_addr, HeapWord* new_addr);
1273 // Verify that all the regions have been emptied.
1274 static void verify_complete(SpaceId space_id);
1275 #endif // #ifdef ASSERT
1276 };
1277
1278 inline bool PSParallelCompact::mark_obj(oop obj) {
1279 const int obj_size = obj->size();
1280 if (mark_bitmap()->mark_obj(obj, obj_size)) {
1281 _summary_data.add_obj(obj, obj_size);
1282 return true;
1283 } else {
1284 return false;
1285 }
1286 }
1287
1288 inline bool PSParallelCompact::is_marked(oop obj) {
1289 return mark_bitmap()->is_marked(obj);
1290 }
1291
1292 inline bool PSParallelCompact::print_phases() {
1293 return _print_phases;
1294 }
1295
1296 inline double PSParallelCompact::normal_distribution(double density) {
1297 assert(_dwl_initialized, "uninitialized");
1298 const double squared_term = (density - _dwl_mean) / _dwl_std_dev;
1299 return _dwl_first_term * exp(-0.5 * squared_term * squared_term);
1300 }
1301
1302 inline bool
1303 PSParallelCompact::dead_space_crosses_boundary(const RegionData* region,
1304 idx_t bit)
1305 {
1306 assert(bit > 0, "cannot call this for the first bit/region");
1307 assert(_summary_data.region_to_addr(region) == _mark_bitmap.bit_to_addr(bit),
1308 "sanity check");
1309
|