Compare commits

...

9 Commits

Author SHA1 Message Date
NoName11234
8f6eb8ff0a added unifyTest 2024-02-11 17:53:09 +01:00
NoName11234
bfefe90650 removed not functional unifyTest 2024-02-11 15:09:53 +01:00
NoName11234
c292ff2d9e added non-threaded close() method for logging 2024-01-25 20:08:32 +01:00
NoName11234
c14dd6e97c added support for non-threaded logging to WriterActiveObject 2024-01-25 19:55:56 +01:00
NoName11234
8f8ee9a385 fixed bug where constraints in test had undefinded placeholder 2024-01-24 22:20:13 +01:00
NoName11234
3863968a6e added smallest unify test possible 2024-01-23 18:59:39 +01:00
NoName11234
03c432455d fixed bug where statisticsFile was not initialized when using one of the constructors of TypeUnifyTask 2024-01-23 18:58:59 +01:00
NoName11234
441e50a70d removed useless synchronized-blocks and concenated multiple writes to logfile 2024-01-23 17:57:07 +01:00
NoName11234
0807885465 WriterActiveObject now uses same forkjointhreadpool as tasks 2024-01-21 22:16:35 +01:00
6 changed files with 246 additions and 206 deletions

View File

@@ -9,6 +9,7 @@ import java.util.Optional;
import java.util.Queue; import java.util.Queue;
import java.util.Set; import java.util.Set;
import java.util.Stack; import java.util.Stack;
import java.util.concurrent.ForkJoinPool;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -48,7 +49,7 @@ public class RuleSet implements IRuleSet{
public RuleSet() { public RuleSet() {
super(); super();
logFile = new WriterActiveObject(new OutputStreamWriter(new NullOutputStream())); logFile = new WriterActiveObject(new OutputStreamWriter(new NullOutputStream()), ForkJoinPool.commonPool());
} }
RuleSet(WriterActiveObject logFile) { RuleSet(WriterActiveObject logFile) {

View File

@@ -24,8 +24,8 @@ public class TypeUnify {
* @return * @return
*/ */
public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { public Set<Set<UnifyPair>> unify(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile), log, 0, ret, usedTasks); ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
ForkJoinPool pool = new ForkJoinPool(); TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, pool);
pool.invoke(unifyTask); pool.invoke(unifyTask);
Set<Set<UnifyPair>> res = unifyTask.join(); Set<Set<UnifyPair>> res = unifyTask.join();
try { try {
@@ -50,8 +50,8 @@ public class TypeUnify {
* @return * @return
*/ */
public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { public UnifyResultModel unifyAsync(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile), log, 0, ret, usedTasks); ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
ForkJoinPool pool = new ForkJoinPool(); TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, pool);
pool.invoke(unifyTask); pool.invoke(unifyTask);
return ret; return ret;
} }
@@ -68,9 +68,10 @@ public class TypeUnify {
* @return * @return
*/ */
public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { public UnifyResultModel unifyParallel(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
ForkJoinPool pool = new ForkJoinPool(Runtime.getRuntime().availableProcessors(), ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true);
TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks); TypeUnifyTask unifyTask = //new TypeUnifyTask(undConstrains, oderConstraints, fc, true, logFile, log, 0, ret, usedTasks);
new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile), log, 0, ret, usedTasks, statistics); new TypeUnifyTask(undConstrains, oderConstraints, fc, true, new WriterActiveObject(logFile, pool), log, 0, ret, usedTasks, pool, statistics);
ForkJoinPool pool = new ForkJoinPool();
pool.invoke(unifyTask); pool.invoke(unifyTask);
Set<Set<UnifyPair>> res = unifyTask.join(); Set<Set<UnifyPair>> res = unifyTask.join();
try { try {
@@ -104,7 +105,7 @@ public class TypeUnify {
* @return * @return
*/ */
public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) { public Set<Set<UnifyPair>> unifyOderConstraints(Set<UnifyPair> undConstrains, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, Writer logFile, Boolean log, UnifyResultModel ret, UnifyTaskModel usedTasks) {
TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, new WriterActiveObject(logFile), log, 0, ret, usedTasks); TypeUnifyTask unifyTask = new TypeUnifyTask(undConstrains, oderConstraints, fc, false, new WriterActiveObject(logFile, ForkJoinPool.commonPool()), log, 0, ret, usedTasks, ForkJoinPool.commonPool());
unifyTask.statisticsFile = statistics; unifyTask.statisticsFile = statistics;
Set<Set<UnifyPair>> res = unifyTask.compute(); Set<Set<UnifyPair>> res = unifyTask.compute();
try { try {

View File

@@ -7,6 +7,7 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ForkJoinPool;
import de.dhbwstuttgart.typeinference.constraints.Constraint; import de.dhbwstuttgart.typeinference.constraints.Constraint;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet; import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
@@ -24,13 +25,13 @@ public class TypeUnify2Task extends TypeUnifyTask {
List<Set<Constraint<UnifyPair>>> oderConstraints, List<Set<Constraint<UnifyPair>>> oderConstraints,
Set<UnifyPair> nextSetElement, Set<UnifyPair> nextSetElement,
IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks,
Set<UnifyPair> methodSignatureConstraintUebergabe, Writer statistics) { Set<UnifyPair> methodSignatureConstraintUebergabe, ForkJoinPool pool, Writer statistics) {
this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe ); this(setToFlatten, eq, oderConstraints, nextSetElement, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraintUebergabe, pool );
} }
public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set<UnifyPair> methodSignatureConstraintUebergabe) { public TypeUnify2Task(Set<Set<UnifyPair>> setToFlatten, Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, Set<UnifyPair> nextSetElement, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Set<UnifyPair> methodSignatureConstraintUebergabe, ForkJoinPool pool) {
super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); super(eq, oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, pool);
this.setToFlatten = setToFlatten; this.setToFlatten = setToFlatten;
this.nextSetElement = nextSetElement; this.nextSetElement = nextSetElement;
this.methodSignatureConstraintUebergabe = methodSignatureConstraintUebergabe; this.methodSignatureConstraintUebergabe = methodSignatureConstraintUebergabe;
@@ -64,6 +65,10 @@ public class TypeUnify2Task extends TypeUnifyTask {
} }
public void closeLogFile() { public void closeLogFile() {
if(parallel){
logFile.close(); logFile.close();
}else{
logFile.closeNonThreaded();
}
} }
} }

View File

@@ -13,6 +13,7 @@ import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.RecursiveTask; import java.util.concurrent.RecursiveTask;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.BinaryOperator; import java.util.function.BinaryOperator;
@@ -42,6 +43,7 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType;
import de.dhbwstuttgart.typeinference.unify.model.WildcardType; import de.dhbwstuttgart.typeinference.unify.model.WildcardType;
import de.dhbwstuttgart.util.Pair; import de.dhbwstuttgart.util.Pair;
import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair; import de.dhbwstuttgart.typeinference.unify.model.OrderingUnifyPair;
import org.apache.commons.io.output.NullWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
@@ -78,6 +80,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/"; public static final String rootDirectory = System.getProperty("user.dir")+"/test/logFiles/";
protected WriterActiveObject logFile; protected WriterActiveObject logFile;
protected ForkJoinPool pool;
/** /**
* The implementation of setOps that will be used during the unification * The implementation of setOps that will be used during the unification
*/ */
@@ -126,7 +129,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
volatile UnifyTaskModel usedTasks; volatile UnifyTaskModel usedTasks;
static Writer statisticsFile; static Writer statisticsFile = new NullWriter();
public TypeUnifyTask() { public TypeUnifyTask() {
rules = new RuleSet(); rules = new RuleSet();
@@ -147,11 +150,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/ */
//statistics //statistics
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, Writer statisticsFile) { public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, ForkJoinPool pool, Writer statisticsFile) {
this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks); this(eq,oderConstraints, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, pool);
this.statisticsFile = statisticsFile; this.statisticsFile = statisticsFile;
} }
public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks) { public TypeUnifyTask(Set<UnifyPair> eq, List<Set<Constraint<UnifyPair>>> oderConstraints, IFiniteClosure fc, boolean parallel, WriterActiveObject logFile, Boolean log, int rekTiefe, UnifyResultModel urm, UnifyTaskModel usedTasks, ForkJoinPool pool) {
this.eq = eq; 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.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 -> {
@@ -170,6 +173,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
this.parallel = parallel; this.parallel = parallel;
this.logFile = logFile; this.logFile = logFile;
this.log = log; this.log = log;
this.pool = pool;
noOfThread++; noOfThread++;
totalnoOfThread++; totalnoOfThread++;
@@ -178,11 +182,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("thNo2 " + thNo); writeLog("thNo2 " + thNo);
try { try {
if(log){ if(log){
this.logFile = new WriterActiveObject(new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "Thread_"+thNo))); this.logFile = new WriterActiveObject(new FileWriter(new File(System.getProperty("user.dir") + "/logFiles/" + "Thread_"+thNo)), pool);
}else{ }else{
this.logFile = new WriterActiveObject(new OutputStreamWriter(new NullOutputStream())); this.logFile = new WriterActiveObject(new OutputStreamWriter(new NullOutputStream()), pool);
} }
logFile.write("");
} }
catch (IOException e) { catch (IOException e) {
System.err.println("log-File nicht vorhanden"); System.err.println("log-File nicht vorhanden");
@@ -264,7 +267,11 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, new HashSet<>()); Set<Set<UnifyPair>> res = unify(neweq, remainingOderconstraints, fc, parallel, rekTiefeField, new HashSet<>());
noOfThread--; noOfThread--;
if(parallel){
logFile.close(); logFile.close();
}else{
logFile.closeNonThreaded();
}
if (isUndefinedPairSetSet(res)) { if (isUndefinedPairSetSet(res)) {
//fuer debug-Zwecke //fuer debug-Zwecke
@@ -375,8 +382,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
eq0.forEach(x -> x.disableCondWildcards()); eq0.forEach(x -> x.disableCondWildcards());
writeLog(nOfUnify.toString() + " Unifikation nach applyTypeUnificationRules: " + eq.toString()); writeLog(nOfUnify.toString() + " Unifikation nach applyTypeUnificationRules: " + eq.toString() + "\n"
writeLog(nOfUnify.toString() + " Oderconstraints nach applyTypeUnificationRules: " + oderConstraints.toString()); + nOfUnify.toString() + " Oderconstraints nach applyTypeUnificationRules: " + oderConstraints.toString());
/* /*
* Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs * Step 2 and 3: Create a subset eq1s of pairs where both sides are TPH and eq2s of the other pairs
@@ -435,8 +442,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
if(!undefinedPairs.isEmpty()) { if(!undefinedPairs.isEmpty()) {
noUndefPair++; noUndefPair++;
for (UnifyPair up : undefinedPairs) { for (UnifyPair up : undefinedPairs) {
writeLog(noUndefPair.toString() + " UndefinedPairs; " + up); writeLog(noUndefPair.toString() + " UndefinedPairs; " + up + "\n"
writeLog("BasePair; " + up.getBasePair()); + "BasePair; " + up.getBasePair());
} }
Set<Set<UnifyPair>> error = new HashSet<>(); Set<Set<UnifyPair>> error = new HashSet<>();
undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new));
@@ -803,8 +810,8 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
*/ */
List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>(); List<Set<UnifyPair>> nextSetasListOderConstraints = new ArrayList<>();
writeLog("nextSet: " + nextSet.toString()); writeLog("nextSet: " + nextSet.toString() + "\n"
writeLog("nextSetasList: " + nextSetasList.toString()); + "nextSetasList: " + nextSetasList.toString());
/* staistics Nextvar an Hand Varianzbestimmung auskommentieren Anfang /* staistics Nextvar an Hand Varianzbestimmung auskommentieren Anfang
if (variance == 1) { if (variance == 1) {
@@ -922,7 +929,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
newElemsOrig.add(a); newElemsOrig.add(a);
/* FORK ANFANG */ /* FORK ANFANG */
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint); TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint, this.pool);
//forks.add(forkOrig); //forks.add(forkOrig);
synchronized(usedTasks) { synchronized(usedTasks) {
if (this.myIsCancelled()) { if (this.myIsCancelled()) {
@@ -932,15 +939,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
/* FORK ENDE */ /* FORK ENDE */
synchronized (this) { writeLog("a in " + variance + " "+ a + "\n" +
writeLog("a in " + variance + " "+ a); "nextSetasListRest: " + nextSetasListRest.toString());
writeLog("nextSetasListRest: " + nextSetasListRest.toString());
}
while (!nextSetasList.isEmpty()) { while (!nextSetasList.isEmpty()) {
Set<UnifyPair> nSaL = nextSetasList.remove(0); Set<UnifyPair> nSaL = nextSetasList.remove(0);
synchronized (this) { //nextSetasList.remove(nSaL); //nextSetasList.remove(nSaL);
writeLog("1 RM" + nSaL.toString()); writeLog("1 RM" + nSaL.toString());
}
if (!oderConstraint) { if (!oderConstraint) {
@@ -960,7 +966,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> newElems = new HashSet<>(elems); Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints); List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
newElems.add(nSaL); newElems.add(nSaL);
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint), this.pool);
forks.add(fork); forks.add(fork);
synchronized(usedTasks) { synchronized(usedTasks) {
if (this.myIsCancelled()) { if (this.myIsCancelled()) {
@@ -972,7 +978,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
/* FORK ANFANG */ /* FORK ANFANG */
synchronized (this) {
writeLog("wait "+ forkOrig.thNo); writeLog("wait "+ forkOrig.thNo);
noOfThread--; noOfThread--;
res = forkOrig.join(); res = forkOrig.join();
@@ -988,12 +994,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
//noOfThread--; an das Ende von compute verschoben //noOfThread--; an das Ende von compute verschoben
//add_res.add(fork_res); //add_res.add(fork_res);
};
/* FORK ENDE */ /* FORK ENDE */
forks.forEach(x -> writeLog("wait: " + x.thNo)); forks.forEach(x -> writeLog("wait: " + x.thNo));
for(TypeUnify2Task fork : forks) { for(TypeUnify2Task fork : forks) {
synchronized (this) {
noOfThread--; noOfThread--;
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
synchronized (usedTasks) { synchronized (usedTasks) {
@@ -1002,17 +1006,16 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
//noOfThread++; //noOfThread++;
writeLog("Join " + new Integer(fork.thNo).toString());
//noOfThread--; an das Ende von compute verschoben //noOfThread--; an das Ende von compute verschoben
writeLog("fork_res: " + fork_res.toString()); writeLog("Join " + new Integer(fork.thNo).toString() + "\n" +
writeLog(new Boolean((isUndefinedPairSetSet(fork_res))).toString()); "fork_res: " + fork_res.toString() + "\n" +
new Boolean((isUndefinedPairSetSet(fork_res))).toString());
add_res.add(fork_res); add_res.add(fork_res);
if (!isUndefinedPairSetSet(fork_res)) { if (!isUndefinedPairSetSet(fork_res)) {
aParDef.add(fork.getNextSetElement()); aParDef.add(fork.getNextSetElement());
} }
fork.writeLog("final 1"); fork.writeLog("final 1");
fork.closeLogFile(); fork.closeLogFile();
};
} }
//noOfThread++; //noOfThread++;
} else { } else {
@@ -1024,7 +1027,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
newElemsOrig.add(a); newElemsOrig.add(a);
/* FORK ANFANG */ /* FORK ANFANG */
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint), this.pool);
//forks.add(forkOrig); //forks.add(forkOrig);
synchronized(usedTasks) { synchronized(usedTasks) {
if (this.myIsCancelled()) { if (this.myIsCancelled()) {
@@ -1034,15 +1037,14 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
/* FORK ENDE */ /* FORK ENDE */
synchronized (this) {
writeLog("a in " + variance + " "+ a); writeLog("a in " + variance + " "+ a + "\n" +
writeLog("nextSetasListRest: " + nextSetasListRest.toString()); "nextSetasListRest: " + nextSetasListRest.toString());
}
while (!nextSetasList.isEmpty()) { while (!nextSetasList.isEmpty()) {
Set<UnifyPair> nSaL = nextSetasList.remove(0); Set<UnifyPair> nSaL = nextSetasList.remove(0);
synchronized (this) { //nextSetasList.remove(nSaL); //nextSetasList.remove(nSaL);
writeLog("-1 RM" + nSaL.toString()); writeLog("-1 RM" + nSaL.toString());
}
if (!oderConstraint) { if (!oderConstraint) {
/* statistics sameEq wird nicht betrachtet ANGFANG /* statistics sameEq wird nicht betrachtet ANGFANG
@@ -1061,7 +1063,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> newElems = new HashSet<>(elems); Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints); List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
newElems.add(nSaL); newElems.add(nSaL);
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint), this.pool);
forks.add(fork); forks.add(fork);
synchronized(usedTasks) { synchronized(usedTasks) {
if (this.myIsCancelled()) { if (this.myIsCancelled()) {
@@ -1073,7 +1075,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
/* FORK ANFANG */ /* FORK ANFANG */
synchronized (this) {
writeLog("wait "+ forkOrig.thNo); writeLog("wait "+ forkOrig.thNo);
noOfThread--; noOfThread--;
res = forkOrig.join(); res = forkOrig.join();
@@ -1089,12 +1090,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
//noOfThread--; an das Ende von compute verschoben //noOfThread--; an das Ende von compute verschoben
//add_res.add(fork_res); //add_res.add(fork_res);
};
/* FORK ENDE */ /* FORK ENDE */
forks.forEach(x -> writeLog("wait: " + x.thNo)); forks.forEach(x -> writeLog("wait: " + x.thNo));
for(TypeUnify2Task fork : forks) { for(TypeUnify2Task fork : forks) {
synchronized (this) {
noOfThread--; noOfThread--;
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
synchronized (usedTasks) { synchronized (usedTasks) {
@@ -1114,7 +1113,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
fork.writeLog("final -1"); fork.writeLog("final -1");
fork.closeLogFile(); fork.closeLogFile();
}; };
}
//noOfThread++; //noOfThread++;
} else { } else {
if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) { if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) {
@@ -1126,7 +1125,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
newElemsOrig.add(a); newElemsOrig.add(a);
/* FORK ANFANG */ /* FORK ANFANG */
TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint)); TypeUnify2Task forkOrig = new TypeUnify2Task(newElemsOrig, newEqOrig, newOderConstraintsOrig, a, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, new HashSet<>(methodSignatureConstraint), this.pool);
//forks.add(forkOrig); //forks.add(forkOrig);
synchronized(usedTasks) { synchronized(usedTasks) {
if (this.myIsCancelled()) { if (this.myIsCancelled()) {
@@ -1136,10 +1135,9 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
/* FORK ENDE */ /* FORK ENDE */
synchronized (this) { writeLog("a in " + variance + " "+ a + "\n" +
writeLog("a in " + variance + " "+ a); "nextSetasListRest: " + nextSetasListRest.toString());
writeLog("nextSetasListRest: " + nextSetasListRest.toString());
}
while (!nextSetasList.isEmpty()) { while (!nextSetasList.isEmpty()) {
Set<UnifyPair> nSaL = nextSetasList.remove(0); Set<UnifyPair> nSaL = nextSetasList.remove(0);
//nextSetasList.remove(nSaL); //PL einkommentiert 20-02-03 //nextSetasList.remove(nSaL); //PL einkommentiert 20-02-03
@@ -1147,7 +1145,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
Set<Set<UnifyPair>> newElems = new HashSet<>(elems); Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints); List<Set<Constraint<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
newElems.add(nSaL); newElems.add(nSaL);
TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint); TypeUnify2Task fork = new TypeUnify2Task(newElems, newEq, newOderConstraints, nSaL, fc, parallel, logFile, log, rekTiefe, urm, usedTasks, methodSignatureConstraint, this.pool);
forks.add(fork); forks.add(fork);
synchronized(usedTasks) { synchronized(usedTasks) {
if (this.myIsCancelled()) { if (this.myIsCancelled()) {
@@ -1159,7 +1157,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe); //res = unify2(newElemsOrig, newEqOrig, newOderConstraintsOrig, fc, parallel, rekTiefe);
/* FORK ANFANG */ /* FORK ANFANG */
synchronized (this) {
writeLog("wait "+ forkOrig.thNo); writeLog("wait "+ forkOrig.thNo);
noOfThread--; noOfThread--;
res = forkOrig.join(); res = forkOrig.join();
@@ -1175,11 +1173,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString()); writeLog("JoinOrig " + new Integer(forkOrig.thNo).toString());
//noOfThread--; an das Ende von compute verschoben //noOfThread--; an das Ende von compute verschoben
//add_res.add(fork_res); //vermutlich falsch //add_res.add(fork_res); //vermutlich falsch
};
/* FORK ENDE */ /* FORK ENDE */
forks.forEach(x -> writeLog("wait: " + x.thNo)); forks.forEach(x -> writeLog("wait: " + x.thNo));
for(TypeUnify2Task fork : forks) { for(TypeUnify2Task fork : forks) {
synchronized (this) {
noOfThread--; noOfThread--;
Set<Set<UnifyPair>> fork_res = fork.join(); Set<Set<UnifyPair>> fork_res = fork.join();
synchronized (usedTasks) { synchronized (usedTasks) {
@@ -1193,7 +1190,6 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
add_res.add(fork_res); add_res.add(fork_res);
fork.writeLog("final 2"); fork.writeLog("final 2");
fork.closeLogFile(); fork.closeLogFile();
};
} }
//noOfThread++; //noOfThread++;
} else {//parallel = false oder MaxNoOfThreads ist erreicht, sequentiell weiterarbeiten } else {//parallel = false oder MaxNoOfThreads ist erreicht, sequentiell weiterarbeiten
@@ -1522,15 +1518,15 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
//NOCH NICHT korrekt PL 2018-10-12 //NOCH NICHT korrekt PL 2018-10-12
//nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y)) //nextSetasList = nextSetasList.stream().filter(y -> couldBecorrect(reducedUndefResSubstGroundedBasePair, y))
// .collect(Collectors.toCollection(ArrayList::new)); // .collect(Collectors.toCollection(ArrayList::new));
writeLog("res (undef): " + res.toString()); writeLog("res (undef): " + res.toString() + "\n" +
writeLog("abhSubst: " + abhSubst.toString()); "abhSubst: " + abhSubst.toString() + "\n" +
writeLog("a2: " + rekTiefe + " " + a.toString()); "a2: " + rekTiefe + " " + a.toString() + "\n" +
writeLog("Durchschnitt: " + durchschnitt.toString()); "Durchschnitt: " + durchschnitt.toString() + "\n" +
writeLog("nextSet: " + nextSet.toString()); "nextSet: " + nextSet.toString() + "\n" +
writeLog("nextSetasList: " + nextSetasList.toString()); "nextSetasList: " + nextSetasList.toString() + "\n" +
writeLog("Number first erased Elements (undef): " + (len - nofstred)); "Number first erased Elements (undef): " + (len - nofstred) + "\n" +
writeLog("Number second erased Elements (undef): " + (nofstred- nextSetasList.size())); "Number second erased Elements (undef): " + (nofstred- nextSetasList.size()) + "\n" +
writeLog("Number erased Elements (undef): " + (len - nextSetasList.size())); "Number erased Elements (undef): " + (len - nextSetasList.size()));
noAllErasedElements = noAllErasedElements + (len - nextSetasList.size()); noAllErasedElements = noAllErasedElements + (len - nextSetasList.size());
writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString()); writeLog("Number of all erased Elements (undef): " + noAllErasedElements.toString());
noBacktracking++; noBacktracking++;
@@ -1990,10 +1986,10 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
} }
} }
writeLog("eq2s: " + eq2s.toString()); writeLog("eq2s: " + eq2s.toString() + "\n" +
writeLog("eq2sAsListFst: " + eq2sAsListFst.toString()); "eq2sAsListFst: " + eq2sAsListFst.toString() + "\n" +
writeLog("eq2sAsListSnd: " + eq2sAsListSnd.toString()); "eq2sAsListSnd: " + eq2sAsListSnd.toString() + "\n" +
writeLog("eq2sAsListBack: " + eq2sAsListBack.toString()); "eq2sAsListBack: " + eq2sAsListBack.toString());
eq2sAsList.addAll(eq2sAsListFst); eq2sAsList.addAll(eq2sAsListFst);
eq2sAsList.addAll(eq2sAsListSnd); eq2sAsList.addAll(eq2sAsListSnd);
@@ -2599,11 +2595,19 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
void writeLog(String str) { void writeLog(String str) {
if (log && finalresult) { if (log && finalresult) {
if(parallel){
logFile.write("Thread no.:" + thNo + "\n" logFile.write("Thread no.:" + thNo + "\n"
+ "noOfThread:" + noOfThread + "\n" + "noOfThread:" + noOfThread + "\n"
+ "parallel:" + parallel + "\n" + "parallel:" + parallel + "\n"
+ str+"\n\n" + str+"\n\n"
); );
}else{
logFile.writeNonThreaded("Thread no.:" + thNo + "\n"
+ "noOfThread:" + noOfThread + "\n"
+ "parallel:" + parallel + "\n"
+ str+"\n\n"
);
}
} }
} }

View File

@@ -6,10 +6,11 @@ import java.util.concurrent.ForkJoinPool;
public class WriterActiveObject { public class WriterActiveObject {
private Writer writer; private Writer writer;
private ForkJoinPool pool = new ForkJoinPool(1, ForkJoinPool.defaultForkJoinWorkerThreadFactory, null, true); private ForkJoinPool pool;
public WriterActiveObject(Writer writer){ public WriterActiveObject(Writer writer, ForkJoinPool pool){
this.writer = writer; this.writer = writer;
this.pool = pool;
} }
public void close(){ public void close(){
@@ -28,8 +29,25 @@ public class WriterActiveObject {
writer.write(message); writer.write(message);
writer.flush(); writer.flush();
} catch (IOException e) { } catch (IOException e) {
System.out.println(e.getMessage()); throw new RuntimeException(e);
} }
}); });
} }
public void writeNonThreaded(String message){
try {
writer.write(message);
writer.flush();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public void closeNonThreaded(){
try {
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
} }

View File

@@ -39,48 +39,58 @@ public class UnifyTest {
public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/"; public static final String rootDirectory = System.getProperty("user.dir")+"/resources/javFiles/";
private UnifyPair genPairListOfInteger(String name){
UnifyType type1 = new PlaceholderType(name);
UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("Integer")));
UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT);
return pair1;
}
private UnifyPair genPairListOfString(String name){
PlaceholderType type1 = new PlaceholderType(name);
UnifyType type2 = new ReferenceType("List", new TypeParams(new ReferenceType("String")));
UnifyPair pair1 = new UnifyPair(type2, type1, PairOperator.SMALLERDOT);
return pair1;
}
@Test @Test
public void unifyTest(){ public void unifyTest(){
UnifyType type1 = new PlaceholderType("a"); UnifyType type1;
UnifyType type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("b"))); UnifyType type2;
UnifyPair pair1 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
type1 = new ReferenceType("List", new TypeParams(new PlaceholderType("c")));
type2 = new PlaceholderType("a");
UnifyPair pair2 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
type1 = new ReferenceType("String");
type2 = new PlaceholderType("b");
UnifyPair pair3 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
type1 = new ReferenceType("Integer");
type2 = new PlaceholderType("c");
UnifyPair pair4 = new UnifyPair(type1, type2, PairOperator.SMALLERDOT);
Set<UnifyPair> undConstraints = new HashSet<>(); Set<UnifyPair> undConstraints = new HashSet<>();
undConstraints.add(pair1); undConstraints.add(genPairListOfInteger("a"));
undConstraints.add(pair2); undConstraints.add(genPairListOfString("a"));
undConstraints.add(pair3);
undConstraints.add(pair4); undConstraints.add(genPairListOfInteger("b"));
undConstraints.add(genPairListOfString("b"));
undConstraints.add(genPairListOfInteger("c"));
undConstraints.add(genPairListOfString("c"));
undConstraints.add(genPairListOfInteger("d"));
undConstraints.add(genPairListOfString("d"));
undConstraints.add(genPairListOfInteger("e"));
undConstraints.add(genPairListOfString("e"));
undConstraints.add(genPairListOfInteger("e1"));
undConstraints.add(genPairListOfString("e1"));
undConstraints.add(genPairListOfInteger("e2"));
undConstraints.add(genPairListOfString("e2"));
undConstraints.add(genPairListOfInteger("e3"));
undConstraints.add(genPairListOfString("e3"));
List<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>(); List<Set<Constraint<UnifyPair>>> oderConstraints = new ArrayList<>();
Set<UnifyPair> constraints = new HashSet<>(); Set<UnifyPair> constraints = new HashSet<>();
type1 = new ReferenceType("Object"); type1 = new ReferenceType("Object");
type2 = new ReferenceType("String");
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
type1 = new ReferenceType("Number");
type2 = new ReferenceType("Integer");
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
type1 = new ReferenceType("Object");
type2 = new ReferenceType("Number");
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER));
type1 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X")));
type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X"))); type2 = new ReferenceType("List", new TypeParams(new PlaceholderType("X")));
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
type1 = new ReferenceType("Object"); type1 = new ReferenceType("Object");
type2 = new ReferenceType("AbstractList", new TypeParams(new PlaceholderType("X"))); type2 = new ReferenceType("Integer");
constraints.add(new UnifyPair(type1, type2, PairOperator.SMALLER)); constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
type1 = new ReferenceType("Object");
type2 = new ReferenceType("String");
constraints.add(new UnifyPair(type2, type1, PairOperator.SMALLER));
IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter()); IFiniteClosure finiteClosure = new FiniteClosure(constraints, new NullWriter());
@@ -90,6 +100,7 @@ public class UnifyTest {
UnifyTaskModel tasks = new UnifyTaskModel(); UnifyTaskModel tasks = new UnifyTaskModel();
Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks); Set<Set<UnifyPair>> solution = unifyAlgo.unify(undConstraints, oderConstraints, finiteClosure, new NullWriter(), false, urm, tasks);
System.out.println(solution.size()); System.out.println(solution.size());
System.out.println(solution);
} }
/* /*
@Test @Test