< prev index next >

src/hotspot/share/oops/oop.cpp

Print this page

 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  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/altHashing.hpp"
 27 #include "classfile/javaClasses.inline.hpp"
 28 #include "gc/shared/collectedHeap.inline.hpp"
 29 #include "gc/shared/gc_globals.hpp"
 30 #include "memory/resourceArea.hpp"
 31 #include "memory/universe.hpp"
 32 #include "oops/access.inline.hpp"

 33 #include "oops/compressedOops.inline.hpp"
 34 #include "oops/oop.inline.hpp"
 35 #include "oops/verifyOopClosure.hpp"
 36 #include "runtime/handles.inline.hpp"

 37 #include "runtime/javaThread.hpp"
 38 #include "utilities/macros.hpp"
 39 
 40 void oopDesc::print_on(outputStream* st) const {
 41   if (*((juint*)this) == badHeapWordVal) {
 42     st->print("BAD WORD");
 43   } else if (*((juint*)this) == badMetaWordVal) {
 44     st->print("BAD META WORD");
 45   } else {
 46     klass()->oop_print_on(cast_to_oop(this), st);
 47   }
 48 }
 49 
 50 void oopDesc::print_address_on(outputStream* st) const {
 51   st->print("{" INTPTR_FORMAT "}", p2i(this));
 52 
 53 }
 54 
 55 void oopDesc::print()         { print_on(tty);         }
 56 

129 }
130 
131 VerifyOopClosure VerifyOopClosure::verify_oop;
132 
133 template <class T> void VerifyOopClosure::do_oop_work(T* p) {
134   oop obj = RawAccess<>::oop_load(p);
135   guarantee(oopDesc::is_oop_or_null(obj), "invalid oop: " INTPTR_FORMAT, p2i((oopDesc*) obj));
136 }
137 
138 void VerifyOopClosure::do_oop(oop* p)       { VerifyOopClosure::do_oop_work(p); }
139 void VerifyOopClosure::do_oop(narrowOop* p) { VerifyOopClosure::do_oop_work(p); }
140 
141 // type test operations that doesn't require inclusion of oop.inline.hpp.
142 bool oopDesc::is_instance_noinline()    const { return is_instance();    }
143 bool oopDesc::is_instanceRef_noinline() const { return is_instanceRef(); }
144 bool oopDesc::is_stackChunk_noinline()  const { return is_stackChunk();  }
145 bool oopDesc::is_array_noinline()       const { return is_array();       }
146 bool oopDesc::is_objArray_noinline()    const { return is_objArray();    }
147 bool oopDesc::is_typeArray_noinline()   const { return is_typeArray();   }
148 
149 bool oopDesc::has_klass_gap() {
150   // Only has a klass gap when compressed class pointers are used.
151   return UseCompressedClassPointers;
152 }
153 
154 #if INCLUDE_CDS_JAVA_HEAP
155 void oopDesc::set_narrow_klass(narrowKlass nk) {
156   assert(DumpSharedSpaces, "Used by CDS only. Do not abuse!");
157   assert(UseCompressedClassPointers, "must be");
158   _metadata._compressed_klass = nk;
159 }
160 #endif
161 
162 void* oopDesc::load_klass_raw(oop obj) {
163   if (UseCompressedClassPointers) {
164     narrowKlass narrow_klass = obj->_metadata._compressed_klass;
165     if (narrow_klass == 0) return NULL;
166     return (void*)CompressedKlassPointers::decode_raw(narrow_klass);
167   } else {
168     return obj->_metadata._klass;
169   }

170 }
171 
172 void* oopDesc::load_oop_raw(oop obj, int offset) {
173   uintptr_t addr = (uintptr_t)(void*)obj + (uint)offset;
174   if (UseCompressedOops) {
175     narrowOop narrow_oop = *(narrowOop*)addr;
176     if (CompressedOops::is_null(narrow_oop)) return NULL;
177     return (void*)CompressedOops::decode_raw(narrow_oop);
178   } else {
179     return *(void**)addr;
180   }
181 }
182 















