Search in sources :

Example 1 with Label

use of com.google.api.ads.admanager.axis.v202108.Label in project jodd by oblac.

the class ProxettaAsmUtil method visitReturn.

// ---------------------------------------------------------------- return
/**
	 * Visits return opcodes.
	 */
public static void visitReturn(MethodVisitor mv, MethodInfo methodInfo, boolean isLast) {
    switch(methodInfo.getReturnOpcodeType()) {
        case 'V':
            if (isLast) {
                mv.visitInsn(POP);
            }
            mv.visitInsn(RETURN);
            break;
        case 'B':
            if (isLast) {
                mv.visitInsn(DUP);
                Label label = new Label();
                mv.visitJumpInsn(IFNONNULL, label);
                mv.visitInsn(POP);
                mv.visitInsn(ICONST_0);
                mv.visitInsn(IRETURN);
                mv.visitLabel(label);
                AsmUtil.byteValue(mv);
            }
            mv.visitInsn(IRETURN);
            break;
        case 'C':
            if (isLast) {
                mv.visitInsn(DUP);
                Label label = new Label();
                mv.visitJumpInsn(IFNONNULL, label);
                mv.visitInsn(POP);
                mv.visitInsn(ICONST_0);
                mv.visitInsn(IRETURN);
                mv.visitLabel(label);
                AsmUtil.charValue(mv);
            }
            mv.visitInsn(IRETURN);
            break;
        case 'S':
            if (isLast) {
                mv.visitInsn(DUP);
                Label label = new Label();
                mv.visitJumpInsn(IFNONNULL, label);
                mv.visitInsn(POP);
                mv.visitInsn(ICONST_0);
                mv.visitInsn(IRETURN);
                mv.visitLabel(label);
                AsmUtil.shortValue(mv);
            }
            mv.visitInsn(IRETURN);
            break;
        case 'I':
            if (isLast) {
                mv.visitInsn(DUP);
                Label label = new Label();
                mv.visitJumpInsn(IFNONNULL, label);
                mv.visitInsn(POP);
                mv.visitInsn(ICONST_0);
                mv.visitInsn(IRETURN);
                mv.visitLabel(label);
                AsmUtil.intValue(mv);
            }
            mv.visitInsn(IRETURN);
            break;
        case 'Z':
            if (isLast) {
                mv.visitInsn(DUP);
                Label label = new Label();
                mv.visitJumpInsn(IFNONNULL, label);
                mv.visitInsn(POP);
                mv.visitInsn(ICONST_0);
                mv.visitInsn(IRETURN);
                mv.visitLabel(label);
                AsmUtil.booleanValue(mv);
            }
            mv.visitInsn(IRETURN);
            break;
        case 'J':
            if (isLast) {
                mv.visitInsn(DUP);
                Label label = new Label();
                mv.visitJumpInsn(IFNONNULL, label);
                mv.visitInsn(POP);
                mv.visitInsn(LCONST_0);
                mv.visitInsn(LRETURN);
                mv.visitLabel(label);
                AsmUtil.longValue(mv);
            }
            mv.visitInsn(LRETURN);
            break;
        case 'F':
            if (isLast) {
                mv.visitInsn(DUP);
                Label label = new Label();
                mv.visitJumpInsn(IFNONNULL, label);
                mv.visitInsn(POP);
                mv.visitInsn(FCONST_0);
                mv.visitInsn(FRETURN);
                mv.visitLabel(label);
                AsmUtil.floatValue(mv);
            }
            mv.visitInsn(FRETURN);
            break;
        case 'D':
            if (isLast) {
                mv.visitInsn(DUP);
                Label label = new Label();
                mv.visitJumpInsn(IFNONNULL, label);
                mv.visitInsn(POP);
                mv.visitInsn(DCONST_0);
                mv.visitInsn(DRETURN);
                mv.visitLabel(label);
                AsmUtil.doubleValue(mv);
            }
            mv.visitInsn(DRETURN);
            break;
        default:
            mv.visitInsn(ARETURN);
            break;
    }
}
Also used : Label(jodd.asm5.Label)

