< prev index next >

src/hotspot/share/oops/oop.cpp

Print this page

 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "cds/cdsConfig.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/javaThread.hpp"
 39 #include "runtime/synchronizer.hpp"

 40 #include "utilities/macros.hpp"
 41 
 42 void oopDesc::print_on(outputStream* st) const {
 43   if (*((juint*)this) == badHeapWordVal) {
 44     st->print_cr("BAD 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("{" PTR_FORMAT "}", p2i(this));
 52 
 53 }
 54 
 55 void oopDesc::print_name_on(outputStream* st) const {
 56   if (*((juint*)this) == badHeapWordVal) {
 57     st->print_cr("BAD WORD");
 58   } else {
 59     st->print_cr("%s", klass()->external_name());

111 
112 // used only for asserts and guarantees
113 bool oopDesc::is_oop(oop obj, bool ignore_mark_word) {
114   if (!Universe::heap()->is_oop(obj)) {
115     return false;
116   }
117 
118   // Header verification: the mark is typically non-zero. If we're
119   // at a safepoint, it must not be zero, except when using the new lightweight locking.
120   // Outside of a safepoint, the header could be changing (for example,
121   // another thread could be inflating a lock on this object).
122   if (ignore_mark_word) {
123     return true;
124   }
125   if (obj->mark().value() != 0) {
126     return true;
127   }
128   return LockingMode == LM_LIGHTWEIGHT || !SafepointSynchronize::is_at_safepoint();
129 }
130 



















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

 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "cds/cdsConfig.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/javaThread.hpp"
 39 #include "runtime/synchronizer.hpp"
 40 #include "runtime/lightweightSynchronizer.hpp"
 41 #include "utilities/macros.hpp"
 42 
 43 void oopDesc::print_on(outputStream* st) const {
 44   if (*((juint*)this) == badHeapWordVal) {
 45     st->print_cr("BAD 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_name_on(outputStream* st) const {
 57   if (*((juint*)this) == badHeapWordVal) {
 58     st->print_cr("BAD WORD");
 59   } else {
 60     st->print_cr("%s", klass()->external_name());

112 
113 // used only for asserts and guarantees
114 bool oopDesc::is_oop(oop obj, bool ignore_mark_word) {
115   if (!Universe::heap()->is_oop(obj)) {
116     return false;
117   }
118 
119   // Header verification: the mark is typically non-zero. If we're
120   // at a safepoint, it must not be zero, except when using the new lightweight locking.
121   // Outside of a safepoint, the header could be changing (for example,
122   // another thread could be inflating a lock on this object).
123   if (ignore_mark_word) {
124     return true;
125   }
126   if (obj->mark().value() != 0) {
127     return true;
128   }
129   return LockingMode == LM_LIGHTWEIGHT || !SafepointSynchronize::is_at_safepoint();
130 }
131 
132 void oopDesc::initialize_hash_if_necessary(oop obj, Klass* k, markWord m) {
133   assert(UseCompactObjectHeaders, "only with compact object headers");
134   assert(!m.has_displaced_mark_helper(), "must not be displaced header");
135   assert(m.is_hashed_not_expanded(), "must be hashed but not moved");
136   assert(!m.is_hashed_expanded(), "must not be moved: " INTPTR_FORMAT, m.value());
137   uint32_t hash = static_cast<uint32_t>(ObjectSynchronizer::get_next_hash(nullptr, obj));
138   int offset = k->hash_offset_in_bytes(cast_to_oop(this));
139   assert(offset >= 4, "hash offset must not be in header");
140 #ifndef PRODUCT
141   log_trace(ihash)("Initializing hash for " PTR_FORMAT ", old: " PTR_FORMAT ", hash: %d, offset: %d", p2i(this), p2i(obj), hash, offset);
142 #endif
143   int_field_put(offset, (jint) hash);
144   m = m.set_hashed_expanded();
145   assert(static_cast<uint32_t>(LightweightSynchronizer::get_hash(m, cast_to_oop(this), k)) == hash,
146          "hash must remain the same");
147   assert(m.narrow_klass() != 0, "must not be null");
148   set_mark(m);
149 }
150 
151 // used only for asserts and guarantees
152 bool oopDesc::is_oop_or_null(oop obj, bool ignore_mark_word) {
153   return obj == nullptr ? true : is_oop(obj, ignore_mark_word);
154 }
155 
156 VerifyOopClosure VerifyOopClosure::verify_oop;
157 
158 template <class T> void VerifyOopClosure::do_oop_work(T* p) {
159   oop obj = RawAccess<>::oop_load(p);
160   guarantee(oopDesc::is_oop_or_null(obj), "invalid oop: " PTR_FORMAT, p2i(obj));
161 }
162 
163 void VerifyOopClosure::do_oop(oop* p)       { VerifyOopClosure::do_oop_work(p); }
164 void VerifyOopClosure::do_oop(narrowOop* p) { VerifyOopClosure::do_oop_work(p); }
165 
166 // type test operations that doesn't require inclusion of oop.inline.hpp.
167 bool oopDesc::is_instance_noinline()    const { return is_instance();    }
168 bool oopDesc::is_instanceRef_noinline() const { return is_instanceRef(); }
169 bool oopDesc::is_stackChunk_noinline()  const { return is_stackChunk();  }
170 bool oopDesc::is_array_noinline()       const { return is_array();       }
< prev index next >