< prev index next >

src/hotspot/share/runtime/objectMonitor.inline.hpp

Print this page

 12  * version 2 for more details (a copy is included in the LICENSE file that
 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 #ifndef SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
 26 #define SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
 27 
 28 #include "runtime/objectMonitor.hpp"
 29 
 30 #include "logging/log.hpp"
 31 #include "oops/access.inline.hpp"

 32 #include "runtime/atomic.hpp"

 33 #include "runtime/lockStack.inline.hpp"
 34 #include "runtime/synchronizer.hpp"


 35 
 36 inline bool ObjectMonitor::is_entered(JavaThread* current) const {
 37   if (LockingMode == LM_LIGHTWEIGHT) {
 38     if (is_owner_anonymous()) {
 39       return current->lock_stack().contains(object());
 40     } else {
 41       return current == owner_raw();
 42     }
 43   } else {
 44     void* owner = owner_raw();
 45     if (current == owner || current->is_lock_owned((address)owner)) {
 46       return true;
 47     }
 48   }
 49   return false;
 50 }
 51 
 52 inline markWord ObjectMonitor::header() const {
 53   return Atomic::load(&_header);




 54 }
 55 
 56 inline volatile markWord* ObjectMonitor::header_addr() {
 57   return &_header;







 58 }
 59 
 60 inline void ObjectMonitor::set_header(markWord hdr) {
 61   Atomic::store(&_header, hdr);











 62 }
 63 
 64 inline int ObjectMonitor::waiters() const {
 65   return _waiters;
 66 }
 67 
 68 inline bool ObjectMonitor::has_owner() const {
 69   void* owner = owner_raw();
 70   return owner != nullptr && owner != DEFLATER_MARKER;
 71 }
 72 
 73 // Returns null if DEFLATER_MARKER is observed.
 74 inline void* ObjectMonitor::owner() const {
 75   void* owner = owner_raw();
 76   return owner != DEFLATER_MARKER ? owner : nullptr;
 77 }
 78 
 79 inline void* ObjectMonitor::owner_raw() const {
 80   return Atomic::load(&_owner);
 81 }

163                                        ", new=" INTPTR_FORMAT, p2i(this),
164                                        p2i(prev), p2i(new_value));
165   }
166   return prev;
167 }
168 
169 // The _next_om field can be concurrently read and modified so we
170 // use Atomic operations to disable compiler optimizations that
171 // might try to elide loading and/or storing this field.
172 
173 // Simply get _next_om field.
174 inline ObjectMonitor* ObjectMonitor::next_om() const {
175   return Atomic::load(&_next_om);
176 }
177 
178 // Simply set _next_om field to new_value.
179 inline void ObjectMonitor::set_next_om(ObjectMonitor* new_value) {
180   Atomic::store(&_next_om, new_value);
181 }
182 































