src/share/vm/gc_implementation/g1/g1BlockOffsetTable.hpp

Print this page
rev 6587 : 8047820: G1 Block offset table does not need to support generic Space classes
Reviewed-by:


  35 // operation may be important.  Implementations of the "BlockOffsetArray"
  36 // class may be useful in providing such efficient implementations.
  37 //
  38 // While generally mirroring the structure of the BOT for GenCollectedHeap,
  39 // the following types are tailored more towards G1's uses; these should,
  40 // however, be merged back into a common BOT to avoid code duplication
  41 // and reduce maintenance overhead.
  42 //
  43 //    G1BlockOffsetTable (abstract)
  44 //    -- G1BlockOffsetArray                (uses G1BlockOffsetSharedArray)
  45 //       -- G1BlockOffsetArrayContigSpace
  46 //
  47 // A main impediment to the consolidation of this code might be the
  48 // effect of making some of the block_start*() calls non-const as
  49 // below. Whether that might adversely affect performance optimizations
  50 // that compilers might normally perform in the case of non-G1
  51 // collectors needs to be carefully investigated prior to any such
  52 // consolidation.
  53 
  54 // Forward declarations
  55 class ContiguousSpace;
  56 class G1BlockOffsetSharedArray;

  57 
  58 class G1BlockOffsetTable VALUE_OBJ_CLASS_SPEC {
  59   friend class VMStructs;
  60 protected:
  61   // These members describe the region covered by the table.
  62 
  63   // The space this table is covering.
  64   HeapWord* _bottom;    // == reserved.start
  65   HeapWord* _end;       // End of currently allocated region.
  66 
  67 public:
  68   // Initialize the table to cover the given space.
  69   // The contents of the initial table are undefined.
  70   G1BlockOffsetTable(HeapWord* bottom, HeapWord* end) :
  71     _bottom(bottom), _end(end)
  72     {
  73       assert(_bottom <= _end, "arguments out of order");
  74     }
  75 
  76   // Note that the committed size of the covered space may have changed,


 264   friend class VMStructs;
 265 private:
 266   enum SomePrivateConstants {
 267     N_words = G1BlockOffsetSharedArray::N_words,
 268     LogN    = G1BlockOffsetSharedArray::LogN
 269   };
 270 
 271   // The following enums are used by do_block_helper
 272   enum Action {
 273     Action_single,      // BOT records a single block (see single_block())
 274     Action_mark,        // BOT marks the start of a block (see mark_block())
 275     Action_check        // Check that BOT records block correctly
 276                         // (see verify_single_block()).
 277   };
 278 
 279   // This is the array, which can be shared by several BlockOffsetArray's
 280   // servicing different
 281   G1BlockOffsetSharedArray* _array;
 282 
 283   // The space that owns this subregion.
 284   Space* _sp;
 285 
 286   // If "_sp" is a contiguous space, the field below is the view of "_sp"
 287   // as a contiguous space, else NULL.
 288   ContiguousSpace* _csp;
 289 
 290   // If true, array entries are initialized to 0; otherwise, they are
 291   // initialized to point backwards to the beginning of the covered region.
 292   bool _init_to_zero;
 293 
 294   // The portion [_unallocated_block, _sp.end()) of the space that
 295   // is a single block known not to contain any objects.
 296   // NOTE: See BlockOffsetArrayUseUnallocatedBlock flag.
 297   HeapWord* _unallocated_block;
 298 
 299   // Sets the entries
 300   // corresponding to the cards starting at "start" and ending at "end"
 301   // to point back to the card before "start": the interval [start, end)
 302   // is right-open.
 303   void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end);
 304   // Same as above, except that the args here are a card _index_ interval
 305   // that is closed: [start_index, end_index]
 306   void set_remainder_to_point_to_start_incl(size_t start, size_t end);
 307 
 308   // A helper function for BOT adjustment/verification work
 309   void do_block_internal(HeapWord* blk_start, HeapWord* blk_end, Action action);
 310 
 311 protected:
 312 
 313   ContiguousSpace* csp() const { return _csp; }


 314 
 315   // Returns the address of a block whose start is at most "addr".
 316   // If "has_max_index" is true, "assumes "max_index" is the last valid one
 317   // in the array.
 318   inline HeapWord* block_at_or_preceding(const void* addr,
 319                                          bool has_max_index,
 320                                          size_t max_index) const;
 321 
 322   // "q" is a block boundary that is <= "addr"; "n" is the address of the
 323   // next block (or the end of the space.)  Return the address of the
 324   // beginning of the block that contains "addr".  Does so without side
 325   // effects (see, e.g., spec of  block_start.)
 326   inline HeapWord*
 327   forward_to_block_containing_addr_const(HeapWord* q, HeapWord* n,
 328                                          const void* addr) const;
 329 
 330   // "q" is a block boundary that is <= "addr"; return the address of the
 331   // beginning of the block that contains "addr".  May have side effects
 332   // on "this", by updating imprecise entries.
 333   inline HeapWord* forward_to_block_containing_addr(HeapWord* q,


 346   // index.  If the block starts at or crosses "*threshold_", records
 347   // "blk_start" as the appropriate block start for the array index
 348   // starting at "*threshold_", and for any other indices crossed by the
 349   // block.  Updates "*threshold_" and "*index_" to correspond to the first
 350   // index after the block end.
 351   void alloc_block_work2(HeapWord** threshold_, size_t* index_,
 352                          HeapWord* blk_start, HeapWord* blk_end);
 353 
 354 public:
 355   // The space may not have it's bottom and top set yet, which is why the
 356   // region is passed as a parameter.  If "init_to_zero" is true, the
 357   // elements of the array are initialized to zero.  Otherwise, they are
 358   // initialized to point backwards to the beginning.
 359   G1BlockOffsetArray(G1BlockOffsetSharedArray* array, MemRegion mr,
 360                      bool init_to_zero);
 361 
 362   // Note: this ought to be part of the constructor, but that would require
 363   // "this" to be passed as a parameter to a member constructor for
 364   // the containing concrete subtype of Space.
 365   // This would be legal C++, but MS VC++ doesn't allow it.
 366   void set_space(Space* sp);
 367 
 368   // Resets the covered region to the given "mr".
 369   void set_region(MemRegion mr);
 370 
 371   // Resets the covered region to one with the same _bottom as before but
 372   // the "new_word_size".
 373   void resize(size_t new_word_size);
 374 
 375   // These must be guaranteed to work properly (i.e., do nothing)
 376   // when "blk_start" ("blk" for second version) is "NULL".
 377   virtual void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
 378   virtual void alloc_block(HeapWord* blk, size_t size) {
 379     alloc_block(blk, blk + size);
 380   }
 381 
 382   // The following methods are useful and optimized for a
 383   // general, non-contiguous space.
 384 
 385   // Given a block [blk_start, blk_start + full_blk_size), and
 386   // a left_blk_size < full_blk_size, adjust the BOT to show two




  35 // operation may be important.  Implementations of the "BlockOffsetArray"
  36 // class may be useful in providing such efficient implementations.
  37 //
  38 // While generally mirroring the structure of the BOT for GenCollectedHeap,
  39 // the following types are tailored more towards G1's uses; these should,
  40 // however, be merged back into a common BOT to avoid code duplication
  41 // and reduce maintenance overhead.
  42 //
  43 //    G1BlockOffsetTable (abstract)
  44 //    -- G1BlockOffsetArray                (uses G1BlockOffsetSharedArray)
  45 //       -- G1BlockOffsetArrayContigSpace
  46 //
  47 // A main impediment to the consolidation of this code might be the
  48 // effect of making some of the block_start*() calls non-const as
  49 // below. Whether that might adversely affect performance optimizations
  50 // that compilers might normally perform in the case of non-G1
  51 // collectors needs to be carefully investigated prior to any such
  52 // consolidation.
  53 
  54 // Forward declarations

  55 class G1BlockOffsetSharedArray;
  56 class G1OffsetTableContigSpace;
  57 
  58 class G1BlockOffsetTable VALUE_OBJ_CLASS_SPEC {
  59   friend class VMStructs;
  60 protected:
  61   // These members describe the region covered by the table.
  62 
  63   // The space this table is covering.
  64   HeapWord* _bottom;    // == reserved.start
  65   HeapWord* _end;       // End of currently allocated region.
  66 
  67 public:
  68   // Initialize the table to cover the given space.
  69   // The contents of the initial table are undefined.
  70   G1BlockOffsetTable(HeapWord* bottom, HeapWord* end) :
  71     _bottom(bottom), _end(end)
  72     {
  73       assert(_bottom <= _end, "arguments out of order");
  74     }
  75 
  76   // Note that the committed size of the covered space may have changed,


 264   friend class VMStructs;
 265 private:
 266   enum SomePrivateConstants {
 267     N_words = G1BlockOffsetSharedArray::N_words,
 268     LogN    = G1BlockOffsetSharedArray::LogN
 269   };
 270 
 271   // The following enums are used by do_block_helper
 272   enum Action {
 273     Action_single,      // BOT records a single block (see single_block())
 274     Action_mark,        // BOT marks the start of a block (see mark_block())
 275     Action_check        // Check that BOT records block correctly
 276                         // (see verify_single_block()).
 277   };
 278 
 279   // This is the array, which can be shared by several BlockOffsetArray's
 280   // servicing different
 281   G1BlockOffsetSharedArray* _array;
 282 
 283   // The space that owns this subregion.
 284   G1OffsetTableContigSpace* _gsp;




 285 
 286   // If true, array entries are initialized to 0; otherwise, they are
 287   // initialized to point backwards to the beginning of the covered region.
 288   bool _init_to_zero;
 289 
 290   // The portion [_unallocated_block, _sp.end()) of the space that
 291   // is a single block known not to contain any objects.
 292   // NOTE: See BlockOffsetArrayUseUnallocatedBlock flag.
 293   HeapWord* _unallocated_block;
 294 
 295   // Sets the entries
 296   // corresponding to the cards starting at "start" and ending at "end"
 297   // to point back to the card before "start": the interval [start, end)
 298   // is right-open.
 299   void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end);
 300   // Same as above, except that the args here are a card _index_ interval
 301   // that is closed: [start_index, end_index]
 302   void set_remainder_to_point_to_start_incl(size_t start, size_t end);
 303 
 304   // A helper function for BOT adjustment/verification work
 305   void do_block_internal(HeapWord* blk_start, HeapWord* blk_end, Action action);
 306 
 307 protected:
 308 
 309   G1OffsetTableContigSpace* gsp() const { return _gsp; }
 310 
 311   inline size_t block_size(const HeapWord* p) const;
 312 
 313   // Returns the address of a block whose start is at most "addr".
 314   // If "has_max_index" is true, "assumes "max_index" is the last valid one
 315   // in the array.
 316   inline HeapWord* block_at_or_preceding(const void* addr,
 317                                          bool has_max_index,
 318                                          size_t max_index) const;
 319 
 320   // "q" is a block boundary that is <= "addr"; "n" is the address of the
 321   // next block (or the end of the space.)  Return the address of the
 322   // beginning of the block that contains "addr".  Does so without side
 323   // effects (see, e.g., spec of  block_start.)
 324   inline HeapWord*
 325   forward_to_block_containing_addr_const(HeapWord* q, HeapWord* n,
 326                                          const void* addr) const;
 327 
 328   // "q" is a block boundary that is <= "addr"; return the address of the
 329   // beginning of the block that contains "addr".  May have side effects
 330   // on "this", by updating imprecise entries.
 331   inline HeapWord* forward_to_block_containing_addr(HeapWord* q,


 344   // index.  If the block starts at or crosses "*threshold_", records
 345   // "blk_start" as the appropriate block start for the array index
 346   // starting at "*threshold_", and for any other indices crossed by the
 347   // block.  Updates "*threshold_" and "*index_" to correspond to the first
 348   // index after the block end.
 349   void alloc_block_work2(HeapWord** threshold_, size_t* index_,
 350                          HeapWord* blk_start, HeapWord* blk_end);
 351 
 352 public:
 353   // The space may not have it's bottom and top set yet, which is why the
 354   // region is passed as a parameter.  If "init_to_zero" is true, the
 355   // elements of the array are initialized to zero.  Otherwise, they are
 356   // initialized to point backwards to the beginning.
 357   G1BlockOffsetArray(G1BlockOffsetSharedArray* array, MemRegion mr,
 358                      bool init_to_zero);
 359 
 360   // Note: this ought to be part of the constructor, but that would require
 361   // "this" to be passed as a parameter to a member constructor for
 362   // the containing concrete subtype of Space.
 363   // This would be legal C++, but MS VC++ doesn't allow it.
 364   void set_space(G1OffsetTableContigSpace* sp);
 365 
 366   // Resets the covered region to the given "mr".
 367   void set_region(MemRegion mr);
 368 
 369   // Resets the covered region to one with the same _bottom as before but
 370   // the "new_word_size".
 371   void resize(size_t new_word_size);
 372 
 373   // These must be guaranteed to work properly (i.e., do nothing)
 374   // when "blk_start" ("blk" for second version) is "NULL".
 375   virtual void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
 376   virtual void alloc_block(HeapWord* blk, size_t size) {
 377     alloc_block(blk, blk + size);
 378   }
 379 
 380   // The following methods are useful and optimized for a
 381   // general, non-contiguous space.
 382 
 383   // Given a block [blk_start, blk_start + full_blk_size), and
 384   // a left_blk_size < full_blk_size, adjust the BOT to show two