65 class FreeBlock: public HeapBlock {
66 friend class VMStructs;
67 protected:
68 FreeBlock* _link;
69
70 public:
71 // Initialization
72 void initialize(size_t length) { HeapBlock::initialize(length); _link= NULL; }
73
74 // Merging
75 void set_length(size_t l) { _header._length = l; }
76
77 // Accessors
78 FreeBlock* link() const { return _link; }
79 void set_link(FreeBlock* link) { _link = link; }
80 };
81
82 class CodeHeap : public CHeapObj<mtCode> {
83 friend class VMStructs;
84 friend class PregeneratedCodeHeap;
85 private:
86 VirtualSpace _memory; // the memory holding the blocks
87 VirtualSpace _segmap; // the memory holding the segment map
88
89 size_t _number_of_committed_segments;
90 size_t _number_of_reserved_segments;
91 size_t _segment_size;
92 int _log2_segment_size;
93
94 size_t _next_segment;
95
96 FreeBlock* _freelist;
97 size_t _freelist_segments; // No. of segments in freelist
98 int _freelist_length;
99 size_t _max_allocated_capacity; // Peak capacity that was allocated during lifetime of the heap
100
101 const char* _name; // Name of the CodeHeap
102 const int _code_blob_type; // CodeBlobType it contains
103 int _blob_count; // Number of CodeBlobs
104 int _nmethod_count; // Number of nmethods
105 int _adapter_count; // Number of adapters
139 void clear(); // clears all heap contents
140
141 public:
142 CodeHeap(const char* name, const int code_blob_type);
143
144 // Heap extents
145 bool reserve(ReservedSpace rs, size_t committed_size, size_t segment_size);
146 bool expand_by(size_t size); // expands committed memory by size
147
148 // Memory allocation
149 void* allocate (size_t size); // Allocate 'size' bytes in the code cache or return NULL
150 void deallocate(void* p); // Deallocate memory
151
152 // Attributes
153 char* low_boundary() const { return _memory.low_boundary (); }
154 char* high() const { return _memory.high(); }
155 char* high_boundary() const { return _memory.high_boundary(); }
156
157 virtual bool contains(const void* p) const { return low_boundary() <= p && p < high(); }
158 virtual void* find_start(void* p) const; // returns the block containing p or NULL
159 size_t alignment_unit() const; // alignment of any block
160 size_t alignment_offset() const; // offset of first byte of any block, within the enclosing alignment unit
161 static size_t header_size(); // returns the header size for each heap block
162
163 size_t allocated_in_freelist() const { return _freelist_segments * CodeCacheSegmentSize; }
164 int freelist_length() const { return _freelist_length; } // number of elements in the freelist
165
166 // returns the first block or NULL
167 virtual void* first() const { return next_used(first_block()); }
168 // returns the next block given a block p or NULL
169 virtual void* next(void* p) const { return next_used(next_block(block_start(p))); }
170
171 // Statistics
172 size_t capacity() const;
173 size_t max_capacity() const;
174 int allocated_segments() const;
175 size_t allocated_capacity() const;
176 size_t max_allocated_capacity() const { return _max_allocated_capacity; }
177 size_t unallocated_capacity() const { return max_capacity() - allocated_capacity(); }
178
|
65 class FreeBlock: public HeapBlock {
66 friend class VMStructs;
67 protected:
68 FreeBlock* _link;
69
70 public:
71 // Initialization
72 void initialize(size_t length) { HeapBlock::initialize(length); _link= NULL; }
73
74 // Merging
75 void set_length(size_t l) { _header._length = l; }
76
77 // Accessors
78 FreeBlock* link() const { return _link; }
79 void set_link(FreeBlock* link) { _link = link; }
80 };
81
82 class CodeHeap : public CHeapObj<mtCode> {
83 friend class VMStructs;
84 friend class PregeneratedCodeHeap;
85 protected:
86 VirtualSpace _memory; // the memory holding the blocks
87 VirtualSpace _segmap; // the memory holding the segment map
88
89 size_t _number_of_committed_segments;
90 size_t _number_of_reserved_segments;
91 size_t _segment_size;
92 int _log2_segment_size;
93
94 size_t _next_segment;
95
96 FreeBlock* _freelist;
97 size_t _freelist_segments; // No. of segments in freelist
98 int _freelist_length;
99 size_t _max_allocated_capacity; // Peak capacity that was allocated during lifetime of the heap
100
101 const char* _name; // Name of the CodeHeap
102 const int _code_blob_type; // CodeBlobType it contains
103 int _blob_count; // Number of CodeBlobs
104 int _nmethod_count; // Number of nmethods
105 int _adapter_count; // Number of adapters
139 void clear(); // clears all heap contents
140
141 public:
142 CodeHeap(const char* name, const int code_blob_type);
143
144 // Heap extents
145 bool reserve(ReservedSpace rs, size_t committed_size, size_t segment_size);
146 bool expand_by(size_t size); // expands committed memory by size
147
148 // Memory allocation
149 void* allocate (size_t size); // Allocate 'size' bytes in the code cache or return NULL
150 void deallocate(void* p); // Deallocate memory
151
152 // Attributes
153 char* low_boundary() const { return _memory.low_boundary (); }
154 char* high() const { return _memory.high(); }
155 char* high_boundary() const { return _memory.high_boundary(); }
156
157 virtual bool contains(const void* p) const { return low_boundary() <= p && p < high(); }
158 virtual void* find_start(void* p) const; // returns the block containing p or NULL
159 virtual CodeBlob* find_blob_unsafe(void* start) const;
160 size_t alignment_unit() const; // alignment of any block
161 size_t alignment_offset() const; // offset of first byte of any block, within the enclosing alignment unit
162 static size_t header_size(); // returns the header size for each heap block
163
164 size_t allocated_in_freelist() const { return _freelist_segments * CodeCacheSegmentSize; }
165 int freelist_length() const { return _freelist_length; } // number of elements in the freelist
166
167 // returns the first block or NULL
168 virtual void* first() const { return next_used(first_block()); }
169 // returns the next block given a block p or NULL
170 virtual void* next(void* p) const { return next_used(next_block(block_start(p))); }
171
172 // Statistics
173 size_t capacity() const;
174 size_t max_capacity() const;
175 int allocated_segments() const;
176 size_t allocated_capacity() const;
177 size_t max_allocated_capacity() const { return _max_allocated_capacity; }
178 size_t unallocated_capacity() const { return max_capacity() - allocated_capacity(); }
179
|