use of org.ballerinalang.bre.bvm.WorkerData in project ballerina by ballerina-lang.
the class BLangFunctions method executeInitWorker.
private static WorkerData executeInitWorker(WorkerExecutionContext parentCtx, int[] argRegs, CallableUnitInfo callableUnitInfo, WorkerInfo workerInfo, WorkerDataIndex wdi) {
InitWorkerResponseContext respCtx = new InitWorkerResponseContext(parentCtx);
WorkerExecutionContext ctx = executeWorker(respCtx, parentCtx, argRegs, callableUnitInfo, workerInfo, wdi, null, null, true);
BLangScheduler.executeNow(ctx);
WorkerData workerLocal = ctx.workerLocal;
if (respCtx.isErrored()) {
return null;
} else {
return workerLocal;
}
}
use of org.ballerinalang.bre.bvm.WorkerData 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.bre.bvm.WorkerData in project ballerina by ballerina-lang.
the class BLangFunctions method invokeNativeCallableAsync.
private static void invokeNativeCallableAsync(CallableUnitInfo callableUnitInfo, WorkerExecutionContext parentCtx, int[] argRegs, int[] retRegs) {
WorkerData caleeSF = BLangVMUtils.createWorkerDataForLocal(callableUnitInfo.getDefaultWorkerInfo(), parentCtx, argRegs, callableUnitInfo.getParamTypes());
Context nativeCtx = new NativeCallContext(parentCtx, callableUnitInfo, caleeSF);
NativeCallableUnit nativeCallable = callableUnitInfo.getNativeCallableUnit();
if (nativeCallable == null) {
return;
}
AsyncInvocableWorkerResponseContext respCtx;
if (nativeCallable.isBlocking()) {
respCtx = BLangScheduler.executeBlockingNativeAsync(nativeCallable, nativeCtx);
} else {
respCtx = BLangScheduler.executeNonBlockingNativeAsync(nativeCallable, nativeCtx);
}
BLangVMUtils.populateWorkerDataWithValues(parentCtx.workerLocal, retRegs, new BValue[] { new BCallableFuture(callableUnitInfo.getName(), respCtx) }, new BType[] { BTypes.typeFuture });
}
use of org.ballerinalang.bre.bvm.WorkerData in project ballerina by ballerina-lang.
the class BLangFunctions method executeWorker.
private static WorkerExecutionContext executeWorker(WorkerResponseContext respCtx, WorkerExecutionContext parentCtx, int[] argRegs, CallableUnitInfo callableUnitInfo, WorkerInfo workerInfo, WorkerDataIndex wdi, WorkerData initWorkerLocalData, CodeAttributeInfo initWorkerCAI, boolean runInCaller) {
WorkerData workerLocal = BLangVMUtils.createWorkerDataForLocal(workerInfo, parentCtx, argRegs, callableUnitInfo.getParamTypes());
if (initWorkerLocalData != null) {
BLangVMUtils.mergeInitWorkertData(initWorkerLocalData, workerLocal, initWorkerCAI);
}
WorkerData workerResult = BLangVMUtils.createWorkerData(wdi);
WorkerExecutionContext ctx = new WorkerExecutionContext(parentCtx, respCtx, callableUnitInfo, workerInfo, workerLocal, workerResult, wdi.retRegs, runInCaller);
BLangScheduler.schedule(ctx);
return ctx;
}
use of org.ballerinalang.bre.bvm.WorkerData in project ballerina by ballerina-lang.
the class BLangFunctions method executeWorker.
private static WorkerExecutionContext executeWorker(WorkerResponseContext respCtx, WorkerExecutionContext parentCtx, int[] argRegs, WorkerInfo workerInfo, Map<String, Object> globalProps, boolean runInCaller) {
WorkerData workerLocal = BLangVMUtils.createWorkerDataForLocal(workerInfo, parentCtx, argRegs);
WorkerExecutionContext ctx = new WorkerExecutionContext(parentCtx, respCtx, parentCtx.callableUnitInfo, workerInfo, workerLocal, runInCaller);
return BLangScheduler.schedule(ctx);
}
Aggregations