but it lets us declare intwrapper, doublewrapper types which work just like the primitives but are really objects behind the scenes
/**
* Number of points in each cluster [nclusters]
**/
- public int[] new_centers_len;
+ public intwrapper[] new_centers_len;
/**
* New centers of the clusters [nclusters][nfeatures]
int nclusters = args.nclusters;
int[] membership = args.membership;
double[][] clusters = args.clusters;
- int[] new_centers_len = args.new_centers_len;
+ intwrapper[] new_centers_len = args.new_centers_len;
double[][] new_centers = args.new_centers;
double delta = 0.0;
int index, start, stop;
* Need to initialize new_centers_len and new_centers[0] to all 0.
* Allocate clusters on different cache lines to reduce false sharing.
*/
- int[] new_centers_len = new int[nclusters];
+ intwrapper[] new_centers_len = new intwrapper[nclusters];
+
double[][] new_centers = new double[nclusters][nfeatures];
int loop = 0;
Common.java \
GlobalArgs.java \
../../../ClassLibrary/JavaSTM/Barrier.java
-FLAGS=-mainclass ${MAINCLASS} -singleTM -optimize -debug -dcopts -joptimize -transstats -stmstats
-FLAGS2=-mainclass ${MAINCLASS} -singleTM -optimize -debug -dcopts -joptimize -transstats
+FLAGS=-mainclass ${MAINCLASS} -singleTM -optimize -debug -dcopts -joptimize -stmstats -fastmemcpy
+FLAGS2=-mainclass ${MAINCLASS} -singleTM -optimize -debug -joptimize -dcopts -fastmemcpy
FLAGS3=-mainclass ${MAINCLASS} -optimize -debug -joptimize -thread
default:
- ../../../buildscript ${FLAGS} -o ${MAINCLASS} ${SRC}
- ../../../buildscript ${FLAGS3} -o LOCK${MAINCLASS} ${SRC}
../../../buildscript ${FLAGS2} -o GEN${MAINCLASS} ${SRC}
clean:
NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal());
fn.addNext(np.getBegin());
return new NodePair(first,np.getEnd());
+ } else if (td.isArray()&&td.dereference().iswrapper()) {
+ NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal());
+ fn.addNext(np.getBegin());
+ return new NodePair(first,np.getEnd());
} else
return new NodePair(first, fn);
}
fcb.setLoop();
//is index<temp[i]
TempDescriptor new_tmp=TempDescriptor.tempFactory("tmp",td);
- FlatNew fn=new FlatNew(td, new_tmp, temparray[i+1], isglobal);
+ FlatNew fn=td.iswrapper()?new FlatNew(td, new_tmp, isglobal):new FlatNew(td, new_tmp, temparray[i+1], isglobal);
FlatSetElementNode fsen=new FlatSetElementNode(tmp,index,new_tmp);
// index=index+1
FlatOpNode fon=new FlatOpNode(index,index,tmpone,new Operation(Operation.ADD));
NodePair np2=generateNewArrayLoop(temparray, td.dereference(), new_tmp, i+1, isglobal);
fsen.addNext(np2.getBegin());
np2.getEnd().addNext(fon);
+ } else if (td.isArray()&&td.dereference().iswrapper()) {
+ NodePair np2=generateNewArrayLoop(temparray, td.dereference(), new_tmp, i+1, isglobal);
+ fsen.addNext(np2.getBegin());
+ np2.getEnd().addNext(fon);
} else {
fsen.addNext(fon);
}
TempDescriptor tmpindex=TempDescriptor.tempFactory("temp",aan.getIndex().getType());
NodePair npe=flattenExpressionNode(aan.getExpression(),tmp);
NodePair npi=flattenExpressionNode(aan.getIndex(),tmpindex);
- FlatElementNode fn=new FlatElementNode(tmp,tmpindex,out_temp);
+ TempDescriptor arraytmp=out_temp;
+ if (aan.iswrapper()) {
+ //have wrapper
+ arraytmp=TempDescriptor.tempFactory("temp", aan.getExpression().getType().dereference());
+ }
+ FlatNode fn=new FlatElementNode(tmp,tmpindex,arraytmp);
npe.getEnd().addNext(npi.getBegin());
npi.getEnd().addNext(fn);
+ if (aan.iswrapper()) {
+ FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)aan.getExpression().getType().dereference().getClassDesc().getFieldTable().get("value") ,arraytmp,out_temp);
+ fn.addNext(ffn);
+ fn=ffn;
+ }
return new NodePair(npe.getBegin(),fn);
}
} else if (an.getDest().kind()==Kind.ArrayAccessNode) {
//We are assigning an array element
-
ArrayAccessNode aan=(ArrayAccessNode)an.getDest();
ExpressionNode en=aan.getExpression();
ExpressionNode enindex=aan.getIndex();
TempDescriptor src_tmp2=pre ? TempDescriptor.tempFactory("src",an.getDest().getType()) : out_temp;
TempDescriptor tmp=TempDescriptor.tempFactory("srctmp3_",an.getDest().getType());
- FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp2);
- last.addNext(fen);
- last=fen;
-
+ if (aan.iswrapper()) {
+ TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
+ TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
+ FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
+ FlatFieldNode ffn=new FlatFieldNode((FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp3,src_tmp2);
+ last.addNext(fen);
+ fen.addNext(ffn);
+ last=ffn;
+ } else {
+ FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp2);
+ last.addNext(fen);
+ last=fen;
+ }
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)});
last.addNext(fc);
last=fc;
} else {
-
-
FlatOpNode fon=new FlatOpNode(tmp, src_tmp2, src_tmp, base);
src_tmp=tmp;
last.addNext(fon);
}
}
-
- FlatSetElementNode fsen=new FlatSetElementNode(dst_tmp, index_tmp, src_tmp);
- last.addNext(fsen);
- last=fsen;
+ if (aan.iswrapper()) {
+ TypeDescriptor arrayeltype=aan.getExpression().getType().dereference();
+ TempDescriptor src_tmp3=TempDescriptor.tempFactory("src3",arrayeltype);
+ FlatElementNode fen=new FlatElementNode(dst_tmp, index_tmp, src_tmp3);
+ FlatSetFieldNode fsfn=new FlatSetFieldNode(src_tmp3,(FieldDescriptor)arrayeltype.getClassDesc().getFieldTable().get("value"),src_tmp);
+ last.addNext(fen);
+ fen.addNext(fsfn);
+ last=fsfn;
+ } else {
+ FlatSetElementNode fsen=new FlatSetElementNode(dst_tmp, index_tmp, src_tmp);
+ last.addNext(fsen);
+ last=fsen;
+ }
if (pre) {
FlatOpNode fon2=new FlatOpNode(out_temp, src_tmp, null, new Operation(Operation.ASSIGN));
- fsen.addNext(fon2);
+ last.addNext(fon2);
last=fon2;
}
return new NodePair(first, last);
public class ArrayAccessNode extends ExpressionNode {
ExpressionNode left;
ExpressionNode index;
+ TypeDescriptor wrappertype;
public ArrayAccessNode(ExpressionNode l, ExpressionNode index) {
this.index=index;
return Kind.ArrayAccessNode;
}
+ public boolean iswrapper() {
+ return wrappertype!=null;
+ }
+
public TypeDescriptor getType() {
- return left.getType().dereference();
+ if (wrappertype!=null)
+ return wrappertype;
+ else
+ return left.getType().dereference();
}
}
public TypeDescriptor getType() {
if (en!=null)
return en.getType();
- else if (fd!=null)
+ else if (fd!=null) {
return fd.getType();
- else if (isTag())
+ } else if (isTag())
return new TypeDescriptor(TypeDescriptor.TAG);
else
return ((VarDescriptor)vd).getType();
fd=(FieldDescriptor) ltd.getClassDesc().getFieldTable().get(fieldname);
if (fd==null)
throw new Error("Unknown field "+fieldname + " in "+fan.printNode(0)+" in "+md);
+ if (fd.getType().iswrapper()) {
+ FieldAccessNode fan2=new FieldAccessNode(left, fieldname);
+ fan2.setField(fd);
+ fan.left=fan2;
+ fan.fieldname="value";
+ ExpressionNode leftwr=fan.getExpression();
+ checkExpressionNode(md,nametable,leftwr,null);
+ TypeDescriptor ltdwr=leftwr.getType();
+ String fieldnamewr=fan.getFieldName();
+ FieldDescriptor fdwr=(FieldDescriptor) ltdwr.getClassDesc().getFieldTable().get(fieldnamewr);
+ if (fdwr==null)
+ throw new Error("Unknown field "+fieldnamewr + " in "+fan.printNode(0)+" in "+md);
+ }
fan.setField(fd);
- if (td!=null)
+
+ if (td!=null) {
if (!typeutil.isSuperorType(td,fan.getType()))
throw new Error("Field node returns "+fan.getType()+", but need "+td);
+ }
}
void checkArrayAccessNode(Descriptor md, SymbolTable nametable, ArrayAccessNode aan, TypeDescriptor td) {
checkExpressionNode(md,nametable,aan.getIndex(),new TypeDescriptor(TypeDescriptor.INT));
TypeDescriptor ltd=left.getType();
+ if (ltd.dereference().iswrapper()) {
+ aan.wrappertype=((FieldDescriptor)ltd.dereference().getClassDesc().getFieldTable().get("value")).getType();
+ }
+
if (td!=null)
if (!typeutil.isSuperorType(td,aan.getType()))
throw new Error("Field node returns "+aan.getType()+", but need "+td);
if (d instanceof VarDescriptor) {
nn.setVar(d);
} else if (d instanceof FieldDescriptor) {
- nn.setField((FieldDescriptor)d);
- nn.setVar((VarDescriptor)nametable.get("this")); /* Need a pointer to this */
+ FieldDescriptor fd=(FieldDescriptor)d;
+ if (fd.getType().iswrapper()) {
+ String id=nd.getIdentifier();
+ NameDescriptor base=nd.getBase();
+ NameNode n=new NameNode(nn.getName());
+ n.setField(fd);
+ n.setVar((VarDescriptor)nametable.get("this")); /* Need a pointer to this */
+ FieldAccessNode fan=new FieldAccessNode(n,"value");
+ nn.setExpression(fan);
+ checkExpressionNode(md,nametable,fan,td);
+ } else {
+ nn.setField(fd);
+ nn.setVar((VarDescriptor)nametable.get("this")); /* Need a pointer to this */
+ }
} else if (d instanceof TagVarDescriptor) {
nn.setVar(d);
} else throw new Error("Wrong type of descriptor");
return hashcode;
}
+ public boolean iswrapper() {
+ if (arraycount!=0||!isClass())
+ return false;
+ return (name.equals("bytewrapper")||
+ name.equals("booleanwrapper")||
+ name.equals("shortwrapper")||
+ name.equals("intwrapper")||
+ name.equals("longwrapper")||
+ name.equals("charwrapper")||
+ name.equals("floatwrapper")||
+ name.equals("doublewrapper")||
+ name.equals("objectwrapper"));
+ }
+
public TypeDescriptor makeArray(State state) {
TypeDescriptor td=new TypeDescriptor(getSymbol());
td.arraycount=arraycount+1;
}
} //end of for
- //THIS IS THE SERIALIZATION POINT *****
+ //THIS IS THE SERIALIZATION END POINT (START POINT IS END OF EXECUTION)*****
for(i=0; i<numoidrdlocked; i++) {
/* Read from the main heap and compare versions */
}
curr = curr->lnext;
}
- //THIS IS THE SERIALIZATION POINT *****
- for(i=numoidrdlocked-1; i>=0; i--) {
+
+
+ //THIS IS THE SERIALIZATION END POINT (START POINT IS END OF EXECUTION)*****
+
+ for(i=0; i<numoidrdlocked; i++) {
objheader_t * header=oidrdlocked[i];
unsigned int version=oidrdversion[i];
if(header->lock>=0) {
typedef struct objheader {
unsigned int version;
unsigned int lock; /* reader and writer lock for object header */
+#ifdef STMSTATS
int abortCount; /* track how many times does this object cause abort */
int accessCount; /* track how many times is this object accessed */
threadrec_t *trec; /* some thread that locked this object */
int riskyflag; /* track how risky is the object */
pthread_mutex_t *objlock; /* lock this object */
+ int padding;
+#endif
} objheader_t;
#define OID(x) \