@@ -416,6 +416,10 @@ public final class BytecodeNode extends AbstractInstrumentableBytecodeNode imple
416
416
@ CompilationFinal (dimensions = 1 ) //
417
417
private final int [] stackOverflowErrorInfo ;
418
418
419
+ /**
420
+ * Outer array should be seen and used as a {@code @CompilationFinal volatile} array, while
421
+ * inner arrays can be seen as {@code final} arrays.
422
+ */
419
423
@ CompilationFinal (dimensions = 2 ) //
420
424
private volatile int [][] jsrBci = null ;
421
425
@@ -1059,14 +1063,17 @@ Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop, int st
1059
1063
if (VolatileArrayAccess .volatileRead (jsrBci , retOpBci ) != null ) {
1060
1064
return ;
1061
1065
}
1062
- // Be very careful on updating the known target bcis, as if another
1063
- // thread reads the not fully initialized array, it may consider 0
1064
- // to be a valid RET target, completely breaking PE.
1065
- int [] targets = new int [1 ];
1066
- VolatileArrayAccess .volatileWrite (targets , 0 , targetBCI );
1066
+ /*
1067
+ * Be very careful on updating the known target bcis, as if another
1068
+ * thread reads the not fully initialized array, it may consider 0
1069
+ * to be a valid RET target, completely breaking PE.
1070
+ */
1071
+ int [] targets = new int []{targetBCI };
1072
+ // Also serves as a "final publication" barrier for the assignment
1073
+ // above.
1067
1074
VolatileArrayAccess .volatileWrite (jsrBci , retOpBci , targets );
1068
1075
});
1069
- knownRets = knownTargets [ retOpBci ] ;
1076
+ knownRets = VolatileArrayAccess . volatileRead ( knownTargets , retOpBci ) ;
1070
1077
}
1071
1078
assert knownRets != null ;
1072
1079
@@ -1093,10 +1100,14 @@ Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop, int st
1093
1100
}
1094
1101
}
1095
1102
int [] updatedTargets = Arrays .copyOf (currentRets , currentRets .length + 1 );
1096
- // Be very careful on updating the known target bcis, as if another
1097
- // thread reads the not fully initialized array, it may consider 0 to be
1098
- // a valid RET target, completely breaking PE.
1099
- VolatileArrayAccess .volatileWrite (updatedTargets , updatedTargets .length - 1 , targetBCI );
1103
+ /*
1104
+ * Be very careful on updating the known target bcis, as if another
1105
+ * thread reads the not fully initialized array, it may consider 0 to be
1106
+ * a valid RET target, completely breaking PE.
1107
+ */
1108
+ updatedTargets [updatedTargets .length - 1 ] = targetBCI ;
1109
+ // Also serves as a "final publication" barrier for the assignment
1110
+ // above.
1100
1111
VolatileArrayAccess .volatileWrite (jsrBci , retOpBci , updatedTargets );
1101
1112
});
1102
1113
top += Bytecodes .stackEffectOf (RET );
@@ -1293,16 +1304,18 @@ Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop, int st
1293
1304
if (VolatileArrayAccess .volatileRead (jsrBci , retOpBci ) != null ) {
1294
1305
return ;
1295
1306
}
1296
- // Be very careful on updating the known target bcis, as if
1297
- // another
1298
- // thread reads the not fully initialized array, it may
1299
- // consider 0
1300
- // to be a valid RET target, completely breaking PE.
1301
- int [] targets = new int [1 ];
1302
- VolatileArrayAccess .volatileWrite (targets , 0 , targetBCI );
1307
+ /*
1308
+ * Be very careful on updating the known target bcis, as if
1309
+ * another thread reads the not fully initialized array, it
1310
+ * may consider 0 to be a valid RET target, completely
1311
+ * breaking PE.
1312
+ */
1313
+ int [] targets = new int []{targetBCI };
1314
+ // Also serves as a "final publication" barrier for the
1315
+ // assignment above.
1303
1316
VolatileArrayAccess .volatileWrite (jsrBci , retOpBci , targets );
1304
1317
});
1305
- knownRets = knownTargets [ retOpBci ] ;
1318
+ knownRets = VolatileArrayAccess . volatileRead ( knownTargets , retOpBci ) ;
1306
1319
}
1307
1320
assert knownRets != null ;
1308
1321
@@ -1329,12 +1342,14 @@ Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop, int st
1329
1342
}
1330
1343
}
1331
1344
int [] updatedTargets = Arrays .copyOf (currentRets , currentRets .length + 1 );
1332
- // Be very careful on updating the known target bcis, as if
1333
- // another
1334
- // thread reads the not fully initialized array, it may consider
1335
- // 0 to be
1336
- // a valid RET target, completely breaking PE.
1337
- VolatileArrayAccess .volatileWrite (updatedTargets , updatedTargets .length - 1 , targetBCI );
1345
+ /*
1346
+ * Be very careful on updating the known target bcis, as if
1347
+ * another thread reads the not fully initialized array, it may
1348
+ * consider 0 to be a valid RET target, completely breaking PE.
1349
+ */
1350
+ updatedTargets [updatedTargets .length - 1 ] = targetBCI ;
1351
+ // Also serves as a "final publication" barrier for the
1352
+ // assignment above.
1338
1353
VolatileArrayAccess .volatileWrite (jsrBci , retOpBci , updatedTargets );
1339
1354
});
1340
1355
top += Bytecodes .stackEffectOf (RET );
0 commit comments