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 | 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); 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); // Allocate 'size' bytes in the code cache or return NULL 144 void deallocate(void* p); // Deallocate memory 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 |