< prev index next >

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

Print this page

 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  *
 25  */
 26 
 27 #ifndef SHARE_RUNTIME_LOCKSTACK_INLINE_HPP
 28 #define SHARE_RUNTIME_LOCKSTACK_INLINE_HPP
 29 
 30 #include "runtime/lockStack.hpp"
 31 
 32 #include "memory/iterator.hpp"
 33 #include "runtime/javaThread.hpp"


 34 #include "runtime/safepoint.hpp"
 35 #include "runtime/stackWatermark.hpp"
 36 #include "runtime/stackWatermarkSet.inline.hpp"
 37 #include "utilities/align.hpp"
 38 #include "utilities/globalDefinitions.hpp"
 39 
 40 inline int LockStack::to_index(uint32_t offset) {
 41   assert(is_aligned(offset, oopSize), "Bad alignment: %u", offset);
 42   assert((offset <= end_offset()), "lockstack overflow: offset %d end_offset %d", offset, end_offset());
 43   assert((offset >= start_offset()), "lockstack underflow: offset %d start_offset %d", offset, start_offset());
 44   return (offset - lock_stack_base_offset) / oopSize;
 45 }
 46 
 47 JavaThread* LockStack::get_thread() const {
 48   char* addr = reinterpret_cast<char*>(const_cast<LockStack*>(this));
 49   return reinterpret_cast<JavaThread*>(addr - lock_stack_offset);
 50 }
 51 
 52 inline bool LockStack::is_full() const {
 53   return to_index(_top) == CAPACITY;

205   int end = to_index(_top);
206   for (int i = end - 1; i >= 0; i--) {
207     if (_base[i] == o) {
208       verify("post-contains");
209       return true;
210     }
211   }
212   verify("post-contains");
213   return false;
214 }
215 
216 inline void LockStack::oops_do(OopClosure* cl) {
217   verify("pre-oops-do");
218   int end = to_index(_top);
219   for (int i = 0; i < end; i++) {
220     cl->do_oop(&_base[i]);
221   }
222   verify("post-oops-do");
223 }
224 


















































225 #endif // SHARE_RUNTIME_LOCKSTACK_INLINE_HPP

 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  *
 25  */
 26 
 27 #ifndef SHARE_RUNTIME_LOCKSTACK_INLINE_HPP
 28 #define SHARE_RUNTIME_LOCKSTACK_INLINE_HPP
 29 
 30 #include "runtime/lockStack.hpp"
 31 
 32 #include "memory/iterator.hpp"
 33 #include "runtime/javaThread.hpp"
 34 #include "runtime/lightweightSynchronizer.hpp"
 35 #include "runtime/objectMonitor.inline.hpp"
 36 #include "runtime/safepoint.hpp"
 37 #include "runtime/stackWatermark.hpp"
 38 #include "runtime/stackWatermarkSet.inline.hpp"
 39 #include "utilities/align.hpp"
 40 #include "utilities/globalDefinitions.hpp"
 41 
 42 inline int LockStack::to_index(uint32_t offset) {
 43   assert(is_aligned(offset, oopSize), "Bad alignment: %u", offset);
 44   assert((offset <= end_offset()), "lockstack overflow: offset %d end_offset %d", offset, end_offset());
 45   assert((offset >= start_offset()), "lockstack underflow: offset %d start_offset %d", offset, start_offset());
 46   return (offset - lock_stack_base_offset) / oopSize;
 47 }
 48 
 49 JavaThread* LockStack::get_thread() const {
 50   char* addr = reinterpret_cast<char*>(const_cast<LockStack*>(this));
 51   return reinterpret_cast<JavaThread*>(addr - lock_stack_offset);
 52 }
 53 
 54 inline bool LockStack::is_full() const {
 55   return to_index(_top) == CAPACITY;

207   int end = to_index(_top);
208   for (int i = end - 1; i >= 0; i--) {
209     if (_base[i] == o) {
210       verify("post-contains");
211       return true;
212     }
213   }
214   verify("post-contains");
215   return false;
216 }
217 
218 inline void LockStack::oops_do(OopClosure* cl) {
219   verify("pre-oops-do");
220   int end = to_index(_top);
221   for (int i = 0; i < end; i++) {
222     cl->do_oop(&_base[i]);
223   }
224   verify("post-oops-do");
225 }
226 
227 inline void OMCache::set_monitor(ObjectMonitor *monitor) {
228   const int end = OMCache::CAPACITY - 1;
229 
230   oop obj = monitor->object_peek();
231   assert(obj != nullptr, "must be alive");
232   assert(monitor == LightweightSynchronizer::get_monitor_from_table(JavaThread::current(), obj), "must be exist in table");
233 
234   OMCacheEntry to_insert = {obj, monitor};
235 
236   for (int i = 0; i < end; ++i) {
237     if (_entries[i]._oop == obj ||
238         _entries[i]._monitor == nullptr ||
239         _entries[i]._monitor->is_being_async_deflated()) {
240       // Use stale slot.
241       _entries[i] = to_insert;
242       return;
243     }
244     // Swap with the most recent value.
245     ::swap(to_insert, _entries[i]);
246   }
247   _entries[end] = to_insert;
248 }
249 
250 inline ObjectMonitor* OMCache::get_monitor(oop o) {
251   for (int i = 0; i < CAPACITY; ++i) {
252     if (_entries[i]._oop == o) {
253       assert(_entries[i]._monitor != nullptr, "monitor must exist");
254       if (_entries[i]._monitor->is_being_async_deflated()) {
255         // Bad monitor
256         // Shift down rest
257         for (; i < CAPACITY - 1; ++i) {
258           _entries[i] = _entries[i + 1];
259         }
260         // Clear end
261         _entries[i] = {};
262         return nullptr;
263       }
264       return _entries[i]._monitor;
265     }
266   }
267   return nullptr;
268 }
269 
270 inline void OMCache::clear() {
271   for (size_t i = 0 , r = 0; i < CAPACITY; ++i) {
272     // Clear
273     _entries[i] = {};
274   }
275 }
276 
277 #endif // SHARE_RUNTIME_LOCKSTACK_INLINE_HPP
< prev index next >