src/share/vm/gc_implementation/parallelScavenge/psParallelCompact.hpp

Sat, 08 Oct 2016 09:31:28 -0400

author
fujie
date
Sat, 08 Oct 2016 09:31:28 -0400
changeset 124
9d7e35a93fad
parent 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

The parallel GC mark-phase should be MT-safe for 3A2000.

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/parallelScavenge/objectStartArray.hpp"
aoqi@0 29 #include "gc_implementation/parallelScavenge/parMarkBitMap.hpp"
aoqi@0 30 #include "gc_implementation/parallelScavenge/psCompactionManager.hpp"
aoqi@0 31 #include "gc_implementation/shared/collectorCounters.hpp"
aoqi@0 32 #include "gc_implementation/shared/markSweep.hpp"
aoqi@0 33 #include "gc_implementation/shared/mutableSpace.hpp"
aoqi@0 34 #include "memory/sharedHeap.hpp"
aoqi@0 35 #include "oops/oop.hpp"
aoqi@0 36
aoqi@0 37 class ParallelScavengeHeap;
aoqi@0 38 class PSAdaptiveSizePolicy;
aoqi@0 39 class PSYoungGen;
aoqi@0 40 class PSOldGen;
aoqi@0 41 class ParCompactionManager;
aoqi@0 42 class ParallelTaskTerminator;
aoqi@0 43 class PSParallelCompact;
aoqi@0 44 class GCTaskManager;
aoqi@0 45 class GCTaskQueue;
aoqi@0 46 class PreGCValues;
aoqi@0 47 class MoveAndUpdateClosure;
aoqi@0 48 class RefProcTaskExecutor;
aoqi@0 49 class ParallelOldTracer;
aoqi@0 50 class STWGCTimer;
aoqi@0 51
aoqi@0 52 // The SplitInfo class holds the information needed to 'split' a source region
aoqi@0 53 // so that the live data can be copied to two destination *spaces*. Normally,
aoqi@0 54 // all the live data in a region is copied to a single destination space (e.g.,
aoqi@0 55 // everything live in a region in eden is copied entirely into the old gen).
aoqi@0 56 // However, when the heap is nearly full, all the live data in eden may not fit
aoqi@0 57 // into the old gen. Copying only some of the regions from eden to old gen
aoqi@0 58 // requires finding a region that does not contain a partial object (i.e., no
aoqi@0 59 // live object crosses the region boundary) somewhere near the last object that
aoqi@0 60 // does fit into the old gen. Since it's not always possible to find such a
aoqi@0 61 // region, splitting is necessary for predictable behavior.
aoqi@0 62 //
aoqi@0 63 // A region is always split at the end of the partial object. This avoids
aoqi@0 64 // additional tests when calculating the new location of a pointer, which is a
aoqi@0 65 // very hot code path. The partial object and everything to its left will be
aoqi@0 66 // copied to another space (call it dest_space_1). The live data to the right
aoqi@0 67 // of the partial object will be copied either within the space itself, or to a
aoqi@0 68 // different destination space (distinct from dest_space_1).
aoqi@0 69 //
aoqi@0 70 // Split points are identified during the summary phase, when region
aoqi@0 71 // destinations are computed: data about the split, including the
aoqi@0 72 // partial_object_size, is recorded in a SplitInfo record and the
aoqi@0 73 // partial_object_size field in the summary data is set to zero. The zeroing is
aoqi@0 74 // possible (and necessary) since the partial object will move to a different
aoqi@0 75 // destination space than anything to its right, thus the partial object should
aoqi@0 76 // not affect the locations of any objects to its right.
aoqi@0 77 //
aoqi@0 78 // The recorded data is used during the compaction phase, but only rarely: when
aoqi@0 79 // the partial object on the split region will be copied across a destination
aoqi@0 80 // region boundary. This test is made once each time a region is filled, and is
aoqi@0 81 // a simple address comparison, so the overhead is negligible (see
aoqi@0 82 // PSParallelCompact::first_src_addr()).
aoqi@0 83 //
aoqi@0 84 // Notes:
aoqi@0 85 //
aoqi@0 86 // Only regions with partial objects are split; a region without a partial
aoqi@0 87 // object does not need any extra bookkeeping.
aoqi@0 88 //
aoqi@0 89 // At most one region is split per space, so the amount of data required is
aoqi@0 90 // constant.
aoqi@0 91 //
aoqi@0 92 // A region is split only when the destination space would overflow. Once that
aoqi@0 93 // happens, the destination space is abandoned and no other data (even from
aoqi@0 94 // other source spaces) is targeted to that destination space. Abandoning the
aoqi@0 95 // destination space may leave a somewhat large unused area at the end, if a
aoqi@0 96 // large object caused the overflow.
aoqi@0 97 //
aoqi@0 98 // Future work:
aoqi@0 99 //
aoqi@0 100 // More bookkeeping would be required to continue to use the destination space.
aoqi@0 101 // The most general solution would allow data from regions in two different
aoqi@0 102 // source spaces to be "joined" in a single destination region. At the very
aoqi@0 103 // least, additional code would be required in next_src_region() to detect the
aoqi@0 104 // join and skip to an out-of-order source region. If the join region was also
aoqi@0 105 // the last destination region to which a split region was copied (the most
aoqi@0 106 // likely case), then additional work would be needed to get fill_region() to
aoqi@0 107 // stop iteration and switch to a new source region at the right point. Basic
aoqi@0 108 // idea would be to use a fake value for the top of the source space. It is
aoqi@0 109 // doable, if a bit tricky.
aoqi@0 110 //
aoqi@0 111 // A simpler (but less general) solution would fill the remainder of the
aoqi@0 112 // destination region with a dummy object and continue filling the next
aoqi@0 113 // destination region.
aoqi@0 114
aoqi@0 115 class SplitInfo
aoqi@0 116 {
aoqi@0 117 public:
aoqi@0 118 // Return true if this split info is valid (i.e., if a split has been
aoqi@0 119 // recorded). The very first region cannot have a partial object and thus is
aoqi@0 120 // never split, so 0 is the 'invalid' value.
aoqi@0 121 bool is_valid() const { return _src_region_idx > 0; }
aoqi@0 122
aoqi@0 123 // Return true if this split holds data for the specified source region.
aoqi@0 124 inline bool is_split(size_t source_region) const;
aoqi@0 125
aoqi@0 126 // The index of the split region, the size of the partial object on that
aoqi@0 127 // region and the destination of the partial object.
aoqi@0 128 size_t src_region_idx() const { return _src_region_idx; }
aoqi@0 129 size_t partial_obj_size() const { return _partial_obj_size; }
aoqi@0 130 HeapWord* destination() const { return _destination; }
aoqi@0 131
aoqi@0 132 // The destination count of the partial object referenced by this split
aoqi@0 133 // (either 1 or 2). This must be added to the destination count of the
aoqi@0 134 // remainder of the source region.
aoqi@0 135 unsigned int destination_count() const { return _destination_count; }
aoqi@0 136
aoqi@0 137 // If a word within the partial object will be written to the first word of a
aoqi@0 138 // destination region, this is the address of the destination region;
aoqi@0 139 // otherwise this is NULL.
aoqi@0 140 HeapWord* dest_region_addr() const { return _dest_region_addr; }
aoqi@0 141
aoqi@0 142 // If a word within the partial object will be written to the first word of a
aoqi@0 143 // destination region, this is the address of that word within the partial
aoqi@0 144 // object; otherwise this is NULL.
aoqi@0 145 HeapWord* first_src_addr() const { return _first_src_addr; }
aoqi@0 146
aoqi@0 147 // Record the data necessary to split the region src_region_idx.
aoqi@0 148 void record(size_t src_region_idx, size_t partial_obj_size,
aoqi@0 149 HeapWord* destination);
aoqi@0 150
aoqi@0 151 void clear();
aoqi@0 152
aoqi@0 153 DEBUG_ONLY(void verify_clear();)
aoqi@0 154
aoqi@0 155 private:
aoqi@0 156 size_t _src_region_idx;
aoqi@0 157 size_t _partial_obj_size;
aoqi@0 158 HeapWord* _destination;
aoqi@0 159 unsigned int _destination_count;
aoqi@0 160 HeapWord* _dest_region_addr;
aoqi@0 161 HeapWord* _first_src_addr;
aoqi@0 162 };
aoqi@0 163
aoqi@0 164 inline bool SplitInfo::is_split(size_t region_idx) const
aoqi@0 165 {
aoqi@0 166 return _src_region_idx == region_idx && is_valid();
aoqi@0 167 }
aoqi@0 168
aoqi@0 169 class SpaceInfo
aoqi@0 170 {
aoqi@0 171 public:
aoqi@0 172 MutableSpace* space() const { return _space; }
aoqi@0 173
aoqi@0 174 // Where the free space will start after the collection. Valid only after the
aoqi@0 175 // summary phase completes.
aoqi@0 176 HeapWord* new_top() const { return _new_top; }
aoqi@0 177
aoqi@0 178 // Allows new_top to be set.
aoqi@0 179 HeapWord** new_top_addr() { return &_new_top; }
aoqi@0 180
aoqi@0 181 // Where the smallest allowable dense prefix ends (used only for perm gen).
aoqi@0 182 HeapWord* min_dense_prefix() const { return _min_dense_prefix; }
aoqi@0 183
aoqi@0 184 // Where the dense prefix ends, or the compacted region begins.
aoqi@0 185 HeapWord* dense_prefix() const { return _dense_prefix; }
aoqi@0 186
aoqi@0 187 // The start array for the (generation containing the) space, or NULL if there
aoqi@0 188 // is no start array.
aoqi@0 189 ObjectStartArray* start_array() const { return _start_array; }
aoqi@0 190
aoqi@0 191 SplitInfo& split_info() { return _split_info; }
aoqi@0 192
aoqi@0 193 void set_space(MutableSpace* s) { _space = s; }
aoqi@0 194 void set_new_top(HeapWord* addr) { _new_top = addr; }
aoqi@0 195 void set_min_dense_prefix(HeapWord* addr) { _min_dense_prefix = addr; }
aoqi@0 196 void set_dense_prefix(HeapWord* addr) { _dense_prefix = addr; }
aoqi@0 197 void set_start_array(ObjectStartArray* s) { _start_array = s; }
aoqi@0 198
aoqi@0 199 void publish_new_top() const { _space->set_top(_new_top); }
aoqi@0 200
aoqi@0 201 private:
aoqi@0 202 MutableSpace* _space;
aoqi@0 203 HeapWord* _new_top;
aoqi@0 204 HeapWord* _min_dense_prefix;
aoqi@0 205 HeapWord* _dense_prefix;
aoqi@0 206 ObjectStartArray* _start_array;
aoqi@0 207 SplitInfo _split_info;
aoqi@0 208 };
aoqi@0 209
aoqi@0 210 class ParallelCompactData
aoqi@0 211 {
aoqi@0 212 public:
aoqi@0 213 // Sizes are in HeapWords, unless indicated otherwise.
aoqi@0 214 static const size_t Log2RegionSize;
aoqi@0 215 static const size_t RegionSize;
aoqi@0 216 static const size_t RegionSizeBytes;
aoqi@0 217
aoqi@0 218 // Mask for the bits in a size_t to get an offset within a region.
aoqi@0 219 static const size_t RegionSizeOffsetMask;
aoqi@0 220 // Mask for the bits in a pointer to get an offset within a region.
aoqi@0 221 static const size_t RegionAddrOffsetMask;
aoqi@0 222 // Mask for the bits in a pointer to get the address of the start of a region.
aoqi@0 223 static const size_t RegionAddrMask;
aoqi@0 224
aoqi@0 225 static const size_t Log2BlockSize;
aoqi@0 226 static const size_t BlockSize;
aoqi@0 227 static const size_t BlockSizeBytes;
aoqi@0 228
aoqi@0 229 static const size_t BlockSizeOffsetMask;
aoqi@0 230 static const size_t BlockAddrOffsetMask;
aoqi@0 231 static const size_t BlockAddrMask;
aoqi@0 232
aoqi@0 233 static const size_t BlocksPerRegion;
aoqi@0 234 static const size_t Log2BlocksPerRegion;
aoqi@0 235
aoqi@0 236 class RegionData
aoqi@0 237 {
aoqi@0 238 public:
aoqi@0 239 // Destination address of the region.
aoqi@0 240 HeapWord* destination() const { return _destination; }
aoqi@0 241
aoqi@0 242 // The first region containing data destined for this region.
aoqi@0 243 size_t source_region() const { return _source_region; }
aoqi@0 244
aoqi@0 245 // The object (if any) starting in this region and ending in a different
aoqi@0 246 // region that could not be updated during the main (parallel) compaction
aoqi@0 247 // phase. This is different from _partial_obj_addr, which is an object that
aoqi@0 248 // extends onto a source region. However, the two uses do not overlap in
aoqi@0 249 // time, so the same field is used to save space.
aoqi@0 250 HeapWord* deferred_obj_addr() const { return _partial_obj_addr; }
aoqi@0 251
aoqi@0 252 // The starting address of the partial object extending onto the region.
aoqi@0 253 HeapWord* partial_obj_addr() const { return _partial_obj_addr; }
aoqi@0 254
aoqi@0 255 // Size of the partial object extending onto the region (words).
aoqi@0 256 size_t partial_obj_size() const { return _partial_obj_size; }
aoqi@0 257
aoqi@0 258 // Size of live data that lies within this region due to objects that start
aoqi@0 259 // in this region (words). This does not include the partial object
aoqi@0 260 // extending onto the region (if any), or the part of an object that extends
aoqi@0 261 // onto the next region (if any).
aoqi@0 262 size_t live_obj_size() const { return _dc_and_los & los_mask; }
aoqi@0 263
aoqi@0 264 // Total live data that lies within the region (words).
aoqi@0 265 size_t data_size() const { return partial_obj_size() + live_obj_size(); }
aoqi@0 266
aoqi@0 267 // The destination_count is the number of other regions to which data from
aoqi@0 268 // this region will be copied. At the end of the summary phase, the valid
aoqi@0 269 // values of destination_count are
aoqi@0 270 //
aoqi@0 271 // 0 - data from the region will be compacted completely into itself, or the
aoqi@0 272 // region is empty. The region can be claimed and then filled.
aoqi@0 273 // 1 - data from the region will be compacted into 1 other region; some
aoqi@0 274 // data from the region may also be compacted into the region itself.
aoqi@0 275 // 2 - data from the region will be copied to 2 other regions.
aoqi@0 276 //
aoqi@0 277 // During compaction as regions are emptied, the destination_count is
aoqi@0 278 // decremented (atomically) and when it reaches 0, it can be claimed and
aoqi@0 279 // then filled.
aoqi@0 280 //
aoqi@0 281 // A region is claimed for processing by atomically changing the
aoqi@0 282 // destination_count to the claimed value (dc_claimed). After a region has
aoqi@0 283 // been filled, the destination_count should be set to the completed value
aoqi@0 284 // (dc_completed).
aoqi@0 285 inline uint destination_count() const;
aoqi@0 286 inline uint destination_count_raw() const;
aoqi@0 287
aoqi@0 288 // Whether the block table for this region has been filled.
aoqi@0 289 inline bool blocks_filled() const;
aoqi@0 290
aoqi@0 291 // Number of times the block table was filled.
aoqi@0 292 DEBUG_ONLY(inline size_t blocks_filled_count() const;)
aoqi@0 293
aoqi@0 294 // The location of the java heap data that corresponds to this region.
aoqi@0 295 inline HeapWord* data_location() const;
aoqi@0 296
aoqi@0 297 // The highest address referenced by objects in this region.
aoqi@0 298 inline HeapWord* highest_ref() const;
aoqi@0 299
aoqi@0 300 // Whether this region is available to be claimed, has been claimed, or has
aoqi@0 301 // been completed.
aoqi@0 302 //
aoqi@0 303 // Minor subtlety: claimed() returns true if the region is marked
aoqi@0 304 // completed(), which is desirable since a region must be claimed before it
aoqi@0 305 // can be completed.
aoqi@0 306 bool available() const { return _dc_and_los < dc_one; }
aoqi@0 307 bool claimed() const { return _dc_and_los >= dc_claimed; }
aoqi@0 308 bool completed() const { return _dc_and_los >= dc_completed; }
aoqi@0 309
aoqi@0 310 // These are not atomic.
aoqi@0 311 void set_destination(HeapWord* addr) { _destination = addr; }
aoqi@0 312 void set_source_region(size_t region) { _source_region = region; }
aoqi@0 313 void set_deferred_obj_addr(HeapWord* addr) { _partial_obj_addr = addr; }
aoqi@0 314 void set_partial_obj_addr(HeapWord* addr) { _partial_obj_addr = addr; }
aoqi@0 315 void set_partial_obj_size(size_t words) {
aoqi@0 316 _partial_obj_size = (region_sz_t) words;
aoqi@0 317 }
aoqi@0 318 inline void set_blocks_filled();
aoqi@0 319
aoqi@0 320 inline void set_destination_count(uint count);
aoqi@0 321 inline void set_live_obj_size(size_t words);
aoqi@0 322 inline void set_data_location(HeapWord* addr);
aoqi@0 323 inline void set_completed();
aoqi@0 324 inline bool claim_unsafe();
aoqi@0 325
aoqi@0 326 // These are atomic.
aoqi@0 327 inline void add_live_obj(size_t words);
aoqi@0 328 inline void set_highest_ref(HeapWord* addr);
aoqi@0 329 inline void decrement_destination_count();
aoqi@0 330 inline bool claim();
aoqi@0 331
aoqi@0 332 private:
aoqi@0 333 // The type used to represent object sizes within a region.
aoqi@0 334 typedef uint region_sz_t;
aoqi@0 335
aoqi@0 336 // Constants for manipulating the _dc_and_los field, which holds both the
aoqi@0 337 // destination count and live obj size. The live obj size lives at the
aoqi@0 338 // least significant end so no masking is necessary when adding.
aoqi@0 339 static const region_sz_t dc_shift; // Shift amount.
aoqi@0 340 static const region_sz_t dc_mask; // Mask for destination count.
aoqi@0 341 static const region_sz_t dc_one; // 1, shifted appropriately.
aoqi@0 342 static const region_sz_t dc_claimed; // Region has been claimed.
aoqi@0 343 static const region_sz_t dc_completed; // Region has been completed.
aoqi@0 344 static const region_sz_t los_mask; // Mask for live obj size.
aoqi@0 345
aoqi@0 346 HeapWord* _destination;
aoqi@0 347 size_t _source_region;
aoqi@0 348 HeapWord* _partial_obj_addr;
aoqi@0 349 region_sz_t _partial_obj_size;
aoqi@0 350 region_sz_t volatile _dc_and_los;
aoqi@0 351 bool _blocks_filled;
aoqi@0 352
aoqi@0 353 #ifdef ASSERT
aoqi@0 354 size_t _blocks_filled_count; // Number of block table fills.
aoqi@0 355
aoqi@0 356 // These enable optimizations that are only partially implemented. Use
aoqi@0 357 // debug builds to prevent the code fragments from breaking.
aoqi@0 358 HeapWord* _data_location;
aoqi@0 359 HeapWord* _highest_ref;
aoqi@0 360 #endif // #ifdef ASSERT
aoqi@0 361
aoqi@0 362 #ifdef ASSERT
aoqi@0 363 public:
aoqi@0 364 uint _pushed; // 0 until region is pushed onto a stack
aoqi@0 365 private:
aoqi@0 366 #endif
aoqi@0 367 };
aoqi@0 368
aoqi@0 369 // "Blocks" allow shorter sections of the bitmap to be searched. Each Block
aoqi@0 370 // holds an offset, which is the amount of live data in the Region to the left
aoqi@0 371 // of the first live object that starts in the Block.
aoqi@0 372 class BlockData
aoqi@0 373 {
aoqi@0 374 public:
aoqi@0 375 typedef unsigned short int blk_ofs_t;
aoqi@0 376
aoqi@0 377 blk_ofs_t offset() const { return _offset; }
aoqi@0 378 void set_offset(size_t val) { _offset = (blk_ofs_t)val; }
aoqi@0 379
aoqi@0 380 private:
aoqi@0 381 blk_ofs_t _offset;
aoqi@0 382 };
aoqi@0 383
aoqi@0 384 public:
aoqi@0 385 ParallelCompactData();
aoqi@0 386 bool initialize(MemRegion covered_region);
aoqi@0 387
aoqi@0 388 size_t region_count() const { return _region_count; }
aoqi@0 389 size_t reserved_byte_size() const { return _reserved_byte_size; }
aoqi@0 390
aoqi@0 391 // Convert region indices to/from RegionData pointers.
aoqi@0 392 inline RegionData* region(size_t region_idx) const;
aoqi@0 393 inline size_t region(const RegionData* const region_ptr) const;
aoqi@0 394
aoqi@0 395 size_t block_count() const { return _block_count; }
aoqi@0 396 inline BlockData* block(size_t block_idx) const;
aoqi@0 397 inline size_t block(const BlockData* block_ptr) const;
aoqi@0 398
aoqi@0 399 void add_obj(HeapWord* addr, size_t len);
aoqi@0 400 void add_obj(oop p, size_t len) { add_obj((HeapWord*)p, len); }
aoqi@0 401
aoqi@0 402 // Fill in the regions covering [beg, end) so that no data moves; i.e., the
aoqi@0 403 // destination of region n is simply the start of region n. The argument beg
aoqi@0 404 // must be region-aligned; end need not be.
aoqi@0 405 void summarize_dense_prefix(HeapWord* beg, HeapWord* end);
aoqi@0 406
aoqi@0 407 HeapWord* summarize_split_space(size_t src_region, SplitInfo& split_info,
aoqi@0 408 HeapWord* destination, HeapWord* target_end,
aoqi@0 409 HeapWord** target_next);
aoqi@0 410 bool summarize(SplitInfo& split_info,
aoqi@0 411 HeapWord* source_beg, HeapWord* source_end,
aoqi@0 412 HeapWord** source_next,
aoqi@0 413 HeapWord* target_beg, HeapWord* target_end,
aoqi@0 414 HeapWord** target_next);
aoqi@0 415
aoqi@0 416 void clear();
aoqi@0 417 void clear_range(size_t beg_region, size_t end_region);
aoqi@0 418 void clear_range(HeapWord* beg, HeapWord* end) {
aoqi@0 419 clear_range(addr_to_region_idx(beg), addr_to_region_idx(end));
aoqi@0 420 }
aoqi@0 421
aoqi@0 422 // Return the number of words between addr and the start of the region
aoqi@0 423 // containing addr.
aoqi@0 424 inline size_t region_offset(const HeapWord* addr) const;
aoqi@0 425
aoqi@0 426 // Convert addresses to/from a region index or region pointer.
aoqi@0 427 inline size_t addr_to_region_idx(const HeapWord* addr) const;
aoqi@0 428 inline RegionData* addr_to_region_ptr(const HeapWord* addr) const;
aoqi@0 429 inline HeapWord* region_to_addr(size_t region) const;
aoqi@0 430 inline HeapWord* region_to_addr(size_t region, size_t offset) const;
aoqi@0 431 inline HeapWord* region_to_addr(const RegionData* region) const;
aoqi@0 432
aoqi@0 433 inline HeapWord* region_align_down(HeapWord* addr) const;
aoqi@0 434 inline HeapWord* region_align_up(HeapWord* addr) const;
aoqi@0 435 inline bool is_region_aligned(HeapWord* addr) const;
aoqi@0 436
aoqi@0 437 // Analogous to region_offset() for blocks.
aoqi@0 438 size_t block_offset(const HeapWord* addr) const;
aoqi@0 439 size_t addr_to_block_idx(const HeapWord* addr) const;
aoqi@0 440 size_t addr_to_block_idx(const oop obj) const {
aoqi@0 441 return addr_to_block_idx((HeapWord*) obj);
aoqi@0 442 }
aoqi@0 443 inline BlockData* addr_to_block_ptr(const HeapWord* addr) const;
aoqi@0 444 inline HeapWord* block_to_addr(size_t block) const;
aoqi@0 445 inline size_t region_to_block_idx(size_t region) const;
aoqi@0 446
aoqi@0 447 inline HeapWord* block_align_down(HeapWord* addr) const;
aoqi@0 448 inline HeapWord* block_align_up(HeapWord* addr) const;
aoqi@0 449 inline bool is_block_aligned(HeapWord* addr) const;
aoqi@0 450
aoqi@0 451 // Return the address one past the end of the partial object.
aoqi@0 452 HeapWord* partial_obj_end(size_t region_idx) const;
aoqi@0 453
aoqi@0 454 // Return the location of the object after compaction.
aoqi@0 455 HeapWord* calc_new_pointer(HeapWord* addr);
aoqi@0 456
aoqi@0 457 HeapWord* calc_new_pointer(oop p) {
aoqi@0 458 return calc_new_pointer((HeapWord*) p);
aoqi@0 459 }
aoqi@0 460
aoqi@0 461 #ifdef ASSERT
aoqi@0 462 void verify_clear(const PSVirtualSpace* vspace);
aoqi@0 463 void verify_clear();
aoqi@0 464 #endif // #ifdef ASSERT
aoqi@0 465
aoqi@0 466 private:
aoqi@0 467 bool initialize_block_data();
aoqi@0 468 bool initialize_region_data(size_t region_size);
aoqi@0 469 PSVirtualSpace* create_vspace(size_t count, size_t element_size);
aoqi@0 470
aoqi@0 471 private:
aoqi@0 472 HeapWord* _region_start;
aoqi@0 473 #ifdef ASSERT
aoqi@0 474 HeapWord* _region_end;
aoqi@0 475 #endif // #ifdef ASSERT
aoqi@0 476
aoqi@0 477 PSVirtualSpace* _region_vspace;
aoqi@0 478 size_t _reserved_byte_size;
aoqi@0 479 RegionData* _region_data;
aoqi@0 480 size_t _region_count;
aoqi@0 481
aoqi@0 482 PSVirtualSpace* _block_vspace;
aoqi@0 483 BlockData* _block_data;
aoqi@0 484 size_t _block_count;
aoqi@0 485 };
aoqi@0 486
aoqi@0 487 inline uint
aoqi@0 488 ParallelCompactData::RegionData::destination_count_raw() const
aoqi@0 489 {
aoqi@0 490 return _dc_and_los & dc_mask;
aoqi@0 491 }
aoqi@0 492
aoqi@0 493 inline uint
aoqi@0 494 ParallelCompactData::RegionData::destination_count() const
aoqi@0 495 {
aoqi@0 496 return destination_count_raw() >> dc_shift;
aoqi@0 497 }
aoqi@0 498
aoqi@0 499 inline bool
aoqi@0 500 ParallelCompactData::RegionData::blocks_filled() const
aoqi@0 501 {
aoqi@0 502 return _blocks_filled;
aoqi@0 503 }
aoqi@0 504
aoqi@0 505 #ifdef ASSERT
aoqi@0 506 inline size_t
aoqi@0 507 ParallelCompactData::RegionData::blocks_filled_count() const
aoqi@0 508 {
aoqi@0 509 return _blocks_filled_count;
aoqi@0 510 }
aoqi@0 511 #endif // #ifdef ASSERT
aoqi@0 512
aoqi@0 513 inline void
aoqi@0 514 ParallelCompactData::RegionData::set_blocks_filled()
aoqi@0 515 {
aoqi@0 516 _blocks_filled = true;
aoqi@0 517 // Debug builds count the number of times the table was filled.
aoqi@0 518 DEBUG_ONLY(Atomic::inc_ptr(&_blocks_filled_count));
aoqi@0 519 }
aoqi@0 520
aoqi@0 521 inline void
aoqi@0 522 ParallelCompactData::RegionData::set_destination_count(uint count)
aoqi@0 523 {
aoqi@0 524 assert(count <= (dc_completed >> dc_shift), "count too large");
aoqi@0 525 const region_sz_t live_sz = (region_sz_t) live_obj_size();
aoqi@0 526 _dc_and_los = (count << dc_shift) | live_sz;
aoqi@0 527 }
aoqi@0 528
aoqi@0 529 inline void ParallelCompactData::RegionData::set_live_obj_size(size_t words)
aoqi@0 530 {
aoqi@0 531 assert(words <= los_mask, "would overflow");
aoqi@0 532 _dc_and_los = destination_count_raw() | (region_sz_t)words;
aoqi@0 533 }
aoqi@0 534
aoqi@0 535 inline void ParallelCompactData::RegionData::decrement_destination_count()
aoqi@0 536 {
aoqi@0 537 assert(_dc_and_los < dc_claimed, "already claimed");
aoqi@0 538 assert(_dc_and_los >= dc_one, "count would go negative");
aoqi@0 539 Atomic::add((int)dc_mask, (volatile int*)&_dc_and_los);
aoqi@0 540 }
aoqi@0 541
aoqi@0 542 inline HeapWord* ParallelCompactData::RegionData::data_location() const
aoqi@0 543 {
aoqi@0 544 DEBUG_ONLY(return _data_location;)
aoqi@0 545 NOT_DEBUG(return NULL;)
aoqi@0 546 }
aoqi@0 547
aoqi@0 548 inline HeapWord* ParallelCompactData::RegionData::highest_ref() const
aoqi@0 549 {
aoqi@0 550 DEBUG_ONLY(return _highest_ref;)
aoqi@0 551 NOT_DEBUG(return NULL;)
aoqi@0 552 }
aoqi@0 553
aoqi@0 554 inline void ParallelCompactData::RegionData::set_data_location(HeapWord* addr)
aoqi@0 555 {
aoqi@0 556 DEBUG_ONLY(_data_location = addr;)
aoqi@0 557 }
aoqi@0 558
aoqi@0 559 inline void ParallelCompactData::RegionData::set_completed()
aoqi@0 560 {
aoqi@0 561 assert(claimed(), "must be claimed first");
aoqi@0 562 _dc_and_los = dc_completed | (region_sz_t) live_obj_size();
aoqi@0 563 }
aoqi@0 564
aoqi@0 565 // MT-unsafe claiming of a region. Should only be used during single threaded
aoqi@0 566 // execution.
aoqi@0 567 inline bool ParallelCompactData::RegionData::claim_unsafe()
aoqi@0 568 {
aoqi@0 569 if (available()) {
aoqi@0 570 _dc_and_los |= dc_claimed;
aoqi@0 571 return true;
aoqi@0 572 }
aoqi@0 573 return false;
aoqi@0 574 }
aoqi@0 575
aoqi@0 576 inline void ParallelCompactData::RegionData::add_live_obj(size_t words)
aoqi@0 577 {
aoqi@0 578 assert(words <= (size_t)los_mask - live_obj_size(), "overflow");
aoqi@0 579 Atomic::add((int) words, (volatile int*) &_dc_and_los);
aoqi@0 580 }
aoqi@0 581
aoqi@0 582 inline void ParallelCompactData::RegionData::set_highest_ref(HeapWord* addr)
aoqi@0 583 {
aoqi@0 584 #ifdef ASSERT
aoqi@0 585 HeapWord* tmp = _highest_ref;
aoqi@0 586 while (addr > tmp) {
aoqi@0 587 tmp = (HeapWord*)Atomic::cmpxchg_ptr(addr, &_highest_ref, tmp);
aoqi@0 588 }
aoqi@0 589 #endif // #ifdef ASSERT
aoqi@0 590 }
aoqi@0 591
aoqi@0 592 inline bool ParallelCompactData::RegionData::claim()
aoqi@0 593 {
aoqi@0 594 const int los = (int) live_obj_size();
aoqi@0 595 const int old = Atomic::cmpxchg(dc_claimed | los,
aoqi@0 596 (volatile int*) &_dc_and_los, los);
aoqi@0 597 return old == los;
aoqi@0 598 }
aoqi@0 599
aoqi@0 600 inline ParallelCompactData::RegionData*
aoqi@0 601 ParallelCompactData::region(size_t region_idx) const
aoqi@0 602 {
aoqi@0 603 assert(region_idx <= region_count(), "bad arg");
aoqi@0 604 return _region_data + region_idx;
aoqi@0 605 }
aoqi@0 606
aoqi@0 607 inline size_t
aoqi@0 608 ParallelCompactData::region(const RegionData* const region_ptr) const
aoqi@0 609 {
aoqi@0 610 assert(region_ptr >= _region_data, "bad arg");
aoqi@0 611 assert(region_ptr <= _region_data + region_count(), "bad arg");
aoqi@0 612 return pointer_delta(region_ptr, _region_data, sizeof(RegionData));
aoqi@0 613 }
aoqi@0 614
aoqi@0 615 inline ParallelCompactData::BlockData*
aoqi@0 616 ParallelCompactData::block(size_t n) const {
aoqi@0 617 assert(n < block_count(), "bad arg");
aoqi@0 618 return _block_data + n;
aoqi@0 619 }
aoqi@0 620
aoqi@0 621 inline size_t
aoqi@0 622 ParallelCompactData::region_offset(const HeapWord* addr) const
aoqi@0 623 {
aoqi@0 624 assert(addr >= _region_start, "bad addr");
aoqi@0 625 assert(addr <= _region_end, "bad addr");
aoqi@0 626 return (size_t(addr) & RegionAddrOffsetMask) >> LogHeapWordSize;
aoqi@0 627 }
aoqi@0 628
aoqi@0 629 inline size_t
aoqi@0 630 ParallelCompactData::addr_to_region_idx(const HeapWord* addr) const
aoqi@0 631 {
aoqi@0 632 assert(addr >= _region_start, "bad addr");
aoqi@0 633 assert(addr <= _region_end, "bad addr");
aoqi@0 634 return pointer_delta(addr, _region_start) >> Log2RegionSize;
aoqi@0 635 }
aoqi@0 636
aoqi@0 637 inline ParallelCompactData::RegionData*
aoqi@0 638 ParallelCompactData::addr_to_region_ptr(const HeapWord* addr) const
aoqi@0 639 {
aoqi@0 640 return region(addr_to_region_idx(addr));
aoqi@0 641 }
aoqi@0 642
aoqi@0 643 inline HeapWord*
aoqi@0 644 ParallelCompactData::region_to_addr(size_t region) const
aoqi@0 645 {
aoqi@0 646 assert(region <= _region_count, "region out of range");
aoqi@0 647 return _region_start + (region << Log2RegionSize);
aoqi@0 648 }
aoqi@0 649
aoqi@0 650 inline HeapWord*
aoqi@0 651 ParallelCompactData::region_to_addr(const RegionData* region) const
aoqi@0 652 {
aoqi@0 653 return region_to_addr(pointer_delta(region, _region_data,
aoqi@0 654 sizeof(RegionData)));
aoqi@0 655 }
aoqi@0 656
aoqi@0 657 inline HeapWord*
aoqi@0 658 ParallelCompactData::region_to_addr(size_t region, size_t offset) const
aoqi@0 659 {
aoqi@0 660 assert(region <= _region_count, "region out of range");
aoqi@0 661 assert(offset < RegionSize, "offset too big"); // This may be too strict.
aoqi@0 662 return region_to_addr(region) + offset;
aoqi@0 663 }
aoqi@0 664
aoqi@0 665 inline HeapWord*
aoqi@0 666 ParallelCompactData::region_align_down(HeapWord* addr) const
aoqi@0 667 {
aoqi@0 668 assert(addr >= _region_start, "bad addr");
aoqi@0 669 assert(addr < _region_end + RegionSize, "bad addr");
aoqi@0 670 return (HeapWord*)(size_t(addr) & RegionAddrMask);
aoqi@0 671 }
aoqi@0 672
aoqi@0 673 inline HeapWord*
aoqi@0 674 ParallelCompactData::region_align_up(HeapWord* addr) const
aoqi@0 675 {
aoqi@0 676 assert(addr >= _region_start, "bad addr");
aoqi@0 677 assert(addr <= _region_end, "bad addr");
aoqi@0 678 return region_align_down(addr + RegionSizeOffsetMask);
aoqi@0 679 }
aoqi@0 680
aoqi@0 681 inline bool
aoqi@0 682 ParallelCompactData::is_region_aligned(HeapWord* addr) const
aoqi@0 683 {
aoqi@0 684 return region_offset(addr) == 0;
aoqi@0 685 }
aoqi@0 686
aoqi@0 687 inline size_t
aoqi@0 688 ParallelCompactData::block_offset(const HeapWord* addr) const
aoqi@0 689 {
aoqi@0 690 assert(addr >= _region_start, "bad addr");
aoqi@0 691 assert(addr <= _region_end, "bad addr");
aoqi@0 692 return (size_t(addr) & BlockAddrOffsetMask) >> LogHeapWordSize;
aoqi@0 693 }
aoqi@0 694
aoqi@0 695 inline size_t
aoqi@0 696 ParallelCompactData::addr_to_block_idx(const HeapWord* addr) const
aoqi@0 697 {
aoqi@0 698 assert(addr >= _region_start, "bad addr");
aoqi@0 699 assert(addr <= _region_end, "bad addr");
aoqi@0 700 return pointer_delta(addr, _region_start) >> Log2BlockSize;
aoqi@0 701 }
aoqi@0 702
aoqi@0 703 inline ParallelCompactData::BlockData*
aoqi@0 704 ParallelCompactData::addr_to_block_ptr(const HeapWord* addr) const
aoqi@0 705 {
aoqi@0 706 return block(addr_to_block_idx(addr));
aoqi@0 707 }
aoqi@0 708
aoqi@0 709 inline HeapWord*
aoqi@0 710 ParallelCompactData::block_to_addr(size_t block) const
aoqi@0 711 {
aoqi@0 712 assert(block < _block_count, "block out of range");
aoqi@0 713 return _region_start + (block << Log2BlockSize);
aoqi@0 714 }
aoqi@0 715
aoqi@0 716 inline size_t
aoqi@0 717 ParallelCompactData::region_to_block_idx(size_t region) const
aoqi@0 718 {
aoqi@0 719 return region << Log2BlocksPerRegion;
aoqi@0 720 }
aoqi@0 721
aoqi@0 722 inline HeapWord*
aoqi@0 723 ParallelCompactData::block_align_down(HeapWord* addr) const
aoqi@0 724 {
aoqi@0 725 assert(addr >= _region_start, "bad addr");
aoqi@0 726 assert(addr < _region_end + RegionSize, "bad addr");
aoqi@0 727 return (HeapWord*)(size_t(addr) & BlockAddrMask);
aoqi@0 728 }
aoqi@0 729
aoqi@0 730 inline HeapWord*
aoqi@0 731 ParallelCompactData::block_align_up(HeapWord* addr) const
aoqi@0 732 {
aoqi@0 733 assert(addr >= _region_start, "bad addr");
aoqi@0 734 assert(addr <= _region_end, "bad addr");
aoqi@0 735 return block_align_down(addr + BlockSizeOffsetMask);
aoqi@0 736 }
aoqi@0 737
aoqi@0 738 inline bool
aoqi@0 739 ParallelCompactData::is_block_aligned(HeapWord* addr) const
aoqi@0 740 {
aoqi@0 741 return block_offset(addr) == 0;
aoqi@0 742 }
aoqi@0 743
aoqi@0 744 // Abstract closure for use with ParMarkBitMap::iterate(), which will invoke the
aoqi@0 745 // do_addr() method.
aoqi@0 746 //
aoqi@0 747 // The closure is initialized with the number of heap words to process
aoqi@0 748 // (words_remaining()), and becomes 'full' when it reaches 0. The do_addr()
aoqi@0 749 // methods in subclasses should update the total as words are processed. Since
aoqi@0 750 // only one subclass actually uses this mechanism to terminate iteration, the
aoqi@0 751 // default initial value is > 0. The implementation is here and not in the
aoqi@0 752 // single subclass that uses it to avoid making is_full() virtual, and thus
aoqi@0 753 // adding a virtual call per live object.
aoqi@0 754
aoqi@0 755 class ParMarkBitMapClosure: public StackObj {
aoqi@0 756 public:
aoqi@0 757 typedef ParMarkBitMap::idx_t idx_t;
aoqi@0 758 typedef ParMarkBitMap::IterationStatus IterationStatus;
aoqi@0 759
aoqi@0 760 public:
aoqi@0 761 inline ParMarkBitMapClosure(ParMarkBitMap* mbm, ParCompactionManager* cm,
aoqi@0 762 size_t words = max_uintx);
aoqi@0 763
aoqi@0 764 inline ParCompactionManager* compaction_manager() const;
aoqi@0 765 inline ParMarkBitMap* bitmap() const;
aoqi@0 766 inline size_t words_remaining() const;
aoqi@0 767 inline bool is_full() const;
aoqi@0 768 inline HeapWord* source() const;
aoqi@0 769
aoqi@0 770 inline void set_source(HeapWord* addr);
aoqi@0 771
aoqi@0 772 virtual IterationStatus do_addr(HeapWord* addr, size_t words) = 0;
aoqi@0 773
aoqi@0 774 protected:
aoqi@0 775 inline void decrement_words_remaining(size_t words);
aoqi@0 776
aoqi@0 777 private:
aoqi@0 778 ParMarkBitMap* const _bitmap;
aoqi@0 779 ParCompactionManager* const _compaction_manager;
aoqi@0 780 DEBUG_ONLY(const size_t _initial_words_remaining;) // Useful in debugger.
aoqi@0 781 size_t _words_remaining; // Words left to copy.
aoqi@0 782
aoqi@0 783 protected:
aoqi@0 784 HeapWord* _source; // Next addr that would be read.
aoqi@0 785 };
aoqi@0 786
aoqi@0 787 inline
aoqi@0 788 ParMarkBitMapClosure::ParMarkBitMapClosure(ParMarkBitMap* bitmap,
aoqi@0 789 ParCompactionManager* cm,
aoqi@0 790 size_t words):
aoqi@0 791 _bitmap(bitmap), _compaction_manager(cm)
aoqi@0 792 #ifdef ASSERT
aoqi@0 793 , _initial_words_remaining(words)
aoqi@0 794 #endif
aoqi@0 795 {
aoqi@0 796 _words_remaining = words;
aoqi@0 797 _source = NULL;
aoqi@0 798 }
aoqi@0 799
aoqi@0 800 inline ParCompactionManager* ParMarkBitMapClosure::compaction_manager() const {
aoqi@0 801 return _compaction_manager;
aoqi@0 802 }
aoqi@0 803
aoqi@0 804 inline ParMarkBitMap* ParMarkBitMapClosure::bitmap() const {
aoqi@0 805 return _bitmap;
aoqi@0 806 }
aoqi@0 807
aoqi@0 808 inline size_t ParMarkBitMapClosure::words_remaining() const {
aoqi@0 809 return _words_remaining;
aoqi@0 810 }
aoqi@0 811
aoqi@0 812 inline bool ParMarkBitMapClosure::is_full() const {
aoqi@0 813 return words_remaining() == 0;
aoqi@0 814 }
aoqi@0 815
aoqi@0 816 inline HeapWord* ParMarkBitMapClosure::source() const {
aoqi@0 817 return _source;
aoqi@0 818 }
aoqi@0 819
aoqi@0 820 inline void ParMarkBitMapClosure::set_source(HeapWord* addr) {
aoqi@0 821 _source = addr;
aoqi@0 822 }
aoqi@0 823
aoqi@0 824 inline void ParMarkBitMapClosure::decrement_words_remaining(size_t words) {
aoqi@0 825 assert(_words_remaining >= words, "processed too many words");
aoqi@0 826 _words_remaining -= words;
aoqi@0 827 }
aoqi@0 828
aoqi@0 829 // The UseParallelOldGC collector is a stop-the-world garbage collector that
aoqi@0 830 // does parts of the collection using parallel threads. The collection includes
aoqi@0 831 // the tenured generation and the young generation. The permanent generation is
aoqi@0 832 // collected at the same time as the other two generations but the permanent
aoqi@0 833 // generation is collect by a single GC thread. The permanent generation is
aoqi@0 834 // collected serially because of the requirement that during the processing of a
aoqi@0 835 // klass AAA, any objects reference by AAA must already have been processed.
aoqi@0 836 // This requirement is enforced by a left (lower address) to right (higher
aoqi@0 837 // address) sliding compaction.
aoqi@0 838 //
aoqi@0 839 // There are four phases of the collection.
aoqi@0 840 //
aoqi@0 841 // - marking phase
aoqi@0 842 // - summary phase
aoqi@0 843 // - compacting phase
aoqi@0 844 // - clean up phase
aoqi@0 845 //
aoqi@0 846 // Roughly speaking these phases correspond, respectively, to
aoqi@0 847 // - mark all the live objects
aoqi@0 848 // - calculate the destination of each object at the end of the collection
aoqi@0 849 // - move the objects to their destination
aoqi@0 850 // - update some references and reinitialize some variables
aoqi@0 851 //
aoqi@0 852 // These three phases are invoked in PSParallelCompact::invoke_no_policy(). The
aoqi@0 853 // marking phase is implemented in PSParallelCompact::marking_phase() and does a
aoqi@0 854 // complete marking of the heap. The summary phase is implemented in
aoqi@0 855 // PSParallelCompact::summary_phase(). The move and update phase is implemented
aoqi@0 856 // in PSParallelCompact::compact().
aoqi@0 857 //
aoqi@0 858 // A space that is being collected is divided into regions and with each region
aoqi@0 859 // is associated an object of type ParallelCompactData. Each region is of a
aoqi@0 860 // fixed size and typically will contain more than 1 object and may have parts
aoqi@0 861 // of objects at the front and back of the region.
aoqi@0 862 //
aoqi@0 863 // region -----+---------------------+----------
aoqi@0 864 // objects covered [ AAA )[ BBB )[ CCC )[ DDD )
aoqi@0 865 //
aoqi@0 866 // The marking phase does a complete marking of all live objects in the heap.
aoqi@0 867 // The marking also compiles the size of the data for all live objects covered
aoqi@0 868 // by the region. This size includes the part of any live object spanning onto
aoqi@0 869 // the region (part of AAA if it is live) from the front, all live objects
aoqi@0 870 // contained in the region (BBB and/or CCC if they are live), and the part of
aoqi@0 871 // any live objects covered by the region that extends off the region (part of
aoqi@0 872 // DDD if it is live). The marking phase uses multiple GC threads and marking
aoqi@0 873 // is done in a bit array of type ParMarkBitMap. The marking of the bit map is
aoqi@0 874 // done atomically as is the accumulation of the size of the live objects
aoqi@0 875 // covered by a region.
aoqi@0 876 //
aoqi@0 877 // The summary phase calculates the total live data to the left of each region
aoqi@0 878 // XXX. Based on that total and the bottom of the space, it can calculate the
aoqi@0 879 // starting location of the live data in XXX. The summary phase calculates for
aoqi@0 880 // each region XXX quantites such as
aoqi@0 881 //
aoqi@0 882 // - the amount of live data at the beginning of a region from an object
aoqi@0 883 // entering the region.
aoqi@0 884 // - the location of the first live data on the region
aoqi@0 885 // - a count of the number of regions receiving live data from XXX.
aoqi@0 886 //
aoqi@0 887 // See ParallelCompactData for precise details. The summary phase also
aoqi@0 888 // calculates the dense prefix for the compaction. The dense prefix is a
aoqi@0 889 // portion at the beginning of the space that is not moved. The objects in the
aoqi@0 890 // dense prefix do need to have their object references updated. See method
aoqi@0 891 // summarize_dense_prefix().
aoqi@0 892 //
aoqi@0 893 // The summary phase is done using 1 GC thread.
aoqi@0 894 //
aoqi@0 895 // The compaction phase moves objects to their new location and updates all
aoqi@0 896 // references in the object.
aoqi@0 897 //
aoqi@0 898 // A current exception is that objects that cross a region boundary are moved
aoqi@0 899 // but do not have their references updated. References are not updated because
aoqi@0 900 // it cannot easily be determined if the klass pointer KKK for the object AAA
aoqi@0 901 // has been updated. KKK likely resides in a region to the left of the region
aoqi@0 902 // containing AAA. These AAA's have there references updated at the end in a
aoqi@0 903 // clean up phase. See the method PSParallelCompact::update_deferred_objects().
aoqi@0 904 // An alternate strategy is being investigated for this deferral of updating.
aoqi@0 905 //
aoqi@0 906 // Compaction is done on a region basis. A region that is ready to be filled is
aoqi@0 907 // put on a ready list and GC threads take region off the list and fill them. A
aoqi@0 908 // region is ready to be filled if it empty of live objects. Such a region may
aoqi@0 909 // have been initially empty (only contained dead objects) or may have had all
aoqi@0 910 // its live objects copied out already. A region that compacts into itself is
aoqi@0 911 // also ready for filling. The ready list is initially filled with empty
aoqi@0 912 // regions and regions compacting into themselves. There is always at least 1
aoqi@0 913 // region that can be put on the ready list. The regions are atomically added
aoqi@0 914 // and removed from the ready list.
aoqi@0 915
aoqi@0 916 class PSParallelCompact : AllStatic {
aoqi@0 917 public:
aoqi@0 918 // Convenient access to type names.
aoqi@0 919 typedef ParMarkBitMap::idx_t idx_t;
aoqi@0 920 typedef ParallelCompactData::RegionData RegionData;
aoqi@0 921 typedef ParallelCompactData::BlockData BlockData;
aoqi@0 922
aoqi@0 923 typedef enum {
aoqi@0 924 old_space_id, eden_space_id,
aoqi@0 925 from_space_id, to_space_id, last_space_id
aoqi@0 926 } SpaceId;
aoqi@0 927
aoqi@0 928 public:
aoqi@0 929 // Inline closure decls
aoqi@0 930 //
aoqi@0 931 class IsAliveClosure: public BoolObjectClosure {
aoqi@0 932 public:
aoqi@0 933 virtual bool do_object_b(oop p);
aoqi@0 934 };
aoqi@0 935
aoqi@0 936 class KeepAliveClosure: public OopClosure {
aoqi@0 937 private:
aoqi@0 938 ParCompactionManager* _compaction_manager;
aoqi@0 939 protected:
aoqi@0 940 template <class T> inline void do_oop_work(T* p);
aoqi@0 941 public:
aoqi@0 942 KeepAliveClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
aoqi@0 943 virtual void do_oop(oop* p);
aoqi@0 944 virtual void do_oop(narrowOop* p);
aoqi@0 945 };
aoqi@0 946
aoqi@0 947 class FollowStackClosure: public VoidClosure {
aoqi@0 948 private:
aoqi@0 949 ParCompactionManager* _compaction_manager;
aoqi@0 950 public:
aoqi@0 951 FollowStackClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
aoqi@0 952 virtual void do_void();
aoqi@0 953 };
aoqi@0 954
aoqi@0 955 class AdjustPointerClosure: public OopClosure {
aoqi@0 956 public:
aoqi@0 957 virtual void do_oop(oop* p);
aoqi@0 958 virtual void do_oop(narrowOop* p);
aoqi@0 959 // do not walk from thread stacks to the code cache on this phase
aoqi@0 960 virtual void do_code_blob(CodeBlob* cb) const { }
aoqi@0 961 };
aoqi@0 962
aoqi@0 963 class AdjustKlassClosure : public KlassClosure {
aoqi@0 964 public:
aoqi@0 965 void do_klass(Klass* klass);
aoqi@0 966 };
aoqi@0 967
aoqi@0 968 friend class KeepAliveClosure;
aoqi@0 969 friend class FollowStackClosure;
aoqi@0 970 friend class AdjustPointerClosure;
aoqi@0 971 friend class AdjustKlassClosure;
aoqi@0 972 friend class FollowKlassClosure;
aoqi@0 973 friend class InstanceClassLoaderKlass;
aoqi@0 974 friend class RefProcTaskProxy;
aoqi@0 975
aoqi@0 976 private:
aoqi@0 977 static STWGCTimer _gc_timer;
aoqi@0 978 static ParallelOldTracer _gc_tracer;
aoqi@0 979 static elapsedTimer _accumulated_time;
aoqi@0 980 static unsigned int _total_invocations;
aoqi@0 981 static unsigned int _maximum_compaction_gc_num;
aoqi@0 982 static jlong _time_of_last_gc; // ms
aoqi@0 983 static CollectorCounters* _counters;
aoqi@0 984 static ParMarkBitMap _mark_bitmap;
aoqi@0 985 static ParallelCompactData _summary_data;
aoqi@0 986 static IsAliveClosure _is_alive_closure;
aoqi@0 987 static SpaceInfo _space_info[last_space_id];
aoqi@0 988 static bool _print_phases;
aoqi@0 989 static AdjustPointerClosure _adjust_pointer_closure;
aoqi@0 990 static AdjustKlassClosure _adjust_klass_closure;
aoqi@0 991
aoqi@0 992 // Reference processing (used in ...follow_contents)
aoqi@0 993 static ReferenceProcessor* _ref_processor;
aoqi@0 994
aoqi@0 995 // Updated location of intArrayKlassObj.
aoqi@0 996 static Klass* _updated_int_array_klass_obj;
aoqi@0 997
aoqi@0 998 // Values computed at initialization and used by dead_wood_limiter().
aoqi@0 999 static double _dwl_mean;
aoqi@0 1000 static double _dwl_std_dev;
aoqi@0 1001 static double _dwl_first_term;
aoqi@0 1002 static double _dwl_adjustment;
aoqi@0 1003 #ifdef ASSERT
aoqi@0 1004 static bool _dwl_initialized;
aoqi@0 1005 #endif // #ifdef ASSERT
aoqi@0 1006
aoqi@0 1007 private:
aoqi@0 1008
aoqi@0 1009 static void initialize_space_info();
aoqi@0 1010
aoqi@0 1011 // Return true if details about individual phases should be printed.
aoqi@0 1012 static inline bool print_phases();
aoqi@0 1013
aoqi@0 1014 // Clear the marking bitmap and summary data that cover the specified space.
aoqi@0 1015 static void clear_data_covering_space(SpaceId id);
aoqi@0 1016
aoqi@0 1017 static void pre_compact(PreGCValues* pre_gc_values);
aoqi@0 1018 static void post_compact();
aoqi@0 1019
aoqi@0 1020 // Mark live objects
aoqi@0 1021 static void marking_phase(ParCompactionManager* cm,
aoqi@0 1022 bool maximum_heap_compaction,
aoqi@0 1023 ParallelOldTracer *gc_tracer);
aoqi@0 1024
aoqi@0 1025 template <class T>
aoqi@0 1026 static inline void follow_root(ParCompactionManager* cm, T* p);
aoqi@0 1027
aoqi@0 1028 // Compute the dense prefix for the designated space. This is an experimental
aoqi@0 1029 // implementation currently not used in production.
aoqi@0 1030 static HeapWord* compute_dense_prefix_via_density(const SpaceId id,
aoqi@0 1031 bool maximum_compaction);
aoqi@0 1032
aoqi@0 1033 // Methods used to compute the dense prefix.
aoqi@0 1034
aoqi@0 1035 // Compute the value of the normal distribution at x = density. The mean and
aoqi@0 1036 // standard deviation are values saved by initialize_dead_wood_limiter().
aoqi@0 1037 static inline double normal_distribution(double density);
aoqi@0 1038
aoqi@0 1039 // Initialize the static vars used by dead_wood_limiter().
aoqi@0 1040 static void initialize_dead_wood_limiter();
aoqi@0 1041
aoqi@0 1042 // Return the percentage of space that can be treated as "dead wood" (i.e.,
aoqi@0 1043 // not reclaimed).
aoqi@0 1044 static double dead_wood_limiter(double density, size_t min_percent);
aoqi@0 1045
aoqi@0 1046 // Find the first (left-most) region in the range [beg, end) that has at least
aoqi@0 1047 // dead_words of dead space to the left. The argument beg must be the first
aoqi@0 1048 // region in the space that is not completely live.
aoqi@0 1049 static RegionData* dead_wood_limit_region(const RegionData* beg,
aoqi@0 1050 const RegionData* end,
aoqi@0 1051 size_t dead_words);
aoqi@0 1052
aoqi@0 1053 // Return a pointer to the first region in the range [beg, end) that is not
aoqi@0 1054 // completely full.
aoqi@0 1055 static RegionData* first_dead_space_region(const RegionData* beg,
aoqi@0 1056 const RegionData* end);
aoqi@0 1057
aoqi@0 1058 // Return a value indicating the benefit or 'yield' if the compacted region
aoqi@0 1059 // were to start (or equivalently if the dense prefix were to end) at the
aoqi@0 1060 // candidate region. Higher values are better.
aoqi@0 1061 //
aoqi@0 1062 // The value is based on the amount of space reclaimed vs. the costs of (a)
aoqi@0 1063 // updating references in the dense prefix plus (b) copying objects and
aoqi@0 1064 // updating references in the compacted region.
aoqi@0 1065 static inline double reclaimed_ratio(const RegionData* const candidate,
aoqi@0 1066 HeapWord* const bottom,
aoqi@0 1067 HeapWord* const top,
aoqi@0 1068 HeapWord* const new_top);
aoqi@0 1069
aoqi@0 1070 // Compute the dense prefix for the designated space.
aoqi@0 1071 static HeapWord* compute_dense_prefix(const SpaceId id,
aoqi@0 1072 bool maximum_compaction);
aoqi@0 1073
aoqi@0 1074 // Return true if dead space crosses onto the specified Region; bit must be
aoqi@0 1075 // the bit index corresponding to the first word of the Region.
aoqi@0 1076 static inline bool dead_space_crosses_boundary(const RegionData* region,
aoqi@0 1077 idx_t bit);
aoqi@0 1078
aoqi@0 1079 // Summary phase utility routine to fill dead space (if any) at the dense
aoqi@0 1080 // prefix boundary. Should only be called if the the dense prefix is
aoqi@0 1081 // non-empty.
aoqi@0 1082 static void fill_dense_prefix_end(SpaceId id);
aoqi@0 1083
aoqi@0 1084 // Clear the summary data source_region field for the specified addresses.
aoqi@0 1085 static void clear_source_region(HeapWord* beg_addr, HeapWord* end_addr);
aoqi@0 1086
aoqi@0 1087 #ifndef PRODUCT
aoqi@0 1088 // Routines to provoke splitting a young gen space (ParallelOldGCSplitALot).
aoqi@0 1089
aoqi@0 1090 // Fill the region [start, start + words) with live object(s). Only usable
aoqi@0 1091 // for the old and permanent generations.
aoqi@0 1092 static void fill_with_live_objects(SpaceId id, HeapWord* const start,
aoqi@0 1093 size_t words);
aoqi@0 1094 // Include the new objects in the summary data.
aoqi@0 1095 static void summarize_new_objects(SpaceId id, HeapWord* start);
aoqi@0 1096
aoqi@0 1097 // Add live objects to a survivor space since it's rare that both survivors
aoqi@0 1098 // are non-empty.
aoqi@0 1099 static void provoke_split_fill_survivor(SpaceId id);
aoqi@0 1100
aoqi@0 1101 // Add live objects and/or choose the dense prefix to provoke splitting.
aoqi@0 1102 static void provoke_split(bool & maximum_compaction);
aoqi@0 1103 #endif
aoqi@0 1104
aoqi@0 1105 static void summarize_spaces_quick();
aoqi@0 1106 static void summarize_space(SpaceId id, bool maximum_compaction);
aoqi@0 1107 static void summary_phase(ParCompactionManager* cm, bool maximum_compaction);
aoqi@0 1108
aoqi@0 1109 // Adjust addresses in roots. Does not adjust addresses in heap.
aoqi@0 1110 static void adjust_roots();
aoqi@0 1111
aoqi@0 1112 DEBUG_ONLY(static void write_block_fill_histogram(outputStream* const out);)
aoqi@0 1113
aoqi@0 1114 // Move objects to new locations.
aoqi@0 1115 static void compact_perm(ParCompactionManager* cm);
aoqi@0 1116 static void compact();
aoqi@0 1117
aoqi@0 1118 // Add available regions to the stack and draining tasks to the task queue.
aoqi@0 1119 static void enqueue_region_draining_tasks(GCTaskQueue* q,
aoqi@0 1120 uint parallel_gc_threads);
aoqi@0 1121
aoqi@0 1122 // Add dense prefix update tasks to the task queue.
aoqi@0 1123 static void enqueue_dense_prefix_tasks(GCTaskQueue* q,
aoqi@0 1124 uint parallel_gc_threads);
aoqi@0 1125
aoqi@0 1126 // Add region stealing tasks to the task queue.
aoqi@0 1127 static void enqueue_region_stealing_tasks(
aoqi@0 1128 GCTaskQueue* q,
aoqi@0 1129 ParallelTaskTerminator* terminator_ptr,
aoqi@0 1130 uint parallel_gc_threads);
aoqi@0 1131
aoqi@0 1132 // If objects are left in eden after a collection, try to move the boundary
aoqi@0 1133 // and absorb them into the old gen. Returns true if eden was emptied.
aoqi@0 1134 static bool absorb_live_data_from_eden(PSAdaptiveSizePolicy* size_policy,
aoqi@0 1135 PSYoungGen* young_gen,
aoqi@0 1136 PSOldGen* old_gen);
aoqi@0 1137
aoqi@0 1138 // Reset time since last full gc
aoqi@0 1139 static void reset_millis_since_last_gc();
aoqi@0 1140
aoqi@0 1141 public:
aoqi@0 1142 class MarkAndPushClosure: public OopClosure {
aoqi@0 1143 private:
aoqi@0 1144 ParCompactionManager* _compaction_manager;
aoqi@0 1145 public:
aoqi@0 1146 MarkAndPushClosure(ParCompactionManager* cm) : _compaction_manager(cm) { }
aoqi@0 1147 virtual void do_oop(oop* p);
aoqi@0 1148 virtual void do_oop(narrowOop* p);
aoqi@0 1149 };
aoqi@0 1150
aoqi@0 1151 // The one and only place to start following the classes.
aoqi@0 1152 // Should only be applied to the ClassLoaderData klasses list.
aoqi@0 1153 class FollowKlassClosure : public KlassClosure {
aoqi@0 1154 private:
aoqi@0 1155 MarkAndPushClosure* _mark_and_push_closure;
aoqi@0 1156 public:
aoqi@0 1157 FollowKlassClosure(MarkAndPushClosure* mark_and_push_closure) :
aoqi@0 1158 _mark_and_push_closure(mark_and_push_closure) { }
aoqi@0 1159 void do_klass(Klass* klass);
aoqi@0 1160 };
aoqi@0 1161
aoqi@0 1162 PSParallelCompact();
aoqi@0 1163
aoqi@0 1164 // Convenient accessor for Universe::heap().
aoqi@0 1165 static ParallelScavengeHeap* gc_heap() {
aoqi@0 1166 return (ParallelScavengeHeap*)Universe::heap();
aoqi@0 1167 }
aoqi@0 1168
aoqi@0 1169 static void invoke(bool maximum_heap_compaction);
aoqi@0 1170 static bool invoke_no_policy(bool maximum_heap_compaction);
aoqi@0 1171
aoqi@0 1172 static void post_initialize();
aoqi@0 1173 // Perform initialization for PSParallelCompact that requires
aoqi@0 1174 // allocations. This should be called during the VM initialization
aoqi@0 1175 // at a pointer where it would be appropriate to return a JNI_ENOMEM
aoqi@0 1176 // in the event of a failure.
aoqi@0 1177 static bool initialize();
aoqi@0 1178
aoqi@0 1179 // Closure accessors
aoqi@0 1180 static OopClosure* adjust_pointer_closure() { return (OopClosure*)&_adjust_pointer_closure; }
aoqi@0 1181 static KlassClosure* adjust_klass_closure() { return (KlassClosure*)&_adjust_klass_closure; }
aoqi@0 1182 static BoolObjectClosure* is_alive_closure() { return (BoolObjectClosure*)&_is_alive_closure; }
aoqi@0 1183
aoqi@0 1184 // Public accessors
aoqi@0 1185 static elapsedTimer* accumulated_time() { return &_accumulated_time; }
aoqi@0 1186 static unsigned int total_invocations() { return _total_invocations; }
aoqi@0 1187 static CollectorCounters* counters() { return _counters; }
aoqi@0 1188
aoqi@0 1189 // Used to add tasks
aoqi@0 1190 static GCTaskManager* const gc_task_manager();
aoqi@0 1191 static Klass* updated_int_array_klass_obj() {
aoqi@0 1192 return _updated_int_array_klass_obj;
aoqi@0 1193 }
aoqi@0 1194
aoqi@0 1195 // Marking support
aoqi@0 1196 static inline bool mark_obj(oop obj);
aoqi@0 1197 static inline bool is_marked(oop obj);
aoqi@0 1198 // Check mark and maybe push on marking stack
aoqi@0 1199 template <class T> static inline void mark_and_push(ParCompactionManager* cm,
aoqi@0 1200 T* p);
aoqi@0 1201 template <class T> static inline void adjust_pointer(T* p);
aoqi@0 1202
aoqi@0 1203 static inline void follow_klass(ParCompactionManager* cm, Klass* klass);
aoqi@0 1204
aoqi@0 1205 static void follow_class_loader(ParCompactionManager* cm,
aoqi@0 1206 ClassLoaderData* klass);
aoqi@0 1207
aoqi@0 1208 // Compaction support.
aoqi@0 1209 // Return true if p is in the range [beg_addr, end_addr).
aoqi@0 1210 static inline bool is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr);
aoqi@0 1211 static inline bool is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr);
aoqi@0 1212
aoqi@0 1213 // Convenience wrappers for per-space data kept in _space_info.
aoqi@0 1214 static inline MutableSpace* space(SpaceId space_id);
aoqi@0 1215 static inline HeapWord* new_top(SpaceId space_id);
aoqi@0 1216 static inline HeapWord* dense_prefix(SpaceId space_id);
aoqi@0 1217 static inline ObjectStartArray* start_array(SpaceId space_id);
aoqi@0 1218
aoqi@0 1219 // Move and update the live objects in the specified space.
aoqi@0 1220 static void move_and_update(ParCompactionManager* cm, SpaceId space_id);
aoqi@0 1221
aoqi@0 1222 // Process the end of the given region range in the dense prefix.
aoqi@0 1223 // This includes saving any object not updated.
aoqi@0 1224 static void dense_prefix_regions_epilogue(ParCompactionManager* cm,
aoqi@0 1225 size_t region_start_index,
aoqi@0 1226 size_t region_end_index,
aoqi@0 1227 idx_t exiting_object_offset,
aoqi@0 1228 idx_t region_offset_start,
aoqi@0 1229 idx_t region_offset_end);
aoqi@0 1230
aoqi@0 1231 // Update a region in the dense prefix. For each live object
aoqi@0 1232 // in the region, update it's interior references. For each
aoqi@0 1233 // dead object, fill it with deadwood. Dead space at the end
aoqi@0 1234 // of a region range will be filled to the start of the next
aoqi@0 1235 // live object regardless of the region_index_end. None of the
aoqi@0 1236 // objects in the dense prefix move and dead space is dead
aoqi@0 1237 // (holds only dead objects that don't need any processing), so
aoqi@0 1238 // dead space can be filled in any order.
aoqi@0 1239 static void update_and_deadwood_in_dense_prefix(ParCompactionManager* cm,
aoqi@0 1240 SpaceId space_id,
aoqi@0 1241 size_t region_index_start,
aoqi@0 1242 size_t region_index_end);
aoqi@0 1243
aoqi@0 1244 // Return the address of the count + 1st live word in the range [beg, end).
aoqi@0 1245 static HeapWord* skip_live_words(HeapWord* beg, HeapWord* end, size_t count);
aoqi@0 1246
aoqi@0 1247 // Return the address of the word to be copied to dest_addr, which must be
aoqi@0 1248 // aligned to a region boundary.
aoqi@0 1249 static HeapWord* first_src_addr(HeapWord* const dest_addr,
aoqi@0 1250 SpaceId src_space_id,
aoqi@0 1251 size_t src_region_idx);
aoqi@0 1252
aoqi@0 1253 // Determine the next source region, set closure.source() to the start of the
aoqi@0 1254 // new region return the region index. Parameter end_addr is the address one
aoqi@0 1255 // beyond the end of source range just processed. If necessary, switch to a
aoqi@0 1256 // new source space and set src_space_id (in-out parameter) and src_space_top
aoqi@0 1257 // (out parameter) accordingly.
aoqi@0 1258 static size_t next_src_region(MoveAndUpdateClosure& closure,
aoqi@0 1259 SpaceId& src_space_id,
aoqi@0 1260 HeapWord*& src_space_top,
aoqi@0 1261 HeapWord* end_addr);
aoqi@0 1262
aoqi@0 1263 // Decrement the destination count for each non-empty source region in the
aoqi@0 1264 // range [beg_region, region(region_align_up(end_addr))). If the destination
aoqi@0 1265 // count for a region goes to 0 and it needs to be filled, enqueue it.
aoqi@0 1266 static void decrement_destination_counts(ParCompactionManager* cm,
aoqi@0 1267 SpaceId src_space_id,
aoqi@0 1268 size_t beg_region,
aoqi@0 1269 HeapWord* end_addr);
aoqi@0 1270
aoqi@0 1271 // Fill a region, copying objects from one or more source regions.
aoqi@0 1272 static void fill_region(ParCompactionManager* cm, size_t region_idx);
aoqi@0 1273 static void fill_and_update_region(ParCompactionManager* cm, size_t region) {
aoqi@0 1274 fill_region(cm, region);
aoqi@0 1275 }
aoqi@0 1276
aoqi@0 1277 // Fill in the block table for the specified region.
aoqi@0 1278 static void fill_blocks(size_t region_idx);
aoqi@0 1279
aoqi@0 1280 // Update the deferred objects in the space.
aoqi@0 1281 static void update_deferred_objects(ParCompactionManager* cm, SpaceId id);
aoqi@0 1282
aoqi@0 1283 static ParMarkBitMap* mark_bitmap() { return &_mark_bitmap; }
aoqi@0 1284 static ParallelCompactData& summary_data() { return _summary_data; }
aoqi@0 1285
aoqi@0 1286 // Reference Processing
aoqi@0 1287 static ReferenceProcessor* const ref_processor() { return _ref_processor; }
aoqi@0 1288
aoqi@0 1289 static STWGCTimer* gc_timer() { return &_gc_timer; }
aoqi@0 1290
aoqi@0 1291 // Return the SpaceId for the given address.
aoqi@0 1292 static SpaceId space_id(HeapWord* addr);
aoqi@0 1293
aoqi@0 1294 // Time since last full gc (in milliseconds).
aoqi@0 1295 static jlong millis_since_last_gc();
aoqi@0 1296
aoqi@0 1297 static void print_on_error(outputStream* st);
aoqi@0 1298
aoqi@0 1299 #ifndef PRODUCT
aoqi@0 1300 // Debugging support.
aoqi@0 1301 static const char* space_names[last_space_id];
aoqi@0 1302 static void print_region_ranges();
aoqi@0 1303 static void print_dense_prefix_stats(const char* const algorithm,
aoqi@0 1304 const SpaceId id,
aoqi@0 1305 const bool maximum_compaction,
aoqi@0 1306 HeapWord* const addr);
aoqi@0 1307 static void summary_phase_msg(SpaceId dst_space_id,
aoqi@0 1308 HeapWord* dst_beg, HeapWord* dst_end,
aoqi@0 1309 SpaceId src_space_id,
aoqi@0 1310 HeapWord* src_beg, HeapWord* src_end);
aoqi@0 1311 #endif // #ifndef PRODUCT
aoqi@0 1312
aoqi@0 1313 #ifdef ASSERT
aoqi@0 1314 // Sanity check the new location of a word in the heap.
aoqi@0 1315 static inline void check_new_location(HeapWord* old_addr, HeapWord* new_addr);
aoqi@0 1316 // Verify that all the regions have been emptied.
aoqi@0 1317 static void verify_complete(SpaceId space_id);
aoqi@0 1318 #endif // #ifdef ASSERT
aoqi@0 1319 };
aoqi@0 1320
aoqi@0 1321 inline bool PSParallelCompact::mark_obj(oop obj) {
aoqi@0 1322 const int obj_size = obj->size();
aoqi@0 1323 if (mark_bitmap()->mark_obj(obj, obj_size)) {
aoqi@0 1324 _summary_data.add_obj(obj, obj_size);
fujie@124 1325 #ifdef MIPS64
fujie@124 1326 if (Use3A2000) OrderAccess::fence();
fujie@124 1327 #endif
aoqi@0 1328 return true;
aoqi@0 1329 } else {
aoqi@0 1330 return false;
aoqi@0 1331 }
aoqi@0 1332 }
aoqi@0 1333
aoqi@0 1334 inline bool PSParallelCompact::is_marked(oop obj) {
aoqi@0 1335 return mark_bitmap()->is_marked(obj);
aoqi@0 1336 }
aoqi@0 1337
aoqi@0 1338 template <class T>
aoqi@0 1339 inline void PSParallelCompact::follow_root(ParCompactionManager* cm, T* p) {
aoqi@0 1340 assert(!Universe::heap()->is_in_reserved(p),
aoqi@0 1341 "roots shouldn't be things within the heap");
aoqi@0 1342
aoqi@0 1343 T heap_oop = oopDesc::load_heap_oop(p);
aoqi@0 1344 if (!oopDesc::is_null(heap_oop)) {
aoqi@0 1345 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
aoqi@0 1346 if (mark_bitmap()->is_unmarked(obj)) {
aoqi@0 1347 if (mark_obj(obj)) {
aoqi@0 1348 obj->follow_contents(cm);
aoqi@0 1349 }
aoqi@0 1350 }
aoqi@0 1351 }
aoqi@0 1352 cm->follow_marking_stacks();
aoqi@0 1353 }
aoqi@0 1354
aoqi@0 1355 template <class T>
aoqi@0 1356 inline void PSParallelCompact::mark_and_push(ParCompactionManager* cm, T* p) {
aoqi@0 1357 T heap_oop = oopDesc::load_heap_oop(p);
aoqi@0 1358 if (!oopDesc::is_null(heap_oop)) {
aoqi@0 1359 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
aoqi@0 1360 if (mark_bitmap()->is_unmarked(obj) && mark_obj(obj)) {
aoqi@0 1361 cm->push(obj);
fujie@124 1362 #ifdef MIPS64
fujie@124 1363 if (Use3A2000) OrderAccess::fence();
fujie@124 1364 #endif
aoqi@0 1365 }
aoqi@0 1366 }
aoqi@0 1367 }
aoqi@0 1368
aoqi@0 1369 template <class T>
aoqi@0 1370 inline void PSParallelCompact::adjust_pointer(T* p) {
aoqi@0 1371 T heap_oop = oopDesc::load_heap_oop(p);
aoqi@0 1372 if (!oopDesc::is_null(heap_oop)) {
aoqi@0 1373 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
aoqi@0 1374 oop new_obj = (oop)summary_data().calc_new_pointer(obj);
aoqi@0 1375 assert(new_obj != NULL, // is forwarding ptr?
aoqi@0 1376 "should be forwarded");
aoqi@0 1377 // Just always do the update unconditionally?
aoqi@0 1378 if (new_obj != NULL) {
aoqi@0 1379 assert(Universe::heap()->is_in_reserved(new_obj),
aoqi@0 1380 "should be in object space");
aoqi@0 1381 oopDesc::encode_store_heap_oop_not_null(p, new_obj);
aoqi@0 1382 }
aoqi@0 1383 }
aoqi@0 1384 }
aoqi@0 1385
aoqi@0 1386 inline void PSParallelCompact::follow_klass(ParCompactionManager* cm, Klass* klass) {
aoqi@0 1387 oop holder = klass->klass_holder();
aoqi@0 1388 PSParallelCompact::mark_and_push(cm, &holder);
aoqi@0 1389 }
aoqi@0 1390
aoqi@0 1391 template <class T>
aoqi@0 1392 inline void PSParallelCompact::KeepAliveClosure::do_oop_work(T* p) {
aoqi@0 1393 mark_and_push(_compaction_manager, p);
aoqi@0 1394 }
aoqi@0 1395
aoqi@0 1396 inline bool PSParallelCompact::print_phases() {
aoqi@0 1397 return _print_phases;
aoqi@0 1398 }
aoqi@0 1399
aoqi@0 1400 inline double PSParallelCompact::normal_distribution(double density) {
aoqi@0 1401 assert(_dwl_initialized, "uninitialized");
aoqi@0 1402 const double squared_term = (density - _dwl_mean) / _dwl_std_dev;
aoqi@0 1403 return _dwl_first_term * exp(-0.5 * squared_term * squared_term);
aoqi@0 1404 }
aoqi@0 1405
aoqi@0 1406 inline bool
aoqi@0 1407 PSParallelCompact::dead_space_crosses_boundary(const RegionData* region,
aoqi@0 1408 idx_t bit)
aoqi@0 1409 {
aoqi@0 1410 assert(bit > 0, "cannot call this for the first bit/region");
aoqi@0 1411 assert(_summary_data.region_to_addr(region) == _mark_bitmap.bit_to_addr(bit),
aoqi@0 1412 "sanity check");
aoqi@0 1413
aoqi@0 1414 // Dead space crosses the boundary if (1) a partial object does not extend
aoqi@0 1415 // onto the region, (2) an object does not start at the beginning of the
aoqi@0 1416 // region, and (3) an object does not end at the end of the prior region.
aoqi@0 1417 return region->partial_obj_size() == 0 &&
aoqi@0 1418 !_mark_bitmap.is_obj_beg(bit) &&
aoqi@0 1419 !_mark_bitmap.is_obj_end(bit - 1);
aoqi@0 1420 }
aoqi@0 1421
aoqi@0 1422 inline bool
aoqi@0 1423 PSParallelCompact::is_in(HeapWord* p, HeapWord* beg_addr, HeapWord* end_addr) {
aoqi@0 1424 return p >= beg_addr && p < end_addr;
aoqi@0 1425 }
aoqi@0 1426
aoqi@0 1427 inline bool
aoqi@0 1428 PSParallelCompact::is_in(oop* p, HeapWord* beg_addr, HeapWord* end_addr) {
aoqi@0 1429 return is_in((HeapWord*)p, beg_addr, end_addr);
aoqi@0 1430 }
aoqi@0 1431
aoqi@0 1432 inline MutableSpace* PSParallelCompact::space(SpaceId id) {
aoqi@0 1433 assert(id < last_space_id, "id out of range");
aoqi@0 1434 return _space_info[id].space();
aoqi@0 1435 }
aoqi@0 1436
aoqi@0 1437 inline HeapWord* PSParallelCompact::new_top(SpaceId id) {
aoqi@0 1438 assert(id < last_space_id, "id out of range");
aoqi@0 1439 return _space_info[id].new_top();
aoqi@0 1440 }
aoqi@0 1441
aoqi@0 1442 inline HeapWord* PSParallelCompact::dense_prefix(SpaceId id) {
aoqi@0 1443 assert(id < last_space_id, "id out of range");
aoqi@0 1444 return _space_info[id].dense_prefix();
aoqi@0 1445 }
aoqi@0 1446
aoqi@0 1447 inline ObjectStartArray* PSParallelCompact::start_array(SpaceId id) {
aoqi@0 1448 assert(id < last_space_id, "id out of range");
aoqi@0 1449 return _space_info[id].start_array();
aoqi@0 1450 }
aoqi@0 1451
aoqi@0 1452 #ifdef ASSERT
aoqi@0 1453 inline void
aoqi@0 1454 PSParallelCompact::check_new_location(HeapWord* old_addr, HeapWord* new_addr)
aoqi@0 1455 {
aoqi@0 1456 assert(old_addr >= new_addr || space_id(old_addr) != space_id(new_addr),
aoqi@0 1457 "must move left or to a different space");
aoqi@0 1458 assert(is_object_aligned((intptr_t)old_addr) && is_object_aligned((intptr_t)new_addr),
aoqi@0 1459 "checking alignment");
aoqi@0 1460 }
aoqi@0 1461 #endif // ASSERT
aoqi@0 1462
aoqi@0 1463 class MoveAndUpdateClosure: public ParMarkBitMapClosure {
aoqi@0 1464 public:
aoqi@0 1465 inline MoveAndUpdateClosure(ParMarkBitMap* bitmap, ParCompactionManager* cm,
aoqi@0 1466 ObjectStartArray* start_array,
aoqi@0 1467 HeapWord* destination, size_t words);
aoqi@0 1468
aoqi@0 1469 // Accessors.
aoqi@0 1470 HeapWord* destination() const { return _destination; }
aoqi@0 1471
aoqi@0 1472 // If the object will fit (size <= words_remaining()), copy it to the current
aoqi@0 1473 // destination, update the interior oops and the start array and return either
aoqi@0 1474 // full (if the closure is full) or incomplete. If the object will not fit,
aoqi@0 1475 // return would_overflow.
aoqi@0 1476 virtual IterationStatus do_addr(HeapWord* addr, size_t size);
aoqi@0 1477
aoqi@0 1478 // Copy enough words to fill this closure, starting at source(). Interior
aoqi@0 1479 // oops and the start array are not updated. Return full.
aoqi@0 1480 IterationStatus copy_until_full();
aoqi@0 1481
aoqi@0 1482 // Copy enough words to fill this closure or to the end of an object,
aoqi@0 1483 // whichever is smaller, starting at source(). Interior oops and the start
aoqi@0 1484 // array are not updated.
aoqi@0 1485 void copy_partial_obj();
aoqi@0 1486
aoqi@0 1487 protected:
aoqi@0 1488 // Update variables to indicate that word_count words were processed.
aoqi@0 1489 inline void update_state(size_t word_count);
aoqi@0 1490
aoqi@0 1491 protected:
aoqi@0 1492 ObjectStartArray* const _start_array;
aoqi@0 1493 HeapWord* _destination; // Next addr to be written.
aoqi@0 1494 };
aoqi@0 1495
aoqi@0 1496 inline
aoqi@0 1497 MoveAndUpdateClosure::MoveAndUpdateClosure(ParMarkBitMap* bitmap,
aoqi@0 1498 ParCompactionManager* cm,
aoqi@0 1499 ObjectStartArray* start_array,
aoqi@0 1500 HeapWord* destination,
aoqi@0 1501 size_t words) :
aoqi@0 1502 ParMarkBitMapClosure(bitmap, cm, words), _start_array(start_array)
aoqi@0 1503 {
aoqi@0 1504 _destination = destination;
aoqi@0 1505 }
aoqi@0 1506
aoqi@0 1507 inline void MoveAndUpdateClosure::update_state(size_t words)
aoqi@0 1508 {
aoqi@0 1509 decrement_words_remaining(words);
aoqi@0 1510 _source += words;
aoqi@0 1511 _destination += words;
aoqi@0 1512 }
aoqi@0 1513
aoqi@0 1514 class UpdateOnlyClosure: public ParMarkBitMapClosure {
aoqi@0 1515 private:
aoqi@0 1516 const PSParallelCompact::SpaceId _space_id;
aoqi@0 1517 ObjectStartArray* const _start_array;
aoqi@0 1518
aoqi@0 1519 public:
aoqi@0 1520 UpdateOnlyClosure(ParMarkBitMap* mbm,
aoqi@0 1521 ParCompactionManager* cm,
aoqi@0 1522 PSParallelCompact::SpaceId space_id);
aoqi@0 1523
aoqi@0 1524 // Update the object.
aoqi@0 1525 virtual IterationStatus do_addr(HeapWord* addr, size_t words);
aoqi@0 1526
aoqi@0 1527 inline void do_addr(HeapWord* addr);
aoqi@0 1528 };
aoqi@0 1529
aoqi@0 1530 inline void UpdateOnlyClosure::do_addr(HeapWord* addr)
aoqi@0 1531 {
aoqi@0 1532 _start_array->allocate_block(addr);
aoqi@0 1533 oop(addr)->update_contents(compaction_manager());
aoqi@0 1534 }
aoqi@0 1535
aoqi@0 1536 class FillClosure: public ParMarkBitMapClosure
aoqi@0 1537 {
aoqi@0 1538 public:
aoqi@0 1539 FillClosure(ParCompactionManager* cm, PSParallelCompact::SpaceId space_id) :
aoqi@0 1540 ParMarkBitMapClosure(PSParallelCompact::mark_bitmap(), cm),
aoqi@0 1541 _start_array(PSParallelCompact::start_array(space_id))
aoqi@0 1542 {
aoqi@0 1543 assert(space_id == PSParallelCompact::old_space_id,
aoqi@0 1544 "cannot use FillClosure in the young gen");
aoqi@0 1545 }
aoqi@0 1546
aoqi@0 1547 virtual IterationStatus do_addr(HeapWord* addr, size_t size) {
aoqi@0 1548 CollectedHeap::fill_with_objects(addr, size);
aoqi@0 1549 HeapWord* const end = addr + size;
aoqi@0 1550 do {
aoqi@0 1551 _start_array->allocate_block(addr);
aoqi@0 1552 addr += oop(addr)->size();
aoqi@0 1553 } while (addr < end);
aoqi@0 1554 return ParMarkBitMap::incomplete;
aoqi@0 1555 }
aoqi@0 1556
aoqi@0 1557 private:
aoqi@0 1558 ObjectStartArray* const _start_array;
aoqi@0 1559 };
aoqi@0 1560
aoqi@0 1561 #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPARALLELCOMPACT_HPP

mercurial