diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index ffa8d54d..89e39b1d 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -176,7 +176,7 @@ public class JavaTXCompiler { .collect(Collectors.toCollection(HashSet::new)); varianceInheritance(xConsSet); Set> result = unify.unifySequential(xConsSet, finiteClosure, logFile, log); - //Set> result = unify.unify(xConsSet, finiteClosure); + //Set> result = unify.unify(xConsSet, finiteClosure, logFile, log); System.out.println("RESULT: " + result); logFile.write("RES: " + result.toString()+"\n"); logFile.flush(); diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index e38e1443..494540b2 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -49,6 +49,8 @@ public class TypeUnifyTask extends RecursiveTask>> { private static int i = 0; private boolean printtag = false; Boolean log = true; //gibt an ob ein Log-File nach System.getProperty("user.dir")+"/test/logFiles/log" geschrieben werden soll? + private static int noOfThread = 0; + private int thNo; public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; FileWriter logFile; @@ -96,6 +98,10 @@ public class TypeUnifyTask extends RecursiveTask>> { this.logFile = logFile; this.log = log; rules = new RuleSet(logFile); + noOfThread++; + thNo = noOfThread; + //System.out.println(noOfThread); + //System.out.println(eq); } @@ -451,9 +457,19 @@ public class TypeUnifyTask extends RecursiveTask>> { writeLog("nextSetasList: " + nextSetasList.toString()); while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) { Set a = null; + List> nextSetasListRest= new ArrayList<>(); if (variance == 1) { a = oup.max(nextSetasList.iterator()); - nextSetasList.remove(a); + //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()); @@ -491,7 +507,21 @@ 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: " + eq.toString()); - Set> res = unify2(elems, eq, fc, parallel); + Set> res = new HashSet<>(); + if(parallel) { + Set forks = new HashSet<>(); + for(Set nSaL : nextSetasListRest) { + TypeUnify2Task fork = new TypeUnify2Task(elems, eq, fc, true, logFile, log); + forks.add(fork); + fork.fork(); + } + for(TypeUnifyTask fork : forks) { + res.addAll(fork.join()); + } + } + else { + res = unify2(elems, eq, fc, parallel); + } if (!isUndefinedPairSetSet(res) && isUndefinedPairSetSet(result)) { //wenn korrektes Ergebnis gefunden alle Fehlerfaelle loeschen result = res; @@ -522,6 +552,9 @@ public class TypeUnifyTask extends RecursiveTask>> { System.out.print(""); Iterator> nextSetasListIt = new ArrayList>(nextSetasList).iterator(); if (variance == 1) { + /* nextSetasList = nextSetasListRest; */ + /* wird bereits vor den unify2-Aufruf durchgefuehrt und nextSetasListRest zugeordnet + */ System.out.println(""); while (nextSetasListIt.hasNext()) { Set a_next = nextSetasListIt.next(); @@ -530,6 +563,7 @@ public class TypeUnifyTask extends RecursiveTask>> { nextSetasList.remove(a_next); } } + } else { if (variance == -1) { System.out.println(""); @@ -1242,6 +1276,7 @@ public class TypeUnifyTask extends RecursiveTask>> { void writeLog(String str) { if (log) { try { + logFile.write("Thread no.:" + thNo + "\n"); logFile.write(str+"\n"); logFile.flush(); diff --git a/test/bytecode/MatrixTest.java b/test/bytecode/MatrixTest.java index 325cc1d8..cea9bccf 100644 --- a/test/bytecode/MatrixTest.java +++ b/test/bytecode/MatrixTest.java @@ -36,55 +36,57 @@ public class MatrixTest { loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)}); classToTest = loader.loadClass("Matrix"); - Vector> vv = new Vector>(); - Vector v1 = new Vector (); - v1.addElement(2); - v1.addElement(2); - Vector v2 = new Vector (); - v2.addElement(3); - v2.addElement(3); - //Matrix m1 = new Matrix(); - //m1.addElement(v1); - //m1.addElement(v2); - vv.addElement(v1); - vv.addElement(v2); - instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv); - - Vector> vv1 = new Vector>(); - Vector v3 = new Vector (); - v3.addElement(2); - v3.addElement(2); - Vector v4 = new Vector (); - v4.addElement(3); - v4.addElement(3); - //Matrix m2 = new Matrix(); - //m2.addElement(v3); - //m2.addElement(v4); - vv1.addElement(v3); - vv1.addElement(v4); - instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1); - - - - //Matrix m3 = m1.mul(vv1); - Method mul = classToTest.getDeclaredMethod("mul", Vector.class); - Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2); - System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString()); + instanceOfClass_m1 = classToTest.getDeclaredConstructor().newInstance(); //Matrix m1 = new Matrix(); + //Vector> vv = new Vector>(); + Vector v1 = new Vector (); + v1.addElement(2); + v1.addElement(2); + Vector v2 = new Vector (); + v2.addElement(3); + v2.addElement(3); + //Method[] ms = classToTest.getSuperclass().getDeclaredMethods(); + Method addElement = classToTest.getSuperclass().getDeclaredMethod("addElement", Object.class); + addElement.invoke(instanceOfClass_m1, v1); //m1.addElement(v1); + addElement.invoke(instanceOfClass_m1, v2); //m1.addElement(v2); + //vv.addElement(v1); + //vv.addElement(v2); + //instanceOfClass_m1 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv); //Matrix m1 = new Matrix(vv); - Vector> res = new Vector>(); - Vector v5 = new Vector (); - v5.addElement(10); - v5.addElement(10); - Vector v6 = new Vector (); - v6.addElement(15); - v6.addElement(15); - //Matrix m2 = new Matrix(); - //m2.addElement(v3); - //m2.addElement(v4); - res.addElement(v5); - res.addElement(v6); - instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res); - assertEquals(result, instanceOfClass_m3); + Vector> vv1 = new Vector>(); + Vector v3 = new Vector (); + v3.addElement(2); + v3.addElement(2); + Vector v4 = new Vector (); + v4.addElement(3); + v4.addElement(3); + //Matrix m2 = new Matrix(); + //m2.addElement(v3); + //m2.addElement(v4); + vv1.addElement(v3); + vv1.addElement(v4); + instanceOfClass_m2 = classToTest.getDeclaredConstructor(Vector.class).newInstance(vv1);//Matrix m2 = new Matrix(vv1); + + + + //Matrix m3 = m1.mul(vv1); + Method mul = classToTest.getDeclaredMethod("mul", Vector.class); + Object result = mul.invoke(instanceOfClass_m1, instanceOfClass_m2); + System.out.println(instanceOfClass_m1.toString() + " * " + instanceOfClass_m1.toString() + " = " + result.toString()); + + Vector> res = new Vector>(); + Vector v5 = new Vector (); + v5.addElement(10); + v5.addElement(10); + Vector v6 = new Vector (); + v6.addElement(15); + v6.addElement(15); + //Matrix m2 = new Matrix(); + //m2.addElement(v3); + //m2.addElement(v4); + res.addElement(v5); + res.addElement(v6); + instanceOfClass_m3 = classToTest.getDeclaredConstructor(Vector.class).newInstance(res); + assertEquals(result, instanceOfClass_m3); }