|
1 /* |
|
2 * Copyright 1997-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 // oopDesc is the top baseclass for objects classes. The {name}Desc classes describe |
|
26 // the format of Java objects so the fields can be accessed from C++. |
|
27 // oopDesc is abstract. |
|
28 // (see oopHierarchy for complete oop class hierarchy) |
|
29 // |
|
30 // no virtual functions allowed |
|
31 |
|
32 // store into oop with store check |
|
33 void oop_store(oop* p, oop v); |
|
34 void oop_store(volatile oop* p, oop v); |
|
35 |
|
36 // store into oop without store check |
|
37 void oop_store_without_check(oop* p, oop v); |
|
38 void oop_store_without_check(volatile oop* p, oop v); |
|
39 |
|
40 |
|
41 extern bool always_do_update_barrier; |
|
42 |
|
43 // Forward declarations. |
|
44 class OopClosure; |
|
45 class ScanClosure; |
|
46 class FastScanClosure; |
|
47 class FilteringClosure; |
|
48 class BarrierSet; |
|
49 class CMSIsAliveClosure; |
|
50 |
|
51 class PSPromotionManager; |
|
52 class ParCompactionManager; |
|
53 |
|
54 class oopDesc { |
|
55 friend class VMStructs; |
|
56 private: |
|
57 volatile markOop _mark; |
|
58 klassOop _klass; |
|
59 |
|
60 // Fast access to barrier set. Must be initialized. |
|
61 static BarrierSet* _bs; |
|
62 |
|
63 public: |
|
64 markOop mark() const { return _mark; } |
|
65 markOop* mark_addr() const { return (markOop*) &_mark; } |
|
66 |
|
67 void set_mark(volatile markOop m) { _mark = m; } |
|
68 |
|
69 void release_set_mark(markOop m); |
|
70 markOop cas_set_mark(markOop new_mark, markOop old_mark); |
|
71 |
|
72 // Used only to re-initialize the mark word (e.g., of promoted |
|
73 // objects during a GC) -- requires a valid klass pointer |
|
74 void init_mark(); |
|
75 |
|
76 klassOop klass() const { return _klass; } |
|
77 oop* klass_addr() const { return (oop*) &_klass; } |
|
78 |
|
79 void set_klass(klassOop k); |
|
80 // For when the klass pointer is being used as a linked list "next" field. |
|
81 void set_klass_to_list_ptr(oop k); |
|
82 |
|
83 // size of object header |
|
84 static int header_size() { return sizeof(oopDesc)/HeapWordSize; } |
|
85 static int header_size_in_bytes() { return sizeof(oopDesc); } |
|
86 |
|
87 Klass* blueprint() const; |
|
88 |
|
89 // Returns whether this is an instance of k or an instance of a subclass of k |
|
90 bool is_a(klassOop k) const; |
|
91 |
|
92 // Returns the actual oop size of the object |
|
93 int size(); |
|
94 |
|
95 // Sometimes (for complicated concurrency-related reasons), it is useful |
|
96 // to be able to figure out the size of an object knowing its klass. |
|
97 int size_given_klass(Klass* klass); |
|
98 |
|
99 // Some perm gen objects are not parseble immediately after |
|
100 // installation of their klass pointer. |
|
101 bool is_parsable(); |
|
102 |
|
103 // type test operations (inlined in oop.inline.h) |
|
104 bool is_instance() const; |
|
105 bool is_instanceRef() const; |
|
106 bool is_array() const; |
|
107 bool is_objArray() const; |
|
108 bool is_symbol() const; |
|
109 bool is_klass() const; |
|
110 bool is_thread() const; |
|
111 bool is_method() const; |
|
112 bool is_constMethod() const; |
|
113 bool is_methodData() const; |
|
114 bool is_constantPool() const; |
|
115 bool is_constantPoolCache() const; |
|
116 bool is_typeArray() const; |
|
117 bool is_javaArray() const; |
|
118 bool is_compiledICHolder() const; |
|
119 |
|
120 private: |
|
121 // field addresses in oop |
|
122 // byte/char/bool/short fields are always stored as full words |
|
123 void* field_base(int offset) const; |
|
124 |
|
125 jbyte* byte_field_addr(int offset) const; |
|
126 jchar* char_field_addr(int offset) const; |
|
127 jboolean* bool_field_addr(int offset) const; |
|
128 jint* int_field_addr(int offset) const; |
|
129 jshort* short_field_addr(int offset) const; |
|
130 jlong* long_field_addr(int offset) const; |
|
131 jfloat* float_field_addr(int offset) const; |
|
132 jdouble* double_field_addr(int offset) const; |
|
133 |
|
134 public: |
|
135 // need this as public for garbage collection |
|
136 oop* obj_field_addr(int offset) const; |
|
137 |
|
138 oop obj_field(int offset) const; |
|
139 void obj_field_put(int offset, oop value); |
|
140 |
|
141 jbyte byte_field(int offset) const; |
|
142 void byte_field_put(int offset, jbyte contents); |
|
143 |
|
144 jchar char_field(int offset) const; |
|
145 void char_field_put(int offset, jchar contents); |
|
146 |
|
147 jboolean bool_field(int offset) const; |
|
148 void bool_field_put(int offset, jboolean contents); |
|
149 |
|
150 jint int_field(int offset) const; |
|
151 void int_field_put(int offset, jint contents); |
|
152 |
|
153 jshort short_field(int offset) const; |
|
154 void short_field_put(int offset, jshort contents); |
|
155 |
|
156 jlong long_field(int offset) const; |
|
157 void long_field_put(int offset, jlong contents); |
|
158 |
|
159 jfloat float_field(int offset) const; |
|
160 void float_field_put(int offset, jfloat contents); |
|
161 |
|
162 jdouble double_field(int offset) const; |
|
163 void double_field_put(int offset, jdouble contents); |
|
164 |
|
165 oop obj_field_acquire(int offset) const; |
|
166 void release_obj_field_put(int offset, oop value); |
|
167 |
|
168 jbyte byte_field_acquire(int offset) const; |
|
169 void release_byte_field_put(int offset, jbyte contents); |
|
170 |
|
171 jchar char_field_acquire(int offset) const; |
|
172 void release_char_field_put(int offset, jchar contents); |
|
173 |
|
174 jboolean bool_field_acquire(int offset) const; |
|
175 void release_bool_field_put(int offset, jboolean contents); |
|
176 |
|
177 jint int_field_acquire(int offset) const; |
|
178 void release_int_field_put(int offset, jint contents); |
|
179 |
|
180 jshort short_field_acquire(int offset) const; |
|
181 void release_short_field_put(int offset, jshort contents); |
|
182 |
|
183 jlong long_field_acquire(int offset) const; |
|
184 void release_long_field_put(int offset, jlong contents); |
|
185 |
|
186 jfloat float_field_acquire(int offset) const; |
|
187 void release_float_field_put(int offset, jfloat contents); |
|
188 |
|
189 jdouble double_field_acquire(int offset) const; |
|
190 void release_double_field_put(int offset, jdouble contents); |
|
191 |
|
192 // printing functions for VM debugging |
|
193 void print_on(outputStream* st) const; // First level print |
|
194 void print_value_on(outputStream* st) const; // Second level print. |
|
195 void print_address_on(outputStream* st) const; // Address printing |
|
196 |
|
197 // printing on default output stream |
|
198 void print(); |
|
199 void print_value(); |
|
200 void print_address(); |
|
201 |
|
202 // return the print strings |
|
203 char* print_string(); |
|
204 char* print_value_string(); |
|
205 |
|
206 // verification operations |
|
207 void verify_on(outputStream* st); |
|
208 void verify(); |
|
209 void verify_old_oop(oop* p, bool allow_dirty); |
|
210 |
|
211 // tells whether this oop is partially constructed (gc during class loading) |
|
212 bool partially_loaded(); |
|
213 void set_partially_loaded(); |
|
214 |
|
215 // locking operations |
|
216 bool is_locked() const; |
|
217 bool is_unlocked() const; |
|
218 bool has_bias_pattern() const; |
|
219 |
|
220 // asserts |
|
221 bool is_oop(bool ignore_mark_word = false) const; |
|
222 bool is_oop_or_null(bool ignore_mark_word = false) const; |
|
223 #ifndef PRODUCT |
|
224 bool is_unlocked_oop() const; |
|
225 #endif |
|
226 |
|
227 // garbage collection |
|
228 bool is_gc_marked() const; |
|
229 // Apply "MarkSweep::mark_and_push" to (the address of) every non-NULL |
|
230 // reference field in "this". |
|
231 void follow_contents(); |
|
232 void follow_header(); |
|
233 |
|
234 #ifndef SERIALGC |
|
235 // Parallel Scavenge |
|
236 void copy_contents(PSPromotionManager* pm); |
|
237 void push_contents(PSPromotionManager* pm); |
|
238 |
|
239 // Parallel Old |
|
240 void update_contents(ParCompactionManager* cm); |
|
241 void update_contents(ParCompactionManager* cm, |
|
242 HeapWord* begin_limit, |
|
243 HeapWord* end_limit); |
|
244 void update_contents(ParCompactionManager* cm, |
|
245 klassOop old_klass, |
|
246 HeapWord* begin_limit, |
|
247 HeapWord* end_limit); |
|
248 |
|
249 void follow_contents(ParCompactionManager* cm); |
|
250 void follow_header(ParCompactionManager* cm); |
|
251 #endif // SERIALGC |
|
252 |
|
253 bool is_perm() const; |
|
254 bool is_perm_or_null() const; |
|
255 bool is_shared() const; |
|
256 bool is_shared_readonly() const; |
|
257 bool is_shared_readwrite() const; |
|
258 |
|
259 // Forward pointer operations for scavenge |
|
260 bool is_forwarded() const; |
|
261 |
|
262 void forward_to(oop p); |
|
263 bool cas_forward_to(oop p, markOop compare); |
|
264 |
|
265 #ifndef SERIALGC |
|
266 // Like "forward_to", but inserts the forwarding pointer atomically. |
|
267 // Exactly one thread succeeds in inserting the forwarding pointer, and |
|
268 // this call returns "NULL" for that thread; any other thread has the |
|
269 // value of the forwarding pointer returned and does not modify "this". |
|
270 oop forward_to_atomic(oop p); |
|
271 #endif // SERIALGC |
|
272 |
|
273 oop forwardee() const; |
|
274 |
|
275 // Age of object during scavenge |
|
276 int age() const; |
|
277 void incr_age(); |
|
278 |
|
279 // Adjust all pointers in this object to point at it's forwarded location and |
|
280 // return the size of this oop. This is used by the MarkSweep collector. |
|
281 int adjust_pointers(); |
|
282 void adjust_header(); |
|
283 |
|
284 #ifndef SERIALGC |
|
285 // Parallel old |
|
286 void update_header(); |
|
287 void update_header(HeapWord* beg_addr, HeapWord* end_addr); |
|
288 #endif // SERIALGC |
|
289 |
|
290 // mark-sweep support |
|
291 void follow_body(int begin, int end); |
|
292 |
|
293 // Fast access to barrier set |
|
294 static BarrierSet* bs() { return _bs; } |
|
295 static void set_bs(BarrierSet* bs) { _bs = bs; } |
|
296 |
|
297 // iterators, returns size of object |
|
298 #define OOP_ITERATE_DECL(OopClosureType, nv_suffix) \ |
|
299 int oop_iterate(OopClosureType* blk); \ |
|
300 int oop_iterate(OopClosureType* blk, MemRegion mr); // Only in mr. |
|
301 |
|
302 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_DECL) |
|
303 ALL_OOP_OOP_ITERATE_CLOSURES_3(OOP_ITERATE_DECL) |
|
304 |
|
305 void oop_iterate_header(OopClosure* blk); |
|
306 void oop_iterate_header(OopClosure* blk, MemRegion mr); |
|
307 |
|
308 // identity hash; returns the identity hash key (computes it if necessary) |
|
309 // NOTE with the introduction of UseBiasedLocking that identity_hash() might reach a |
|
310 // safepoint if called on a biased object. Calling code must be aware of that. |
|
311 intptr_t identity_hash(); |
|
312 intptr_t slow_identity_hash(); |
|
313 |
|
314 // marks are forwarded to stack when object is locked |
|
315 bool has_displaced_mark() const; |
|
316 markOop displaced_mark() const; |
|
317 void set_displaced_mark(markOop m); |
|
318 |
|
319 // for code generation |
|
320 static int klass_offset_in_bytes() { return offset_of(oopDesc, _klass); } |
|
321 static int mark_offset_in_bytes() { return offset_of(oopDesc, _mark); } |
|
322 }; |