Skip to content

Commit 537f8d7

Browse files
committed
jsr/ret mapping array: outer should be volatile final, inners can be simple final.
1 parent 05bf7a0 commit 537f8d7

File tree

1 file changed

+39
-24
lines changed
  • espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes

1 file changed

+39
-24
lines changed

espresso/src/com.oracle.truffle.espresso/src/com/oracle/truffle/espresso/nodes/BytecodeNode.java

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ public final class BytecodeNode extends AbstractInstrumentableBytecodeNode imple
416416
@CompilationFinal(dimensions = 1) //
417417
private final int[] stackOverflowErrorInfo;
418418

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+
*/
419423
@CompilationFinal(dimensions = 2) //
420424
private volatile int[][] jsrBci = null;
421425

@@ -1059,14 +1063,17 @@ Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop, int st
10591063
if (VolatileArrayAccess.volatileRead(jsrBci, retOpBci) != null) {
10601064
return;
10611065
}
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.
10671074
VolatileArrayAccess.volatileWrite(jsrBci, retOpBci, targets);
10681075
});
1069-
knownRets = knownTargets[retOpBci];
1076+
knownRets = VolatileArrayAccess.volatileRead(knownTargets, retOpBci);
10701077
}
10711078
assert knownRets != null;
10721079

@@ -1093,10 +1100,14 @@ Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop, int st
10931100
}
10941101
}
10951102
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.
11001111
VolatileArrayAccess.volatileWrite(jsrBci, retOpBci, updatedTargets);
11011112
});
11021113
top += Bytecodes.stackEffectOf(RET);
@@ -1293,16 +1304,18 @@ Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop, int st
12931304
if (VolatileArrayAccess.volatileRead(jsrBci, retOpBci) != null) {
12941305
return;
12951306
}
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.
13031316
VolatileArrayAccess.volatileWrite(jsrBci, retOpBci, targets);
13041317
});
1305-
knownRets = knownTargets[retOpBci];
1318+
knownRets = VolatileArrayAccess.volatileRead(knownTargets, retOpBci);
13061319
}
13071320
assert knownRets != null;
13081321

@@ -1329,12 +1342,14 @@ Object executeBodyFromBCI(VirtualFrame frame, int startBCI, int startTop, int st
13291342
}
13301343
}
13311344
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.
13381353
VolatileArrayAccess.volatileWrite(jsrBci, retOpBci, updatedTargets);
13391354
});
13401355
top += Bytecodes.stackEffectOf(RET);

0 commit comments

Comments
 (0)