RFR: 6869327: Add new C2 flag to keep safepoints in counted loops.

Andreas Eriksson andreas.eriksson at oracle.com
Fri Nov 27 13:48:53 UTC 2015



On 2015-11-27 14:29, Andreas Eriksson wrote:
>
>
> On 2015-11-27 14:18, Aleksey Shipilev wrote:
>> Hi,
>>
>> On 11/27/2015 04:01 PM, Andreas Eriksson wrote:
>>> Please review this change that adds a flag to keep a safepoint in
>>> counted loops.
>>>
>>> Currently C2 removes safepoints in counted loops.
>>> This can force other safepointing threads to wait for the counted loop
>>> thread for long periods of time.
>>> This change adds a flag, UseCountedLoopSafepoints, which keeps a
>>> safepoint in the loop. Its default value is false.
>>>
>>> Bug: 6869327: Add new C2 flag to keep safepoints in counted loops.
>>> https://bugs.openjdk.java.net/browse/JDK-6869327
>>>
>>> Webrev: http://cr.openjdk.java.net/~aeriksso/6869327/webrev.00/
>> Do I get it right that this logic works good with loop unrolling? Can we
>> check?
>
> It should, but verifying it would indeed be good.
> I'll check and let you know.

The loop from the test gets unrolled and safepointed correctly, like 
your example.
Attached PrintOptoAssembly of the interesting part in case you wish to 
look at it.

- Andreas

>
> Thanks,
> Andreas
>
>> E.g. I would expect that a counted loop like this:
>>
>>   int s = 0;
>>   for (int c = 0; c < N; c++) {
>>      s += c;
>>      <safepoint>
>>   }
>>
>> ...would get unrolled and stripped to:
>>
>>   int s = 0;
>>   for (int c = 0; c < N; c += 4) {
>>     s += c + 0;
>>     s += c + 1;
>>     s += c + 2;
>>     s += c + 3;
>>     <safepoint> // only one safepoint here
>>   }
>>
>> This would basically perform a limited variant of what Vladimir mentions
>> as "strip mining" (aka transform a countable loop into two nested loops
>> and place safepoint into external loop), where the size of "internal"
>> loop is limited by unrolling.
>>
>> Thanks,
>> -Aleksey
>>
>

-------------- next part --------------
080   B6: #	B6 B7 <- B5 B6 	Loop: B6-B6 inner main of N118 Freq: 999999
080   	MEMBAR-release ! (empty encoding)
080   	
080   	ADDQ  [[R11 + #16 (8-bit)]],#1
086   	
086   	MEMBAR-acquire ! (empty encoding)
086   	MEMBAR-release ! (empty encoding)
086   	
086   	ADDQ  [[R11 + #16 (8-bit)]],#1
08c   	
08c   	MEMBAR-acquire ! (empty encoding)
08c   	MEMBAR-release ! (empty encoding)
08c   	
08c   	ADDQ  [[R11 + #16 (8-bit)]],#1
092   	
092   	MEMBAR-acquire ! (empty encoding)
092   	MEMBAR-release ! (empty encoding)
092   	
092   	ADDQ  [[R11 + #16 (8-bit)]],#1
098   	
098   	MEMBAR-acquire ! (empty encoding)
098   	addl    R14, #4	# int
09c   	testl  rax, [rip + #offset_to_poll_page]	# Safepoint: poll for GC        # UseCountedLoopSafepoints::main @ bci:31  L[0]=_ L[1]=RBX L[2]=R14 # OopMap{r11=Oop off=156}
0a2   	cmpl    R14, R10
0a5   	jl,s   B6	# loop end  P=1.000000 C=12509.000000


More information about the hotspot-compiler-dev mailing list