From aae2e5244b2214c025fdf32f18fb405c48cefe74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 16 Jan 2019 17:39:01 +0100 Subject: [PATCH 01/17] 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/TypeUnifyTask.java Erster Ansatz Parallelisierung --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 10 +- .../typeinference/unify/TypeUnify.java | 10 +- .../typeinference/unify/TypeUnifyTask.java | 134 ++++++++++++++++-- 3 files changed, 140 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index f8d4a363..f339af1a 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -388,7 +388,15 @@ public class JavaTXCompiler { //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); //Set> result = unify.unify(xConsSet, finiteClosure); - Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), unifyCons.getOderConstraints(), finiteClosure, logFile, log); + List>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> { + Set> ret = new HashSet<>(); + for (Constraint y : x) { + ret.add(new HashSet<>(y)); + } + return ret; + }).collect(Collectors.toCollection(ArrayList::new)); + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index d2428def..fecd28fe 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -10,22 +10,24 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { - public Set> unify(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { - TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, true, logFile, log); + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); return res; } + /* public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); Set> res = unifyTask.compute(); return res; } + */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log); + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0); Set> res = unifyTask.compute(); return res; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index a149be4c..c08ace4f 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -34,6 +34,7 @@ import de.dhbwstuttgart.typeinference.unify.model.TypeParams; import de.dhbwstuttgart.typeinference.unify.model.Unifier; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; +import de.dhbwstuttgart.typeinference.unify.model.WildcardType; import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; import de.dhbwstuttgart.typeinference.unify.model.Pair; @@ -55,6 +56,13 @@ public class TypeUnifyTask extends RecursiveTask>> { private boolean printtag = false; Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? + /* + * Fuer die Threads + */ + private static int noOfThread = 0; + private int thNo; + protected boolean one = false; + public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; FileWriter logFile; @@ -83,6 +91,8 @@ public class TypeUnifyTask extends RecursiveTask>> { protected boolean parallel; + int rekTiefeField; + Integer nOfUnify = 0; Integer noUndefPair = 0; @@ -97,6 +107,7 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(); } + /* public TypeUnifyTask(Set eq, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) { this.eq = eq; this.fc = fc; @@ -105,18 +116,22 @@ public class TypeUnifyTask extends RecursiveTask>> { this.logFile = logFile; this.log = log; rules = new RuleSet(logFile); + noOfThread++; + thNo = noOfThread; } + */ - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe) { 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 -> { + this.oderConstraintsField = oderConstraints; /*.stream().map(x -> { Set> ret = new HashSet<>(); for (Constraint y : x) { ret.add(new HashSet<>(y)); } return ret; }).collect(Collectors.toCollection(ArrayList::new)); + */ //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); this.fc = fc; @@ -125,6 +140,9 @@ public class TypeUnifyTask extends RecursiveTask>> { this.logFile = logFile; this.log = log; rules = new RuleSet(logFile); + this.rekTiefeField = rekTiefe; + noOfThread++; + thNo = noOfThread; } /** @@ -161,6 +179,10 @@ public class TypeUnifyTask extends RecursiveTask>> { */ protected Set> compute() { + if (one) { + System.out.println("two"); + } + one = true; Set neweq = new HashSet<>(eq); /* 1-elementige Oder-Constraints werden in und-Constraints umgewandelt */ oderConstraintsField.stream() @@ -169,7 +191,7 @@ public class TypeUnifyTask extends RecursiveTask>> { ArrayList>> remainingOderconstraints = oderConstraintsField.stream() .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); - Set> res = unify(neweq, remainingOderconstraints, fc, parallel, 0); + Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField); if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } @@ -439,7 +461,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * @param fc The finite closure * @return The set of all principal type unifiers */ - protected Set> unify(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { + protected Set> unify(final Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, int rekTiefe) { //Set aas = eq.stream().filter(x -> x.getLhsType().getName().equals("AA") //&& x.getPairOp().equals(PairOperator.SMALLERDOT) // ).collect(Collectors.toCollection(HashSet::new)); //writeLog(nOfUnify.toString() + " AA: " + aas.toString()); @@ -613,10 +635,13 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //writeLog("vor Subst: " + eqPrime); Optional> eqPrimePrime = rules.subst(eqPrime); + Set> unifyres1 = null; + Set> unifyres2 = null; //writeLog("nach Subst: " + eqPrimePrime); /* * Step 6 a) Restart (fork) for pairs where subst was applied */ + /* if(parallel) { if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() && oderConstraints.isEmpty()) //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch @@ -637,7 +662,8 @@ public class TypeUnifyTask extends RecursiveTask>> { fork.fork(); } } - else { // sequentiell (Step 6b is included) + else */ + {// sequentiell (Step 6b is included) if (printtag) System.out.println("nextStep: " + eqPrimePrime); if (eqPrime.equals(eq) && !eqPrimePrime.isPresent() && oderConstraints.isEmpty()) { //PL 2017-09-29 //(!eqPrimePrime.isPresent()) auskommentiert und durch @@ -656,12 +682,12 @@ public class TypeUnifyTask extends RecursiveTask>> { eqPrimePrimeSet.add(eqPrime); } else if(eqPrimePrime.isPresent()) { - Set> unifyres = unify(eqPrimePrime.get(), oderConstraints, fc, false, rekTiefe); + Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), oderConstraints, fc, parallel, rekTiefe); eqPrimePrimeSet.addAll(unifyres); } else { - Set> unifyres = unify(eqPrime, oderConstraints, fc, false, rekTiefe); + Set> unifyres = unifyres2 = unify(eqPrime, oderConstraints, fc, parallel, rekTiefe); eqPrimePrimeSet.addAll(unifyres); @@ -683,8 +709,14 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 7: Filter empty sets; */ eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); - if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) + if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) { writeLog("Result1 " + eqPrimePrimeSet.toString()); + Iterator upit = eqPrimePrimeSet.iterator().next().iterator(); + if (upit.next().getLhsType() instanceof WildcardType + || upit.next().getLhsType() instanceof WildcardType) { + System.out.println(""); + } + } return eqPrimePrimeSet; } @@ -758,9 +790,19 @@ public class TypeUnifyTask extends RecursiveTask>> { Set a = null; while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a_last = a; + List> nextSetasListRest= new ArrayList<>(); if (variance == 1) { a = oup.max(nextSetasList.iterator()); nextSetasList.remove(a); + nextSetasListRest = new ArrayList<>(nextSetasList); + Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); + while (nextSetasListItRest.hasNext()) { + Set a_next = nextSetasListItRest.next(); + if (//a.equals(a_next) || + (oup.compare(a, a_next) == 1)) { + nextSetasListRest.remove(a_next); + } + } } else if (variance == -1) { a = oup.min(nextSetasList.iterator()); @@ -799,10 +841,56 @@ public class TypeUnifyTask extends RecursiveTask>> { elems.add(a); //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt //writeLog("Vor unify2 Aufruf: " + elems.toString()); - Set> res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); + Set> res = new HashSet<>(); + Set>> add_res = new HashSet<>(); + if(parallel && (variance == 1)) { + /* + elems.add(a); + TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log); + fork.fork(); + res = fork.join(); + */ + + Set forks = new HashSet<>(); + + //TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log); + + + Set newEqOrig = new HashSet<>(eq); + Set> newElemsOrig = new HashSet<>(elems); + List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + newElemsOrig.add(a); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); + forks.add(forkOrig); + forkOrig.fork(); + + while (!nextSetasListRest.isEmpty()) { + Set nSaL = nextSetasListRest.remove(0); + Set newEq = new HashSet<>(eq); + Set> newElems = new HashSet<>(elems); + List>> newOderConstraints = new ArrayList<>(oderConstraints); + newElems.add(nSaL); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe); + forks.add(fork); + fork.fork(); + } + //res = unify2(elems, eq, fc, parallel); + res = forkOrig.join(); + for(TypeUnifyTask fork : forks) { + Set> fork_res = fork.join(); + add_res.add(fork_res); + } + } + else { + elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 833 + res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); + } if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; + if (res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } } else { if ((isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) @@ -874,11 +962,13 @@ public class TypeUnifyTask extends RecursiveTask>> { //result = result; }}}} else { if (variance == 0) { + writeLog("RESADD:" + result.toString() + " " + res.toString()); result.addAll(res); }}} //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden } else { + writeLog("RESADD:" + result.toString() + " " + res.toString()); result.addAll(res); } } @@ -901,6 +991,31 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RESADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } + } + break; + } + /* nextSetasList = nextSetasListRest; */ + /* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet + */ + System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); while (nextSetasListIt.hasNext()) { @@ -1828,6 +1943,7 @@ public class TypeUnifyTask extends RecursiveTask>> { void writeLog(String str) { if (log) { try { + logFile.write("Thread no.:" + thNo + "\n"); logFile.write(str+"\n\n"); logFile.flush(); From 01891c95138632a60cb8ad3f7216aef76a0c4f37 Mon Sep 17 00:00:00 2001 From: Pluemicke Martin Date: Wed, 16 Jan 2019 20:25:54 +0100 Subject: [PATCH 02/17] neue Datei: TypeUnify2Task.java --- .../typeinference/unify/TypeUnify2Task.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java new file mode 100644 index 00000000..95ccdf07 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -0,0 +1,34 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.io.FileWriter; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; + +public class TypeUnify2Task extends TypeUnifyTask { + + Set> setToFlatten; + + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe) { + super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe); + this.setToFlatten = setToFlatten; + } + + @Override + protected Set> compute() { + if (one) { + System.out.println("two"); + } + one = true; + Set> res = unify2(setToFlatten, eq, oderConstraintsField, fc, parallel, rekTiefeField); + /*if (isUndefinedPairSetSet(res)) { + return new HashSet<>(); } + else + */ + return res; + } +} From 38d44817564d024241c534802ae96f1f35d1dee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 16 Jan 2019 22:57:24 +0100 Subject: [PATCH 03/17] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Es muss noch geklaert werden, wann ein neuer Thread generiert werden darf. modified: ../../resources/bytecode/javFiles/MatrixOP.jav --- .../typeinference/unify/TypeUnifyTask.java | 144 ++++++++++++++++-- .../resources/bytecode/javFiles/MatrixOP.jav | 2 +- 2 files changed, 130 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index c08ace4f..5c52c237 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -56,12 +56,13 @@ public class TypeUnifyTask extends RecursiveTask>> { private boolean printtag = false; Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? - /* + /** * Fuer die Threads */ private static int noOfThread = 0; private int thNo; protected boolean one = false; + Integer MaxNoOfThreads = 4; public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; FileWriter logFile; @@ -141,7 +142,7 @@ public class TypeUnifyTask extends RecursiveTask>> { this.log = log; rules = new RuleSet(logFile); this.rekTiefeField = rekTiefe; - noOfThread++; + synchronized (this) { noOfThread++; } thNo = noOfThread; } @@ -790,23 +791,34 @@ public class TypeUnifyTask extends RecursiveTask>> { Set a = null; while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a_last = a; - List> nextSetasListRest= new ArrayList<>(); + List> nextSetasListRestMax = new ArrayList<>(); + List> nextSetasListRestMin = new ArrayList<>(); + List> nextSetasListRestOder = new ArrayList<>(); if (variance == 1) { a = oup.max(nextSetasList.iterator()); nextSetasList.remove(a); - nextSetasListRest = new ArrayList<>(nextSetasList); - Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); + nextSetasListRestMax = new ArrayList<>(nextSetasList); + Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRestMax).iterator(); while (nextSetasListItRest.hasNext()) { Set a_next = nextSetasListItRest.next(); if (//a.equals(a_next) || (oup.compare(a, a_next) == 1)) { - nextSetasListRest.remove(a_next); + nextSetasListRestMax.remove(a_next); } } } else if (variance == -1) { a = oup.min(nextSetasList.iterator()); nextSetasList.remove(a); + nextSetasListRestMin = new ArrayList<>(nextSetasList); + Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRestMin).iterator(); + while (nextSetasListItRest.hasNext()) { + Set a_next = nextSetasListItRest.next(); + if (//a.equals(a_next) || + (oup.compare(a, a_next) == -1)) { + nextSetasListRestMin.remove(a_next); + } + } } else if (variance == 0 || variance == 2) { a = nextSetasList.remove(0); @@ -843,7 +855,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //writeLog("Vor unify2 Aufruf: " + elems.toString()); Set> res = new HashSet<>(); Set>> add_res = new HashSet<>(); - if(parallel && (variance == 1)) { + if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { /* elems.add(a); TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log); @@ -864,8 +876,8 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(forkOrig); forkOrig.fork(); - while (!nextSetasListRest.isEmpty()) { - Set nSaL = nextSetasListRest.remove(0); + while (!nextSetasListRestMax.isEmpty()) { + Set nSaL = nextSetasListRestMax.remove(0); Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); @@ -878,13 +890,70 @@ public class TypeUnifyTask extends RecursiveTask>> { res = forkOrig.join(); for(TypeUnifyTask fork : forks) { Set> fork_res = fork.join(); + synchronized (this) { noOfThread--; }; add_res.add(fork_res); } - } - else { + } else { + if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { + Set forks = new HashSet<>(); + Set newEqOrig = new HashSet<>(eq); + Set> newElemsOrig = new HashSet<>(elems); + List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + newElemsOrig.add(a); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); + forks.add(forkOrig); + forkOrig.fork(); + + while (!nextSetasListRestMin.isEmpty()) { + Set nSaL = nextSetasListRestMin.remove(0); + Set newEq = new HashSet<>(eq); + Set> newElems = new HashSet<>(elems); + List>> newOderConstraints = new ArrayList<>(oderConstraints); + newElems.add(nSaL); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe); + forks.add(fork); + fork.fork(); + } + //res = unify2(elems, eq, fc, parallel); + res = forkOrig.join(); + for(TypeUnifyTask fork : forks) { + Set> fork_res = fork.join(); + synchronized (this) { noOfThread--; }; + add_res.add(fork_res); + } + } else { + if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { + Set forks = new HashSet<>(); + Set newEqOrig = new HashSet<>(eq); + Set> newElemsOrig = new HashSet<>(elems); + List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); + newElemsOrig.add(a); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); + forks.add(forkOrig); + forkOrig.fork(); + + while (!nextSetasListRestOder.isEmpty()) { + Set nSaL = nextSetasListRestOder.remove(0); + Set newEq = new HashSet<>(eq); + Set> newElems = new HashSet<>(elems); + List>> newOderConstraints = new ArrayList<>(oderConstraints); + newElems.add(nSaL); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe); + forks.add(fork); + fork.fork(); + } + //res = unify2(elems, eq, fc, parallel); + res = forkOrig.join(); + for(TypeUnifyTask fork : forks) { + Set> fork_res = fork.join(); + synchronized (this) { noOfThread--; }; + add_res.add(fork_res); + }} + else { + parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 833 res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); - } + }}} if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; @@ -1032,6 +1101,27 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else { if (variance == -1) { + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RESADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } + } + break; + } System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); while (nextSetasListIt.hasNext()) { @@ -1047,10 +1137,32 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } - else if (variance == 0) { + else { if (variance == 0) { writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); - break; - } + break; } + else { if (variance == 2) { + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RESADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } + } + break; + } + }}} writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); } } @@ -1944,6 +2056,8 @@ public class TypeUnifyTask extends RecursiveTask>> { if (log) { try { logFile.write("Thread no.:" + thNo + "\n"); + logFile.write("noOfThread:" + noOfThread + "\n"); + logFile.write("parallel:" + parallel + "\n"); logFile.write(str+"\n\n"); logFile.flush(); diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index 828a270b..c78c42c7 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Byte; +import java.lang.Byte; import java.lang.Boolean; public class MatrixOP extends Vector> { From cf951043ef7d1d01f594155c187b54007a6b3166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 18 Jan 2019 00:54:43 +0100 Subject: [PATCH 04/17] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java --- .../de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 5c52c237..a23ff422 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -143,7 +143,9 @@ public class TypeUnifyTask extends RecursiveTask>> { rules = new RuleSet(logFile); this.rekTiefeField = rekTiefe; synchronized (this) { noOfThread++; } + writeLog("thNo1 " + thNo); thNo = noOfThread; + writeLog("thNo2 " + thNo); } /** @@ -2053,6 +2055,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } void writeLog(String str) { + synchronized ( this ) { if (log) { try { logFile.write("Thread no.:" + thNo + "\n"); @@ -2066,5 +2069,6 @@ public class TypeUnifyTask extends RecursiveTask>> { System.err.println("kein LogFile"); } } + } } } From 188ea1f7f8d9cd07b9658719ece39f73d7b318be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Sun, 20 Jan 2019 21:49:22 +0100 Subject: [PATCH 05/17] modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java einige Aenderungen, die parallele Verarbeitung ermoeglicht --- .../typeinference/unify/TypeUnifyTask.java | 166 +++++++++++------- .../resources/bytecode/javFiles/Matrix.jav | 2 +- 2 files changed, 101 insertions(+), 67 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index a23ff422..ab672f5e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -60,6 +60,7 @@ public class TypeUnifyTask extends RecursiveTask>> { * Fuer die Threads */ private static int noOfThread = 0; + private static int totalnoOfThread = 0; private int thNo; protected boolean one = false; Integer MaxNoOfThreads = 4; @@ -123,29 +124,33 @@ public class TypeUnifyTask extends RecursiveTask>> { */ public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe) { - 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 -> { + synchronized (this) { + 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 -> { Set> ret = new HashSet<>(); for (Constraint y : x) { ret.add(new HashSet<>(y)); } return ret; - }).collect(Collectors.toCollection(ArrayList::new)); - */ + }).collect(Collectors.toCollection(ArrayList::new)); + */ - //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); - this.fc = fc; - this.oup = new OrderingUnifyPair(fc); - this.parallel = parallel; - this.logFile = logFile; - this.log = log; - rules = new RuleSet(logFile); - this.rekTiefeField = rekTiefe; - synchronized (this) { noOfThread++; } - writeLog("thNo1 " + thNo); - thNo = noOfThread; - writeLog("thNo2 " + thNo); + //x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); + this.fc = fc; + this.oup = new OrderingUnifyPair(fc); + this.parallel = parallel; + this.logFile = logFile; + this.log = log; + rules = new RuleSet(logFile); + this.rekTiefeField = rekTiefe; + + noOfThread++; + totalnoOfThread++; + writeLog("thNo1 " + thNo); + thNo = totalnoOfThread; + writeLog("thNo2 " + thNo); + } } /** @@ -703,7 +708,9 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 6 b) Build the union over everything. */ - + /* + * PL 2019-01-20: muss uebrprueft werden + */ if(parallel) for(TypeUnifyTask fork : forks) eqPrimePrimeSet.addAll(fork.join()); @@ -714,11 +721,6 @@ public class TypeUnifyTask extends RecursiveTask>> { eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); if (!eqPrimePrimeSet.isEmpty() && !isUndefinedPairSetSet(eqPrimePrimeSet)) { writeLog("Result1 " + eqPrimePrimeSet.toString()); - Iterator upit = eqPrimePrimeSet.iterator().next().iterator(); - if (upit.next().getLhsType() instanceof WildcardType - || upit.next().getLhsType() instanceof WildcardType) { - System.out.println(""); - } } return eqPrimePrimeSet; } @@ -793,36 +795,40 @@ public class TypeUnifyTask extends RecursiveTask>> { Set a = null; while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a_last = a; - List> nextSetasListRestMax = new ArrayList<>(); - List> nextSetasListRestMin = new ArrayList<>(); - List> nextSetasListRestOder = new ArrayList<>(); + List> nextSetasListRest = new ArrayList<>(); + //List> nextSetasListRestMin = new ArrayList<>(); + //List> nextSetasListRestOder = new ArrayList<>(); if (variance == 1) { a = oup.max(nextSetasList.iterator()); nextSetasList.remove(a); - nextSetasListRestMax = new ArrayList<>(nextSetasList); - Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRestMax).iterator(); + nextSetasListRest = new ArrayList<>(nextSetasList); + Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); while (nextSetasListItRest.hasNext()) { Set a_next = nextSetasListItRest.next(); if (//a.equals(a_next) || (oup.compare(a, a_next) == 1)) { - nextSetasListRestMax.remove(a_next); + nextSetasListRest.remove(a_next); } } } else if (variance == -1) { a = oup.min(nextSetasList.iterator()); nextSetasList.remove(a); - nextSetasListRestMin = new ArrayList<>(nextSetasList); - Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRestMin).iterator(); + nextSetasListRest = new ArrayList<>(nextSetasList); + Iterator> nextSetasListItRest = new ArrayList>(nextSetasListRest).iterator(); while (nextSetasListItRest.hasNext()) { Set a_next = nextSetasListItRest.next(); if (//a.equals(a_next) || (oup.compare(a, a_next) == -1)) { - nextSetasListRestMin.remove(a_next); + nextSetasListRest.remove(a_next); } } } - else if (variance == 0 || variance == 2) { + else if (variance == 2) { + a = nextSetasList.remove(0); + nextSetasListRest = new ArrayList<>(nextSetasList); + } + else if (variance == 0) { a = nextSetasList.remove(0); } //writeLog("nextSet: " + nextSetasList.toString()+ "\n"); @@ -852,7 +858,8 @@ public class TypeUnifyTask extends RecursiveTask>> { i++; Set> elems = new HashSet>(fstElems); writeLog("a1: " + rekTiefe + " "+ a.toString()+ "\n"); - elems.add(a); + //elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall + //im else-Zweig //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt //writeLog("Vor unify2 Aufruf: " + elems.toString()); Set> res = new HashSet<>(); @@ -877,9 +884,15 @@ public class TypeUnifyTask extends RecursiveTask>> { TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); forks.add(forkOrig); forkOrig.fork(); - - while (!nextSetasListRestMax.isEmpty()) { - Set nSaL = nextSetasListRestMax.remove(0); + synchronized (this) { + writeLog("a in " + variance + " "+ a); + writeLog("nextSetasListRest: " + nextSetasListRest.toString()); + } + while (!nextSetasListRest.isEmpty()) { + Set nSaL = nextSetasListRest.remove(0); + synchronized (this) { nextSetasList.remove(nSaL); + writeLog("1 RM" + nSaL.toString()); + } Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); @@ -891,9 +904,12 @@ public class TypeUnifyTask extends RecursiveTask>> { //res = unify2(elems, eq, fc, parallel); res = forkOrig.join(); for(TypeUnifyTask fork : forks) { - Set> fork_res = fork.join(); - synchronized (this) { noOfThread--; }; - add_res.add(fork_res); + synchronized (this) { + Set> fork_res = fork.join(); + writeLog("Join " + new Integer(fork.thNo).toString()); + noOfThread--; + add_res.add(fork_res); + }; } } else { if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) { @@ -905,9 +921,15 @@ public class TypeUnifyTask extends RecursiveTask>> { TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); forks.add(forkOrig); forkOrig.fork(); - - while (!nextSetasListRestMin.isEmpty()) { - Set nSaL = nextSetasListRestMin.remove(0); + synchronized (this) { + writeLog("a in " + variance + " "+ a); + writeLog("nextSetasListRest: " + nextSetasListRest.toString()); + } + while (!nextSetasListRest.isEmpty()) { + Set nSaL = nextSetasListRest.remove(0); + synchronized (this) { nextSetasList.remove(nSaL); + writeLog("-1 RM" + nSaL.toString()); + } Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); @@ -919,12 +941,17 @@ public class TypeUnifyTask extends RecursiveTask>> { //res = unify2(elems, eq, fc, parallel); res = forkOrig.join(); for(TypeUnifyTask fork : forks) { - Set> fork_res = fork.join(); - synchronized (this) { noOfThread--; }; - add_res.add(fork_res); + synchronized (this) { + Set> fork_res = fork.join(); + writeLog("Join " + new Integer(fork.thNo).toString()); + noOfThread--; + add_res.add(fork_res); + }; } } else { - if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { + if(parallel && (variance == 2) //&& noOfThread <= MaxNoOfThreads + ) { + writeLog("var2einstieg"); Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); @@ -933,9 +960,13 @@ public class TypeUnifyTask extends RecursiveTask>> { TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); forks.add(forkOrig); forkOrig.fork(); - - while (!nextSetasListRestOder.isEmpty()) { - Set nSaL = nextSetasListRestOder.remove(0); + synchronized (this) { + writeLog("a in " + variance + " "+ a); + writeLog("nextSetasListRest: " + nextSetasListRest.toString()); + } + while (!nextSetasListRest.isEmpty()) { + Set nSaL = nextSetasListRest.remove(0); + //nextSetasList.remove(nSaL); Set newEq = new HashSet<>(eq); Set> newElems = new HashSet<>(elems); List>> newOderConstraints = new ArrayList<>(oderConstraints); @@ -947,13 +978,16 @@ public class TypeUnifyTask extends RecursiveTask>> { //res = unify2(elems, eq, fc, parallel); res = forkOrig.join(); for(TypeUnifyTask fork : forks) { - Set> fork_res = fork.join(); - synchronized (this) { noOfThread--; }; - add_res.add(fork_res); + synchronized (this) { + Set> fork_res = fork.join(); + writeLog("Join " + new Integer(fork.thNo).toString()); + noOfThread--; + add_res.add(fork_res); + }; }} else { - parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten - elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 833 + //parallel = false; //Wenn MaxNoOfThreads erreicht ist, sequentiell weiterarbeiten + elems.add(a); //PL 2019-01-16 muss das wirklich hin steht schon in Zeile 859 ja braucht man siehe Zeile 859 res = unify2(elems, eq, oderConstraints, fc, parallel, rekTiefe); }}} if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { @@ -1033,13 +1067,13 @@ public class TypeUnifyTask extends RecursiveTask>> { //result = result; }}}} else { if (variance == 0) { - writeLog("RESADD:" + result.toString() + " " + res.toString()); + writeLog("RES var=1 ADD:" + result.toString() + " " + res.toString()); result.addAll(res); - }}} - //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + }}} } else { - writeLog("RESADD:" + result.toString() + " " + res.toString()); + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES Fst:" + result.toString() + " " + res.toString()); result.addAll(res); } } @@ -1076,12 +1110,12 @@ public class TypeUnifyTask extends RecursiveTask>> { || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) || result.isEmpty()) { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RESADD:" + result.toString() + " " + par_res.toString()); + writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); result.addAll(par_res); } } } - break; + //break; } /* nextSetasList = nextSetasListRest; */ /* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet @@ -1117,12 +1151,12 @@ public class TypeUnifyTask extends RecursiveTask>> { || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) || result.isEmpty()) { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RESADD:" + result.toString() + " " + par_res.toString()); + writeLog("RES var-1 ADD:" + result.toString() + " " + par_res.toString()); result.addAll(par_res); } } } - break; + //break; } System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); @@ -1157,12 +1191,12 @@ public class TypeUnifyTask extends RecursiveTask>> { || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) || result.isEmpty()) { //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden - writeLog("RESADD:" + result.toString() + " " + par_res.toString()); + writeLog("RES var2 ADD:" + result.toString() + " " + par_res.toString()); result.addAll(par_res); } } } - break; + //break; } }}} writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); @@ -2069,6 +2103,6 @@ public class TypeUnifyTask extends RecursiveTask>> { System.err.println("kein LogFile"); } } - } + } } } diff --git a/src/test/resources/bytecode/javFiles/Matrix.jav b/src/test/resources/bytecode/javFiles/Matrix.jav index 9e87c1e6..29505161 100644 --- a/src/test/resources/bytecode/javFiles/Matrix.jav +++ b/src/test/resources/bytecode/javFiles/Matrix.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -//import java.lang.Float; +import java.lang.Float; //import java.lang.Byte; //import java.lang.Boolean; From 25487469c7359d5d0102b8aebd2a5feff1c52626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 23 Jan 2019 01:31:25 +0100 Subject: [PATCH 06/17] modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java reduceEq-Regel korrigiert modified: ../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java Threads soweit fertig --- .../typeinference/unify/RuleSet.java | 17 ++- .../typeinference/unify/TypeUnifyTask.java | 105 +++++++++++++++--- 2 files changed, 101 insertions(+), 21 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index d4e6b551..a3430577 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -319,13 +319,20 @@ public class RuleSet implements IRuleSet{ UnifyType lhsType = pair.getLhsType(); ReferenceType lhsSType; + UnifyType rhsType = pair.getRhsType(); + ReferenceType rhsSType; - if(lhsType instanceof ReferenceType) + if ((lhsType instanceof ReferenceType) && (rhsType instanceof ReferenceType)) { lhsSType = (ReferenceType) lhsType; - else if(lhsType instanceof WildcardType) { + rhsSType = (ReferenceType) rhsType; + } + else if ((lhsType instanceof WildcardType) && (rhsType instanceof WildcardType)) { UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType(); - if(lhsSTypeRaw instanceof ReferenceType) + UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType(); + if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) { lhsSType = (ReferenceType) lhsSTypeRaw; + rhsSType = (ReferenceType) rhsSTypeRaw; + } else return Optional.empty(); } @@ -334,7 +341,8 @@ public class RuleSet implements IRuleSet{ if(lhsSType.getTypeParams().empty()) return Optional.empty(); - + + /* PL 2018-01-22 in obere Teil integriert UnifyType rhsType = pair.getRhsType(); ReferenceType rhsSType; @@ -349,6 +357,7 @@ public class RuleSet implements IRuleSet{ } else return Optional.empty(); + */ if(!rhsSType.getName().equals(lhsSType.getName())) return Optional.empty(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index ab672f5e..8b2c7c3c 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -61,7 +61,7 @@ public class TypeUnifyTask extends RecursiveTask>> { */ private static int noOfThread = 0; private static int totalnoOfThread = 0; - private int thNo; + int thNo; protected boolean one = false; Integer MaxNoOfThreads = 4; @@ -709,12 +709,12 @@ public class TypeUnifyTask extends RecursiveTask>> { * Step 6 b) Build the union over everything. */ /* - * PL 2019-01-20: muss uebrprueft werden - */ + * PL 2019-01-22: geloescht + if(parallel) for(TypeUnifyTask fork : forks) eqPrimePrimeSet.addAll(fork.join()); - + */ /* * Step 7: Filter empty sets; */ @@ -881,9 +881,13 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); + + /* FORK ANFANG TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); - forks.add(forkOrig); + //forks.add(forkOrig); forkOrig.fork(); + FORK ENDE */ + synchronized (this) { writeLog("a in " + variance + " "+ a); writeLog("nextSetasListRest: " + nextSetasListRest.toString()); @@ -901,8 +905,18 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - //res = unify2(elems, eq, fc, parallel); - res = forkOrig.join(); + res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + + /* FORK ANFANG + synchronized (this) { + res = forkOrig.join(); + //Set> fork_res = forkOrig.join(); + writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + noOfThread--; + //add_res.add(fork_res); + }; + FORK ENDE */ + for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -918,9 +932,13 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); + + /* FORK ANFANG TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); - forks.add(forkOrig); + //forks.add(forkOrig); forkOrig.fork(); + FORK ENDE */ + synchronized (this) { writeLog("a in " + variance + " "+ a); writeLog("nextSetasListRest: " + nextSetasListRest.toString()); @@ -938,8 +956,18 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - //res = unify2(elems, eq, fc, parallel); - res = forkOrig.join(); + res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + + /* FORK ANFANG + synchronized (this) { + res = forkOrig.join(); + //Set> fork_res = forkOrig.join(); + writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + noOfThread--; + //add_res.add(fork_res); + }; + FORK ENDE */ + for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -949,17 +977,20 @@ public class TypeUnifyTask extends RecursiveTask>> { }; } } else { - if(parallel && (variance == 2) //&& noOfThread <= MaxNoOfThreads - ) { + if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { writeLog("var2einstieg"); Set forks = new HashSet<>(); Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); + + /* FORK ANFANG TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); - forks.add(forkOrig); + //forks.add(forkOrig); forkOrig.fork(); + FORK ENDE */ + synchronized (this) { writeLog("a in " + variance + " "+ a); writeLog("nextSetasListRest: " + nextSetasListRest.toString()); @@ -975,8 +1006,18 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - //res = unify2(elems, eq, fc, parallel); - res = forkOrig.join(); + res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + + /* FORK ANFANG + synchronized (this) { + res = forkOrig.join(); + //Set> fork_res = forkOrig.join(); + writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); + noOfThread--; + //add_res.add(fork_res); //vermutlich falsch + }; + FORK ENDE */ + for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); @@ -1089,6 +1130,27 @@ public class TypeUnifyTask extends RecursiveTask>> { //else {//duerfte gar nicht mehr vorkommen PL 2018-04-03 //result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); //} + if (parallel) { + for (Set> par_res : add_res) { + if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { + //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen + result = par_res; + if (par_res.iterator().next() instanceof WildcardType) { + System.out.println(""); + } + } + else { + if ((isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) + || (!isUndefinedPairSetSet(par_res) && !isUndefinedPairSetSet(result)) + || result.isEmpty()) { + //alle Fehlerfaelle und alle korrekten Ergebnis jeweils adden + writeLog("RES var1 ADD:" + result.toString() + " " + par_res.toString()); + result.addAll(par_res); + } + } + } + //break; + } /* auskommentiert um alle Max und min Betrachtung auszuschalten ANFANG */ if (!result.isEmpty() && !isUndefinedPairSetSet(res)) { @@ -1096,6 +1158,7 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { + /* vorgezogen vor das if if (parallel) { for (Set> par_res : add_res) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { @@ -1116,7 +1179,8 @@ public class TypeUnifyTask extends RecursiveTask>> { } } //break; - } + */ + /* nextSetasList = nextSetasListRest; */ /* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet */ @@ -1137,6 +1201,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } } else { if (variance == -1) { + /* vorgezogen vor das if if (parallel) { for (Set> par_res : add_res) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { @@ -1156,8 +1221,12 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } - //break; + //break; } + + } + */ + System.out.println(""); writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); while (nextSetasListIt.hasNext()) { @@ -1177,6 +1246,7 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); break; } else { if (variance == 2) { + /* vorgezogen vor das if if (parallel) { for (Set> par_res : add_res) { if (!isUndefinedPairSetSet(par_res) && isUndefinedPairSetSet(result)) { @@ -1198,6 +1268,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } //break; } + */ }}} writeLog("a: " + rekTiefe + " variance: " + variance + a.toString()); } From 0a4a625198a784cbb43ec87b5a7474ccb9d397b3 Mon Sep 17 00:00:00 2001 From: Michael Uhl Date: Wed, 23 Jan 2019 22:04:25 +0100 Subject: [PATCH 07/17] Removed "tycho-p2-repository-plugin". --- pom.xml | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pom.xml b/pom.xml index 8ae93bf5..5ef18209 100644 --- a/pom.xml +++ b/pom.xml @@ -139,19 +139,6 @@ - - org.eclipse.tycho - tycho-p2-repository-plugin - ${tycho.version} - - - package - - archive-repository - - - - From 449a11f43300ff43059e5b666c616be028830a60 Mon Sep 17 00:00:00 2001 From: Michael Uhl Date: Wed, 23 Jan 2019 22:25:30 +0100 Subject: [PATCH 08/17] =?UTF-8?q?Observer=20f=C3=BCr=20TypeResults.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../typeinference/unify/UnifyResultEvent.java | 16 +++++++++++ .../unify/UnifyResultListener.java | 7 +++++ .../typeinference/unify/UnifyResultModel.java | 27 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListener.java create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java new file mode 100644 index 00000000..05433287 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java @@ -0,0 +1,16 @@ +package de.dhbwstuttgart.typeinference.unify; + +import de.dhbwstuttgart.typeinference.result.ResultSet; + +public class UnifyResultEvent { + + private ResultSet newTypeResult; + + public UnifyResultEvent(ResultSet newTypeResult) { + this.newTypeResult = newTypeResult; + } + + public ResultSet getNewTypeResult() { + return newTypeResult; + } +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListener.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListener.java new file mode 100644 index 00000000..f490ccde --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListener.java @@ -0,0 +1,7 @@ +package de.dhbwstuttgart.typeinference.unify; + +public interface UnifyResultListener { + + void onNewTypeResultFound(UnifyResultEvent evt); + +} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java new file mode 100644 index 00000000..a5919c18 --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java @@ -0,0 +1,27 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.List; + +import de.dhbwstuttgart.typeinference.result.ResultSet; + +public class UnifyResultModel { + + private List listeners = new ArrayList<>(); + + public void addUnifyResultListener(UnifyResultListener listenerToAdd) { + listeners.add(listenerToAdd); + } + + public void removeUnifyResultListener(UnifyResultListener listenerToRemove) { + listeners.remove(listenerToRemove); + } + + public void notify(ResultSet newResult) { + UnifyResultEvent evt = new UnifyResultEvent(newResult); + + for (UnifyResultListener listener : listeners) { + listener.onNewTypeResultFound(evt); + } + } +} From e83d59d97d3d1cbda70544b50cb1a70a3642e744 Mon Sep 17 00:00:00 2001 From: Michael Uhl Date: Thu, 24 Jan 2019 11:16:26 +0100 Subject: [PATCH 09/17] =?UTF-8?q?Observer=20Pattern=20f=C3=BCr=20ResultSet?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 7 +++++++ .../typeinference/unify/UnifyResultEvent.java | 8 +++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index f339af1a..d7915f3f 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -33,6 +33,7 @@ import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; +import de.dhbwstuttgart.typeinference.unify.UnifyResultModel; import java.io.File; import java.io.FileOutputStream; @@ -43,6 +44,8 @@ import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; + public class JavaTXCompiler { final CompilationEnvironment environment; @@ -268,6 +271,10 @@ public class JavaTXCompiler { } */ + public UnifyResultModel typeInferenceAsync() throws ClassNotFoundException { + return new UnifyResultModel(); + } + public List typeInference() throws ClassNotFoundException { List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java index 05433287..a79e34ec 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultEvent.java @@ -1,16 +1,18 @@ package de.dhbwstuttgart.typeinference.unify; +import java.util.List; + import de.dhbwstuttgart.typeinference.result.ResultSet; public class UnifyResultEvent { - private ResultSet newTypeResult; + private List newTypeResult; - public UnifyResultEvent(ResultSet newTypeResult) { + public UnifyResultEvent(List newTypeResult) { this.newTypeResult = newTypeResult; } - public ResultSet getNewTypeResult() { + public List getNewTypeResult() { return newTypeResult; } } From 3c0beabc1b1a27855b9279a250be07fccb2399d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 25 Jan 2019 22:19:32 +0100 Subject: [PATCH 10/17] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java reduce2 nochmals angepasst modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java - Fehler behoben - In den Thread nur noch Element von nextSet verschieben, die auf alle Faele berechnet werdne muessen --- .../typeinference/unify/RuleSet.java | 3 +- .../typeinference/unify/TypeUnifyTask.java | 47 +++++++++++++++++-- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index a3430577..a8c0675d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -326,7 +326,8 @@ public class RuleSet implements IRuleSet{ lhsSType = (ReferenceType) lhsType; rhsSType = (ReferenceType) rhsType; } - else if ((lhsType instanceof WildcardType) && (rhsType instanceof WildcardType)) { + else if (((lhsType instanceof ExtendsType) && (rhsType instanceof ExtendsType)) + || ((lhsType instanceof SuperType) && (rhsType instanceof SuperType))) { UnifyType lhsSTypeRaw = ((WildcardType) lhsType).getWildcardedType(); UnifyType rhsSTypeRaw = ((WildcardType) rhsType).getWildcardedType(); if ((lhsSTypeRaw instanceof ReferenceType) && (rhsSTypeRaw instanceof ReferenceType)) { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 8b2c7c3c..da3d508b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -810,6 +810,23 @@ public class TypeUnifyTask extends RecursiveTask>> { nextSetasListRest.remove(a_next); } } + //Alle maximale Elemente in nextSetasListRest bestimmen + List> nextSetasListRestTest; + do { + nextSetasListRestTest = new ArrayList>(nextSetasListRest); + if (!nextSetasListRest.isEmpty()) { + Set max = oup.max(nextSetasListRest.iterator()); + Iterator> nextSetasListItRest2 = new ArrayList>(nextSetasListRest).iterator(); + while (nextSetasListItRest2.hasNext()) { + Set a_nextRest = nextSetasListItRest2.next(); + if (//a.equals(a_next) || + (oup.compare(max, a_nextRest) == 1)) { + nextSetasListRest.remove(a_nextRest); + } + + }} + } while(!nextSetasListRestTest.equals(nextSetasListRest)); + } else if (variance == -1) { a = oup.min(nextSetasList.iterator()); @@ -823,6 +840,23 @@ public class TypeUnifyTask extends RecursiveTask>> { nextSetasListRest.remove(a_next); } } + //Alle minimalen Elemente in nextSetasListRest bestimmen + + List> nextSetasListRestTest; + do { + nextSetasListRestTest = new ArrayList>(nextSetasListRest); + if (!nextSetasListRest.isEmpty()) { + Set min = oup.min(nextSetasListRest.iterator()); + Iterator> nextSetasListItRest2 = new ArrayList>(nextSetasListRest).iterator(); + while (nextSetasListItRest2.hasNext()) { + Set a_nextRest = nextSetasListItRest2.next(); + if (//a.equals(a_next) || + (oup.compare(min, a_nextRest) == -1)) { + nextSetasListRest.remove(a_nextRest); + } + + }} + } while(!nextSetasListRestTest.equals(nextSetasListRest)); } else if (variance == 2) { a = nextSetasList.remove(0); @@ -1860,13 +1894,17 @@ public class TypeUnifyTask extends RecursiveTask>> { for(UnifyType c : csPHRenamed) { //PL 18-02-05 getChildren durch smaller ersetzt in getChildren werden die Varianlen nicht ersetzt. - Set thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new)); + Set thetaQs = new HashSet<>(); + //TODO smaller wieder reinnehmen? + //thetaQs.add(c);// + thetaQs = fc.smaller(c, new HashSet<>()).stream().collect(Collectors.toCollection(HashSet::new)); //Set thetaQs = fc.getChildren(c).stream().collect(Collectors.toCollection(HashSet::new)); //thetaQs.add(thetaPrime); //PL 18-02-05 wieder geloescht //PL 2017-10-03: War auskommentiert habe ich wieder einkommentiert, //da children offensichtlich ein echtes kleiner und kein kleinergleich ist //PL 18-02-06: eingefuegt, thetaQs der Form V> <. V'> werden entfernt + //TODO PL 19-01-14 wieder reinnehmen kurzfristig auskommentiert thetaQs = thetaQs.stream().filter(ut -> ut.getTypeParams().arePlaceholders()).collect(Collectors.toCollection(HashSet::new)); //PL 18-02-06: eingefuegt @@ -1931,13 +1969,16 @@ public class TypeUnifyTask extends RecursiveTask>> { if(allGen) { UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); - while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor + while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance());//((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } else { UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); - while (upit.hasNext()) ((PlaceholderType)upit.next()).setVariance(a.getVariance()); + distributeVariance dv = new distributeVariance(); + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor + while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance()); //((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } resultPrime.addAll(substitutionSet); From 9dcb1f76cab606a7356b4baaa3a5590d8a9fb427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 25 Jan 2019 22:22:16 +0100 Subject: [PATCH 11/17] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java --- .../de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java index a5919c18..dc600939 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java @@ -17,7 +17,7 @@ public class UnifyResultModel { listeners.remove(listenerToRemove); } - public void notify(ResultSet newResult) { + public void notify(Set newResult) { UnifyResultEvent evt = new UnifyResultEvent(newResult); for (UnifyResultListener listener : listeners) { From 26634bb03842b55e9884b85c01d65ceb911e310e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Fri, 25 Jan 2019 22:26:38 +0100 Subject: [PATCH 12/17] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java --- .../de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java index dc600939..fe72bfea 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.util.ArrayList; import java.util.List; +import java.util.Set; import de.dhbwstuttgart.typeinference.result.ResultSet; @@ -17,7 +18,7 @@ public class UnifyResultModel { listeners.remove(listenerToRemove); } - public void notify(Set newResult) { + public void notify(List newResult) { UnifyResultEvent evt = new UnifyResultEvent(newResult); for (UnifyResultListener listener : listeners) { From ca7c76a99af59c6fc6eb3fd6886c6721391e258e Mon Sep 17 00:00:00 2001 From: Pluemicke Martin Date: Tue, 29 Jan 2019 14:47:20 +0100 Subject: [PATCH 13/17] =?UTF-8?q?=09ge=C3=A4ndert:=20=20=20=20=20=20=20src?= =?UTF-8?q?/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java=20=09ge?= =?UTF-8?q?=C3=A4ndert:=20=20=20=20=20=20=20src/main/java/de/dhbwstuttgart?= =?UTF-8?q?/typeinference/constraints/ConstraintSet.java=20=09ge=C3=A4nder?= =?UTF-8?q?t:=20=20=20=20=20=20=20src/main/java/de/dhbwstuttgart/typeinfer?= =?UTF-8?q?ence/constraints/Pair.java=20=09ge=C3=A4ndert:=20=20=20=20=20?= =?UTF-8?q?=20=20src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUn?= =?UTF-8?q?ify.java=20=09ge=C3=A4ndert:=20=20=20=20=20=20=20src/main/java/?= =?UTF-8?q?de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java=20=09g?= =?UTF-8?q?e=C3=A4ndert:=20=20=20=20=20=20=20src/main/java/de/dhbwstuttgar?= =?UTF-8?q?t/typeinference/unify/TypeUnifyTask.java=20=09ge=C3=A4ndert:=20?= =?UTF-8?q?=20=20=20=20=20=20src/main/java/de/dhbwstuttgart/typeinference/?= =?UTF-8?q?unify/UnifyResultModel.java?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 24 +++++------------ .../constraints/ConstraintSet.java | 1 + .../typeinference/constraints/Pair.java | 18 +++++++++++++ .../typeinference/unify/TypeUnify.java | 19 ++++++++++--- .../typeinference/unify/TypeUnify2Task.java | 6 +++-- .../typeinference/unify/TypeUnifyTask.java | 27 ++++++++++++++++--- .../typeinference/unify/UnifyResultModel.java | 2 +- 7 files changed, 69 insertions(+), 28 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index d7915f3f..5a749dcc 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -27,6 +27,7 @@ import de.dhbwstuttgart.typeinference.typeAlgo.TYPE; import de.dhbwstuttgart.typeinference.unify.RuleSet; import de.dhbwstuttgart.typeinference.unify.TypeUnify; import de.dhbwstuttgart.typeinference.unify.distributeVariance; +import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; @@ -289,7 +290,7 @@ public class JavaTXCompiler { try { FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); - FiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); + IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); @@ -402,8 +403,9 @@ public class JavaTXCompiler { } return ret; }).collect(Collectors.toCollection(ArrayList::new)); - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log); + unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); @@ -430,7 +432,7 @@ public class JavaTXCompiler { System.err.println("kein LogFile"); } return results.stream().map((unifyPairs -> - new ResultSet(UnifyTypeFactory.convert(unifyPairs, generateTPHMap(cons))))).collect(Collectors.toList()); + new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()); } @@ -479,19 +481,7 @@ public class JavaTXCompiler { } - private Map generateTPHMap(ConstraintSet constraints) { - HashMap ret = new HashMap<>(); - constraints.map((Pair p) -> { - if (p.TA1 instanceof TypePlaceholder) { - ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1); - } - if (p.TA2 instanceof TypePlaceholder) { - ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2); - } - return null; - }); - return ret; - } + private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException { CompilationUnitContext tree = JavaTXParser.parse(sourceFile); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java index 4d1f076f..1dda8dc5 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/ConstraintSet.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.constraints; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.unify.GuavaSetOperations; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java index 98679f7d..0c8ad7a5 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/constraints/Pair.java @@ -1,7 +1,10 @@ package de.dhbwstuttgart.typeinference.constraints; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric; +import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.typeinference.unify.model.PairOperator; @@ -110,5 +113,20 @@ public class Pair implements Serializable public boolean OperatorSmallerDot() { return eOperator == PairOperator.SMALLERDOT; } + + + static public Map generateTPHMap(ConstraintSet constraints) { + HashMap ret = new HashMap<>(); + constraints.map((Pair p) -> { + if (p.TA1 instanceof TypePlaceholder) { + ret.put(((TypePlaceholder) p.TA1).getName(), (TypePlaceholder) p.TA1); + } + if (p.TA2 instanceof TypePlaceholder) { + ret.put(((TypePlaceholder) p.TA2).getName(), (TypePlaceholder) p.TA2); + } + return null; + }); + return ret; + } } // ino.end diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index fecd28fe..aa7fe5ea 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -6,18 +6,29 @@ import java.util.Set; import java.util.concurrent.ForkJoinPool; import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; +import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class TypeUnify { - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0); + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, new UnifyResultModel(), cons); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); Set> res = unifyTask.join(); return res; } + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { + UnifyResultModel ret = new UnifyResultModel(); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); + ForkJoinPool pool = new ForkJoinPool(); + pool.invoke(unifyTask); + return ret; + } + /* public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); @@ -26,8 +37,8 @@ public class TypeUnify { } */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0); + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, logFile, log, 0, new UnifyResultModel(), cons); Set> res = unifyTask.compute(); return res; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 95ccdf07..7c0a587d 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -6,6 +6,8 @@ import java.util.List; import java.util.Set; import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.constraints.Pair; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; @@ -13,8 +15,8 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe) { - super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe); + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { + super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); 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 8b2c7c3c..5b043b27 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -19,7 +19,10 @@ import java.util.function.BinaryOperator; import java.util.stream.Collectors; import java.util.stream.Stream; +import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory; import de.dhbwstuttgart.typeinference.constraints.Constraint; +import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; +import de.dhbwstuttgart.typeinference.result.ResultSet; import de.dhbwstuttgart.typeinference.unify.interfaces.IFiniteClosure; import de.dhbwstuttgart.typeinference.unify.interfaces.IRuleSet; import de.dhbwstuttgart.typeinference.unify.interfaces.ISetOperations; @@ -59,6 +62,8 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Fuer die Threads */ + UnifyResultModel urm; + ConstraintSet cons; private static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; @@ -123,7 +128,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } */ - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons2) { synchronized (this) { 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)); @@ -144,6 +149,8 @@ public class TypeUnifyTask extends RecursiveTask>> { this.log = log; rules = new RuleSet(logFile); this.rekTiefeField = rekTiefe; + this.urm = urm; + this.cons = cons2; noOfThread++; totalnoOfThread++; @@ -688,6 +695,18 @@ public class TypeUnifyTask extends RecursiveTask>> { System.err.println("log-File nicht vorhanden"); } eqPrimePrimeSet.add(eqPrime); + Set> eqPrimePrimeSetRet = eqPrimePrimeSet.stream().map(x -> { + Optional> res = new RuleSet().subst(x.stream().map(y -> { + if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); + return y; //alle Paare a <.? b erden durch a =. b ersetzt + }).collect(Collectors.toCollection(HashSet::new))); + if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert + return new TypeUnifyTask().applyTypeUnificationRules(res.get(), fc); + } + else return x; //wenn nichts veraendert wurde wird x zurueckgegeben + }).collect(Collectors.toCollection(HashSet::new)); + urm.notify(eqPrimePrimeSetRet.stream().map((unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, de.dhbwstuttgart.typeinference.constraints.Pair.generateTPHMap(cons))))).collect(Collectors.toList())); } else if(eqPrimePrime.isPresent()) { Set> unifyres = unifyres1 = unify(eqPrimePrime.get(), oderConstraints, fc, parallel, rekTiefe); @@ -901,7 +920,7 @@ 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, fc, parallel, logFile, log, rekTiefe); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -952,7 +971,7 @@ 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, fc, parallel, logFile, log, rekTiefe); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } @@ -1002,7 +1021,7 @@ 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, fc, parallel, logFile, log, rekTiefe); + TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); forks.add(fork); fork.fork(); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java index a5919c18..fc04c8e7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultModel.java @@ -17,7 +17,7 @@ public class UnifyResultModel { listeners.remove(listenerToRemove); } - public void notify(ResultSet newResult) { + public void notify(List newResult) { UnifyResultEvent evt = new UnifyResultEvent(newResult); for (UnifyResultListener listener : listeners) { From 9e1d58f4b17e1a6ffc82971674ec6e18ac452860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Tue, 29 Jan 2019 14:51:19 +0100 Subject: [PATCH 14/17] modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java Threads soweit fertig --- .../typeinference/unify/TypeUnify2Task.java | 1 + .../typeinference/unify/TypeUnifyTask.java | 60 ++++++++----------- .../unify/model/FiniteClosure.java | 29 ++++++++- .../unify/model/OrderingUnifyPair.java | 2 +- 4 files changed, 54 insertions(+), 38 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 95ccdf07..a8f446c9 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -29,6 +29,7 @@ public class TypeUnify2Task extends TypeUnifyTask { return new HashSet<>(); } else */ + noOfThread--; return res; } } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index da3d508b..acbabdd2 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -59,11 +59,11 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Fuer die Threads */ - private static int noOfThread = 0; + protected static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; protected boolean one = false; - Integer MaxNoOfThreads = 4; + Integer MaxNoOfThreads = 8; public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; FileWriter logFile; @@ -200,6 +200,7 @@ public class TypeUnifyTask extends RecursiveTask>> { .filter(x -> x.size()>1) .collect(Collectors.toCollection(ArrayList::new)); Set> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField); + noOfThread--; if (isUndefinedPairSetSet(res)) { return new HashSet<>(); } else return res; } @@ -891,7 +892,7 @@ public class TypeUnifyTask extends RecursiveTask>> { //for(Set a : newSet) { i++; Set> elems = new HashSet>(fstElems); - writeLog("a1: " + rekTiefe + " "+ a.toString()+ "\n"); + writeLog("a1: " + rekTiefe + " "+ "variance: "+ variance + " " + a.toString()+ "\n"); //elems.add(a); PL 2019-01-20 Muss weg, weil das in jeweiligen Thread erfolgen muss. Fuer den sequentiellen Fall //im else-Zweig //if (remainingSets.isEmpty()) {//muss immer gegeben sein, weil nur 1 Element der topLevelSets mehr als ein Elemet enthaelt @@ -899,28 +900,17 @@ public class TypeUnifyTask extends RecursiveTask>> { Set> res = new HashSet<>(); Set>> add_res = new HashSet<>(); if(parallel && (variance == 1) && noOfThread <= MaxNoOfThreads) { - /* - elems.add(a); - TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log); - fork.fork(); - res = fork.join(); - */ - Set forks = new HashSet<>(); - - //TypeUnify2Task fork1 = new TypeUnify2Task(elems, eq, fc, parallel, logFile, log); - - Set newEqOrig = new HashSet<>(eq); Set> newElemsOrig = new HashSet<>(elems); List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); - /* FORK ANFANG + /* FORK ANFANG */ TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); //forks.add(forkOrig); forkOrig.fork(); - FORK ENDE */ + /* FORK ENDE */ synchronized (this) { writeLog("a in " + variance + " "+ a); @@ -939,23 +929,23 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); - /* FORK ANFANG + /* FORK ANFANG */ synchronized (this) { res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben //add_res.add(fork_res); }; - FORK ENDE */ + /* FORK ENDE */ for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); }; } @@ -967,11 +957,11 @@ public class TypeUnifyTask extends RecursiveTask>> { List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); - /* FORK ANFANG + /* FORK ANFANG */ TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); //forks.add(forkOrig); forkOrig.fork(); - FORK ENDE */ + /* FORK ENDE */ synchronized (this) { writeLog("a in " + variance + " "+ a); @@ -990,23 +980,23 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); - /* FORK ANFANG + /* FORK ANFANG */ synchronized (this) { res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben //add_res.add(fork_res); }; - FORK ENDE */ + /* FORK ENDE */ for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); }; } @@ -1019,11 +1009,11 @@ public class TypeUnifyTask extends RecursiveTask>> { List>> newOderConstraintsOrig = new ArrayList<>(oderConstraints); newElemsOrig.add(a); - /* FORK ANFANG + /* FORK ANFANG */ TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); //forks.add(forkOrig); forkOrig.fork(); - FORK ENDE */ + /* FORK ENDE */ synchronized (this) { writeLog("a in " + variance + " "+ a); @@ -1040,23 +1030,23 @@ public class TypeUnifyTask extends RecursiveTask>> { forks.add(fork); fork.fork(); } - res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); + //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); - /* FORK ANFANG + /* FORK ANFANG */ synchronized (this) { res = forkOrig.join(); //Set> fork_res = forkOrig.join(); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben //add_res.add(fork_res); //vermutlich falsch }; - FORK ENDE */ + /* FORK ENDE */ for(TypeUnifyTask fork : forks) { synchronized (this) { Set> fork_res = fork.join(); writeLog("Join " + new Integer(fork.thNo).toString()); - noOfThread--; + //noOfThread--; an das Ende von compute verschoben add_res.add(fork_res); }; }} diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 07c86457..c52f47a7 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -109,6 +109,18 @@ implements IFiniteClosure { strInheritanceGraph.get(key.getName()).add(inheritanceGraph.get(key)); } } + + void testSmaller() { + UnifyType tq1, tq2, tq3; + tq1 = new ExtendsType(PlaceholderType.freshPlaceholder()); + List l1 = new ArrayList<>(); + List l2 = new ArrayList<>(); + l1.add(tq1); + tq2 = new ReferenceType("java.util.Vector", new TypeParams(l1)); + l2.add(tq2); + tq3 = new ReferenceType("java.util.Vector", new TypeParams(l2)); + Set smaller = smaller(tq3, new HashSet<>()); + } /** * Returns all types of the finite closure that are subtypes of the argument. @@ -641,8 +653,7 @@ implements IFiniteClosure { */ public int compare (UnifyType left, UnifyType right, PairOperator pairop) { - if ((left instanceof ExtendsType && right instanceof ReferenceType) - || (right instanceof ExtendsType && left instanceof ReferenceType)) + if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) System.out.println(""); /* List al = new ArrayList<>(); @@ -693,6 +704,13 @@ implements IFiniteClosure { HashSet hs = new HashSet<>(); hs.add(up); Set smallerRes = unifyTask.applyTypeUnificationRules(hs, this); + if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) + {try { + logFile.write("\nsmallerRes: " + smallerRes);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile");}} //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. long smallerLen = smallerRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); if (smallerLen == 0) return -1; @@ -702,6 +720,13 @@ implements IFiniteClosure { hs = new HashSet<>(); hs.add(up); Set greaterRes = unifyTask.applyTypeUnificationRules(hs, this); + if (left.getName().equals("Matrix") || right.getName().equals("Matrix")) + {try { + logFile.write("\ngreaterRes: " + greaterRes);//"smallerHash: " + greaterHash.toString()); + logFile.flush(); + } + catch (IOException e) { + System.err.println("no LogFile");}} //Gleichungen der Form a <./=. Theta oder Theta <./=. a oder a <./=. b sind ok. long greaterLen = greaterRes.stream().filter(x -> !(x.getLhsType() instanceof PlaceholderType || x.getRhsType() instanceof PlaceholderType)).count(); if (greaterLen == 0) return 1; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java index 73d73578..490826cc 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/OrderingUnifyPair.java @@ -229,7 +229,7 @@ public class OrderingUnifyPair extends Ordering> { if (leftlewc.iterator().next().getLhsType() instanceof PlaceholderType) { hm = rsleuni.stream().reduce(new HashMap(), (x, y)-> { x.put(y.getLhsType(),y); return x; }, combiner); Stream lslewcstr = lsleuni.stream().filter(x -> !(hm.get(x.getLhsType()) == null)); - si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); + si = lslewcstr.map(x -> fc.compare(x.getRhsType(), hm.get(x.getLhsType()).getRhsType(), PairOperator.SMALLERDOTWC)).reduce((x,y)-> { if (x == y) return x; else return 0; } ); } //4. Fall else { From aa0b1573743b0aa73b8473c7184ca7b686d6fb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Wed, 30 Jan 2019 09:11:33 +0100 Subject: [PATCH 15/17] 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/TypeUnifyTask.java new file: src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java modified: src/test/resources/bytecode/javFiles/MatrixOP.jav Erster Ansatz asyncrone Threads --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 73 +++++++++++-------- .../typeinference/unify/TypeUnify.java | 11 ++- .../typeinference/unify/TypeUnifyTask.java | 17 +++-- .../unify/UnifyResultListenerImpl.java | 21 ++++++ .../resources/bytecode/javFiles/MatrixOP.jav | 2 +- 5 files changed, 84 insertions(+), 40 deletions(-) create mode 100644 src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 5a749dcc..b9d1da90 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -34,6 +34,7 @@ import de.dhbwstuttgart.typeinference.unify.model.PlaceholderType; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; import de.dhbwstuttgart.typeinference.unify.model.UnifyType; import de.dhbwstuttgart.typeinference.unify.TypeUnifyTask; +import de.dhbwstuttgart.typeinference.unify.UnifyResultListenerImpl; import de.dhbwstuttgart.typeinference.unify.UnifyResultModel; import java.io.File; @@ -50,6 +51,7 @@ import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; public class JavaTXCompiler { final CompilationEnvironment environment; + Boolean resultmodel = true; public final Map sourceFiles = new HashMap<>(); Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"src/test/java/logFiles" geschrieben werden soll? @@ -403,37 +405,50 @@ public class JavaTXCompiler { } return ret; }).collect(Collectors.toCollection(ArrayList::new)); - unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); - Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); - //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); - System.out.println("RESULT: " + result); - logFile.write("RES: " + result.toString()+"\n"); - logFile.flush(); - results.addAll(result); + if (resultmodel) { + /* UnifyResultModel Anfang */ + UnifyResultModel urm = new UnifyResultModel(); + UnifyResultListenerImpl li = new UnifyResultListenerImpl(); + urm.addUnifyResultListener(li); + unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm); + System.out.println("RESULT Final: " + li.getResults()); + logFile.write("RES_FINAL: " + li.getResults().toString()+"\n"); + logFile.flush(); + return li.getResults(); + } + /* UnifyResultModel End */ + else { + Set> result = unify.unify(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + //Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons); + System.out.println("RESULT: " + result); + logFile.write("RES: " + result.toString()+"\n"); + logFile.flush(); + results.addAll(result); - results = results.stream().map(x -> { - Optional> res = new RuleSet().subst(x.stream().map(y -> { - if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); - return y; //alle Paare a <.? b erden durch a =. b ersetzt - }).collect(Collectors.toCollection(HashSet::new))); - if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert - return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure); - } - else return x; //wenn nichts veraendert wurde wird x zurueckgegeben - }).collect(Collectors.toCollection(HashSet::new)); - System.out.println("RESULT Final: " + results); - logFile.write("RES_FINAL: " + results.toString()+"\n"); - logFile.flush(); - logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); - logFile.flush(); - } - catch (IOException e) { - System.err.println("kein LogFile"); - } - return results.stream().map((unifyPairs -> - new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()); - } + results = results.stream().map(x -> { + Optional> res = new RuleSet().subst(x.stream().map(y -> { + if (y.getPairOp() == PairOperator.SMALLERDOTWC) y.setPairOp(PairOperator.EQUALSDOT); + return y; //alle Paare a <.? b erden durch a =. b ersetzt + }).collect(Collectors.toCollection(HashSet::new))); + if (res.isPresent()) {//wenn subst ein Erg liefert wurde was veraendert + return new TypeUnifyTask().applyTypeUnificationRules(res.get(), finiteClosure); + } + else return x; //wenn nichts veraendert wurde wird x zurueckgegeben + }).collect(Collectors.toCollection(HashSet::new)); + System.out.println("RESULT Final: " + results); + logFile.write("RES_FINAL: " + results.toString()+"\n"); + logFile.flush(); + logFile.write("PLACEHOLDERS: " + PlaceholderType.EXISTING_PLACEHOLDERS); + logFile.flush(); + }} + catch (IOException e) { + System.err.println("kein LogFile"); + } + return results.stream().map((unifyPairs -> + new ResultSet(UnifyTypeFactory.convert(unifyPairs, Pair.generateTPHMap(cons))))).collect(Collectors.toList()); + } + /** diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index aa7fe5ea..d1fc2afe 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -21,14 +21,21 @@ public class TypeUnify { return res; } - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons) { - UnifyResultModel ret = new UnifyResultModel(); + public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); return ret; } + public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); + ForkJoinPool pool = new ForkJoinPool(); + pool.invoke(unifyTask); + Set> res = unifyTask.join(); + return ret; + } + /* public Set> unifySequential(Set eq, IFiniteClosure fc, FileWriter logFile, Boolean log) { TypeUnifyTask unifyTask = new TypeUnifyTask(eq, fc, false, logFile, log); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 904959bb..d8588ae4 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -926,7 +926,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -977,7 +977,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1029,7 +1029,7 @@ public class TypeUnifyTask extends RecursiveTask>> { newElemsOrig.add(a); /* FORK ANFANG */ - TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe); + TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, logFile, log, rekTiefe, urm, cons); //forks.add(forkOrig); forkOrig.fork(); /* FORK ENDE */ @@ -1878,12 +1878,13 @@ public class TypeUnifyTask extends RecursiveTask>> { allGen = false; break; } - //if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 - // && thetaPrime instanceof ReferenceType - // && ((ReferenceType)thetaPrime).getTypeParams().iterator().next().getName().equals("java.util.Vector") + if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 + && thetaPrime instanceof ReferenceType + && ((ReferenceType)thetaPrime).getTypeParams().iterator().next().getName().equals("java.util.Vector")) // && ((ReferenceType)((ReferenceType)thetaPrime).getTypeParams().iterator().next()).getTypeParams().iterator().next().getName().equals("java.lang.Integer")) { - // System.out.println(""); - //} + { + System.out.println(""); + } Set cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector, java.util.Vector>, ????java.util.Vector???] diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java new file mode 100644 index 00000000..16133a3f --- /dev/null +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java @@ -0,0 +1,21 @@ +package de.dhbwstuttgart.typeinference.unify; + +import java.util.ArrayList; +import java.util.List; + +import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; + +public class UnifyResultListenerImpl implements UnifyResultListener { + + List results = new ArrayList<>(); + + public void onNewTypeResultFound(UnifyResultEvent evt) { + results.addAll(evt.getNewTypeResult()); + } + + public List getResults() { + return results; + } + +} diff --git a/src/test/resources/bytecode/javFiles/MatrixOP.jav b/src/test/resources/bytecode/javFiles/MatrixOP.jav index c78c42c7..828a270b 100644 --- a/src/test/resources/bytecode/javFiles/MatrixOP.jav +++ b/src/test/resources/bytecode/javFiles/MatrixOP.jav @@ -1,6 +1,6 @@ import java.util.Vector; import java.lang.Integer; -import java.lang.Byte; +//import java.lang.Byte; import java.lang.Boolean; public class MatrixOP extends Vector> { From 33f2bf3d217a94a16f43d82cb167bb419736bbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pl=C3=BCmicke?= Date: Thu, 31 Jan 2019 15:08:36 +0100 Subject: [PATCH 16/17] modified: src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java modified: src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java Asynchrone Variante soweit ok --- .../de/dhbwstuttgart/core/JavaTXCompiler.java | 133 +++++++++++++++++- .../typeinference/unify/TypeUnifyTask.java | 16 +-- .../unify/UnifyResultListenerImpl.java | 2 +- 3 files changed, 141 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index b9d1da90..2c19d8b3 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -275,7 +275,138 @@ public class JavaTXCompiler { */ public UnifyResultModel typeInferenceAsync() throws ClassNotFoundException { - return new UnifyResultModel(); + List allClasses = new ArrayList<>();//environment.getAllAvailableClasses(); + //Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC + for(SourceFile sf : this.sourceFiles.values()) { + allClasses.addAll(getAvailableClasses(sf)); + allClasses.addAll(sf.getClasses()); + } + + final ConstraintSet cons = getConstraints(); + Set> results = new HashSet<>(); + UnifyResultModel urm = new UnifyResultModel(); + try { + FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + + IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); + System.out.println(finiteClosure); + ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); + + Function distributeInnerVars = + x -> { + UnifyType lhs, rhs; + if (((lhs = x.getLhsType()) instanceof PlaceholderType) + && ((rhs = x.getRhsType()) instanceof PlaceholderType) + && (((PlaceholderType)lhs).isInnerType() + || ((PlaceholderType)rhs).isInnerType())) + { + ((PlaceholderType)lhs).setInnerType(true); + ((PlaceholderType)rhs).setInnerType(true); + } + return x; + + }; + logFile.write(unifyCons.toString()); + unifyCons = unifyCons.map(distributeInnerVars); + logFile.write(unifyCons.toString()); + TypeUnify unify = new TypeUnify(); + //Set> results = new HashSet<>(); Nach vorne gezogen + logFile.write("FC:\\" + finiteClosure.toString()+"\n"); + for(SourceFile sf : this.sourceFiles.values()) { + logFile.write(ASTTypePrinter.print(sf)); + } + logFile.flush(); + + Set methodParaTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().map(y -> y.getParameterList().getFormalparalist() + .stream().filter(z -> z.getType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) ) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;} ); + + Set constructorParaTypeVarNames = allClasses.stream().map(x -> x.getConstructors().stream().map(y -> y.getParameterList().getFormalparalist() + .stream().filter(z -> z.getType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getType()).getName()).collect(Collectors.toCollection(HashSet::new))) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;}, (a,b) -> { a.addAll(b); return a;} ) ) + .reduce(new HashSet(), (a,b) -> { a.addAll(b); return a;} ); + + Set paraTypeVarNames = methodParaTypeVarNames; + paraTypeVarNames.addAll(constructorParaTypeVarNames); + + + Set returnTypeVarNames = allClasses.stream().map(x -> x.getMethods().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get(); + + Set fieldTypeVarNames = allClasses.stream().map(x -> x.getFieldDecl().stream().filter(y -> y.getReturnType() instanceof TypePlaceholder) + .map(z -> ((TypePlaceholder)z.getReturnType()).getName()).collect(Collectors.toCollection(HashSet::new))).reduce((a,b) -> { a.addAll(b); return a;} ).get(); + + returnTypeVarNames.addAll(fieldTypeVarNames); + + unifyCons = unifyCons.map(x -> { + //Hier muss ueberlegt werden, ob + //1. alle Argument- und Retuntyp-Variablen in allen UnifyPairs + // mit disableWildcardtable() werden. + //2. alle Typvariablen mit Argument- oder Retuntyp-Variablen + //in Beziehung auch auf disableWildcardtable() gesetzt werden muessen + //PL 2018-04-23 + if ((x.getLhsType() instanceof PlaceholderType)) { + if (paraTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); + } + if (returnTypeVarNames.contains(x.getLhsType().getName())) { + ((PlaceholderType)x.getLhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getLhsType()).disableWildcardtable(); + } + } + if ((x.getRhsType() instanceof PlaceholderType)) { + if (paraTypeVarNames.contains(x.getRhsType().getName())) { + ((PlaceholderType)x.getRhsType()).setVariance((byte)1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); + } + if (returnTypeVarNames.contains(x.getRhsType().getName())) { + ((PlaceholderType)x.getRhsType()).setVariance((byte)-1); + ((PlaceholderType)x.getRhsType()).disableWildcardtable(); + } + } + return x;//HIER DIE JEWEILS RECHT BZW. LINKE SEITE AUF GLEICHE VARIANZ SETZEN WIE DIE JEWEILS ANDERE SEITE + }); + Set varianceTPHold; + Set varianceTPH = new HashSet<>(); + varianceTPH = varianceInheritanceConstraintSet(unifyCons); + + /* PL 2018-11-07 wird in varianceInheritanceConstraintSet erledigt + do { //PL 2018-11-05 Huellenbildung Variance auf alle TPHs der Terme auf der jeweiligen + //anderen Seite übertragen + varianceTPHold = new HashSet<>(varianceTPH); + varianceTPH = varianceInheritanceConstraintSet(unifyCons); + unifyCons.map( y -> { + if ((y.getLhsType() instanceof PlaceholderType) && (y.getRhsType() instanceof PlaceholderType)) { + if (((PlaceholderType)y.getLhsType()).getVariance() != 0 && ((PlaceholderType)y.getRhsType()).getVariance() == 0) { + ((PlaceholderType)y.getRhsType()).setVariance(((PlaceholderType)y.getLhsType()).getVariance()); + } + if (((PlaceholderType)y.getLhsType()).getVariance() == 0 && ((PlaceholderType)y.getRhsType()).getVariance() != 0) { + ((PlaceholderType)y.getLhsType()).setVariance(((PlaceholderType)y.getRhsType()).getVariance()); + } + } + return y; } ); } + while (!varianceTPHold.equals(varianceTPH)); + */ + + //Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); + //Set> result = unify.unify(xConsSet, finiteClosure); + List>> oderConstraints = unifyCons.getOderConstraints().stream().map(x -> { + Set> ret = new HashSet<>(); + for (Constraint y : x) { + ret.add(new HashSet<>(y)); + } + return ret; + }).collect(Collectors.toCollection(ArrayList::new)); + unify.unifyAsync(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, cons, urm); + } + catch (IOException e) { + System.err.println("kein LogFile"); + } + return urm; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index d8588ae4..eb81e200 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -1878,13 +1878,13 @@ public class TypeUnifyTask extends RecursiveTask>> { allGen = false; break; } - if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 - && thetaPrime instanceof ReferenceType - && ((ReferenceType)thetaPrime).getTypeParams().iterator().next().getName().equals("java.util.Vector")) + //if (thetaPrime.getName().equals("java.util.Vector") //Fuer Bug 127 + // && thetaPrime instanceof ReferenceType + // && ((ReferenceType)thetaPrime).getTypeParams().iterator().next() instanceof PlaceholderType) //.getName().equals("java.util.Vector")) // && ((ReferenceType)((ReferenceType)thetaPrime).getTypeParams().iterator().next()).getTypeParams().iterator().next().getName().equals("java.lang.Integer")) { - { - System.out.println(""); - } + // { + // System.out.println(""); + //} Set cs = fc.getAllTypesByName(thetaPrime.getName());//cs= [java.util.Vector, java.util.Vector>, ????java.util.Vector???] @@ -1979,7 +1979,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if(allGen) { UnifyPair up = new UnifyPair(a, theta, PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); - //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance());//((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } @@ -1987,7 +1987,7 @@ public class TypeUnifyTask extends RecursiveTask>> { UnifyPair up = new UnifyPair(a, theta.setTypeParams(new TypeParams(freshTphs.toArray(new UnifyType[0]))), PairOperator.EQUALSDOT, pair.getSubstitution(), pair); Iterator upit = up.getRhsType().getTypeParams().iterator(); distributeVariance dv = new distributeVariance(); - //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor + //TODO PL 2019-01-24: upit.next() ist nicht unbedingt ein PlaceholderType -> Visitor erledigt while (upit.hasNext()) upit.next().accept(new distributeVariance(), a.getVariance()); //((PlaceholderType)upit.next()).setVariance(a.getVariance()); resultPrime.add(up); } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java index 16133a3f..ea34728b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/UnifyResultListenerImpl.java @@ -10,7 +10,7 @@ public class UnifyResultListenerImpl implements UnifyResultListener { List results = new ArrayList<>(); - public void onNewTypeResultFound(UnifyResultEvent evt) { + public synchronized void onNewTypeResultFound(UnifyResultEvent evt) { results.addAll(evt.getNewTypeResult()); } From 2eaebbf0f809efe29c5c702e6265a183986a992e Mon Sep 17 00:00:00 2001 From: Michael Uhl Date: Fri, 1 Feb 2019 22:56:30 +0100 Subject: [PATCH 17/17] FileWriter -> Writer. --- src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java | 6 +++++- .../dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java | 3 ++- .../java/de/dhbwstuttgart/typeinference/unify/RuleSet.java | 5 +++-- .../de/dhbwstuttgart/typeinference/unify/TypeUnify.java | 3 ++- .../dhbwstuttgart/typeinference/unify/TypeUnify2Task.java | 3 ++- .../de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java | 5 +++-- .../typeinference/unify/model/FiniteClosure.java | 5 +++-- 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 2c19d8b3..446cd514 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -41,12 +41,15 @@ import java.io.File; import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.Writer; import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; import java.util.stream.Stream; import org.antlr.v4.parse.ANTLRParser.throwsSpec_return; +import org.apache.commons.io.output.NullOutputStream; public class JavaTXCompiler { @@ -286,7 +289,8 @@ public class JavaTXCompiler { Set> results = new HashSet<>(); UnifyResultModel urm = new UnifyResultModel(); try { - FileWriter logFile = new FileWriter(new File(System.getProperty("user.dir")+"/src/test/java/logFiles/"+"log_"+sourceFiles.keySet().iterator().next().getName())); + Writer logFile = new OutputStreamWriter(new NullOutputStream()); + //new FileWriter(new File("log_"+sourceFiles.keySet().iterator().next().getName())); IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses,logFile); System.out.println(finiteClosure); diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index f3fbdd63..a764db6e 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.syntaxtree.factory; import java.io.FileWriter; +import java.io.Writer; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -30,7 +31,7 @@ public class UnifyTypeFactory { private static ArrayList PLACEHOLDERS = new ArrayList<>(); - public static FiniteClosure generateFC(List fromClasses, FileWriter logFile) throws ClassNotFoundException { + public static FiniteClosure generateFC(List fromClasses, Writer logFile) throws ClassNotFoundException { /* Die transitive Hülle muss funktionieren. Man darf schreiben List extends AL diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java index a8c0675d..e333bdfe 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/RuleSet.java @@ -28,6 +28,7 @@ import de.dhbwstuttgart.typeinference.unify.distributeVariance; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; /** * Implementation of the type inference rules. @@ -36,13 +37,13 @@ import java.io.IOException; */ public class RuleSet implements IRuleSet{ - FileWriter logFile; + Writer logFile; public RuleSet() { super(); } - RuleSet(FileWriter logFile) { + RuleSet(Writer logFile) { this.logFile = logFile; } diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java index d1fc2afe..6d58b959 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; +import java.io.Writer; import java.util.List; import java.util.Set; import java.util.concurrent.ForkJoinPool; @@ -21,7 +22,7 @@ public class TypeUnify { return res; } - public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, FileWriter logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { + public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, ConstraintSet cons, UnifyResultModel ret) { TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, cons); ForkJoinPool pool = new ForkJoinPool(); pool.invoke(unifyTask); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 6916f6dc..ac6f04bb 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -1,6 +1,7 @@ package de.dhbwstuttgart.typeinference.unify; import java.io.FileWriter; +import java.io.Writer; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -15,7 +16,7 @@ public class TypeUnify2Task extends TypeUnifyTask { Set> setToFlatten; - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons) { super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, cons); 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 eb81e200..43142773 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -44,6 +44,7 @@ import de.dhbwstuttgart.typeinference.unify.model.Pair; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import com.google.common.collect.Ordering; @@ -71,7 +72,7 @@ public class TypeUnifyTask extends RecursiveTask>> { Integer MaxNoOfThreads = 8; public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; - FileWriter logFile; + Writer logFile; /** * The implementation of setOps that will be used during the unification @@ -128,7 +129,7 @@ public class TypeUnifyTask extends RecursiveTask>> { } */ - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, FileWriter logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons2) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, Writer logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ConstraintSet cons2) { synchronized (this) { 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)); diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index c52f47a7..29a0e198 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -2,6 +2,7 @@ package de.dhbwstuttgart.typeinference.unify.model; import java.io.FileWriter; import java.io.IOException; +import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -32,7 +33,7 @@ import de.dhbwstuttgart.typeinference.unify.interfaces.IUnify; public class FiniteClosure //extends Ordering //entfernt PL 2018-12-11 implements IFiniteClosure { - FileWriter logFile; + Writer logFile; static Boolean log = false; public void setLogTrue() { log = true; @@ -66,7 +67,7 @@ implements IFiniteClosure { /** * Creates a new instance using the inheritance tree defined in the pairs. */ - public FiniteClosure(Set pairs, FileWriter logFile) { + public FiniteClosure(Set pairs, Writer logFile) { this.logFile = logFile; this.pairs = new HashSet<>(pairs); inheritanceGraph = new HashMap>();