comparison src/share/vm/oops/oop.inline.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children ba764ed4b6f2
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
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 // Implementation of all inlined member functions defined in oop.hpp
26 // We need a separate file to avoid circular references
27
28
29 inline void oopDesc::release_set_mark(markOop m) {
30 OrderAccess::release_store_ptr(&_mark, m);
31 }
32
33 inline markOop oopDesc::cas_set_mark(markOop new_mark, markOop old_mark) {
34 return (markOop) Atomic::cmpxchg_ptr(new_mark, &_mark, old_mark);
35 }
36
37 inline void oopDesc::set_klass(klassOop k) {
38 // since klasses are promoted no store check is needed
39 assert(Universe::is_bootstrapping() || k != NULL, "must be a real klassOop");
40 assert(Universe::is_bootstrapping() || k->is_klass(), "not a klassOop");
41 oop_store_without_check((oop*) &_klass, (oop) k);
42 }
43
44 inline void oopDesc::set_klass_to_list_ptr(oop k) {
45 // This is only to be used during GC, for from-space objects, so no
46 // barrier is needed.
47 _klass = (klassOop)k;
48 }
49
50 inline void oopDesc::init_mark() { set_mark(markOopDesc::prototype_for_object(this)); }
51 inline Klass* oopDesc::blueprint() const { return klass()->klass_part(); }
52
53 inline bool oopDesc::is_a(klassOop k) const { return blueprint()->is_subtype_of(k); }
54
55 inline bool oopDesc::is_instance() const { return blueprint()->oop_is_instance(); }
56 inline bool oopDesc::is_instanceRef() const { return blueprint()->oop_is_instanceRef(); }
57 inline bool oopDesc::is_array() const { return blueprint()->oop_is_array(); }
58 inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_objArray(); }
59 inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
60 inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
61 inline bool oopDesc::is_symbol() const { return blueprint()->oop_is_symbol(); }
62 inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
63 inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
64 inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
65 inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
66 inline bool oopDesc::is_methodData() const { return blueprint()->oop_is_methodData(); }
67 inline bool oopDesc::is_constantPool() const { return blueprint()->oop_is_constantPool(); }
68 inline bool oopDesc::is_constantPoolCache() const { return blueprint()->oop_is_constantPoolCache(); }
69 inline bool oopDesc::is_compiledICHolder() const { return blueprint()->oop_is_compiledICHolder(); }
70
71 inline void* oopDesc::field_base(int offset) const { return (void*)&((char*)this)[offset]; }
72
73 inline oop* oopDesc::obj_field_addr(int offset) const { return (oop*) field_base(offset); }
74 inline jbyte* oopDesc::byte_field_addr(int offset) const { return (jbyte*) field_base(offset); }
75 inline jchar* oopDesc::char_field_addr(int offset) const { return (jchar*) field_base(offset); }
76 inline jboolean* oopDesc::bool_field_addr(int offset) const { return (jboolean*)field_base(offset); }
77 inline jint* oopDesc::int_field_addr(int offset) const { return (jint*) field_base(offset); }
78 inline jshort* oopDesc::short_field_addr(int offset) const { return (jshort*) field_base(offset); }
79 inline jlong* oopDesc::long_field_addr(int offset) const { return (jlong*) field_base(offset); }
80 inline jfloat* oopDesc::float_field_addr(int offset) const { return (jfloat*) field_base(offset); }
81 inline jdouble* oopDesc::double_field_addr(int offset) const { return (jdouble*) field_base(offset); }
82
83 inline oop oopDesc::obj_field(int offset) const { return *obj_field_addr(offset); }
84 inline void oopDesc::obj_field_put(int offset, oop value) { oop_store(obj_field_addr(offset), value); }
85
86 inline jbyte oopDesc::byte_field(int offset) const { return (jbyte) *byte_field_addr(offset); }
87 inline void oopDesc::byte_field_put(int offset, jbyte contents) { *byte_field_addr(offset) = (jint) contents; }
88
89 inline jboolean oopDesc::bool_field(int offset) const { return (jboolean) *bool_field_addr(offset); }
90 inline void oopDesc::bool_field_put(int offset, jboolean contents) { *bool_field_addr(offset) = (jint) contents; }
91
92 inline jchar oopDesc::char_field(int offset) const { return (jchar) *char_field_addr(offset); }
93 inline void oopDesc::char_field_put(int offset, jchar contents) { *char_field_addr(offset) = (jint) contents; }
94
95 inline jint oopDesc::int_field(int offset) const { return *int_field_addr(offset); }
96 inline void oopDesc::int_field_put(int offset, jint contents) { *int_field_addr(offset) = contents; }
97
98 inline jshort oopDesc::short_field(int offset) const { return (jshort) *short_field_addr(offset); }
99 inline void oopDesc::short_field_put(int offset, jshort contents) { *short_field_addr(offset) = (jint) contents;}
100
101 inline jlong oopDesc::long_field(int offset) const { return *long_field_addr(offset); }
102 inline void oopDesc::long_field_put(int offset, jlong contents) { *long_field_addr(offset) = contents; }
103
104 inline jfloat oopDesc::float_field(int offset) const { return *float_field_addr(offset); }
105 inline void oopDesc::float_field_put(int offset, jfloat contents) { *float_field_addr(offset) = contents; }
106
107 inline jdouble oopDesc::double_field(int offset) const { return *double_field_addr(offset); }
108 inline void oopDesc::double_field_put(int offset, jdouble contents) { *double_field_addr(offset) = contents; }
109
110 inline oop oopDesc::obj_field_acquire(int offset) const { return (oop)OrderAccess::load_ptr_acquire(obj_field_addr(offset)); }
111 inline void oopDesc::release_obj_field_put(int offset, oop value) { oop_store((volatile oop*)obj_field_addr(offset), value); }
112
113 inline jbyte oopDesc::byte_field_acquire(int offset) const { return OrderAccess::load_acquire(byte_field_addr(offset)); }
114 inline void oopDesc::release_byte_field_put(int offset, jbyte contents) { OrderAccess::release_store(byte_field_addr(offset), contents); }
115
116 inline jboolean oopDesc::bool_field_acquire(int offset) const { return OrderAccess::load_acquire(bool_field_addr(offset)); }
117 inline void oopDesc::release_bool_field_put(int offset, jboolean contents) { OrderAccess::release_store(bool_field_addr(offset), contents); }
118
119 inline jchar oopDesc::char_field_acquire(int offset) const { return OrderAccess::load_acquire(char_field_addr(offset)); }
120 inline void oopDesc::release_char_field_put(int offset, jchar contents) { OrderAccess::release_store(char_field_addr(offset), contents); }
121
122 inline jint oopDesc::int_field_acquire(int offset) const { return OrderAccess::load_acquire(int_field_addr(offset)); }
123 inline void oopDesc::release_int_field_put(int offset, jint contents) { OrderAccess::release_store(int_field_addr(offset), contents); }
124
125 inline jshort oopDesc::short_field_acquire(int offset) const { return (jshort)OrderAccess::load_acquire(short_field_addr(offset)); }
126 inline void oopDesc::release_short_field_put(int offset, jshort contents) { OrderAccess::release_store(short_field_addr(offset), contents); }
127
128 inline jlong oopDesc::long_field_acquire(int offset) const { return OrderAccess::load_acquire(long_field_addr(offset)); }
129 inline void oopDesc::release_long_field_put(int offset, jlong contents) { OrderAccess::release_store(long_field_addr(offset), contents); }
130
131 inline jfloat oopDesc::float_field_acquire(int offset) const { return OrderAccess::load_acquire(float_field_addr(offset)); }
132 inline void oopDesc::release_float_field_put(int offset, jfloat contents) { OrderAccess::release_store(float_field_addr(offset), contents); }
133
134 inline jdouble oopDesc::double_field_acquire(int offset) const { return OrderAccess::load_acquire(double_field_addr(offset)); }
135 inline void oopDesc::release_double_field_put(int offset, jdouble contents) { OrderAccess::release_store(double_field_addr(offset), contents); }
136
137
138 inline int oopDesc::size_given_klass(Klass* klass) {
139 int lh = klass->layout_helper();
140 int s = lh >> LogHeapWordSize; // deliver size scaled by wordSize
141
142 // lh is now a value computed at class initialization that may hint
143 // at the size. For instances, this is positive and equal to the
144 // size. For arrays, this is negative and provides log2 of the
145 // array element size. For other oops, it is zero and thus requires
146 // a virtual call.
147 //
148 // We go to all this trouble because the size computation is at the
149 // heart of phase 2 of mark-compaction, and called for every object,
150 // alive or dead. So the speed here is equal in importance to the
151 // speed of allocation.
152
153 if (lh <= Klass::_lh_neutral_value) {
154 // The most common case is instances; fall through if so.
155 if (lh < Klass::_lh_neutral_value) {
156 // Second most common case is arrays. We have to fetch the
157 // length of the array, shift (multiply) it appropriately,
158 // up to wordSize, add the header, and align to object size.
159 size_t size_in_bytes;
160 #ifdef _M_IA64
161 // The Windows Itanium Aug 2002 SDK hoists this load above
162 // the check for s < 0. An oop at the end of the heap will
163 // cause an access violation if this load is performed on a non
164 // array oop. Making the reference volatile prohibits this.
165 // (%%% please explain by what magic the length is actually fetched!)
166 volatile int *array_length;
167 array_length = (volatile int *)( (intptr_t)this +
168 arrayOopDesc::length_offset_in_bytes() );
169 assert(array_length > 0, "Integer arithmetic problem somewhere");
170 // Put into size_t to avoid overflow.
171 size_in_bytes = (size_t) array_length;
172 size_in_bytes = size_in_bytes << Klass::layout_helper_log2_element_size(lh);
173 #else
174 size_t array_length = (size_t) ((arrayOop)this)->length();
175 size_in_bytes = array_length << Klass::layout_helper_log2_element_size(lh);
176 #endif
177 size_in_bytes += Klass::layout_helper_header_size(lh);
178
179 // This code could be simplified, but by keeping array_header_in_bytes
180 // in units of bytes and doing it this way we can round up just once,
181 // skipping the intermediate round to HeapWordSize. Cast the result
182 // of round_to to size_t to guarantee unsigned division == right shift.
183 s = (int)((size_t)round_to(size_in_bytes, MinObjAlignmentInBytes) /
184 HeapWordSize);
185
186 // UseParNewGC can change the length field of an "old copy" of an object
187 // array in the young gen so it indicates the stealable portion of
188 // an already copied array. This will cause the first disjunct below
189 // to fail if the sizes are computed across such a concurrent change.
190 // UseParNewGC also runs with promotion labs (which look like int
191 // filler arrays) which are subject to changing their declared size
192 // when finally retiring a PLAB; this also can cause the first disjunct
193 // to fail for another worker thread that is concurrently walking the block
194 // offset table. Both these invariant failures are benign for their
195 // current uses; we relax the assertion checking to cover these two cases below:
196 // is_objArray() && is_forwarded() // covers first scenario above
197 // || is_typeArray() // covers second scenario above
198 // If and when UseParallelGC uses the same obj array oop stealing/chunking
199 // technique, or when G1 is integrated (and currently uses this array chunking
200 // technique) we will need to suitably modify the assertion.
201 assert((s == klass->oop_size(this)) ||
202 (((UseParNewGC || UseParallelGC) &&
203 Universe::heap()->is_gc_active()) &&
204 (is_typeArray() ||
205 (is_objArray() && is_forwarded()))),
206 "wrong array object size");
207 } else {
208 // Must be zero, so bite the bullet and take the virtual call.
209 s = klass->oop_size(this);
210 }
211 }
212
213 assert(s % MinObjAlignment == 0, "alignment check");
214 assert(s > 0, "Bad size calculated");
215 return s;
216 }
217
218
219 inline int oopDesc::size() {
220 return size_given_klass(blueprint());
221 }
222
223 inline bool oopDesc::is_parsable() {
224 return blueprint()->oop_is_parsable(this);
225 }
226
227
228 inline void update_barrier_set(oop *p, oop v) {
229 assert(oopDesc::bs() != NULL, "Uninitialized bs in oop!");
230 oopDesc::bs()->write_ref_field(p, v);
231 }
232
233
234 inline void oop_store(oop* p, oop v) {
235 if (always_do_update_barrier) {
236 oop_store((volatile oop*)p, v);
237 } else {
238 *p = v;
239 update_barrier_set(p, v);
240 }
241 }
242
243 inline void oop_store(volatile oop* p, oop v) {
244 // Used by release_obj_field_put, so use release_store_ptr.
245 OrderAccess::release_store_ptr(p, v);
246 update_barrier_set((oop *)p, v);
247 }
248
249 inline void oop_store_without_check(oop* p, oop v) {
250 // XXX YSR FIX ME!!!
251 if (always_do_update_barrier) {
252 oop_store(p, v);
253 } else {
254 assert(!Universe::heap()->barrier_set()->write_ref_needs_barrier(p, v),
255 "oop store without store check failed");
256 *p = v;
257 }
258 }
259
260 // When it absolutely has to get there.
261 inline void oop_store_without_check(volatile oop* p, oop v) {
262 // XXX YSR FIX ME!!!
263 if (always_do_update_barrier) {
264 oop_store(p, v);
265 } else {
266 assert(!Universe::heap()->barrier_set()->
267 write_ref_needs_barrier((oop *)p, v),
268 "oop store without store check failed");
269 OrderAccess::release_store_ptr(p, v);
270 }
271 }
272
273
274 // Used only for markSweep, scavenging
275 inline bool oopDesc::is_gc_marked() const {
276 return mark()->is_marked();
277 }
278
279 inline bool oopDesc::is_locked() const {
280 return mark()->is_locked();
281 }
282
283 inline bool oopDesc::is_unlocked() const {
284 return mark()->is_unlocked();
285 }
286
287 inline bool oopDesc::has_bias_pattern() const {
288 return mark()->has_bias_pattern();
289 }
290
291 inline bool check_obj_alignment(oop obj) {
292 return (intptr_t)obj % MinObjAlignmentInBytes == 0;
293 }
294
295
296 // used only for asserts
297 inline bool oopDesc::is_oop(bool ignore_mark_word) const {
298 oop obj = (oop) this;
299 if (!check_obj_alignment(obj)) return false;
300 if (!Universe::heap()->is_in_reserved(obj)) return false;
301 // obj is aligned and accessible in heap
302 // try to find metaclass cycle safely without seg faulting on bad input
303 // we should reach klassKlassObj by following klass link at most 3 times
304 for (int i = 0; i < 3; i++) {
305 obj = obj->klass();
306 // klass should be aligned and in permspace
307 if (!check_obj_alignment(obj)) return false;
308 if (!Universe::heap()->is_in_permanent(obj)) return false;
309 }
310 if (obj != Universe::klassKlassObj()) {
311 // During a dump, the _klassKlassObj moved to a shared space.
312 if (DumpSharedSpaces && Universe::klassKlassObj()->is_shared()) {
313 return true;
314 }
315 return false;
316 }
317
318 // Header verification: the mark is typically non-NULL. If we're
319 // at a safepoint, it must not be null.
320 // Outside of a safepoint, the header could be changing (for example,
321 // another thread could be inflating a lock on this object).
322 if (ignore_mark_word) {
323 return true;
324 }
325 if (mark() != NULL) {
326 return true;
327 }
328 return !SafepointSynchronize::is_at_safepoint();
329 }
330
331
332 // used only for asserts
333 inline bool oopDesc::is_oop_or_null(bool ignore_mark_word) const {
334 return this == NULL ? true : is_oop(ignore_mark_word);
335 }
336
337 #ifndef PRODUCT
338 // used only for asserts
339 inline bool oopDesc::is_unlocked_oop() const {
340 if (!Universe::heap()->is_in_reserved(this)) return false;
341 return mark()->is_unlocked();
342 }
343
344
345 #endif // PRODUCT
346
347 inline void oopDesc::follow_header() {
348 MarkSweep::mark_and_push((oop*)&_klass);
349 }
350
351 inline void oopDesc::follow_contents() {
352 assert (is_gc_marked(), "should be marked");
353 blueprint()->oop_follow_contents(this);
354 }
355
356
357 // Used by scavengers
358
359 inline bool oopDesc::is_forwarded() const {
360 // The extra heap check is needed since the obj might be locked, in which case the
361 // mark would point to a stack location and have the sentinel bit cleared
362 return mark()->is_marked();
363 }
364
365
366 // Used by scavengers
367 inline void oopDesc::forward_to(oop p) {
368 assert(Universe::heap()->is_in_reserved(p),
369 "forwarding to something not in heap");
370 markOop m = markOopDesc::encode_pointer_as_mark(p);
371 assert(m->decode_pointer() == p, "encoding must be reversable");
372 set_mark(m);
373 }
374
375 // Used by parallel scavengers
376 inline bool oopDesc::cas_forward_to(oop p, markOop compare) {
377 assert(Universe::heap()->is_in_reserved(p),
378 "forwarding to something not in heap");
379 markOop m = markOopDesc::encode_pointer_as_mark(p);
380 assert(m->decode_pointer() == p, "encoding must be reversable");
381 return cas_set_mark(m, compare) == compare;
382 }
383
384 // Note that the forwardee is not the same thing as the displaced_mark.
385 // The forwardee is used when copying during scavenge and mark-sweep.
386 // It does need to clear the low two locking- and GC-related bits.
387 inline oop oopDesc::forwardee() const { return (oop) mark()->decode_pointer(); }
388
389
390 inline bool oopDesc::has_displaced_mark() const {
391 return mark()->has_displaced_mark_helper();
392 }
393
394 inline markOop oopDesc::displaced_mark() const {
395 return mark()->displaced_mark_helper();
396 }
397
398 inline void oopDesc::set_displaced_mark(markOop m) {
399 mark()->set_displaced_mark_helper(m);
400 }
401
402 // The following method needs to be MT safe.
403 inline int oopDesc::age() const {
404 assert(!is_forwarded(), "Attempt to read age from forwarded mark");
405 if (has_displaced_mark()) {
406 return displaced_mark()->age();
407 } else {
408 return mark()->age();
409 }
410 }
411
412 inline void oopDesc::incr_age() {
413 assert(!is_forwarded(), "Attempt to increment age of forwarded mark");
414 if (has_displaced_mark()) {
415 set_displaced_mark(displaced_mark()->incr_age());
416 } else {
417 set_mark(mark()->incr_age());
418 }
419 }
420
421
422 inline intptr_t oopDesc::identity_hash() {
423 // Fast case; if the object is unlocked and the hash value is set, no locking is needed
424 // Note: The mark must be read into local variable to avoid concurrent updates.
425 markOop mrk = mark();
426 if (mrk->is_unlocked() && !mrk->has_no_hash()) {
427 return mrk->hash();
428 } else if (mrk->is_marked()) {
429 return mrk->hash();
430 } else {
431 return slow_identity_hash();
432 }
433 }
434
435
436 inline void oopDesc::oop_iterate_header(OopClosure* blk) {
437 blk->do_oop((oop*)&_klass);
438 }
439
440
441 inline void oopDesc::oop_iterate_header(OopClosure* blk, MemRegion mr) {
442 if (mr.contains(&_klass)) blk->do_oop((oop*)&_klass);
443 }
444
445
446 inline int oopDesc::adjust_pointers() {
447 debug_only(int check_size = size());
448 int s = blueprint()->oop_adjust_pointers(this);
449 assert(s == check_size, "should be the same");
450 return s;
451 }
452
453 inline void oopDesc::adjust_header() {
454 MarkSweep::adjust_pointer((oop*)&_klass);
455 }
456
457 #define OOP_ITERATE_DEFN(OopClosureType, nv_suffix) \
458 \
459 inline int oopDesc::oop_iterate(OopClosureType* blk) { \
460 SpecializationStats::record_call(); \
461 return blueprint()->oop_oop_iterate##nv_suffix(this, blk); \
462 } \
463 \
464 inline int oopDesc::oop_iterate(OopClosureType* blk, MemRegion mr) { \
465 SpecializationStats::record_call(); \
466 return blueprint()->oop_oop_iterate##nv_suffix##_m(this, blk, mr); \
467 }
468
469 ALL_OOP_OOP_ITERATE_CLOSURES_1(OOP_ITERATE_DEFN)
470 ALL_OOP_OOP_ITERATE_CLOSURES_3(OOP_ITERATE_DEFN)
471
472
473 inline bool oopDesc::is_shared() const {
474 return CompactingPermGenGen::is_shared(this);
475 }
476
477 inline bool oopDesc::is_shared_readonly() const {
478 return CompactingPermGenGen::is_shared_readonly(this);
479 }
480
481 inline bool oopDesc::is_shared_readwrite() const {
482 return CompactingPermGenGen::is_shared_readwrite(this);
483 }