< prev index next >

src/share/vm/gc/parallel/psParallelCompact.cpp

Print this page




 178   assert(_src_region_idx == 0, "not clear");
 179   assert(_partial_obj_size == 0, "not clear");
 180   assert(_destination == NULL, "not clear");
 181   assert(_destination_count == 0, "not clear");
 182   assert(_dest_region_addr == NULL, "not clear");
 183   assert(_first_src_addr == NULL, "not clear");
 184 }
 185 #endif  // #ifdef ASSERT
 186 
 187 
 188 void PSParallelCompact::print_on_error(outputStream* st) {
 189   _mark_bitmap.print_on_error(st);
 190 }
 191 
 192 #ifndef PRODUCT
 193 const char* PSParallelCompact::space_names[] = {
 194   "old ", "eden", "from", "to  "
 195 };
 196 
 197 void PSParallelCompact::print_region_ranges() {
 198   if (!log_develop_is_enabled(Trace, gc, compaction, phases)) {
 199     return;
 200   }
 201   LogHandle(gc, compaction, phases) log;
 202   ResourceMark rm;
 203   Universe::print_on(log.trace_stream());
 204   log.trace("space  bottom     top        end        new_top");
 205   log.trace("------ ---------- ---------- ---------- ----------");
 206 
 207   for (unsigned int id = 0; id < last_space_id; ++id) {
 208     const MutableSpace* space = _space_info[id].space();
 209     log.trace("%u %s "
 210               SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " "
 211               SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " ",
 212               id, space_names[id],
 213               summary_data().addr_to_region_idx(space->bottom()),
 214               summary_data().addr_to_region_idx(space->top()),
 215               summary_data().addr_to_region_idx(space->end()),
 216               summary_data().addr_to_region_idx(_space_info[id].new_top()));
 217   }
 218 }
 219 
 220 void
 221 print_generic_summary_region(size_t i, const ParallelCompactData::RegionData* c)
 222 {
 223 #define REGION_IDX_FORMAT        SIZE_FORMAT_W(7)
 224 #define REGION_DATA_FORMAT       SIZE_FORMAT_W(5)
 225 
 226   ParallelCompactData& sd = PSParallelCompact::summary_data();
 227   size_t dci = c->destination() ? sd.addr_to_region_idx(c->destination()) : 0;
 228   log_develop_trace(gc, compaction, phases)(
 229       REGION_IDX_FORMAT " " PTR_FORMAT " "
 230       REGION_IDX_FORMAT " " PTR_FORMAT " "
 231       REGION_DATA_FORMAT " " REGION_DATA_FORMAT " "
 232       REGION_DATA_FORMAT " " REGION_IDX_FORMAT " %d",
 233       i, p2i(c->data_location()), dci, p2i(c->destination()),
 234       c->partial_obj_size(), c->live_obj_size(),
 235       c->data_size(), c->source_region(), c->destination_count());
 236 
 237 #undef  REGION_IDX_FORMAT
 238 #undef  REGION_DATA_FORMAT
 239 }
 240 
 241 void
 242 print_generic_summary_data(ParallelCompactData& summary_data,
 243                            HeapWord* const beg_addr,
 244                            HeapWord* const end_addr)
 245 {
 246   size_t total_words = 0;
 247   size_t i = summary_data.addr_to_region_idx(beg_addr);
 248   const size_t last = summary_data.addr_to_region_idx(end_addr);
 249   HeapWord* pdest = 0;
 250 
 251   while (i <= last) {
 252     ParallelCompactData::RegionData* c = summary_data.region(i);
 253     if (c->data_size() != 0 || c->destination() != pdest) {
 254       print_generic_summary_region(i, c);
 255       total_words += c->data_size();
 256       pdest = c->destination();
 257     }
 258     ++i;
 259   }
 260 
 261   log_develop_trace(gc, compaction, phases)("summary_data_bytes=" SIZE_FORMAT, total_words * HeapWordSize);
 262 }
 263 
 264 void
 265 print_generic_summary_data(ParallelCompactData& summary_data,
 266                            SpaceInfo* space_info)
 267 {
 268   if (!log_develop_is_enabled(Trace, gc, compaction, phases)) {
 269     return;
 270   }
 271 
 272   for (unsigned int id = 0; id < PSParallelCompact::last_space_id; ++id) {
 273     const MutableSpace* space = space_info[id].space();
 274     print_generic_summary_data(summary_data, space->bottom(),
 275                                MAX2(space->top(), space_info[id].new_top()));
 276   }
 277 }
 278 
 279 void
 280 print_initial_summary_data(ParallelCompactData& summary_data,
 281                            const MutableSpace* space) {
 282   if (space->top() == space->bottom()) {
 283     return;
 284   }
 285 
 286   const size_t region_size = ParallelCompactData::RegionSize;
 287   typedef ParallelCompactData::RegionData RegionData;
 288   HeapWord* const top_aligned_up = summary_data.region_align_up(space->top());
 289   const size_t end_region = summary_data.addr_to_region_idx(top_aligned_up);
 290   const RegionData* c = summary_data.region(end_region - 1);
 291   HeapWord* end_addr = c->destination() + c->data_size();
 292   const size_t live_in_space = pointer_delta(end_addr, space->bottom());
 293 
 294   // Print (and count) the full regions at the beginning of the space.
 295   size_t full_region_count = 0;
 296   size_t i = summary_data.addr_to_region_idx(space->bottom());
 297   while (i < end_region && summary_data.region(i)->data_size() == region_size) {
 298     ParallelCompactData::RegionData* c = summary_data.region(i);
 299     log_develop_trace(gc, compaction, phases)(
 300         SIZE_FORMAT_W(5) " " PTR_FORMAT " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d",
 301         i, p2i(c->destination()),
 302         c->partial_obj_size(), c->live_obj_size(),
 303         c->data_size(), c->source_region(), c->destination_count());
 304     ++full_region_count;
 305     ++i;
 306   }
 307 
 308   size_t live_to_right = live_in_space - full_region_count * region_size;
 309 
 310   double max_reclaimed_ratio = 0.0;
 311   size_t max_reclaimed_ratio_region = 0;
 312   size_t max_dead_to_right = 0;
 313   size_t max_live_to_right = 0;
 314 
 315   // Print the 'reclaimed ratio' for regions while there is something live in
 316   // the region or to the right of it.  The remaining regions are empty (and
 317   // uninteresting), and computing the ratio will result in division by 0.
 318   while (i < end_region && live_to_right > 0) {
 319     c = summary_data.region(i);
 320     HeapWord* const region_addr = summary_data.region_to_addr(i);
 321     const size_t used_to_right = pointer_delta(space->top(), region_addr);
 322     const size_t dead_to_right = used_to_right - live_to_right;
 323     const double reclaimed_ratio = double(dead_to_right) / live_to_right;
 324 
 325     if (reclaimed_ratio > max_reclaimed_ratio) {
 326             max_reclaimed_ratio = reclaimed_ratio;
 327             max_reclaimed_ratio_region = i;
 328             max_dead_to_right = dead_to_right;
 329             max_live_to_right = live_to_right;
 330     }
 331 
 332     ParallelCompactData::RegionData* c = summary_data.region(i);
 333     log_develop_trace(gc, compaction, phases)(
 334         SIZE_FORMAT_W(5) " " PTR_FORMAT " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d"
 335         "%12.10f " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10),
 336         i, p2i(c->destination()),
 337         c->partial_obj_size(), c->live_obj_size(),
 338         c->data_size(), c->source_region(), c->destination_count(),
 339         reclaimed_ratio, dead_to_right, live_to_right);
 340 
 341 
 342     live_to_right -= c->data_size();
 343     ++i;
 344   }
 345 
 346   // Any remaining regions are empty.  Print one more if there is one.
 347   if (i < end_region) {
 348     ParallelCompactData::RegionData* c = summary_data.region(i);
 349     log_develop_trace(gc, compaction, phases)(
 350         SIZE_FORMAT_W(5) " " PTR_FORMAT " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d",
 351          i, p2i(c->destination()),
 352          c->partial_obj_size(), c->live_obj_size(),
 353          c->data_size(), c->source_region(), c->destination_count());
 354   }
 355 
 356   log_develop_trace(gc, compaction, phases)("max:  " SIZE_FORMAT_W(4) " d2r=" SIZE_FORMAT_W(10) " l2r=" SIZE_FORMAT_W(10) " max_ratio=%14.12f",
 357                                             max_reclaimed_ratio_region, max_dead_to_right, max_live_to_right, max_reclaimed_ratio);
 358 }
 359 
 360 void
 361 print_initial_summary_data(ParallelCompactData& summary_data,
 362                            SpaceInfo* space_info) {
 363   if (!log_develop_is_enabled(Trace, gc, compaction, phases)) {
 364     return;
 365   }
 366 
 367   unsigned int id = PSParallelCompact::old_space_id;
 368   const MutableSpace* space;
 369   do {
 370     space = space_info[id].space();
 371     print_initial_summary_data(summary_data, space);
 372   } while (++id < PSParallelCompact::eden_space_id);
 373 
 374   do {
 375     space = space_info[id].space();
 376     print_generic_summary_data(summary_data, space->bottom(), space->top());
 377   } while (++id < PSParallelCompact::last_space_id);
 378 }
 379 #endif  // #ifndef PRODUCT
 380 
 381 #ifdef  ASSERT
 382 size_t add_obj_count;
 383 size_t add_obj_size;


 604     // implies a region must be filled).
 605     //
 606     // An alternative to the simple loop below:  clear during post_compact(),
 607     // which uses memcpy instead of individual stores, and is easy to
 608     // parallelize.  (The downside is that it clears the entire RegionData
 609     // object as opposed to just one field.)
 610     //
 611     // post_compact() would have to clear the summary data up to the highest
 612     // address that was written during the summary phase, which would be
 613     //
 614     //         max(top, max(new_top, clear_top))
 615     //
 616     // where clear_top is a new field in SpaceInfo.  Would have to set clear_top
 617     // to target_end.
 618     const RegionData* const sr = region(split_region);
 619     const size_t beg_idx =
 620       addr_to_region_idx(region_align_up(sr->destination() +
 621                                          sr->partial_obj_size()));
 622     const size_t end_idx = addr_to_region_idx(target_end);
 623 
 624     log_develop_trace(gc, compaction, phases)("split:  clearing source_region field in [" SIZE_FORMAT ", " SIZE_FORMAT ")", beg_idx, end_idx);
 625     for (size_t idx = beg_idx; idx < end_idx; ++idx) {
 626       _region_data[idx].set_source_region(0);
 627     }
 628 
 629     // Set split_destination and partial_obj_size to reflect the split region.
 630     split_destination = sr->destination();
 631     partial_obj_size = sr->partial_obj_size();
 632   }
 633 
 634   // The split is recorded only if a partial object extends onto the region.
 635   if (partial_obj_size != 0) {
 636     _region_data[split_region].set_partial_obj_size(0);
 637     split_info.record(split_region, partial_obj_size, split_destination);
 638   }
 639 
 640   // Setup the continuation addresses.
 641   *target_next = split_destination + partial_obj_size;
 642   HeapWord* const source_next = region_to_addr(split_region) + partial_obj_size;
 643 
 644   if (log_develop_is_enabled(Trace, gc, compaction, phases)) {
 645     const char * split_type = partial_obj_size == 0 ? "easy" : "hard";
 646     log_develop_trace(gc, compaction, phases)("%s split:  src=" PTR_FORMAT " src_c=" SIZE_FORMAT " pos=" SIZE_FORMAT,
 647                                               split_type, p2i(source_next), split_region, partial_obj_size);
 648     log_develop_trace(gc, compaction, phases)("%s split:  dst=" PTR_FORMAT " dst_c=" SIZE_FORMAT " tn=" PTR_FORMAT,
 649                                               split_type, p2i(split_destination),
 650                                               addr_to_region_idx(split_destination),
 651                                               p2i(*target_next));
 652 
 653     if (partial_obj_size != 0) {
 654       HeapWord* const po_beg = split_info.destination();
 655       HeapWord* const po_end = po_beg + split_info.partial_obj_size();
 656       log_develop_trace(gc, compaction, phases)("%s split:  po_beg=" PTR_FORMAT " " SIZE_FORMAT " po_end=" PTR_FORMAT " " SIZE_FORMAT,
 657                                                 split_type,
 658                                                 p2i(po_beg), addr_to_region_idx(po_beg),
 659                                                 p2i(po_end), addr_to_region_idx(po_end));
 660     }
 661   }
 662 
 663   return source_next;
 664 }
 665 
 666 bool ParallelCompactData::summarize(SplitInfo& split_info,
 667                                     HeapWord* source_beg, HeapWord* source_end,
 668                                     HeapWord** source_next,
 669                                     HeapWord* target_beg, HeapWord* target_end,
 670                                     HeapWord** target_next)
 671 {
 672   HeapWord* const source_next_val = source_next == NULL ? NULL : *source_next;
 673   log_develop_trace(gc, compaction, phases)(
 674       "sb=" PTR_FORMAT " se=" PTR_FORMAT " sn=" PTR_FORMAT
 675       "tb=" PTR_FORMAT " te=" PTR_FORMAT " tn=" PTR_FORMAT,
 676       p2i(source_beg), p2i(source_end), p2i(source_next_val),
 677       p2i(target_beg), p2i(target_end), p2i(*target_next));
 678 
 679   size_t cur_region = addr_to_region_idx(source_beg);
 680   const size_t end_region = addr_to_region_idx(region_align_up(source_end));
 681 
 682   HeapWord *dest_addr = target_beg;
 683   while (cur_region < end_region) {
 684     // The destination must be set even if the region has no data.
 685     _region_data[cur_region].set_destination(dest_addr);
 686 
 687     size_t words = _region_data[cur_region].data_size();
 688     if (words > 0) {
 689       // If cur_region does not fit entirely into the target space, find a point
 690       // at which the source space can be 'split' so that part is copied to the
 691       // target space and the rest is copied elsewhere.
 692       if (dest_addr + words > target_end) {
 693         assert(source_next != NULL, "source_next is NULL when splitting");


 921 
 922   const size_t beg_region = _summary_data.addr_to_region_idx(bot);
 923   const size_t end_region =
 924     _summary_data.addr_to_region_idx(_summary_data.region_align_up(max_top));
 925   _summary_data.clear_range(beg_region, end_region);
 926 
 927   // Clear the data used to 'split' regions.
 928   SplitInfo& split_info = _space_info[id].split_info();
 929   if (split_info.is_valid()) {
 930     split_info.clear();
 931   }
 932   DEBUG_ONLY(split_info.verify_clear();)
 933 }
 934 
 935 void PSParallelCompact::pre_compact()
 936 {
 937   // Update the from & to space pointers in space_info, since they are swapped
 938   // at each young gen gc.  Do the update unconditionally (even though a
 939   // promotion failure does not swap spaces) because an unknown number of young
 940   // collections will have swapped the spaces an unknown number of times.
 941   GCTraceTime(Trace, gc, phases) tm("Pre Compact", &_gc_timer);
 942   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
 943   _space_info[from_space_id].set_space(heap->young_gen()->from_space());
 944   _space_info[to_space_id].set_space(heap->young_gen()->to_space());
 945 
 946   DEBUG_ONLY(add_obj_count = add_obj_size = 0;)
 947   DEBUG_ONLY(mark_bitmap_count = mark_bitmap_size = 0;)
 948 
 949   // Increment the invocation count
 950   heap->increment_total_collections(true);
 951 
 952   // We need to track unique mark sweep invocations as well.
 953   _total_invocations++;
 954 
 955   heap->print_heap_before_gc();
 956   heap->trace_heap_before_gc(&_gc_tracer);
 957 
 958   // Fill in TLABs
 959   heap->accumulate_statistics_all_tlabs();
 960   heap->ensure_parsability(true);  // retire TLABs
 961 


 964     Universe::verify("Before GC");
 965   }
 966 
 967   // Verify object start arrays
 968   if (VerifyObjectStartArray &&
 969       VerifyBeforeGC) {
 970     heap->old_gen()->verify_object_start_array();
 971   }
 972 
 973   DEBUG_ONLY(mark_bitmap()->verify_clear();)
 974   DEBUG_ONLY(summary_data().verify_clear();)
 975 
 976   // Have worker threads release resources the next time they run a task.
 977   gc_task_manager()->release_all_resources();
 978 
 979   ParCompactionManager::reset_all_bitmap_query_caches();
 980 }
 981 
 982 void PSParallelCompact::post_compact()
 983 {
 984   GCTraceTime(Trace, gc, phases) tm("Post Compact", &_gc_timer);
 985 
 986   for (unsigned int id = old_space_id; id < last_space_id; ++id) {
 987     // Clear the marking bitmap, summary data and split info.
 988     clear_data_covering_space(SpaceId(id));
 989     // Update top().  Must be done after clearing the bitmap and summary data.
 990     _space_info[id].publish_new_top();
 991   }
 992 
 993   MutableSpace* const eden_space = _space_info[eden_space_id].space();
 994   MutableSpace* const from_space = _space_info[from_space_id].space();
 995   MutableSpace* const to_space   = _space_info[to_space_id].space();
 996 
 997   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
 998   bool eden_empty = eden_space->is_empty();
 999   if (!eden_empty) {
1000     eden_empty = absorb_live_data_from_eden(heap->size_policy(),
1001                                             heap->young_gen(), heap->old_gen());
1002   }
1003 
1004   // Update heap occupancy information which is used as input to the soft ref


1507     // Recompute the summary data, taking into account the dense prefix.  If
1508     // every last byte will be reclaimed, then the existing summary data which
1509     // compacts everything can be left in place.
1510     if (!maximum_compaction && dense_prefix_end != space->bottom()) {
1511       // If dead space crosses the dense prefix boundary, it is (at least
1512       // partially) filled with a dummy object, marked live and added to the
1513       // summary data.  This simplifies the copy/update phase and must be done
1514       // before the final locations of objects are determined, to prevent
1515       // leaving a fragment of dead space that is too small to fill.
1516       fill_dense_prefix_end(id);
1517 
1518       // Compute the destination of each Region, and thus each object.
1519       _summary_data.summarize_dense_prefix(space->bottom(), dense_prefix_end);
1520       _summary_data.summarize(_space_info[id].split_info(),
1521                               dense_prefix_end, space->top(), NULL,
1522                               dense_prefix_end, space->end(),
1523                               _space_info[id].new_top_addr());
1524     }
1525   }
1526 
1527   if (log_develop_is_enabled(Trace, gc, compaction, phases)) {
1528     const size_t region_size = ParallelCompactData::RegionSize;
1529     HeapWord* const dense_prefix_end = _space_info[id].dense_prefix();
1530     const size_t dp_region = _summary_data.addr_to_region_idx(dense_prefix_end);
1531     const size_t dp_words = pointer_delta(dense_prefix_end, space->bottom());
1532     HeapWord* const new_top = _space_info[id].new_top();
1533     const HeapWord* nt_aligned_up = _summary_data.region_align_up(new_top);
1534     const size_t cr_words = pointer_delta(nt_aligned_up, dense_prefix_end);
1535     log_develop_trace(gc, compaction, phases)(
1536         "id=%d cap=" SIZE_FORMAT " dp=" PTR_FORMAT " "
1537         "dp_region=" SIZE_FORMAT " " "dp_count=" SIZE_FORMAT " "
1538         "cr_count=" SIZE_FORMAT " " "nt=" PTR_FORMAT,
1539         id, space->capacity_in_words(), p2i(dense_prefix_end),
1540         dp_region, dp_words / region_size,
1541         cr_words / region_size, p2i(new_top));
1542   }
1543 }
1544 
1545 #ifndef PRODUCT
1546 void PSParallelCompact::summary_phase_msg(SpaceId dst_space_id,
1547                                           HeapWord* dst_beg, HeapWord* dst_end,
1548                                           SpaceId src_space_id,
1549                                           HeapWord* src_beg, HeapWord* src_end)
1550 {
1551   log_develop_trace(gc, compaction, phases)(
1552       "Summarizing %d [%s] into %d [%s]:  "
1553       "src=" PTR_FORMAT "-" PTR_FORMAT " "
1554       SIZE_FORMAT "-" SIZE_FORMAT " "
1555       "dst=" PTR_FORMAT "-" PTR_FORMAT " "
1556       SIZE_FORMAT "-" SIZE_FORMAT,
1557       src_space_id, space_names[src_space_id],
1558       dst_space_id, space_names[dst_space_id],
1559       p2i(src_beg), p2i(src_end),
1560       _summary_data.addr_to_region_idx(src_beg),
1561       _summary_data.addr_to_region_idx(src_end),
1562       p2i(dst_beg), p2i(dst_end),
1563       _summary_data.addr_to_region_idx(dst_beg),
1564       _summary_data.addr_to_region_idx(dst_end));
1565 }
1566 #endif  // #ifndef PRODUCT
1567 
1568 void PSParallelCompact::summary_phase(ParCompactionManager* cm,
1569                                       bool maximum_compaction)
1570 {
1571   GCTraceTime(Trace, gc, phases) tm("Summary Phase", &_gc_timer);
1572 
1573 #ifdef  ASSERT
1574   if (TraceParallelOldGCMarkingPhase) {
1575     tty->print_cr("add_obj_count=" SIZE_FORMAT " "
1576                   "add_obj_bytes=" SIZE_FORMAT,
1577                   add_obj_count, add_obj_size * HeapWordSize);
1578     tty->print_cr("mark_bitmap_count=" SIZE_FORMAT " "
1579                   "mark_bitmap_bytes=" SIZE_FORMAT,
1580                   mark_bitmap_count, mark_bitmap_size * HeapWordSize);
1581   }
1582 #endif  // #ifdef ASSERT
1583 
1584   // Quick summarization of each space into itself, to see how much is live.
1585   summarize_spaces_quick();
1586 
1587   log_develop_trace(gc, compaction, phases)("summary phase:  after summarizing each space to self");
1588   NOT_PRODUCT(print_region_ranges());
1589   NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info));
1590 
1591   // The amount of live data that will end up in old space (assuming it fits).
1592   size_t old_space_total_live = 0;
1593   for (unsigned int id = old_space_id; id < last_space_id; ++id) {
1594     old_space_total_live += pointer_delta(_space_info[id].new_top(),
1595                                           _space_info[id].space()->bottom());
1596   }
1597 
1598   MutableSpace* const old_space = _space_info[old_space_id].space();
1599   const size_t old_capacity = old_space->capacity_in_words();
1600   if (old_space_total_live > old_capacity) {
1601     // XXX - should also try to expand
1602     maximum_compaction = true;
1603   }
1604 
1605   // Old generations.
1606   summarize_space(old_space_id, maximum_compaction);
1607 


