21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "cds/cdsConfig.hpp"
27 #include "classfile/altHashing.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "gc/shared/collectedHeap.inline.hpp"
30 #include "gc/shared/gc_globals.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "memory/universe.hpp"
33 #include "oops/access.inline.hpp"
34 #include "oops/compressedKlass.inline.hpp"
35 #include "oops/compressedOops.inline.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "oops/verifyOopClosure.hpp"
38 #include "runtime/handles.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_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 // used only for asserts and guarantees
133 bool oopDesc::is_oop_or_null(oop obj, bool ignore_mark_word) {
134 return obj == nullptr ? true : is_oop(obj, ignore_mark_word);
135 }
136
137 VerifyOopClosure VerifyOopClosure::verify_oop;
138
139 template <class T> void VerifyOopClosure::do_oop_work(T* p) {
140 oop obj = RawAccess<>::oop_load(p);
141 guarantee(oopDesc::is_oop_or_null(obj), "invalid oop: " PTR_FORMAT, p2i(obj));
142 }
143
144 void VerifyOopClosure::do_oop(oop* p) { VerifyOopClosure::do_oop_work(p); }
145 void VerifyOopClosure::do_oop(narrowOop* p) { VerifyOopClosure::do_oop_work(p); }
146
147 // type test operations that doesn't require inclusion of oop.inline.hpp.
148 bool oopDesc::is_instance_noinline() const { return is_instance(); }
149 bool oopDesc::is_instanceRef_noinline() const { return is_instanceRef(); }
150 bool oopDesc::is_stackChunk_noinline() const { return is_stackChunk(); }
151 bool oopDesc::is_array_noinline() const { return is_array(); }
|
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "cds/cdsConfig.hpp"
27 #include "classfile/altHashing.hpp"
28 #include "classfile/javaClasses.inline.hpp"
29 #include "gc/shared/collectedHeap.inline.hpp"
30 #include "gc/shared/gc_globals.hpp"
31 #include "memory/resourceArea.hpp"
32 #include "memory/universe.hpp"
33 #include "oops/access.inline.hpp"
34 #include "oops/compressedKlass.inline.hpp"
35 #include "oops/compressedOops.inline.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "oops/verifyOopClosure.hpp"
38 #include "runtime/handles.inline.hpp"
39 #include "runtime/javaThread.hpp"
40 #include "runtime/synchronizer.hpp"
41 #include "runtime/lightweightSynchronizer.hpp"
42 #include "utilities/macros.hpp"
43
44 void oopDesc::print_on(outputStream* st) const {
45 if (*((juint*)this) == badHeapWordVal) {
46 st->print_cr("BAD 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("{" PTR_FORMAT "}", p2i(this));
54
55 }
56
57 void oopDesc::print_name_on(outputStream* st) const {
58 if (*((juint*)this) == badHeapWordVal) {
59 st->print_cr("BAD WORD");
60 } else {
61 st->print_cr("%s", klass()->external_name());
113
114 // used only for asserts and guarantees
115 bool oopDesc::is_oop(oop obj, bool ignore_mark_word) {
116 if (!Universe::heap()->is_oop(obj)) {
117 return false;
118 }
119
120 // Header verification: the mark is typically non-zero. If we're
121 // at a safepoint, it must not be zero, except when using the new lightweight locking.
122 // Outside of a safepoint, the header could be changing (for example,
123 // another thread could be inflating a lock on this object).
124 if (ignore_mark_word) {
125 return true;
126 }
127 if (obj->mark().value() != 0) {
128 return true;
129 }
130 return LockingMode == LM_LIGHTWEIGHT || !SafepointSynchronize::is_at_safepoint();
131 }
132
133 void oopDesc::initialize_hash_if_necessary(oop obj, Klass* k, markWord m) {
134 assert(UseCompactObjectHeaders, "only with compact object headers");
135 assert(!m.has_displaced_mark_helper(), "must not be displaced header");
136 assert(m.is_hashed_not_expanded(), "must be hashed but not moved");
137 assert(!m.is_hashed_expanded(), "must not be moved: " INTPTR_FORMAT, m.value());
138 uint32_t hash = static_cast<uint32_t>(ObjectSynchronizer::get_next_hash(nullptr, obj));
139 int offset = k->hash_offset_in_bytes(cast_to_oop(this));
140 assert(offset >= 4, "hash offset must not be in header");
141 #ifndef PRODUCT
142 log_trace(ihash)("Initializing hash for " PTR_FORMAT ", old: " PTR_FORMAT ", hash: %d, offset: %d", p2i(this), p2i(obj), hash, offset);
143 #endif
144 int_field_put(offset, (jint) hash);
145 m = m.set_hashed_expanded();
146 assert(static_cast<uint32_t>(LightweightSynchronizer::get_hash(m, cast_to_oop(this), k)) == hash,
147 "hash must remain the same");
148 assert(m.narrow_klass() != 0, "must not be null");
149 set_mark(m);
150 }
151
152 // used only for asserts and guarantees
153 bool oopDesc::is_oop_or_null(oop obj, bool ignore_mark_word) {
154 return obj == nullptr ? true : is_oop(obj, ignore_mark_word);
155 }
156
157 VerifyOopClosure VerifyOopClosure::verify_oop;
158
159 template <class T> void VerifyOopClosure::do_oop_work(T* p) {
160 oop obj = RawAccess<>::oop_load(p);
161 guarantee(oopDesc::is_oop_or_null(obj), "invalid oop: " PTR_FORMAT, p2i(obj));
162 }
163
164 void VerifyOopClosure::do_oop(oop* p) { VerifyOopClosure::do_oop_work(p); }
165 void VerifyOopClosure::do_oop(narrowOop* p) { VerifyOopClosure::do_oop_work(p); }
166
167 // type test operations that doesn't require inclusion of oop.inline.hpp.
168 bool oopDesc::is_instance_noinline() const { return is_instance(); }
169 bool oopDesc::is_instanceRef_noinline() const { return is_instanceRef(); }
170 bool oopDesc::is_stackChunk_noinline() const { return is_stackChunk(); }
171 bool oopDesc::is_array_noinline() const { return is_array(); }
|