183 oop oopDesc::obj_field_acquire(int offset) const                      { return HeapAccess<MO_ACQUIRE>::oop_load_at(as_oop(), offset); }
184 
185 void oopDesc::obj_field_put_raw(int offset, oop value)                { RawAccess<>::oop_store_at(as_oop(), offset, value); }
186 void oopDesc::release_obj_field_put(int offset, oop value)            { HeapAccess<MO_RELEASE>::oop_store_at(as_oop(), offset, value); }
187 void oopDesc::obj_field_put_volatile(int offset, oop value)           { HeapAccess<MO_SEQ_CST>::oop_store_at(as_oop(), offset, value); }
188 
189 address oopDesc::address_field(int offset) const                      { return *field_addr<address>(offset); }
190 address oopDesc::address_field_acquire(int offset) const              { return Atomic::load_acquire(field_addr<address>(offset)); }
191 
192 void oopDesc::address_field_put(int offset, address value)            { *field_addr<address>(offset) = value; }
193 void oopDesc::release_address_field_put(int offset, address value)    { Atomic::release_store(field_addr<address>(offset), value); }
194 
195 Metadata* oopDesc::metadata_field(int offset) const                   { return *field_addr<Metadata*>(offset); }
196 void oopDesc::metadata_field_put(int offset, Metadata* value)         { *field_addr<Metadata*>(offset) = value; }
197 
198 Metadata* oopDesc::metadata_field_acquire(int offset) const           { return Atomic::load_acquire(field_addr<Metadata*>(offset)); }
199 void oopDesc::release_metadata_field_put(int offset, Metadata* value) { Atomic::release_store(field_addr<Metadata*>(offset), value); }
200 
201 jbyte oopDesc::byte_field_acquire(int offset) const                   { return Atomic::load_acquire(field_addr<jbyte>(offset)); }
202 void oopDesc::release_byte_field_put(int offset, jbyte value)         { Atomic::release_store(field_addr<jbyte>(offset), value); }

 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  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "classfile/altHashing.hpp"
 27 #include "classfile/javaClasses.inline.hpp"
 28 #include "gc/shared/collectedHeap.inline.hpp"
 29 #include "gc/shared/gc_globals.hpp"
 30 #include "memory/resourceArea.hpp"
 31 #include "memory/universe.hpp"
 32 #include "oops/access.inline.hpp"
 33 #include "oops/compressedKlass.inline.hpp"
 34 #include "oops/compressedOops.inline.hpp"
 35 #include "oops/oop.inline.hpp"
 36 #include "oops/verifyOopClosure.hpp"
 37 #include "runtime/handles.inline.hpp"
 38 #include "runtime/interfaceSupport.inline.hpp"
 39 #include "runtime/javaThread.hpp"
 40 #include "utilities/macros.hpp"
 41 
 42 void oopDesc::print_on(outputStream* st) const {
 43   if (*((juint*)this) == badHeapWordVal) {
 44     st->print("BAD WORD");
 45   } else if (*((juint*)this) == badMetaWordVal) {
 46     st->print("BAD META WORD");
 47   } else {
 48     klass()->oop_print_on(cast_to_oop(this), st);
 49   }
 50 }
 51 
 52 void oopDesc::print_address_on(outputStream* st) const {
 53   st->print("{" INTPTR_FORMAT "}", p2i(this));
 54 
 55 }
 56 
 57 void oopDesc::print()         { print_on(tty);         }
 58 

131 }
132 
133 VerifyOopClosure VerifyOopClosure::verify_oop;
134 
135 template <class T> void VerifyOopClosure::do_oop_work(T* p) {
136   oop obj = RawAccess<>::oop_load(p);
137   guarantee(oopDesc::is_oop_or_null(obj), "invalid oop: " INTPTR_FORMAT, p2i((oopDesc*) obj));
138 }
139 
140 void VerifyOopClosure::do_oop(oop* p)       { VerifyOopClosure::do_oop_work(p); }
141 void VerifyOopClosure::do_oop(narrowOop* p) { VerifyOopClosure::do_oop_work(p); }
142 
143 // type test operations that doesn't require inclusion of oop.inline.hpp.
144 bool oopDesc::is_instance_noinline()    const { return is_instance();    }
145 bool oopDesc::is_instanceRef_noinline() const { return is_instanceRef(); }
146 bool oopDesc::is_stackChunk_noinline()  const { return is_stackChunk();  }
147 bool oopDesc::is_array_noinline()       const { return is_array();       }
148 bool oopDesc::is_objArray_noinline()    const { return is_objArray();    }
149 bool oopDesc::is_typeArray_noinline()   const { return is_typeArray();   }
150 