1643       assert(next_src_addr != NULL, "sanity");
1644 
1645       // The source space becomes the new target, so the remainder is compacted
1646       // within the space itself.
1647       dst_space_id = SpaceId(id);
1648       dst_space_end = space->end();
1649       new_top_addr = _space_info[id].new_top_addr();
1650       NOT_PRODUCT(summary_phase_msg(dst_space_id,
1651                                     space->bottom(), dst_space_end,
1652                                     SpaceId(id), next_src_addr, space->top());)
1653       done = _summary_data.summarize(_space_info[id].split_info(),
1654                                      next_src_addr, space->top(),
1655                                      NULL,
1656                                      space->bottom(), dst_space_end,
1657                                      new_top_addr);
1658       assert(done, "space must fit when compacted into itself");
1659       assert(*new_top_addr <= space->top(), "usage should not grow");
1660     }
1661   }
1662 
1663   log_develop_trace(gc, compaction, phases)("Summary_phase:  after final summarization");
1664   NOT_PRODUCT(print_region_ranges());
1665   NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info));
1666 }
1667 
1668 // This method should contain all heap-specific policy for invoking a full
1669 // collection.  invoke_no_policy() will only attempt to compact the heap; it
1670 // will do nothing further.  If we need to bail out for policy reasons, scavenge
1671 // before full gc, or any other specialized behavior, it needs to be added here.
1672 //
1673 // Note that this method should only be called from the vm_thread while at a
1674 // safepoint.
1675 //
1676 // Note that the all_soft_refs_clear flag in the collector policy
1677 // may be true because this method can be called without intervening
1678 // activity.  For example when the heap space is tight and full measure
1679 // are being taken to free space.
1680 void PSParallelCompact::invoke(bool maximum_heap_compaction) {
1681   assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
1682   assert(Thread::current() == (Thread*)VMThread::vm_thread(),
1683          "should be in vm thread");


2025 
2026   // Could update the promoted average here, but it is not typically updated at
2027   // full GCs and the value to use is unclear.  Something like
2028   //
2029   // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc.
2030 
2031   size_policy->set_bytes_absorbed_from_eden(absorb_size);
2032   return true;
2033 }
2034 
2035 GCTaskManager* const PSParallelCompact::gc_task_manager() {
2036   assert(ParallelScavengeHeap::gc_task_manager() != NULL,
2037     "shouldn't return NULL");
2038   return ParallelScavengeHeap::gc_task_manager();
2039 }
2040 
2041 void PSParallelCompact::marking_phase(ParCompactionManager* cm,
2042                                       bool maximum_heap_compaction,
2043                                       ParallelOldTracer *gc_tracer) {
2044   // Recursively traverse all live objects and mark them
2045   GCTraceTime(Trace, gc, phases) tm("Marking Phase", &_gc_timer);
2046 
2047   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
2048   uint parallel_gc_threads = heap->gc_task_manager()->workers();
2049   uint active_gc_threads = heap->gc_task_manager()->active_workers();
2050   TaskQueueSetSuper* qset = ParCompactionManager::region_array();
2051   ParallelTaskTerminator terminator(active_gc_threads, qset);
2052 
2053   ParCompactionManager::MarkAndPushClosure mark_and_push_closure(cm);
2054   ParCompactionManager::FollowStackClosure follow_stack_closure(cm);
2055 
2056   // Need new claim bits before marking starts.
2057   ClassLoaderDataGraph::clear_claimed_marks();
2058 
2059   {
2060     GCTraceTime(Trace, gc, phases) tm("Par Mark", &_gc_timer);
2061 
2062     ParallelScavengeHeap::ParStrongRootsScope psrs;
2063 
2064     GCTaskQueue* q = GCTaskQueue::create();
2065 
2066     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe));
2067     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles));
2068     // We scan the thread roots in parallel
2069     Threads::create_thread_roots_marking_tasks(q);
2070     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer));
2071     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::flat_profiler));
2072     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management));
2073     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary));
2074     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::class_loader_data));
2075     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti));
2076     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::code_cache));
2077 
2078     if (active_gc_threads > 1) {
2079       for (uint j = 0; j < active_gc_threads; j++) {
2080         q->enqueue(new StealMarkingTask(&terminator));
2081       }
2082     }
2083 
2084     gc_task_manager()->execute_and_wait(q);
2085   }
2086 
2087   // Process reference objects found during marking
2088   {
2089     GCTraceTime(Trace, gc, phases) tm("Reference Processing", &_gc_timer);
2090 
2091     ReferenceProcessorStats stats;
2092     if (ref_processor()->processing_is_mt()) {
2093       RefProcTaskExecutor task_executor;
2094       stats = ref_processor()->process_discovered_references(
2095         is_alive_closure(), &mark_and_push_closure, &follow_stack_closure,
2096         &task_executor, &_gc_timer);
2097     } else {
2098       stats = ref_processor()->process_discovered_references(
2099         is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, NULL,
2100         &_gc_timer);
2101     }
2102 
2103     gc_tracer->report_gc_reference_stats(stats);
2104   }
2105 
2106   // This is the point where the entire marking should have completed.
2107   assert(cm->marking_stacks_empty(), "Marking should have completed");
2108 
2109   {
2110     GCTraceTime(Debug, gc) tm_m("Class Unloading", &_gc_timer);
2111 
2112     // Follow system dictionary roots and unload classes.
2113     bool purged_class = SystemDictionary::do_unloading(is_alive_closure());
2114 
2115     // Unload nmethods.
2116     CodeCache::do_unloading(is_alive_closure(), purged_class);
2117 
2118     // Prune dead klasses from subklass/sibling/implementor lists.
2119     Klass::clean_weak_klass_links(is_alive_closure());
2120   }
2121 
2122   {
2123     GCTraceTime(Debug, gc) t("Scrub String Table", &_gc_timer);
2124     // Delete entries for dead interned strings.
2125     StringTable::unlink(is_alive_closure());
2126   }
2127 
2128   {
2129     GCTraceTime(Debug, gc) t("Scrub Symbol Table", &_gc_timer);
2130     // Clean up unreferenced symbols in symbol table.
2131     SymbolTable::unlink();
2132   }
2133 
2134   _gc_tracer.report_object_count_after_gc(is_alive_closure());
2135 }
2136 
2137 void PSParallelCompact::adjust_roots(ParCompactionManager* cm) {
2138   // Adjust the pointers to reflect the new locations
2139   GCTraceTime(Trace, gc, phases) tm("Adjust Roots", &_gc_timer);
2140 
2141   // Need new claim bits when tracing through and adjusting pointers.
2142   ClassLoaderDataGraph::clear_claimed_marks();
2143 
2144   PSParallelCompact::AdjustPointerClosure oop_closure(cm);
2145   PSParallelCompact::AdjustKlassClosure klass_closure(cm);
2146 
2147   // General strong roots.
2148   Universe::oops_do(&oop_closure);
2149   JNIHandles::oops_do(&oop_closure);   // Global (strong) JNI handles
2150   CLDToOopClosure adjust_from_cld(&oop_closure);
2151   Threads::oops_do(&oop_closure, &adjust_from_cld, NULL);
2152   ObjectSynchronizer::oops_do(&oop_closure);
2153   FlatProfiler::oops_do(&oop_closure);
2154   Management::oops_do(&oop_closure);
2155   JvmtiExport::oops_do(&oop_closure);
2156   SystemDictionary::oops_do(&oop_closure);
2157   ClassLoaderDataGraph::oops_do(&oop_closure, &klass_closure, true);
2158 
2159   // Now adjust pointers in remaining weak roots.  (All of which should


2393 
2394       size_t histo[5] = { 0, 0, 0, 0, 0 };
2395       const size_t histo_len = sizeof(histo) / sizeof(size_t);
2396       const size_t region_cnt = pointer_delta(end, beg, sizeof(rd_t));
2397 
2398       for (const rd_t* cur = beg; cur < end; ++cur) {
2399         ++histo[MIN2(cur->blocks_filled_count(), histo_len - 1)];
2400       }
2401       out->print("Block fill histogram: %u %-4s" SIZE_FORMAT_W(5), id, space_names[id], region_cnt);
2402       for (size_t i = 0; i < histo_len; ++i) {
2403         out->print(" " SIZE_FORMAT_W(5) " %5.1f%%",
2404                    histo[i], 100.0 * histo[i] / region_cnt);
2405       }
2406       out->cr();
2407     }
2408   }
2409 }
2410 #endif // #ifdef ASSERT
2411 
2412 void PSParallelCompact::compact() {
2413   GCTraceTime(Trace, gc, phases) tm("Compaction Phase", &_gc_timer);
2414 
2415   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
2416   PSOldGen* old_gen = heap->old_gen();
2417   old_gen->start_array()->reset();
2418   uint parallel_gc_threads = heap->gc_task_manager()->workers();
2419   uint active_gc_threads = heap->gc_task_manager()->active_workers();
2420   TaskQueueSetSuper* qset = ParCompactionManager::region_array();
2421   ParallelTaskTerminator terminator(active_gc_threads, qset);
2422 
2423   GCTaskQueue* q = GCTaskQueue::create();
2424   enqueue_region_draining_tasks(q, active_gc_threads);
2425   enqueue_dense_prefix_tasks(q, active_gc_threads);
2426   enqueue_region_stealing_tasks(q, &terminator, active_gc_threads);
2427 
2428   {
2429     GCTraceTime(Trace, gc, phases) tm("Par Compact", &_gc_timer);
2430 
2431     gc_task_manager()->execute_and_wait(q);
2432 
2433 #ifdef  ASSERT




 178   assert(_src_region_idx == 0, "not clear");
 179   assert(_partial_obj_size == 0, "not clear");
 180   assert(_destination == NULL, "not clear");
 181   assert(_destination_count == 0, "not clear");
 182   assert(_dest_region_addr == NULL, "not clear");
 183   assert(_first_src_addr == NULL, "not clear");
 184 }
 185 #endif  // #ifdef ASSERT
 186 
 187 
 188 void PSParallelCompact::print_on_error(outputStream* st) {
 189   _mark_bitmap.print_on_error(st);
 190 }
 191 
 192 #ifndef PRODUCT
 193 const char* PSParallelCompact::space_names[] = {
 194   "old ", "eden", "from", "to  "
 195 };
 196 
 197 void PSParallelCompact::print_region_ranges() {
 198   if (!log_develop_is_enabled(Trace, gc, compaction)) {
 199     return;
 200   }
 201   LogHandle(gc, compaction) log;
 202   ResourceMark rm;
 203   Universe::print_on(log.trace_stream());
 204   log.trace("space  bottom     top        end        new_top");
 205   log.trace("------ ---------- ---------- ---------- ----------");
 206 
 207   for (unsigned int id = 0; id < last_space_id; ++id) {
 208     const MutableSpace* space = _space_info[id].space();
 209     log.trace("%u %s "
 210               SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " "
 211               SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10) " ",
 212               id, space_names[id],
 213               summary_data().addr_to_region_idx(space->bottom()),
 214               summary_data().addr_to_region_idx(space->top()),
 215               summary_data().addr_to_region_idx(space->end()),
 216               summary_data().addr_to_region_idx(_space_info[id].new_top()));
 217   }
 218 }
 219 
 220 void
 221 print_generic_summary_region(size_t i, const ParallelCompactData::RegionData* c)
 222 {
 223 #define REGION_IDX_FORMAT        SIZE_FORMAT_W(7)
 224 #define REGION_DATA_FORMAT       SIZE_FORMAT_W(5)
 225 
 226   ParallelCompactData& sd = PSParallelCompact::summary_data();
 227   size_t dci = c->destination() ? sd.addr_to_region_idx(c->destination()) : 0;
 228   log_develop_trace(gc, compaction)(
 229       REGION_IDX_FORMAT " " PTR_FORMAT " "
 230       REGION_IDX_FORMAT " " PTR_FORMAT " "
 231       REGION_DATA_FORMAT " " REGION_DATA_FORMAT " "
 232       REGION_DATA_FORMAT " " REGION_IDX_FORMAT " %d",
 233       i, p2i(c->data_location()), dci, p2i(c->destination()),
 234       c->partial_obj_size(), c->live_obj_size(),
 235       c->data_size(), c->source_region(), c->destination_count());
 236 
 237 #undef  REGION_IDX_FORMAT
 238 #undef  REGION_DATA_FORMAT
 239 }
 240 
 241 void
 242 print_generic_summary_data(ParallelCompactData& summary_data,
 243                            HeapWord* const beg_addr,
 244                            HeapWord* const end_addr)
 245 {
 246   size_t total_words = 0;
 247   size_t i = summary_data.addr_to_region_idx(beg_addr);
 248   const size_t last = summary_data.addr_to_region_idx(end_addr);
 249   HeapWord* pdest = 0;
 250 
 251   while (i <= last) {
 252     ParallelCompactData::RegionData* c = summary_data.region(i);
 253     if (c->data_size() != 0 || c->destination() != pdest) {
 254       print_generic_summary_region(i, c);
 255       total_words += c->data_size();
 256       pdest = c->destination();
 257     }
 258     ++i;
 259   }
 260 
 261   log_develop_trace(gc, compaction)("summary_data_bytes=" SIZE_FORMAT, total_words * HeapWordSize);
 262 }
 263 
 264 void
 265 print_generic_summary_data(ParallelCompactData& summary_data,
 266                            SpaceInfo* space_info)
 267 {
 268   if (!log_develop_is_enabled(Trace, gc, compaction)) {
 269     return;
 270   }
 271 
 272   for (unsigned int id = 0; id < PSParallelCompact::last_space_id; ++id) {
 273     const MutableSpace* space = space_info[id].space();
 274     print_generic_summary_data(summary_data, space->bottom(),
 275                                MAX2(space->top(), space_info[id].new_top()));
 276   }
 277 }
 278 
 279 void
 280 print_initial_summary_data(ParallelCompactData& summary_data,
 281                            const MutableSpace* space) {
 282   if (space->top() == space->bottom()) {
 283     return;
 284   }
 285 
 286   const size_t region_size = ParallelCompactData::RegionSize;
 287   typedef ParallelCompactData::RegionData RegionData;
 288   HeapWord* const top_aligned_up = summary_data.region_align_up(space->top());
 289   const size_t end_region = summary_data.addr_to_region_idx(top_aligned_up);
 290   const RegionData* c = summary_data.region(end_region - 1);
 291   HeapWord* end_addr = c->destination() + c->data_size();
 292   const size_t live_in_space = pointer_delta(end_addr, space->bottom());
 293 
 294   // Print (and count) the full regions at the beginning of the space.
 295   size_t full_region_count = 0;
 296   size_t i = summary_data.addr_to_region_idx(space->bottom());
 297   while (i < end_region && summary_data.region(i)->data_size() == region_size) {
 298     ParallelCompactData::RegionData* c = summary_data.region(i);
 299     log_develop_trace(gc, compaction)(
 300         SIZE_FORMAT_W(5) " " PTR_FORMAT " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d",
 301         i, p2i(c->destination()),
 302         c->partial_obj_size(), c->live_obj_size(),
 303         c->data_size(), c->source_region(), c->destination_count());
 304     ++full_region_count;
 305     ++i;
 306   }
 307 
 308   size_t live_to_right = live_in_space - full_region_count * region_size;
 309 
 310   double max_reclaimed_ratio = 0.0;
 311   size_t max_reclaimed_ratio_region = 0;
 312   size_t max_dead_to_right = 0;
 313   size_t max_live_to_right = 0;
 314 
 315   // Print the 'reclaimed ratio' for regions while there is something live in
 316   // the region or to the right of it.  The remaining regions are empty (and
 317   // uninteresting), and computing the ratio will result in division by 0.
 318   while (i < end_region && live_to_right > 0) {
 319     c = summary_data.region(i);
 320     HeapWord* const region_addr = summary_data.region_to_addr(i);
 321     const size_t used_to_right = pointer_delta(space->top(), region_addr);
 322     const size_t dead_to_right = used_to_right - live_to_right;
 323     const double reclaimed_ratio = double(dead_to_right) / live_to_right;
 324 
 325     if (reclaimed_ratio > max_reclaimed_ratio) {
 326             max_reclaimed_ratio = reclaimed_ratio;
 327             max_reclaimed_ratio_region = i;
 328             max_dead_to_right = dead_to_right;
 329             max_live_to_right = live_to_right;
 330     }
 331 
 332     ParallelCompactData::RegionData* c = summary_data.region(i);
 333     log_develop_trace(gc, compaction)(
 334         SIZE_FORMAT_W(5) " " PTR_FORMAT " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d"
 335         "%12.10f " SIZE_FORMAT_W(10) " " SIZE_FORMAT_W(10),
 336         i, p2i(c->destination()),
 337         c->partial_obj_size(), c->live_obj_size(),
 338         c->data_size(), c->source_region(), c->destination_count(),
 339         reclaimed_ratio, dead_to_right, live_to_right);
 340 
 341 
 342     live_to_right -= c->data_size();
 343     ++i;
 344   }
 345 
 346   // Any remaining regions are empty.  Print one more if there is one.
 347   if (i < end_region) {
 348     ParallelCompactData::RegionData* c = summary_data.region(i);
 349     log_develop_trace(gc, compaction)(
 350         SIZE_FORMAT_W(5) " " PTR_FORMAT " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " " SIZE_FORMAT_W(5) " %d",
 351          i, p2i(c->destination()),
 352          c->partial_obj_size(), c->live_obj_size(),
 353          c->data_size(), c->source_region(), c->destination_count());
 354   }
 355 
 356   log_develop_trace(gc, compaction)("max:  " SIZE_FORMAT_W(4) " d2r=" SIZE_FORMAT_W(10) " l2r=" SIZE_FORMAT_W(10) " max_ratio=%14.12f",
 357                                     max_reclaimed_ratio_region, max_dead_to_right, max_live_to_right, max_reclaimed_ratio);
 358 }
 359 
 360 void
 361 print_initial_summary_data(ParallelCompactData& summary_data,
 362                            SpaceInfo* space_info) {
 363   if (!log_develop_is_enabled(Trace, gc, compaction)) {
 364     return;
 365   }
 366 
 367   unsigned int id = PSParallelCompact::old_space_id;
 368   const MutableSpace* space;
 369   do {
 370     space = space_info[id].space();
 371     print_initial_summary_data(summary_data, space);
 372   } while (++id < PSParallelCompact::eden_space_id);
 373 
 374   do {
 375     space = space_info[id].space();
 376     print_generic_summary_data(summary_data, space->bottom(), space->top());
 377   } while (++id < PSParallelCompact::last_space_id);
 378 }
 379 #endif  // #ifndef PRODUCT
 380 
 381 #ifdef  ASSERT
 382 size_t add_obj_count;
 383 size_t add_obj_size;


 604     // implies a region must be filled).
 605     //
 606     // An alternative to the simple loop below:  clear during post_compact(),
 607     // which uses memcpy instead of individual stores, and is easy to
 608     // parallelize.  (The downside is that it clears the entire RegionData
 609     // object as opposed to just one field.)
 610     //
 611     // post_compact() would have to clear the summary data up to the highest
 612     // address that was written during the summary phase, which would be
 613     //
 614     //         max(top, max(new_top, clear_top))
 615     //
 616     // where clear_top is a new field in SpaceInfo.  Would have to set clear_top
 617     // to target_end.
 618     const RegionData* const sr = region(split_region);
 619     const size_t beg_idx =
 620       addr_to_region_idx(region_align_up(sr->destination() +
 621                                          sr->partial_obj_size()));
 622     const size_t end_idx = addr_to_region_idx(target_end);
 623 
 624     log_develop_trace(gc, compaction)("split:  clearing source_region field in [" SIZE_FORMAT ", " SIZE_FORMAT ")", beg_idx, end_idx);
 625     for (size_t idx = beg_idx; idx < end_idx; ++idx) {
 626       _region_data[idx].set_source_region(0);
 627     }
 628 
 629     // Set split_destination and partial_obj_size to reflect the split region.
 630     split_destination = sr->destination();
 631     partial_obj_size = sr->partial_obj_size();
 632   }
 633 
 634   // The split is recorded only if a partial object extends onto the region.
 635   if (partial_obj_size != 0) {
 636     _region_data[split_region].set_partial_obj_size(0);
 637     split_info.record(split_region, partial_obj_size, split_destination);
 638   }
 639 
 640   // Setup the continuation addresses.
 641   *target_next = split_destination + partial_obj_size;
 642   HeapWord* const source_next = region_to_addr(split_region) + partial_obj_size;
 643 
 644   if (log_develop_is_enabled(Trace, gc, compaction)) {
 645     const char * split_type = partial_obj_size == 0 ? "easy" : "hard";
 646     log_develop_trace(gc, compaction)("%s split:  src=" PTR_FORMAT " src_c=" SIZE_FORMAT " pos=" SIZE_FORMAT,
 647                                       split_type, p2i(source_next), split_region, partial_obj_size);
 648     log_develop_trace(gc, compaction)("%s split:  dst=" PTR_FORMAT " dst_c=" SIZE_FORMAT " tn=" PTR_FORMAT,
 649                                       split_type, p2i(split_destination),
 650                                       addr_to_region_idx(split_destination),
 651                                       p2i(*target_next));
 652 
 653     if (partial_obj_size != 0) {
 654       HeapWord* const po_beg = split_info.destination();
 655       HeapWord* const po_end = po_beg + split_info.partial_obj_size();
 656       log_develop_trace(gc, compaction)("%s split:  po_beg=" PTR_FORMAT " " SIZE_FORMAT " po_end=" PTR_FORMAT " " SIZE_FORMAT,
 657                                         split_type,
 658                                         p2i(po_beg), addr_to_region_idx(po_beg),
 659                                         p2i(po_end), addr_to_region_idx(po_end));
 660     }
 661   }
 662 
 663   return source_next;
 664 }
 665 
 666 bool ParallelCompactData::summarize(SplitInfo& split_info,
 667                                     HeapWord* source_beg, HeapWord* source_end,
 668                                     HeapWord** source_next,
 669                                     HeapWord* target_beg, HeapWord* target_end,
 670                                     HeapWord** target_next)
 671 {
 672   HeapWord* const source_next_val = source_next == NULL ? NULL : *source_next;
 673   log_develop_trace(gc, compaction)(
 674       "sb=" PTR_FORMAT " se=" PTR_FORMAT " sn=" PTR_FORMAT
 675       "tb=" PTR_FORMAT " te=" PTR_FORMAT " tn=" PTR_FORMAT,
 676       p2i(source_beg), p2i(source_end), p2i(source_next_val),
 677       p2i(target_beg), p2i(target_end), p2i(*target_next));
 678 
 679   size_t cur_region = addr_to_region_idx(source_beg);
 680   const size_t end_region = addr_to_region_idx(region_align_up(source_end));
 681 
 682   HeapWord *dest_addr = target_beg;
 683   while (cur_region < end_region) {
 684     // The destination must be set even if the region has no data.
 685     _region_data[cur_region].set_destination(dest_addr);
 686 
 687     size_t words = _region_data[cur_region].data_size();
 688     if (words > 0) {
 689       // If cur_region does not fit entirely into the target space, find a point
 690       // at which the source space can be 'split' so that part is copied to the
 691       // target space and the rest is copied elsewhere.
 692       if (dest_addr + words > target_end) {
 693         assert(source_next != NULL, "source_next is NULL when splitting");


 921 
 922   const size_t beg_region = _summary_data.addr_to_region_idx(bot);
 923   const size_t end_region =
 924     _summary_data.addr_to_region_idx(_summary_data.region_align_up(max_top));
 925   _summary_data.clear_range(beg_region, end_region);
 926 
 927   // Clear the data used to 'split' regions.
 928   SplitInfo& split_info = _space_info[id].split_info();
 929   if (split_info.is_valid()) {
 930     split_info.clear();
 931   }
 932   DEBUG_ONLY(split_info.verify_clear();)
 933 }
 934 
 935 void PSParallelCompact::pre_compact()
 936 {
 937   // Update the from & to space pointers in space_info, since they are swapped
 938   // at each young gen gc.  Do the update unconditionally (even though a
 939   // promotion failure does not swap spaces) because an unknown number of young
 940   // collections will have swapped the spaces an unknown number of times.
 941   GCTraceTime(Debug, gc, phases) tm("Pre Compact", &_gc_timer);
 942   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
 943   _space_info[from_space_id].set_space(heap->young_gen()->from_space());
 944   _space_info[to_space_id].set_space(heap->young_gen()->to_space());
 945 
 946   DEBUG_ONLY(add_obj_count = add_obj_size = 0;)
 947   DEBUG_ONLY(mark_bitmap_count = mark_bitmap_size = 0;)
 948 
 949   // Increment the invocation count
 950   heap->increment_total_collections(true);
 951 
 952   // We need to track unique mark sweep invocations as well.
 953   _total_invocations++;
 954 
 955   heap->print_heap_before_gc();
 956   heap->trace_heap_before_gc(&_gc_tracer);
 957 
 958   // Fill in TLABs
 959   heap->accumulate_statistics_all_tlabs();
 960   heap->ensure_parsability(true);  // retire TLABs
 961 


 964     Universe::verify("Before GC");
 965   }
 966 
 967   // Verify object start arrays
 968   if (VerifyObjectStartArray &&
 969       VerifyBeforeGC) {
 970     heap->old_gen()->verify_object_start_array();
 971   }
 972 
 973   DEBUG_ONLY(mark_bitmap()->verify_clear();)
 974   DEBUG_ONLY(summary_data().verify_clear();)
 975 
 976   // Have worker threads release resources the next time they run a task.
 977   gc_task_manager()->release_all_resources();
 978 
 979   ParCompactionManager::reset_all_bitmap_query_caches();
 980 }
 981 
 982 void PSParallelCompact::post_compact()
 983 {
 984   GCTraceTime(Info, gc, phases) tm("Post Compact", &_gc_timer);
 985 
 986   for (unsigned int id = old_space_id; id < last_space_id; ++id) {
 987     // Clear the marking bitmap, summary data and split info.
 988     clear_data_covering_space(SpaceId(id));
 989     // Update top().  Must be done after clearing the bitmap and summary data.
 990     _space_info[id].publish_new_top();
 991   }
 992 
 993   MutableSpace* const eden_space = _space_info[eden_space_id].space();
 994   MutableSpace* const from_space = _space_info[from_space_id].space();
 995   MutableSpace* const to_space   = _space_info[to_space_id].space();
 996 
 997   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
 998   bool eden_empty = eden_space->is_empty();
 999   if (!eden_empty) {
1000     eden_empty = absorb_live_data_from_eden(heap->size_policy(),
1001                                             heap->young_gen(), heap->old_gen());
1002   }
1003 
1004   // Update heap occupancy information which is used as input to the soft ref


1507     // Recompute the summary data, taking into account the dense prefix.  If
1508     // every last byte will be reclaimed, then the existing summary data which
1509     // compacts everything can be left in place.
1510     if (!maximum_compaction && dense_prefix_end != space->bottom()) {
1511       // If dead space crosses the dense prefix boundary, it is (at least
1512       // partially) filled with a dummy object, marked live and added to the
1513       // summary data.  This simplifies the copy/update phase and must be done
1514       // before the final locations of objects are determined, to prevent
1515       // leaving a fragment of dead space that is too small to fill.
1516       fill_dense_prefix_end(id);
1517 
1518       // Compute the destination of each Region, and thus each object.
1519       _summary_data.summarize_dense_prefix(space->bottom(), dense_prefix_end);
1520       _summary_data.summarize(_space_info[id].split_info(),
1521                               dense_prefix_end, space->top(), NULL,
1522                               dense_prefix_end, space->end(),
1523                               _space_info[id].new_top_addr());
1524     }
1525   }
1526 
1527   if (log_develop_is_enabled(Trace, gc, compaction)) {
1528     const size_t region_size = ParallelCompactData::RegionSize;
1529     HeapWord* const dense_prefix_end = _space_info[id].dense_prefix();
1530     const size_t dp_region = _summary_data.addr_to_region_idx(dense_prefix_end);
1531     const size_t dp_words = pointer_delta(dense_prefix_end, space->bottom());
1532     HeapWord* const new_top = _space_info[id].new_top();
1533     const HeapWord* nt_aligned_up = _summary_data.region_align_up(new_top);
1534     const size_t cr_words = pointer_delta(nt_aligned_up, dense_prefix_end);
1535     log_develop_trace(gc, compaction)(
1536         "id=%d cap=" SIZE_FORMAT " dp=" PTR_FORMAT " "
1537         "dp_region=" SIZE_FORMAT " " "dp_count=" SIZE_FORMAT " "
1538         "cr_count=" SIZE_FORMAT " " "nt=" PTR_FORMAT,
1539         id, space->capacity_in_words(), p2i(dense_prefix_end),
1540         dp_region, dp_words / region_size,
1541         cr_words / region_size, p2i(new_top));
1542   }
1543 }
1544 
1545 #ifndef PRODUCT
1546 void PSParallelCompact::summary_phase_msg(SpaceId dst_space_id,
1547                                           HeapWord* dst_beg, HeapWord* dst_end,
1548                                           SpaceId src_space_id,
1549                                           HeapWord* src_beg, HeapWord* src_end)
1550 {
1551   log_develop_trace(gc, compaction)(
1552       "Summarizing %d [%s] into %d [%s]:  "
1553       "src=" PTR_FORMAT "-" PTR_FORMAT " "
1554       SIZE_FORMAT "-" SIZE_FORMAT " "
1555       "dst=" PTR_FORMAT "-" PTR_FORMAT " "
1556       SIZE_FORMAT "-" SIZE_FORMAT,
1557       src_space_id, space_names[src_space_id],
1558       dst_space_id, space_names[dst_space_id],
1559       p2i(src_beg), p2i(src_end),
1560       _summary_data.addr_to_region_idx(src_beg),
1561       _summary_data.addr_to_region_idx(src_end),
1562       p2i(dst_beg), p2i(dst_end),
1563       _summary_data.addr_to_region_idx(dst_beg),
1564       _summary_data.addr_to_region_idx(dst_end));
1565 }
1566 #endif  // #ifndef PRODUCT
1567 
1568 void PSParallelCompact::summary_phase(ParCompactionManager* cm,
1569                                       bool maximum_compaction)
1570 {
1571   GCTraceTime(Info, gc, phases) tm("Summary Phase", &_gc_timer);
1572 
1573 #ifdef  ASSERT
1574   if (TraceParallelOldGCMarkingPhase) {
1575     tty->print_cr("add_obj_count=" SIZE_FORMAT " "
1576                   "add_obj_bytes=" SIZE_FORMAT,
1577                   add_obj_count, add_obj_size * HeapWordSize);
1578     tty->print_cr("mark_bitmap_count=" SIZE_FORMAT " "
1579                   "mark_bitmap_bytes=" SIZE_FORMAT,
1580                   mark_bitmap_count, mark_bitmap_size * HeapWordSize);
1581   }
1582 #endif  // #ifdef ASSERT
1583 
1584   // Quick summarization of each space into itself, to see how much is live.
1585   summarize_spaces_quick();
1586 
1587   log_develop_trace(gc, compaction)("summary phase:  after summarizing each space to self");
1588   NOT_PRODUCT(print_region_ranges());
1589   NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info));
1590 
1591   // The amount of live data that will end up in old space (assuming it fits).
1592   size_t old_space_total_live = 0;
1593   for (unsigned int id = old_space_id; id < last_space_id; ++id) {
1594     old_space_total_live += pointer_delta(_space_info[id].new_top(),
1595                                           _space_info[id].space()->bottom());
1596   }
1597 
1598   MutableSpace* const old_space = _space_info[old_space_id].space();
1599   const size_t old_capacity = old_space->capacity_in_words();
1600   if (old_space_total_live > old_capacity) {
1601     // XXX - should also try to expand
1602     maximum_compaction = true;
1603   }
1604 
1605   // Old generations.
1606   summarize_space(old_space_id, maximum_compaction);
1607 