Example 2 with Label

use of com.google.api.ads.admanager.axis.v202108.Label in project intellij-community by JetBrains.

the class AdvancedEnhancer method emitBindCallbacks.

private void emitBindCallbacks(ClassEmitter ce) {
    CodeEmitter e = ce.begin_method(Constants.PRIVATE_FINAL_STATIC, BIND_CALLBACKS, null);
    Local me = e.make_local();
    e.load_arg(0);
    e.checkcast_this();
    e.store_local(me);
    $Label end = e.make_label();
    e.load_local(me);
    e.getfield(BOUND_FIELD);
    e.if_jump(e.NE, end);
    e.load_local(me);
    e.push(1);
    e.putfield(BOUND_FIELD);
    e.getfield(THREAD_CALLBACKS_FIELD);
    e.invoke_virtual(THREAD_LOCAL, THREAD_LOCAL_GET);
    e.dup();
    $Label found_callback = e.make_label();
    e.ifnonnull(found_callback);
    e.pop();
    e.getfield(STATIC_CALLBACKS_FIELD);
    e.dup();
    e.ifnonnull(found_callback);
    e.pop();
    e.goTo(end);
    e.mark(found_callback);
    e.checkcast(CALLBACK_ARRAY);
    e.load_local(me);
    e.swap();
    for (int i = callbackTypes.length - 1; i >= 0; i--) {
        if (i != 0) {
            e.dup2();
        }
        e.aaload(i);
        e.checkcast(callbackTypes[i]);
        e.putfield(getCallbackField(i));
    }
    e.mark(end);
    e.return_value();
    e.end_method();
}
Also used : net.sf.cglib.asm.$Label(net.sf.cglib.asm.$Label)

Example 3 with Label

use of com.google.api.ads.admanager.axis.v202108.Label in project bgpcep by opendaylight.

the class Type1LabelParser method serializeLabel.

@Override
public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) {
    Preconditions.checkArgument(subobject instanceof Type1LabelCase, "Unknown Label Subobject instance. Passed {}. Needed Type1LabelCase.", subobject.getClass());
    final ByteBuf body = Unpooled.buffer(LABEL_LENGTH);
    final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label();
    Preconditions.checkArgument(type1Label != null, "Type1Label is mandatory.");
    writeUnsignedInt(type1Label.getType1Label(), body);
    LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
Also used : Type1Label(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.type1.label._case.Type1Label) Type1LabelCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCase) ByteBuf(io.netty.buffer.ByteBuf)

Example 4 with Label

use of com.google.api.ads.admanager.axis.v202108.Label in project bgpcep by opendaylight.

the class Type1LabelParser method serializeLabel.

@Override
public void serializeLabel(final boolean unidirectional, final boolean global, final LabelType subobject, final ByteBuf buffer) {
    Preconditions.checkArgument(subobject instanceof Type1LabelCase, "Unknown Label Subobject instance. Passed {}. Needed Type1LabelCase.", subobject.getClass());
    final ByteBuf body = Unpooled.buffer(LABEL_LENGTH);
    final Type1Label type1Label = ((Type1LabelCase) subobject).getType1Label();
    Preconditions.checkArgument(type1Label != null, "Type1Label is mandatory.");
    writeUnsignedInt(type1Label.getType1Label(), body);
    LabelUtil.formatLabel(CTYPE, unidirectional, global, body, buffer);
}
Also used : Type1Label(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.type1.label._case.Type1Label) Type1LabelCase(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.rsvp.rev150820.label.subobject.label.type.Type1LabelCase) ByteBuf(io.netty.buffer.ByteBuf)

Example 5 with Label

use of com.google.api.ads.admanager.axis.v202108.Label in project component-runtime by Talend.

the class ProxyGenerator method delegateMethod.

