author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58557 | cf3205fdb6dc |
permissions | -rw-r--r-- |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
1 |
/* |
58122
48d51def09f9
8230845: ZGC: Implement ZLock using os::PlatformMutex
pliden
parents:
52653
diff
changeset
|
2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
4 |
* |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
8 |
* |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
13 |
* accompanied this code). |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
14 |
* |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
18 |
* |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
21 |
* questions. |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
22 |
*/ |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
23 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
24 |
#ifndef SHARE_GC_Z_ZLOCK_INLINE_HPP |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
25 |
#define SHARE_GC_Z_ZLOCK_INLINE_HPP |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
26 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
27 |
#include "gc/z/zLock.hpp" |
52653 | 28 |
#include "runtime/atomic.hpp" |
58122
48d51def09f9
8230845: ZGC: Implement ZLock using os::PlatformMutex
pliden
parents:
52653
diff
changeset
|
29 |
#include "runtime/os.inline.hpp" |
52653 | 30 |
#include "runtime/thread.hpp" |
31 |
#include "utilities/debug.hpp" |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
32 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
33 |
inline void ZLock::lock() { |
58122
48d51def09f9
8230845: ZGC: Implement ZLock using os::PlatformMutex
pliden
parents:
52653
diff
changeset
|
34 |
_lock.lock(); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
35 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
36 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
37 |
inline bool ZLock::try_lock() { |
58122
48d51def09f9
8230845: ZGC: Implement ZLock using os::PlatformMutex
pliden
parents:
52653
diff
changeset
|
38 |
return _lock.try_lock(); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
39 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
40 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
41 |
inline void ZLock::unlock() { |
58122
48d51def09f9
8230845: ZGC: Implement ZLock using os::PlatformMutex
pliden
parents:
52653
diff
changeset
|
42 |
_lock.unlock(); |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
43 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
44 |
|
52653 | 45 |
inline ZReentrantLock::ZReentrantLock() : |
46 |
_lock(), |
|
47 |
_owner(NULL), |
|
48 |
_count(0) {} |
|
49 |
||
50 |
inline void ZReentrantLock::lock() { |
|
51 |
Thread* const thread = Thread::current(); |
|
52 |
Thread* const owner = Atomic::load(&_owner); |
|
53 |
||
54 |
if (owner != thread) { |
|
55 |
_lock.lock(); |
|
56 |
Atomic::store(thread, &_owner); |
|
57 |
} |
|
58 |
||
59 |
_count++; |
|
60 |
} |
|
61 |
||
62 |
inline void ZReentrantLock::unlock() { |
|
63 |
assert(is_owned(), "Invalid owner"); |
|
64 |
assert(_count > 0, "Invalid count"); |
|
65 |
||
66 |
_count--; |
|
67 |
||
68 |
if (_count == 0) { |
|
69 |
Atomic::store((Thread*)NULL, &_owner); |
|
70 |
_lock.unlock(); |
|
71 |
} |
|
72 |
} |
|
73 |
||
74 |
inline bool ZReentrantLock::is_owned() const { |
|
75 |
Thread* const thread = Thread::current(); |
|
76 |
Thread* const owner = Atomic::load(&_owner); |
|
77 |
return owner == thread; |
|
78 |
} |
|
79 |
||
80 |
template <typename T> |
|
81 |
inline ZLocker<T>::ZLocker(T* lock) : |
|
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
82 |
_lock(lock) { |
58557
cf3205fdb6dc
8232116: ZGC: Remove redundant ZLock in ZNMethodTable
eosterlund
parents:
58122
diff
changeset
|
83 |
if (_lock != NULL) { |
cf3205fdb6dc
8232116: ZGC: Remove redundant ZLock in ZNMethodTable
eosterlund
parents:
58122
diff
changeset
|
84 |
_lock->lock(); |
cf3205fdb6dc
8232116: ZGC: Remove redundant ZLock in ZNMethodTable
eosterlund
parents:
58122
diff
changeset
|
85 |
} |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
86 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
87 |
|
52653 | 88 |
template <typename T> |
89 |
inline ZLocker<T>::~ZLocker() { |
|
58557
cf3205fdb6dc
8232116: ZGC: Remove redundant ZLock in ZNMethodTable
eosterlund
parents:
58122
diff
changeset
|
90 |
if (_lock != NULL) { |
cf3205fdb6dc
8232116: ZGC: Remove redundant ZLock in ZNMethodTable
eosterlund
parents:
58122
diff
changeset
|
91 |
_lock->unlock(); |
cf3205fdb6dc
8232116: ZGC: Remove redundant ZLock in ZNMethodTable
eosterlund
parents:
58122
diff
changeset
|
92 |
} |
50525
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
93 |
} |
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
94 |
|
767cdb97f103
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
pliden
parents:
diff
changeset
|
95 |
#endif // SHARE_GC_Z_ZLOCK_INLINE_HPP |