List of usage examples for org.objectweb.asm Opcodes ACC_PUBLIC
int ACC_PUBLIC
To view the source code for org.objectweb.asm Opcodes ACC_PUBLIC.
Click Source Link
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. *///ww w. jav a 2s . 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(); } } } }
From source file:com.googlecode.japi.checker.model.JavaItem.java
License:Apache License
public static Scope toScope(int access) { if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) { return Scope.PRIVATE; } else if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) { return Scope.PROTECTED; }/*from w w w . ja v a 2 s. c o m*/ if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) { return Scope.PUBLIC; } else { return Scope.NO_SCOPE; } }
From source file:com.googlecode.japi.checker.Utils.java
License:Apache License
public static Scope toScope(int access) { if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) { return Scope.PRIVATE; } else if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) { return Scope.PROTECTED; }//w w w .j a v a 2s.c o m if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) { return Scope.PUBLIC; } else { return Scope.PACKAGE; } }
From source file:com.hea3ven.hardmodetweaks.core.ClassTransformerHardModeTweaks.java
License:Open Source License
private MethodNode createNewGetWorldTimeMethod(String methodName, boolean obfuscated) { // > long getWorldTime() { // > return TimeTweaksManager.getWorldTime(this); // > }//from ww w . j av a 2 s . co m MethodNode getWorldTimeMethod = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PUBLIC, methodName, "()J", null, null); getWorldTimeMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); getWorldTimeMethod.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/hea3ven/hardmodetweaks/TimeTweaksManager", "getWorldTime", "(L" + WORLD_INFO.getPath(obfuscated) + ";)J")); getWorldTimeMethod.instructions.add(new InsnNode(Opcodes.LRETURN)); return getWorldTimeMethod; }
From source file:com.hea3ven.hardmodetweaks.core.ClassTransformerHardModeTweaks.java
License:Open Source License
private MethodNode createNewSetWorldTimeMethod(String methodName, boolean obfuscated) { // > void setWorldTime(long time) { // > TimeTweaksManager.setWorldTime(this, time); // > }/* w w w.j a v a 2s. c o m*/ MethodNode setWorldTimeMethod = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PUBLIC, methodName, "(J)V", null, null); setWorldTimeMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); setWorldTimeMethod.instructions.add(new VarInsnNode(Opcodes.LLOAD, 1)); setWorldTimeMethod.instructions .add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/hea3ven/hardmodetweaks/TimeTweaksManager", "setWorldTime", "(L" + WORLD_INFO.getPath(obfuscated) + ";J)V")); setWorldTimeMethod.instructions.add(new InsnNode(Opcodes.RETURN)); return setWorldTimeMethod; }
From source file:com.hea3ven.hardmodetweaks.core.ClassTransformerHardModeTweaks.java
License:Open Source License
private MethodNode createNewCalcCelAngleMethod(String methodName, boolean obfuscated) { // > float calculateCelestialAngle(long time, float off) { // > return TimeTweaksManager.calculateCelestialAngle(time, off); // > }//from w w w.j a va 2 s. c o m MethodNode getWorldTimeMethod = new MethodNode(Opcodes.ASM4, Opcodes.ACC_PUBLIC, methodName, "(JF)F", null, null); getWorldTimeMethod.instructions.add(new VarInsnNode(Opcodes.LLOAD, 1)); getWorldTimeMethod.instructions.add(new VarInsnNode(Opcodes.FLOAD, 3)); getWorldTimeMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "com/hea3ven/hardmodetweaks/TimeTweaksManager", "calculateCelestialAngle", "(JF)F")); getWorldTimeMethod.instructions.add(new InsnNode(Opcodes.FRETURN)); return getWorldTimeMethod; }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java
License:Open Source License
/** * compile. This method generates the class definition *//* www.ja va2 s . c o m*/ public byte[] compile(InputStream inputStream, String classname, boolean verboseOutput) throws Exception { try { /* * a message */ logger.info("Parsing input for classname: '" + classname + "'"); /* * get tree */ final ProgContext progContext = parse(inputStream); /* * print tree */ final TreePrinter treePrinter = new TreePrinter(); treePrinter.printTree(progContext); /* * a message */ logger.info("Generating Bytecode for class '" + classname + "'"); /* * class */ final ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); classWriter.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, classname, null, "java/lang/Object", null); /* * the execution context */ FieldVisitor fieldVistor = classWriter.visitField(Opcodes.ACC_PUBLIC, RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE, null, null); fieldVistor.visitEnd(); /* * input stream */ fieldVistor = classWriter.visitField(Opcodes.ACC_PUBLIC, "inputStream", "Ljava/io/InputStream;", null, null); fieldVistor.visitEnd(); /* * output stream */ fieldVistor = classWriter.visitField(Opcodes.ACC_PUBLIC, "outputStream", "Ljava/io/PrintStream;", null, null); fieldVistor.visitEnd(); /* * init method */ generateInit(classname, classWriter); /* * main() */ generateMain(classname, classWriter); /* * program */ generateProgram(classname, classWriter, progContext); /* * generate the class */ classWriter.visitEnd(); return classWriter.toByteArray(); } catch (final Exception e) { throw new Exception("Exception in compile", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java
License:Open Source License
/** * generate init./*from w ww. j a v a 2s .c om*/ * <p> * This inits the class members and assigns class members, such as the ExecutionContext. * </p> * <p> * <code> * public ExecutionContext executionContext = new ExecutionContext(); * </code> * </p> */ protected void generateInit(String className, ClassWriter classWriter) throws Exception { try { final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode(); /* * call init() */ final Label l0 = new Label(); methodVisitor.visitLabel(l0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); /* * create a new execution context and assign it */ final Label l1 = new Label(); methodVisitor.visitLabel(l1); methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitTypeInsn(Opcodes.NEW, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "<init>", "()V"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, className, RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); /* * return */ final Label l2 = new Label(); methodVisitor.visitLabel(l2); methodVisitor.visitLineNumber(8, l2); methodVisitor.visitInsn(Opcodes.RETURN); /* * declare variables */ final Label l3 = new Label(); methodVisitor.visitLabel(l3); methodVisitor.visitLocalVariable("this", "L" + className + ";", null, l0, l3, 0); methodVisitor.visitMaxs(3, 1); methodVisitor.visitEnd(); } catch (final Exception e) { throw new Exception("Exception in generateInit", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java
License:Open Source License
/** * generate void main(String[])//ww w . j a va2s . c om * <p> * <code> * public static void main(String[] args) { * ExampleProgram exampleProgram = new ExampleProgram(); * try { * exampleProgram.inputStream = System.in; * exampleProgram.outputStream = System.out; * exampleProgram.program(); * } catch (Exception e) { * e.printStackTrace(); * } * } * </code> * </p> */ protected void generateMain(String classname, ClassWriter classWriter) throws Exception { try { /* * make method */ final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null); methodVisitor.visitCode(); final Label l0 = new Label(); final Label l1 = new Label(); final Label l2 = new Label(); methodVisitor.visitTryCatchBlock(l0, l1, l2, "java/lang/Exception"); final Label l3 = new Label(); methodVisitor.visitLabel(l3); /* * declare a local instance of the class in the void() main, store as variable 1. */ methodVisitor.visitTypeInsn(Opcodes.NEW, classname); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, classname, "<init>", "()V"); methodVisitor.visitVarInsn(Opcodes.ASTORE, 1); /* * assign the input stream */ methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "in", "Ljava/io/InputStream;"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "inputStream", "Ljava/io/InputStream;"); /* * assign the output stream */ methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); methodVisitor.visitFieldInsn(Opcodes.PUTFIELD, classname, "outputStream", "Ljava/io/PrintStream;"); /* * load the class instance from variable 1 and call "program" */ methodVisitor.visitLabel(l0); methodVisitor.visitVarInsn(Opcodes.ALOAD, 1); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, classname, "program", "()V"); methodVisitor.visitLabel(l1); final Label l4 = new Label(); methodVisitor.visitJumpInsn(Opcodes.GOTO, l4); methodVisitor.visitLabel(l2); methodVisitor.visitFrame(Opcodes.F_FULL, 2, new Object[] { "[Ljava/lang/String;", classname }, 1, new Object[] { "java/lang/Exception" }); methodVisitor.visitVarInsn(Opcodes.ASTORE, 2); final Label l5 = new Label(); methodVisitor.visitLabel(l5); methodVisitor.visitLineNumber(21, l5); methodVisitor.visitVarInsn(Opcodes.ALOAD, 2); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Exception", "printStackTrace", "()V"); /* * return */ methodVisitor.visitLabel(l4); methodVisitor.visitFrame(Opcodes.F_SAME, 0, null, 0, null); methodVisitor.visitInsn(Opcodes.RETURN); /* * declare the parameters */ final Label l6 = new Label(); methodVisitor.visitLabel(l6); methodVisitor.visitLocalVariable("args", "[Ljava/lang/String;", null, l3, l6, 0); methodVisitor.visitLocalVariable("exampleProgram", "L" + classname + ";", null, l0, l6, 1); methodVisitor.visitLocalVariable("e", "Ljava/lang/Exception;", null, l5, l4, 2); /* * done */ methodVisitor.visitMaxs(2, 3); methodVisitor.visitEnd(); } catch (final Exception e) { throw new Exception("Exception in generateMain", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.JVMBasicCompiler.java
License:Open Source License
/** * Generate program/* w w w.j av a2 s . c om*/ * <p> * Java prototype is "public program()" * </p> */ protected void generateProgram(String classname, ClassWriter classWriter, ProgContext progContext) throws Exception { try { final MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "program", "()V", null, new String[] { "java/lang/Exception" }); methodVisitor.visitCode(); /* * label for the start of the method */ final Label l0 = new Label(); methodVisitor.visitLabel(l0); /* * do the static analysis */ final StaticAnalysis programStaticAnalysis = new StaticAnalysis(); programStaticAnalysis.performStaticAnalysis(progContext); /* * show the static analysis */ logger.info("Static analyis results for '" + classname + "'"); programStaticAnalysis.showAnalysisResults(); /* * recurse into the parse tree */ final Function function = new progRule(); final GenerationContext generationContext = new GenerationContext(classname, methodVisitor, classWriter, progContext, programStaticAnalysis); function.execute(generationContext); /* * return */ final Label l1 = new Label(); methodVisitor.visitLabel(l1); methodVisitor.visitInsn(Opcodes.RETURN); /* * declare the *this* local variable */ final Label l2 = new Label(); methodVisitor.visitLabel(l2); methodVisitor.visitLocalVariable("this", "L" + classname + ";", null, l0, l2, 0); /* * show all the other local variables */ logger.info("JVM local variables"); for (int i = 1; i < (GenerationContext.getLocalvariables().size() + 1); i++) { final LocalVariableDeclaration lvd = GenerationContext.getLocalvariables().get(i); logger.info("variable: " + lvd.getName() + " declared on line: " + lvd.getBasicLine() + " frame index: " + lvd.getIndex()); } /* * we are done */ methodVisitor.visitMaxs(0, 1); methodVisitor.visitEnd(); } catch (final Exception e) { throw new Exception("Exception in generateProgram", e); } }