RFR(M) 8043575: Dynamically parallelize reference processing work

Kim Barrett kim.barrett at oracle.com
Tue Jun 5 00:11:13 UTC 2018


> On Jun 1, 2018, at 5:48 PM, sangheon.kim at oracle.com wrote:
> 
> Hi all,
> 
> As webrev.0 is conflicting with webrev.0 of "8203319: JDK-8201487 disabled too much queue balancing"(out for review, but not yet pushed), I'm posting webrev.1.
> 
> http://cr.openjdk.java.net/~sangheki/8043575/webrev.1
> http://cr.openjdk.java.net/~sangheki/8043575/webrev.1_to_0

The hookup of the changes into the various collectors seems okay.  My
comments are mostly focused on the ReferenceProcessor changes.

------------------------------------------------------------------------------ 
src/hotspot/share/gc/shared/referenceProcessorPhaseTimes.hpp
 140   void set_phase_number(RefProcPhaseNumbers phase_number) { _phase_number = phase_number; }
 141   RefProcPhaseNumbers phase_number() const { return _phase_number; }

I think I dislike these and how they are used.  And see other
discussion below, suggesting they might not be needed.

(Though they are similar to other related states. But maybe I dislike
those too.)

------------------------------------------------------------------------------ 
src/hotspot/share/gc/shared/referenceProcessor.hpp
 641 class RefProcMTDegreeAdjuster : public StackObj {
...
 649   RefProcMTDegreeAdjuster(ReferenceProcessor* rp, ReferenceProcessorPhaseTimes* times, size_t ref_count);

The times argument is here to provide information about what phase
we're in.  That seems really indirect, and I'd really prefer that
information to be provided directly as arguments here.

I think that might also remove the need for the new phase_number and
set_phase_number functions for the phase times class.

This also would flow through to ergo_proc_thread_count and use_max_threads.

------------------------------------------------------------------------------ 
src/hotspot/share/gc/shared/referenceProcessor.cpp
 727   bool must_balance = mt_processing && need_balance_queues(refs_lists);

need_balance_queues returns the right answer for an initial balancing,
but not for a re-balance after some processing.  Specifically, further
reducing the mt-degree may require rebalancing, even if it wasn't
previously needed.

(This comment is assuming the updated version of need_balance_queues
that I sent out today.  The situation is worse without that.)

------------------------------------------------------------------------------
src/hotspot/share/gc/shared/referenceProcessor.cpp 
 787   // For discovery_is_atomic() is true, phase 3 should be processed to call do_void() from VoidClosure.
 788   // For discovery_is_atomic() is false, phase 3 can be skipped if there are no references because do_void() is
 789   // already called at phase 2.
 790   if (!discovery_is_atomic()) {
 791     if (total_count(refs_lists) == 0) {
 792       return;
 793     }
 794   }

The discovery_is_atomic stuff is left-over from before JDK-8203028.
Phase2 now never calls the complete_gc closure, because it is never
needed, regardless of the value of discovery_is_atomic.  So checking
that can be removed here.

At least, that's what's expected by the ReferenceProcessing code.  The
atomic discovery case for phase2 has "always" (since at least the
beginning of the mercurial age) ignored the complete_gc argument, and
only used it when dealing with the concurrent discovery case.

But G1CopyingKeepAliveClosure appears to have always passed the buck
to the complete_gc closure, contrary to the expectations of the RP
phase2 code.  So G1 young/mixed collections only work because phase3
will eventually call the complete_gc closure (by each of the threads).
(G1 concurrent and full gc's have a cuttoff where no work is left for
the complete_gc closure if the object is already marked. I spot
checked other collectors, and at a quick glance it looks like the
others meet the expectations of the ReferenceProcessor code; it's just
G1 young/mixed collections that don't.)

I'm not entirely sure what happens if the number of threads in phase3
is less than the number in phase2 in that case.  I think any pending
phase2 work associated with the missing threads will get stolen by
phase3 working threads, but haven't verified that.

I think the simplest fix for this is to change phase2 to always call
the complete_gc closure after all.  For some collections that's a
(perhaps somewhat expensive) nop, but in the overall context of
reference processing that's probably in the noise.  And also update
the relevant comment in phase2.

The alternative would be to make G1CopyingKeepAliveClosure meet the
(not explicitly stated in the API) ReferenceProcessor expectations,
perhaps bypassing some of the G1ParScanThreadState machinery.

------------------------------------------------------------------------------ 
src/hotspot/share/gc/shared/referenceProcessor.cpp 
 800     RefProcMTDegreeAdjuster a(this, phase_times, ref_count);

This is using ref_count, which was last set on line 759, and not
updated after phase2.  It should have been updated as part of the new
code block around line 790.

------------------------------------------------------------------------------ 
src/hotspot/share/gc/shared/referenceProcessor.cpp
1193 uint ReferenceProcessor::ergo_proc_thread_count(ReferenceProcessorPhaseTimes* times) const {
1194   size_t ref_count = total_count(_discovered_refs);
1195 
1196   return ergo_proc_thread_count(ref_count, num_queues(), times);
1197 }

I don't think this overload should exist.  The ref_count used here is
the SoftReference count, which isn't particularly interesting
here. (It's not the total number of discovered references, which is
also not an interesting number for this purpose.)

It seems to only exist as part of the workarounds for making ParNew
kind of limp along with these changes.  But wouldn't it be simpler to
leave ParNewRefProceTaskExecutor::execute alone, using the
active_workers as before?  (And recall that I suggested above that
execute should just use the currently configured mt-processing degree,
rather than adding an ergo_workers argument.) It will be called in the
context of RefProcMTDegreeAdjuster, that won't do anything because of
ParNew disables mt-degree adjustment.  So I think by leaving things
alone here we retain the current behavior, e.g. CMS ParNew uses
ParallelRefProcEnabled as an all-or-nothing flag, and doesn't pay
attention to the new ReferencesPerThread.  And that seems reasonable
to me for a deprecated collector.

------------------------------------------------------------------------------ 
src/hotspot/share/gc/cms/parNewGeneration.cpp
1455                              false);                     // disable adjusting queue size when processing references

It's not the queue size that adjusted (or not), it's the number of
queues.  And really, it's the MT processing degree.

That last probably should also apply to the name of the variable in
the reference processor, and related names.  Although given that this
is all a bit of a kludge to work around (deprecated) CMS deficiencies,
maybe I shouldn't be too concerned.  And you did file JDK-8203951.

Though I see Thomas also requested a name change...

If you change the name, remember to update JDK-8203951.

------------------------------------------------------------------------------ 
src/hotspot/share/gc/shared/referenceProcessor.cpp
1199 uint ReferenceProcessor::ergo_proc_thread_count(size_t ref_count,
1200                                                 uint max_threads,
1201                                                 ReferenceProcessorPhaseTimes* times) const {
...
1204   if (ReferencesPerThread == 0) {
1205     return _num_queues;
1206   }

Why is _num_queues used here, but max_threads used elsewhere in this
function.  I *think* this ought to also be max_threads.

------------------------------------------------------------------------------ 
src/hotspot/share/gc/shared/referenceProcessor.cpp  
1229 RefProcMTDegreeAdjuster::RefProcMTDegreeAdjuster(ReferenceProcessor* rp,
...
1235   if (!_rp->has_adjustable_queue() || (ReferencesPerThread == 0)) {

This checks ReferencesPerThread for 0 to do nothing.  And then
ergo_proc_thread_count similarly checks for 0 to (effectively) do
nothing. If the earlier suggestion to kill the 1-arg overload is
taken, then ergo_proc_thread_count is really just a helper for
RefProcMTDegreeAdjuster, and we don't need that special case twice.

And perhaps it should be a private helper in RefProcMTDegreeAdjuster?
Similarly for use_max_threads.  Or maybe just inline them into that
class's constructor.

------------------------------------------------------------------------------ 
src/hotspot/share/gc/shared/referenceProcessor.cpp 
1199 uint ReferenceProcessor::ergo_proc_thread_count(size_t ref_count,
...
1213   return (uint)MIN3(thread_count,
1214                     static_cast<size_t>(max_threads),
1215                     (size_t)os::initial_active_processor_count());

I don't see why this should look at initial_active_processor_count?

------------------------------------------------------------------------------




More information about the hotspot-gc-dev mailing list