From b13f2b357b39646f6a3895f30974f98e2c12e51d Mon Sep 17 00:00:00 2001 From: NoName11234 <47484268+NoName11234@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:03:55 +0100 Subject: [PATCH] removed old UnifyTaskModel from TypeUnify and TypeUnifyTask --- .../typeinference/unify/TypeUnify.java | 8 +- .../typeinference/unify/TypeUnify2Task.java | 17 +-- .../typeinference/unify/TypeUnifyTask.java | 132 ++++-------------- 3 files changed, 33 insertions(+), 124 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index 9efe8bc93..59c23e5df 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -25,7 +25,7 @@ public class TypeUnify { */ public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, pool); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, pool); pool.invoke(unifyTask); Set> res = unifyTask.join(); try { @@ -51,7 +51,7 @@ public class TypeUnify { */ public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, pool); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, pool); pool.invoke(unifyTask); return ret; } @@ -70,7 +70,7 @@ public class TypeUnify { public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); - new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, pool, statistics); + new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, pool, statistics); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -105,7 +105,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, new WriterActiveObject(logFile, ForkJoinPool.commonPool()), log, 0, ret, usedTasks, ForkJoinPool.commonPool()); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, new WriterActiveObject(logFile, ForkJoinPool.commonPool()), log, 0, ret, ForkJoinPool.commonPool()); unifyTask.statisticsFile = 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 03472f656..934405108 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -24,14 +24,14 @@ public class TypeUnify2Task extends TypeUnifyTask { TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, - IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, + IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, Set methodSignatureConstraintUebergabe, ForkJoinPool pool, Writer statistics) { - this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe, pool ); + this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, methodSignatureConstraintUebergabe, pool ); } - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set methodSignatureConstraintUebergabe, ForkJoinPool pool) { - super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, pool); + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, Set methodSignatureConstraintUebergabe, ForkJoinPool pool) { + super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, pool); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; this.methodSignatureConstraintUebergabe = methodSignatureConstraintUebergabe; @@ -54,14 +54,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 f7bbb96a2..656b79582 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -125,10 +125,6 @@ public class TypeUnifyTask extends RecursiveTask>> { static Integer noShortendElements = 0; - Boolean myIsCanceled = false; - - volatile UnifyTaskModel usedTasks; - static Writer statisticsFile = new NullWriter(); public TypeUnifyTask() { @@ -150,11 +146,11 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //statistics - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, ForkJoinPool pool, Writer statisticsFile) { - this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, pool); + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ForkJoinPool pool, Writer statisticsFile) { + this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, pool); this.statisticsFile = statisticsFile; } - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, ForkJoinPool pool) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ForkJoinPool pool) { this.eq = eq; //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); this.oderConstraintsField = oderConstraints; /*.stream().map(x -> { @@ -207,8 +203,6 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(logFile); this.rekTiefeField = rekTiefe; this.urm = urm; - this.usedTasks = usedTasks; - this.usedTasks.add(this); } /** @@ -243,13 +237,6 @@ public class TypeUnifyTask extends RecursiveTask>> { } } */ - void myCancel(Boolean b) { - myIsCanceled = true; - } - - public boolean myIsCancelled() { - return myIsCanceled; - } protected Set> compute() { if (one) { @@ -280,14 +267,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; } } /* @@ -320,12 +300,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()); @@ -507,12 +481,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<>(); @@ -929,14 +897,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, methodSignatureConstraint, this.pool); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, methodSignatureConstraint, this.pool); //forks.add(forkOrig); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - forkOrig.fork(); - } + forkOrig.fork(); + /* FORK ENDE */ writeLog("a in " + variance + " "+ a + "\n" + @@ -966,14 +930,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), this.pool); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, new HashSet<>(methodSignatureConstraint), this.pool); forks.add(fork); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - fork.fork(); - } + fork.fork(); } //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); @@ -982,11 +941,7 @@ 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(); @@ -1000,11 +955,7 @@ public class TypeUnifyTask extends RecursiveTask>> { for(TypeUnify2Task fork : forks) { noOfThread--; Set> fork_res = fork.join(); - synchronized (usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - } + //noOfThread++; //noOfThread--; an das Ende von compute verschoben writeLog("Join " + new Integer(fork.thNo).toString() + "\n" + @@ -1027,14 +978,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), this.pool); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, new HashSet<>(methodSignatureConstraint), this.pool); //forks.add(forkOrig); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - forkOrig.fork(); - } + forkOrig.fork(); + /* FORK ENDE */ @@ -1063,14 +1010,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), this.pool); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, new HashSet<>(methodSignatureConstraint), this.pool); forks.add(fork); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - fork.fork(); - } + fork.fork(); } //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); @@ -1078,11 +1020,7 @@ 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(); @@ -1096,11 +1034,7 @@ public class TypeUnifyTask extends RecursiveTask>> { for(TypeUnify2Task fork : forks) { 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 @@ -1125,14 +1059,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), this.pool); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, new HashSet<>(methodSignatureConstraint), this.pool); //forks.add(forkOrig); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - forkOrig.fork(); - } + forkOrig.fork(); /* FORK ENDE */ writeLog("a in " + variance + " "+ a + "\n" + @@ -1145,14 +1074,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, methodSignatureConstraint, this.pool); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, methodSignatureConstraint, this.pool); forks.add(fork); - synchronized(usedTasks) { - if (this.myIsCancelled()) { - return new HashSet<>(); - } - fork.fork(); - } + fork.fork(); } //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); @@ -1161,11 +1085,7 @@ 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(); @@ -1179,11 +1099,7 @@ public class TypeUnifyTask extends RecursiveTask>> { for(TypeUnify2Task fork : forks) { 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