< prev index next >

src/hotspot/share/memory/heap.hpp

Print this page
rev 49260 : [mq]: 8198691.patch


 112   size_t   segments_to_size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; }
 113 
 114   size_t   segment_for(void* p) const            { return ((char*)p - _memory.low()) >> _log2_segment_size; }
 115   bool     is_segment_unused(int val) const      { return val == free_sentinel; }
 116   HeapBlock* block_at(size_t i) const            { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); }
 117 
 118   void  mark_segmap_as_free(size_t beg, size_t end);
 119   void  mark_segmap_as_used(size_t beg, size_t end);
 120 
 121   // Freelist management helpers
 122   FreeBlock* following_block(FreeBlock* b);
 123   void insert_after(FreeBlock* a, FreeBlock* b);
 124   bool merge_right (FreeBlock* a);
 125 
 126   // Toplevel freelist management
 127   void add_to_freelist(HeapBlock* b);
 128   FreeBlock* search_freelist(size_t length);
 129 
 130   // Iteration helpers
 131   void*      next_used(HeapBlock* b) const;
 132   HeapBlock* first_block() const;
 133   HeapBlock* next_block(HeapBlock* b) const;
 134   HeapBlock* block_start(void* p) const;
 135 
 136   // to perform additional actions on creation of executable code
 137   void on_code_mapping(char* base, size_t size);
 138   void clear();                                 // clears all heap contents
 139 
 140  public:
 141   CodeHeap(const char* name, const int code_blob_type);
 142 
 143   // Heap extents
 144   bool  reserve(ReservedSpace rs, size_t committed_size, size_t segment_size);
 145   bool  expand_by(size_t size);                  // expands committed memory by size
 146 
 147   // Memory allocation
 148   void* allocate (size_t size); // Allocate 'size' bytes in the code cache or return NULL
 149   void  deallocate(void* p);    // Deallocate memory
 150   // Free the tail of segments allocated by the last call to 'allocate()' which exceed 'used_size'.
 151   // ATTENTION: this is only safe to use if there was no other call to 'allocate()' after
 152   //            'p' was allocated. Only intended for freeing memory which would be otherwise
 153   //            wasted after the interpreter generation because we don't know the interpreter size


 161 
 162   bool contains(const void* p) const             { return low_boundary() <= p && p < high(); }
 163   bool contains_blob(const CodeBlob* blob) const {
 164     // AOT CodeBlobs (i.e. AOTCompiledMethod) objects aren't allocated in the AOTCodeHeap but on the C-Heap.
 165     // Only the code they are pointing to is located in the AOTCodeHeap. All other CodeBlobs are allocated
 166     // directly in their corresponding CodeHeap with their code appended to the actual C++ object.
 167     // So all CodeBlobs except AOTCompiledMethod are continuous in memory with their data and code while
 168     // AOTCompiledMethod and their code/data is distributed in the C-Heap. This means we can use the
 169     // address of a CodeBlob object in order to locate it in its heap while we have to use the address
 170     // of the actual code an AOTCompiledMethod object is pointing to in order to locate it.
 171     // Notice that for an ordinary CodeBlob with code size zero, code_begin() may point beyond the object!
 172     const void* start = AOT_ONLY( (code_blob_type() == CodeBlobType::AOT) ? blob->code_begin() : ) (void*)blob;
 173     return contains(start);
 174   }
 175 
 176   virtual void* find_start(void* p)     const;   // returns the block containing p or NULL
 177   virtual CodeBlob* find_blob_unsafe(void* start) const;
 178   size_t alignment_unit()       const;           // alignment of any block
 179   size_t alignment_offset()     const;           // offset of first byte of any block, within the enclosing alignment unit
 180   static size_t header_size();                   // returns the header size for each heap block






 181 
 182   size_t allocated_in_freelist() const           { return _freelist_segments * CodeCacheSegmentSize; }
 183   int    freelist_length()       const           { return _freelist_length; } // number of elements in the freelist
 184 
 185   // returns the first block or NULL
 186   virtual void* first() const                    { return next_used(first_block()); }
 187   // returns the next block given a block p or NULL
 188   virtual void* next(void* p) const              { return next_used(next_block(block_start(p))); }
 189 
 190   // Statistics
 191   size_t capacity() const;
 192   size_t max_capacity() const;
 193   int    allocated_segments() const;
 194   size_t allocated_capacity() const;
 195   size_t max_allocated_capacity() const          { return _max_allocated_capacity; }
 196   size_t unallocated_capacity() const            { return max_capacity() - allocated_capacity(); }
 197 
 198   // Returns true if the CodeHeap contains CodeBlobs of the given type
 199   bool accepts(int code_blob_type) const         { return (_code_blob_type == CodeBlobType::All) ||
 200                                                           (_code_blob_type == code_blob_type); }




 112   size_t   segments_to_size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; }
 113 
 114   size_t   segment_for(void* p) const            { return ((char*)p - _memory.low()) >> _log2_segment_size; }
 115   bool     is_segment_unused(int val) const      { return val == free_sentinel; }
 116   HeapBlock* block_at(size_t i) const            { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); }
 117 
 118   void  mark_segmap_as_free(size_t beg, size_t end);
 119   void  mark_segmap_as_used(size_t beg, size_t end);
 120 
 121   // Freelist management helpers
 122   FreeBlock* following_block(FreeBlock* b);
 123   void insert_after(FreeBlock* a, FreeBlock* b);
 124   bool merge_right (FreeBlock* a);
 125 
 126   // Toplevel freelist management
 127   void add_to_freelist(HeapBlock* b);
 128   FreeBlock* search_freelist(size_t length);
 129 
 130   // Iteration helpers
 131   void*      next_used(HeapBlock* b) const;
 132 //   HeapBlock* first_block() const;
 133 //   HeapBlock* next_block(HeapBlock* b) const;
 134   HeapBlock* block_start(void* p) const;
 135 
 136   // to perform additional actions on creation of executable code
 137   void on_code_mapping(char* base, size_t size);
 138   void clear();                                 // clears all heap contents
 139 
 140  public:
 141   CodeHeap(const char* name, const int code_blob_type);
 142 
 143   // Heap extents
 144   bool  reserve(ReservedSpace rs, size_t committed_size, size_t segment_size);
 145   bool  expand_by(size_t size);                  // expands committed memory by size
 146 
 147   // Memory allocation
 148   void* allocate (size_t size); // Allocate 'size' bytes in the code cache or return NULL
 149   void  deallocate(void* p);    // Deallocate memory
 150   // Free the tail of segments allocated by the last call to 'allocate()' which exceed 'used_size'.
 151   // ATTENTION: this is only safe to use if there was no other call to 'allocate()' after
 152   //            'p' was allocated. Only intended for freeing memory which would be otherwise
 153   //            wasted after the interpreter generation because we don't know the interpreter size


 161 
 162   bool contains(const void* p) const             { return low_boundary() <= p && p < high(); }
 163   bool contains_blob(const CodeBlob* blob) const {
 164     // AOT CodeBlobs (i.e. AOTCompiledMethod) objects aren't allocated in the AOTCodeHeap but on the C-Heap.
 165     // Only the code they are pointing to is located in the AOTCodeHeap. All other CodeBlobs are allocated
 166     // directly in their corresponding CodeHeap with their code appended to the actual C++ object.
 167     // So all CodeBlobs except AOTCompiledMethod are continuous in memory with their data and code while
 168     // AOTCompiledMethod and their code/data is distributed in the C-Heap. This means we can use the
 169     // address of a CodeBlob object in order to locate it in its heap while we have to use the address
 170     // of the actual code an AOTCompiledMethod object is pointing to in order to locate it.
 171     // Notice that for an ordinary CodeBlob with code size zero, code_begin() may point beyond the object!
 172     const void* start = AOT_ONLY( (code_blob_type() == CodeBlobType::AOT) ? blob->code_begin() : ) (void*)blob;
 173     return contains(start);
 174   }
 175 
 176   virtual void* find_start(void* p)     const;   // returns the block containing p or NULL
 177   virtual CodeBlob* find_blob_unsafe(void* start) const;
 178   size_t alignment_unit()       const;           // alignment of any block
 179   size_t alignment_offset()     const;           // offset of first byte of any block, within the enclosing alignment unit
 180   static size_t header_size();                   // returns the header size for each heap block
 181 
 182   size_t segment_size()         const { return _segment_size; }  // for CodeHeapState
 183   HeapBlock* first_block() const;                                // for CodeHeapState
 184   HeapBlock* next_block(HeapBlock* b) const;                     // for CodeHeapState
 185 
 186   FreeBlock* freelist()         const { return _freelist; }      // for CodeHeapState
 187 
 188   size_t allocated_in_freelist() const           { return _freelist_segments * CodeCacheSegmentSize; }
 189   int    freelist_length()       const           { return _freelist_length; } // number of elements in the freelist
 190 
 191   // returns the first block or NULL
 192   virtual void* first() const                    { return next_used(first_block()); }
 193   // returns the next block given a block p or NULL
 194   virtual void* next(void* p) const              { return next_used(next_block(block_start(p))); }
 195 
 196   // Statistics
 197   size_t capacity() const;
 198   size_t max_capacity() const;
 199   int    allocated_segments() const;
 200   size_t allocated_capacity() const;
 201   size_t max_allocated_capacity() const          { return _max_allocated_capacity; }
 202   size_t unallocated_capacity() const            { return max_capacity() - allocated_capacity(); }
 203 
 204   // Returns true if the CodeHeap contains CodeBlobs of the given type
 205   bool accepts(int code_blob_type) const         { return (_code_blob_type == CodeBlobType::All) ||
 206                                                           (_code_blob_type == code_blob_type); }


< prev index next >