Search in sources :

Example 1 with CodeAttributeInfo

use of org.ballerinalang.util.codegen.attributes.CodeAttributeInfo in project ballerina by ballerina-lang.

the class CPU method copyValues.

public static void copyValues(WorkerExecutionContext ctx, WorkerData parent, WorkerData workerSF) {
    CodeAttributeInfo codeInfo = ctx.parent.callableUnitInfo.getDefaultWorkerInfo().getCodeAttributeInfo();
    System.arraycopy(parent.longRegs, 0, workerSF.longRegs, 0, codeInfo.getMaxLongLocalVars());
    System.arraycopy(parent.doubleRegs, 0, workerSF.doubleRegs, 0, codeInfo.getMaxDoubleLocalVars());
    System.arraycopy(parent.intRegs, 0, workerSF.intRegs, 0, codeInfo.getMaxIntLocalVars());
    System.arraycopy(parent.stringRegs, 0, workerSF.stringRegs, 0, codeInfo.getMaxStringLocalVars());
    System.arraycopy(parent.byteRegs, 0, workerSF.byteRegs, 0, codeInfo.getMaxByteLocalVars());
    System.arraycopy(parent.refRegs, 0, workerSF.refRegs, 0, codeInfo.getMaxRefLocalVars());
}
Also used : CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo)

Example 2 with CodeAttributeInfo

use of org.ballerinalang.util.codegen.attributes.CodeAttributeInfo in project ballerina by ballerina-lang.

the class ProgramFileReader method getWorkerInfo.

private WorkerInfo getWorkerInfo(DataInputStream dataInStream, PackageInfo packageInfo) throws IOException {
    int workerNameCPIndex = dataInStream.readInt();
    UTF8CPEntry workerNameUTF8Entry = (UTF8CPEntry) packageInfo.getCPEntry(workerNameCPIndex);
    WorkerInfo workerInfo = new WorkerInfo(workerNameCPIndex, workerNameUTF8Entry.getValue());
    int wrkrDtChnlRefCPIndex = dataInStream.readInt();
    workerInfo.setWrkrDtChnlRefCPIndex(wrkrDtChnlRefCPIndex);
    if (wrkrDtChnlRefCPIndex >= 0) {
        WorkerDataChannelRefCPEntry refCPEntry = (WorkerDataChannelRefCPEntry) packageInfo.getCPEntry(wrkrDtChnlRefCPIndex);
        workerInfo.setWorkerDataChannelInfoForForkJoin(refCPEntry.getWorkerDataChannelInfo());
    }
    readForkJoinInfo(dataInStream, packageInfo, workerInfo);
    // Read attributes
    readAttributeInfoEntries(dataInStream, packageInfo, workerInfo);
    CodeAttributeInfo codeAttribute = (CodeAttributeInfo) workerInfo.getAttributeInfo(AttributeInfo.Kind.CODE_ATTRIBUTE);
    workerInfo.setCodeAttributeInfo(codeAttribute);
    return workerInfo;
}
Also used : UTF8CPEntry(org.ballerinalang.util.codegen.cpentries.UTF8CPEntry) CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo) WorkerDataChannelRefCPEntry(org.ballerinalang.util.codegen.cpentries.WorkerDataChannelRefCPEntry)

Example 3 with CodeAttributeInfo

use of org.ballerinalang.util.codegen.attributes.CodeAttributeInfo in project ballerina by ballerina-lang.

the class ProgramFileReader method getAttributeInfo.

