author | stefank |
Thu, 22 Feb 2018 18:36:32 +0100 | |
changeset 49048 | 4e8c86b75428 |
parent 47216 | 71c04702a3d5 |
child 52904 | d2f118d3f8e7 |
permissions | -rw-r--r-- |
38216 | 1 |
/* |
41094 | 2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
38216 | 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 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#ifndef SHARE_VM_GC_SHARED_WORKERMANAGER_HPP |
|
26 |
#define SHARE_VM_GC_SHARED_WORKERMANAGER_HPP |
|
27 |
||
28 |
#include "gc/shared/adaptiveSizePolicy.hpp" |
|
29 |
||
30 |
class WorkerManager : public AllStatic { |
|
31 |
public: |
|
32 |
// Create additional workers as needed. |
|
33 |
// active_workers - number of workers being requested for an upcoming |
|
34 |
// parallel task. |
|
35 |
// total_workers - total number of workers. This is the maximum |
|
36 |
// number possible. |
|
37 |
// created_workers - number of workers already created. This maybe |
|
38 |
// less than, equal to, or greater than active workers. If greater than |
|
39 |
// or equal to active_workers, nothing is done. |
|
40 |
// worker_type - type of thread. |
|
41 |
// initializing - true if this is called to get the initial number of |
|
42 |
// GC workers. |
|
43 |
// If initializing is true, do a vm exit if the workers cannot be created. |
|
44 |
// The initializing = true case is for JVM start up and failing to |
|
45 |
// create all the worker at start should considered a problem so exit. |
|
46 |
// If initializing = false, there are already some number of worker |
|
47 |
// threads and a failure would not be optimal but should not be fatal. |
|
48 |
template <class WorkerType> |
|
49 |
static uint add_workers (WorkerType* holder, |
|
39704 | 50 |
uint active_workers, |
51 |
uint total_workers, |
|
52 |
uint created_workers, |
|
53 |
os::ThreadType worker_type, |
|
54 |
bool initializing) { |
|
38216 | 55 |
uint start = created_workers; |
56 |
uint end = MIN2(active_workers, total_workers); |
|
57 |
for (uint worker_id = start; worker_id < end; worker_id += 1) { |
|
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
58 |
WorkerThread* new_worker = NULL; |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
59 |
if (initializing || !InjectGCWorkerCreationFailure) { |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
60 |
new_worker = holder->install_worker(worker_id); |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
61 |
} |
38216 | 62 |
if (new_worker == NULL || !os::create_thread(new_worker, worker_type)) { |
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
63 |
log_trace(gc, task)("WorkerManager::add_workers() : " |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
64 |
"creation failed due to failed allocation of native %s", |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
65 |
new_worker == NULL ? "memory" : "thread"); |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
66 |
if (new_worker != NULL) { |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
67 |
delete new_worker; |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
68 |
} |
39704 | 69 |
if (initializing) { |
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
70 |
vm_exit_out_of_memory(0, OOM_MALLOC_ERROR, "Cannot create worker GC thread. Out of system resources."); |
38216 | 71 |
} |
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
72 |
break; |
38216 | 73 |
} |
74 |
created_workers++; |
|
75 |
os::start_thread(new_worker); |
|
76 |
} |
|
77 |
||
40096
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
78 |
log_trace(gc, task)("WorkerManager::add_workers() : " |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
79 |
"created_workers: %u", created_workers); |
246c62cd9180
8159073: : Error handling incomplete when creating GC threads lazily
jmasa
parents:
39704
diff
changeset
|
80 |
|
39704 | 81 |
return created_workers; |
82 |
} |
|
38216 | 83 |
|
39704 | 84 |
// Log (at trace level) a change in the number of created workers. |
85 |
template <class WorkerType> |
|
86 |
static void log_worker_creation(WorkerType* holder, |
|
87 |
uint previous_created_workers, |
|
88 |
uint active_workers, |
|
89 |
uint created_workers, |
|
90 |
bool initializing) { |
|
91 |
if (previous_created_workers < created_workers) { |
|
92 |
const char* initializing_msg = initializing ? "Adding initial" : "Creating additional"; |
|
93 |
log_trace(gc, task)("%s %s(s) previously created workers %u active workers %u total created workers %u", |
|
94 |
initializing_msg, holder->group_name(), previous_created_workers, active_workers, created_workers); |
|
95 |
} |
|
38216 | 96 |
} |
97 |
}; |
|
98 |
#endif // SHARE_VM_GC_SHARED_WORKERMANAGER_HPP |