< 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/thread.inline.hpp"
 38 #include "utilities/copy.hpp"
 39 #include "utilities/macros.hpp"
 40 
 41 void oopDesc::print_on(outputStream* st) const {
 42   klass()->oop_print_on(const_cast<oopDesc*>(this), st);
 43 }
 44 
 45 void oopDesc::print_address_on(outputStream* st) const {
 46   st->print("{" INTPTR_FORMAT "}", p2i(this));
 47 
 48 }
 49 
 50 void oopDesc::print()         { print_on(tty);         }
 51 
 52 void oopDesc::print_address() { print_address_on(tty); }
 53 
 54 char* oopDesc::print_string() {
 55   stringStream st;
 56   print_on(&st);

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

164 }
165 
166 void* oopDesc::load_oop_raw(oop obj, int offset) {
167   uintptr_t addr = (uintptr_t)(void*)obj + (uint)offset;
168   if (UseCompressedOops) {
169     narrowOop narrow_oop = *(narrowOop*)addr;
170     if (CompressedOops::is_null(narrow_oop)) return NULL;
171     return (void*)CompressedOops::decode_raw(narrow_oop);
172   } else {
173     return *(void**)addr;
174   }
175 }
176 















177 oop oopDesc::obj_field_acquire(int offset) const                      { return HeapAccess<MO_ACQUIRE>::oop_load_at(as_oop(), offset); }
178 
179 void oopDesc::obj_field_put_raw(int offset, oop value)                { RawAccess<>::oop_store_at(as_oop(), offset, value); }
180 void oopDesc::release_obj_field_put(int offset, oop value)            { HeapAccess<MO_RELEASE>::oop_store_at(as_oop(), offset, value); }
181 void oopDesc::obj_field_put_volatile(int offset, oop value)           { HeapAccess<MO_SEQ_CST>::oop_store_at(as_oop(), offset, value); }
182 
183 address oopDesc::address_field(int offset) const                      { return *field_addr<address>(offset); }
184 address oopDesc::address_field_acquire(int offset) const              { return Atomic::load_acquire(field_addr<address>(offset)); }
185 
186 void oopDesc::address_field_put(int offset, address value)            { *field_addr<address>(offset) = value; }
187 void oopDesc::release_address_field_put(int offset, address value)    { Atomic::release_store(field_addr<address>(offset), value); }
188 
189 Metadata* oopDesc::metadata_field(int offset) const                   { return *field_addr<Metadata*>(offset); }
190 void oopDesc::metadata_field_put(int offset, Metadata* value)         { *field_addr<Metadata*>(offset) = value; }
191 
192 Metadata* oopDesc::metadata_field_acquire(int offset) const           { return Atomic::load_acquire(field_addr<Metadata*>(offset)); }
193 void oopDesc::release_metadata_field_put(int offset, Metadata* value) { Atomic::release_store(field_addr<Metadata*>(offset), value); }
194 
195 jbyte oopDesc::byte_field_acquire(int offset) const                   { return Atomic::load_acquire(field_addr<jbyte>(offset)); }
196 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/thread.inline.hpp"
 40 #include "utilities/copy.hpp"
 41 #include "utilities/macros.hpp"
 42 
 43 void oopDesc::print_on(outputStream* st) const {
 44   klass()->oop_print_on(const_cast<oopDesc*>(this), st);
 45 }
 46 
 47 void oopDesc::print_address_on(outputStream* st) const {
 48   st->print("{" INTPTR_FORMAT "}", p2i(this));
 49 
 50 }
 51 
 52 void oopDesc::print()         { print_on(tty);         }
 53 
 54 void oopDesc::print_address() { print_address_on(tty); }
 55 
 56 char* oopDesc::print_string() {
 57   stringStream st;
 58   print_on(&st);

125   return obj == NULL ? true : is_oop(obj, ignore_mark_word);
126 }
127 
128 VerifyOopClosure VerifyOopClosure::verify_oop;
129 
130 template <class T> void VerifyOopClosure::do_oop_work(T* p) {
131   oop obj = RawAccess<>::oop_load(p);
132   guarantee(oopDesc::is_oop_or_null(obj), "invalid oop: " INTPTR_FORMAT, p2i((oopDesc*) obj));
133 }
134 
135 void VerifyOopClosure::do_oop(oop* p)       { VerifyOopClosure::do_oop_work(p); }
136 void VerifyOopClosure::do_oop(narrowOop* p) { VerifyOopClosure::do_oop_work(p); }
137 
138 // type test operations that doesn't require inclusion of oop.inline.hpp.
139 bool oopDesc::is_instance_noinline()    const { return is_instance();    }
140 bool oopDesc::is_instanceRef_noinline() const { return is_instanceRef(); }
141 bool oopDesc::is_array_noinline()       const { return is_array();       }
142 bool oopDesc::is_objArray_noinline()    const { return is_objArray();    }
143 bool oopDesc::is_typeArray_noinline()   const { return is_typeArray();   }
144 













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