private AttributeInfo getAttributeInfo(DataInputStream dataInStream, ConstantPool constantPool) throws IOException {
    int attribNameCPIndex = dataInStream.readInt();
    UTF8CPEntry attribNameCPEntry = (UTF8CPEntry) constantPool.getCPEntry(attribNameCPIndex);
    AttributeInfo.Kind attribKind = AttributeInfo.Kind.fromString(attribNameCPEntry.getValue());
    if (attribKind == null) {
        throw new ProgramFileFormatException("unknown attribute kind " + attribNameCPEntry.getValue());
    }
    switch(attribKind) {
        case CODE_ATTRIBUTE:
            CodeAttributeInfo codeAttributeInfo = new CodeAttributeInfo();
            codeAttributeInfo.setAttributeNameIndex(attribNameCPIndex);
            codeAttributeInfo.setCodeAddrs(dataInStream.readInt());
            codeAttributeInfo.setMaxLongLocalVars(dataInStream.readUnsignedShort());
            codeAttributeInfo.setMaxDoubleLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxStringLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxIntLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxByteLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxRefLocalVars(dataInStream.readShort());
            codeAttributeInfo.setMaxLongRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxDoubleRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxStringRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxIntRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxByteRegs(dataInStream.readShort());
            codeAttributeInfo.setMaxRefRegs(dataInStream.readShort());
            return codeAttributeInfo;
        case VARIABLE_TYPE_COUNT_ATTRIBUTE:
            VarTypeCountAttributeInfo varCountAttributeInfo = new VarTypeCountAttributeInfo(attribNameCPIndex);
            varCountAttributeInfo.setMaxLongVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxDoubleVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxStringVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxIntVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxByteVars(dataInStream.readShort());
            varCountAttributeInfo.setMaxRefVars(dataInStream.readShort());
            return varCountAttributeInfo;
        case ERROR_TABLE:
            ErrorTableAttributeInfo tableAttributeInfo = new ErrorTableAttributeInfo(attribNameCPIndex);
            int tableEntryCount = dataInStream.readShort();
            for (int i = 0; i < tableEntryCount; i++) {
                int ipFrom = dataInStream.readInt();
                int ipTo = dataInStream.readInt();
                int ipTarget = dataInStream.readInt();
                int priority = dataInStream.readInt();
                int errorStructCPIndex = dataInStream.readInt();
                ErrorTableEntry tableEntry = new ErrorTableEntry(ipFrom, ipTo, ipTarget, priority, errorStructCPIndex);
                if (errorStructCPIndex != -1) {
                    StructureRefCPEntry structureRefCPEntry = (StructureRefCPEntry) constantPool.getCPEntry(errorStructCPIndex);
                    tableEntry.setError((StructInfo) structureRefCPEntry.getStructureTypeInfo());
                }
                tableAttributeInfo.addErrorTableEntry(tableEntry);
            }
            return tableAttributeInfo;
        case LOCAL_VARIABLES_ATTRIBUTE:
            LocalVariableAttributeInfo localVarAttrInfo = new LocalVariableAttributeInfo(attribNameCPIndex);
            int localVarInfoCount = dataInStream.readShort();
            for (int i = 0; i < localVarInfoCount; i++) {
                LocalVariableInfo localVariableInfo = getLocalVariableInfo(dataInStream, constantPool);
                localVarAttrInfo.addLocalVarInfo(localVariableInfo);
            }
            return localVarAttrInfo;
        case LINE_NUMBER_TABLE_ATTRIBUTE:
            LineNumberTableAttributeInfo lnNoTblAttrInfo = new LineNumberTableAttributeInfo(attribNameCPIndex);
            int lineNoInfoCount = dataInStream.readShort();
            for (int i = 0; i < lineNoInfoCount; i++) {
                LineNumberInfo lineNumberInfo = getLineNumberInfo(dataInStream, constantPool);
                lnNoTblAttrInfo.addLineNumberInfo(lineNumberInfo);
            }
            return lnNoTblAttrInfo;
        case DEFAULT_VALUE_ATTRIBUTE:
            DefaultValue defaultValue = getDefaultValue(dataInStream, constantPool);
            DefaultValueAttributeInfo defaultValAttrInfo = new DefaultValueAttributeInfo(attribNameCPIndex, defaultValue);
            return defaultValAttrInfo;
        case PARAMETER_DEFAULTS_ATTRIBUTE:
            ParamDefaultValueAttributeInfo paramDefaultValAttrInfo = new ParamDefaultValueAttributeInfo(attribNameCPIndex);
            int paramDefaultsInfoCount = dataInStream.readShort();
            for (int i = 0; i < paramDefaultsInfoCount; i++) {
                DefaultValue paramDefaultValue = getDefaultValue(dataInStream, constantPool);
                paramDefaultValAttrInfo.addParamDefaultValueInfo(paramDefaultValue);
            }
            return paramDefaultValAttrInfo;
        default:
            throw new ProgramFileFormatException("unsupported attribute kind " + attribNameCPEntry.getValue());
    }
}
Also used : VarTypeCountAttributeInfo(org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo) LineNumberTableAttributeInfo(org.ballerinalang.util.codegen.attributes.LineNumberTableAttributeInfo) ProgramFileFormatException(org.ballerinalang.util.exceptions.ProgramFileFormatException) UTF8CPEntry(org.ballerinalang.util.codegen.cpentries.UTF8CPEntry) ParamDefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.ParamDefaultValueAttributeInfo) LocalVariableAttributeInfo(org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo) ErrorTableAttributeInfo(org.ballerinalang.util.codegen.attributes.ErrorTableAttributeInfo) LineNumberTableAttributeInfo(org.ballerinalang.util.codegen.attributes.LineNumberTableAttributeInfo) CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo) DefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.DefaultValueAttributeInfo) VarTypeCountAttributeInfo(org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo) AttributeInfo(org.ballerinalang.util.codegen.attributes.AttributeInfo) ParamDefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.ParamDefaultValueAttributeInfo) LocalVariableAttributeInfo(org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo) ParamDefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.ParamDefaultValueAttributeInfo) DefaultValueAttributeInfo(org.ballerinalang.util.codegen.attributes.DefaultValueAttributeInfo) ErrorTableAttributeInfo(org.ballerinalang.util.codegen.attributes.ErrorTableAttributeInfo) CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo) StructureRefCPEntry(org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)

