Mercurial > hg > truffle
annotate src/share/vm/compiler/oopMap.hpp @ 21244:bf5e055dbc9c
SSAUtils: minor refactoring.
author | Josef Eisl <josef.eisl@jku.at> |
---|---|
date | Thu, 30 Apr 2015 15:36:03 +0200 |
parents | 82ff6c8c8f6e |
children |
rev | line source |
---|---|
0 | 1 /* |
1972 | 2 * Copyright (c) 1998, 2010, 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:
948
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
948
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:
948
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #ifndef SHARE_VM_COMPILER_OOPMAP_HPP |
26 #define SHARE_VM_COMPILER_OOPMAP_HPP | |
27 | |
28 #include "code/compressedStream.hpp" | |
29 #include "code/vmreg.hpp" | |
30 #include "memory/allocation.hpp" | |
31 #include "utilities/growableArray.hpp" | |
32 | |
0 | 33 // Interface for generating the frame map for compiled code. A frame map |
34 // describes for a specific pc whether each register and frame stack slot is: | |
35 // Oop - A GC root for current frame | |
36 // Value - Live non-oop, non-float value: int, either half of double | |
37 // Dead - Dead; can be Zapped for debugging | |
38 // CalleeXX - Callee saved; also describes which caller register is saved | |
39 // DerivedXX - A derived oop; original oop is described. | |
40 // | |
41 // OopMapValue describes a single OopMap entry | |
42 | |
43 class frame; | |
44 class RegisterMap; | |
45 class DerivedPointerEntry; | |
46 | |
47 class OopMapValue: public StackObj { | |
48 friend class VMStructs; | |
49 private: | |
8151
b8f261ba79c6
Minimize diff to plain HotSpot version.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2044
diff
changeset
|
50 short _value; |
0 | 51 int value() const { return _value; } |
52 void set_value(int value) { _value = value; } | |
53 short _content_reg; | |
54 | |
55 public: | |
56 // Constants | |
14988
82ff6c8c8f6e
Increase maximum allocatable spill area by factor of 2.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
57 enum { type_bits = 4, |
8151
b8f261ba79c6
Minimize diff to plain HotSpot version.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
2044
diff
changeset
|
58 register_bits = BitsPerShort - type_bits }; |
0 | 59 |
60 enum { type_shift = 0, | |
61 register_shift = type_bits }; | |
62 | |
63 enum { type_mask = right_n_bits(type_bits), | |
64 type_mask_in_place = type_mask << type_shift, | |
65 register_mask = right_n_bits(register_bits), | |
66 register_mask_in_place = register_mask << register_shift }; | |
67 | |
68 enum oop_types { // must fit in type_bits | |
69 unused_value =0, // powers of 2, for masking OopMapStream | |
70 oop_value = 1, | |
14988
82ff6c8c8f6e
Increase maximum allocatable spill area by factor of 2.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
71 narrowoop_value = 2, |
82ff6c8c8f6e
Increase maximum allocatable spill area by factor of 2.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
72 callee_saved_value = 4, |
82ff6c8c8f6e
Increase maximum allocatable spill area by factor of 2.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
8151
diff
changeset
|
73 derived_oop_value= 8 }; |
0 | 74 |
75 // Constructors | |
76 OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); } | |
77 OopMapValue (VMReg reg, oop_types t) { set_reg_type(reg,t); } | |
78 OopMapValue (VMReg reg, oop_types t, VMReg reg2) { set_reg_type(reg,t); set_content_reg(reg2); } | |
79 OopMapValue (CompressedReadStream* stream) { read_from(stream); } | |
80 | |
81 // Archiving | |
82 void write_on(CompressedWriteStream* stream) { | |
83 stream->write_int(value()); | |
84 if(is_callee_saved() || is_derived_oop()) { | |
85 stream->write_int(content_reg()->value()); | |
86 } | |
87 } | |
88 | |
89 void read_from(CompressedReadStream* stream) { | |
90 set_value(stream->read_int()); | |
91 if(is_callee_saved() || is_derived_oop()) { | |
92 set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true)); | |
93 } | |
94 } | |
95 | |
96 // Querying | |
97 bool is_oop() { return mask_bits(value(), type_mask_in_place) == oop_value; } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
98 bool is_narrowoop() { return mask_bits(value(), type_mask_in_place) == narrowoop_value; } |
0 | 99 bool is_callee_saved() { return mask_bits(value(), type_mask_in_place) == callee_saved_value; } |
100 bool is_derived_oop() { return mask_bits(value(), type_mask_in_place) == derived_oop_value; } | |
101 | |
102 void set_oop() { set_value((value() & register_mask_in_place) | oop_value); } | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
103 void set_narrowoop() { set_value((value() & register_mask_in_place) | narrowoop_value); } |
0 | 104 void set_callee_saved() { set_value((value() & register_mask_in_place) | callee_saved_value); } |
105 void set_derived_oop() { set_value((value() & register_mask_in_place) | derived_oop_value); } | |
106 | |
107 VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); } | |
108 oop_types type() const { return (oop_types)mask_bits(value(), type_mask_in_place); } | |
109 | |
110 static bool legal_vm_reg_name(VMReg p) { | |
111 return (p->value() == (p->value() & register_mask)); | |
112 } | |
113 | |
114 void set_reg_type(VMReg p, oop_types t) { | |
115 set_value((p->value() << register_shift) | t); | |
116 assert(reg() == p, "sanity check" ); | |
117 assert(type() == t, "sanity check" ); | |
118 } | |
119 | |
120 | |
121 VMReg content_reg() const { return VMRegImpl::as_VMReg(_content_reg, true); } | |
122 void set_content_reg(VMReg r) { _content_reg = r->value(); } | |
123 | |
124 // Physical location queries | |
125 bool is_register_loc() { return reg()->is_reg(); } | |
126 bool is_stack_loc() { return reg()->is_stack(); } | |
127 | |
128 // Returns offset from sp. | |
129 int stack_offset() { | |
130 assert(is_stack_loc(), "must be stack location"); | |
131 return reg()->reg2stack(); | |
132 } | |
133 | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
25
diff
changeset
|
134 void print_on(outputStream* st) const; |
25
c5cbd367e4d1
6621094: PrintOptoAssembly is broken for oops information in DebugInfo
kvn
parents:
0
diff
changeset
|
135 void print() const { print_on(tty); } |
0 | 136 }; |
137 | |
138 | |
139 class OopMap: public ResourceObj { | |
140 friend class OopMapStream; | |
141 friend class VMStructs; | |
142 private: | |
143 int _pc_offset; | |
144 int _omv_count; | |
145 int _omv_data_size; | |
146 unsigned char* _omv_data; | |
147 CompressedWriteStream* _write_stream; | |
148 | |
149 debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;) | |
150 | |
151 // Accessors | |
152 unsigned char* omv_data() const { return _omv_data; } | |
153 void set_omv_data(unsigned char* value) { _omv_data = value; } | |
154 int omv_data_size() const { return _omv_data_size; } | |
155 void set_omv_data_size(int value) { _omv_data_size = value; } | |
156 int omv_count() const { return _omv_count; } | |
157 void set_omv_count(int value) { _omv_count = value; } | |
158 void increment_count() { _omv_count++; } | |
159 CompressedWriteStream* write_stream() const { return _write_stream; } | |
160 void set_write_stream(CompressedWriteStream* value) { _write_stream = value; } | |
161 | |
162 private: | |
163 enum DeepCopyToken { _deep_copy_token }; | |
164 OopMap(DeepCopyToken, OopMap* source); // used only by deep_copy | |
165 | |
166 public: | |
167 OopMap(int frame_size, int arg_count); | |
168 | |
169 // pc-offset handling | |
170 int offset() const { return _pc_offset; } | |
171 void set_offset(int o) { _pc_offset = o; } | |
172 | |
173 // Check to avoid double insertion | |
174 debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; }) | |
175 | |
176 // Construction | |
177 // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd | |
178 // slots to hold 4-byte values like ints and floats in the LP64 build. | |
179 void set_oop ( VMReg local); | |
180 void set_value( VMReg local); | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
181 void set_narrowoop(VMReg local); |
0 | 182 void set_dead ( VMReg local); |
183 void set_callee_saved( VMReg local, VMReg caller_machine_register ); | |
184 void set_derived_oop ( VMReg local, VMReg derived_from_local_register ); | |
185 void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional); | |
186 | |
187 int heap_size() const; | |
188 void copy_to(address addr); | |
189 OopMap* deep_copy(); | |
190 | |
191 bool has_derived_pointer() const PRODUCT_RETURN0; | |
192 | |
193 bool legal_vm_reg_name(VMReg local) { | |
194 return OopMapValue::legal_vm_reg_name(local); | |
195 } | |
196 | |
197 // Printing | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
25
diff
changeset
|
198 void print_on(outputStream* st) const; |
0 | 199 void print() const { print_on(tty); } |
200 }; | |
201 | |
202 | |
203 class OopMapSet : public ResourceObj { | |
204 friend class VMStructs; | |
205 private: | |
206 int _om_count; | |
207 int _om_size; | |
208 OopMap** _om_data; | |
209 | |
210 int om_count() const { return _om_count; } | |
211 void set_om_count(int value) { _om_count = value; } | |
212 void increment_count() { _om_count++; } | |
213 int om_size() const { return _om_size; } | |
214 void set_om_size(int value) { _om_size = value; } | |
215 OopMap** om_data() const { return _om_data; } | |
216 void set_om_data(OopMap** value) { _om_data = value; } | |
217 void grow_om_data(); | |
218 void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; } | |
219 | |
220 public: | |
221 OopMapSet(); | |
222 | |
223 // returns the number of OopMaps in this OopMapSet | |
224 int size() const { return _om_count; } | |
225 // returns the OopMap at a given index | |
226 OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; } | |
227 | |
228 // Collect OopMaps. | |
229 void add_gc_map(int pc, OopMap* map); | |
230 | |
231 // Returns the only oop map. Used for reconstructing | |
232 // Adapter frames during deoptimization | |
233 OopMap* singular_oop_map(); | |
234 | |
235 // returns OopMap in that is anchored to the pc | |
236 OopMap* find_map_at_offset(int pc_offset) const; | |
237 | |
238 int heap_size() const; | |
239 void copy_to(address addr); | |
240 | |
858 | 241 // Methods oops_do() and all_do() filter out NULL oops and |
242 // oop == Universe::narrow_oop_base() before passing oops | |
243 // to closures. | |
244 | |
0 | 245 // Iterates through frame for a compiled method |
246 static void oops_do (const frame* fr, | |
247 const RegisterMap* reg_map, OopClosure* f); | |
248 static void update_register_map(const frame* fr, RegisterMap *reg_map); | |
249 | |
250 // Iterates through frame for a compiled method for dead ones and values, too | |
251 static void all_do(const frame* fr, const RegisterMap* reg_map, | |
252 OopClosure* oop_fn, | |
253 void derived_oop_fn(oop* base, oop* derived), | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
100
diff
changeset
|
254 OopClosure* value_fn); |
0 | 255 |
256 // Printing | |
100
c7c777385a15
6667042: PrintAssembly option does not work without special plugin
jrose
parents:
25
diff
changeset
|
257 void print_on(outputStream* st) const; |
0 | 258 void print() const { print_on(tty); } |
259 }; | |
260 | |
261 | |
262 class OopMapStream : public StackObj { | |
263 private: | |
264 CompressedReadStream* _stream; | |
265 int _mask; | |
266 int _size; | |
267 int _position; | |
268 bool _valid_omv; | |
269 OopMapValue _omv; | |
270 void find_next(); | |
271 | |
272 public: | |
273 OopMapStream(OopMap* oop_map); | |
274 OopMapStream(OopMap* oop_map, int oop_types_mask); | |
275 bool is_done() { if(!_valid_omv) { find_next(); } return !_valid_omv; } | |
276 void next() { find_next(); } | |
277 OopMapValue current() { return _omv; } | |
278 }; | |
279 | |
280 | |
281 // Derived pointer support. This table keeps track of all derived points on a | |
282 // stack. It is cleared before each scavenge/GC. During the traversal of all | |
283 // oops, it is filled in with references to all locations that contains a | |
284 // derived oop (assumed to be very few). When the GC is complete, the derived | |
285 // pointers are updated based on their base pointers new value and an offset. | |
286 #ifdef COMPILER2 | |
287 class DerivedPointerTable : public AllStatic { | |
288 friend class VMStructs; | |
289 private: | |
290 static GrowableArray<DerivedPointerEntry*>* _list; | |
291 static bool _active; // do not record pointers for verify pass etc. | |
292 public: | |
293 static void clear(); // Called before scavenge/GC | |
294 static void add(oop *derived, oop *base); // Called during scavenge/GC | |
295 static void update_pointers(); // Called after scavenge/GC | |
296 static bool is_empty() { return _list == NULL || _list->is_empty(); } | |
297 static bool is_active() { return _active; } | |
298 static void set_active(bool value) { _active = value; } | |
299 }; | |
300 | |
301 // A utility class to temporarily "deactivate" the DerivedPointerTable. | |
302 // (Note: clients are responsible for any MT-safety issues) | |
303 class DerivedPointerTableDeactivate: public StackObj { | |
304 private: | |
305 bool _active; | |
306 public: | |
307 DerivedPointerTableDeactivate() { | |
308 _active = DerivedPointerTable::is_active(); | |
309 if (_active) { | |
310 DerivedPointerTable::set_active(false); | |
311 } | |
312 } | |
313 | |
314 ~DerivedPointerTableDeactivate() { | |
315 assert(!DerivedPointerTable::is_active(), | |
316 "Inconsistency: not MT-safe"); | |
317 if (_active) { | |
318 DerivedPointerTable::set_active(true); | |
319 } | |
320 } | |
321 }; | |
322 #endif // COMPILER2 | |
1972 | 323 |
324 #endif // SHARE_VM_COMPILER_OOPMAP_HPP |