use of org.objectweb.asm.commons.Method in project deltaspike by apache.
the class AsmProxyClassGenerator method defineDefaultConstructor.
private static void defineDefaultConstructor(ClassWriter cw, Type proxyType, Type superType) {
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, new Method("<init>", Type.VOID_TYPE, new Type[] {}), null, null, cw);
mg.visitCode();
// invoke super constructor
mg.loadThis();
mg.invokeConstructor(superType, Method.getMethod("void <init> ()"));
mg.returnValue();
mg.endMethod();
mg.visitEnd();
}
use of org.objectweb.asm.commons.Method in project deltaspike by apache.
the class AsmProxyClassGenerator method defineDeltaSpikeProxyMethods.
private static void defineDeltaSpikeProxyMethods(ClassWriter cw, Type proxyType, Type delegateInvocationHandlerType) {
try {
// implement #setDelegateInvocationHandler
Method asmMethod = Method.getMethod(DeltaSpikeProxy.class.getDeclaredMethod("setDelegateInvocationHandler", InvocationHandler.class));
GeneratorAdapter mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, asmMethod, null, null, cw);
mg.visitCode();
mg.loadThis();
mg.loadArg(0);
mg.checkCast(delegateInvocationHandlerType);
mg.putField(proxyType, FIELDNAME_DELEGATE_INVOCATION_HANDLER, delegateInvocationHandlerType);
mg.returnValue();
mg.visitMaxs(2, 1);
mg.visitEnd();
// implement #getDelegateInvocationHandler
asmMethod = Method.getMethod(DeltaSpikeProxy.class.getDeclaredMethod("getDelegateInvocationHandler"));
mg = new GeneratorAdapter(Opcodes.ACC_PUBLIC, asmMethod, null, null, cw);
mg.visitCode();
mg.loadThis();
mg.getField(proxyType, FIELDNAME_DELEGATE_INVOCATION_HANDLER, delegateInvocationHandlerType);
mg.returnValue();
mg.visitMaxs(2, 1);
mg.visitEnd();
} catch (NoSuchMethodException e) {
throw new IllegalStateException("Unable to implement " + DeltaSpikeProxy.class.getName(), e);
}
}
use of org.objectweb.asm.commons.Method in project Lucee by lucee.
the class ComponentUtil method createMethod.
private static int createMethod(ConstrBytecodeContext constr, java.util.List<LitString> keys, ClassWriter cw, String className, Object member, int max, boolean writeLog, boolean suppressWSbeforeArg, boolean output, boolean returnValue) throws PageException {
boolean hasOptionalArgs = false;
if (member instanceof UDF) {
UDF udf = (UDF) member;
FunctionArgument[] args = udf.getFunctionArguments();
Type[] types = new Type[max < 0 ? args.length : max];
for (int y = 0; y < types.length; y++) {
types[y] = toType(args[y].getTypeAsString(), true);
if (!args[y].isRequired())
hasOptionalArgs = true;
}
Type rtnType = toType(udf.getReturnTypeAsString(), true);
Method method = new Method(udf.getFunctionName(), rtnType, types);
GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, method, null, null, cw);
BytecodeContext bc = new BytecodeContext(null, constr, getPage(constr), keys, cw, className, adapter, method, writeLog, suppressWSbeforeArg, output, returnValue);
Label start = adapter.newLabel();
adapter.visitLabel(start);
// ComponentController.invoke(name, args);
// name
adapter.push(udf.getFunctionName());
// args
ArrayVisitor av = new ArrayVisitor();
av.visitBegin(adapter, Types.OBJECT, types.length);
for (int y = 0; y < types.length; y++) {
av.visitBeginItem(adapter, y);
adapter.loadArg(y);
av.visitEndItem(bc.getAdapter());
}
av.visitEnd();
adapter.invokeStatic(Types.COMPONENT_CONTROLLER, INVOKE);
adapter.checkCast(rtnType);
// ASMConstants.NULL(adapter);
adapter.returnValue();
Label end = adapter.newLabel();
adapter.visitLabel(end);
for (int y = 0; y < types.length; y++) {
adapter.visitLocalVariable(args[y].getName().getString(), types[y].getDescriptor(), null, start, end, y + 1);
}
adapter.endMethod();
if (hasOptionalArgs) {
if (max == -1)
max = args.length - 1;
else
max--;
return max;
}
}
return -1;
}
use of org.objectweb.asm.commons.Method in project Lucee by lucee.
the class BodyBase method writeOut.
public static void writeOut(final BytecodeContext bc, List<Statement> statements) throws TransformerException {
GeneratorAdapter adapter = bc.getAdapter();
boolean isOutsideMethod;
GeneratorAdapter a = null;
Method m;
BytecodeContext _bc = bc;
Iterator<Statement> it = statements.iterator();
boolean split = bc.getPage().getSplitIfNecessary();
// int lastLine=-1;
while (it.hasNext()) {
isOutsideMethod = bc.getMethod().getReturnType().equals(Types.VOID);
Statement s = it.next();
if (split && _bc.incCount() > MAX_STATEMENTS && bc.doSubFunctions() && (isOutsideMethod || !s.hasFlowController()) && s.getStart() != null) {
if (a != null) {
a.returnValue();
a.endMethod();
}
// ExpressionUtil.visitLine(bc, s.getLine());
String method = ASMUtil.createOverfowMethod(bc.getMethod().getName(), bc.getPage().getMethodCount());
ExpressionUtil.visitLine(bc, s.getStart());
// ExpressionUtil.lastLine(bc);
m = new Method(method, Types.VOID, new Type[] { Types.PAGE_CONTEXT });
a = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, m, null, new Type[] { Types.THROWABLE }, bc.getClassWriter());
_bc = new BytecodeContext(bc.getConstructor(), bc.getKeys(), bc, a, m);
if (bc.getRoot() != null)
_bc.setRoot(bc.getRoot());
else
_bc.setRoot(bc);
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.visitVarInsn(Opcodes.ALOAD, 1);
adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, bc.getClassName(), method, "(Llucee/runtime/PageContext;)V");
}
if (_bc != bc && s.hasFlowController()) {
if (a != null) {
a.returnValue();
a.endMethod();
}
_bc = bc;
a = null;
}
ExpressionUtil.writeOut(s, _bc);
}
if (a != null) {
a.returnValue();
a.endMethod();
}
}
use of org.objectweb.asm.commons.Method in project Lucee by lucee.
the class BodyBase method addToSubMethod.
private static void addToSubMethod(BytecodeContext bc, Statement... statements) throws TransformerException {
if (statements == null || statements.length == 0)
return;
GeneratorAdapter adapter = bc.getAdapter();
String method = ASMUtil.createOverfowMethod(bc.getMethod().getName(), bc.getPage().getMethodCount());
for (int i = 0; i < statements.length; i++) {
if (statements[i].getStart() != null) {
ExpressionUtil.visitLine(bc, statements[i].getStart());
break;
}
}
// ExpressionUtil.lastLine(bc);
Method m = new Method(method, Types.VOID, new Type[] { Types.PAGE_CONTEXT });
GeneratorAdapter a = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, m, null, new Type[] { Types.THROWABLE }, bc.getClassWriter());
BytecodeContext _bc = new BytecodeContext(bc.getConstructor(), bc.getKeys(), bc, a, m);
if (bc.getRoot() != null)
_bc.setRoot(bc.getRoot());
else
_bc.setRoot(bc);
adapter.visitVarInsn(Opcodes.ALOAD, 0);
adapter.visitVarInsn(Opcodes.ALOAD, 1);
adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, bc.getClassName(), method, "(Llucee/runtime/PageContext;)V");
for (int i = 0; i < statements.length; i++) {
ExpressionUtil.writeOut(statements[i], _bc);
}
a.returnValue();
a.endMethod();
}
Aggregations