Mercurial > hg > truffle
annotate src/share/vm/memory/heap.hpp @ 14725:ba7b08d90fde
new ProfileCompiledMethods tool
author | Lukas Stadler <lukas.stadler@oracle.com> |
---|---|
date | Mon, 24 Mar 2014 14:02:58 +0100 |
parents | 480b0109db65 |
children | 92aa6797d639 |
rev | line source |
---|---|
0 | 1 /* |
14223
de6a9e811145
8029233: Update copyright year to match last edit in jdk8 hotspot repository for 2013
mikael
parents:
10114
diff
changeset
|
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_MEMORY_HEAP_HPP |
26 #define SHARE_VM_MEMORY_HEAP_HPP | |
27 | |
28 #include "memory/allocation.hpp" | |
29 #include "runtime/virtualspace.hpp" | |
30 | |
0 | 31 // Blocks |
32 | |
33 class HeapBlock VALUE_OBJ_CLASS_SPEC { | |
34 friend class VMStructs; | |
35 | |
36 public: | |
37 struct Header { | |
38 size_t _length; // the length in segments | |
39 bool _used; // Used bit | |
40 }; | |
41 | |
42 protected: | |
43 union { | |
44 Header _header; | |
45 int64_t _padding[ (sizeof(Header) + sizeof(int64_t)-1) / sizeof(int64_t) ]; | |
46 // pad to 0 mod 8 | |
47 }; | |
48 | |
49 public: | |
50 // Initialization | |
51 void initialize(size_t length) { _header._length = length; set_used(); } | |
52 | |
53 // Accessors | |
54 void* allocated_space() const { return (void*)(this + 1); } | |
55 size_t length() const { return _header._length; } | |
56 | |
57 // Used/free | |
58 void set_used() { _header._used = true; } | |
59 void set_free() { _header._used = false; } | |
60 bool free() { return !_header._used; } | |
61 }; | |
62 | |
63 class FreeBlock: public HeapBlock { | |
64 friend class VMStructs; | |
65 protected: | |
66 FreeBlock* _link; | |
67 | |
68 public: | |
69 // Initialization | |
70 void initialize(size_t length) { HeapBlock::initialize(length); _link= NULL; } | |
71 | |
72 // Merging | |
73 void set_length(size_t l) { _header._length = l; } | |
74 | |
75 // Accessors | |
76 FreeBlock* link() const { return _link; } | |
77 void set_link(FreeBlock* link) { _link = link; } | |
78 }; | |
79 | |
6197 | 80 class CodeHeap : public CHeapObj<mtCode> { |
0 | 81 friend class VMStructs; |
82 private: | |
83 VirtualSpace _memory; // the memory holding the blocks | |
84 VirtualSpace _segmap; // the memory holding the segment map | |
85 | |
86 size_t _number_of_committed_segments; | |
87 size_t _number_of_reserved_segments; | |
88 size_t _segment_size; | |
89 int _log2_segment_size; | |
90 | |
91 size_t _next_segment; | |
92 | |
93 FreeBlock* _freelist; | |
10114
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
94 size_t _freelist_segments; // No. of segments in freelist |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
95 int _freelist_length; |
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
96 |
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
97 enum { free_sentinel = 0xFF }; |
0 | 98 |
99 // Helper functions | |
10114
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
100 size_t size_to_segments(size_t size) const { return (size + _segment_size - 1) >> _log2_segment_size; } |
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
101 size_t segments_to_size(size_t number_of_segments) const { return number_of_segments << _log2_segment_size; } |
0 | 102 |
103 size_t segment_for(void* p) const { return ((char*)p - _memory.low()) >> _log2_segment_size; } | |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
104 bool is_segment_unused(int val) const { return val == free_sentinel; } |
0 | 105 HeapBlock* block_at(size_t i) const { return (HeapBlock*)(_memory.low() + (i << _log2_segment_size)); } |
106 | |
107 void mark_segmap_as_free(size_t beg, size_t end); | |
108 void mark_segmap_as_used(size_t beg, size_t end); | |
109 | |
110 // Freelist management helpers | |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
111 FreeBlock* following_block(FreeBlock* b); |
0 | 112 void insert_after(FreeBlock* a, FreeBlock* b); |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
113 bool merge_right (FreeBlock* a); |
0 | 114 |
115 // Toplevel freelist management | |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
116 void add_to_freelist(HeapBlock* b); |
10114
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
117 FreeBlock* search_freelist(size_t length, bool is_critical); |
0 | 118 |
119 // Iteration helpers | |
120 void* next_free(HeapBlock* b) const; | |
121 HeapBlock* first_block() const; | |
122 HeapBlock* next_block(HeapBlock* b) const; | |
123 HeapBlock* block_start(void* p) const; | |
124 | |
125 // to perform additional actions on creation of executable code | |
126 void on_code_mapping(char* base, size_t size); | |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
127 void clear(); // clears all heap contents |
0 | 128 |
129 public: | |
130 CodeHeap(); | |
131 | |
132 // Heap extents | |
133 bool reserve(size_t reserved_size, size_t committed_size, size_t segment_size); | |
14309 | 134 bool expand_by(size_t size); // expands committed memory by size |
0 | 135 |
136 // Memory allocation | |
10114
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
137 void* allocate (size_t size, bool is_critical); // allocates a block of size or returns NULL |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
138 void deallocate(void* p); // deallocates a block |
0 | 139 |
140 // Attributes | |
10114
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
141 char* low_boundary() const { return _memory.low_boundary (); } |
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
142 char* high() const { return _memory.high(); } |
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
143 char* high_boundary() const { return _memory.high_boundary(); } |
0 | 144 |
10114
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
145 bool contains(const void* p) const { return low_boundary() <= p && p < high(); } |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
146 void* find_start(void* p) const; // returns the block containing p or NULL |
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
147 size_t alignment_unit() const; // alignment of any block |
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
148 size_t alignment_offset() const; // offset of first byte of any block, within the enclosing alignment unit |
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
149 static size_t header_size(); // returns the header size for each heap block |
0 | 150 |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
151 size_t allocated_in_freelist() const { return _freelist_segments * CodeCacheSegmentSize; } |
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
152 int freelist_length() const { return _freelist_length; } // number of elements in the freelist |
0 | 153 |
154 // returns the first block or NULL | |
155 void* first() const { return next_free(first_block()); } | |
156 // returns the next block given a block p or NULL | |
157 void* next(void* p) const { return next_free(next_block(block_start(p))); } | |
158 | |
159 // Statistics | |
160 size_t capacity() const; | |
161 size_t max_capacity() const; | |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
162 int allocated_segments() const; |
0 | 163 size_t allocated_capacity() const; |
164 size_t unallocated_capacity() const { return max_capacity() - allocated_capacity(); } | |
165 | |
10114
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
166 private: |
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
167 size_t heap_unallocated_capacity() const; |
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
168 |
a7fb14888912
8006952: Slow VM due to excessive code cache freelist iteration
neliasso
parents:
6842
diff
changeset
|
169 public: |
0 | 170 // Debugging |
14687
480b0109db65
8029799: vm/mlvm/anonloader/stress/oome prints warning: CodeHeap: # of free blocks > 10000
anoll
parents:
14309
diff
changeset
|
171 void verify() PRODUCT_RETURN; |
0 | 172 void print() PRODUCT_RETURN; |
173 }; | |
1972 | 174 |
175 #endif // SHARE_VM_MEMORY_HEAP_HPP |