1 /*
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
72 _cr = cr;
73 _num_max_threads = num_max_threads;
74
75 _threads = NEW_C_HEAP_ARRAY_RETURN_NULL(G1ConcurrentRefineThread*, num_max_threads, mtGC);
76 if (_threads == NULL) {
77 vm_shutdown_during_initialization("Could not allocate thread holder array.");
78 return JNI_ENOMEM;
79 }
80
81 for (uint i = 0; i < num_max_threads; i++) {
82 if (UseDynamicNumberOfGCThreads && i != 0 /* Always start first thread. */) {
83 _threads[i] = NULL;
84 } else {
85 _threads[i] = create_refinement_thread(i, true);
86 if (_threads[i] == NULL) {
87 vm_shutdown_during_initialization("Could not allocate refinement threads.");
88 return JNI_ENOMEM;
89 }
90 }
91 }
92 return JNI_OK;
93 }
94
95 void G1ConcurrentRefineThreadControl::maybe_activate_next(uint cur_worker_id) {
96 assert(cur_worker_id < _num_max_threads,
97 "Activating another thread from %u not allowed since there can be at most %u",
98 cur_worker_id, _num_max_threads);
99 if (cur_worker_id == (_num_max_threads - 1)) {
100 // Already the last thread, there is no more thread to activate.
101 return;
102 }
103
104 uint worker_id = cur_worker_id + 1;
105 G1ConcurrentRefineThread* thread_to_activate = _threads[worker_id];
106 if (thread_to_activate == NULL) {
107 // Still need to create the thread...
108 _threads[worker_id] = create_refinement_thread(worker_id, false);
109 thread_to_activate = _threads[worker_id];
110 }
111 if (thread_to_activate != NULL && !thread_to_activate->is_active()) {
112 thread_to_activate->activate();
113 }
114 }
115
116 void G1ConcurrentRefineThreadControl::print_on(outputStream* st) const {
117 for (uint i = 0; i < _num_max_threads; ++i) {
118 if (_threads[i] != NULL) {
119 _threads[i]->print_on(st);
120 st->cr();
121 }
122 }
123 }
124
125 void G1ConcurrentRefineThreadControl::worker_threads_do(ThreadClosure* tc) {
126 for (uint i = 0; i < _num_max_threads; i++) {
127 if (_threads[i] != NULL) {
128 tc->do_thread(_threads[i]);
129 }
130 }
131 }
|
1 /*
2 * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
72 _cr = cr;
73 _num_max_threads = num_max_threads;
74
75 _threads = NEW_C_HEAP_ARRAY_RETURN_NULL(G1ConcurrentRefineThread*, num_max_threads, mtGC);
76 if (_threads == NULL) {
77 vm_shutdown_during_initialization("Could not allocate thread holder array.");
78 return JNI_ENOMEM;
79 }
80
81 for (uint i = 0; i < num_max_threads; i++) {
82 if (UseDynamicNumberOfGCThreads && i != 0 /* Always start first thread. */) {
83 _threads[i] = NULL;
84 } else {
85 _threads[i] = create_refinement_thread(i, true);
86 if (_threads[i] == NULL) {
87 vm_shutdown_during_initialization("Could not allocate refinement threads.");
88 return JNI_ENOMEM;
89 }
90 }
91 }
92
93 if (num_max_threads > 0) {
94 G1BarrierSet::dirty_card_queue_set().set_primary_refinement_thread(_threads[0]);
95 }
96
97 return JNI_OK;
98 }
99
100 void G1ConcurrentRefineThreadControl::maybe_activate_next(uint cur_worker_id) {
101 assert(cur_worker_id < _num_max_threads,
102 "Activating another thread from %u not allowed since there can be at most %u",
103 cur_worker_id, _num_max_threads);
104 if (cur_worker_id == (_num_max_threads - 1)) {
105 // Already the last thread, there is no more thread to activate.
106 return;
107 }
108
109 uint worker_id = cur_worker_id + 1;
110 G1ConcurrentRefineThread* thread_to_activate = _threads[worker_id];
111 if (thread_to_activate == NULL) {
112 // Still need to create the thread...
113 _threads[worker_id] = create_refinement_thread(worker_id, false);
114 thread_to_activate = _threads[worker_id];
115 }
116 if (thread_to_activate != NULL) {
117 thread_to_activate->activate();
118 }
119 }
120
121 void G1ConcurrentRefineThreadControl::print_on(outputStream* st) const {
122 for (uint i = 0; i < _num_max_threads; ++i) {
123 if (_threads[i] != NULL) {
124 _threads[i]->print_on(st);
125 st->cr();
126 }
127 }
128 }
129
130 void G1ConcurrentRefineThreadControl::worker_threads_do(ThreadClosure* tc) {
131 for (uint i = 0; i < _num_max_threads; i++) {
132 if (_threads[i] != NULL) {
133 tc->do_thread(_threads[i]);
134 }
135 }
136 }
|