List of usage examples for org.objectweb.asm Opcodes ACC_STATIC
int ACC_STATIC
To view the source code for org.objectweb.asm Opcodes ACC_STATIC.
Click Source Link
From source file:jp.co.dgic.testing.common.virtualmock.asm2x.AsmClassVisitor2x.java
License:Open Source License
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { boolean isStatic = false; if ((access & Opcodes.ACC_STATIC) > 0) { isStatic = true;/*from w w w. ja va 2 s. c o m*/ } InternalMockObjectManager.printConsole("#################################################################"); InternalMockObjectManager.printConsole("#################################################################"); InternalMockObjectManager .printConsole("### " + access + (isStatic ? " static " : " ") + name + " " + signature); InternalMockObjectManager.printConsole("#################################################################"); InternalMockObjectManager.printConsole("#################################################################"); MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); // is abstract or native if ((access & Opcodes.ACC_ABSTRACT) > 0) return mv; if ((access & Opcodes.ACC_NATIVE) > 0) return mv; if ((access & Opcodes.ACC_BRIDGE) > 0) return mv; int maxLocals = acc.getMaxLocals(name, desc); return createMethodVisitor(mv, name, desc, signature, isStatic, exceptions, maxLocals); }
From source file:jpcsp.Allegrex.compiler.CodeBlock.java
License:Open Source License
private void addNonStaticMethods(CompilerContext context, ClassVisitor cv) { MethodVisitor mv;/*from w ww . j a va 2 s . c om*/ // public int exec(int returnAddress, int alternativeReturnAddress, boolean isJump) throws Exception; mv = cv.visitMethod(Opcodes.ACC_PUBLIC, context.getExecMethodName(), context.getExecMethodDesc(), null, exceptions); mv.visitCode(); mv.visitMethodInsn(Opcodes.INVOKESTATIC, getClassName(), context.getStaticExecMethodName(), context.getStaticExecMethodDesc()); mv.visitInsn(Opcodes.IRETURN); mv.visitMaxs(1, 1); mv.visitEnd(); // private static IExecutable e; FieldVisitor fv = cv.visitField(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, context.getReplaceFieldName(), executableDescriptor, null, null); fv.visitEnd(); // public void setExecutable(IExecutable e); mv = cv.visitMethod(Opcodes.ACC_PUBLIC, context.getReplaceMethodName(), context.getReplaceMethodDesc(), null, exceptions); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 1); mv.visitFieldInsn(Opcodes.PUTSTATIC, getClassName(), context.getReplaceFieldName(), executableDescriptor); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 2); mv.visitEnd(); // public IExecutable getExecutable(); mv = cv.visitMethod(Opcodes.ACC_PUBLIC, context.getGetMethodName(), context.getGetMethodDesc(), null, exceptions); mv.visitCode(); mv.visitFieldInsn(Opcodes.GETSTATIC, getClassName(), context.getReplaceFieldName(), executableDescriptor); mv.visitInsn(Opcodes.ARETURN); mv.visitMaxs(1, 1); mv.visitEnd(); }
From source file:jpcsp.Allegrex.compiler.CodeBlock.java
License:Open Source License
private Class<IExecutable> interpret(CompilerContext context) { Class<IExecutable> compiledClass = null; context.setCodeBlock(this); String className = getInternalClassName(); if (log.isInfoEnabled()) { log.info("Compiling for Interpreter " + className); }/*from w w w .j a v a 2 s . com*/ int computeFlag = ClassWriter.COMPUTE_FRAMES; if (context.isAutomaticMaxLocals() || context.isAutomaticMaxStack()) { computeFlag |= ClassWriter.COMPUTE_MAXS; } ClassWriter cw = new ClassWriter(computeFlag); ClassVisitor cv = cw; if (log.isDebugEnabled()) { cv = new CheckClassAdapter(cv); } StringWriter debugOutput = null; if (log.isDebugEnabled()) { debugOutput = new StringWriter(); PrintWriter debugPrintWriter = new PrintWriter(debugOutput); cv = new TraceClassVisitor(cv, debugPrintWriter); } cv.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, className, null, objectInternalName, interfacesForExecutable); context.startClass(cv); addConstructor(cv); addNonStaticMethods(context, cv); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, context.getStaticExecMethodName(), context.getStaticExecMethodDesc(), null, exceptions); mv.visitCode(); context.setMethodVisitor(mv); context.startMethod(); context.compileExecuteInterpreter(getStartAddress()); mv.visitMaxs(context.getMaxStack(), context.getMaxLocals()); mv.visitEnd(); cv.visitEnd(); if (debugOutput != null) { log.debug(debugOutput.toString()); } compiledClass = loadExecutable(context, className, cw.toByteArray()); return compiledClass; }
From source file:jpcsp.Allegrex.compiler.CodeBlock.java
License:Open Source License
private Class<IExecutable> compile(CompilerContext context) throws ClassFormatError { Class<IExecutable> compiledClass = null; context.setCodeBlock(this); String className = getInternalClassName(); if (log.isDebugEnabled()) { String functionName = Utilities.getFunctionNameByAddress(getStartAddress()); if (functionName != null) { log.debug(String.format("Compiling %s (%s)", className, functionName)); } else {// www.j a v a 2 s. c om log.debug(String.format("Compiling %s", className)); } } prepare(context, context.getMethodMaxInstructions()); currentSequence = null; int computeFlag = ClassWriter.COMPUTE_FRAMES; if (context.isAutomaticMaxLocals() || context.isAutomaticMaxStack()) { computeFlag |= ClassWriter.COMPUTE_MAXS; } ClassWriter cw = new ClassWriter(computeFlag); ClassVisitor cv = cw; if (log.isDebugEnabled()) { cv = new CheckClassAdapter(cv); } StringWriter debugOutput = null; if (log.isTraceEnabled()) { debugOutput = new StringWriter(); PrintWriter debugPrintWriter = new PrintWriter(debugOutput); cv = new TraceClassVisitor(cv, debugPrintWriter); } cv.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, className, null, objectInternalName, interfacesForExecutable); context.startClass(cv); addConstructor(cv); addNonStaticMethods(context, cv); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, context.getStaticExecMethodName(), context.getStaticExecMethodDesc(), null, exceptions); mv.visitCode(); context.setMethodVisitor(mv); context.startMethod(); // Jump to the block start if other instructions have been inserted in front if (!codeInstructions.isEmpty() && codeInstructions.getFirst().getAddress() != getStartAddress()) { mv.visitJumpInsn(Opcodes.GOTO, getCodeInstruction(getStartAddress()).getLabel()); } compile(context, mv, codeInstructions); mv.visitMaxs(context.getMaxStack(), context.getMaxLocals()); mv.visitEnd(); for (SequenceCodeInstruction sequenceCodeInstruction : sequenceCodeInstructions) { if (log.isDebugEnabled()) { log.debug("Compiling Sequence " + sequenceCodeInstruction.getMethodName(context)); } currentSequence = sequenceCodeInstruction; mv = cv.visitMethod(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, sequenceCodeInstruction.getMethodName(context), "()V", null, exceptions); mv.visitCode(); context.setMethodVisitor(mv); context.startSequenceMethod(); compile(context, mv, sequenceCodeInstruction.getCodeSequence().getInstructions()); context.endSequenceMethod(); mv.visitMaxs(context.getMaxStack(), context.getMaxLocals()); mv.visitEnd(); } currentSequence = null; cv.visitEnd(); if (debugOutput != null) { log.trace(debugOutput.toString()); } try { compiledClass = loadExecutable(context, className, cw.toByteArray()); } catch (NullPointerException e) { log.error("Error while compiling " + className + ": " + e); } return compiledClass; }
From source file:lapin.comp.asm.ASMByteCodeGenerator.java
License:Open Source License
private void generateFields(Env env) { Iterator it;//from w w w. jav a 2 s . c om // fields for static subr (singleton) instance _cw.visitField(Opcodes.ACC_STATIC + Opcodes.ACC_VOLATILE, "SELF", toTypeDescriptor(super.classInfo.classname()), null, null).visitEnd(); // fields for constants it = constTable.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); // key: const object String val = Data.string(constTable.get(key)); _cw.visitField(Opcodes.ACC_PRIVATE, val, TYPE_OBJECT.getDescriptor(), null, null).visitEnd(); } // fields for vars it = varTable.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); // key: symbol (var) String val = Data.string(varTable.get(key)); _cw.visitField(Opcodes.ACC_PRIVATE, val, TYPE_SYMBOL.getDescriptor(), null, null).visitEnd(); } // fields for lls it = llTable.keySet().iterator(); while (it.hasNext()) { Object key = it.next(); // key: lambdaList String val = Data.string(llTable.get(key)); _cw.visitField(Opcodes.ACC_PRIVATE, val, TYPE_LAMBDA_LIST.getDescriptor(), null, null).visitEnd(); } }
From source file:lapin.comp.asm.ASMByteCodeGenerator.java
License:Open Source License
private void generateClassInitializer(Env env) { MethodVisitor mv = _cw.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null); // field for SELF (static field) mv.visitCode();//ww w . j a v a 2s . c o m mv.visitInsn(Opcodes.ACONST_NULL); mv.visitFieldInsn(Opcodes.PUTSTATIC, toInternalName(super.classInfo.classname()), "SELF", toTypeDescriptor(super.classInfo.classname())); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(0, 0); mv.visitEnd(); }
From source file:lombok.patcher.MethodLogistics.java
License:Open Source License
/** * Creates a new logistics support class given a method descriptor and the access flags. * //from www . j a v a 2s. c o m * These can be copied verbatim from what ASM gives you. * * @see org.objectweb.asm.ClassVisitor#visitMethod(int, String, String, String, String[]) */ public MethodLogistics(int accessFlags, String descriptor) { this.staticOffset = ((accessFlags & Opcodes.ACC_STATIC) != 0) ? 0 : 1; List<String> specs = MethodTarget.decomposeFullDesc(descriptor); Iterator<String> it = specs.iterator(); String returnSpec = it.next(); returnSize = sizeOf(returnSpec); returnOpcode = returnOpcodeFor(returnSpec); int index = staticOffset; List<Integer> paramSizes = new ArrayList<Integer>(); List<Integer> paramIndices = new ArrayList<Integer>(); List<Integer> loadOpcodes = new ArrayList<Integer>(); while (it.hasNext()) { String spec = it.next(); int size = sizeOf(spec); paramSizes.add(size); paramIndices.add(index); loadOpcodes.add(loadOpcodeFor(spec)); index += size; } this.paramSizes = Collections.unmodifiableList(paramSizes); this.paramIndices = Collections.unmodifiableList(paramIndices); this.loadOpcodes = Collections.unmodifiableList(loadOpcodes); }
From source file:lombok.patcher.scripts.SetSymbolDuringMethodCallScript.java
License:Open Source License
private void makeWrapperMethod(ClassVisitor cv, WrapperMethodDescriptor wmd) { MethodVisitor mv = cv.visitMethod(Opcodes.ACC_SYNTHETIC | Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, wmd.getWrapperName(), wmd.getWrapperDescriptor(), null, null); MethodLogistics logistics = new MethodLogistics(Opcodes.ACC_STATIC, wmd.getWrapperDescriptor()); mv.visitCode();// ww w . j a va 2 s . c o m Label start = new Label(); Label end = new Label(); Label handler = new Label(); mv.visitTryCatchBlock(start, end, handler, null); mv.visitLabel(start); mv.visitLdcInsn(symbol); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "lombok/patcher/Symbols", "push", "(Ljava/lang/String;)V", false); for (int i = 0; i < logistics.getParamCount(); i++) { logistics.generateLoadOpcodeForParam(i, mv); } mv.visitMethodInsn(wmd.getOpcode(), wmd.getOwner(), wmd.getName(), wmd.getTargetDescriptor(), wmd.isItf()); mv.visitLabel(end); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "lombok/patcher/Symbols", "pop", "()V", false); logistics.generateReturnOpcode(mv); mv.visitLabel(handler); mv.visitFrame(Opcodes.F_FULL, 0, null, 1, new Object[] { "java/lang/Throwable" }); mv.visitMethodInsn(Opcodes.INVOKESTATIC, "lombok/patcher/Symbols", "pop", "()V", false); mv.visitInsn(Opcodes.ATHROW); mv.visitMaxs(Math.max(1, logistics.getParamCount()), logistics.getParamCount()); mv.visitEnd(); }
From source file:lucee.transformer.bytecode.util.ASMUtil.java
License:Open Source License
public static byte[] createPojo(String className, ASMProperty[] properties, Class parent, Class[] interfaces, String srcName) throws PageException { className = className.replace('.', '/'); className = className.replace('\\', '/'); className = ListUtil.trim(className, "/"); String[] inter = null;/*ww w . ja v a 2 s .c om*/ if (interfaces != null) { inter = new String[interfaces.length]; for (int i = 0; i < inter.length; i++) { inter[i] = interfaces[i].getName().replace('.', '/'); } } // CREATE CLASS ClassWriter cw = ASMUtil.getClassWriter(); cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC, className, null, parent.getName().replace('.', '/'), inter); String md5; try { md5 = createMD5(properties); } catch (Throwable t) { md5 = ""; t.printStackTrace(); } FieldVisitor fv = cw.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, "_md5_", "Ljava/lang/String;", null, md5); fv.visitEnd(); // Constructor GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_OBJECT, null, null, cw); adapter.loadThis(); adapter.invokeConstructor(toType(parent, true), CONSTRUCTOR_OBJECT); adapter.returnValue(); adapter.endMethod(); // properties for (int i = 0; i < properties.length; i++) { createProperty(cw, className, properties[i]); } // complexType src if (!StringUtil.isEmpty(srcName)) { GeneratorAdapter _adapter = new GeneratorAdapter( Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, _SRC_NAME, null, null, cw); _adapter.push(srcName); _adapter.returnValue(); _adapter.endMethod(); } cw.visitEnd(); return cw.toByteArray(); }
From source file:me.tunsi.test.dynamic.JiteClassTest.java
License:Apache License
@Test public void testFields() throws Exception { JiteClass jiteClass = new JiteClass("testFields", p(Object.class), new String[0]) { {/* www .j av a 2s. c om*/ defineField("foo", ACC_PUBLIC | ACC_STATIC, ci(String.class), "bar"); } }; Class<?> clazz = new DynamicClassLoader().define(jiteClass); Field foo = clazz.getDeclaredField("foo"); assertEquals("foo field was not a string", String.class, foo.getType()); assertEquals("foo field was not set to 'bar'", "bar", foo.get(null)); jiteClass.defineField("foo1", Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, ci(String.class), "Bardd"); clazz = new DynamicClassLoader().define(jiteClass); Field foo2 = clazz.getDeclaredField("foo1"); System.out.println(foo2.get(null)); }