private void delegateMethod(final ClassWriter cw, final Method method, final String proxyClassFileName, final int methodIndex) {
    final Class<?> returnType = method.getReturnType();
    final Class<?>[] parameterTypes = method.getParameterTypes();
    final Class<?>[] exceptionTypes = method.getExceptionTypes();
    final int modifiers = method.getModifiers();
    if (Modifier.isFinal(modifiers) || Modifier.isStatic(modifiers)) {
        throw new IllegalStateException("It's not possible to proxy a final or static method: " + method.getDeclaringClass().getName() + " " + method.getName());
    }
    // push the method definition
    int modifier = modifiers & (ACC_PUBLIC | ACC_PROTECTED | ACC_VARARGS);
    MethodVisitor mv = cw.visitMethod(modifier, method.getName(), Type.getMethodDescriptor(method), null, null);
    mv.visitCode();
    // push try/catch block, to catch declared exceptions, and to catch java.lang.Throwable
    final Label l0 = new Label();
    final Label l1 = new Label();
    final Label l2 = new Label();
    if (exceptionTypes.length > 0) {
        mv.visitTryCatchBlock(l0, l1, l2, "java/lang/reflect/InvocationTargetException");
    }
    // push try code
    mv.visitLabel(l0);
    final String classNameToOverride = method.getDeclaringClass().getName().replace('.', '/');
    mv.visitLdcInsn(Type.getType("L" + classNameToOverride + ";"));
    // the following code generates the bytecode for this line of Java:
    // Method method = <proxy>.class.getMethod("add", new Class[] { <array of function argument classes> });
    // get the method name to invoke, and push to stack
    mv.visitLdcInsn(method.getName());
    // create the Class[]
    createArrayDefinition(mv, parameterTypes.length, Class.class);
    int length = 1;
    // push parameters into array
    for (int i = 0; i < parameterTypes.length; i++) {
        // keep copy of array on stack
        mv.visitInsn(DUP);
        Class<?> parameterType = parameterTypes[i];
        // push number onto stack
        pushIntOntoStack(mv, i);
        if (parameterType.isPrimitive()) {
            String wrapperType = getWrapperType(parameterType);
            mv.visitFieldInsn(GETSTATIC, wrapperType, "TYPE", "Ljava/lang/Class;");
        } else {
            mv.visitLdcInsn(Type.getType(parameterType));
        }
        mv.visitInsn(AASTORE);
        if (Long.TYPE.equals(parameterType) || Double.TYPE.equals(parameterType)) {
            length += 2;
        } else {
            length++;
        }
    }
    // the following code generates bytecode equivalent to:
    // return ((<returntype>) invocationHandler.invoke(this, {methodIndex}, new Object[] { <function arguments
    // }))[.<primitive>Value()];
    final Label l4 = new Label();
    mv.visitLabel(l4);
    mv.visitVarInsn(ALOAD, 0);
    // get the invocationHandler field from this class
    mv.visitFieldInsn(GETFIELD, proxyClassFileName, FIELD_INTERCEPTOR_HANDLER, Type.getDescriptor(InterceptorHandler.class));
    // add the Method from the static array as first parameter
    mv.visitFieldInsn(GETSTATIC, proxyClassFileName, FIELD_INTERCEPTED_METHODS, Type.getDescriptor(Method[].class));
    // push the methodIndex of the current method
    if (methodIndex < 128) {
        mv.visitIntInsn(BIPUSH, methodIndex);
    } else if (methodIndex < 32267) {
        // for methods > 127 we need to push a short number as index
        mv.visitIntInsn(SIPUSH, methodIndex);
    } else {
        throw new IllegalStateException("Sorry, we only support Classes with 2^15 methods...");
    }
    // and now load the Method from the array
    mv.visitInsn(AALOAD);
    // prepare the parameter array as Object[] and store it on the stack
    pushMethodParameterArray(mv, parameterTypes);
    // invoke the invocationHandler
    mv.visitMethodInsn(INVOKEINTERFACE, Type.getInternalName(InterceptorHandler.class), "invoke", "(Ljava/lang/reflect/Method;[Ljava/lang/Object;)Ljava/lang/Object;", true);
    // cast the result
    mv.visitTypeInsn(CHECKCAST, getCastType(returnType));
    if (returnType.isPrimitive() && (!Void.TYPE.equals(returnType))) {
        // get the primitive value
        mv.visitMethodInsn(INVOKEVIRTUAL, getWrapperType(returnType), getPrimitiveMethod(returnType), "()" + Type.getDescriptor(returnType), false);
    }
    // push return
    mv.visitLabel(l1);
    if (!Void.TYPE.equals(returnType)) {
        mv.visitInsn(getReturnInsn(returnType));
    } else {
        mv.visitInsn(POP);
        mv.visitInsn(RETURN);
    }
    // catch InvocationTargetException
    if (exceptionTypes.length > 0) {
        mv.visitLabel(l2);
        mv.visitVarInsn(ASTORE, length);
        Label l5 = new Label();
        mv.visitLabel(l5);
        for (int i = 0; i < exceptionTypes.length; i++) {
            Class<?> exceptionType = exceptionTypes[i];
            mv.visitLdcInsn(Type.getType("L" + exceptionType.getCanonicalName().replace('.', '/') + ";"));
            mv.visitVarInsn(ALOAD, length);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "getCause", "()Ljava/lang/Throwable;", false);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
            final Label l6 = new Label();
            mv.visitJumpInsn(IFEQ, l6);
            final Label l7 = new Label();
            mv.visitLabel(l7);
            mv.visitVarInsn(ALOAD, length);
            mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/reflect/InvocationTargetException", "getCause", "()Ljava/lang/Throwable;", false);
            mv.visitTypeInsn(CHECKCAST, getCastType(exceptionType));
            mv.visitInsn(ATHROW);
            mv.visitLabel(l6);
            if (i == (exceptionTypes.length - 1)) {
                mv.visitTypeInsn(NEW, "java/lang/reflect/UndeclaredThrowableException");
                mv.visitInsn(DUP);
                mv.visitVarInsn(ALOAD, length);
                mv.visitMethodInsn(INVOKESPECIAL, "java/lang/reflect/UndeclaredThrowableException", "<init>", "(Ljava/lang/Throwable;)V", false);
                mv.visitInsn(ATHROW);
            }
        }
    }
    // finish this method
    mv.visitMaxs(0, 0);
    mv.visitEnd();
}
Also used : InterceptorHandler(org.talend.sdk.component.api.service.interceptor.InterceptorHandler) Label(org.apache.xbean.asm6.Label) MethodVisitor(org.apache.xbean.asm6.MethodVisitor)

