use of org.robovm.compiler.llvm.FunctionRef in project robovm by robovm.
the class AbstractMethodCompiler method compileSynchronizedWrapper.
private void compileSynchronizedWrapper(ModuleBuilder moduleBuilder, SootMethod method) {
String targetName = Symbols.methodSymbol(method);
Function syncFn = FunctionBuilder.synchronizedWrapper(method);
moduleBuilder.addFunction(syncFn);
FunctionType functionType = syncFn.getType();
FunctionRef target = new FunctionRef(targetName, functionType);
Value monitor = null;
if (method.isStatic()) {
FunctionRef fn = FunctionBuilder.ldcInternal(sootMethod.getDeclaringClass()).ref();
monitor = call(syncFn, fn, syncFn.getParameterRef(0));
} else {
monitor = syncFn.getParameterRef(1);
}
call(syncFn, MONITORENTER, syncFn.getParameterRef(0), monitor);
BasicBlockRef bbSuccess = syncFn.newBasicBlockRef(new Label("success"));
BasicBlockRef bbFailure = syncFn.newBasicBlockRef(new Label("failure"));
trycatchAllEnter(syncFn, bbSuccess, bbFailure);
syncFn.newBasicBlock(bbSuccess.getLabel());
Value result = call(syncFn, target, syncFn.getParameterRefs());
trycatchLeave(syncFn);
call(syncFn, MONITOREXIT, syncFn.getParameterRef(0), monitor);
syncFn.add(new Ret(result));
syncFn.newBasicBlock(bbFailure.getLabel());
trycatchLeave(syncFn);
call(syncFn, MONITOREXIT, syncFn.getParameterRef(0), monitor);
call(syncFn, BC_THROW_IF_EXCEPTION_OCCURRED, syncFn.getParameterRef(0));
syncFn.add(new Unreachable());
}
Aggregations