Skip to content

Commit 86a2008

Browse files
committed
8051680: (ref) unnecessary process_soft_ref_reconsider
Reviewed-by: kbarrett, tschatzl
1 parent ac75a53 commit 86a2008

File tree

4 files changed

+8
-150
lines changed

4 files changed

+8
-150
lines changed

src/hotspot/share/gc/shared/referenceProcessor.cpp

Lines changed: 2 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,6 @@ void ReferenceProcessor::enable_discovery(bool check_no_refs) {
8181
}
8282
#endif // ASSERT
8383

84-
// Someone could have modified the value of the static
85-
// field in the j.l.r.SoftReference class that holds the
86-
// soft reference timestamp clock using reflection or
87-
// Unsafe between GCs. Unconditionally update the static
88-
// field in ReferenceProcessor here so that we use the new
89-
// value during reference discovery.
90-
91-
_soft_ref_timestamp_clock = java_lang_ref_SoftReference::clock();
9284
_discovering_refs = true;
9385
}
9486

@@ -156,8 +148,6 @@ void ReferenceProcessor::update_soft_ref_master_clock() {
156148
// We need a monotonically non-decreasing time in ms but
157149
// os::javaTimeMillis() does not guarantee monotonicity.
158150
jlong now = os::javaTimeNanos() / NANOSECS_PER_MILLISEC;
159-
jlong soft_ref_clock = java_lang_ref_SoftReference::clock();
160-
assert(soft_ref_clock == _soft_ref_timestamp_clock, "soft ref clocks out of sync");
161151

162152
NOT_PRODUCT(
163153
if (now < _soft_ref_timestamp_clock) {
@@ -201,26 +191,11 @@ ReferenceProcessorStats ReferenceProcessor::process_discovered_references(RefPro
201191
// Stop treating discovered references specially.
202192
disable_discovery();
203193

204-
// If discovery was concurrent, someone could have modified
205-
// the value of the static field in the j.l.r.SoftReference
206-
// class that holds the soft reference timestamp clock using
207-
// reflection or Unsafe between when discovery was enabled and
208-
// now. Unconditionally update the static field in ReferenceProcessor
209-
// here so that we use the new value during processing of the
210-
// discovered soft refs.
211-
212-
_soft_ref_timestamp_clock = java_lang_ref_SoftReference::clock();
213-
214194
ReferenceProcessorStats stats(total_count(_discoveredSoftRefs),
215195
total_count(_discoveredWeakRefs),
216196
total_count(_discoveredFinalRefs),
217197
total_count(_discoveredPhantomRefs));
218198

219-
{
220-
RefProcTotalPhaseTimesTracker tt(RefPhase1, &phase_times);
221-
process_soft_ref_reconsider(proxy_task, phase_times);
222-
}
223-
224199
update_soft_ref_master_clock();
225200

226201
{
@@ -329,37 +304,6 @@ inline void log_enqueued_ref(const DiscoveredListIterator& iter, const char* rea
329304
assert(oopDesc::is_oop(iter.obj()), "Adding a bad reference");
330305
}
331306

332-
size_t ReferenceProcessor::process_soft_ref_reconsider_work(DiscoveredList& refs_list,
333-
ReferencePolicy* policy,
334-
BoolObjectClosure* is_alive,
335-
OopClosure* keep_alive,
336-
VoidClosure* complete_gc) {
337-
assert(policy != NULL, "Must have a non-NULL policy");
338-
DiscoveredListIterator iter(refs_list, keep_alive, is_alive);
339-
// Decide which softly reachable refs should be kept alive.
340-
while (iter.has_next()) {
341-
iter.load_ptrs(DEBUG_ONLY(!discovery_is_atomic() /* allow_null_referent */));
342-
bool referent_is_dead = (iter.referent() != NULL) && !iter.is_referent_alive();
343-
if (referent_is_dead &&
344-
!policy->should_clear_reference(iter.obj(), _soft_ref_timestamp_clock)) {
345-
log_dropped_ref(iter, "by policy");
346-
// Remove Reference object from list
347-
iter.remove();
348-
// keep the referent around
349-
iter.make_referent_alive();
350-
iter.move_to_next();
351-
} else {
352-
iter.next();
353-
}
354-
}
355-
// Close the reachable set
356-
complete_gc->do_void();
357-
358-
log_develop_trace(gc, ref)(" Dropped " SIZE_FORMAT " dead Refs out of " SIZE_FORMAT " discovered Refs by policy, from list " INTPTR_FORMAT,
359-
iter.removed(), iter.processed(), p2i(&refs_list));
360-
return iter.removed();
361-
}
362-
363307
size_t ReferenceProcessor::process_soft_weak_final_refs_work(DiscoveredList& refs_list,
364308
BoolObjectClosure* is_alive,
365309
OopClosure* keep_alive,
@@ -508,34 +452,6 @@ size_t ReferenceProcessor::total_reference_count(ReferenceType type) const {
508452
}
509453

510454

511-
512-
class RefProcPhase1Task : public RefProcTask {
513-
public:
514-
RefProcPhase1Task(ReferenceProcessor& ref_processor,
515-
ReferenceProcessorPhaseTimes* phase_times,
516-
ReferencePolicy* policy)
517-
: RefProcTask(ref_processor,
518-
phase_times),
519-
_policy(policy) { }
520-
521-
void rp_work(uint worker_id,
522-
BoolObjectClosure* is_alive,
523-
OopClosure* keep_alive,
524-
VoidClosure* complete_gc) override {
525-
ResourceMark rm;
526-
RefProcSubPhasesWorkerTimeTracker tt(ReferenceProcessor::SoftRefSubPhase1, _phase_times, tracker_id(worker_id));
527-
size_t const removed = _ref_processor.process_soft_ref_reconsider_work(_ref_processor._discoveredSoftRefs[worker_id],
528-
_policy,
529-
is_alive,
530-
keep_alive,
531-
complete_gc);
532-
_phase_times->add_ref_cleared(REF_SOFT, removed);
533-
}
534-
535-
private:
536-
ReferencePolicy* _policy;
537-
};
538-
539455
class RefProcPhase2Task: public RefProcTask {
540456
void run_phase2(uint worker_id,
541457
DiscoveredList list[],
@@ -791,38 +707,6 @@ void ReferenceProcessor::run_task(RefProcTask& task, RefProcProxyTask& proxy_tas
791707
}
792708
}
793709

794-
void ReferenceProcessor::process_soft_ref_reconsider(RefProcProxyTask& proxy_task,
795-
ReferenceProcessorPhaseTimes& phase_times) {
796-
797-
size_t const num_soft_refs = total_count(_discoveredSoftRefs);
798-
phase_times.set_ref_discovered(REF_SOFT, num_soft_refs);
799-
phase_times.set_processing_is_mt(processing_is_mt());
800-
801-
if (num_soft_refs == 0) {
802-
log_debug(gc, ref)("Skipped phase 1 of Reference Processing: no references");
803-
return;
804-
}
805-
806-
if (_current_soft_ref_policy == NULL) {
807-
log_debug(gc, ref)("Skipped phase 1 of Reference Processing: no policy");
808-
return;
809-
}
810-
811-
RefProcMTDegreeAdjuster a(this, RefPhase1, num_soft_refs);
812-
813-
if (processing_is_mt()) {
814-
RefProcBalanceQueuesTimeTracker tt(RefPhase1, &phase_times);
815-
maybe_balance_queues(_discoveredSoftRefs);
816-
}
817-
818-
RefProcPhaseTimeTracker tt(RefPhase1, &phase_times);
819-
820-
log_reflist("Phase 1 Soft before", _discoveredSoftRefs, _max_num_queues);
821-
RefProcPhase1Task phase1(*this, &phase_times, _current_soft_ref_policy);
822-
run_task(phase1, proxy_task, true);
823-
log_reflist("Phase 1 Soft after", _discoveredSoftRefs, _max_num_queues);
824-
}
825-
826710
void ReferenceProcessor::process_soft_weak_final_refs(RefProcProxyTask& proxy_task,
827711
ReferenceProcessorPhaseTimes& phase_times) {
828712

@@ -1305,8 +1189,8 @@ uint RefProcMTDegreeAdjuster::ergo_proc_thread_count(size_t ref_count,
13051189
}
13061190

13071191
bool RefProcMTDegreeAdjuster::use_max_threads(RefProcPhases phase) const {
1308-
// Even a small number of references in either of those cases could produce large amounts of work.
1309-
return (phase == ReferenceProcessor::RefPhase1 || phase == ReferenceProcessor::RefPhase3);
1192+
// Even a small number of references in this phase could produce large amounts of work.
1193+
return phase == ReferenceProcessor::RefPhase3;
13101194
}
13111195

13121196
RefProcMTDegreeAdjuster::RefProcMTDegreeAdjuster(ReferenceProcessor* rp,

src/hotspot/share/gc/shared/referenceProcessor.hpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,13 @@ class DiscoveredListIterator {
160160
// straightforward manner in a general, non-generational, non-contiguous generation
161161
// (or heap) setting.
162162
class ReferenceProcessor : public ReferenceDiscoverer {
163-
friend class RefProcPhase1Task;
164163
friend class RefProcPhase2Task;
165164
friend class RefProcPhase3Task;
166165
friend class RefProcPhase4Task;
167166
public:
168167
// Names of sub-phases of reference processing. Indicates the type of the reference
169168
// processed and the associated phase number at the end.
170169
enum RefProcSubPhases {
171-
SoftRefSubPhase1,
172170
SoftRefSubPhase2,
173171
WeakRefSubPhase2,
174172
FinalRefSubPhase2,
@@ -179,7 +177,6 @@ class ReferenceProcessor : public ReferenceDiscoverer {
179177

180178
// Main phases of reference processing.
181179
enum RefProcPhases {
182-
RefPhase1,
183180
RefPhase2,
184181
RefPhase3,
185182
RefPhase4,
@@ -237,10 +234,6 @@ class ReferenceProcessor : public ReferenceDiscoverer {
237234

238235
void run_task(RefProcTask& task, RefProcProxyTask& proxy_task, bool marks_oops_alive);
239236

240-
// Phase 1: Re-evaluate soft ref policy.
241-
void process_soft_ref_reconsider(RefProcProxyTask& proxy_task,
242-
ReferenceProcessorPhaseTimes& phase_times);
243-
244237
// Phase 2: Drop Soft/Weak/Final references with a NULL or live referent, and clear
245238
// and enqueue non-Final references.
246239
void process_soft_weak_final_refs(RefProcProxyTask& proxy_task,
@@ -257,15 +250,6 @@ class ReferenceProcessor : public ReferenceDiscoverer {
257250
// Work methods used by the process_* methods. All methods return the number of
258251
// removed elements.
259252

260-
// (SoftReferences only) Traverse the list and remove any SoftReferences whose
261-
// referents are not alive, but that should be kept alive for policy reasons.
262-
// Keep alive the transitive closure of all such referents.
263-
size_t process_soft_ref_reconsider_work(DiscoveredList& refs_list,
264-
ReferencePolicy* policy,
265-
BoolObjectClosure* is_alive,
266-
OopClosure* keep_alive,
267-
VoidClosure* complete_gc);
268-
269253
// Traverse the list and remove any Refs whose referents are alive,
270254
// or NULL if discovery is not atomic. Enqueue and clear the reference for
271255
// others if do_enqueue_and_clear is set.

src/hotspot/share/gc/shared/referenceProcessorPhaseTimes.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,15 @@
3636
#define ASSERT_REF_TYPE(ref_type) assert((ref_type) >= REF_SOFT && (ref_type) <= REF_PHANTOM, \
3737
"Invariant (%d)", (int)ref_type)
3838

39-
#define ASSERT_PHASE(phase) assert((phase) >= ReferenceProcessor::RefPhase1 && \
39+
#define ASSERT_PHASE(phase) assert((phase) >= ReferenceProcessor::RefPhase2 && \
4040
(phase) < ReferenceProcessor::RefPhaseMax, \
4141
"Invariant (%d)", (int)phase);
4242

43-
#define ASSERT_SUB_PHASE(phase) assert((phase) >= ReferenceProcessor::SoftRefSubPhase1 && \
43+
#define ASSERT_SUB_PHASE(phase) assert((phase) >= ReferenceProcessor::SoftRefSubPhase2 && \
4444
(phase) < ReferenceProcessor::RefSubPhaseMax, \
4545
"Invariant (%d)", (int)phase);
4646

4747
static const char* SubPhasesParWorkTitle[ReferenceProcessor::RefSubPhaseMax] = {
48-
"SoftRef (ms):",
4948
"SoftRef (ms):",
5049
"WeakRef (ms):",
5150
"FinalRef (ms):",
@@ -56,7 +55,6 @@ static const char* SubPhasesParWorkTitle[ReferenceProcessor::RefSubPhaseMax] = {
5655
static const char* Phase2ParWorkTitle = "Total (ms):";
5756

5857
static const char* SubPhasesSerWorkTitle[ReferenceProcessor::RefSubPhaseMax] = {
59-
"SoftRef:",
6058
"SoftRef:",
6159
"WeakRef:",
6260
"FinalRef:",
@@ -69,7 +67,6 @@ static const char* Phase2SerWorkTitle = "Total:";
6967
static const char* Indents[6] = {"", " ", " ", " ", " ", " "};
7068

7169
static const char* PhaseNames[ReferenceProcessor::RefPhaseMax] = {
72-
"Reconsider SoftReferences",
7370
"Notify Soft/WeakReferences",
7471
"Notify and keep alive finalizable",
7572
"Notify PhantomReferences"
@@ -275,7 +272,6 @@ void ReferenceProcessorPhaseTimes::print_all_references(uint base_indent, bool p
275272
}
276273

277274
uint next_indent = base_indent + 1;
278-
print_phase(ReferenceProcessor::RefPhase1, next_indent);
279275
print_phase(ReferenceProcessor::RefPhase2, next_indent);
280276
print_phase(ReferenceProcessor::RefPhase3, next_indent);
281277
print_phase(ReferenceProcessor::RefPhase4, next_indent);
@@ -329,9 +325,6 @@ void ReferenceProcessorPhaseTimes::print_phase(ReferenceProcessor::RefProcPhases
329325
}
330326

331327
switch (phase) {
332-
case ReferenceProcessor::RefPhase1:
333-
print_sub_phase(&ls, ReferenceProcessor::SoftRefSubPhase1, indent + 1);
334-
break;
335328
case ReferenceProcessor::RefPhase2:
336329
print_sub_phase(&ls, ReferenceProcessor::SoftRefSubPhase2, indent + 1);
337330
print_sub_phase(&ls, ReferenceProcessor::WeakRefSubPhase2, indent + 1);

test/hotspot/jtreg/gc/logging/TestPrintReferences.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class TestPrintReferences {
5050
static final String finalReference = "FinalReference";
5151
static final String phantomReference = "PhantomReference";
5252

53-
static final String phaseReconsiderSoftReferences = "Reconsider SoftReferences";
5453
static final String phaseNotifySoftWeakReferences = "Notify Soft/WeakReferences";
5554
static final String phaseNotifyKeepAliveFinalizer = "Notify and keep alive finalizable";
5655
static final String phaseNotifyPhantomReferences = "Notify PhantomReferences";
@@ -137,7 +136,6 @@ private static void checkLogFormat(OutputAnalyzer output, boolean parallelRefPro
137136

138137
final boolean p = parallelRefProcEnabled;
139138

140-
String phase1Regex = gcLogTimeRegex + phaseRegex(phaseReconsiderSoftReferences) + balanceRegex + subphaseRegex("SoftRef", p);
141139
String phase2Regex = gcLogTimeRegex + phaseRegex(phaseNotifySoftWeakReferences) +
142140
balanceRegex +
143141
subphaseRegex("SoftRef", p) +
@@ -148,7 +146,6 @@ private static void checkLogFormat(OutputAnalyzer output, boolean parallelRefPro
148146
String phase4Regex = gcLogTimeRegex + phaseRegex(phaseNotifyPhantomReferences) + balanceRegex + subphaseRegex("PhantomRef", p);
149147

150148
output.shouldMatch(totalRegex +
151-
phase1Regex +
152149
phase2Regex +
153150
phase3Regex +
154151
phase4Regex);
@@ -220,14 +217,14 @@ public static void checkLogValue(OutputAnalyzer out) {
220217
private static void checkTrimmedLogValue() {
221218
BigDecimal refProcTime = getTimeValue(referenceProcessing, 0);
222219

223-
BigDecimal sumOfSubPhasesTime = getTimeValue(phaseReconsiderSoftReferences, 2);
220+
BigDecimal sumOfSubPhasesTime = BigDecimal.ZERO;
224221
sumOfSubPhasesTime = sumOfSubPhasesTime.add(getTimeValue(phaseNotifySoftWeakReferences, 2));
225222
sumOfSubPhasesTime = sumOfSubPhasesTime.add(getTimeValue(phaseNotifyKeepAliveFinalizer, 2));
226223
sumOfSubPhasesTime = sumOfSubPhasesTime.add(getTimeValue(phaseNotifyPhantomReferences, 2));
227224

228-
// If there are 4 phases, we should allow 0.2 tolerance.
229-
final BigDecimal toleranceFor4SubPhases = BigDecimal.valueOf(0.2);
230-
if (!greaterThanOrApproximatelyEqual(refProcTime, sumOfSubPhasesTime, toleranceFor4SubPhases)) {
225+
// If there are 3 phases, we should allow 0.2 tolerance.
226+
final BigDecimal toleranceFor3SubPhases = BigDecimal.valueOf(0.2);
227+
if (!greaterThanOrApproximatelyEqual(refProcTime, sumOfSubPhasesTime, toleranceFor3SubPhases)) {
231228
throw new RuntimeException("Reference Processing time(" + refProcTime + "ms) is less than the sum("
232229
+ sumOfSubPhasesTime + "ms) of each phases");
233230
}

0 commit comments

Comments
 (0)