}
}
+ FlatAtomicEnterNode curran=null;
+
private void flattenClass(ClassDescriptor cn) {
Iterator methodit=cn.getMethods();
while(methodit.hasNext()) {
currmd=(MethodDescriptor)methodit.next();
BlockNode bn=state.getMethodBody(currmd);
+
+ if (state.DSM&&currmd.getModifiers().isAtomic()) {
+ curran=new FlatAtomicEnterNode();
+ } else
+ curran=null;
NodePair np=flattenBlockNode(bn);
FlatNode fn=np.getBegin();
if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
fcunlock.addNext(rnflat);
}
} else if (state.DSM&&currmd.getModifiers().isAtomic()) {
- FlatAtomicEnterNode an=new FlatAtomicEnterNode();
- an.addNext(fn);
- fn=an;
+ curran.addNext(fn);
+ fn=curran;
if (np.getEnd().kind()!=FKind.FlatReturnNode) {
- FlatAtomicExitNode aen=new FlatAtomicExitNode();
+ FlatAtomicExitNode aen=new FlatAtomicExitNode(curran);
np.getEnd().addNext(aen);
FlatReturnNode rnflat=new FlatReturnNode(null);
aen.addNext(rnflat);
FlatNew fn=new FlatNew(td, out_temp, con.isGlobal());
TempDescriptor[] temps=new TempDescriptor[con.numArgs()];
FlatNode last=fn;
+ // Build arguments
+ for(int i=0;i<con.numArgs();i++) {
+ ExpressionNode en=con.getArg(i);
+ TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
+ temps[i]=tmp;
+ NodePair np=flattenExpressionNode(en, tmp);
+ last.addNext(np.getBegin());
+ last=np.getEnd();
+ }
+ MethodDescriptor md=con.getConstructor();
+ //Call to constructor
+ FlatCall fc=new FlatCall(md, null, out_temp, temps);
+ last.addNext(fc);
+ last=fc;
if (td.getClassDesc().hasFlags()) {
// if (con.getFlagEffects()!=null) {
FlatFlagActionNode ffan=new FlatFlagActionNode(FlatFlagActionNode.NEWOBJECT);
last.addNext(ffan);
last=ffan;
}
- //Build arguments
- for(int i=0;i<con.numArgs();i++) {
- ExpressionNode en=con.getArg(i);
- TempDescriptor tmp=TempDescriptor.tempFactory("arg",en.getType());
- temps[i]=tmp;
- NodePair np=flattenExpressionNode(en, tmp);
- last.addNext(np.getBegin());
- last=np.getEnd();
- }
- MethodDescriptor md=con.getConstructor();
- //Call to constructor
- FlatCall fc=new FlatCall(md, null, out_temp, temps);
- last.addNext(fc);
- last=fc;
return new NodePair(fn,last);
} else {
FlatNode first=null;
FlatOpNode fcomp=new FlatOpNode(tmpbool,index,temparray[i],new Operation(Operation.LT));
FlatCondBranch fcb=new FlatCondBranch(tmpbool);
+ fcb.setTrueProb(State.TRUEPROB);
+ fcb.setLoop();
//is index<temp[i]
TempDescriptor new_tmp=TempDescriptor.tempFactory("tmp",td);
FlatNew fn=new FlatNew(td, new_tmp, temparray[i+1], isglobal);
//If it is a preinc we need to store the initial value
TempDescriptor src_tmp2=pre?TempDescriptor.tempFactory("src",an.getDest().getType()):out_temp;
TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3",an.getDest().getType());
-
FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
last.addNext(ffn);
last=ffn;
- FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
- src_tmp=tmp;
- last.addNext(fon);
- last=fon;
+
+ if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+ ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+ MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+ FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+ src_tmp=tmp;
+ last.addNext(fc);
+ last=fc;
+ } else {
+ FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+ src_tmp=tmp;
+ last.addNext(fon);
+ last=fon;
+ }
}
FlatSetFieldNode fsfn=new FlatSetFieldNode(dst_tmp, fan.getField(), src_tmp);
FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp2);
last.addNext(fen);
last=fen;
- FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
- src_tmp=tmp;
- last.addNext(fon);
- last=fon;
+
+ if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+ ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+ MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+ FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+ src_tmp=tmp;
+ last.addNext(fc);
+ last=fc;
+ } else {
+
+
+ FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+ src_tmp=tmp;
+ last.addNext(fon);
+ last=fon;
+ }
}
FlatFieldNode ffn=new FlatFieldNode(fan.getField(), dst_tmp, src_tmp2);
last.addNext(ffn);
last=ffn;
- FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
- src_tmp=tmp;
- last.addNext(fon);
- last=fon;
+
+
+ if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+ ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+ MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+ FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+ src_tmp=tmp;
+ last.addNext(fc);
+ last=fc;
+ } else {
+ FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+ src_tmp=tmp;
+ last.addNext(fon);
+ last=fon;
+ }
}
last.addNext(ffn);
}
last=ffn;
- FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
- src_tmp=tmp;
- last.addNext(fon);
- last=fon;
+
+
+ if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+ ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+ MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+ FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+ src_tmp=tmp;
+ last.addNext(fc);
+ last=fc;
+ } else {
+ FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+ src_tmp=tmp;
+ last.addNext(fon);
+ last=fon;
+ }
}
FlatSetFieldNode fsfn=new FlatSetFieldNode(getTempforVar(nn.getVar()), nn.getField(), src_tmp);
last=fon;
}
- FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
- if (first==null)
- first=fon;
- else
- last.addNext(fon);
- src_tmp=tmp;
- last=fon;
+
+ if (base.getOp()==Operation.ADD&&an.getDest().getType().isString()) {
+ ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+ MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat2", new TypeDescriptor[] {new TypeDescriptor(stringcd), new TypeDescriptor(stringcd)});
+ FlatCall fc=new FlatCall(concatmd, tmp, null, new TempDescriptor[] {src_tmp2, src_tmp});
+ if (first==null)
+ first=fc;
+ else
+ last.addNext(fc);
+ src_tmp=tmp;
+ last=fc;
+ } else {
+ FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
+ if (first==null)
+ first=fon;
+ else
+ last.addNext(fon);
+ src_tmp=tmp;
+ last=fon;
+ }
}
FlatOpNode fon=new FlatOpNode(getTempforVar(nn.getVar()), src_tmp, null, new Operation(Operation.ASSIGN));
TempDescriptor temp_right=null;
Operation op=on.getOp();
- /* We've moved this to assignment nodes
-
- if (op.getOp()==Operation.POSTINC||
- op.getOp()==Operation.POSTDEC||
- op.getOp()==Operation.PREINC||
- op.getOp()==Operation.PREDEC) {
- LiteralNode ln=new LiteralNode("int",new Integer(1));
- ln.setType(new TypeDescriptor(TypeDescriptor.INT));
-
- AssignmentNode an=new AssignmentNode(on.getLeft(),
- new OpNode(on.getLeft(),ln,
- new Operation((op.getOp()==Operation.POSTINC||op.getOp()==Operation.PREINC)?Operation.PLUS:Operation.MINUS))
- );
- if (op.getOp()==Operation.POSTINC||
- op.getOp()==Operation.POSTDEC) {
- //Can't do, this could have side effects
- NodePair left=flattenExpressionNode(on.getLeft(),out_temp);
- NodePair assign=flattenAssignmentNode(an,temp_left);
- left.getEnd().addNext(assign.getBegin());
- return new NodePair(left.getBegin(),assign.getEnd());
- } else {
- NodePair assign=flattenAssignmentNode(an,out_temp);
- return assign;
- }
- } */
-
+
NodePair left=flattenExpressionNode(on.getLeft(),temp_left);
NodePair right;
if (on.getRight()!=null) {
fcb.addFalseNext(fon1);
fon1.addNext(fnop);
return new NodePair(left.getBegin(), fnop);
+ } else if (op.getOp()==Operation.ADD&&on.getLeft().getType().isString()) {
+ //We have a string concatenate
+ ClassDescriptor stringcd=typeutil.getClass(TypeUtil.StringClass);
+ MethodDescriptor concatmd=typeutil.getMethod(stringcd, "concat", new TypeDescriptor[] {new TypeDescriptor(stringcd)});
+ FlatCall fc=new FlatCall(concatmd, out_temp, temp_left, new TempDescriptor[] {temp_right});
+ left.getEnd().addNext(right.getBegin());
+ right.getEnd().addNext(fc);
+ return new NodePair(left.getBegin(), fc);
}
FlatOpNode fon=new FlatOpNode(out_temp,temp_left,temp_right,op);
NodePair body=flattenBlockNode(ln.getBody());
FlatNode begin=initializer.getBegin();
FlatCondBranch fcb=new FlatCondBranch(cond_temp);
+ fcb.setTrueProb(State.TRUEPROB);
+ fcb.setLoop();
FlatNop nopend=new FlatNop();
FlatBackEdge backedge=new FlatBackEdge();
- initializer.getEnd().addNext(condition.getBegin());
+ FlatNop nop2=new FlatNop();
+ initializer.getEnd().addNext(nop2);
+ nop2.addNext(condition.getBegin());
body.getEnd().addNext(update.getBegin());
update.getEnd().addNext(backedge);
backedge.addNext(condition.getBegin());
NodePair body=flattenBlockNode(ln.getBody());
FlatNode begin=condition.getBegin();
FlatCondBranch fcb=new FlatCondBranch(cond_temp);
+ fcb.setTrueProb(State.TRUEPROB);
+ fcb.setLoop();
FlatNop nopend=new FlatNop();
FlatBackEdge backedge=new FlatBackEdge();
NodePair body=flattenBlockNode(ln.getBody());
FlatNode begin=body.getBegin();
FlatCondBranch fcb=new FlatCondBranch(cond_temp);
+ fcb.setTrueProb(State.TRUEPROB);
+ fcb.setLoop();
FlatNop nopend=new FlatNop();
FlatBackEdge backedge=new FlatBackEdge();
MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
TempDescriptor thistd=getTempforVar(currmd.getThis());
FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
- fc.addNext(rnflat);
+ fc.addNext(ln);
ln=fc;
}
+ if (state.DSM&&currmd.getModifiers().isAtomic()) {
+ FlatAtomicExitNode faen=new FlatAtomicExitNode(curran);
+ faen.addNext(ln);
+ ln=faen;
+ }
if (cond!=null) {
cond.getEnd().addNext(ln);
private NodePair flattenAtomicNode(AtomicNode sbn) {
NodePair np=flattenBlockNode(sbn.getBlockNode());
FlatAtomicEnterNode faen=new FlatAtomicEnterNode();
- FlatAtomicExitNode faexn=new FlatAtomicExitNode();
+ FlatAtomicExitNode faexn=new FlatAtomicExitNode(faen);
faen.addNext(np.getBegin());
np.getEnd().addNext(faexn);
return new NodePair(faen, faexn);