src/share/vm/memory/space.hpp

Print this page
rev 7084 : [mq]: demacro

@@ -44,10 +44,11 @@
 // Here's the Space hierarchy:
 //
 // - Space               -- an abstract base class describing a heap area
 //   - CompactibleSpace  -- a space supporting compaction
 //     - CompactibleFreeListSpace -- (used for CMS generation)
+//     - G1OffsetTableContigSpace -- G1 version of OffsetTableContigSpace
 //     - ContiguousSpace -- a compactible space in which all free space
 //                          is contiguous
 //       - EdenSpace     -- contiguous space used as nursery
 //         - ConcEdenSpace -- contiguous space with a 'soft end safe' allocation
 //       - OffsetTableContigSpace -- contiguous space with a block offset array

@@ -389,11 +390,11 @@
   // which we are currently compacting.  This call updates "cp" as necessary,
   // and leaves the "compaction_top" of the final value of
   // "cp->compaction_space" up-to-date.  Offset tables may be updated in
   // this phase as if the final copy had occurred; if so, "cp->threshold"
   // indicates when the next such action should be taken.
-  virtual void prepare_for_compaction(CompactPoint* cp);
+  virtual void prepare_for_compaction(CompactPoint* cp) = 0;
   // MarkSweep support phase3
   virtual void adjust_pointers();
   // MarkSweep support phase4
   virtual void compact();
 

@@ -424,10 +425,25 @@
                     HeapWord* compact_top);
 
   // Return a size with adjustments as required of the space.
   virtual size_t adjust_object_size_v(size_t size) const { return size; }
 
+  // Functions for scan_and_{forward,adjust_pointers,compact} support.
+  inline bool scanned_block_is_obj(const HeapWord* addr) const {
+    // Perform virtual call. This is currently not a problem since this
+    // function is only used in an assert (from scan_and_adjust_pointers).
+    return block_is_obj(addr);
+  }
+
+  inline size_t adjust_obj_size(size_t size) const {
+    return size;
+  }
+
+  inline size_t obj_size(const HeapWord* addr) const {
+    return oop(addr)->size();
+  }
+
 protected:
   // Used during compaction.
   HeapWord* _first_dead;
   HeapWord* _end_of_live;
 

@@ -448,10 +464,29 @@
   // iff the free region was made deadspace, and modifies
   // "allowed_deadspace_words" to reflect the number of available deadspace
   // words remaining after this operation.
   bool insert_deadspace(size_t& allowed_deadspace_words, HeapWord* q,
                         size_t word_len);
+
+  // Below are template functions for scan_and_* algorithms (avoiding virtual calls).
+  // The space argument should be a subclass of CompactibleSpace, implementing
+  // scan_limit(), scanned_block_is_obj(), and scanned_block_size(),
+  // and possibly also overriding obj_size(), and adjust_obj_size().
+  // These functions should avoid virtual calls whenever possible.
+
+  // Frequently calls adjust_obj_size(). (Asserts on scanned_block_is_obj().)
+  template <class SpaceType>
+  static inline void scan_and_adjust_pointers(SpaceType* space);
+
+  // Frequently calls obj_size().
+  template <class SpaceType>
+  static inline void scan_and_compact(SpaceType* space);
+
+  // Frequently calls scanned_block_is_obj() and scanned_block_size().
+  // Requires the scan_limit() function.
+  template <class SpaceType>
+  static inline void scan_and_forward(SpaceType* space, CompactPoint* cp);
 };
 
 class GenSpaceMangler;
 
 // A space in which the free area is contiguous.  It therefore supports

@@ -622,10 +657,22 @@
 
   // Used to increase collection frequency.  "factor" of 0 means entire
   // space.
   void allocate_temporary_filler(int factor);
 
+  // Functions for scan_and_{forward,adjust_pointers,compact} support.
+  inline HeapWord* scan_limit() const {
+    return top();
+  }
+
+  inline bool scanned_block_is_obj(const HeapWord* addr) const {
+    return true; // Always true, since scan_limit is top
+  }
+
+  inline size_t scanned_block_size(const HeapWord* addr) const {
+    return oop(addr)->size();
+  }
 };
 
 
 // A dirty card to oop closure that does filtering.
 // It knows how to filter out objects that are outside of the _boundary.