151 void* oopDesc::load_klass_raw(oop obj) {
152   // TODO: Remove method altogether and replace with calls to obj->klass() ?
153   // OTOH, we may eventually get rid of locking in header, and then no
154   // longer have to deal with that anymore.
155 #ifdef _LP64
156   return obj->klass();
157 #else
158   return obj->_klass;
159 #endif
160 }
161 
162 void* oopDesc::load_oop_raw(oop obj, int offset) {
163   uintptr_t addr = (uintptr_t)(void*)obj + (uint)offset;
164   if (UseCompressedOops) {
165     narrowOop narrow_oop = *(narrowOop*)addr;
166     if (CompressedOops::is_null(narrow_oop)) return NULL;
167     return (void*)CompressedOops::decode_raw(narrow_oop);
168   } else {
169     return *(void**)addr;
170   }
171 }
172 
173 #ifdef _LP64
174 JRT_LEAF(narrowKlass, oopDesc::load_nklass_runtime(oopDesc* o))
175   assert(o != NULL, "null-check");
176   oop obj = oop(o);
177   assert(oopDesc::is_oop(obj), "need a valid oop here: " PTR_FORMAT, p2i(o));
178   markWord header = obj->mark();
179   if (!header.is_neutral()) {
180     header = ObjectSynchronizer::stable_mark(obj);
181   }
182   assert(header.is_neutral(), "expect neutral header here");
183   narrowKlass nklass = header.narrow_klass();
184   return nklass;
185 JRT_END
186 #endif
187 
188 oop oopDesc::obj_field_acquire(int offset) const                      { return HeapAccess<MO_ACQUIRE>::oop_load_at(as_oop(), offset); }
189 
190 void oopDesc::obj_field_put_raw(int offset, oop value)                { RawAccess<>::oop_store_at(as_oop(), offset, value); }
191 void oopDesc::release_obj_field_put(int offset, oop value)            { HeapAccess<MO_RELEASE>::oop_store_at(as_oop(), offset, value); }
192 void oopDesc::obj_field_put_volatile(int offset, oop value)           { HeapAccess<MO_SEQ_CST>::oop_store_at(as_oop(), offset, value); }
193 
194 address oopDesc::address_field(int offset) const                      { return *field_addr<address>(offset); }
195 address oopDesc::address_field_acquire(int offset) const              { return Atomic::load_acquire(field_addr<address>(offset)); }
196 
197 void oopDesc::address_field_put(int offset, address value)            { *field_addr<address>(offset) = value; }
198 void oopDesc::release_address_field_put(int offset, address value)    { Atomic::release_store(field_addr<address>(offset), value); }
199 
200 Metadata* oopDesc::metadata_field(int offset) const                   { return *field_addr<Metadata*>(offset); }
201 void oopDesc::metadata_field_put(int offset, Metadata* value)         { *field_addr<Metadata*>(offset) = value; }
202 
203 Metadata* oopDesc::metadata_field_acquire(int offset) const           { return Atomic::load_acquire(field_addr<Metadata*>(offset)); }
204 void oopDesc::release_metadata_field_put(int offset, Metadata* value) { Atomic::release_store(field_addr<Metadata*>(offset), value); }
205 
206 jbyte oopDesc::byte_field_acquire(int offset) const                   { return Atomic::load_acquire(field_addr<jbyte>(offset)); }
207 void oopDesc::release_byte_field_put(int offset, jbyte value)         { Atomic::release_store(field_addr<jbyte>(offset), value); }
< prev index next >