Search in sources :

Example 1 with ForkjoinInfo

use of org.wso2.ballerinalang.programfile.ForkjoinInfo in project ballerina by ballerina-lang.

the class CodeGenerator method visit.

public void visit(BLangForkJoin forkJoin) {
    SymbolEnv forkJoinEnv = SymbolEnv.createForkJoinSymbolEnv(forkJoin, this.env);
    ForkjoinInfo forkjoinInfo = new ForkjoinInfo(this.lvIndexes.toArray());
    this.populateForkJoinWorkerInfo(forkJoin, forkjoinInfo);
    int forkJoinInfoIndex = this.forkJoinCount++;
    /* was I already inside a fork/join */
    if (this.env.forkJoin != null) {
        this.currentWorkerInfo.addForkJoinInfo(forkjoinInfo);
    } else {
        this.currentCallableUnitInfo.defaultWorkerInfo.addForkJoinInfo(forkjoinInfo);
    }
    ForkJoinCPEntry forkJoinCPEntry = new ForkJoinCPEntry(forkJoinInfoIndex);
    Operand forkJoinCPIndex = getOperand(this.currentPkgInfo.addCPEntry(forkJoinCPEntry));
    forkjoinInfo.setIndexCPIndex(forkJoinCPIndex.value);
    RegIndex timeoutRegIndex = new RegIndex(-1, TypeTags.INT);
    addToRegIndexList(timeoutRegIndex);
    if (forkJoin.timeoutExpression != null) {
        forkjoinInfo.setTimeoutAvailable(true);
        this.genNode(forkJoin.timeoutExpression, forkJoinEnv);
        timeoutRegIndex.value = forkJoin.timeoutExpression.regIndex.value;
    }
    // FORKJOIN forkJoinCPIndex timeoutRegIndex joinVarRegIndex joinBlockAddr timeoutVarRegIndex timeoutBlockAddr
    RegIndex joinVarRegIndex = new RegIndex(-1, TypeTags.MAP);
    Operand joinBlockAddr = getOperand(-1);
    RegIndex timeoutVarRegIndex = new RegIndex(-1, TypeTags.MAP);
    Operand timeoutBlockAddr = getOperand(-1);
    this.emit(InstructionCodes.FORKJOIN, forkJoinCPIndex, timeoutRegIndex, joinVarRegIndex, joinBlockAddr, timeoutVarRegIndex, timeoutBlockAddr);
    this.processJoinWorkers(forkJoin, forkjoinInfo, forkJoinEnv);
    int i = 0;
    int[] joinWrkrNameCPIndexes = new int[forkJoin.joinedWorkers.size()];
    String[] joinWrkrNames = new String[joinWrkrNameCPIndexes.length];
    for (BLangIdentifier workerName : forkJoin.joinedWorkers) {
        UTF8CPEntry workerNameCPEntry = new UTF8CPEntry(workerName.value);
        int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
        joinWrkrNameCPIndexes[i] = workerNameCPIndex;
        joinWrkrNames[i] = workerName.value;
        i++;
    }
    forkjoinInfo.setJoinWrkrNameIndexes(joinWrkrNameCPIndexes);
    forkjoinInfo.setJoinWorkerNames(joinWrkrNames);
    forkjoinInfo.setWorkerCount(forkJoin.joinedWorkerCount);
    this.processJoinBlock(forkJoin, forkjoinInfo, forkJoinEnv, joinVarRegIndex, joinBlockAddr);
    this.processTimeoutBlock(forkJoin, forkJoinEnv, timeoutVarRegIndex, timeoutBlockAddr);
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) ForkjoinInfo(org.wso2.ballerinalang.programfile.ForkjoinInfo) Operand(org.wso2.ballerinalang.programfile.Instruction.Operand) ForkJoinCPEntry(org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry) SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv) BLangXMLQuotedString(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString) BLangIdentifier(org.wso2.ballerinalang.compiler.tree.BLangIdentifier) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Example 2 with ForkjoinInfo

use of org.wso2.ballerinalang.programfile.ForkjoinInfo in project ballerina by ballerina-lang.

the class CodeGenerator method processJoinBlock.

