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());
}
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;
}
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());
}
}
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;
}
}
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);
}
}
Aggregations