List of usage examples for org.objectweb.asm Opcodes ACONST_NULL
int ACONST_NULL
To view the source code for org.objectweb.asm Opcodes ACONST_NULL.
Click Source Link
From source file:io.syncframework.optimizer.OInterceptorClassVisitor.java
License:Apache License
/** * Generates the code://from ww w .j a v a2s .c om * * public Result _asBefore() { * return before(); * } */ public void createBeforeMethod() { String signature = "()" + Type.getDescriptor(Result.class); MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC, "_asBefore", signature, null, null); Label l0 = new Label(); if (reflector.getAfter() != null) { mv.visitLabel(l0); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, reflector.getClazzInternalName(), "before", signature, false); mv.visitInsn(Opcodes.ARETURN); } else { mv.visitLabel(l0); mv.visitInsn(Opcodes.ACONST_NULL); mv.visitInsn(Opcodes.ARETURN); } Label l1 = new Label(); mv.visitLocalVariable("this", reflector.getClazzDescriptor(), null, l0, l1, 0); mv.visitMaxs(1, 1); mv.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();/*w w w . j a v a 2 s . c om*/ 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
/** * Writes the opcode to load 'this', or, for static methods, 'null'. * //from w w w .j ava 2 s. c o m * @param mv The opcode will be generated in this MethodVisitor object. */ public void generateLoadOpcodeForThis(MethodVisitor mv) { if (isStatic()) mv.visitInsn(Opcodes.ACONST_NULL); else mv.visitVarInsn(Opcodes.ALOAD, 0); }
From source file:lucee.transformer.bytecode.Page.java
License:Open Source License
/** * result byte code as binary array// w ww .j a v a 2 s. com * @param classFile * @return byte code * @throws IOException * @throws TemplateException */ public byte[] execute(PageSource source, Resource classFile) throws BytecodeException { /* // this is done that the Page can be executed more than once if(initFunctions==null) initFunctions=(ArrayList<IFunction>) functions.clone(); else functions=initFunctions; if(initThreads==null) initThreads=(ArrayList<TagThread>) threads.clone(); else threads=initThreads; methodCount=0; off=0; staticTextLocation=null; print.e(this.functions); print.e(this.threads);*/ Resource p = classFile.getParentResource().getRealResource(classFile.getName() + ".txt"); List<LitString> keys = new ArrayList<LitString>(); ClassWriter cw = ASMUtil.getClassWriter(); ArrayList<String> imports = new ArrayList<String>(); getImports(imports, this); // parent String parent = "lucee/runtime/PagePlus"; if (isComponent()) parent = "lucee/runtime/ComponentPage"; else if (isInterface()) parent = "lucee/runtime/InterfacePage"; cw.visit(Opcodes.V1_6, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, name, null, parent, null); cw.visitSource(this.pageSource.getPhyscalFile().getAbsolutePath(), "rel:" + this.pageSource.getFullRealpath()); // when adding more use ; as delimiter // // static constructor //GeneratorAdapter statConstrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC,STATIC_CONSTRUCTOR,null,null,cw); BytecodeContext statConstr = null;//new BytecodeContext(null,null,this,externalizer,keys,cw,name,statConstrAdapter,STATIC_CONSTRUCTOR,writeLog(),suppressWSbeforeArg); // constructor GeneratorAdapter constrAdapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC, CONSTRUCTOR_PS, null, null, cw); BytecodeContext constr = new BytecodeContext(source, null, null, this, keys, cw, name, constrAdapter, CONSTRUCTOR_PS, writeLog(), suppressWSbeforeArg, output); constrAdapter.loadThis(); Type t = Types.PAGE_PLUS; if (isComponent()) t = Types.COMPONENT_PAGE; else if (isInterface()) t = Types.INTERFACE_PAGE; constrAdapter.invokeConstructor(t, CONSTRUCTOR); // call _init() constrAdapter.visitVarInsn(Opcodes.ALOAD, 0); constrAdapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, constr.getClassName(), "initKeys", "()V"); // private static ImportDefintion[] test=new ImportDefintion[]{...}; { FieldVisitor fv = cw.visitField(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, "imports", "[Llucee/runtime/component/ImportDefintion;", null, null); fv.visitEnd(); constrAdapter.visitVarInsn(Opcodes.ALOAD, 0); ArrayVisitor av = new ArrayVisitor(); av.visitBegin(constrAdapter, Types.IMPORT_DEFINITIONS, imports.size()); int index = 0; Iterator<String> it = imports.iterator(); while (it.hasNext()) { av.visitBeginItem(constrAdapter, index++); constrAdapter.push(it.next()); ASMConstants.NULL(constrAdapter); constrAdapter.invokeStatic(Types.IMPORT_DEFINITIONS_IMPL, ID_GET_INSTANCE); av.visitEndItem(constrAdapter); } av.visitEnd(); constrAdapter.visitFieldInsn(Opcodes.PUTFIELD, name, "imports", "[Llucee/runtime/component/ImportDefintion;"); } // getVersion GeneratorAdapter adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, VERSION, null, null, cw); adapter.push(version); adapter.returnValue(); adapter.endMethod(); // public ImportDefintion[] getImportDefintions() if (imports.size() > 0) { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.visitFieldInsn(Opcodes.GETFIELD, name, "imports", "[Llucee/runtime/component/ImportDefintion;"); adapter.returnValue(); adapter.endMethod(); } else { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, GET_IMPORT_DEFINITIONS, null, null, cw); adapter.visitInsn(Opcodes.ICONST_0); adapter.visitTypeInsn(Opcodes.ANEWARRAY, "lucee/runtime/component/ImportDefintion"); adapter.returnValue(); adapter.endMethod(); } // getSourceLastModified adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, LAST_MOD, null, null, cw); adapter.push(lastModifed); adapter.returnValue(); adapter.endMethod(); // getCompileTime adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, COMPILE_TIME, null, null, cw); adapter.push(System.currentTimeMillis()); adapter.returnValue(); adapter.endMethod(); // newInstance/initComponent/call if (isComponent()) { Tag component = getComponent(); writeOutNewComponent(statConstr, constr, keys, cw, component); writeOutInitComponent(statConstr, constr, keys, cw, component); } else if (isInterface()) { Tag interf = getInterface(); writeOutNewInterface(statConstr, constr, keys, cw, interf); writeOutInitInterface(statConstr, constr, keys, cw, interf); } else { writeOutCall(statConstr, constr, keys, cw); } // udfCall Function[] functions = getFunctions(); ConditionVisitor cv; DecisionIntVisitor div; // less/equal than 10 functions if (isInterface()) { } else if (functions.length <= 10) { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_CALL, null, new Type[] { Types.THROWABLE }, cw); BytecodeContext bc = new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, UDF_CALL, writeLog(), suppressWSbeforeArg, output); if (functions.length == 0) { } else if (functions.length == 1) { ExpressionUtil.visitLine(bc, functions[0].getStart()); functions[0].getBody().writeOut(bc); ExpressionUtil.visitLine(bc, functions[0].getEnd()); } else writeOutUdfCallInner(bc, functions, 0, functions.length); adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); } // more than 10 functions else { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_CALL, null, new Type[] { Types.THROWABLE }, cw); BytecodeContext bc = new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, UDF_CALL, writeLog(), suppressWSbeforeArg, output); cv = new ConditionVisitor(); cv.visitBefore(); int count = 0; for (int i = 0; i < functions.length; i += 10) { cv.visitWhenBeforeExpr(); div = new DecisionIntVisitor(); div.visitBegin(); adapter.loadArg(2); div.visitLT(); adapter.push(i + 10); div.visitEnd(bc); cv.visitWhenAfterExprBeforeBody(bc); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.visitVarInsn(Opcodes.ALOAD, 1); adapter.visitVarInsn(Opcodes.ALOAD, 2); adapter.visitVarInsn(Opcodes.ILOAD, 3); adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, createFunctionName(++count), "(Llucee/runtime/PageContext;Llucee/runtime/type/UDF;I)Ljava/lang/Object;"); adapter.visitInsn(Opcodes.ARETURN);//adapter.returnValue(); cv.visitWhenAfterBody(bc); } cv.visitAfter(bc); adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); count = 0; Method innerCall; for (int i = 0; i < functions.length; i += 10) { innerCall = new Method(createFunctionName(++count), Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, USER_DEFINED_FUNCTION, Types.INT_VALUE }); adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, innerCall, null, new Type[] { Types.THROWABLE }, cw); writeOutUdfCallInner( new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, innerCall, writeLog(), suppressWSbeforeArg, output), functions, i, i + 10 > functions.length ? functions.length : i + 10); adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); } } // threadCall TagThread[] threads = getThreads(); if (true) { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, THREAD_CALL, null, new Type[] { Types.THROWABLE }, cw); if (threads.length > 0) writeOutThreadCallInner(new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, THREAD_CALL, writeLog(), suppressWSbeforeArg, output), threads, 0, threads.length); //adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); } // udfDefaultValue // less/equal than 10 functions if (isInterface()) { } else if (functions.length <= 10) { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_DEFAULT_VALUE, null, new Type[] { Types.PAGE_EXCEPTION }, cw); if (functions.length > 0) writeUdfDefaultValueInner( new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, UDF_DEFAULT_VALUE, writeLog(), suppressWSbeforeArg, output), functions, 0, functions.length); adapter.loadArg(DEFAULT_VALUE); adapter.returnValue(); adapter.endMethod(); } else { adapter = new GeneratorAdapter(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, UDF_DEFAULT_VALUE, null, new Type[] { Types.PAGE_EXCEPTION }, cw); BytecodeContext bc = new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, UDF_DEFAULT_VALUE, writeLog(), suppressWSbeforeArg, output); cv = new ConditionVisitor(); cv.visitBefore(); int count = 0; for (int i = 0; i < functions.length; i += 10) { cv.visitWhenBeforeExpr(); div = new DecisionIntVisitor(); div.visitBegin(); adapter.loadArg(1); div.visitLT(); adapter.push(i + 10); div.visitEnd(bc); cv.visitWhenAfterExprBeforeBody(bc); adapter.visitVarInsn(Opcodes.ALOAD, 0); adapter.visitVarInsn(Opcodes.ALOAD, 1); adapter.visitVarInsn(Opcodes.ILOAD, 2); adapter.visitVarInsn(Opcodes.ILOAD, 3); adapter.visitVarInsn(Opcodes.ALOAD, 4); adapter.visitMethodInsn(Opcodes.INVOKEVIRTUAL, name, "udfDefaultValue" + (++count), "(Llucee/runtime/PageContext;IILjava/lang/Object;)Ljava/lang/Object;"); adapter.visitInsn(Opcodes.ARETURN);//adapter.returnValue(); cv.visitWhenAfterBody(bc); } cv.visitAfter(bc); adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); count = 0; Method innerDefaultValue; for (int i = 0; i < functions.length; i += 10) { innerDefaultValue = new Method("udfDefaultValue" + (++count), Types.OBJECT, new Type[] { Types.PAGE_CONTEXT, Types.INT_VALUE, Types.INT_VALUE, Types.OBJECT }); adapter = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, innerDefaultValue, null, new Type[] { Types.PAGE_EXCEPTION }, cw); writeUdfDefaultValueInner( new BytecodeContext(source, statConstr, constr, this, keys, cw, name, adapter, innerDefaultValue, writeLog(), suppressWSbeforeArg, output), functions, i, i + 10 > functions.length ? functions.length : i + 10); adapter.loadArg(DEFAULT_VALUE); //adapter.visitInsn(Opcodes.ACONST_NULL); adapter.returnValue(); adapter.endMethod(); } } // register fields { GeneratorAdapter aInit = new GeneratorAdapter(Opcodes.ACC_PRIVATE + Opcodes.ACC_FINAL, _INIT, null, null, cw); BytecodeContext bcInit = new BytecodeContext(source, statConstr, constr, this, keys, cw, name, aInit, _INIT, writeLog(), suppressWSbeforeArg, output); registerFields(bcInit, keys); aInit.returnValue(); aInit.endMethod(); } //setPageSource(pageSource); constrAdapter.visitVarInsn(Opcodes.ALOAD, 0); constrAdapter.visitVarInsn(Opcodes.ALOAD, 1); constrAdapter.invokeVirtual(t, SET_PAGE_SOURCE); constrAdapter.returnValue(); constrAdapter.endMethod(); return cw.toByteArray(); }
From source file:lucee.transformer.bytecode.statement.tag.TagHelper.java
License:Open Source License
private static void setAttributes(BytecodeContext bc, Tag tag, int currLocal, Type currType, boolean doDefault) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); Map<String, Attribute> attributes = tag.getAttributes(); String methodName;//from w w w . ja va 2 s .com Attribute attr; Iterator<Attribute> it = attributes.values().iterator(); while (it.hasNext()) { attr = it.next(); if (doDefault != attr.isDefaultAttribute()) continue; if (attr.isDynamicType()) { adapter.loadLocal(currLocal); adapter.visitInsn(Opcodes.ACONST_NULL); //adapter.push(attr.getName()); Variable.registerKey(bc, LitString.toExprString(attr.getName())); attr.getValue().writeOut(bc, Expression.MODE_REF); adapter.invokeVirtual(currType, SET_DYNAMIC_ATTRIBUTE); } else { Type type = CastOther.getType(attr.getType()); methodName = tag.getTagLibTag().getSetter(attr, type); adapter.loadLocal(currLocal); attr.getValue().writeOut(bc, Types.isPrimitiveType(type) ? Expression.MODE_VALUE : Expression.MODE_REF); adapter.invokeVirtual(currType, new Method(methodName, Type.VOID_TYPE, new Type[] { type })); } } }
From source file:lucee.transformer.bytecode.statement.tag.TagLoop.java
License:Open Source License
/** * write out file loop/* www .j ava2s. c o m*/ * @param adapter * @throws TemplateException */ private void writeOutTypeFile(BytecodeContext bc) throws BytecodeException { WhileVisitor whileVisitor = new WhileVisitor(); loopVisitor = whileVisitor; GeneratorAdapter adapter = bc.getAdapter(); // charset=@charset int charset = adapter.newLocal(Types.STRING); Attribute attrCharset = getAttribute("charset"); if (attrCharset == null) adapter.visitInsn(Opcodes.ACONST_NULL); else attrCharset.getValue().writeOut(bc, Expression.MODE_REF); adapter.storeLocal(charset); // startline=@startline int startline = adapter.newLocal(Types.INT_VALUE); Attribute attrStartLine = getAttribute("startline"); if (attrStartLine == null) attrStartLine = getAttribute("from"); // CF8 if (attrStartLine == null) adapter.push(1); else { attrStartLine.getValue().writeOut(bc, Expression.MODE_VALUE); adapter.visitInsn(Opcodes.D2I); } adapter.storeLocal(startline); // endline=@endline int endline = adapter.newLocal(Types.INT_VALUE); Attribute attrEndLine = getAttribute("endline"); if (attrEndLine == null) attrEndLine = getAttribute("to"); if (attrEndLine == null) adapter.push(-1); else { attrEndLine.getValue().writeOut(bc, Expression.MODE_VALUE); adapter.visitInsn(Opcodes.D2I); } adapter.storeLocal(endline); //VariableReference index=VariableInterpreter.getVariableReference(pc,@index); int index = -1, item = -1; // item Attribute attrItem = getAttribute("item"); if (attrItem != null) { item = adapter.newLocal(Types.VARIABLE_REFERENCE); adapter.loadArg(0); attrItem.getValue().writeOut(bc, Expression.MODE_REF); adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE); adapter.storeLocal(item); } // index Attribute attrIndex = getAttribute("index"); if (attrIndex != null) { index = adapter.newLocal(Types.VARIABLE_REFERENCE); adapter.loadArg(0); attrIndex.getValue().writeOut(bc, Expression.MODE_REF); adapter.invokeStatic(Types.VARIABLE_INTERPRETER, GET_VARIABLE_REFERENCE); adapter.storeLocal(index); } //java.io.File file=FileUtil.toResourceExisting(pc,@file); int resource = adapter.newLocal(Types.RESOURCE); adapter.loadArg(0); getAttribute("file").getValue().writeOut(bc, Expression.MODE_REF); adapter.invokeStatic(RESOURCE_UTIL, TO_RESOURCE_EXISTING); adapter.storeLocal(resource); // pc.getConfig().getSecurityManager().checkFileLocation(resource); adapter.loadArg(0); adapter.invokeVirtual(Types.PAGE_CONTEXT, GET_CONFIG); adapter.invokeInterface(Types.CONFIG_WEB, GET_SECURITY_MANAGER); adapter.loadLocal(resource); adapter.invokeInterface(Types.SECURITY_MANAGER, CHECK_FILE_LOCATION); // char[] carr=new char[characters]; Attribute attr = getAttribute("characters"); int carr = -1; if (attr != null) { carr = adapter.newLocal(Types.CHAR_ARRAY); attr.getValue().writeOut(bc, Expression.MODE_VALUE); adapter.cast(Types.DOUBLE_VALUE, Types.INT_VALUE); adapter.newArray(Types.CHAR); adapter.storeLocal(carr); } // BufferedReader reader = IOUtil.getBufferedReader(resource,charset); final int br = adapter.newLocal(Types.BUFFERED_READER); adapter.loadLocal(resource); adapter.loadLocal(charset); adapter.invokeStatic(IO_UTIL, GET_BUFFERED_READER); adapter.storeLocal(br); // String line; int line = adapter.newLocal(Types.STRING); // int count=0; int count = adapter.newLocal(Types.INT_VALUE); adapter.push(0); adapter.storeLocal(count); TryFinallyVisitor tfv = new TryFinallyVisitor(new OnFinally() { public void _writeOut(BytecodeContext bc) { bc.getAdapter().loadLocal(br); bc.getAdapter().invokeStatic(IO_UTIL, CLOSE_EL); } }, null); //TryFinallyVisitor tcfv=new TryFinallyVisitor(); // try tfv.visitTryBegin(bc); //tcfv.visitTryBegin(bc); // while((line=br.readLine())!=null) { //WhileVisitor wv=new WhileVisitor(); whileVisitor.visitBeforeExpression(bc); DecisionObjectVisitor dv = new DecisionObjectVisitor(); dv.visitBegin(); if (attr != null) { // IOUtil.read(bufferedreader,12) adapter.loadLocal(br); adapter.loadLocal(carr); adapter.arrayLength(); adapter.invokeStatic(Types.IOUTIL, READ); } else { // br.readLine() adapter.loadLocal(br); adapter.invokeVirtual(Types.BUFFERED_READER, READ_LINE); } adapter.dup(); adapter.storeLocal(line); dv.visitNEQ(); adapter.visitInsn(Opcodes.ACONST_NULL); dv.visitEnd(bc); whileVisitor.visitAfterExpressionBeforeBody(bc); //if(++count < startLine) continue; DecisionIntVisitor dv2 = new DecisionIntVisitor(); dv2.visitBegin(); adapter.iinc(count, 1); adapter.loadLocal(count); dv2.visitLT(); adapter.loadLocal(startline); dv2.visitEnd(bc); Label end = new Label(); adapter.ifZCmp(Opcodes.IFEQ, end); whileVisitor.visitContinue(bc); adapter.visitLabel(end); // if(endLine!=-1 && count > endLine) break; DecisionIntVisitor div = new DecisionIntVisitor(); div.visitBegin(); adapter.loadLocal(endline); div.visitNEQ(); adapter.push(-1); div.visitEnd(bc); Label end2 = new Label(); adapter.ifZCmp(Opcodes.IFEQ, end2); DecisionIntVisitor div2 = new DecisionIntVisitor(); div2.visitBegin(); adapter.loadLocal(count); div2.visitGT(); adapter.loadLocal(endline); div2.visitEnd(bc); Label end3 = new Label(); adapter.ifZCmp(Opcodes.IFEQ, end3); whileVisitor.visitBreak(bc); adapter.visitLabel(end3); adapter.visitLabel(end2); // index and item if (index != -1 && item != -1) { // index.set(pc,line); adapter.loadLocal(index); adapter.loadArg(0); adapter.loadLocal(count); adapter.cast(Types.INT_VALUE, Types.DOUBLE_VALUE); adapter.invokeStatic(Types.CASTER, Methods.METHOD_TO_DOUBLE_FROM_DOUBLE); adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET); adapter.pop(); // item.set(pc,line); adapter.loadLocal(item); adapter.loadArg(0); adapter.loadLocal(line); adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET); adapter.pop(); } // only index else if (index != -1) { // index.set(pc,line); adapter.loadLocal(index); adapter.loadArg(0); adapter.loadLocal(line); adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET); adapter.pop(); } // only item else { // item.set(pc,line); adapter.loadLocal(item); adapter.loadArg(0); adapter.loadLocal(line); adapter.invokeVirtual(Types.VARIABLE_REFERENCE, SET); adapter.pop(); } getBody().writeOut(bc); whileVisitor.visitAfterBody(bc, getEnd()); tfv.visitTryEnd(bc); }
From source file:lucee.transformer.bytecode.statement.tag.TagParam.java
License:Open Source License
/** * * @see lucee.transformer.bytecode.statement.tag.TagBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter) *//* w w w . j ava2 s.c o m*/ public void _writeOut(BytecodeContext bc) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); //PageContextImpl pc=null; //pc.param("", "", ""); Argument.checkDefaultValue(this); // pc adapter.loadArg(0); // type Attribute attrType = getAttribute("type"); if (attrType != null) { attrType.getValue().writeOut(bc, Expression.MODE_REF); } else adapter.push("any"); // name getAttribute("name").getValue().writeOut(bc, Expression.MODE_REF); // default Attribute attrDefault = getAttribute("default"); if (attrDefault != null) { attrDefault.getValue().writeOut(bc, Expression.MODE_REF); } else adapter.visitInsn(Opcodes.ACONST_NULL); Attribute attrMin = getAttribute("min"); Attribute attrMax = getAttribute("max"); Attribute attrPattern = getAttribute("pattern"); Attribute maxLength = getAttribute("maxLength"); if (attrMin != null || attrMax != null) { // min if (attrMin != null) attrMin.getValue().writeOut(bc, Expression.MODE_VALUE); else { adapter.visitLdcInsn(new Double("NaN")); } // max if (attrMax != null) attrMax.getValue().writeOut(bc, Expression.MODE_VALUE); else { adapter.visitLdcInsn(new Double("NaN")); } adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE_MIN_MAX); } else if (attrPattern != null) { attrPattern.getValue().writeOut(bc, Expression.MODE_REF); adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE_REGEX); } else if (maxLength != null) { CastInt.toExprInt(maxLength.getValue()).writeOut(bc, Expression.MODE_VALUE); adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE_MAXLENGTH); } else adapter.invokeVirtual(Types.PAGE_CONTEXT, PARAM_TYPE_NAME_DEFAULTVALUE); }
From source file:lucee.transformer.bytecode.statement.TryCatchFinally.java
License:Open Source License
/** * * @see lucee.transformer.bytecode.statement.StatementBase#_writeOut(org.objectweb.asm.commons.GeneratorAdapter) *///from w ww . j a va2s .c o m public void _writeOut(BytecodeContext bc) throws BytecodeException { GeneratorAdapter adapter = bc.getAdapter(); adapter.visitLabel(begin); // Reference ref=null; final int lRef = adapter.newLocal(Types.REFERENCE); adapter.visitInsn(Opcodes.ACONST_NULL); adapter.storeLocal(lRef); // has no try body, if there is no try body, no catches are executed, only finally if (!tryBody.hasStatements()) { if (finallyBody != null) finallyBody.writeOut(bc); return; } TryCatchFinallyVisitor tcfv = new TryCatchFinallyVisitor(new OnFinally() { public void _writeOut(BytecodeContext bc) throws BytecodeException { _writeOutFinally(bc, lRef); } }, getFlowControlFinal()); // try tcfv.visitTryBegin(bc); tryBody.writeOut(bc); int lThrow = tcfv.visitTryEndCatchBeging(bc); _writeOutCatch(bc, lRef, lThrow); tcfv.visitCatchEnd(bc); }
From source file:lucee.transformer.bytecode.util.ASMConstants.java
License:Open Source License
public static void NULL(GeneratorAdapter ga) { ga.visitInsn(Opcodes.ACONST_NULL); }
From source file:net.minecraftforge.fml.common.asm.transformers.SoundEngineFixTransformer.java
License:Open Source License
@Override public byte[] transform(String name, String transformedName, byte[] basicClass) { if (transformedName.equals("paulscode.sound.Source")) { ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode, 0); classNode.fields.add(new FieldNode(Opcodes.ACC_PUBLIC, "removed", "Z", null, null)); // adding field 'public boolean removed;' ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer);// w w w . j av a2 s . com return writer.toByteArray(); } else if (transformedName.equals("paulscode.sound.Library")) { ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode, 0); MethodNode method = null; for (MethodNode m : classNode.methods) { if (m.name.equals("removeSource") && m.desc.equals("(Ljava/lang/String;)V")) // trying to find paulscode.sound.Library.removeSource(String) { method = m; break; } } if (method == null) throw new RuntimeException( "Error processing " + transformedName + " - no removeSource method found"); AbstractInsnNode referenceNode = null; for (Iterator<AbstractInsnNode> iterator = method.instructions.iterator(); iterator.hasNext();) { AbstractInsnNode insn = iterator.next(); if (insn instanceof MethodInsnNode && ((MethodInsnNode) insn).owner.equals("paulscode/sound/Source") // searching for mySource.cleanup() node (line 1086) && ((MethodInsnNode) insn).name.equals("cleanup")) { referenceNode = insn; break; } } if (referenceNode != null) { LabelNode after = (LabelNode) referenceNode.getNext(); AbstractInsnNode beginning = referenceNode.getPrevious(); int varIndex = ((VarInsnNode) beginning).var; method.instructions.insertBefore(beginning, new VarInsnNode(Opcodes.ALOAD, varIndex)); // adding extra if (mySource.toStream) method.instructions.insertBefore(beginning, new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/Source", "toStream", "Z")); LabelNode elseNode = new LabelNode(); method.instructions.insertBefore(beginning, new JumpInsnNode(Opcodes.IFEQ, elseNode)); // if fails (else) -> go to mySource.cleanup(); method.instructions.insertBefore(beginning, new VarInsnNode(Opcodes.ALOAD, varIndex)); // if (mySource.toStream) { mySource.removed = true; } method.instructions.insertBefore(beginning, new InsnNode(Opcodes.ICONST_1)); method.instructions.insertBefore(beginning, new FieldInsnNode(Opcodes.PUTFIELD, "paulscode/sound/Source", "removed", "Z")); method.instructions.insertBefore(beginning, new JumpInsnNode(Opcodes.GOTO, after)); // still inside if -> jump to sourceMap.remove( sourcename ); method.instructions.insertBefore(beginning, elseNode); } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); } else if (transformedName.equals("paulscode.sound.StreamThread")) { ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode, 0); MethodNode method = null; for (MethodNode m : classNode.methods) { if (m.name.equals("run") && m.desc.equals("()V")) // trying to find paulscode.sound.StreamThread.run(); { method = m; break; } } if (method == null) throw new RuntimeException("Error processing " + transformedName + " - no run method found"); AbstractInsnNode referenceNode = null; for (Iterator<AbstractInsnNode> iterator = method.instructions.iterator(); iterator.hasNext();) { AbstractInsnNode insn = iterator.next(); if (insn instanceof MethodInsnNode && ((MethodInsnNode) insn).owner.equals("java/util/ListIterator") // searching for 'src = iter.next();' node (line 110) && ((MethodInsnNode) insn).name.equals("next")) { referenceNode = insn.getNext().getNext(); break; } } if (referenceNode != null) { int varIndex = ((VarInsnNode) referenceNode).var; LabelNode after = (LabelNode) referenceNode.getNext(); method.instructions.insertBefore(after, new VarInsnNode(Opcodes.ALOAD, varIndex)); // add if(removed) method.instructions.insertBefore(after, new FieldInsnNode(Opcodes.GETFIELD, "paulscode/sound/Source", "removed", "Z")); method.instructions.insertBefore(after, new JumpInsnNode(Opcodes.IFEQ, after)); // if the source has been marked as removed, clean it up and set the variable to null so it will be removed from the list method.instructions.insertBefore(after, new VarInsnNode(Opcodes.ALOAD, varIndex)); // src.cleanup(); method.instructions.insertBefore(after, new MethodInsnNode(Opcodes.INVOKEVIRTUAL, "paulscode/sound/Source", "cleanup", "()V", false)); method.instructions.insertBefore(after, new InsnNode(Opcodes.ACONST_NULL)); // src = null; method.instructions.insertBefore(after, new VarInsnNode(Opcodes.ASTORE, varIndex)); } ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(writer); return writer.toByteArray(); } return basicClass; }