Skip to content
Snippets Groups Projects
Commit 51656aa7 authored by Lukas Stadler's avatar Lukas Stadler
Browse files

[GR-2313] Thread safety issues in FrameSlotInfo, avoid problem with ExactMath.multiplyExact.

parents d4836e13 828fe94f
No related branches found
No related tags found
No related merge requests found
...@@ -517,38 +517,43 @@ public final class FrameSlotChangeMonitor { ...@@ -517,38 +517,43 @@ public final class FrameSlotChangeMonitor {
*/ */
private void setValue(boolean value, FrameSlot slot) { private void setValue(boolean value, FrameSlot slot) {
if (stableValue != null && (!(stableValue.getValue() instanceof Boolean) || ((boolean) stableValue.getValue()) != value)) { StableValue<Object> sv = stableValue;
invalidateStableValue(value, slot); if (sv != null && (!(sv.getValue() instanceof Boolean) || ((boolean) sv.getValue()) != value)) {
invalidateStableValue(sv, value, slot);
} }
} }
private void setValue(byte value, FrameSlot slot) { private void setValue(byte value, FrameSlot slot) {
if (stableValue != null && (!(stableValue.getValue() instanceof Byte) || ((byte) stableValue.getValue()) != value)) { StableValue<Object> sv = stableValue;
invalidateStableValue(value, slot); if (sv != null && (!(sv.getValue() instanceof Byte) || ((byte) sv.getValue()) != value)) {
invalidateStableValue(sv, value, slot);
} }
} }
private void setValue(int value, FrameSlot slot) { private void setValue(int value, FrameSlot slot) {
if (stableValue != null && (!(stableValue.getValue() instanceof Integer) || ((int) stableValue.getValue()) != value)) { StableValue<Object> sv = stableValue;
invalidateStableValue(value, slot); if (sv != null && (!(sv.getValue() instanceof Integer) || ((int) sv.getValue()) != value)) {
invalidateStableValue(sv, value, slot);
} }
} }
private void setValue(double value, FrameSlot slot) { private void setValue(double value, FrameSlot slot) {
if (stableValue != null && (!(stableValue.getValue() instanceof Double) || ((double) stableValue.getValue()) != value)) { StableValue<Object> sv = stableValue;
invalidateStableValue(value, slot); if (sv != null && (!(sv.getValue() instanceof Double) || ((double) sv.getValue()) != value)) {
invalidateStableValue(sv, value, slot);
} }
} }
private void setValue(Object value, FrameSlot slot) { private void setValue(Object value, FrameSlot slot) {
if (stableValue != null && stableValue.getValue() != value) { StableValue<Object> sv = stableValue;
invalidateStableValue(value, slot); if (sv != null && sv.getValue() != value) {
invalidateStableValue(sv, value, slot);
} }
} }
private void invalidateStableValue(Object value, FrameSlot slot) { private void invalidateStableValue(StableValue<Object> sv, Object value, FrameSlot slot) {
CompilerDirectives.transferToInterpreterAndInvalidate(); CompilerDirectives.transferToInterpreterAndInvalidate();
stableValue.getAssumption().invalidate(); sv.getAssumption().invalidate();
if (invalidationCount > 0) { if (invalidationCount > 0) {
invalidationCount--; invalidationCount--;
out("setting singleton value %s = %s", slot.getIdentifier(), value == null ? "null" : value.getClass()); out("setting singleton value %s = %s", slot.getIdentifier(), value == null ? "null" : value.getClass());
......
...@@ -136,13 +136,14 @@ public abstract class BinaryArithmetic extends Operation { ...@@ -136,13 +136,14 @@ public abstract class BinaryArithmetic extends Operation {
@Override @Override
public int op(int left, int right) { public int op(int left, int right) {
try { int r = left + right;
return ExactMath.addExact(left, right); // TODO: not using ExactMath because of perf problems
} catch (ArithmeticException e) { if (((left ^ r) & (right ^ r)) < 0) {
CompilerDirectives.transferToInterpreterAndInvalidate(); CompilerDirectives.transferToInterpreterAndInvalidate();
replace(new AddOverflow()); replace(new AddOverflow());
return INT_NA; return INT_NA;
} }
return r;
} }
@Override @Override
...@@ -193,13 +194,14 @@ public abstract class BinaryArithmetic extends Operation { ...@@ -193,13 +194,14 @@ public abstract class BinaryArithmetic extends Operation {
@Override @Override
public int op(int left, int right) { public int op(int left, int right) {
try { int r = left - right;
return ExactMath.subtractExact(left, right); // TODO: not using ExactMath because of perf problems
} catch (ArithmeticException e) { if (((left ^ right) & (left ^ r)) < 0) {
CompilerDirectives.transferToInterpreterAndInvalidate(); CompilerDirectives.transferToInterpreterAndInvalidate();
replace(new SubtractOverflow()); replace(new SubtractOverflow());
return INT_NA; return INT_NA;
} }
return r;
} }
@Override @Override
...@@ -249,13 +251,14 @@ public abstract class BinaryArithmetic extends Operation { ...@@ -249,13 +251,14 @@ public abstract class BinaryArithmetic extends Operation {
@Override @Override
public int op(int left, int right) { public int op(int left, int right) {
try { long r = (long) left * (long) right;
return ExactMath.multiplyExact(left, right); // TODO: not using ExactMath because of perf problems
} catch (ArithmeticException e) { if ((int) r != r) {
CompilerDirectives.transferToInterpreterAndInvalidate(); CompilerDirectives.transferToInterpreterAndInvalidate();
replace(new MultiplyOverflow()); replace(new MultiplyOverflow());
return INT_NA; return INT_NA;
} }
return (int) r;
} }
@Override @Override
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment