Wed, 02 Jul 2008 12:55:16 -0700
6719955: Update copyright year
Summary: Update copyright year for files that have been modified in 2008
Reviewed-by: ohair, tbell
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 = 6,
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,
67 stack_obj = 32 };
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); }
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 }
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 }
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_narrowoop() { return mask_bits(value(), type_mask_in_place) == narrowoop_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; }
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_narrowoop() { set_value((value() & register_mask_in_place) | narrowoop_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); }
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); }
108 static bool legal_vm_reg_name(VMReg p) {
109 return (p->value() == (p->value() & register_mask));
110 }
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 }
119 VMReg content_reg() const { return VMRegImpl::as_VMReg(_content_reg, true); }
120 void set_content_reg(VMReg r) { _content_reg = r->value(); }
122 // Physical location queries
123 bool is_register_loc() { return reg()->is_reg(); }
124 bool is_stack_loc() { return reg()->is_stack(); }
126 // Returns offset from sp.
127 int stack_offset() {
128 assert(is_stack_loc(), "must be stack location");
129 return reg()->reg2stack();
130 }
132 void print_on(outputStream* st) const;
133 void print() const { print_on(tty); }
134 };
137 class OopMap: public ResourceObj {
138 friend class OopMapStream;
139 friend class VMStructs;
140 private:
141 int _pc_offset;
142 int _omv_count;
143 int _omv_data_size;
144 unsigned char* _omv_data;
145 CompressedWriteStream* _write_stream;
147 debug_only( OopMapValue::oop_types* _locs_used; int _locs_length;)
149 // Accessors
150 unsigned char* omv_data() const { return _omv_data; }
151 void set_omv_data(unsigned char* value) { _omv_data = value; }
152 int omv_data_size() const { return _omv_data_size; }
153 void set_omv_data_size(int value) { _omv_data_size = value; }
154 int omv_count() const { return _omv_count; }
155 void set_omv_count(int value) { _omv_count = value; }
156 void increment_count() { _omv_count++; }
157 CompressedWriteStream* write_stream() const { return _write_stream; }
158 void set_write_stream(CompressedWriteStream* value) { _write_stream = value; }
160 private:
161 enum DeepCopyToken { _deep_copy_token };
162 OopMap(DeepCopyToken, OopMap* source); // used only by deep_copy
164 public:
165 OopMap(int frame_size, int arg_count);
167 // pc-offset handling
168 int offset() const { return _pc_offset; }
169 void set_offset(int o) { _pc_offset = o; }
171 // Check to avoid double insertion
172 debug_only(OopMapValue::oop_types locs_used( int indx ) { return _locs_used[indx]; })
174 // Construction
175 // frame_size units are stack-slots (4 bytes) NOT intptr_t; we can name odd
176 // slots to hold 4-byte values like ints and floats in the LP64 build.
177 void set_oop ( VMReg local);
178 void set_value( VMReg local);
179 void set_narrowoop(VMReg local);
180 void set_dead ( VMReg local);
181 void set_callee_saved( VMReg local, VMReg caller_machine_register );
182 void set_derived_oop ( VMReg local, VMReg derived_from_local_register );
183 void set_stack_obj( VMReg local);
184 void set_xxx(VMReg reg, OopMapValue::oop_types x, VMReg optional);
186 int heap_size() const;
187 void copy_to(address addr);
188 OopMap* deep_copy();
190 bool has_derived_pointer() const PRODUCT_RETURN0;
192 bool legal_vm_reg_name(VMReg local) {
193 return OopMapValue::legal_vm_reg_name(local);
194 }
196 // Printing
197 void print_on(outputStream* st) const;
198 void print() const { print_on(tty); }
199 };
202 class OopMapSet : public ResourceObj {
203 friend class VMStructs;
204 private:
205 int _om_count;
206 int _om_size;
207 OopMap** _om_data;
209 int om_count() const { return _om_count; }
210 void set_om_count(int value) { _om_count = value; }
211 void increment_count() { _om_count++; }
212 int om_size() const { return _om_size; }
213 void set_om_size(int value) { _om_size = value; }
214 OopMap** om_data() const { return _om_data; }
215 void set_om_data(OopMap** value) { _om_data = value; }
216 void grow_om_data();
217 void set(int index,OopMap* value) { assert((index == 0) || ((index > 0) && (index < om_size())),"bad index"); _om_data[index] = value; }
219 public:
220 OopMapSet();
222 // returns the number of OopMaps in this OopMapSet
223 int size() const { return _om_count; }
224 // returns the OopMap at a given index
225 OopMap* at(int index) const { assert((index >= 0) && (index <= om_count()),"bad index"); return _om_data[index]; }
227 // Collect OopMaps.
228 void add_gc_map(int pc, OopMap* map);
230 // Returns the only oop map. Used for reconstructing
231 // Adapter frames during deoptimization
232 OopMap* singular_oop_map();
234 // returns OopMap in that is anchored to the pc
235 OopMap* find_map_at_offset(int pc_offset) const;
237 int heap_size() const;
238 void copy_to(address addr);
240 // Iterates through frame for a compiled method
241 static void oops_do (const frame* fr,
242 const RegisterMap* reg_map, OopClosure* f);
243 static void update_register_map(const frame* fr, RegisterMap *reg_map);
245 // Iterates through frame for a compiled method for dead ones and values, too
246 static void all_do(const frame* fr, const RegisterMap* reg_map,
247 OopClosure* oop_fn,
248 void derived_oop_fn(oop* base, oop* derived),
249 OopClosure* value_fn);
251 // Printing
252 void print_on(outputStream* st) const;
253 void print() const { print_on(tty); }
254 };
257 class OopMapStream : public StackObj {
258 private:
259 CompressedReadStream* _stream;
260 int _mask;
261 int _size;
262 int _position;
263 bool _valid_omv;
264 OopMapValue _omv;
265 void find_next();
267 public:
268 OopMapStream(OopMap* oop_map);
269 OopMapStream(OopMap* oop_map, int oop_types_mask);
270 bool is_done() { if(!_valid_omv) { find_next(); } return !_valid_omv; }
271 void next() { find_next(); }
272 OopMapValue current() { return _omv; }
273 };
276 // Derived pointer support. This table keeps track of all derived points on a
277 // stack. It is cleared before each scavenge/GC. During the traversal of all
278 // oops, it is filled in with references to all locations that contains a
279 // derived oop (assumed to be very few). When the GC is complete, the derived
280 // pointers are updated based on their base pointers new value and an offset.
281 #ifdef COMPILER2
282 class DerivedPointerTable : public AllStatic {
283 friend class VMStructs;
284 private:
285 static GrowableArray<DerivedPointerEntry*>* _list;
286 static bool _active; // do not record pointers for verify pass etc.
287 public:
288 static void clear(); // Called before scavenge/GC
289 static void add(oop *derived, oop *base); // Called during scavenge/GC
290 static void update_pointers(); // Called after scavenge/GC
291 static bool is_empty() { return _list == NULL || _list->is_empty(); }
292 static bool is_active() { return _active; }
293 static void set_active(bool value) { _active = value; }
294 };
296 // A utility class to temporarily "deactivate" the DerivedPointerTable.
297 // (Note: clients are responsible for any MT-safety issues)
298 class DerivedPointerTableDeactivate: public StackObj {
299 private:
300 bool _active;
301 public:
302 DerivedPointerTableDeactivate() {
303 _active = DerivedPointerTable::is_active();
304 if (_active) {
305 DerivedPointerTable::set_active(false);
306 }
307 }
309 ~DerivedPointerTableDeactivate() {
310 assert(!DerivedPointerTable::is_active(),
311 "Inconsistency: not MT-safe");
312 if (_active) {
313 DerivedPointerTable::set_active(true);
314 }
315 }
316 };
317 #endif // COMPILER2