author | david |
Tue, 29 Sep 2015 11:02:08 +0200 | |
changeset 33105 | 294e48b4f704 |
parent 31620 | 53be635ad49c |
child 34158 | 1f8d643b02d5 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
30291
54cdc5c1a9cb
8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents:
28493
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#ifndef SHARE_VM_MEMORY_HEAP_HPP |
26 |
#define SHARE_VM_MEMORY_HEAP_HPP |
|
27 |
||
26796 | 28 |
#include "code/codeBlob.hpp" |
7397 | 29 |
#include "memory/allocation.hpp" |
30291
54cdc5c1a9cb
8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents:
28493
diff
changeset
|
30 |
#include "memory/virtualspace.hpp" |
31620
53be635ad49c
8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents:
30291
diff
changeset
|
31 |
#include "utilities/macros.hpp" |
7397 | 32 |
|
1 | 33 |
// Blocks |
34 |
||
35 |
class HeapBlock VALUE_OBJ_CLASS_SPEC { |
|
36 |
friend class VMStructs; |
|
37 |
||
38 |
public: |
|
39 |
struct Header { |
|
40 |
size_t _length; // the length in segments |
|
41 |
bool _used; // Used bit |
|
42 |
}; |
|
43 |
||
44 |
protected: |
|
45 |
union { |
|
46 |
Header _header; |
|
47 |
int64_t _padding[ (sizeof(Header) + sizeof(int64_t)-1) / sizeof(int64_t) ]; |
|
48 |
// pad to 0 mod 8 |
|
49 |
}; |
|
50 |
||
51 |
public: |
|
52 |
// Initialization |
|
53 |
void initialize(size_t length) { _header._length = length; set_used(); } |
|
54 |
||
55 |
// Accessors |
|
56 |
void* allocated_space() const { return (void*)(this + 1); } |
|
57 |
size_t length() const { return _header._length; } |
|
58 |
||
59 |
// Used/free |
|
60 |
void set_used() { _header._used = true; } |
|
61 |
void set_free() { _header._used = false; } |
|
62 |
bool free() { return !_header._used; } |
|
63 |
}; |
|
64 |
||
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 |
||
13195 | 82 |
class CodeHeap : public CHeapObj<mtCode> { |
1 | 83 |
friend class VMStructs; |
31620
53be635ad49c
8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents:
30291
diff
changeset
|
84 |
friend class PregeneratedCodeHeap; |
1 | 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; |
|
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
97 |
size_t _freelist_segments; // No. of segments in freelist |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
98 |
int _freelist_length; |
26796 | 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 |
bool _was_full; // True if the code heap was full |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
104 |
|
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
105 |
enum { free_sentinel = 0xFF }; |
1 | 106 |
|
107 |
// Helper functions |
|
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
108 |
size_t size_to_segments(size_t size) const { return (size + _segment_size - 1) >> _log2_segment_size; } |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
109 |
size_t segments_to_size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; } |
1 | 110 |
|
111 |
size_t segment_for(void* p) const { return ((char*)p - _memory.low()) >> _log2_segment_size; } |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
112 |
bool is_segment_unused(int val) const { return val == free_sentinel; } |
1 | 113 |
HeapBlock* block_at(size_t i) const { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); } |
114 |
||
115 |
void mark_segmap_as_free(size_t beg, size_t end); |
|
116 |
void mark_segmap_as_used(size_t beg, size_t end); |
|
117 |
||
118 |
// Freelist management helpers |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
119 |
FreeBlock* following_block(FreeBlock* b); |
1 | 120 |
void insert_after(FreeBlock* a, FreeBlock* b); |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
121 |
bool merge_right (FreeBlock* a); |
1 | 122 |
|
123 |
// Toplevel freelist management |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
124 |
void add_to_freelist(HeapBlock* b); |
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26942
diff
changeset
|
125 |
FreeBlock* search_freelist(size_t length); |
1 | 126 |
|
127 |
// Iteration helpers |
|
28493 | 128 |
void* next_used(HeapBlock* b) const; |
1 | 129 |
HeapBlock* first_block() const; |
130 |
HeapBlock* next_block(HeapBlock* b) const; |
|
131 |
HeapBlock* block_start(void* p) const; |
|
132 |
||
133 |
// to perform additional actions on creation of executable code |
|
134 |
void on_code_mapping(char* base, size_t size); |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
135 |
void clear(); // clears all heap contents |
1 | 136 |
|
137 |
public: |
|
26796 | 138 |
CodeHeap(const char* name, const int code_blob_type); |
1 | 139 |
|
140 |
// Heap extents |
|
26796 | 141 |
bool reserve(ReservedSpace rs, size_t committed_size, size_t segment_size); |
22551 | 142 |
bool expand_by(size_t size); // expands committed memory by size |
1 | 143 |
|
144 |
// Memory allocation |
|
27420
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26942
diff
changeset
|
145 |
void* allocate (size_t size); // Allocate 'size' bytes in the code cache or return NULL |
04e6f914cce1
8046809: vm/mlvm/meth/stress/compiler/deoptimize CodeCache is full.
anoll
parents:
26942
diff
changeset
|
146 |
void deallocate(void* p); // Deallocate memory |
1 | 147 |
|
148 |
// Attributes |
|
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
149 |
char* low_boundary() const { return _memory.low_boundary (); } |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
150 |
char* high() const { return _memory.high(); } |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
151 |
char* high_boundary() const { return _memory.high_boundary(); } |
1 | 152 |
|
31620
53be635ad49c
8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents:
30291
diff
changeset
|
153 |
virtual bool contains(const void* p) const { return low_boundary() <= p && p < high(); } |
53be635ad49c
8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents:
30291
diff
changeset
|
154 |
virtual void* find_start(void* p) const; // returns the block containing p or NULL |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
155 |
size_t alignment_unit() const; // alignment of any block |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
156 |
size_t alignment_offset() const; // offset of first byte of any block, within the enclosing alignment unit |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
157 |
static size_t header_size(); // returns the header size for each heap block |
1 | 158 |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
159 |
size_t allocated_in_freelist() const { return _freelist_segments * CodeCacheSegmentSize; } |
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
160 |
int freelist_length() const { return _freelist_length; } // number of elements in the freelist |
1 | 161 |
|
162 |
// returns the first block or NULL |
|
31620
53be635ad49c
8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents:
30291
diff
changeset
|
163 |
virtual void* first() const { return next_used(first_block()); } |
1 | 164 |
// returns the next block given a block p or NULL |
31620
53be635ad49c
8087333: Optionally Pre-Generate the HotSpot Template Interpreter
bdelsart
parents:
30291
diff
changeset
|
165 |
virtual void* next(void* p) const { return next_used(next_block(block_start(p))); } |
1 | 166 |
|
167 |
// Statistics |
|
168 |
size_t capacity() const; |
|
169 |
size_t max_capacity() const; |
|
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
170 |
int allocated_segments() const; |
1 | 171 |
size_t allocated_capacity() const; |
26796 | 172 |
size_t max_allocated_capacity() const { return _max_allocated_capacity; } |
1 | 173 |
size_t unallocated_capacity() const { return max_capacity() - allocated_capacity(); } |
174 |
||
26796 | 175 |
// Returns true if the CodeHeap contains CodeBlobs of the given type |
26942
fa5ea7ff078d
8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents:
26796
diff
changeset
|
176 |
bool accepts(int code_blob_type) const { return (_code_blob_type == CodeBlobType::All) || |
fa5ea7ff078d
8059390: code cache fills up for bigapps/Weblogic+medrec/nowarnings
zmajo
parents:
26796
diff
changeset
|
177 |
(_code_blob_type == code_blob_type); } |
26796 | 178 |
int code_blob_type() const { return _code_blob_type; } |
179 |
||
180 |
// Debugging / Profiling |
|
181 |
const char* name() const { return _name; } |
|
182 |
bool was_full() { return _was_full; } |
|
183 |
void report_full() { _was_full = true; } |
|
184 |
||
17016
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
185 |
private: |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
186 |
size_t heap_unallocated_capacity() const; |
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
187 |
|
78b1c3670525
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
13963
diff
changeset
|
188 |
public: |
1 | 189 |
// Debugging |
23214
b6426873cb37
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
22551
diff
changeset
|
190 |
void verify() PRODUCT_RETURN; |
1 | 191 |
void print() PRODUCT_RETURN; |
192 |
}; |
|
7397 | 193 |
|
194 |
#endif // SHARE_VM_MEMORY_HEAP_HPP |