Example 4 with CodeAttributeInfo

use of org.ballerinalang.util.codegen.attributes.CodeAttributeInfo in project ballerina by ballerina-lang.

the class BLangFunctions method invokeNonNativeCallable.

public static WorkerExecutionContext invokeNonNativeCallable(CallableUnitInfo callableUnitInfo, WorkerExecutionContext parentCtx, int[] argRegs, int[] retRegs, boolean waitForResponse, int flags) {
    WorkerSet workerSet = callableUnitInfo.getWorkerSet();
    int generalWorkersCount = workerSet.generalWorkers.length;
    CallableWorkerResponseContext respCtx = createWorkerResponseContext(callableUnitInfo.getRetParamTypes(), generalWorkersCount);
    WaitForResponseCallback respCallback = null;
    if (waitForResponse) {
        respCallback = new WaitForResponseCallback();
        respCtx.registerResponseCallback(respCallback);
    }
    if (TraceManagerWrapper.getInstance().isTraceEnabled() && FunctionFlags.isObserved(flags)) {
        respCtx.registerResponseCallback(new TraceableCallback(parentCtx));
    }
    respCtx.joinTargetContextInfo(parentCtx, retRegs);
    WorkerDataIndex wdi = callableUnitInfo.retWorkerIndex;
    /* execute the init worker and extract the local variables created by it */
    WorkerData initWorkerLocalData = null;
    CodeAttributeInfo initWorkerCAI = null;
    if (workerSet.initWorker != null) {
        initWorkerLocalData = executeInitWorker(parentCtx, argRegs, callableUnitInfo, workerSet.initWorker, wdi);
        if (initWorkerLocalData == null) {
            handleError(parentCtx);
            return null;
        }
        initWorkerCAI = workerSet.initWorker.getCodeAttributeInfo();
    }
    for (int i = 1; i < generalWorkersCount; i++) {
        executeWorker(respCtx, parentCtx, argRegs, callableUnitInfo, workerSet.generalWorkers[i], wdi, initWorkerLocalData, initWorkerCAI, false);
    }
    WorkerExecutionContext runInCallerCtx = executeWorker(respCtx, parentCtx, argRegs, callableUnitInfo, workerSet.generalWorkers[0], wdi, initWorkerLocalData, initWorkerCAI, true);
    if (waitForResponse) {
        BLangScheduler.executeNow(runInCallerCtx);
        respCallback.waitForResponse();
        // An error in the context at this point means an unhandled runtime error has propagated
        // all the way up to the entry point. Hence throw a {@link BLangRuntimeException} and
        // terminate the execution.
        BStruct error = parentCtx.getError();
        if (error != null) {
            handleError(parentCtx);
        }
        return null;
    } else {
        return runInCallerCtx;
    }
}
Also used : WorkerExecutionContext(org.ballerinalang.bre.bvm.WorkerExecutionContext) WorkerSet(org.ballerinalang.util.codegen.CallableUnitInfo.WorkerSet) BStruct(org.ballerinalang.model.values.BStruct) CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo) WorkerData(org.ballerinalang.bre.bvm.WorkerData) TraceableCallback(org.ballerinalang.util.tracer.TraceableCallback) SyncCallableWorkerResponseContext(org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext) CallableWorkerResponseContext(org.ballerinalang.bre.bvm.CallableWorkerResponseContext)

Example 5 with CodeAttributeInfo

use of org.ballerinalang.util.codegen.attributes.CodeAttributeInfo in project ballerina by ballerina-lang.

