diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 3745521bf..04415a13a 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -30,7 +30,7 @@ public class TypeUnify { * @return */ public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -56,7 +56,7 @@ public class TypeUnify { * @return */ public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); return ret; @@ -75,7 +75,7 @@ public class TypeUnify { */ public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); - new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks, statistics); + new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, statistics); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -110,7 +110,7 @@ public class TypeUnify { * @return */ public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret, usedTasks); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, ret); unifyTask.statistics = statistics; Set> res = unifyTask.compute(); try { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 61d6ce8ef..d0742ea85 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -23,14 +23,14 @@ public class TypeUnify2Task extends TypeUnifyTask { TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, - IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, + IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, Set methodSignatureConstraintUebergabe, Writer statistics) { - this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe ); + this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, methodSignatureConstraintUebergabe ); } - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set methodSignatureConstraintUebergabe) { - super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, Set methodSignatureConstraintUebergabe) { + super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; this.methodSignatureConstraintUebergabe = methodSignatureConstraintUebergabe; @@ -53,14 +53,7 @@ public class TypeUnify2Task extends TypeUnifyTask { */ //writeLog("xxx"); //noOfThread--; - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - else { - return res; - } - } + return res; } public void closeLogFile() { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index d2c1fc6b2..e00e3d4b6 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -132,10 +132,6 @@ public class TypeUnifyTask extends RecursiveTask>> { static Integer noShortendElements = 0; - Boolean myIsCanceled = false; - - volatile UnifyTaskModel usedTasks; - static Writer statistics; public TypeUnifyTask() { @@ -157,11 +153,11 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //statistics - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Writer statistics) { - this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, Writer statistics) { + this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm); this.statistics = statistics; } - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm) { synchronized (this) { if(statistics==null){ statistics = new NullWriter(); @@ -215,8 +211,6 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(logFile); this.rekTiefeField = rekTiefe; this.urm = urm; - this.usedTasks = usedTasks; - this.usedTasks.add(this); } } @@ -252,13 +246,6 @@ public class TypeUnifyTask extends RecursiveTask>> { } } */ - void myCancel(Boolean b) { - myIsCanceled = true; - } - - public boolean myIsCancelled() { - return myIsCanceled; - } protected Set> compute() { if (one) { @@ -288,14 +275,7 @@ public class TypeUnifyTask extends RecursiveTask>> { throw new TypeinferenceException("Unresolved constraints: " + res.toString(), new NullToken()); //return new HashSet<>(); } else { - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - else { - return res; - } - } + return res; } } /* @@ -328,12 +308,6 @@ public class TypeUnifyTask extends RecursiveTask>> { //.collect(Collectors.toCollection(HashSet::new))); - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - } - rekTiefe++; nOfUnify++; writeLog(nOfUnify.toString() + " Unifikation: " + eq.toString()); @@ -515,12 +489,6 @@ public class TypeUnifyTask extends RecursiveTask>> { // .collect(Collectors.toCollection(HashSet::new)); //Muss auskommentiert werden, wenn computeCartesianRecursive ENDE - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - } - Set> eqPrimePrimeSet = new HashSet<>(); Set forks = new HashSet<>(); @@ -937,14 +905,9 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, methodSignatureConstraint); //forks.add(forkOrig); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - forkOrig.fork(); - } + forkOrig.fork(); /* FORK ENDE */ synchronized (this) { @@ -975,14 +938,9 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, new HashSet<>(methodSignatureConstraint)); forks.add(fork); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - fork.fork(); - } + fork.fork(); } //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); @@ -991,11 +949,6 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("wait "+ forkOrig.thNo); noOfThread--; res = forkOrig.join(); - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - } //noOfThread++; forkOrig.writeLog("final Orig 1"); forkOrig.closeLogFile(); @@ -1011,11 +964,6 @@ public class TypeUnifyTask extends RecursiveTask>> { synchronized (this) { noOfThread--; Set> fork_res = fork.join(); - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - } //noOfThread++; writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1039,14 +987,9 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, new HashSet<>(methodSignatureConstraint)); //forks.add(forkOrig); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - forkOrig.fork(); - } + forkOrig.fork(); /* FORK ENDE */ synchronized (this) { @@ -1076,14 +1019,9 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, new HashSet<>(methodSignatureConstraint)); forks.add(fork); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - fork.fork(); - } + fork.fork(); } //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); @@ -1092,11 +1030,6 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("wait "+ forkOrig.thNo); noOfThread--; res = forkOrig.join(); - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - } //noOfThread++; forkOrig.writeLog("final Orig -1"); forkOrig.closeLogFile(); @@ -1112,11 +1045,6 @@ public class TypeUnifyTask extends RecursiveTask>> { synchronized (this) { noOfThread--; Set> fork_res = fork.join(); - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - } //noOfThread++; writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben @@ -1141,14 +1069,10 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, new HashSet<>(methodSignatureConstraint)); //forks.add(forkOrig); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - forkOrig.fork(); - } + forkOrig.fork(); + /* FORK ENDE */ synchronized (this) { @@ -1162,14 +1086,10 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); newElems.add(nSaL); - TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, methodSignatureConstraint); forks.add(fork); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - fork.fork(); - } + fork.fork(); + } //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); @@ -1178,11 +1098,6 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("wait "+ forkOrig.thNo); noOfThread--; res = forkOrig.join(); - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - } //noOfThread++; forkOrig.writeLog("final Orig 2"); forkOrig.closeLogFile(); @@ -1197,11 +1112,6 @@ public class TypeUnifyTask extends RecursiveTask>> { synchronized (this) { noOfThread--; Set> fork_res = fork.join(); - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - } //noOfThread++; writeLog("Join " + new Integer(fork.thNo).toString()); //noOfThread--; an das Ende von compute verschoben