/* generate code for Join block */
private void processJoinBlock(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo, SymbolEnv forkJoinEnv, RegIndex joinVarRegIndex, Operand joinBlockAddr) {
    UTF8CPEntry joinType = new UTF8CPEntry(forkJoin.joinType.name());
    int joinTypeCPIndex = this.currentPkgInfo.addCPEntry(joinType);
    forkjoinInfo.setJoinType(forkJoin.joinType.name());
    forkjoinInfo.setJoinTypeCPIndex(joinTypeCPIndex);
    joinBlockAddr.value = nextIP();
    if (forkJoin.joinResultVar != null) {
        visitForkJoinParameterDefs(forkJoin.joinResultVar, forkJoinEnv);
        joinVarRegIndex.value = forkJoin.joinResultVar.symbol.varIndex.value;
    }
    if (forkJoin.joinedBody != null) {
        this.genNode(forkJoin.joinedBody, forkJoinEnv);
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 3 with ForkjoinInfo

use of org.wso2.ballerinalang.programfile.ForkjoinInfo in project ballerina by ballerina-lang.

the class CodeGenerator method populateForkJoinWorkerInfo.

private void populateForkJoinWorkerInfo(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo) {
    for (BLangWorker worker : forkJoin.workers) {
        UTF8CPEntry workerNameCPEntry = new UTF8CPEntry(worker.name.value);
        int workerNameCPIndex = this.currentPkgInfo.addCPEntry(workerNameCPEntry);
        WorkerInfo workerInfo = new WorkerInfo(workerNameCPIndex, worker.name.value);
        forkjoinInfo.addWorkerInfo(worker.name.value, workerInfo);
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint)

Example 4 with ForkjoinInfo

use of org.wso2.ballerinalang.programfile.ForkjoinInfo in project ballerina by ballerina-lang.

the class CodeGenerator method processJoinWorkers.

/* visit the workers within fork-join block */
private void processJoinWorkers(BLangForkJoin forkJoin, ForkjoinInfo forkjoinInfo, SymbolEnv forkJoinEnv) {
    UTF8CPEntry codeUTF8CPEntry = new UTF8CPEntry(AttributeInfo.Kind.CODE_ATTRIBUTE.toString());
    int codeAttribNameIndex = this.currentPkgInfo.addCPEntry(codeUTF8CPEntry);
    for (BLangWorker worker : forkJoin.workers) {
        VariableIndex lvIndexesCopy = copyVarIndex(this.lvIndexes);
        this.regIndexes = new VariableIndex(REG);
        VariableIndex regIndexesCopy = this.regIndexes;
        this.regIndexes = new VariableIndex(REG);
        VariableIndex maxRegIndexesCopy = this.maxRegIndexes;
        this.maxRegIndexes = new VariableIndex(REG);
        List<RegIndex> regIndexListCopy = this.regIndexList;
        this.regIndexList = new ArrayList<>();
        WorkerInfo workerInfo = forkjoinInfo.getWorkerInfo(worker.name.value);
        workerInfo.codeAttributeInfo.attributeNameIndex = codeAttribNameIndex;
        workerInfo.codeAttributeInfo.codeAddrs = this.nextIP();
        this.currentWorkerInfo = workerInfo;
        this.genNode(worker.body, forkJoinEnv);
        this.endWorkerInfoUnit(workerInfo.codeAttributeInfo);
        this.emit(InstructionCodes.HALT);
        this.lvIndexes = lvIndexesCopy;
        this.regIndexes = regIndexesCopy;
        this.maxRegIndexes = maxRegIndexesCopy;
        this.regIndexList = regIndexListCopy;
    }
}
Also used : UTF8CPEntry(org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry) BLangWorker(org.wso2.ballerinalang.compiler.tree.BLangWorker) WorkerInfo(org.wso2.ballerinalang.programfile.WorkerInfo) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) RegIndex(org.wso2.ballerinalang.programfile.Instruction.RegIndex)

Aggregations

BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)4 UTF8CPEntry (org.wso2.ballerinalang.programfile.cpentries.UTF8CPEntry)4 BLangWorker (org.wso2.ballerinalang.compiler.tree.BLangWorker)2 RegIndex (org.wso2.ballerinalang.programfile.Instruction.RegIndex)2 WorkerInfo (org.wso2.ballerinalang.programfile.WorkerInfo)2 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)1 BLangIdentifier (org.wso2.ballerinalang.compiler.tree.BLangIdentifier)1 BLangXMLQuotedString (org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQuotedString)1 ForkjoinInfo (org.wso2.ballerinalang.programfile.ForkjoinInfo)1 Operand (org.wso2.ballerinalang.programfile.Instruction.Operand)1 ForkJoinCPEntry (org.wso2.ballerinalang.programfile.cpentries.ForkJoinCPEntry)1