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

 95 void oopDesc::verify(oopDesc* oop_desc) {
 96   verify_on(tty, oop_desc);
 97 }
 98 
 99 intptr_t oopDesc::slow_identity_hash() {
100   // slow case; we have to acquire the micro lock in order to locate the header
101   Thread* current = Thread::current();
102   return ObjectSynchronizer::FastHashCode(current, this);
103 }
104 
105 // used only for asserts and guarantees
106 bool oopDesc::is_oop(oop obj, bool ignore_mark_word) {
107   if (!Universe::heap()->is_oop(obj)) {
108     return false;
109   }
110 
111   // Header verification: the mark is typically non-zero. If we're
112   // at a safepoint, it must not be zero.
113   // Outside of a safepoint, the header could be changing (for example,
114   // another thread could be inflating a lock on this object).
115   if (ignore_mark_word) {
116     return true;
117   }
118   if (obj->mark().value() != 0) {
119     return true;
120   }
121   return !SafepointSynchronize::is_at_safepoint();
122 }
123 
124 // used only for asserts and guarantees
125 bool oopDesc::is_oop_or_null(oop obj, bool ignore_mark_word) {
126   return obj == NULL ? true : is_oop(obj, ignore_mark_word);
127 }
128 
129 VerifyOopClosure VerifyOopClosure::verify_oop;
130 
131 template <class T> void VerifyOopClosure::do_oop_work(T* p) {
132   oop obj = RawAccess<>::oop_load(p);
133   guarantee(oopDesc::is_oop_or_null(obj), "invalid oop: " PTR_FORMAT, p2i(obj));
134 }
135 
136 void VerifyOopClosure::do_oop(oop* p)       { VerifyOopClosure::do_oop_work(p); }
137 void VerifyOopClosure::do_oop(narrowOop* p) { VerifyOopClosure::do_oop_work(p); }
138 
139 // type test operations that doesn't require inclusion of oop.inline.hpp.
140 bool oopDesc::is_instance_noinline()    const { return is_instance();    }
141 bool oopDesc::is_instanceRef_noinline() const { return is_instanceRef(); }
142 bool oopDesc::is_stackChunk_noinline()  const { return is_stackChunk();  }
143 bool oopDesc::is_array_noinline()       const { return is_array();       }
144 bool oopDesc::is_objArray_noinline()    const { return is_objArray();    }
145 bool oopDesc::is_typeArray_noinline()   const { return is_typeArray();   }
146 
147 bool oopDesc::has_klass_gap() {
148   // Only has a klass gap when compressed class pointers are used.
149   return UseCompressedClassPointers;
150 }
151 
152 #if INCLUDE_CDS_JAVA_HEAP
153 void oopDesc::set_narrow_klass(narrowKlass nk) {
154   assert(DumpSharedSpaces, "Used by CDS only. Do not abuse!");
155   assert(UseCompressedClassPointers, "must be");
156   _metadata._compressed_klass = nk;
157 }
158 #endif
159 
160 void* oopDesc::load_klass_raw(oop obj) {
161   if (UseCompressedClassPointers) {
162     narrowKlass narrow_klass = obj->_metadata._compressed_klass;
163     if (narrow_klass == 0) return NULL;
164     return (void*)CompressedKlassPointers::decode_raw(narrow_klass);
165   } else {
166     return obj->_metadata._klass;
167   }

168 }
169 
170 void* oopDesc::load_oop_raw(oop obj, int offset) {
171   uintptr_t addr = (uintptr_t)(void*)obj + (uint)offset;
172   if (UseCompressedOops) {
173     narrowOop narrow_oop = *(narrowOop*)addr;
174     if (CompressedOops::is_null(narrow_oop)) return NULL;
175     return (void*)CompressedOops::decode_raw(narrow_oop);
176   } else {
177     return *(void**)addr;
178   }
179 }
180 
181 oop oopDesc::obj_field_acquire(int offset) const                      { return HeapAccess<MO_ACQUIRE>::oop_load_at(as_oop(), offset); }
182 
183 void oopDesc::obj_field_put_raw(int offset, oop value)                { RawAccess<>::oop_store_at(as_oop(), offset, value); }
184 void oopDesc::release_obj_field_put(int offset, oop value)            { HeapAccess<MO_RELEASE>::oop_store_at(as_oop(), offset, value); }
185 void oopDesc::obj_field_put_volatile(int offset, oop value)           { HeapAccess<MO_SEQ_CST>::oop_store_at(as_oop(), offset, value); }
186 
187 address oopDesc::address_field(int offset) const                      { return *field_addr<address>(offset); }

 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 "runtime/synchronizer.hpp"
 41 #include "utilities/macros.hpp"
 42 
 43 void oopDesc::print_on(outputStream* st) const {
 44   if (*((juint*)this) == badHeapWordVal) {
 45     st->print("BAD WORD");
 46   } else if (*((juint*)this) == badMetaWordVal) {
 47     st->print("BAD META WORD");
 48   } else {
 49     klass()->oop_print_on(cast_to_oop(this), st);
 50   }
 51 }
 52 
 53 void oopDesc::print_address_on(outputStream* st) const {
 54   st->print("{" PTR_FORMAT "}", p2i(this));
 55 
 56 }
 57 
 58 void oopDesc::print()         { print_on(tty);         }

 97 void oopDesc::verify(oopDesc* oop_desc) {
 98   verify_on(tty, oop_desc);
 99 }
