diff --git a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java index 97eee0d13..88cc37c4c 100644 --- a/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/main/java/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -369,7 +369,7 @@ public class JavaTXCompiler { * } */ - public UnifyResultModel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile) + public UnifyResultModelParallel typeInferenceAsync(UnifyResultListener resultListener, Writer logFile) throws ClassNotFoundException, IOException { List allClasses = new ArrayList<>();// environment.getAllAvailableClasses(); // Alle Importierten Klassen in allen geparsten Sourcefiles kommen ins FC @@ -382,7 +382,7 @@ public class JavaTXCompiler { final ConstraintSet cons = getConstraints(); Set> results = new HashSet<>(); - UnifyResultModel urm = null; + UnifyResultModelParallel urm = null; // urm.addUnifyResultListener(resultListener); try { logFile = logFile == null @@ -390,7 +390,7 @@ public class JavaTXCompiler { : logFile; IFiniteClosure finiteClosure = UnifyTypeFactory.generateFC(allClasses, logFile, classLoader); System.out.println(finiteClosure); - urm = new UnifyResultModel(cons, finiteClosure); + urm = new UnifyResultModelParallel(cons, finiteClosure); urm.addUnifyResultListener(resultListener); ConstraintSet unifyCons = UnifyTypeFactory.convert(cons); @@ -720,7 +720,7 @@ public class JavaTXCompiler { }).collect(Collectors.toCollection(ArrayList::new))*/; if (resultmodel) { /* UnifyResultModel Anfang */ - UnifyResultModel urm = new UnifyResultModel(cons, finiteClosure); + UnifyResultModelParallel urm = new UnifyResultModelParallel(cons, finiteClosure); UnifyResultListenerImpl li = new UnifyResultListenerImpl(); urm.addUnifyResultListener(li); unify.unifyParallel(unifyCons.getUndConstraints(), oderConstraints, finiteClosure, logFile, log, urm, @@ -738,7 +738,7 @@ public class JavaTXCompiler { // oderConstraints, finiteClosure, logFile, log, new UnifyResultModel(cons, // finiteClosure)); Set> result = unify.unifyOderConstraints(unifyCons.getUndConstraints(), oderConstraints, - finiteClosure, logFile, log, new UnifyResultModel(cons, finiteClosure), usedTasks); + finiteClosure, logFile, log, new UnifyResultModelParallel(cons, finiteClosure), usedTasks); 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 236049b3b..c2b52ca45 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify.java @@ -23,10 +23,11 @@ public class TypeUnify { * @param cons * @return */ - public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModelParallel taskModel) { + public Set> unify(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModelParallel resultModel, UnifyTaskModelParallel taskModel) { ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); taskModel.setPool(pool); - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, pool); + resultModel.setPool(pool); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, resultModel, pool); pool.invoke(unifyTask); Set> res = unifyTask.join(); try { @@ -50,12 +51,13 @@ public class TypeUnify { * @param ret * @return */ - public UnifyResultModel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModelParallel taskModel) { + public UnifyResultModelParallel unifyAsync(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModelParallel resultModel, UnifyTaskModelParallel taskModel) { ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); taskModel.setPool(pool); - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, pool); + resultModel.setPool(pool); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, resultModel, pool); pool.invoke(unifyTask); - return ret; + return resultModel; } /** @@ -69,11 +71,12 @@ public class TypeUnify { * @param ret * @return */ - public UnifyResultModel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModelParallel taskModel) { + public UnifyResultModelParallel unifyParallel(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModelParallel resultModel, UnifyTaskModelParallel taskModel) { ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); taskModel.setPool(pool); + resultModel.setPool(pool); TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); - new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, pool, statistics); + new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, resultModel, pool, statistics); pool.invoke(unifyTask); Set> res = unifyTask.join(); @@ -86,7 +89,7 @@ public class TypeUnify { catch (IOException e) { System.err.println("no log-File"); } - return ret; + return resultModel; } /* @@ -107,8 +110,9 @@ public class TypeUnify { * @param cons * @return */ - public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModelParallel taskModel) { - TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, new WriterActiveObject(logFile, ForkJoinPool.commonPool()), log, 0, ret, ForkJoinPool.commonPool()); + public Set> unifyOderConstraints(Set undConstrains, List>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModelParallel resultModel, UnifyTaskModelParallel taskModel) { + resultModel.setPool(ForkJoinPool.commonPool()); + TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, new WriterActiveObject(logFile, ForkJoinPool.commonPool()), log, 0, resultModel, ForkJoinPool.commonPool()); unifyTask.statisticsFile = statistics; Set> res = unifyTask.compute(); try { diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java index 934405108..2546f8e1b 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnify2Task.java @@ -24,13 +24,13 @@ public class TypeUnify2Task extends TypeUnifyTask { TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, - IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, + IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModelParallel urm, Set methodSignatureConstraintUebergabe, ForkJoinPool pool, Writer statistics) { this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, methodSignatureConstraintUebergabe, pool ); } - public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, Set methodSignatureConstraintUebergabe, ForkJoinPool pool) { + public TypeUnify2Task(Set> setToFlatten, Set eq, List>> oderConstraints, Set nextSetElement, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModelParallel urm, Set methodSignatureConstraintUebergabe, ForkJoinPool pool) { super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, pool); this.setToFlatten = setToFlatten; this.nextSetElement = nextSetElement; diff --git a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 656b79582..8d42dde0e 100644 --- a/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -71,7 +71,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /** * Fuer die Threads */ - UnifyResultModel urm; + protected UnifyResultModelParallel urm; protected static int noOfThread = 0; private static int totalnoOfThread = 0; int thNo; @@ -146,11 +146,11 @@ public class TypeUnifyTask extends RecursiveTask>> { */ //statistics - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ForkJoinPool pool, Writer statisticsFile) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModelParallel urm, ForkJoinPool pool, Writer statisticsFile) { this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, pool); this.statisticsFile = statisticsFile; } - public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, ForkJoinPool pool) { + public TypeUnifyTask(Set eq, List>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModelParallel urm, ForkJoinPool pool) { this.eq = eq; //this.oderConstraints = oderConstraints.stream().map(x -> x.stream().map(y -> new HashSet<>(y)).collect(Collectors.toSet(HashSet::new))).collect(Collectors.toList(ArrayList::new)); this.oderConstraintsField = oderConstraints; /*.stream().map(x -> {