Aggregations

StatementBuilder (com.google.api.ads.admanager.axis.utils.v202108.StatementBuilder)7 Label (org.apache.xbean.asm9.Label)7 Label (com.google.api.ads.admanager.axis.v202108.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202108.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202111.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202111.LabelServiceInterface)5 Label (com.google.api.ads.admanager.axis.v202202.Label)5 LabelServiceInterface (com.google.api.ads.admanager.axis.v202202.LabelServiceInterface)5 MethodVisitor (org.apache.xbean.asm9.MethodVisitor)5 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202111.StatementBuilder)4 StatementBuilder (com.google.api.ads.admanager.axis.utils.v202202.StatementBuilder)4 CreativeWrapper (com.google.api.ads.admanager.axis.v202108.CreativeWrapper)4 CreativeWrapperServiceInterface (com.google.api.ads.admanager.axis.v202108.CreativeWrapperServiceInterface)4 LabelPage (com.google.api.ads.admanager.axis.v202108.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202111.LabelPage)4 LabelPage (com.google.api.ads.admanager.axis.v202202.LabelPage)4 CreativeWrapperPage (com.google.api.ads.admanager.axis.v202108.CreativeWrapperPage)3 Random (java.util.Random)3 net.sf.cglib.asm.$Label (net.sf.cglib.asm.$Label)3 UpdateResult (com.google.api.ads.admanager.axis.v202108.UpdateResult)2