src/share/vm/memory/heap.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8015774 Sdiff src/share/vm/memory

src/share/vm/memory/heap.hpp

Print this page




   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_HEAP_HPP
  26 #define SHARE_VM_MEMORY_HEAP_HPP
  27 

  28 #include "memory/allocation.hpp"
  29 #include "runtime/virtualspace.hpp"
  30 
  31 // Blocks
  32 
  33 class HeapBlock VALUE_OBJ_CLASS_SPEC {
  34   friend class VMStructs;
  35 
  36  public:
  37   struct Header {
  38     size_t  _length;                             // the length in segments
  39     bool    _used;                               // Used bit
  40   };
  41 
  42  protected:
  43   union {
  44     Header _header;
  45     int64_t _padding[ (sizeof(Header) + sizeof(int64_t)-1) / sizeof(int64_t) ];
  46                         // pad to 0 mod 8
  47   };


  76   FreeBlock* link() const                    { return _link; }
  77   void set_link(FreeBlock* link)             { _link = link; }
  78 };
  79 
  80 class CodeHeap : public CHeapObj<mtCode> {
  81   friend class VMStructs;
  82  private:
  83   VirtualSpace _memory;                          // the memory holding the blocks
  84   VirtualSpace _segmap;                          // the memory holding the segment map
  85 
  86   size_t       _number_of_committed_segments;
  87   size_t       _number_of_reserved_segments;
  88   size_t       _segment_size;
  89   int          _log2_segment_size;
  90 
  91   size_t       _next_segment;
  92 
  93   FreeBlock*   _freelist;
  94   size_t       _freelist_segments;               // No. of segments in freelist
  95   int          _freelist_length;





  96 
  97   enum { free_sentinel = 0xFF };
  98 
  99   // Helper functions
 100   size_t   size_to_segments(size_t size) const { return (size + _segment_size - 1) >> _log2_segment_size; }
 101   size_t   segments_to_size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; }
 102 
 103   size_t   segment_for(void* p) const            { return ((char*)p - _memory.low()) >> _log2_segment_size; }
 104   bool     is_segment_unused(int val) const      { return val == free_sentinel; }
 105   HeapBlock* block_at(size_t i) const            { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); }
 106 
 107   void  mark_segmap_as_free(size_t beg, size_t end);
 108   void  mark_segmap_as_used(size_t beg, size_t end);
 109 
 110   // Freelist management helpers
 111   FreeBlock* following_block(FreeBlock* b);
 112   void insert_after(FreeBlock* a, FreeBlock* b);
 113   bool merge_right (FreeBlock* a);
 114 
 115   // Toplevel freelist management
 116   void add_to_freelist(HeapBlock* b);
 117   FreeBlock* search_freelist(size_t length, bool is_critical);
 118 
 119   // Iteration helpers
 120   void*      next_free(HeapBlock* b) const;
 121   HeapBlock* first_block() const;
 122   HeapBlock* next_block(HeapBlock* b) const;
 123   HeapBlock* block_start(void* p) const;
 124 
 125   // to perform additional actions on creation of executable code
 126   void on_code_mapping(char* base, size_t size);
 127   void clear();                                 // clears all heap contents
 128 
 129  public:
 130   CodeHeap();
 131 
 132   // Heap extents
 133   bool  reserve(size_t reserved_size, size_t committed_size, size_t segment_size);
 134   bool  expand_by(size_t size);                  // expands committed memory by size
 135 
 136   // Memory allocation
 137   void* allocate  (size_t size, bool is_critical);  // allocates a block of size or returns NULL
 138   void  deallocate(void* p);                        // deallocates a block
 139 
 140   // Attributes
 141   char* low_boundary() const                     { return _memory.low_boundary (); }
 142   char* high() const                             { return _memory.high(); }
 143   char* high_boundary() const                    { return _memory.high_boundary(); }
 144 
 145   bool  contains(const void* p) const            { return low_boundary() <= p && p < high(); }
 146   void* find_start(void* p)     const;           // returns the block containing p or NULL
 147   size_t alignment_unit()       const;           // alignment of any block
 148   size_t alignment_offset()     const;           // offset of first byte of any block, within the enclosing alignment unit
 149   static size_t header_size();                   // returns the header size for each heap block
 150 
 151   size_t allocated_in_freelist() const           { return _freelist_segments * CodeCacheSegmentSize; }
 152   int    freelist_length()       const           { return _freelist_length; } // number of elements in the freelist
 153 
 154   // returns the first block or NULL
 155   void* first() const       { return next_free(first_block()); }
 156   // returns the next block given a block p or NULL
 157   void* next(void* p) const { return next_free(next_block(block_start(p))); }
 158 
 159   // Statistics
 160   size_t capacity() const;
 161   size_t max_capacity() const;
 162   int    allocated_segments() const;
 163   size_t allocated_capacity() const;

 164   size_t unallocated_capacity() const            { return max_capacity() - allocated_capacity(); }









 165 
 166 private:
 167   size_t heap_unallocated_capacity() const;
 168 
 169 public:
 170   // Debugging
 171   void verify() PRODUCT_RETURN;
 172   void print()  PRODUCT_RETURN;
 173 };
 174 
 175 #endif // SHARE_VM_MEMORY_HEAP_HPP


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_MEMORY_HEAP_HPP
  26 #define SHARE_VM_MEMORY_HEAP_HPP
  27 
  28 #include "code/codeBlob.hpp"
  29 #include "memory/allocation.hpp"
  30 #include "runtime/virtualspace.hpp"
  31 
  32 // Blocks
  33 
  34 class HeapBlock VALUE_OBJ_CLASS_SPEC {
  35   friend class VMStructs;
  36 
  37  public:
  38   struct Header {
  39     size_t  _length;                             // the length in segments
  40     bool    _used;                               // Used bit
  41   };
  42 
  43  protected:
  44   union {
  45     Header _header;
  46     int64_t _padding[ (sizeof(Header) + sizeof(int64_t)-1) / sizeof(int64_t) ];
  47                         // pad to 0 mod 8
  48   };


  77   FreeBlock* link() const                    { return _link; }
  78   void set_link(FreeBlock* link)             { _link = link; }
  79 };
  80 
  81 class CodeHeap : public CHeapObj<mtCode> {
  82   friend class VMStructs;
  83  private:
  84   VirtualSpace _memory;                          // the memory holding the blocks
  85   VirtualSpace _segmap;                          // the memory holding the segment map
  86 
  87   size_t       _number_of_committed_segments;
  88   size_t       _number_of_reserved_segments;
  89   size_t       _segment_size;
  90   int          _log2_segment_size;
  91 
  92   size_t       _next_segment;
  93 
  94   FreeBlock*   _freelist;
  95   size_t       _freelist_segments;               // No. of segments in freelist
  96   int          _freelist_length;
  97   size_t       _max_allocated_capacity;          // Peak capacity that was allocated during lifetime of the heap
  98 
  99   const char*  _name;                            // Name of the CodeHeap
 100   const int    _code_blob_type;                  // CodeBlobType it contains
 101   bool         _was_full;                        // True if the code heap was full
 102 
 103   enum { free_sentinel = 0xFF };
 104 
 105   // Helper functions
 106   size_t   size_to_segments(size_t size) const { return (size + _segment_size - 1) >> _log2_segment_size; }
 107   size_t   segments_to_size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; }
 108 
 109   size_t   segment_for(void* p) const            { return ((char*)p - _memory.low()) >> _log2_segment_size; }
 110   bool     is_segment_unused(int val) const      { return val == free_sentinel; }
 111   HeapBlock* block_at(size_t i) const            { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); }
 112 
 113   void  mark_segmap_as_free(size_t beg, size_t end);
 114   void  mark_segmap_as_used(size_t beg, size_t end);
 115 
 116   // Freelist management helpers
 117   FreeBlock* following_block(FreeBlock* b);
 118   void insert_after(FreeBlock* a, FreeBlock* b);
 119   bool merge_right (FreeBlock* a);
 120 
 121   // Toplevel freelist management
 122   void add_to_freelist(HeapBlock* b);
 123   FreeBlock* search_freelist(size_t length, bool is_critical);
 124 
 125   // Iteration helpers
 126   void*      next_free(HeapBlock* b) const;
 127   HeapBlock* first_block() const;
 128   HeapBlock* next_block(HeapBlock* b) const;
 129   HeapBlock* block_start(void* p) const;
 130 
 131   // to perform additional actions on creation of executable code
 132   void on_code_mapping(char* base, size_t size);
 133   void clear();                                 // clears all heap contents
 134 
 135  public:
 136   CodeHeap(const char* name, const int code_blob_type);
 137 
 138   // Heap extents
 139   bool  reserve(ReservedSpace rs, size_t committed_size, size_t segment_size);
 140   bool  expand_by(size_t size);                  // expands committed memory by size
 141 
 142   // Memory allocation
 143   void* allocate  (size_t size, bool is_critical);  // allocates a block of size or returns NULL
 144   void  deallocate(void* p);                        // deallocates a block
 145 
 146   // Attributes
 147   char* low_boundary() const                     { return _memory.low_boundary (); }
 148   char* high() const                             { return _memory.high(); }
 149   char* high_boundary() const                    { return _memory.high_boundary(); }
 150 
 151   bool  contains(const void* p) const            { return low_boundary() <= p && p < high(); }
 152   void* find_start(void* p)     const;           // returns the block containing p or NULL
 153   size_t alignment_unit()       const;           // alignment of any block
 154   size_t alignment_offset()     const;           // offset of first byte of any block, within the enclosing alignment unit
 155   static size_t header_size();                   // returns the header size for each heap block
 156 
 157   size_t allocated_in_freelist() const           { return _freelist_segments * CodeCacheSegmentSize; }
 158   int    freelist_length()       const           { return _freelist_length; } // number of elements in the freelist
 159 
 160   // returns the first block or NULL
 161   void* first() const       { return next_free(first_block()); }
 162   // returns the next block given a block p or NULL
 163   void* next(void* p) const { return next_free(next_block(block_start(p))); }
 164 
 165   // Statistics
 166   size_t capacity() const;
 167   size_t max_capacity() const;
 168   int    allocated_segments() const;
 169   size_t allocated_capacity() const;
 170   size_t max_allocated_capacity() const          { return _max_allocated_capacity; }
 171   size_t unallocated_capacity() const            { return max_capacity() - allocated_capacity(); }
 172 
 173   // Returns true if the CodeHeap contains CodeBlobs of the given type
 174   bool accepts(int code_blob_type) const         { return (_code_blob_type == code_blob_type); }
 175   int code_blob_type() const                     { return _code_blob_type; }
 176 
 177   // Debugging / Profiling
 178   const char* name() const                       { return _name; }
 179   bool was_full()                                { return _was_full; }
 180   void report_full()                             { _was_full = true; }
 181 
 182 private:
 183   size_t heap_unallocated_capacity() const;
 184 
 185 public:
 186   // Debugging
 187   void verify() PRODUCT_RETURN;
 188   void print()  PRODUCT_RETURN;
 189 };
 190 
 191 #endif // SHARE_VM_MEMORY_HEAP_HPP
src/share/vm/memory/heap.hpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File