183 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP

 12  * version 2 for more details (a copy is included in the LICENSE file that
 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 #ifndef SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
 26 #define SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
 27 
 28 #include "runtime/objectMonitor.hpp"
 29 
 30 #include "logging/log.hpp"
 31 #include "oops/access.inline.hpp"
 32 #include "oops/markWord.hpp"
 33 #include "runtime/atomic.hpp"
 34 #include "runtime/globals.hpp"
 35 #include "runtime/lockStack.inline.hpp"
 36 #include "runtime/synchronizer.hpp"
 37 #include "utilities/checkedCast.hpp"
 38 #include "utilities/globalDefinitions.hpp"
 39 
 40 inline bool ObjectMonitor::is_entered(JavaThread* current) const {
 41   if (LockingMode == LM_LIGHTWEIGHT) {
 42     if (is_owner_anonymous()) {
 43       return current->lock_stack().contains(object());
 44     } else {
 45       return current == owner_raw();
 46     }
 47   } else {
 48     void* owner = owner_raw();
 49     if (current == owner || current->is_lock_owned((address)owner)) {
 50       return true;
 51     }
 52   }
 53   return false;
 54 }
 55 
 56 inline uintptr_t ObjectMonitor::metadata() const {
 57   return Atomic::load(&_metadata);
 58 }
 59 
 60 inline void ObjectMonitor::set_metadata(uintptr_t value) {
 61   Atomic::store(&_metadata, value);
 62 }
 63 
 64 inline volatile uintptr_t* ObjectMonitor::metadata_addr() {
 65   STATIC_ASSERT(std::is_standard_layout<ObjectMonitor>::value);
 66   STATIC_ASSERT(offsetof(ObjectMonitor, _metadata) == 0);
 67   return &_metadata;
 68 }
 69 
 70 inline markWord ObjectMonitor::header() const {
 71   assert(!UseObjectMonitorTable, "Lightweight locking with OM table does not use header");
 72   return markWord(metadata());
 73 }
 74 
 75 inline void ObjectMonitor::set_header(markWord hdr) {
 76   assert(!UseObjectMonitorTable, "Lightweight locking with OM table does not use header");
 77   set_metadata(hdr.value());
 78 }
 79 
 80 inline intptr_t ObjectMonitor::hash() const {
 81   assert(UseObjectMonitorTable, "Only used by lightweight locking with OM table");
 82   return metadata();
 83 }
 84 
 85 inline void ObjectMonitor::set_hash(intptr_t hash) {
 86   assert(UseObjectMonitorTable, "Only used by lightweight locking with OM table");
 87   set_metadata(hash);
 88 }
 89 
 90 inline int ObjectMonitor::waiters() const {
 91   return _waiters;
 92 }
 93 
 94 inline bool ObjectMonitor::has_owner() const {
 95   void* owner = owner_raw();
 96   return owner != nullptr && owner != DEFLATER_MARKER;
 97 }
 98 
 99 // Returns null if DEFLATER_MARKER is observed.
100 inline void* ObjectMonitor::owner() const {
101   void* owner = owner_raw();
102   return owner != DEFLATER_MARKER ? owner : nullptr;
103 }
104 
105 inline void* ObjectMonitor::owner_raw() const {
106   return Atomic::load(&_owner);
107 }

189                                        ", new=" INTPTR_FORMAT, p2i(this),
190                                        p2i(prev), p2i(new_value));
191   }
192   return prev;
193 }
194 
195 // The _next_om field can be concurrently read and modified so we
196 // use Atomic operations to disable compiler optimizations that
197 // might try to elide loading and/or storing this field.
198 
199 // Simply get _next_om field.
200 inline ObjectMonitor* ObjectMonitor::next_om() const {
201   return Atomic::load(&_next_om);
202 }
203 
204 // Simply set _next_om field to new_value.
205 inline void ObjectMonitor::set_next_om(ObjectMonitor* new_value) {
206   Atomic::store(&_next_om, new_value);
207 }
208 
209 inline ObjectMonitorContentionMark::ObjectMonitorContentionMark(ObjectMonitor* monitor)
210   : _monitor(monitor) {
211   _monitor->add_to_contentions(1);
212 }
213 
214 inline ObjectMonitorContentionMark::~ObjectMonitorContentionMark() {
215   _monitor->add_to_contentions(-1);
216 }
217 
218 inline oop ObjectMonitor::object_peek() const {
219   if (_object.is_null()) {
220     return nullptr;
221   }
222   return _object.peek();
223 }
224 
225 inline bool ObjectMonitor::object_is_dead() const {
226   return object_peek() == nullptr;
227 }
228 
229 inline bool ObjectMonitor::object_is_cleared() const {
230   return _object.is_null();
231 }
232 
233 inline bool ObjectMonitor::object_refers_to(oop obj) const {
234   if (_object.is_null()) {
235     return false;
236   }
237   return _object.peek() == obj;
238 }
239 
240 #endif // SHARE_RUNTIME_OBJECTMONITOR_INLINE_HPP
< prev index next >