Preventing duplicate field access

This commit is contained in:
upnotes
2018-10-03 17:19:32 +02:00
parent 5650f57ad2
commit c3ff7141ab
7 changed files with 159 additions and 11 deletions

View File

@@ -178,7 +178,7 @@ public class SimplifyExprentsHelper {
}
// expr++ and expr--
if (isIPPorIMM(current, next)) {
if (isIPPorIMM(current, next) || isIPPorIMM2(current, next)) {
list.remove(index + 1);
res = true;
continue;
@@ -458,6 +458,48 @@ public class SimplifyExprentsHelper {
return false;
}
private static boolean isIPPorIMM2(Exprent first, Exprent second) {
if (first.type != Exprent.EXPRENT_ASSIGNMENT || second.type != Exprent.EXPRENT_ASSIGNMENT) {
return false;
}
AssignmentExprent af = (AssignmentExprent)first;
AssignmentExprent as = (AssignmentExprent)second;
if(as.getRight().type != Exprent.EXPRENT_FUNCTION) {
return false;
}
FunctionExprent func = (FunctionExprent)as.getRight();
if(func.getFuncType() != FunctionExprent.FUNCTION_ADD && func.getFuncType() != FunctionExprent.FUNCTION_SUB) {
return false;
}
Exprent econd = func.getLstOperands().get(0);
Exprent econst = func.getLstOperands().get(1);
if(econst.type != Exprent.EXPRENT_CONST && econd.type == Exprent.EXPRENT_CONST && func.getFuncType() == FunctionExprent.FUNCTION_ADD) {
econd = econst;
econst = func.getLstOperands().get(0);
}
if(econst.type == Exprent.EXPRENT_CONST && ((ConstExprent)econst).hasValueOne()) {
if(af.getLeft().equals(econd) && af.getRight().equals(as.getLeft()) && (af.getLeft().getExprentUse() & Exprent.MULTIPLE_USES) != 0) {
int type = func.getFuncType() == FunctionExprent.FUNCTION_ADD ? FunctionExprent.FUNCTION_IPP : FunctionExprent.FUNCTION_IMM;
FunctionExprent ret = new FunctionExprent(type, af.getRight(), func.bytecode);
ret.setImplicitType(VarType.VARTYPE_INT);
af.setRight(ret);
return true;
}
}
return false;
}
private static boolean isMonitorExit(Exprent first) {
if (first.type == Exprent.EXPRENT_MONITOR) {
MonitorExprent expr = (MonitorExprent)first;

View File

@@ -134,8 +134,9 @@ public class DominatorTreeExceptionFilter {
exit = childid;
}
else {
// exit = map.containsKey(handler)?-1:mapChild.get(handler); FIXME: Eclipse bug?
exit = map.containsKey(handler) ? -1 : mapChild.get(handler);
// after replacing 'new Integer(-1)' with '-1' Eclipse throws a NullPointerException on the following line
// could be a bug in Eclipse or some obscure specification glitch, FIXME: needs further investigation
exit = map.containsKey(handler) ? new Integer(-1) : mapChild.get(handler);
}
if (exit != null) {

View File

@@ -54,7 +54,7 @@ public class FieldExprent extends Exprent {
@Override
public int getExprentUse() {
return instance == null ? Exprent.MULTIPLE_USES : instance.getExprentUse() & Exprent.MULTIPLE_USES;
return 0; // multiple references to a field considered dangerous in a multithreaded environment, thus no Exprent.MULTIPLE_USES set here
}
@Override