Fri, 11 Jul 2008 12:19:29 -0700
Merge
1 /*
2 * Copyright 1998-2008 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 */
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
35 class frame;
36 class RegisterMap;
37 class DerivedPointerEntry;
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;
47 public:
48 // Constants
49 enum { type_bits = 5,
50 register_bits = BitsPerShort - type_bits };
52 enum { type_shift = 0,
53 register_shift = type_bits };
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 };
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 narrowoop_value = 4,
65 callee_saved_value = 8,
66 derived_oop_value= 16 };
68 // Constructors
69 OopMapValue () { set_value(0); set_content_reg(VMRegImpl::Bad()); }
70 OopMapValue (VMReg reg, oop_types t) { set_reg_type(reg,t); }
71 OopMapValue (VMReg reg, oop_types t, VMReg reg2) { set_reg_type(reg,t); set_content_reg(reg2); }
72 OopMapValue (CompressedReadStream* stream) { read_from(stream); }
74 // Archiving
75 void write_on(CompressedWriteStream* stream) {
76 stream->write_int(value());
77 if(is_callee_saved() || is_derived_oop()) {
78 stream->write_int(content_reg()->value());
79 }
80 }
82 void read_from(CompressedReadStream* stream) {
83 set_value(stream->read_int());
84 if(is_callee_saved() || is_derived_oop()) {
85 set_content_reg(VMRegImpl::as_VMReg(stream->read_int(), true));
86 }
87 }
89 // Querying
90 bool is_oop() { return mask_bits(value(), type_mask_in_place) == oop_value; }
91 bool is_value() { return mask_bits(value(), type_mask_in_place) == value_value; }
92 bool is_narrowoop() { return mask_bits(value(), type_mask_in_place) == narrowoop_value; }
93 bool is_callee_saved() { return mask_bits(value(), type_mask_in_place) == callee_saved_value; }
94 bool is_derived_oop() { return mask_bits(value(), type_mask_in_place) == derived_oop_value; }
96 void set_oop() { set_value((value() & register_mask_in_place) | oop_value); }
97 void set_value() { set_value((value() & register_mask_in_place) | value_value); }
98 void set_narrowoop() { set_value((value() & register_mask_in_place) | narrowoop_value); }
99 void set_callee_saved() { set_value((value() & register_mask_in_place) | callee_saved_value); }
100 void set_derived_oop() { set_value((value() & register_mask_in_place) | derived_oop_value); }
102 VMReg reg() const { return VMRegImpl::as_VMReg(mask_bits(value(), register_mask_in_place) >> register_shift); }
103 oop_types type() const { return (oop_types)mask_bits(value(), type_mask_in_place); }
105 static bool legal_vm_reg_name(VMReg p) {
106 return (p->value() == (p->value() & register_mask));
107 }
109 void set_reg_type(VMReg p, oop_types t) {
110 set_value((p->value() << register_shift) | t);
111 assert(reg() == p, "sanity check" );
112 assert(type() == t, "sanity check" );
113 }
116 VMReg content_reg() const { return VMRegImpl::as_VMReg(_content_reg, true); }
117 void set_content_reg(VMReg r) { _content_reg = r->value(); }
119 // Physical location queries
120 bool is_register_loc() { return reg()->is_reg(); }
121 bool is_stack_loc() { return reg()->is_stack(); }
123 // Returns offset from sp.
124 int stack_offset() {
125 assert(is_stack_loc(), "must be stack location");
126 return reg()->reg2stack();
127 }
129 void print_on(outputStream* st) const;
130 void print() const { print_on(tty); }
131 };
134 class OopMap: public ResourceObj {
135 friend class OopMapStream;
136 friend class VMStructs;
137 private:
138 int _pc_offset;
139 int _omv_count;
140 int _omv_data_size;
141 unsigned char* _omv_data;
142 CompressedWriteStream* _write_stream;
144 debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)
146 // Accessors
147 unsigned char* omv_data() const { return _omv_data; }
148 void set_omv_data(unsigned char* value) { _omv_data = value; }
149 int omv_data_size() const { return _omv_data_size; }
150 void set_omv_data_size(int value) { _omv_data_size = value; }
151 int omv_count() const { return _omv_count; }
152 void set_omv_count(int value) { _omv_count = value; }
153 void increment_count() { _omv_count++; }
154 CompressedWriteStream* write_stream() const { return _write_stream; }
155 void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }
157 private:
158 enum DeepCopyToken { _deep_copy_token };
159 OopMap(DeepCopyToken, OopMap* source); // used only by deep_copy
161 public:
162 OopMap(int frame_size, int arg_count);
164 // pc-offset handling
165 int offset() const { return _pc_offset; }
166 void set_offset(int o) { _pc_offset = o; }
168 // Check to avoid double insertion
169 debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; })
171 // Construction
172 // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
173 // slots to hold 4-byte values like ints and floats in the LP64 build.
174 void set_oop ( VMReg local);
175 void set_value( VMReg local);
176 void set_narrowoop(VMReg local);
177 void set_dead ( VMReg local);
178 void set_callee_saved( VMReg local, VMReg caller_machine_register );
179 void set_derived_oop ( VMReg local, VMReg derived_from_local_register );
180 void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);
182 int heap_size() const;
183 void copy_to(address addr);
184 OopMap* deep_copy();
186 bool has_derived_pointer() const PRODUCT_RETURN0;
188 bool legal_vm_reg_name(VMReg local) {
189 return OopMapValue::legal_vm_reg_name(local);
190 }
192 // Printing
193 void print_on(outputStream* st) const;
194 void print() const { print_on(tty); }
195 };
198 class OopMapSet : public ResourceObj {
199 friend class VMStructs;
200 private:
201 int _om_count;
202 int _om_size;
203 OopMap** _om_data;
205 int om_count() const { return _om_count; }
206 void set_om_count(int value) { _om_count = value; }
207 void increment_count() { _om_count++; }
208 int om_size() const { return _om_size; }
209 void set_om_size(int value) { _om_size = value; }
210 OopMap** om_data() const { return _om_data; }
211 void set_om_data(OopMap** value) { _om_data = value; }
212 void grow_om_data();
213 void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; }
215 public:
216 OopMapSet();
218 // returns the number of OopMaps in this OopMapSet
219 int size() const { return _om_count; }
220 // returns the OopMap at a given index
221 OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; }
223 // Collect OopMaps.
224 void add_gc_map(int pc, OopMap* map);
226 // Returns the only oop map. Used for reconstructing
227 // Adapter frames during deoptimization
228 OopMap* singular_oop_map();
230 // returns OopMap in that is anchored to the pc
231 OopMap* find_map_at_offset(int pc_offset) const;
233 int heap_size() const;
234 void copy_to(address addr);
236 // Iterates through frame for a compiled method
237 static void oops_do (const frame* fr,
238 const RegisterMap* reg_map, OopClosure* f);
239 static void update_register_map(const frame* fr, RegisterMap *reg_map);
241 // Iterates through frame for a compiled method for dead ones and values, too
242 static void all_do(const frame* fr, const RegisterMap* reg_map,
243 OopClosure* oop_fn,
244 void derived_oop_fn(oop* base, oop* derived),
245 OopClosure* value_fn);
247 // Printing
248 void print_on(outputStream* st) const;
249 void print() const { print_on(tty); }
250 };
253 class OopMapStream : public StackObj {
254 private:
255 CompressedReadStream* _stream;
256 int _mask;
257 int _size;
258 int _position;
259 bool _valid_omv;
260 OopMapValue _omv;
261 void find_next();
263 public:
264 OopMapStream(OopMap* oop_map);
265 OopMapStream(OopMap* oop_map, int oop_types_mask);
266 bool is_done() { if(!_valid_omv) { find_next(); } return !_valid_omv; }
267 void next() { find_next(); }
268 OopMapValue current() { return _omv; }
269 };
272 // Derived pointer support. This table keeps track of all derived points on a
273 // stack. It is cleared before each scavenge/GC. During the traversal of all
274 // oops, it is filled in with references to all locations that contains a
275 // derived oop (assumed to be very few). When the GC is complete, the derived
276 // pointers are updated based on their base pointers new value and an offset.
277 #ifdef COMPILER2
278 class DerivedPointerTable : public AllStatic {
279 friend class VMStructs;
280 private:
281 static GrowableArray<DerivedPointerEntry*>* _list;
282 static bool _active; // do not record pointers for verify pass etc.
283 public:
284 static void clear(); // Called before scavenge/GC
285 static void add(oop *derived, oop *base); // Called during scavenge/GC
286 static void update_pointers(); // Called after scavenge/GC
287 static bool is_empty() { return _list == NULL || _list->is_empty(); }
288 static bool is_active() { return _active; }
289 static void set_active(bool value) { _active = value; }
290 };
292 // A utility class to temporarily "deactivate" the DerivedPointerTable.
293 // (Note: clients are responsible for any MT-safety issues)
294 class DerivedPointerTableDeactivate: public StackObj {
295 private:
296 bool _active;
297 public:
298 DerivedPointerTableDeactivate() {
299 _active = DerivedPointerTable::is_active();
300 if (_active) {
301 DerivedPointerTable::set_active(false);
302 }
303 }
305 ~DerivedPointerTableDeactivate() {
306 assert(!DerivedPointerTable::is_active(),
307 "Inconsistency: not MT-safe");
308 if (_active) {
309 DerivedPointerTable::set_active(true);
310 }
311 }
312 };
313 #endif // COMPILER2