From 14606a846e0a104d796097fdb6d4a7b1c201f61e Mon Sep 17 00:00:00 2001 From: "pl@gohorb.ba-horb.de" Date: Wed, 22 Mar 2023 19:01:36 +0100 Subject: [PATCH] modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 3 +- .../typeinference/unify/TypeUnify.java | 5 +++- .../typeinference/unify/TypeUnify2Task.java | 10 +++++++ .../typeinference/unify/TypeUnifyTask.java | 30 +++++++++++++++++-- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 23c74248..64b89f9a 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -70,7 +70,7 @@ public class JavaTXCompiler { //public static JavaTXCompiler INSTANCE; final CompilationEnvironment environment; - Boolean resultmodel = true; + Boolean resultmodel = false; public final Map sourceFiles = new HashMap<>(); Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll? public volatile UnifyTaskModel usedTasks = new UnifyTaskModel(); @@ -582,6 +582,7 @@ public class JavaTXCompiler { unifyCons = unifyCons.map(distributeInnerVars); logFile.write("\nUnify_distributeInnerVars: " + unifyCons.toString()); TypeUnify unify = new TypeUnify(); + unify.statistics = statistics; // Set> results = new HashSet<>(); Nach vorne gezogen logFile.write("FC:\\" + finiteClosure.toString() + "\n"); for (SourceFile sf : this.sourceFiles.values()) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index d78d8c8d..46eec8db 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -18,6 +18,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { + public static Writer statistics; /** * unify parallel ohne result modell * @param undConstrains @@ -73,7 +74,8 @@ public class TypeUnify { * @return */ 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); + 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); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -107,6 +109,7 @@ public class TypeUnify { */ 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); + unifyTask.statistics = statistics; Set> res = unifyTask.compute(); try { logFile.write("\nnoShortendElements: " + unifyTask.noShortendElements +"\n"); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 20820eef..61d6ce8e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -19,6 +19,16 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; Set methodSignatureConstraintUebergabe; + //statistics + 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, Writer statistics) { + this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, 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); this.setToFlatten = setToFlatten; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 0d66bfb7..31495bdf 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -21,6 +21,7 @@ import java.util.stream.Stream; import org.apache.commons.io.output.NullOutputStream; +import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.exceptions.TypeinferenceException; import de.dhbwstuttgart.parser.NullToken; import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; @@ -46,6 +47,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.model.WildcardType; import de.dhbwstuttgart.util.Pair; import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; +import de.dhbwstuttgart.core.JavaTXCompiler; import java.io.File; import java.io.FileWriter; @@ -131,6 +133,8 @@ public class TypeUnifyTask extends RecursiveTask>> { volatile UnifyTaskModel usedTasks; + static Writer statistics; + public TypeUnifyTask() { rules = new RuleSet(); } @@ -149,7 +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); + this.statistics = statistics; + } public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { synchronized (this) { this.eq = eq; @@ -592,6 +600,7 @@ public class TypeUnifyTask extends RecursiveTask>> { urm.notify(eqPrimePrimeSet); + writeStatistics("Result: " + eqPrimePrimeSet.toString()); } } else if(eqPrimePrime.isPresent()) { @@ -732,7 +741,7 @@ public class TypeUnifyTask extends RecursiveTask>> { variance = optVariance.isPresent() ? optVariance.get() : 2; } /* Varianzbestimmung Ende */ - variance = 2; + //variance = 2;//statistics //writeLog("nextSetasList: " + nextSetasList.toString()); Set nextSetElem = nextSetasList.get(0); @@ -777,6 +786,8 @@ public class TypeUnifyTask extends RecursiveTask>> { Set a = null; while (nextSetasList.size() > 0) { + //statistics + writeStatistics(rekTiefe + " Number of elements: " + nextSetasList.size()); Set a_last = a; /* Liste der Faelle für die parallele Verarbeitung @@ -1180,6 +1191,7 @@ public class TypeUnifyTask extends RecursiveTask>> { }}} //Ab hier alle parallele Berechnungen wieder zusammengeführt. + writeStatistics("Zusammengeführt: " + rekTiefe + " " + nextSetasList.size()); if (oderConstraint) {//Wenn weiteres Element nextSetasList genommen wird, muss die vorherige methodsignatur geloescht werden methodSignatureConstraint.removeAll(((Constraint)a).getmethodSignatureConstraint()); //System.out.println("REMOVE: " +methodSignatureConstraint); @@ -1504,6 +1516,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString()); noBacktracking++; writeLog("Number of Backtracking: " + noBacktracking); + writeStatistics("Number of Backtracking: " + noBacktracking); System.out.println(""); } //if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result) && nextSet.size() > 1) { @@ -2577,4 +2590,17 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } + + void writeStatistics(String str) { + synchronized ( this ) { + try { + statistics.write(str + "\n"); + statistics.flush(); + + } + catch (IOException e) { + System.err.println("kein StatisticsFile"); + } + } + } }