1 /*
2 * Copyright (c) 2017, 2021, Red Hat, Inc. All rights reserved.
3 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26 #include "precompiled.hpp"
27
28 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
29 #include "gc/shenandoah/shenandoahThreadLocalData.hpp"
30 #include "gc/shenandoah/shenandoahWorkGroup.hpp"
31 #include "gc/shenandoah/shenandoahTaskqueue.hpp"
32
33 #include "logging/log.hpp"
34 #include "runtime/threads.hpp"
35
36 ShenandoahWorkerScope::ShenandoahWorkerScope(WorkerThreads* workers, uint nworkers, const char* msg, bool check) :
37 _workers(workers) {
38 assert(msg != nullptr, "Missing message");
39
40 _n_workers = _workers->set_active_workers(nworkers);
41 assert(_n_workers <= nworkers, "Must be");
42
43 log_info(gc, task)("Using %u of %u workers for %s",
44 _n_workers, ShenandoahHeap::heap()->max_workers(), msg);
45
46 if (check) {
47 ShenandoahHeap::heap()->assert_gc_workers(_n_workers);
48 }
49 }
50
51 ShenandoahWorkerScope::~ShenandoahWorkerScope() {
52 assert(_workers->active_workers() == _n_workers,
53 "Active workers can not be changed within this scope");
54 }
55
56 ShenandoahPushWorkerScope::ShenandoahPushWorkerScope(WorkerThreads* workers, uint nworkers, bool check) :
57 _old_workers(workers->active_workers()),
58 _workers(workers) {
59 _n_workers = _workers->set_active_workers(nworkers);
60 assert(_n_workers <= nworkers, "Must be");
61
62 // bypass concurrent/parallel protocol check for non-regular paths, e.g. verifier, etc.
63 if (check) {
64 ShenandoahHeap::heap()->assert_gc_workers(_n_workers);
65 }
66 }
67
68 ShenandoahPushWorkerScope::~ShenandoahPushWorkerScope() {
69 assert(_workers->active_workers() == _n_workers,
70 "Active workers can not be changed within this scope");
71 // Restore old worker value
72 uint nworkers = _workers->set_active_workers(_old_workers);
73 assert(nworkers == _old_workers, "Must be able to restore");
74 }
75
76 void ShenandoahWorkerThreads::on_create_worker(WorkerThread* worker) {
77 if (_initialize_gclab) {
78 ShenandoahThreadLocalData::initialize_gclab(worker);
79 }
80 }
--- EOF ---