equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
79 // See orderAccess.hpp. We assume throughout the VM that mutex lock and |
79 // See orderAccess.hpp. We assume throughout the VM that mutex lock and |
80 // try_lock do fence-lock-acquire, and that unlock does a release-unlock, |
80 // try_lock do fence-lock-acquire, and that unlock does a release-unlock, |
81 // *in that order*. If their implementations change such that these |
81 // *in that order*. If their implementations change such that these |
82 // assumptions are violated, a whole lot of code will break. |
82 // assumptions are violated, a whole lot of code will break. |
83 |
83 |
84 // The default length of monitor name is chosen to be 64 to avoid false sharing. |
84 // The default length of monitor name was originally chosen to be 64 to avoid |
|
85 // false sharing. Now, PaddedMonitor is available for this purpose. |
|
86 // TODO: Check if _name[MONITOR_NAME_LEN] should better get replaced by const char*. |
85 static const int MONITOR_NAME_LEN = 64; |
87 static const int MONITOR_NAME_LEN = 64; |
86 |
88 |
87 class Monitor : public CHeapObj<mtInternal> { |
89 class Monitor : public CHeapObj<mtInternal> { |
88 |
90 |
89 public: |
91 public: |
252 #endif |
254 #endif |
253 } |
255 } |
254 |
256 |
255 }; |
257 }; |
256 |
258 |
|
259 class PaddedMonitor : public Monitor { |
|
260 enum { |
|
261 CACHE_LINE_PADDING = (int)DEFAULT_CACHE_LINE_SIZE - (int)sizeof(Monitor), |
|
262 PADDING_LEN = CACHE_LINE_PADDING > 0 ? CACHE_LINE_PADDING : 1 |
|
263 }; |
|
264 char _padding[PADDING_LEN]; |
|
265 public: |
|
266 PaddedMonitor(int rank, const char *name, bool allow_vm_block = false, |
|
267 SafepointCheckRequired safepoint_check_required = _safepoint_check_always) : |
|
268 Monitor(rank, name, allow_vm_block, safepoint_check_required) {}; |
|
269 }; |
|
270 |
257 // Normally we'd expect Monitor to extend Mutex in the sense that a monitor |
271 // Normally we'd expect Monitor to extend Mutex in the sense that a monitor |
258 // constructed from pthreads primitives might extend a mutex by adding |
272 // constructed from pthreads primitives might extend a mutex by adding |
259 // a condvar and some extra metadata. In fact this was the case until J2SE7. |
273 // a condvar and some extra metadata. In fact this was the case until J2SE7. |
260 // |
274 // |
261 // Currently, however, the base object is a monitor. Monitor contains all the |
275 // Currently, however, the base object is a monitor. Monitor contains all the |
290 ShouldNotReachHere() ; |
304 ShouldNotReachHere() ; |
291 return false ; |
305 return false ; |
292 } |
306 } |
293 }; |
307 }; |
294 |
308 |
|
309 class PaddedMutex : public Mutex { |
|
310 enum { |
|
311 CACHE_LINE_PADDING = (int)DEFAULT_CACHE_LINE_SIZE - (int)sizeof(Mutex), |
|
312 PADDING_LEN = CACHE_LINE_PADDING > 0 ? CACHE_LINE_PADDING : 1 |
|
313 }; |
|
314 char _padding[PADDING_LEN]; |
|
315 public: |
|
316 PaddedMutex(int rank, const char *name, bool allow_vm_block = false, |
|
317 SafepointCheckRequired safepoint_check_required = _safepoint_check_always) : |
|
318 Mutex(rank, name, allow_vm_block, safepoint_check_required) {}; |
|
319 }; |
295 |
320 |
296 #endif // SHARE_VM_RUNTIME_MUTEX_HPP |
321 #endif // SHARE_VM_RUNTIME_MUTEX_HPP |