diff --git a/site.properties b/site.properties index 7c7cb341..639bba5c 100644 --- a/site.properties +++ b/site.properties @@ -5,7 +5,7 @@ # can only expand system properties #jpf-core = ${user.home}/IdeaProjects/VarexJ -jpf-core = ${user.dir} +jpf-core = ${user.home}/Documents/package/jpf-core jpf-nhandler = ${jpf-core}/jpf-nhandler extensions = ${jpf-core},${jpf-nhandler} diff --git a/src/main/gov/nasa/jpf/vm/va/DataCollect.java b/src/main/gov/nasa/jpf/vm/va/DataCollect.java deleted file mode 100644 index 6cb62d07..00000000 --- a/src/main/gov/nasa/jpf/vm/va/DataCollect.java +++ /dev/null @@ -1,80 +0,0 @@ -package gov.nasa.jpf.vm.va; - -import java.util.*; - -public class DataCollect { - public Integer numCopy = 0; - public StackHandler owner; - // change name - Integer size = 0; - Integer max = 0; - Integer min = 0; - Integer ave = 0; - Integer gmax = 0; - - - public DataCollect(StackHandler sh){ - this.owner = sh; - } - - public void set(Integer size, Integer min, Integer max, Integer ave) { - this.size = size; - this.max = max; - this.min = min; - this.ave = ave; - } - - - public void setMin(Integer min){ - this.min = min; - } - - public void push(){ - calculate(); -// System.out.println("PUSH"); -// System.out.println(owner.toString()); -// System.out.println(this.toString()); - } - - public void pop(){ - calculate(); -// System.out.println("POP"); -// System.out.println(owner.toString()); -// System.out.println(this.toString()); - } - - public void dup(){ - calculate(); -// System.out.println("DUP"); -// System.out.println(owner.toString()); -// System.out.println(this.toString()); - } - - public void calculate(){ - List temp = owner.getTop().toList(); - Integer len = temp.size(); - Integer sum = temp.get(0) + 1; - max = temp.get(0) + 1; - min = temp.get(0) + 1; - if(max > gmax){ - gmax = max; - } - for(int i = 1; i < len; i++){ - if(temp.get(i) + 1 > gmax){ - this.gmax = temp.get(i) + 1; - } - if(temp.get(i) + 1 > max) - this.max = temp.get(i) + 1; - if(temp.get(i) + 1 < min){ - this.min = temp.get(i) + 1; - } - sum += temp.get(i) + 1; - } - this.ave = sum/len; - this.size = len; - } - - public String toString(){ - return "The size is " + this.size + "\nMinimun elements is "+ this.min + "\nMaximum elements is " +this.max + "\nAverage is " + this.ave + "\nNumbers of copys " + this.numCopy + "\ngmax is "+ this.gmax+ "\n"; - } -} diff --git a/src/main/gov/nasa/jpf/vm/va/Log.java b/src/main/gov/nasa/jpf/vm/va/Log.java new file mode 100644 index 00000000..0b8ff606 --- /dev/null +++ b/src/main/gov/nasa/jpf/vm/va/Log.java @@ -0,0 +1,32 @@ +package gov.nasa.jpf.vm.va; + +import java.io.IOException; +import java.util.logging.FileHandler; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.logging.SimpleFormatter;; +public class Log { + static Logger logger = null; + public static void init() { + logger = Logger.getLogger("DataCollect"); + logger.setLevel(Level.INFO); + FileHandler fileHandler = null; + try { + fileHandler = new FileHandler("/home/meng/Documents/1.log"); + } catch(IOException e) { + } + fileHandler.setLevel(Level.INFO); + SimpleFormatter formatter = new SimpleFormatter(); + fileHandler.setFormatter(formatter); + logger.addHandler(fileHandler); + logger.setUseParentHandlers(false); + logger.info("Begin Crawling, Good Luck!"); + } + public static Logger getInstance() { + if(logger == null) { + System.out.println("init()"); + init(); + } + return logger; + } +} diff --git a/src/main/gov/nasa/jpf/vm/va/Stack.java b/src/main/gov/nasa/jpf/vm/va/Stack.java index 64f6e1a2..ded26e83 100644 --- a/src/main/gov/nasa/jpf/vm/va/Stack.java +++ b/src/main/gov/nasa/jpf/vm/va/Stack.java @@ -16,13 +16,13 @@ public class Stack { public int top; public Entry[] slots; - public DataCollect owner; + public StackHandlerTracker c; - public Stack(int nOperands, DataCollect dc) { + public Stack(int nOperands, StackHandlerTracker dc) { top = -1; slots = new Entry[nOperands]; - owner = dc; + c = dc; } public void clear() { @@ -115,9 +115,9 @@ public void setIndex(int index, Integer value, boolean isRef) { Stack copy() { - owner.numCopy += top+1; + c.stackcopy(this); //System.out.println(owner.c.redNum); - Stack clone = new Stack(slots.length, owner); + Stack clone = new Stack(slots.length, c); clone.top = top; System.arraycopy(slots, 0, clone.slots, 0, top + 1); return clone; diff --git a/src/main/gov/nasa/jpf/vm/va/StackHandler.java b/src/main/gov/nasa/jpf/vm/va/StackHandler.java index b9c9f317..cbf4d6e2 100644 --- a/src/main/gov/nasa/jpf/vm/va/StackHandler.java +++ b/src/main/gov/nasa/jpf/vm/va/StackHandler.java @@ -45,10 +45,10 @@ enum StackInstruction { public FeatureExpr stackCTX; - //*** dataCollect class object***// - public DataCollect c = new DataCollect(this); + //*** StackHandlerTracker class object***// + public StackHandlerTracker c = new StackHandlerTracker(); - static LinkedList q = new LinkedList(); + //static LinkedList q = new LinkedList(); /* (non-Javadoc) @@ -84,7 +84,6 @@ public String toString() { @SuppressWarnings("unchecked") public StackHandler(FeatureExpr ctx, int nLocals, int nOperands) { - c.setMin(nOperands); if (ctx == null) { throw new RuntimeException("CTX == NULL"); } @@ -93,7 +92,7 @@ public StackHandler(FeatureExpr ctx, int nLocals, int nOperands) { Arrays.fill(locals, nullValue); stack = new One<>(new Stack(nOperands, this.c)); stackCTX = ctx; - q.addLast(this.c); + //q.addLast(this.c); } @SuppressWarnings("unchecked") @@ -439,7 +438,7 @@ public Conditional apply(final FeatureExpr f, final Stack stack) { return ChoiceFactory.create(ctx, new One<>(clone), new One<>(stack)); } }).simplify(); - c.push(); + c.push(this, ctx, value, isRef); } /* (non-Javadoc) @@ -514,7 +513,7 @@ public Conditional apply(final FeatureExpr f, final Stack s) { } }).simplifyValues(); stack = stack.simplify(); - c.pop(); + c.pop(this, ctx,0); return result; } @@ -542,7 +541,7 @@ public Conditional apply(final FeatureExpr f, final Stack s) { return ChoiceFactory.create(f, new One<>(clone), new One<>(s)); } }).simplify(); - c.pop(); + c.pop(this, ctx, n); } /* (non-Javadoc) @@ -847,6 +846,7 @@ public void dup2(final FeatureExpr ctx) { @Override public void dup(final FeatureExpr ctx) { function(ctx, StackInstruction.DUP); + c.dup(this, ctx); } /* (non-Javadoc) @@ -910,7 +910,6 @@ public Conditional apply(final FeatureExpr f, final Stack stack) { return ChoiceFactory.create(ctx, new One<>(clone), new One<>(stack)); } }).simplify(); - c.dup(); } @Override diff --git a/src/main/gov/nasa/jpf/vm/va/StackHandlerTracker.java b/src/main/gov/nasa/jpf/vm/va/StackHandlerTracker.java new file mode 100644 index 00000000..0e59f270 --- /dev/null +++ b/src/main/gov/nasa/jpf/vm/va/StackHandlerTracker.java @@ -0,0 +1,168 @@ +package gov.nasa.jpf.vm.va; + +import java.util.*; +import de.fosd.typechef.featureexpr.FeatureExpr; + +public class StackHandlerTracker { + Integer numCopy; + Integer size; + Integer max; + Integer min; + Integer ave; + Integer gmax; + + + StackHandlerTracker() { + this.numCopy = 0; + this.size = 0; + this.max = 0; + this.min = 0; + this.ave = 0; + this.gmax = 0; + } + + public void set(Integer size, Integer min, Integer max, Integer ave) { + this.size = size; + this.max = max; + this.min = min; + this.ave = ave; + } + + /*** + * StackHandler + * push pop isref INC + * set dup swap + */ + public void push(StackHandler sh, final FeatureExpr ctx, final Object value, final boolean isRef){ + calculate(sh); + Log.getInstance().info("PUSH\n"+ sh.toString() + "\n" + this.toString()); + } + + public void pop(StackHandler sh, FeatureExpr ctx, final int n){ + calculate(sh); + Log.getInstance().info("POP\n"+ sh.toString() + "\n" + this.toString()); + } + + public void set(StackHandler sh, final FeatureExpr ctx, final int offset, final int value, final boolean isRef){} + + public void dup(StackHandler sh, final FeatureExpr ctx) { + calculate(sh); + Log.getInstance().info("DUP\n"+ sh.toString() + "\n" + this.toString()); + } + + public void isRef(StackHandler sh, final FeatureExpr ctx, final int offset) {} + + public void set(final FeatureExpr ctx, final int offset, final int value, final boolean isRef) {} + + public void getTop(StackHandler sh) {} + + public void setTop(StackHandler sh, final FeatureExpr ctx, final int i) {} + + public void clear(StackHandler sh, final FeatureExpr ctx) {} + + public void getSlots(StackHandler sh, FeatureExpr ctx) {} + + /*** + * Stack operations + * + * + */ + public void dup_x1(StackHandler sh, final FeatureExpr ctx) {} + + public void dup2_x2(StackHandler sh, final FeatureExpr ctx) {} + + public void dup2_x1(StackHandler sh, final FeatureExpr ctx) {} + + public void dup2(StackHandler sh, final FeatureExpr ctx) {} + + public void dup_x2(StackHandler sh, final FeatureExpr ctx){} + + public void swap(StackHandler sh, final FeatureExpr ctx) {} + + public void getLength(StackHandler sh) {} + + public void getStack(StackHandler sh) {} + + public void getAllReferences(StackHandler sh) {} + + public void getLocalWidth(StackHandler sh) {} + + public void getMaxLocal(StackHandler sh) {} + + public void IINC(StackHandler sh, FeatureExpr ctx, int index, final int increment){} + + /*** + * Stack + * stackcopy entrycopy + * + */ + + public void stackcopy(Stack s) { + this.numCopy += s.top+1; + } + + public void clear(Stack s){} + + public void setRef(Stack s, int index, boolean ref){} + + public void hasAnyRef(Stack s){} + + public void getSlots(Stack s){} + + public void get(Stack s, int index){} + + public void peek(Stack s, int offset){} + + public void push(Stack s, Integer value, boolean isRef){} + + public void isRef(Stack s, int offset){} + + public void isRefIndex(Stack s, int index){} + + public void set(Stack s, int offset, int value, boolean isRef){} + + public void setIndex(Stack s, int index, Integer value, boolean isRef){} + + public void dup2_x1(Stack s){} + + public void dup2(Stack s){} + + public void dup(Stack s){} + + public void dup_x2(Stack s){} + + public void swap(Stack s){} + + public void getReferences(Stack s){} + + public void entrycopy(Stack s){} + + public void calculate(StackHandler sh){ + List temp = sh.getTop().toList(); + Integer len = temp.size(); + Integer sum = temp.get(0) + 1; + max = temp.get(0) + 1; + min = temp.get(0) + 1; + for(int i = 1; i < len; i++){ + if(temp.get(i) + 1 > max) + this.max = temp.get(i) + 1; + if(temp.get(i) + 1 < min){ + this.min = temp.get(i) + 1; + } + + sum += temp.get(i) + 1; + } + if(this.max > this.gmax){ + this.gmax = this.max; + } + this.ave = sum/len; + this.size = len; + } + + + + + public String toString(){ + return "The size is " + this.size + "\nMinimun elements is "+ this.min + "\nMaximum elements is " +this.max + "\nAverage is " + this.ave + "\nNumbers of copys " + this.numCopy + "\ngmax is "+ this.gmax+ "\n"; + } +} diff --git a/src/main/gov/nasa/jpf/vm/va/Test.java b/src/main/gov/nasa/jpf/vm/va/Test.java index 15e1d229..6d53ae55 100644 --- a/src/main/gov/nasa/jpf/vm/va/Test.java +++ b/src/main/gov/nasa/jpf/vm/va/Test.java @@ -5,6 +5,7 @@ import gov.nasa.jpf.vm.MJIEnv; import gov.nasa.jpf.vm.Types; +import java.io.IOException; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -18,12 +19,15 @@ import cmu.conditional.VoidBiFunction; import de.fosd.typechef.featureexpr.FeatureExpr; import de.fosd.typechef.featureexpr.FeatureExprFactory; - +import java.util.logging.*; +import java.util.logging.Logger; +import java.util.logging.FileHandler; +import java.util.logging.Handler; public class Test { - - public static void main(String[] args) { - + + public static void main(String[] args) throws IOException { + FeatureExpr ta, tb, tc; @@ -49,18 +53,26 @@ public static void main(String[] args) { Conditional F = ChoiceFactory.create(tb, G, new One<>(10)); - //stack.push(FeatureExprFactory.True(), A, true); stack.push(FeatureExprFactory.True(), B, false); stack.push(FeatureExprFactory.True(), C, true); stack.push(FeatureExprFactory.True(), D, false); + stack.pop(FeatureExprFactory.True()); stack.push(FeatureExprFactory.True(), E, false); - //stack.push(FeatureExprFactory.True(), F, false); - //stack.push(FeatureExprFactory.True(), G, false); - //stack.dup2_x2(ctx); - stack.push(ta, B, false); - stack.pop(ta); + stack.push(ta.not(), D, false); stack.dup(ta.not()); stack.dup(ta.not()); + stack.pop(ta.not()); + stack.pop(ta, 2); + + // System.out.println(StackHandler.q.toString()); + stack.push(tb, D); + + + +// System.out.println(StackHandler.q.toString()); +// System.out.println(stack.toString()); + + // IStackHandler stack2 = StackHandlerFactory.createStack(FeatureExprFactory.True(), 0, 10); // stack2.push(FeatureExprFactory.True(), A, true); // stack2.push(FeatureExprFactory.True(), B, false); @@ -69,14 +81,9 @@ public static void main(String[] args) { //stack.push(FeatureExprFactory.True(), E, false); //stack2.push(FeatureExprFactory.True(), F, false); - - + //System.out.println(stack); //System.out.println(stack.getTop()); //System.out.println(stack.numOP().toString()); - System.out.println(StackHandler.q.toString()); - //System.out.println(stack); - - //System.out.println(stack2.getTop()); //System.out.println(stack2.numOP().toString());