author | zgu |
Tue, 29 Jan 2019 08:28:24 -0500 | |
changeset 53544 | aed190ed8549 |
parent 53536 | 482109fae02b |
child 53702 | 50a5d0353570 |
permissions | -rw-r--r-- |
47648
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
1 |
/* |
53536
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
2 |
* Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved. |
47648
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
4 |
* |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
8 |
* |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
13 |
* accompanied this code). |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
14 |
* |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
18 |
* |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
21 |
* questions. |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
22 |
* |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
23 |
*/ |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
24 |
|
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
25 |
#include "precompiled.hpp" |
53536
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
26 |
#include "classfile/stringTable.hpp" |
50297
580744d900c8
8202813: Move vm_weak processing from SystemDictionary to WeakProcessor
coleenp
parents:
50113
diff
changeset
|
27 |
#include "gc/shared/oopStorage.inline.hpp" |
51546
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
28 |
#include "gc/shared/oopStorageParState.inline.hpp" |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
29 |
#include "gc/shared/weakProcessor.inline.hpp" |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
30 |
#include "gc/shared/weakProcessorPhases.hpp" |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
31 |
#include "gc/shared/weakProcessorPhaseTimes.hpp" |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
32 |
#include "memory/allocation.inline.hpp" |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
33 |
#include "memory/iterator.hpp" |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
34 |
#include "runtime/globals.hpp" |
50113 | 35 |
#include "utilities/macros.hpp" |
47648
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
36 |
|
47676
b1c020fc35a3
8189748: More precise closures for WeakProcessor::weak_oops_do calls
stefank
parents:
47649
diff
changeset
|
37 |
void WeakProcessor::weak_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive) { |
53536
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
38 |
StringTable::reset_dead_counter(); |
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
39 |
CountingIsAliveClosure<BoolObjectClosure> cl(is_alive); |
51546
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
40 |
FOR_EACH_WEAK_PROCESSOR_PHASE(phase) { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
41 |
if (WeakProcessorPhases::is_serial(phase)) { |
53536
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
42 |
WeakProcessorPhases::processor(phase)(&cl, keep_alive); |
51546
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
43 |
} else { |
53536
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
44 |
WeakProcessorPhases::oop_storage(phase)->weak_oops_do(&cl, keep_alive); |
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
45 |
} |
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
46 |
if (WeakProcessorPhases::is_stringtable(phase)) { |
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
47 |
StringTable::inc_dead_counter(cl.num_dead()); |
51546
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
48 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
49 |
} |
53536
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
50 |
StringTable::finish_dead_counter(); |
47648
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
51 |
} |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
52 |
|
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
53 |
void WeakProcessor::oops_do(OopClosure* closure) { |
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
54 |
AlwaysTrueClosure always_true; |
47676
b1c020fc35a3
8189748: More precise closures for WeakProcessor::weak_oops_do calls
stefank
parents:
47649
diff
changeset
|
55 |
weak_oops_do(&always_true, closure); |
47648
226b1fc611b9
8189359: Move native weak oops cleaning out of ReferenceProcessor
stefank
parents:
diff
changeset
|
56 |
} |
51546
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
57 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
58 |
uint WeakProcessor::ergo_workers(uint max_workers) { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
59 |
// Ignore ParallelRefProcEnabled; that's for j.l.r.Reference processing. |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
60 |
if (ReferencesPerThread == 0) { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
61 |
// Configuration says always use all the threads. |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
62 |
return max_workers; |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
63 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
64 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
65 |
// One thread per ReferencesPerThread references (or fraction thereof) |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
66 |
// in the various OopStorage objects, bounded by max_threads. |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
67 |
// |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
68 |
// Serial phases are ignored in this calculation, because of the |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
69 |
// cost of running unnecessary threads. These phases are normally |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
70 |
// small or empty (assuming they are configured to exist at all), |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
71 |
// and development oriented, so not allocating any threads |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
72 |
// specifically for them is okay. |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
73 |
size_t ref_count = 0; |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
74 |
FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(phase) { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
75 |
ref_count += WeakProcessorPhases::oop_storage(phase)->allocation_count(); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
76 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
77 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
78 |
// +1 to (approx) round up the ref per thread division. |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
79 |
size_t nworkers = 1 + (ref_count / ReferencesPerThread); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
80 |
nworkers = MIN2(nworkers, static_cast<size_t>(max_workers)); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
81 |
return static_cast<uint>(nworkers); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
82 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
83 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
84 |
void WeakProcessor::Task::initialize() { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
85 |
assert(_nworkers != 0, "must be"); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
86 |
assert(_phase_times == NULL || _nworkers <= _phase_times->max_threads(), |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
87 |
"nworkers (%u) exceeds max threads (%u)", |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
88 |
_nworkers, _phase_times->max_threads()); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
89 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
90 |
if (_phase_times) { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
91 |
_phase_times->set_active_workers(_nworkers); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
92 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
93 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
94 |
uint storage_count = WeakProcessorPhases::oop_storage_phase_count; |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
95 |
_storage_states = NEW_C_HEAP_ARRAY(StorageState, storage_count, mtGC); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
96 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
97 |
StorageState* states = _storage_states; |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
98 |
FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(phase) { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
99 |
OopStorage* storage = WeakProcessorPhases::oop_storage(phase); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
100 |
new (states++) StorageState(storage, _nworkers); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
101 |
} |
53536
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
102 |
StringTable::reset_dead_counter(); |
51546
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
103 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
104 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
105 |
WeakProcessor::Task::Task(uint nworkers) : |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
106 |
_phase_times(NULL), |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
107 |
_nworkers(nworkers), |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
108 |
_serial_phases_done(WeakProcessorPhases::serial_phase_count), |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
109 |
_storage_states(NULL) |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
110 |
{ |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
111 |
initialize(); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
112 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
113 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
114 |
WeakProcessor::Task::Task(WeakProcessorPhaseTimes* phase_times, uint nworkers) : |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
115 |
_phase_times(phase_times), |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
116 |
_nworkers(nworkers), |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
117 |
_serial_phases_done(WeakProcessorPhases::serial_phase_count), |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
118 |
_storage_states(NULL) |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
119 |
{ |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
120 |
initialize(); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
121 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
122 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
123 |
WeakProcessor::Task::~Task() { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
124 |
if (_storage_states != NULL) { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
125 |
StorageState* states = _storage_states; |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
126 |
FOR_EACH_WEAK_PROCESSOR_OOP_STORAGE_PHASE(phase) { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
127 |
states->StorageState::~StorageState(); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
128 |
++states; |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
129 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
130 |
FREE_C_HEAP_ARRAY(StorageState, _storage_states); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
131 |
} |
53536
482109fae02b
8213229: Investigate treating StringTable as weak in young collections
tschatzl
parents:
51546
diff
changeset
|
132 |
StringTable::finish_dead_counter(); |
51546
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
133 |
} |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
134 |
|
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
135 |
void WeakProcessor::GangTask::work(uint worker_id) { |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
136 |
_erased_do_work(this, worker_id); |
b9f6a4427da9
8072498: Multi-thread JNI weak reference processing
kbarrett
parents:
50297
diff
changeset
|
137 |
} |