C2: Compiler scheduling oddity
Andrew Haley
aph at redhat.com
Thu Jun 16 15:38:46 UTC 2016
I have an interesting problem with opto scheduling. At the moment I
only see this with the AArch64 back-end in jdk8u, but I'm asking here
because as far as I can see it could happen anywhere.
I have a load and a store of the same field. The load must come
before the store. The code looks like this:
tree.accept(this);
JCTree tmpResult = this.result;
this.result = null;
public <T extends com.sun.tools.javac.tree.JCTree> T translate(T);
Code:
0: aload_1
1: ifnonnull 6
4: aconst_null
5: areturn
6: aload_1
7: aload_0
8: invokevirtual #2 // Method com/sun/tools/javac/tree/JCTree.accept:(Lcom/sun/tools/javac/tree/JCTree$Visitor;)V
11: aload_0
12: getfield #3 // Field result:Lcom/sun/tools/javac/tree/JCTree;
15: astore_2
16: aload_0
17: aconst_null
18: putfield #3 // Field result:Lcom/sun/tools/javac/tree/JCTree;
21: aload_2
22: areturn
Occasionally I get a segfault because the store (of NULL) at bci 18 is
scheduled before the load. It only happens when the method is deeply
inlined, and it only happens about 1 time in 30.
Here's what happens:
PhaseCFG::insert_anti_dependences notices that the load must be
scheduled before the store. However, it does not insert a precedence
link because the store is in a different basic block from the load,
and that basic block is going to be executed after the load. As far
as I can see the load is in a different basic block from the store
because the load has an implicit null check.
Later, the blocks containing the load and the store are merged, but
there is nothing to stop the store from rising above the load, and
occasionally it does.
So, it's clear to me what is happening, but how to fix it? I don't
know why this doesn't happen all the time. Does any of this sound
familiar?
I have appended the basic blocks in three phases. These are only the
mach nodes, in order to keep the dumps reasonably small.
Thanks,
Andrew.
The dumps: @@@@@@@@@@@@@@@@@@@@@ marks the load, ################# the
store.
---- After ScheduleLate ----
B40: # B42 B41 <- N1329 N264 Freq: 0.999885
280 decodeHeapOop === _ 281 [[ 99 284 292 1063 ]] com/sun/tools/javac/tree/JCTree * Oop:com/sun/tools/javac/tree/JCTree * !jvms: @@@@@@@@@@@@@@@@@@ TreeTranslator::translate @ bci:12 @@@@@@@@@@@@@@@@@@@@@ TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
281 loadN === _ 282 195 [[ 280 ]] narrowoop: com/sun/tools/javac/tree/JCTree * needs_anti_dependence_check !jvms: @@@@@@@@@@@@@@@@@@ TreeTranslator::translate @ bci:12 @@@@@@@@@@@@@@@@@@@@@ TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
103 CallDynamicJavaDirect === 105 267 268 14 0 241 195 195 11 0 11 195 0 0 277 0 0 195 0 0 | 278 [[ 104 102 279 282 ]] Dynamic com.sun.tools.javac.tree.JCTree::accept # void ( com/sun/tools/javac/tree/JCTree:NotNull *, com/sun/tools/javac/tree/JCTree$Visitor * ) TreeTranslator::translate @ bci:8 TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162 !jvms: TreeTranslator::translate @ bci:8 TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
271 storeimmB0 === 105 269 229 272 [[ 268 ]] memory Memory: @rawptr:BotPTR, idx=Raw; !jvms: TransTypes::translate @ bci:7 TransTypes::visitSelect @ bci:162
272 urShiftP_reg_imm === 105 195 [[ 271 ]] #9/0x00000009
273 storeN === 105 269 195 274 | 278 [[ 268 ]] memory Memory: @com/sun/tools/javac/comp/TransTypes:NotNull+60 * [narrow], name=pt, idx=16; !jvms: TransTypes::translate @ bci:7 TransTypes::visitSelect @ bci:162
274 encodeHeapOop_not_null === 105 275 [[ 273 ]] narrowoop: com/sun/tools/javac/code/Type:NotNull *
277 decodeHeapOop === _ 278 [[ 103 ]] com/sun/tools/javac/code/Type * Oop:com/sun/tools/javac/code/Type * !jvms: TransTypes::translate @ bci:1 TransTypes::visitSelect @ bci:162
278 loadN === _ 269 195 [[ 277 293 803 273 103 ]] narrowoop: com/sun/tools/javac/code/Type * needs_anti_dependence_check !jvms: TransTypes::translate @ bci:1 TransTypes::visitSelect @ bci:162
B42: # B44 B43 <- N105 Freq: 0.999865
288 storeimmB0 === 1326 282 229 289 [[ 286 1059 1066 ]] memory Memory: @rawptr:BotPTR, idx=Raw; !jvms: TransTypes::translate @ bci:19 TransTypes::visitSelect @ bci:162
289 urShiftP_reg_imm === 1326 195 [[ 288 ]] #9/0x00000009
293 storeN === 1326 282 195 278 [[ 285 1059 1066 ]] memory Memory: @com/sun/tools/javac/comp/TransTypes:NotNull+60 * [narrow], name=pt, idx=16; !jvms: TransTypes::translate @ bci:19 TransTypes::visitSelect @ bci:162
294 storeN === 1326 282 195 295 [[ 285 1059 1066 ]] memory Memory: @com/sun/tools/javac/comp/TransTypes:NotNull+12 * [narrow], name=result, idx=17; !jvms: ################ TreeTranslator::translate @ bci:18 ################# TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
295 loadConN0 === 1 [[ 294 ]] narrowoop: NULL
99 cmpP_imm0_branch === 1326 280 [[ 98 1058 ]] P=0.999999, C=-1.000000 !jvms: TransTypes::visitSelect @ bci:165
---- After GCM ----
B42: # B44 B43 <- N105 Freq: 0.999865
1720 loadN === _ 282 195 [[ 1719 ]] narrowoop: com/sun/tools/javac/tree/JCTree * needs_anti_dependence_check !orig=[281] !jvms: @@@@@@@@@@@@@@@@@@ TreeTranslator::translate @ bci:12 @@@@@@@@@@@@@@@@@@@@@ TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
1719 decodeHeapOop === _ 1720 [[ 1063 284 292 ]] com/sun/tools/javac/tree/JCTree * Oop:com/sun/tools/javac/tree/JCTree * !orig=[280] !jvms: @@@@@@@@@@@@@@@@@@ TreeTranslator::translate @ bci:12 @@@@@@@@@@@@@@@@@@@@@ TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
295 loadConN0 === 1 [[ 294 ]] narrowoop: NULL
289 urShiftP_reg_imm === 1326 195 [[ 288 ]] #9/0x00000009
288 storeimmB0 === 1326 282 229 289 [[ 286 1059 1066 ]] memory Memory: @rawptr:BotPTR, idx=Raw; !jvms: TransTypes::translate @ bci:19 TransTypes::visitSelect @ bci:162
294 storeN === 1326 282 195 295 [[ 285 1059 1066 ]] memory Memory: @com/sun/tools/javac/comp/TransTypes:NotNull+12 * [narrow], name=result, idx=17; !jvms: ################ TreeTranslator::translate @ bci:18 ################# TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
293 storeN === 1326 282 195 278 [[ 285 1059 1066 ]] memory Memory: @com/sun/tools/javac/comp/TransTypes:NotNull+60 * [narrow], name=pt, idx=16; !jvms: TransTypes::translate @ bci:19 TransTypes::visitSelect @ bci:162
284 loadNKlass === 1326 13 1719 [[ 283 1625 ]] narrowklass: klass com/sun/tools/javac/tree/JCTree: 0x0000007e89553d20 * !jvms: TransTypes::visitSelect @ bci:165
1625 NullCheck === 1326 284 [[ 1058 98 ]]
---- After Reg Alloc ----
B31: # B180 B32 <- N105 Freq: 0.999865
295 loadConN0 === 1 [[ 294 ]] narrowoop: NULL
1878 MachSpillCopy === _ 1859 [[ 1720 289 294 293 1883 ]] Oop:com/sun/tools/javac/comp/TransTypes:NotNull *
289 urShiftP_reg_imm === 1326 1878 [[ 288 ]] #9/0x00000009
294 storeN === 1326 282 1878 295 [[ 285 1059 1066 1880 ]] memory Memory: @com/sun/tools/javac/comp/TransTypes:NotNull+12 * [narrow], name=result, idx=17; !jvms: ################ TreeTranslator::translate @ bci:18 ################# TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
1879 loadByteMapBase === 10 [[ 288 286 ]] 0x0000007f7a940000
1720 loadN === _ 282 1878 [[ 1719 ]] narrowoop: com/sun/tools/javac/tree/JCTree * needs_anti_dependence_check !orig=[281] !jvms: @@@@@@@@@@@@@@@@@@ TreeTranslator::translate @ bci:12 @@@@@@@@@@@@@@@@@@@@@ TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
1880 MachSpillCopy === _ 1875 | 294 [[ 293 ]]
288 storeimmB0 === 1326 282 1879 289 [[ 286 1059 1066 ]] memory Memory: @rawptr:BotPTR, idx=Raw; !jvms: TransTypes::translate @ bci:19 TransTypes::visitSelect @ bci:162
1719 decodeHeapOop === _ 1720 [[ 1813 284 292 ]] com/sun/tools/javac/tree/JCTree * Oop:com/sun/tools/javac/tree/JCTree * !orig=[280] !jvms: @@@@@@@@@@@@@@@@@@ TreeTranslator::translate @ bci:12 @@@@@@@@@@@@@@@@@@@@@ TransTypes::translate @ bci:12 TransTypes::visitSelect @ bci:162
293 storeN === 1326 282 1878 1880 [[ 285 1059 1066 ]] memory Memory: @com/sun/tools/javac/comp/TransTypes:NotNull+60 * [narrow], name=pt, idx=16; !jvms: TransTypes::translate @ bci:19 TransTypes::visitSelect @ bci:162
284 loadNKlass === 1326 13 1719 [[ 283 1625 ]] narrowklass: klass com/sun/tools/javac/tree/JCTree: 0x0000007e89553d20 * !jvms: TransTypes::visitSelect @ bci:165
1625 NullCheck === 1326 284 [[ 1058 98 ]]
0x0000007f7135a660: bl 0x0000007f7135b4d0 ; OopMap{[0]=Oop [8]=Oop [16]=NarrowOop [32]=Oop off=804}
;*invokevirtual accept
; - com.sun.tools.javac.tree.TreeTranslator::translate at 8 (line 58)
; - com.sun.tools.javac.comp.TransTypes::translate at 12 (line 490)
; - com.sun.tools.javac.comp.TransTypes::visitSelect at 162 (line 825)
; {virtual_call}
;; B31: # B180 B32 <- B30 Freq: 0.999865
0x0000007f7135a664: mov x11, xzr
0x0000007f7135a668: ldr x13, [sp,#32]
0x0000007f7135a66c: lsr x12, x13, #9
0x0000007f7135a670: str w11, [x13,#12] ;*putfield result
; - com.sun.tools.javac.tree.TreeTranslator::translate at 18 (line 60)
; - com.sun.tools.javac.comp.TransTypes::translate at 12 (line 490)
; - com.sun.tools.javac.comp.TransTypes::visitSelect at 162 (line 825)
0x0000007f7135a674: adrp x14, word_map_base ; {external_word}
0x0000007f7135a678: ldr w10, [x13,#12] ;*getfield result
; - com.sun.tools.javac.tree.TreeTranslator::translate at 12 (line 59)
; - com.sun.tools.javac.comp.TransTypes::translate at 12 (line 490)
; - com.sun.tools.javac.comp.TransTypes::visitSelect at 162 (line 825)
More information about the hotspot-compiler-dev
mailing list