the class BLangFunctions method invokeCallable.

/**
 * This method does not short circuit the execution of the first worker to execute in the
 * same calling thread, but rather executes all the workers in their own separate threads.
 * This is specifically useful in executing service resources, where the calling transport
 * threads shouldn't be blocked, but rather the worker threads should be used.
 */
public static void invokeCallable(CallableUnitInfo callableUnitInfo, WorkerExecutionContext parentCtx, int[] argRegs, int[] retRegs, CallableUnitCallback responseCallback) {
    WorkerSet workerSet = callableUnitInfo.getWorkerSet();
    SyncCallableWorkerResponseContext respCtx = new SyncCallableWorkerResponseContext(callableUnitInfo.getRetParamTypes(), workerSet.generalWorkers.length);
    respCtx.registerResponseCallback(responseCallback);
    if (TraceManagerWrapper.getInstance().isTraceEnabled()) {
        respCtx.registerResponseCallback(new TraceableCallback(parentCtx));
    }
    respCtx.joinTargetContextInfo(parentCtx, retRegs);
    WorkerDataIndex wdi = callableUnitInfo.retWorkerIndex;
    /* execute the init worker and extract the local variables created by it */
    WorkerData initWorkerLocalData = null;
    CodeAttributeInfo initWorkerCAI = null;
    if (workerSet.initWorker != null) {
        initWorkerLocalData = executeInitWorker(parentCtx, argRegs, callableUnitInfo, workerSet.initWorker, wdi);
        if (initWorkerLocalData == null) {
            handleError(parentCtx);
            return;
        }
        initWorkerCAI = workerSet.initWorker.getCodeAttributeInfo();
    }
    for (int i = 0; i < workerSet.generalWorkers.length; i++) {
        executeWorker(respCtx, parentCtx, argRegs, callableUnitInfo, workerSet.generalWorkers[i], wdi, initWorkerLocalData, initWorkerCAI, false);
    }
}
Also used : WorkerSet(org.ballerinalang.util.codegen.CallableUnitInfo.WorkerSet) CodeAttributeInfo(org.ballerinalang.util.codegen.attributes.CodeAttributeInfo) WorkerData(org.ballerinalang.bre.bvm.WorkerData) TraceableCallback(org.ballerinalang.util.tracer.TraceableCallback) SyncCallableWorkerResponseContext(org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext)

Aggregations

CodeAttributeInfo (org.ballerinalang.util.codegen.attributes.CodeAttributeInfo)6 WorkerData (org.ballerinalang.bre.bvm.WorkerData)3 WorkerSet (org.ballerinalang.util.codegen.CallableUnitInfo.WorkerSet)3 SyncCallableWorkerResponseContext (org.ballerinalang.bre.bvm.SyncCallableWorkerResponseContext)2 WorkerExecutionContext (org.ballerinalang.bre.bvm.WorkerExecutionContext)2 UTF8CPEntry (org.ballerinalang.util.codegen.cpentries.UTF8CPEntry)2 TraceableCallback (org.ballerinalang.util.tracer.TraceableCallback)2 ArrayList (java.util.ArrayList)1 AsyncInvocableWorkerResponseContext (org.ballerinalang.bre.bvm.AsyncInvocableWorkerResponseContext)1 CallableWorkerResponseContext (org.ballerinalang.bre.bvm.CallableWorkerResponseContext)1 BCallableFuture (org.ballerinalang.model.values.BCallableFuture)1 BStruct (org.ballerinalang.model.values.BStruct)1 AttributeInfo (org.ballerinalang.util.codegen.attributes.AttributeInfo)1 DefaultValueAttributeInfo (org.ballerinalang.util.codegen.attributes.DefaultValueAttributeInfo)1 ErrorTableAttributeInfo (org.ballerinalang.util.codegen.attributes.ErrorTableAttributeInfo)1 LineNumberTableAttributeInfo (org.ballerinalang.util.codegen.attributes.LineNumberTableAttributeInfo)1 LocalVariableAttributeInfo (org.ballerinalang.util.codegen.attributes.LocalVariableAttributeInfo)1 ParamDefaultValueAttributeInfo (org.ballerinalang.util.codegen.attributes.ParamDefaultValueAttributeInfo)1 VarTypeCountAttributeInfo (org.ballerinalang.util.codegen.attributes.VarTypeCountAttributeInfo)1 StructureRefCPEntry (org.ballerinalang.util.codegen.cpentries.StructureRefCPEntry)1