8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Kim Barrett <kim.barrett@oracle.com>
Co-authored-by: Nils Eliasson <nils.eliasson@oracle.com>
Co-authored-by: Rickard Backman <rickard.backman@oracle.com>
Co-authored-by: Roland Westrelin <rwestrel@redhat.com>
Co-authored-by: Coleen Phillimore <coleen.phillimore@oracle.com>
Co-authored-by: Robbin Ehn <robbin.ehn@oracle.com>
Co-authored-by: Gerard Ziemski <gerard.ziemski@oracle.com>
Co-authored-by: Hugh Wilkinson <hugh.wilkinson@intel.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Co-authored-by: Bill Wheeler <bill.npo.wheeler@intel.com>
Co-authored-by: Vinay K. Awasthi <vinay.k.awasthi@intel.com>
Co-authored-by: Yasumasa Suenaga <yasuenag@gmail.com>
Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke
2018-06-12 17:40:28 +02:00
|
|
|
/*
|
2019-04-25 10:56:31 -04:00
|
|
|
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Kim Barrett <kim.barrett@oracle.com>
Co-authored-by: Nils Eliasson <nils.eliasson@oracle.com>
Co-authored-by: Rickard Backman <rickard.backman@oracle.com>
Co-authored-by: Roland Westrelin <rwestrel@redhat.com>
Co-authored-by: Coleen Phillimore <coleen.phillimore@oracle.com>
Co-authored-by: Robbin Ehn <robbin.ehn@oracle.com>
Co-authored-by: Gerard Ziemski <gerard.ziemski@oracle.com>
Co-authored-by: Hugh Wilkinson <hugh.wilkinson@intel.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Co-authored-by: Bill Wheeler <bill.npo.wheeler@intel.com>
Co-authored-by: Vinay K. Awasthi <vinay.k.awasthi@intel.com>
Co-authored-by: Yasumasa Suenaga <yasuenag@gmail.com>
Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke
2018-06-12 17:40:28 +02:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SHARE_GC_Z_ZMESSAGEPORT_INLINE_HPP
|
|
|
|
#define SHARE_GC_Z_ZMESSAGEPORT_INLINE_HPP
|
|
|
|
|
|
|
|
#include "gc/z/zMessagePort.hpp"
|
|
|
|
#include "gc/z/zFuture.inline.hpp"
|
|
|
|
#include "gc/z/zList.inline.hpp"
|
|
|
|
#include "runtime/mutexLocker.hpp"
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class ZMessageRequest : public StackObj {
|
|
|
|
friend class ZList<ZMessageRequest>;
|
|
|
|
|
|
|
|
private:
|
|
|
|
T _message;
|
|
|
|
uint64_t _seqnum;
|
|
|
|
ZFuture<T> _result;
|
|
|
|
ZListNode<ZMessageRequest> _node;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void initialize(T message, uint64_t seqnum) {
|
|
|
|
_message = message;
|
|
|
|
_seqnum = seqnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
T message() const {
|
|
|
|
return _message;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t seqnum() const {
|
|
|
|
return _seqnum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wait() {
|
|
|
|
const T message = _result.get();
|
|
|
|
assert(message == _message, "Message mismatch");
|
|
|
|
}
|
|
|
|
|
|
|
|
void satisfy(T message) {
|
|
|
|
_result.set(message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline ZMessagePort<T>::ZMessagePort() :
|
|
|
|
_monitor(Monitor::leaf,
|
|
|
|
"ZMessagePort",
|
|
|
|
Monitor::_allow_vm_block_flag,
|
|
|
|
Monitor::_safepoint_check_never),
|
|
|
|
_has_message(false),
|
|
|
|
_seqnum(0),
|
|
|
|
_queue() {}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void ZMessagePort<T>::send_sync(T message) {
|
|
|
|
Request request;
|
|
|
|
|
|
|
|
{
|
|
|
|
// Enqueue message
|
2019-04-25 10:56:31 -04:00
|
|
|
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
|
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Kim Barrett <kim.barrett@oracle.com>
Co-authored-by: Nils Eliasson <nils.eliasson@oracle.com>
Co-authored-by: Rickard Backman <rickard.backman@oracle.com>
Co-authored-by: Roland Westrelin <rwestrel@redhat.com>
Co-authored-by: Coleen Phillimore <coleen.phillimore@oracle.com>
Co-authored-by: Robbin Ehn <robbin.ehn@oracle.com>
Co-authored-by: Gerard Ziemski <gerard.ziemski@oracle.com>
Co-authored-by: Hugh Wilkinson <hugh.wilkinson@intel.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Co-authored-by: Bill Wheeler <bill.npo.wheeler@intel.com>
Co-authored-by: Vinay K. Awasthi <vinay.k.awasthi@intel.com>
Co-authored-by: Yasumasa Suenaga <yasuenag@gmail.com>
Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke
2018-06-12 17:40:28 +02:00
|
|
|
request.initialize(message, _seqnum);
|
|
|
|
_queue.insert_last(&request);
|
|
|
|
ml.notify();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for completion
|
|
|
|
request.wait();
|
2018-06-15 13:31:20 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
// Guard deletion of underlying semaphore. This is a workaround for a
|
|
|
|
// bug in sem_post() in glibc < 2.21, where it's not safe to destroy
|
|
|
|
// the semaphore immediately after returning from sem_wait(). The
|
|
|
|
// reason is that sem_post() can touch the semaphore after a waiting
|
|
|
|
// thread have returned from sem_wait(). To avoid this race we are
|
|
|
|
// forcing the waiting thread to acquire/release the lock held by the
|
|
|
|
// posting thread. https://sourceware.org/bugzilla/show_bug.cgi?id=12674
|
2019-04-25 10:56:31 -04:00
|
|
|
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
|
2018-06-15 13:31:20 +02:00
|
|
|
}
|
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Kim Barrett <kim.barrett@oracle.com>
Co-authored-by: Nils Eliasson <nils.eliasson@oracle.com>
Co-authored-by: Rickard Backman <rickard.backman@oracle.com>
Co-authored-by: Roland Westrelin <rwestrel@redhat.com>
Co-authored-by: Coleen Phillimore <coleen.phillimore@oracle.com>
Co-authored-by: Robbin Ehn <robbin.ehn@oracle.com>
Co-authored-by: Gerard Ziemski <gerard.ziemski@oracle.com>
Co-authored-by: Hugh Wilkinson <hugh.wilkinson@intel.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Co-authored-by: Bill Wheeler <bill.npo.wheeler@intel.com>
Co-authored-by: Vinay K. Awasthi <vinay.k.awasthi@intel.com>
Co-authored-by: Yasumasa Suenaga <yasuenag@gmail.com>
Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke
2018-06-12 17:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void ZMessagePort<T>::send_async(T message) {
|
2019-04-25 10:56:31 -04:00
|
|
|
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
|
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Kim Barrett <kim.barrett@oracle.com>
Co-authored-by: Nils Eliasson <nils.eliasson@oracle.com>
Co-authored-by: Rickard Backman <rickard.backman@oracle.com>
Co-authored-by: Roland Westrelin <rwestrel@redhat.com>
Co-authored-by: Coleen Phillimore <coleen.phillimore@oracle.com>
Co-authored-by: Robbin Ehn <robbin.ehn@oracle.com>
Co-authored-by: Gerard Ziemski <gerard.ziemski@oracle.com>
Co-authored-by: Hugh Wilkinson <hugh.wilkinson@intel.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Co-authored-by: Bill Wheeler <bill.npo.wheeler@intel.com>
Co-authored-by: Vinay K. Awasthi <vinay.k.awasthi@intel.com>
Co-authored-by: Yasumasa Suenaga <yasuenag@gmail.com>
Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke
2018-06-12 17:40:28 +02:00
|
|
|
if (!_has_message) {
|
|
|
|
// Post message
|
|
|
|
_message = message;
|
|
|
|
_has_message = true;
|
|
|
|
ml.notify();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline T ZMessagePort<T>::receive() {
|
2019-04-25 10:56:31 -04:00
|
|
|
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
|
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Kim Barrett <kim.barrett@oracle.com>
Co-authored-by: Nils Eliasson <nils.eliasson@oracle.com>
Co-authored-by: Rickard Backman <rickard.backman@oracle.com>
Co-authored-by: Roland Westrelin <rwestrel@redhat.com>
Co-authored-by: Coleen Phillimore <coleen.phillimore@oracle.com>
Co-authored-by: Robbin Ehn <robbin.ehn@oracle.com>
Co-authored-by: Gerard Ziemski <gerard.ziemski@oracle.com>
Co-authored-by: Hugh Wilkinson <hugh.wilkinson@intel.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Co-authored-by: Bill Wheeler <bill.npo.wheeler@intel.com>
Co-authored-by: Vinay K. Awasthi <vinay.k.awasthi@intel.com>
Co-authored-by: Yasumasa Suenaga <yasuenag@gmail.com>
Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke
2018-06-12 17:40:28 +02:00
|
|
|
|
|
|
|
// Wait for message
|
|
|
|
while (!_has_message && _queue.is_empty()) {
|
2019-04-25 10:56:31 -04:00
|
|
|
ml.wait();
|
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Kim Barrett <kim.barrett@oracle.com>
Co-authored-by: Nils Eliasson <nils.eliasson@oracle.com>
Co-authored-by: Rickard Backman <rickard.backman@oracle.com>
Co-authored-by: Roland Westrelin <rwestrel@redhat.com>
Co-authored-by: Coleen Phillimore <coleen.phillimore@oracle.com>
Co-authored-by: Robbin Ehn <robbin.ehn@oracle.com>
Co-authored-by: Gerard Ziemski <gerard.ziemski@oracle.com>
Co-authored-by: Hugh Wilkinson <hugh.wilkinson@intel.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Co-authored-by: Bill Wheeler <bill.npo.wheeler@intel.com>
Co-authored-by: Vinay K. Awasthi <vinay.k.awasthi@intel.com>
Co-authored-by: Yasumasa Suenaga <yasuenag@gmail.com>
Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke
2018-06-12 17:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Increment request sequence number
|
|
|
|
_seqnum++;
|
|
|
|
|
|
|
|
if (!_has_message) {
|
|
|
|
// Message available in the queue
|
|
|
|
_message = _queue.first()->message();
|
|
|
|
_has_message = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return _message;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
inline void ZMessagePort<T>::ack() {
|
2019-04-25 10:56:31 -04:00
|
|
|
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
|
8204210: Implementation: JEP 333: ZGC: A Scalable Low-Latency Garbage Collector (Experimental)
Co-authored-by: Stefan Karlsson <stefan.karlsson@oracle.com>
Co-authored-by: Erik Osterlund <erik.osterlund@oracle.com>
Co-authored-by: Mikael Gerdin <mikael.gerdin@oracle.com>
Co-authored-by: Kim Barrett <kim.barrett@oracle.com>
Co-authored-by: Nils Eliasson <nils.eliasson@oracle.com>
Co-authored-by: Rickard Backman <rickard.backman@oracle.com>
Co-authored-by: Roland Westrelin <rwestrel@redhat.com>
Co-authored-by: Coleen Phillimore <coleen.phillimore@oracle.com>
Co-authored-by: Robbin Ehn <robbin.ehn@oracle.com>
Co-authored-by: Gerard Ziemski <gerard.ziemski@oracle.com>
Co-authored-by: Hugh Wilkinson <hugh.wilkinson@intel.com>
Co-authored-by: Sandhya Viswanathan <sandhya.viswanathan@intel.com>
Co-authored-by: Bill Wheeler <bill.npo.wheeler@intel.com>
Co-authored-by: Vinay K. Awasthi <vinay.k.awasthi@intel.com>
Co-authored-by: Yasumasa Suenaga <yasuenag@gmail.com>
Reviewed-by: pliden, stefank, eosterlund, ehelin, sjohanss, rbackman, coleenp, ihse, jgeorge, lmesnik, rkennke
2018-06-12 17:40:28 +02:00
|
|
|
|
|
|
|
if (!_has_message) {
|
|
|
|
// Nothing to ack
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Satisfy requests (and duplicates) in queue
|
|
|
|
ZListIterator<Request> iter(&_queue);
|
|
|
|
for (Request* request; iter.next(&request);) {
|
|
|
|
if (request->message() == _message && request->seqnum() < _seqnum) {
|
|
|
|
// Dequeue and satisfy request. Note that the dequeue operation must
|
|
|
|
// happen first, since the request will immediately be deallocated
|
|
|
|
// once it has been satisfied.
|
|
|
|
_queue.remove(request);
|
|
|
|
request->satisfy(_message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_queue.is_empty()) {
|
|
|
|
// Queue is empty
|
|
|
|
_has_message = false;
|
|
|
|
} else {
|
|
|
|
// Post first message in queue
|
|
|
|
_message = _queue.first()->message();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void ZRendezvousPort::signal() {
|
|
|
|
_port.send_sync(true /* ignored */);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void ZRendezvousPort::wait() {
|
|
|
|
_port.receive();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void ZRendezvousPort::ack() {
|
|
|
|
_port.ack();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SHARE_GC_Z_ZMESSAGEPORT_INLINE_HPP
|