forked from JavaTX/JavaCompilerCore
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
This commit is contained in:
parent
01891c9513
commit
38d4481756
@ -56,12 +56,13 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
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<Set<Set<UnifyPair>>> {
|
||||
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<Set<UnifyPair>>> {
|
||||
Set<UnifyPair> a = null;
|
||||
while (nextSetasList.size() > 0) { //(nextSetasList.size() != 0) {
|
||||
Set<UnifyPair> a_last = a;
|
||||
List<Set<UnifyPair>> nextSetasListRest= new ArrayList<>();
|
||||
List<Set<UnifyPair>> nextSetasListRestMax = new ArrayList<>();
|
||||
List<Set<UnifyPair>> nextSetasListRestMin = new ArrayList<>();
|
||||
List<Set<UnifyPair>> nextSetasListRestOder = new ArrayList<>();
|
||||
if (variance == 1) {
|
||||
a = oup.max(nextSetasList.iterator());
|
||||
nextSetasList.remove(a);
|
||||
nextSetasListRest = new ArrayList<>(nextSetasList);
|
||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRest).iterator();
|
||||
nextSetasListRestMax = new ArrayList<>(nextSetasList);
|
||||
Iterator<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRestMax).iterator();
|
||||
while (nextSetasListItRest.hasNext()) {
|
||||
Set<UnifyPair> 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<Set<UnifyPair>> nextSetasListItRest = new ArrayList<Set<UnifyPair>>(nextSetasListRestMin).iterator();
|
||||
while (nextSetasListItRest.hasNext()) {
|
||||
Set<UnifyPair> 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<Set<Set<UnifyPair>>> {
|
||||
//writeLog("Vor unify2 Aufruf: " + elems.toString());
|
||||
Set<Set<UnifyPair>> res = new HashSet<>();
|
||||
Set<Set<Set<UnifyPair>>> 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<Set<Set<UnifyPair>>> {
|
||||
forks.add(forkOrig);
|
||||
forkOrig.fork();
|
||||
|
||||
while (!nextSetasListRest.isEmpty()) {
|
||||
Set<UnifyPair> nSaL = nextSetasListRest.remove(0);
|
||||
while (!nextSetasListRestMax.isEmpty()) {
|
||||
Set<UnifyPair> nSaL = nextSetasListRestMax.remove(0);
|
||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> newOderConstraints = new ArrayList<>(oderConstraints);
|
||||
@ -878,13 +890,70 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
res = forkOrig.join();
|
||||
for(TypeUnifyTask fork : forks) {
|
||||
Set<Set<UnifyPair>> fork_res = fork.join();
|
||||
synchronized (this) { noOfThread--; };
|
||||
add_res.add(fork_res);
|
||||
}
|
||||
} else {
|
||||
if(parallel && (variance == -1) && noOfThread <= MaxNoOfThreads) {
|
||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> 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<UnifyPair> nSaL = nextSetasListRestMin.remove(0);
|
||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> 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<Set<UnifyPair>> fork_res = fork.join();
|
||||
synchronized (this) { noOfThread--; };
|
||||
add_res.add(fork_res);
|
||||
}
|
||||
} else {
|
||||
if(parallel && (variance == 2) && noOfThread <= MaxNoOfThreads) {
|
||||
Set<TypeUnifyTask> forks = new HashSet<>();
|
||||
Set<UnifyPair> newEqOrig = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElemsOrig = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> 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<UnifyPair> nSaL = nextSetasListRestOder.remove(0);
|
||||
Set<UnifyPair> newEq = new HashSet<>(eq);
|
||||
Set<Set<UnifyPair>> newElems = new HashSet<>(elems);
|
||||
List<Set<Set<UnifyPair>>> 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<Set<UnifyPair>> 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<Set<Set<UnifyPair>>> {
|
||||
}
|
||||
}
|
||||
else { if (variance == -1) {
|
||||
if (parallel) {
|
||||
for (Set<Set<UnifyPair>> 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<Set<Set<UnifyPair>>> {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (variance == 0) {
|
||||
else { if (variance == 0) {
|
||||
writeLog("a: " + rekTiefe + " variance: " + variance + a.toString());
|
||||
break; }
|
||||
else { if (variance == 2) {
|
||||
if (parallel) {
|
||||
for (Set<Set<UnifyPair>> 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<Set<Set<UnifyPair>>> {
|
||||
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();
|
||||
|
||||
|
@ -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<Vector<Integer>> {
|
||||
|
Loading…
Reference in New Issue
Block a user