100 
101 intptr_t oopDesc::slow_identity_hash() {
102   // slow case; we have to acquire the micro lock in order to locate the header
103   Thread* current = Thread::current();
104   return ObjectSynchronizer::FastHashCode(current, this);
105 }
106 
107 // used only for asserts and guarantees
108 bool oopDesc::is_oop(oop obj, bool ignore_mark_word) {
109   if (!Universe::heap()->is_oop(obj)) {
110     return false;
111   }
112 
113   // Header verification: the mark is typically non-zero. If we're
114   // at a safepoint, it must not be zero.
115   // Outside of a safepoint, the header could be changing (for example,
116   // another thread could be inflating a lock on this object).
117   if (ignore_mark_word || UseFastLocking) {
118     return true;
119   }
120   if (obj->mark().value() != 0) {
121     return true;
122   }
123   return !SafepointSynchronize::is_at_safepoint();
124 }
125 
126 // used only for asserts and guarantees
127 bool oopDesc::is_oop_or_null(oop obj, bool ignore_mark_word) {
128   return obj == NULL ? true : is_oop(obj, ignore_mark_word);
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: " PTR_FORMAT, p2i(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 void* oopDesc::load_klass_raw(oop obj) {
150   // TODO: Remove method altogether and replace with calls to obj->klass() ?
151   // OTOH, we may eventually get rid of locking in header, and then no
152   // longer have to deal with that anymore.
153 #ifdef _LP64
154   return obj->klass();
155 #else
156   return obj->_klass;
157 #endif
158 }
159 
160 void* oopDesc::load_oop_raw(oop obj, int offset) {
161   uintptr_t addr = (uintptr_t)(void*)obj + (uint)offset;
162   if (UseCompressedOops) {
163     narrowOop narrow_oop = *(narrowOop*)addr;
164     if (CompressedOops::is_null(narrow_oop)) return NULL;
165     return (void*)CompressedOops::decode_raw(narrow_oop);
166   } else {
167     return *(void**)addr;
168   }
169 }
170 
171 oop oopDesc::obj_field_acquire(int offset) const                      { return HeapAccess<MO_ACQUIRE>::oop_load_at(as_oop(), offset); }
172 
173 void oopDesc::obj_field_put_raw(int offset, oop value)                { RawAccess<>::oop_store_at(as_oop(), offset, value); }
174 void oopDesc::release_obj_field_put(int offset, oop value)            { HeapAccess<MO_RELEASE>::oop_store_at(as_oop(), offset, value); }
175 void oopDesc::obj_field_put_volatile(int offset, oop value)           { HeapAccess<MO_SEQ_CST>::oop_store_at(as_oop(), offset, value); }
176 
177 address oopDesc::address_field(int offset) const                      { return *field_addr<address>(offset); }
< prev index next >