Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8257082: ZGC: Clean up ZRuntimeWorkers and ZWorkers
Reviewed-by: stefank
  • Loading branch information
pliden committed Nov 26, 2020
1 parent f6d6a07 commit 7946c94170553d7f5e045baac8a4a2734ac442f7
@@ -23,40 +23,34 @@

#include "precompiled.hpp"
#include "gc/shared/gcLogPrecious.hpp"
#include "gc/z/zLock.inline.hpp"
#include "gc/z/zRuntimeWorkers.hpp"
#include "gc/z/zTask.hpp"
#include "gc/z/zThread.hpp"
#include "runtime/java.hpp"
#include "runtime/mutex.hpp"
#include "runtime/mutexLocker.hpp"

class ZRuntimeWorkersInitializeTask : public AbstractGangTask {
private:
const uint _nworkers;
uint _started;
Monitor _monitor;
const uint _nworkers;
uint _started;
ZConditionLock _lock;

public:
ZRuntimeWorkersInitializeTask(uint nworkers) :
AbstractGangTask("ZRuntimeWorkersInitializeTask"),
_nworkers(nworkers),
_started(0),
_monitor(Monitor::leaf,
"ZRuntimeWorkersInitialize",
false /* allow_vm_block */,
Monitor::_safepoint_check_never) {}
_lock() {}

virtual void work(uint worker_id) {
// Register as runtime worker
ZThread::set_runtime_worker();

// Wait for all threads to start
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
ZLocker<ZConditionLock> locker(&_lock);
if (++_started == _nworkers) {
// All threads started
ml.notify_all();
_lock.notify_all();
} else {
while (_started != _nworkers) {
ml.wait();
_lock.wait();
}
}
}
@@ -77,9 +71,8 @@ ZRuntimeWorkers::ZRuntimeWorkers() :
vm_exit_during_initialization("Failed to create ZRuntimeWorkers");
}

// Execute task to register threads as runtime workers. This also
// helps reduce latency in early safepoints, which otherwise would
// have to take on any warmup costs.
// Execute task to reduce latency in early safepoints,
// which otherwise would have to take on any warmup costs.
ZRuntimeWorkersInitializeTask task(nworkers());
_workers.run_task(&task);
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -31,7 +31,6 @@ THREAD_LOCAL uintptr_t ZThread::_id;
THREAD_LOCAL bool ZThread::_is_vm;
THREAD_LOCAL bool ZThread::_is_java;
THREAD_LOCAL bool ZThread::_is_worker;
THREAD_LOCAL bool ZThread::_is_runtime_worker;
THREAD_LOCAL uint ZThread::_worker_id;

void ZThread::initialize() {
@@ -42,7 +41,6 @@ void ZThread::initialize() {
_is_vm = thread->is_VM_thread();
_is_java = thread->is_Java_thread();
_is_worker = false;
_is_runtime_worker = false;
_worker_id = (uint)-1;
}

@@ -63,11 +61,6 @@ void ZThread::set_worker() {
_is_worker = true;
}

void ZThread::set_runtime_worker() {
ensure_initialized();
_is_runtime_worker = true;
}

bool ZThread::has_worker_id() {
return _initialized &&
_is_worker &&
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -38,14 +38,12 @@ class ZThread : public AllStatic {
static THREAD_LOCAL bool _is_vm;
static THREAD_LOCAL bool _is_java;
static THREAD_LOCAL bool _is_worker;
static THREAD_LOCAL bool _is_runtime_worker;
static THREAD_LOCAL uint _worker_id;

static void initialize();
static void ensure_initialized();

static void set_worker();
static void set_runtime_worker();

static bool has_worker_id();
static void set_worker_id(uint worker_id);
@@ -57,7 +55,6 @@ class ZThread : public AllStatic {
static bool is_vm();
static bool is_java();
static bool is_worker();
static bool is_runtime_worker();
static uint worker_id();
};

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -53,11 +53,6 @@ inline bool ZThread::is_worker() {
return _is_worker;
}

inline bool ZThread::is_runtime_worker() {
ensure_initialized();
return _is_runtime_worker;
}

inline uint ZThread::worker_id() {
assert(has_worker_id(), "Worker id not initialized");
return _worker_id;
@@ -23,41 +23,37 @@

#include "precompiled.hpp"
#include "gc/shared/gcLogPrecious.hpp"
#include "gc/z/zLock.inline.hpp"
#include "gc/z/zTask.hpp"
#include "gc/z/zThread.hpp"
#include "gc/z/zWorkers.inline.hpp"
#include "runtime/java.hpp"
#include "runtime/mutex.hpp"
#include "runtime/mutexLocker.hpp"

class ZWorkersInitializeTask : public ZTask {
private:
const uint _nworkers;
uint _started;
Monitor _monitor;
const uint _nworkers;
uint _started;
ZConditionLock _lock;

public:
ZWorkersInitializeTask(uint nworkers) :
ZTask("ZWorkersInitializeTask"),
_nworkers(nworkers),
_started(0),
_monitor(Monitor::leaf,
"ZWorkersInitialize",
false /* allow_vm_block */,
Monitor::_safepoint_check_never) {}
_lock() {}

virtual void work() {
// Register as worker
ZThread::set_worker();

// Wait for all threads to start
MonitorLocker ml(&_monitor, Monitor::_no_safepoint_check_flag);
ZLocker<ZConditionLock> locker(&_lock);
if (++_started == _nworkers) {
// All threads started
ml.notify_all();
_lock.notify_all();
} else {
while (_started != _nworkers) {
ml.wait();
_lock.wait();
}
}
}
@@ -79,9 +75,7 @@ ZWorkers::ZWorkers() :
vm_exit_during_initialization("Failed to create ZWorkers");
}

// Execute task to register threads as workers. This also helps
// reduce latency in early GC pauses, which otherwise would have
// to take on any warmup costs.
// Execute task to register threads as workers
ZWorkersInitializeTask task(nworkers());
run(&task, nworkers());
}

0 comments on commit 7946c94

Please sign in to comment.