1643       assert(next_src_addr != NULL, "sanity");
1644 
1645       // The source space becomes the new target, so the remainder is compacted
1646       // within the space itself.
1647       dst_space_id = SpaceId(id);
1648       dst_space_end = space->end();
1649       new_top_addr = _space_info[id].new_top_addr();
1650       NOT_PRODUCT(summary_phase_msg(dst_space_id,
1651                                     space->bottom(), dst_space_end,
1652                                     SpaceId(id), next_src_addr, space->top());)
1653       done = _summary_data.summarize(_space_info[id].split_info(),
1654                                      next_src_addr, space->top(),
1655                                      NULL,
1656                                      space->bottom(), dst_space_end,
1657                                      new_top_addr);
1658       assert(done, "space must fit when compacted into itself");
1659       assert(*new_top_addr <= space->top(), "usage should not grow");
1660     }
1661   }
1662 
1663   log_develop_trace(gc, compaction)("Summary_phase:  after final summarization");
1664   NOT_PRODUCT(print_region_ranges());
1665   NOT_PRODUCT(print_initial_summary_data(_summary_data, _space_info));
1666 }
1667 
1668 // This method should contain all heap-specific policy for invoking a full
1669 // collection.  invoke_no_policy() will only attempt to compact the heap; it
1670 // will do nothing further.  If we need to bail out for policy reasons, scavenge
1671 // before full gc, or any other specialized behavior, it needs to be added here.
1672 //
1673 // Note that this method should only be called from the vm_thread while at a
1674 // safepoint.
1675 //
1676 // Note that the all_soft_refs_clear flag in the collector policy
1677 // may be true because this method can be called without intervening
1678 // activity.  For example when the heap space is tight and full measure
1679 // are being taken to free space.
1680 void PSParallelCompact::invoke(bool maximum_heap_compaction) {
1681   assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
1682   assert(Thread::current() == (Thread*)VMThread::vm_thread(),
1683          "should be in vm thread");


2025 
2026   // Could update the promoted average here, but it is not typically updated at
2027   // full GCs and the value to use is unclear.  Something like
2028   //
2029   // cur_promoted_avg + absorb_size / number_of_scavenges_since_last_full_gc.
2030 
2031   size_policy->set_bytes_absorbed_from_eden(absorb_size);
2032   return true;
2033 }
2034 
2035 GCTaskManager* const PSParallelCompact::gc_task_manager() {
2036   assert(ParallelScavengeHeap::gc_task_manager() != NULL,
2037     "shouldn't return NULL");
2038   return ParallelScavengeHeap::gc_task_manager();
2039 }
2040 
2041 void PSParallelCompact::marking_phase(ParCompactionManager* cm,
2042                                       bool maximum_heap_compaction,
2043                                       ParallelOldTracer *gc_tracer) {
2044   // Recursively traverse all live objects and mark them
2045   GCTraceTime(Info, gc, phases) tm("Marking Phase", &_gc_timer);
2046 
2047   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
2048   uint parallel_gc_threads = heap->gc_task_manager()->workers();
2049   uint active_gc_threads = heap->gc_task_manager()->active_workers();
2050   TaskQueueSetSuper* qset = ParCompactionManager::region_array();
2051   ParallelTaskTerminator terminator(active_gc_threads, qset);
2052 
2053   ParCompactionManager::MarkAndPushClosure mark_and_push_closure(cm);
2054   ParCompactionManager::FollowStackClosure follow_stack_closure(cm);
2055 
2056   // Need new claim bits before marking starts.
2057   ClassLoaderDataGraph::clear_claimed_marks();
2058 
2059   {
2060     GCTraceTime(Debug, gc, phases) tm("Par Mark", &_gc_timer);
2061 
2062     ParallelScavengeHeap::ParStrongRootsScope psrs;
2063 
2064     GCTaskQueue* q = GCTaskQueue::create();
2065 
2066     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::universe));
2067     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jni_handles));
2068     // We scan the thread roots in parallel
2069     Threads::create_thread_roots_marking_tasks(q);
2070     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::object_synchronizer));
2071     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::flat_profiler));
2072     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::management));
2073     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::system_dictionary));
2074     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::class_loader_data));
2075     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::jvmti));
2076     q->enqueue(new MarkFromRootsTask(MarkFromRootsTask::code_cache));
2077 
2078     if (active_gc_threads > 1) {
2079       for (uint j = 0; j < active_gc_threads; j++) {
2080         q->enqueue(new StealMarkingTask(&terminator));
2081       }
2082     }
2083 
2084     gc_task_manager()->execute_and_wait(q);
2085   }
2086 
2087   // Process reference objects found during marking
2088   {
2089     GCTraceTime(Debug, gc, phases) tm("Reference Processing", &_gc_timer);
2090 
2091     ReferenceProcessorStats stats;
2092     if (ref_processor()->processing_is_mt()) {
2093       RefProcTaskExecutor task_executor;
2094       stats = ref_processor()->process_discovered_references(
2095         is_alive_closure(), &mark_and_push_closure, &follow_stack_closure,
2096         &task_executor, &_gc_timer);
2097     } else {
2098       stats = ref_processor()->process_discovered_references(
2099         is_alive_closure(), &mark_and_push_closure, &follow_stack_closure, NULL,
2100         &_gc_timer);
2101     }
2102 
2103     gc_tracer->report_gc_reference_stats(stats);
2104   }
2105 
2106   // This is the point where the entire marking should have completed.
2107   assert(cm->marking_stacks_empty(), "Marking should have completed");
2108 
2109   {
2110     GCTraceTime(Debug, gc, phases) tm_m("Class Unloading", &_gc_timer);
2111 
2112     // Follow system dictionary roots and unload classes.
2113     bool purged_class = SystemDictionary::do_unloading(is_alive_closure());
2114 
2115     // Unload nmethods.
2116     CodeCache::do_unloading(is_alive_closure(), purged_class);
2117 
2118     // Prune dead klasses from subklass/sibling/implementor lists.
2119     Klass::clean_weak_klass_links(is_alive_closure());
2120   }
2121 
2122   {
2123     GCTraceTime(Debug, gc, phases) t("Scrub String Table", &_gc_timer);
2124     // Delete entries for dead interned strings.
2125     StringTable::unlink(is_alive_closure());
2126   }
2127 
2128   {
2129     GCTraceTime(Debug, gc, phases) t("Scrub Symbol Table", &_gc_timer);
2130     // Clean up unreferenced symbols in symbol table.
2131     SymbolTable::unlink();
2132   }
2133 
2134   _gc_tracer.report_object_count_after_gc(is_alive_closure());
2135 }
2136 
2137 void PSParallelCompact::adjust_roots(ParCompactionManager* cm) {
2138   // Adjust the pointers to reflect the new locations
2139   GCTraceTime(Info, gc, phases) tm("Adjust Roots", &_gc_timer);
2140 
2141   // Need new claim bits when tracing through and adjusting pointers.
2142   ClassLoaderDataGraph::clear_claimed_marks();
2143 
2144   PSParallelCompact::AdjustPointerClosure oop_closure(cm);
2145   PSParallelCompact::AdjustKlassClosure klass_closure(cm);
2146 
2147   // General strong roots.
2148   Universe::oops_do(&oop_closure);
2149   JNIHandles::oops_do(&oop_closure);   // Global (strong) JNI handles
2150   CLDToOopClosure adjust_from_cld(&oop_closure);
2151   Threads::oops_do(&oop_closure, &adjust_from_cld, NULL);
2152   ObjectSynchronizer::oops_do(&oop_closure);
2153   FlatProfiler::oops_do(&oop_closure);
2154   Management::oops_do(&oop_closure);
2155   JvmtiExport::oops_do(&oop_closure);
2156   SystemDictionary::oops_do(&oop_closure);
2157   ClassLoaderDataGraph::oops_do(&oop_closure, &klass_closure, true);
2158 
2159   // Now adjust pointers in remaining weak roots.  (All of which should


2393 
2394       size_t histo[5] = { 0, 0, 0, 0, 0 };
2395       const size_t histo_len = sizeof(histo) / sizeof(size_t);
2396       const size_t region_cnt = pointer_delta(end, beg, sizeof(rd_t));
2397 
2398       for (const rd_t* cur = beg; cur < end; ++cur) {
2399         ++histo[MIN2(cur->blocks_filled_count(), histo_len - 1)];
2400       }
2401       out->print("Block fill histogram: %u %-4s" SIZE_FORMAT_W(5), id, space_names[id], region_cnt);
2402       for (size_t i = 0; i < histo_len; ++i) {
2403         out->print(" " SIZE_FORMAT_W(5) " %5.1f%%",
2404                    histo[i], 100.0 * histo[i] / region_cnt);
2405       }
2406       out->cr();
2407     }
2408   }
2409 }
2410 #endif // #ifdef ASSERT
2411 
2412 void PSParallelCompact::compact() {
2413   GCTraceTime(Info, gc, phases) tm("Compaction Phase", &_gc_timer);
2414 
2415   ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
2416   PSOldGen* old_gen = heap->old_gen();
2417   old_gen->start_array()->reset();
2418   uint parallel_gc_threads = heap->gc_task_manager()->workers();
2419   uint active_gc_threads = heap->gc_task_manager()->active_workers();
2420   TaskQueueSetSuper* qset = ParCompactionManager::region_array();
2421   ParallelTaskTerminator terminator(active_gc_threads, qset);
2422 
2423   GCTaskQueue* q = GCTaskQueue::create();
2424   enqueue_region_draining_tasks(q, active_gc_threads);
2425   enqueue_dense_prefix_tasks(q, active_gc_threads);
2426   enqueue_region_stealing_tasks(q, &terminator, active_gc_threads);
2427 
2428   {
2429     GCTraceTime(Trace, gc, phases) tm("Par Compact", &_gc_timer);
2430 
2431     gc_task_manager()->execute_and_wait(q);
2432 
2433 #ifdef  ASSERT


< prev index next >