comparison src/share/vm/memory/heap.hpp @ 14687:480b0109db65

8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000 Summary: Double CodeCacheSegmentSize from 64 byte to 128 bytes if tiered compilation is enabled Reviewed-by: kvn, twisti
author anoll
date Fri, 07 Mar 2014 07:42:40 +0100
parents 63a4eb8bcd23
children 92aa6797d639
comparison
equal deleted inserted replaced
14686:97586c131ac8 14687:480b0109db65
90 90
91 size_t _next_segment; 91 size_t _next_segment;
92 92
93 FreeBlock* _freelist; 93 FreeBlock* _freelist;
94 size_t _freelist_segments; // No. of segments in freelist 94 size_t _freelist_segments; // No. of segments in freelist
95 int _freelist_length;
96
97 enum { free_sentinel = 0xFF };
95 98
96 // Helper functions 99 // Helper functions
97 size_t size_to_segments(size_t size) const { return (size + _segment_size - 1) >> _log2_segment_size; } 100 size_t size_to_segments(size_t size) const { return (size + _segment_size - 1) >> _log2_segment_size; }
98 size_t segments_to_size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; } 101 size_t segments_to_size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; }
99 102
100 size_t segment_for(void* p) const { return ((char*)p - _memory.low()) >> _log2_segment_size; } 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; }
101 HeapBlock* block_at(size_t i) const { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); } 105 HeapBlock* block_at(size_t i) const { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); }
102 106
103 void mark_segmap_as_free(size_t beg, size_t end); 107 void mark_segmap_as_free(size_t beg, size_t end);
104 void mark_segmap_as_used(size_t beg, size_t end); 108 void mark_segmap_as_used(size_t beg, size_t end);
105 109
106 // Freelist management helpers 110 // Freelist management helpers
107 FreeBlock* following_block(FreeBlock *b); 111 FreeBlock* following_block(FreeBlock* b);
108 void insert_after(FreeBlock* a, FreeBlock* b); 112 void insert_after(FreeBlock* a, FreeBlock* b);
109 void merge_right (FreeBlock* a); 113 bool merge_right (FreeBlock* a);
110 114
111 // Toplevel freelist management 115 // Toplevel freelist management
112 void add_to_freelist(HeapBlock *b); 116 void add_to_freelist(HeapBlock* b);
113 FreeBlock* search_freelist(size_t length, bool is_critical); 117 FreeBlock* search_freelist(size_t length, bool is_critical);
114 118
115 // Iteration helpers 119 // Iteration helpers
116 void* next_free(HeapBlock* b) const; 120 void* next_free(HeapBlock* b) const;
117 HeapBlock* first_block() const; 121 HeapBlock* first_block() const;
118 HeapBlock* next_block(HeapBlock* b) const; 122 HeapBlock* next_block(HeapBlock* b) const;
119 HeapBlock* block_start(void* p) const; 123 HeapBlock* block_start(void* p) const;
120 124
121 // to perform additional actions on creation of executable code 125 // to perform additional actions on creation of executable code
122 void on_code_mapping(char* base, size_t size); 126 void on_code_mapping(char* base, size_t size);
127 void clear(); // clears all heap contents
123 128
124 public: 129 public:
125 CodeHeap(); 130 CodeHeap();
126 131
127 // Heap extents 132 // Heap extents
128 bool reserve(size_t reserved_size, size_t committed_size, size_t segment_size); 133 bool reserve(size_t reserved_size, size_t committed_size, size_t segment_size);
129 void release(); // releases all allocated memory
130 bool expand_by(size_t size); // expands committed memory by size 134 bool expand_by(size_t size); // expands committed memory by size
131 void shrink_by(size_t size); // shrinks committed memory by size
132 void clear(); // clears all heap contents
133 135
134 // Memory allocation 136 // Memory allocation
135 void* allocate (size_t size, bool is_critical); // allocates a block of size or returns NULL 137 void* allocate (size_t size, bool is_critical); // allocates a block of size or returns NULL
136 void deallocate(void* p); // deallocates a block 138 void deallocate(void* p); // deallocates a block
137 139
138 // Attributes 140 // Attributes
139 char* low_boundary() const { return _memory.low_boundary (); } 141 char* low_boundary() const { return _memory.low_boundary (); }
140 char* high() const { return _memory.high(); } 142 char* high() const { return _memory.high(); }
141 char* high_boundary() const { return _memory.high_boundary(); } 143 char* high_boundary() const { return _memory.high_boundary(); }
142 144
143 bool contains(const void* p) const { return low_boundary() <= p && p < high(); } 145 bool contains(const void* p) const { return low_boundary() <= p && p < high(); }
144 void* find_start(void* p) const; // returns the block containing p or NULL 146 void* find_start(void* p) const; // returns the block containing p or NULL
145 size_t alignment_unit() const; // alignment of any block 147 size_t alignment_unit() const; // alignment of any block
146 size_t alignment_offset() const; // offset of first byte of any block, within the enclosing alignment unit 148 size_t alignment_offset() const; // offset of first byte of any block, within the enclosing alignment unit
147 static size_t header_size(); // returns the header size for each heap block 149 static size_t header_size(); // returns the header size for each heap block
148 150
149 // Iteration 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
150 153
151 // returns the first block or NULL 154 // returns the first block or NULL
152 void* first() const { return next_free(first_block()); } 155 void* first() const { return next_free(first_block()); }
153 // returns the next block given a block p or NULL 156 // returns the next block given a block p or NULL
154 void* next(void* p) const { return next_free(next_block(block_start(p))); } 157 void* next(void* p) const { return next_free(next_block(block_start(p))); }
155 158
156 // Statistics 159 // Statistics
157 size_t capacity() const; 160 size_t capacity() const;
158 size_t max_capacity() const; 161 size_t max_capacity() const;
162 int allocated_segments() const;
159 size_t allocated_capacity() const; 163 size_t allocated_capacity() const;
160 size_t unallocated_capacity() const { return max_capacity() - allocated_capacity(); } 164 size_t unallocated_capacity() const { return max_capacity() - allocated_capacity(); }
161 165
162 private: 166 private:
163 size_t heap_unallocated_capacity() const; 167 size_t heap_unallocated_capacity() const;
164 168
165 public: 169 public:
166 // Debugging 170 // Debugging
167 void verify(); 171 void verify() PRODUCT_RETURN;
168 void print() PRODUCT_RETURN; 172 void print() PRODUCT_RETURN;
169 }; 173 };
170 174
171 #endif // SHARE_VM_MEMORY_HEAP_HPP 175 #endif // SHARE_VM_MEMORY_HEAP_HPP