1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
124 *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes()) = v;
125 }
126 }
127
128 inline void oopDesc::set_klass_to_list_ptr(oop k) {
129 // This is only to be used during GC, for from-space objects, so no
130 // barrier is needed.
131 if (UseCompressedOops) {
132 _metadata._compressed_klass = encode_heap_oop(k); // may be null (parnew overflow handling)
133 } else {
134 _metadata._klass = (klassOop)k;
135 }
136 }
137
138 inline void oopDesc::init_mark() { set_mark(markOopDesc::prototype_for_object(this)); }
139 inline Klass* oopDesc::blueprint() const { return klass()->klass_part(); }
140
141 inline bool oopDesc::is_a(klassOop k) const { return blueprint()->is_subtype_of(k); }
142
143 inline bool oopDesc::is_instance() const { return blueprint()->oop_is_instance(); }
144 inline bool oopDesc::is_instanceRef() const { return blueprint()->oop_is_instanceRef(); }
145 inline bool oopDesc::is_array() const { return blueprint()->oop_is_array(); }
146 inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_objArray(); }
147 inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
148 inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
149 inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
150 inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
151 inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
152 inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
153 inline bool oopDesc::is_methodData() const { return blueprint()->oop_is_methodData(); }
154 inline bool oopDesc::is_constantPool() const { return blueprint()->oop_is_constantPool(); }
155 inline bool oopDesc::is_constantPoolCache() const { return blueprint()->oop_is_constantPoolCache(); }
156 inline bool oopDesc::is_compiledICHolder() const { return blueprint()->oop_is_compiledICHolder(); }
157
158 inline void* oopDesc::field_base(int offset) const { return (void*)&((char*)this)[offset]; }
159
160 template <class T> inline T* oopDesc::obj_field_addr(int offset) const { return (T*)field_base(offset); }
161 inline jbyte* oopDesc::byte_field_addr(int offset) const { return (jbyte*) field_base(offset); }
162 inline jchar* oopDesc::char_field_addr(int offset) const { return (jchar*) field_base(offset); }
163 inline jboolean* oopDesc::bool_field_addr(int offset) const { return (jboolean*)field_base(offset); }
382 inline jint oopDesc::int_field_acquire(int offset) const { return OrderAccess::load_acquire(int_field_addr(offset)); }
383 inline void oopDesc::release_int_field_put(int offset, jint contents) { OrderAccess::release_store(int_field_addr(offset), contents); }
384
385 inline jshort oopDesc::short_field_acquire(int offset) const { return (jshort)OrderAccess::load_acquire(short_field_addr(offset)); }
386 inline void oopDesc::release_short_field_put(int offset, jshort contents) { OrderAccess::release_store(short_field_addr(offset), contents); }
387
388 inline jlong oopDesc::long_field_acquire(int offset) const { return OrderAccess::load_acquire(long_field_addr(offset)); }
389 inline void oopDesc::release_long_field_put(int offset, jlong contents) { OrderAccess::release_store(long_field_addr(offset), contents); }
390
391 inline jfloat oopDesc::float_field_acquire(int offset) const { return OrderAccess::load_acquire(float_field_addr(offset)); }
392 inline void oopDesc::release_float_field_put(int offset, jfloat contents) { OrderAccess::release_store(float_field_addr(offset), contents); }
393
394 inline jdouble oopDesc::double_field_acquire(int offset) const { return OrderAccess::load_acquire(double_field_addr(offset)); }
395 inline void oopDesc::release_double_field_put(int offset, jdouble contents) { OrderAccess::release_store(double_field_addr(offset), contents); }
396
397 inline address oopDesc::address_field_acquire(int offset) const { return (address) OrderAccess::load_ptr_acquire(address_field_addr(offset)); }
398 inline void oopDesc::release_address_field_put(int offset, address contents) { OrderAccess::release_store_ptr(address_field_addr(offset), contents); }
399
400 inline int oopDesc::size_given_klass(Klass* klass) {
401 int lh = klass->layout_helper();
402 int s = lh >> LogHeapWordSize; // deliver size scaled by wordSize
403
404 // lh is now a value computed at class initialization that may hint
405 // at the size. For instances, this is positive and equal to the
406 // size. For arrays, this is negative and provides log2 of the
407 // array element size. For other oops, it is zero and thus requires
408 // a virtual call.
409 //
410 // We go to all this trouble because the size computation is at the
411 // heart of phase 2 of mark-compaction, and called for every object,
412 // alive or dead. So the speed here is equal in importance to the
413 // speed of allocation.
414
415 if (lh <= Klass::_lh_neutral_value) {
416 // The most common case is instances; fall through if so.
417 if (lh < Klass::_lh_neutral_value) {
418 // Second most common case is arrays. We have to fetch the
419 // length of the array, shift (multiply) it appropriately,
420 // up to wordSize, add the header, and align to object size.
421 size_t size_in_bytes;
422 #ifdef _M_IA64
423 // The Windows Itanium Aug 2002 SDK hoists this load above
424 // the check for s < 0. An oop at the end of the heap will
425 // cause an access violation if this load is performed on a non
426 // array oop. Making the reference volatile prohibits this.
427 // (%%% please explain by what magic the length is actually fetched!)
428 volatile int *array_length;
429 array_length = (volatile int *)( (intptr_t)this +
430 arrayOopDesc::length_offset_in_bytes() );
431 assert(array_length > 0, "Integer arithmetic problem somewhere");
432 // Put into size_t to avoid overflow.
433 size_in_bytes = (size_t) array_length;
434 size_in_bytes = size_in_bytes << Klass::layout_helper_log2_element_size(lh);
435 #else
|
1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
124 *(int*)(((intptr_t)this) + klass_gap_offset_in_bytes()) = v;
125 }
126 }
127
128 inline void oopDesc::set_klass_to_list_ptr(oop k) {
129 // This is only to be used during GC, for from-space objects, so no
130 // barrier is needed.
131 if (UseCompressedOops) {
132 _metadata._compressed_klass = encode_heap_oop(k); // may be null (parnew overflow handling)
133 } else {
134 _metadata._klass = (klassOop)k;
135 }
136 }
137
138 inline void oopDesc::init_mark() { set_mark(markOopDesc::prototype_for_object(this)); }
139 inline Klass* oopDesc::blueprint() const { return klass()->klass_part(); }
140
141 inline bool oopDesc::is_a(klassOop k) const { return blueprint()->is_subtype_of(k); }
142
143 inline bool oopDesc::is_instance() const { return blueprint()->oop_is_instance(); }
144 inline bool oopDesc::is_instanceMirror() const { return blueprint()->oop_is_instanceMirror(); }
145 inline bool oopDesc::is_instanceRef() const { return blueprint()->oop_is_instanceRef(); }
146 inline bool oopDesc::is_array() const { return blueprint()->oop_is_array(); }
147 inline bool oopDesc::is_objArray() const { return blueprint()->oop_is_objArray(); }
148 inline bool oopDesc::is_typeArray() const { return blueprint()->oop_is_typeArray(); }
149 inline bool oopDesc::is_javaArray() const { return blueprint()->oop_is_javaArray(); }
150 inline bool oopDesc::is_klass() const { return blueprint()->oop_is_klass(); }
151 inline bool oopDesc::is_thread() const { return blueprint()->oop_is_thread(); }
152 inline bool oopDesc::is_method() const { return blueprint()->oop_is_method(); }
153 inline bool oopDesc::is_constMethod() const { return blueprint()->oop_is_constMethod(); }
154 inline bool oopDesc::is_methodData() const { return blueprint()->oop_is_methodData(); }
155 inline bool oopDesc::is_constantPool() const { return blueprint()->oop_is_constantPool(); }
156 inline bool oopDesc::is_constantPoolCache() const { return blueprint()->oop_is_constantPoolCache(); }
157 inline bool oopDesc::is_compiledICHolder() const { return blueprint()->oop_is_compiledICHolder(); }
158
159 inline void* oopDesc::field_base(int offset) const { return (void*)&((char*)this)[offset]; }
160
161 template <class T> inline T* oopDesc::obj_field_addr(int offset) const { return (T*)field_base(offset); }
162 inline jbyte* oopDesc::byte_field_addr(int offset) const { return (jbyte*) field_base(offset); }
163 inline jchar* oopDesc::char_field_addr(int offset) const { return (jchar*) field_base(offset); }
164 inline jboolean* oopDesc::bool_field_addr(int offset) const { return (jboolean*)field_base(offset); }
383 inline jint oopDesc::int_field_acquire(int offset) const { return OrderAccess::load_acquire(int_field_addr(offset)); }
384 inline void oopDesc::release_int_field_put(int offset, jint contents) { OrderAccess::release_store(int_field_addr(offset), contents); }
385
386 inline jshort oopDesc::short_field_acquire(int offset) const { return (jshort)OrderAccess::load_acquire(short_field_addr(offset)); }
387 inline void oopDesc::release_short_field_put(int offset, jshort contents) { OrderAccess::release_store(short_field_addr(offset), contents); }
388
389 inline jlong oopDesc::long_field_acquire(int offset) const { return OrderAccess::load_acquire(long_field_addr(offset)); }
390 inline void oopDesc::release_long_field_put(int offset, jlong contents) { OrderAccess::release_store(long_field_addr(offset), contents); }
391
392 inline jfloat oopDesc::float_field_acquire(int offset) const { return OrderAccess::load_acquire(float_field_addr(offset)); }
393 inline void oopDesc::release_float_field_put(int offset, jfloat contents) { OrderAccess::release_store(float_field_addr(offset), contents); }
394
395 inline jdouble oopDesc::double_field_acquire(int offset) const { return OrderAccess::load_acquire(double_field_addr(offset)); }
396 inline void oopDesc::release_double_field_put(int offset, jdouble contents) { OrderAccess::release_store(double_field_addr(offset), contents); }
397
398 inline address oopDesc::address_field_acquire(int offset) const { return (address) OrderAccess::load_ptr_acquire(address_field_addr(offset)); }
399 inline void oopDesc::release_address_field_put(int offset, address contents) { OrderAccess::release_store_ptr(address_field_addr(offset), contents); }
400
401 inline int oopDesc::size_given_klass(Klass* klass) {
402 int lh = klass->layout_helper();
403 int s;
404
405 // lh is now a value computed at class initialization that may hint
406 // at the size. For instances, this is positive and equal to the
407 // size. For arrays, this is negative and provides log2 of the
408 // array element size. For other oops, it is zero and thus requires
409 // a virtual call.
410 //
411 // We go to all this trouble because the size computation is at the
412 // heart of phase 2 of mark-compaction, and called for every object,
413 // alive or dead. So the speed here is equal in importance to the
414 // speed of allocation.
415
416 if (lh > Klass::_lh_neutral_value) {
417 if (!Klass::layout_helper_needs_slow_path(lh)) {
418 s = lh >> LogHeapWordSize; // deliver size scaled by wordSize
419 } else {
420 s = klass->oop_size(this);
421 }
422 } else if (lh <= Klass::_lh_neutral_value) {
423 // The most common case is instances; fall through if so.
424 if (lh < Klass::_lh_neutral_value) {
425 // Second most common case is arrays. We have to fetch the
426 // length of the array, shift (multiply) it appropriately,
427 // up to wordSize, add the header, and align to object size.
428 size_t size_in_bytes;
429 #ifdef _M_IA64
430 // The Windows Itanium Aug 2002 SDK hoists this load above
431 // the check for s < 0. An oop at the end of the heap will
432 // cause an access violation if this load is performed on a non
433 // array oop. Making the reference volatile prohibits this.
434 // (%%% please explain by what magic the length is actually fetched!)
435 volatile int *array_length;
436 array_length = (volatile int *)( (intptr_t)this +
437 arrayOopDesc::length_offset_in_bytes() );
438 assert(array_length > 0, "Integer arithmetic problem somewhere");
439 // Put into size_t to avoid overflow.
440 size_in_bytes = (size_t) array_length;
441 size_in_bytes = size_in_bytes << Klass::layout_helper_log2_element_size(lh);
442 #else
|