List of usage examples for com.google.gwt.dev.asm Type getSize
public int getSize()
From source file:com.googlecode.gwt.test.internal.rewrite.RewriteSingleJsoImplDispatches.java
License:Apache License
/** * For regular Java objects that implement a SingleJsoImpl interface, write instance trampoline * dispatchers for mangled method names to the implementing method. *///from w ww .j a va 2 s .c om private void writeTrampoline(String stubIntr) { /* * This is almost the same kind of trampoline as the ones generated in WriteJsoImpl, however * there are enough small differences between the semantics of the dispatches that would make * a common implementation far more awkward than the duplication of code. */ for (String mangledName : toImplement(stubIntr)) { for (Method method : jsoData.getDeclarations(mangledName)) { Method toCall = new Method(method.getName(), method.getDescriptor()); // Must not be final MethodVisitor mv = super.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC, mangledName, method.getDescriptor(), null, null); if (mv != null) { mv.visitCode(); /* * It just so happens that the stack and local variable sizes are the same, but * they're kept distinct to aid in clarity should the dispatch logic change. * * These start at 1 because we need to load "this" onto the stack */ int var = 1; int size = 1; // load this mv.visitVarInsn(Opcodes.ALOAD, 0); // then the rest of the arguments for (Type t : toCall.getArgumentTypes()) { size += t.getSize(); mv.visitVarInsn(t.getOpcode(Opcodes.ILOAD), var); var += t.getSize(); } // Make sure there's enough room for the return value size = Math.max(size, toCall.getReturnType().getSize()); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, currentTypeName, toCall.getName(), toCall.getDescriptor()); mv.visitInsn(toCall.getReturnType().getOpcode(Opcodes.IRETURN)); mv.visitMaxs(size, var); mv.visitEnd(); } } } }