List of usage examples for org.objectweb.asm MethodVisitor visitIntInsn
public void visitIntInsn(final int opcode, final int operand)
From source file:org.teavm.flavour.regex.bytecode.MatcherClassBuilder.java
License:Apache License
private void generateTransition(MethodVisitor mv, DfaState source, DfaState target) { if (source.isTerminal() && source != target) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitInsn(Opcodes.ICONST_M1); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "domain", "I"); }// w w w. ja va 2 s . c om mv.visitIntInsn(Opcodes.SIPUSH, target.getIndex()); mv.visitVarInsn(Opcodes.ISTORE, 5); if (target.isTerminal() && source != target) { mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitIntInsn(Opcodes.SIPUSH, target.getDomains()[0]); mv.visitFieldInsn(Opcodes.PUTFIELD, className, "domain", "I"); } debug(mv, "DFA: " + source.getIndex() + " -> " + target.getIndex() + " " + Arrays.toString(target.getDomains())); if (target.isTerminal()) { Label noReluctant = new Label(); mv.visitVarInsn(Opcodes.ILOAD, 4); mv.visitJumpInsn(Opcodes.IFEQ, noReluctant); mv.visitIincInsn(2, 1); debug(mv, "DFA reached terminal state"); mv.visitJumpInsn(Opcodes.GOTO, saveLabel); mv.visitLabel(noReluctant); } if (source.getIndex() + 1 == target.getIndex()) { mv.visitIincInsn(2, 1); generateLengthGuard(mv); mv.visitJumpInsn(Opcodes.GOTO, stateLabels[target.getIndex()]); } else { mv.visitJumpInsn(Opcodes.GOTO, continueLabel); } }
From source file:org.teiid.jboss.rest.RestASMBasedWebArchiveBuilder.java
License:Open Source License
private void buildRestService(String vdbName, int vdbVersion, String modelName, Procedure procedure, String method, String uri, ClassWriter cw, String contentType, String charSet, boolean passthroughAuth) { List<ProcedureParameter> params = new ArrayList<ProcedureParameter>(procedure.getParameters().size()); boolean usingReturn = false; boolean hasLobInput = false; for (ProcedureParameter p : procedure.getParameters()) { if (p.getType() == Type.In || p.getType() == Type.InOut) { params.add(p);/*from w ww . ja v a 2 s.c o m*/ } else if (p.getType() == Type.ReturnValue && procedure.getResultSet() == null) { usingReturn = true; } if (!hasLobInput) { String runtimeType = p.getRuntimeType(); hasLobInput = DataTypeManager.isLOB(runtimeType); } } int paramsSize = params.size(); MethodVisitor mv; boolean useMultipart = false; if (method.toUpperCase().equals("POST") && hasLobInput) { useMultipart = true; } AnnotationVisitor av0; { StringBuilder paramSignature = new StringBuilder(); paramSignature.append("("); for (int i = 0; i < paramsSize; i++) { paramSignature.append("Ljava/lang/String;"); } paramSignature.append(")"); if (useMultipart) { mv = cw.visitMethod(ACC_PUBLIC, procedure.getName() + contentType.replace('/', '_'), "(Lorg/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInput;)Ljavax/ws/rs/core/StreamingOutput;", null, new String[] { "javax/ws/rs/WebApplicationException" }); } else { mv = cw.visitMethod(ACC_PUBLIC, procedure.getName() + contentType.replace('/', '_'), paramSignature + "Ljavax/ws/rs/core/StreamingOutput;", null, new String[] { "javax/ws/rs/WebApplicationException" }); } { av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, contentType); av1.visitEnd(); } av0.visitEnd(); } { av0 = mv.visitAnnotation("Ljavax/ws/rs/" + method.toUpperCase() + ";", true); av0.visitEnd(); } { av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", uri); av0.visitEnd(); } { av0 = mv.visitAnnotation("Ljavax/annotation/security/PermitAll;", true); av0.visitEnd(); } if (useMultipart) { av0 = mv.visitAnnotation("Ljavax/ws/rs/Consumes;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, "multipart/form-data"); av1.visitEnd(); } av0.visitEnd(); } if (!useMultipart) { // post only accepts Form inputs, not path params HashSet<String> pathParms = getPathParameters(uri); for (int i = 0; i < paramsSize; i++) { String paramType = "Ljavax/ws/rs/FormParam;"; if (method.toUpperCase().equals("GET")) { paramType = "Ljavax/ws/rs/QueryParam;"; } if (pathParms.contains(params.get(i).getName())) { paramType = "Ljavax/ws/rs/PathParam;"; } av0 = mv.visitParameterAnnotation(i, paramType, true); av0.visit("value", params.get(i).getName()); av0.visitEnd(); } } mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/sql/SQLException"); mv.visitLabel(l0); if (!useMultipart) { mv.visitTypeInsn(NEW, "java/util/LinkedHashMap"); mv.visitInsn(DUP); mv.visitMethodInsn(INVOKESPECIAL, "java/util/LinkedHashMap", "<init>", "()V"); mv.visitVarInsn(ASTORE, paramsSize + 1); for (int i = 0; i < paramsSize; i++) { mv.visitVarInsn(ALOAD, paramsSize + 1); mv.visitLdcInsn(params.get(i).getName()); mv.visitVarInsn(ALOAD, i + 1); mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"); mv.visitInsn(POP); } mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(vdbName); mv.visitIntInsn(BIPUSH, vdbVersion); mv.visitLdcInsn(procedure.getSQLString()); mv.visitVarInsn(ALOAD, paramsSize + 1); mv.visitLdcInsn(charSet == null ? "" : charSet); mv.visitInsn(passthroughAuth ? ICONST_1 : ICONST_0); mv.visitInsn(usingReturn ? ICONST_1 : ICONST_0); mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/" + modelName, "execute", "(Ljava/lang/String;ILjava/lang/String;Ljava/util/LinkedHashMap;Ljava/lang/String;ZZ)Ljavax/ws/rs/core/StreamingOutput;"); mv.visitLabel(l1); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(F_SAME1, 0, null, 1, new Object[] { "java/sql/SQLException" }); mv.visitVarInsn(ASTORE, paramsSize + 1); mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, paramsSize + 1); mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;"); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V"); mv.visitInsn(ATHROW); mv.visitMaxs(7, paramsSize + 2); mv.visitEnd(); } else { mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(vdbName); mv.visitIntInsn(BIPUSH, vdbVersion); mv.visitLdcInsn(procedure.getSQLString()); mv.visitVarInsn(ALOAD, 1); mv.visitLdcInsn(charSet == null ? "" : charSet); mv.visitInsn(passthroughAuth ? ICONST_1 : ICONST_0); mv.visitInsn(usingReturn ? ICONST_1 : ICONST_0); mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/" + modelName, "executePost", "(Ljava/lang/String;ILjava/lang/String;Lorg/jboss/resteasy/plugins/providers/multipart/MultipartFormDataInput;Ljava/lang/String;ZZ)Ljavax/ws/rs/core/StreamingOutput;"); mv.visitLabel(l1); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(Opcodes.F_SAME1, 0, null, 1, new Object[] { "java/sql/SQLException" }); mv.visitVarInsn(ASTORE, 2); mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 2); mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;"); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V"); mv.visitInsn(ATHROW); mv.visitMaxs(8, 3); mv.visitEnd(); } } }
From source file:org.teiid.jboss.rest.RestASMBasedWebArchiveBuilder.java
License:Open Source License
private void buildQueryProcedure(String vdbName, int vdbVersion, String modelName, String context, ClassWriter cw, boolean passthroughAuth) { MethodVisitor mv; {// w ww . j av a2s . c o m AnnotationVisitor av0; mv = cw.visitMethod(ACC_PUBLIC, "sqlQuery" + context, "(Ljava/lang/String;)Ljavax/ws/rs/core/StreamingOutput;", null, null); { av0 = mv.visitAnnotation("Ljavax/ws/rs/Produces;", true); { AnnotationVisitor av1 = av0.visitArray("value"); av1.visit(null, "application/" + context); av1.visitEnd(); } av0.visitEnd(); } { av0 = mv.visitAnnotation("Ljavax/ws/rs/POST;", true); av0.visitEnd(); } { av0 = mv.visitAnnotation("Ljavax/ws/rs/Path;", true); av0.visit("value", "/query"); av0.visitEnd(); } { av0 = mv.visitParameterAnnotation(0, "Ljavax/ws/rs/FormParam;", true); av0.visit("value", "sql"); av0.visitEnd(); } mv.visitCode(); Label l0 = new Label(); Label l1 = new Label(); Label l2 = new Label(); mv.visitTryCatchBlock(l0, l1, l2, "java/sql/SQLException"); mv.visitLabel(l0); mv.visitVarInsn(ALOAD, 0); mv.visitLdcInsn(vdbName); mv.visitIntInsn(BIPUSH, vdbVersion); mv.visitVarInsn(ALOAD, 1); mv.visitInsn(context.equals("xml") ? ICONST_0 : ICONST_1); mv.visitInsn(passthroughAuth ? ICONST_1 : ICONST_0); mv.visitMethodInsn(INVOKEVIRTUAL, "org/teiid/jboss/rest/" + modelName, "executeQuery", "(Ljava/lang/String;ILjava/lang/String;ZZ)Ljavax/ws/rs/core/StreamingOutput;"); mv.visitLabel(l1); mv.visitInsn(ARETURN); mv.visitLabel(l2); mv.visitFrame(F_SAME1, 0, null, 1, new Object[] { "java/sql/SQLException" }); mv.visitVarInsn(ASTORE, 2); mv.visitTypeInsn(NEW, "javax/ws/rs/WebApplicationException"); mv.visitInsn(DUP); mv.visitVarInsn(ALOAD, 2); mv.visitFieldInsn(GETSTATIC, "javax/ws/rs/core/Response$Status", "INTERNAL_SERVER_ERROR", "Ljavax/ws/rs/core/Response$Status;"); mv.visitMethodInsn(INVOKESPECIAL, "javax/ws/rs/WebApplicationException", "<init>", "(Ljava/lang/Throwable;Ljavax/ws/rs/core/Response$Status;)V"); mv.visitInsn(ATHROW); mv.visitMaxs(6, 3); mv.visitEnd(); } }
From source file:org.truelicense.maven.plugin.obfuscation.core.Obfuscator.java
License:Open Source License
private void addComputationMethod(final ConstantStringReference csr) { final int access = csr.access; final boolean keepField = csr.keepField(); final boolean isStatic = csr.isStatic(); final String name = csr.name; final String value = csr.value; final String lvalue = literal(value); final MethodVisitor mv; if (keepField && isStatic) { mv = cv.visitMethod(access, "<clinit>", "()V", null, null); if (null == mv) return; logger().debug("Adding method <clinit> to compute \"{}\" and put it into field {}.", lvalue, name); } else {//from w ww . j ava 2 s . c o m mv = cv.visitMethod(access, name, "()Ljava/lang/String;", null, null); if (null == mv) return; logger().debug("Adding method {} to compute \"{}\".", name, lvalue); } mv.visitCode(); mv.visitTypeInsn(NEW, OBFUSCATED_STRING_INTERNAL_NAME); mv.visitInsn(DUP); final long[] obfuscated = array(value); addInsn(mv, obfuscated.length); mv.visitIntInsn(NEWARRAY, T_LONG); for (int i = 0; i < obfuscated.length; i++) { mv.visitInsn(DUP); addInsn(mv, i); mv.visitLdcInsn(obfuscated[i]); mv.visitInsn(LASTORE); } mv.visitMethodInsn(INVOKESPECIAL, OBFUSCATED_STRING_INTERNAL_NAME, "<init>", "([J)V", false); mv.visitMethodInsn(INVOKEVIRTUAL, OBFUSCATED_STRING_INTERNAL_NAME, cmn, "()Ljava/lang/String;", false); if (keepField && isStatic) { mv.visitFieldInsn(PUTSTATIC, internalClassName(), name, "Ljava/lang/String;"); mv.visitInsn(RETURN); mv.visitMaxs(7, 0); } else { mv.visitInsn(ARETURN); mv.visitMaxs(7, isStatic ? 0 : 1); } mv.visitEnd(); }
From source file:org.truelicense.maven.plugin.obfuscation.core.Obfuscator.java
License:Open Source License
private static void addInsn(final MethodVisitor mv, final int index) { switch (index) { case 0:/*from ww w. j a va 2 s .co m*/ mv.visitInsn(ICONST_0); break; case 1: mv.visitInsn(ICONST_1); break; case 2: mv.visitInsn(ICONST_2); break; case 3: mv.visitInsn(ICONST_3); break; case 4: mv.visitInsn(ICONST_4); break; case 5: mv.visitInsn(ICONST_5); break; default: mv.visitIntInsn(BIPUSH, index); } }
From source file:org.ubiquity.mirror.impl.MirrorGenerator.java
License:Apache License
private static void generateConstructor(ClassWriter writer) { MethodVisitor visitor = writer.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); visitor.visitIntInsn(ALOAD, 0); visitor.visitMethodInsn(INVOKESPECIAL, "org/ubiquity/mirror/impl/AbstractMirror", "<init>", "()V"); visitor.visitInsn(RETURN);/*from w w w. j a v a2 s .com*/ visitor.visitMaxs(1, 1); visitor.visitEnd(); }
From source file:org.ubiquity.mirror.impl.MirrorGenerator.java
License:Apache License
private static void mapArrayValue(MethodVisitor visitor, AnnotationProperty property) { final String arrayType = property.getDesc().substring(1); final String arrayByteCodeName = byteCodeName(arrayType); Class concreteClass = toJavaClass(arrayByteCodeName); final String arrayBytecodeType = concreteClass.isAnnotation() ? "org/ubiquity/mirror/Annotation" : arrayByteCodeName;//from w w w . j a v a 2s . c o m if (!concreteClass.isPrimitive()) { Object[] array = (Object[]) property.getValue(); visitor.visitLdcInsn(array.length); visitor.visitTypeInsn(ANEWARRAY, arrayBytecodeType); for (int i = 0; i < array.length; i++) { visitor.visitInsn(DUP); visitor.visitLdcInsn(i); addArrayValueInStack(visitor, array[i], arrayBytecodeType); visitor.visitInsn(AASTORE); } } else { final String arrayByteCodeUpperName = property.getDesc().toUpperCase(); final int length = Array.getLength(property.getValue()); visitor.visitLdcInsn(length); visitor.visitIntInsn(NEWARRAY, PRIMITIVE_ARRAY_CREATION.get(arrayByteCodeUpperName)); for (int i = 0; i < length; i++) { visitor.visitInsn(DUP); visitor.visitLdcInsn(i); visitor.visitLdcInsn(Array.get(property.getValue(), i)); visitor.visitInsn(PRIMITIVE_ARRAY_STORE.get(arrayByteCodeUpperName)); } } }
From source file:org.ubiquity.mirror.impl.MirrorGenerator.java
License:Apache License
private static void createInnerClassConstructor(ClassWriter writer, BytecodeProperty property) { MethodVisitor constructor = writer.visitMethod(ACC_PROTECTED, "<init>", "()V", null, null); constructor.visitIntInsn(ALOAD, 0); constructor.visitLdcInsn(property.getName()); String propertyObjectName = property.getType(); if (property.isPrimitive()) { propertyObjectName = byteCodeName(Constants.SIMPLE_PROPERTIES.get(getDescription(propertyObjectName))); }//from w w w .jav a2s. c o m constructor.visitLdcInsn(Type.getObjectType(propertyObjectName)); constructor.visitMethodInsn(INVOKESPECIAL, "org/ubiquity/mirror/impl/AbstractProperty", "<init>", "(Ljava/lang/String;Ljava/lang/Class;)V"); constructor.visitInsn(RETURN); constructor.visitMaxs(0, 0); constructor.visitEnd(); }
From source file:org.ubiquity.mirror.impl.MirrorGenerator.java
License:Apache License
private static void createGet(ClassWriter writer, BytecodeProperty property, String handledClassName, String innerClassName) {/*from w ww .j a va 2s .c o m*/ // Create actual get code String resolvedArgumentType = getDescription(property.getTypeGetter()); if (property.isPrimitive()) { resolvedArgumentType = Constants.SIMPLE_PROPERTIES.get(resolvedArgumentType); } String description = "(" + getDescription(handledClassName) + ")" + resolvedArgumentType; MethodVisitor visitor = writer.visitMethod(ACC_PUBLIC, "get", description, null, null); visitor.visitIntInsn(ALOAD, 1); visitor.visitMethodInsn(INVOKEVIRTUAL, handledClassName, property.getGetter(), "()" + getDescription(property.getTypeGetter())); if (property.isPrimitive()) { visitor.visitMethodInsn(INVOKESTATIC, "org/ubiquity/util/NativeConverter", "convert", "(" + property.getType() + ")" + resolvedArgumentType); } visitor.visitInsn(ARETURN); visitor.visitMaxs(0, 0); visitor.visitEnd(); // Create bridge code visitor = writer.visitMethod(ACC_PUBLIC | ACC_BRIDGE | ACC_VOLATILE | ACC_SYNTHETIC, "get", "(Ljava/lang/Object;)Ljava/lang/Object;", null, null); visitor.visitIntInsn(ALOAD, 0); visitor.visitIntInsn(ALOAD, 1); visitor.visitTypeInsn(CHECKCAST, byteCodeName(handledClassName)); visitor.visitMethodInsn(INVOKEVIRTUAL, innerClassName, "get", description); visitor.visitInsn(ARETURN); visitor.visitMaxs(0, 0); visitor.visitEnd(); }
From source file:org.ubiquity.mirror.impl.MirrorGenerator.java
License:Apache License
private static void createSet(ClassWriter writer, BytecodeProperty property, String handledClassName, String innerClassName) {//from w w w . j a v a2 s .c o m // Create actual code String resolvedArgumentType = getDescription(property.getTypeSetter()); if (property.isPrimitive()) { resolvedArgumentType = Constants.SIMPLE_PROPERTIES.get(resolvedArgumentType); } String description = "(" + getDescription(handledClassName) + resolvedArgumentType + ")V"; MethodVisitor visitor = writer.visitMethod(ACC_PUBLIC, "set", description, null, null); visitor.visitIntInsn(ALOAD, 1); visitor.visitIntInsn(ALOAD, 2); if (property.isPrimitive()) { visitor.visitMethodInsn(INVOKESTATIC, "org/ubiquity/util/NativeConverter", "convert", "(" + resolvedArgumentType + ")" + property.getType()); } visitor.visitMethodInsn(INVOKEVIRTUAL, handledClassName, property.getSetter(), "(" + getDescription(property.getTypeSetter()) + ")V"); visitor.visitInsn(RETURN); visitor.visitMaxs(0, 0); visitor.visitEnd(); // create bridge visitor = writer.visitMethod(ACC_PUBLIC | ACC_BRIDGE | ACC_VOLATILE | ACC_SYNTHETIC, "set", "(Ljava/lang/Object;Ljava/lang/Object;)V", null, null); visitor.visitIntInsn(ALOAD, 0); visitor.visitIntInsn(ALOAD, 1); visitor.visitTypeInsn(CHECKCAST, handledClassName); visitor.visitIntInsn(ALOAD, 2); visitor.visitTypeInsn(CHECKCAST, byteCodeName(resolvedArgumentType)); visitor.visitMethodInsn(INVOKEVIRTUAL, innerClassName, "set", description); visitor.visitInsn(RETURN); visitor.visitMaxs(0, 0); visitor.visitEnd(); }