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