Example usage for org.objectweb.asm Opcodes UNINITIALIZED_THIS

List of usage examples for org.objectweb.asm Opcodes UNINITIALIZED_THIS

Introduction

In this page you can find the example usage for org.objectweb.asm Opcodes UNINITIALIZED_THIS.

Prototype

Integer UNINITIALIZED_THIS

To view the source code for org.objectweb.asm Opcodes UNINITIALIZED_THIS.

Click Source Link

Usage

From source file:com.google.devtools.build.android.desugar.BytecodeTypeInference.java

License:Open Source License

/** Convert the type in stack map frame to inference type. */
private InferredType convertTypeInStackMapFrame(Object typeInStackMapFrame) {
    if (typeInStackMapFrame == Opcodes.TOP) {
        return InferredType.TOP;
    } else if (typeInStackMapFrame == Opcodes.INTEGER) {
        return InferredType.INT;
    } else if (typeInStackMapFrame == Opcodes.FLOAT) {
        return InferredType.FLOAT;
    } else if (typeInStackMapFrame == Opcodes.DOUBLE) {
        return InferredType.DOUBLE;
    } else if (typeInStackMapFrame == Opcodes.LONG) {
        return InferredType.LONG;
    } else if (typeInStackMapFrame == Opcodes.NULL) {
        return InferredType.NULL;
    } else if (typeInStackMapFrame == Opcodes.UNINITIALIZED_THIS) {
        return InferredType.UNINITIALIZED_THIS;
    } else if (typeInStackMapFrame instanceof String) {
        String referenceTypeName = (String) typeInStackMapFrame;
        if (referenceTypeName.charAt(0) == '[') {
            return InferredType.createNonUninitializedType(referenceTypeName);
        } else {/*from  ww w .j a v a2 s. c  o m*/
            return InferredType.createNonUninitializedType('L' + referenceTypeName + ';');
        }
    } else if (typeInStackMapFrame instanceof Label) {
        Label label = (Label) typeInStackMapFrame;
        return InferredType.createUninitializedType(label);
    } else {
        throw new RuntimeException("Cannot reach here. Unhandled element: value=" + typeInStackMapFrame
                + ", class=" + typeInStackMapFrame.getClass() + ". The current method being desugared is "
                + methodSignature);
    }
}

From source file:de.scoopgmbh.copper.instrument.StackInfo.java

License:Apache License

static Type deferLocalDesc(Object object) {
    if (object instanceof String)
        return Type.getObjectType((String) object);
    //TODO: analyze opcode at pos label
    if (object instanceof Label)
        return Type.getType(Object.class);
    int intObject = (Integer) object;
    if (intObject == Opcodes.TOP)
        return null;
    if (intObject == Opcodes.INTEGER)
        return Type.INT_TYPE;
    if (intObject == Opcodes.FLOAT)
        return Type.FLOAT_TYPE;
    if (intObject == Opcodes.LONG)
        return Type.LONG_TYPE;
    if (intObject == Opcodes.DOUBLE)
        return Type.getType(double.class);
    if (intObject == Opcodes.LONG)
        return Type.getType(long.class);
    if (intObject == Opcodes.NULL)
        return Type.getType(Object.class);
    //TODO: defer from containing class
    if (intObject == Opcodes.UNINITIALIZED_THIS)
        return Type.getType(Object.class);
    throw new BuildStackFrameException("Couldnt defer desc for " + object);
}

From source file:edu.ubc.mirrors.holograms.FrameAnalyzer.java

License:Open Source License

public Object toFrameObject(FrameValue value) {
    if (value.isUninitializedThis()) {
        return Opcodes.UNINITIALIZED_THIS;
    } else if (value.isUninitialized()) {
        AbstractInsnNode newInsn = value.getNewInsn();
        // TODO: Could also search up to the previous actual instruction...
        AbstractInsnNode labelNode = newInsn.getPrevious();
        if (labelNode == null || !(labelNode instanceof LabelNode)) {
            labelNode = new LabelNode();
            m.instructions.insertBefore(newInsn, labelNode);
        }//from   w w  w  . j  ava 2s .co m
        return ((LabelNode) labelNode).getLabel();
    } else {
        Type type = value.getBasicValue().getType();
        if (type == null) {
            return Opcodes.TOP;
        } else {
            switch (type.getSort()) {
            case Type.VOID:
                // TODO: Not sure what to do here. Used for BasicValue.RETURNADDRESS_VALUE,
                // but I can't figure out the correct verifier type for the return addresses
                // used by JSR/RET.
                return Opcodes.TOP;
            case Type.BOOLEAN:
            case Type.BYTE:
            case Type.CHAR:
            case Type.SHORT:
            case Type.INT:
                return Opcodes.INTEGER;
            case Type.LONG:
                return Opcodes.LONG;
            case Type.FLOAT:
                return Opcodes.FLOAT;
            case Type.DOUBLE:
                return Opcodes.DOUBLE;
            case Type.OBJECT:
            case Type.ARRAY:
                return type.getInternalName();
            case Type.METHOD:
                // Shouldn't happen
            default:
                throw new RuntimeException("Bad sort: " + type.getSort());
            }
        }
    }
}

From source file:edu.ubc.mirrors.holograms.HologramMethodGenerator.java

License:Open Source License

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
    // Various special cases here to adjust for the fact that Object and Throwable
    // are still in the hierarchy and have some methods with incompatible types.

    Type stringHologramType = getHologramType(String.class);
    if (name.equals("toString") && desc.equals(Type.getMethodDescriptor(stringHologramType))) {
        desc = Type.getMethodDescriptor(Type.getType(String.class));
        if (owner.equals(Type.getInternalName(Hologram.class))) {
            owner = OBJECT_TYPE.getInternalName();
            // Handle calling Object.toString() with an invokespecial opcode, 
            // which doesn't work any more since we've changed the superclass.
            if (opcode == Opcodes.INVOKESPECIAL) {
                opcode = Opcodes.INVOKESTATIC;
                owner = objectHologramType.getInternalName();
                name = "hologramToString";
                desc = Type.getMethodDescriptor(stringType, hologramType);
            }//from w  w w  . j  av a 2  s  .c o  m
        }

        super.visitMethodInsn(opcode, owner, name, desc);

        getClassMirror(this.owner);
        invokestatic(objectHologramType.getInternalName(), "makeStringHologram",
                Type.getMethodDescriptor(hologramType, stringType, classMirrorType));
        checkcast(stringHologramType);
        return;
    }

    if (name.equals("getClass") && desc.equals(Type.getMethodDescriptor(getHologramType(Class.class)))) {
        invokeinterface(Type.getInternalName(Hologram.class), "getMirror",
                Type.getMethodDescriptor(objectMirrorType));
        invokeinterface(objectMirrorType.getInternalName(), "getClassMirror",
                Type.getMethodDescriptor(Type.getType(ClassMirror.class)));

        invokestatic(objectHologramType.getInternalName(), "make",
                Type.getMethodDescriptor(hologramType, objectMirrorType));
        checkcast(getHologramType(Class.class));
        return;
    }

    if (owner.equals(Type.getInternalName(Hologram.class))) {
        if (name.equals("<init>") && this.owner.equals(getHologramType(Throwable.class))) {
            owner = Type.getInternalName(Throwable.class);
        } else if (name.equals("<init>") || name.equals("toString")) {
            owner = objectHologramType.getInternalName();
        } else {
            owner = OBJECT_TYPE.getInternalName();
        }
    }

    if (name.equals("clone")) {
        if (desc.equals(Type.getMethodDescriptor(hologramType))) {
            desc = Type.getMethodDescriptor(OBJECT_TYPE);

            // Object.clone() on an array type is legal since array types
            // are treated specially by the JVM, but the mirror interfaces 
            // are not granted the same leeway.
            Object t = stackType(0);
            if (t instanceof String) {
                String internalName = (String) t;
                Type type = Type.getObjectType(internalName);
                if (HologramClassGenerator.getOriginalType(type).getSort() == Type.ARRAY) {
                    owner = internalName;
                }
            }
        }
        if (owner.equals(Type.getType(ObjectArrayMirror.class).getInternalName())
                || (owner.startsWith("hologramarray") && !owner.startsWith("hologramarrayimpl"))) {
            String originalName = getOriginalInternalClassName(owner);
            owner = getHologramType(Type.getObjectType(originalName), true).getInternalName();
            checkcast(Type.getObjectType(owner));
        }
    }

    //        if (owner.equals(getHologramType(Throwable.class).getInternalName())) {
    //            if (name.equals("<init>") && desc.equals(Type.getMethodDescriptor(Type.VOID_TYPE, getHologramType(String.class)))) {
    //                desc = Type.getMethodDescriptor(Type.VOID_TYPE, objectHologramType);
    //            }
    //        }

    if (owner.equals(hologramThrowableType.getInternalName()) && name.equals("fillInStackTrace")
            && desc.equals(Type.getMethodDescriptor(hologramThrowableType))) {
        desc = Type.getMethodDescriptor(throwableType);
        owner = throwableType.getInternalName();
    }

    if (name.equals("equals")
            && desc.equals(Type.getMethodDescriptor(Type.BOOLEAN_TYPE, Type.getType(Hologram.class)))) {
        desc = Type.getMethodDescriptor(Type.BOOLEAN_TYPE, OBJECT_TYPE);
    }

    if (name.equals("<init>") && !owner.equals(Type.getInternalName(Throwable.class))) {
        int argsSize = Type.getArgumentsAndReturnSizes(desc) >> 2;
        desc = HologramClassGenerator.addMirrorParam(desc);

        Object targetType = stackType(argsSize - 1);
        if (targetType.equals(Opcodes.UNINITIALIZED_THIS)) {
            // If the target is an uninitialized this (i.e. we're calling super(...)
            // or this(...)), pass along the extra mirror argument
            load((methodType.getArgumentsAndReturnSizes() >> 2) - 1, instanceMirrorType);
        } else if (targetType instanceof Label) {
            // If the target is just uninitialized (i.e. we're calling <init> after
            // a new), create the mirror
            getClassMirror(Type.getObjectType(owner));
            invokeinterface(classMirrorType.getInternalName(), "newRawInstance",
                    Type.getMethodDescriptor(instanceMirrorType));
        } else {
            // Shouldn't happen
            throw new RuntimeException("Calling <init> on already initialized type: " + targetType);
        }
    }

    super.visitMethodInsn(opcode, owner, name, desc);

    if (owner.equals(Type.getInternalName(Throwable.class)) && name.equals("getStackTraceElement")) {
        Type steType = Type.getType(StackTraceElement.class);
        invokestatic(Type.getInternalName(ObjectHologram.class), "cleanStackTraceElement",
                Type.getMethodDescriptor(steType, steType));
    }
}

From source file:edu.ubc.mirrors.holograms.HologramMethodGenerator.java

License:Open Source License

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    boolean isSet = (opcode == Opcodes.PUTFIELD || opcode == Opcodes.PUTSTATIC);
    boolean isStatic = (opcode == Opcodes.GETSTATIC || opcode == Opcodes.PUTSTATIC);

    Type fieldType = Type.getType(desc);
    int setValueLocal = -1;

    if (isStatic) {
        // For a static field the instance is null
        if (isSet) {
            setValueLocal = lvs.newLocal(fieldType);
            store(setValueLocal, fieldType);
        }/*w  ww .  j  a va  2s  .  c  om*/
        aconst(null);
        if (isSet) {
            load(setValueLocal, fieldType);
        }
    } else {
        // If this is an "uninitialized this", the mirror is the nth argument instead
        // of the mirror field on ObjectHologram.
        Object stackType = stackType(isSet ? 1 : 0);
        if (stackType == Opcodes.UNINITIALIZED_THIS) {
            // Pop the original argument
            if (isSet) {
                setValueLocal = lvs.newLocal(fieldType);
                store(setValueLocal, fieldType);
            }

            pop();
            load((methodType.getArgumentsAndReturnSizes() >> 2) - 1, instanceMirrorType);

            MethodHandle.OBJECT_HOLOGRAM_MAKE.invoke(this);

            if (isSet) {
                load(setValueLocal, fieldType);
            }
        }
    }

    getClassMirror(Type.getObjectType(owner));
    aconst(name);

    Type fieldTypeForMirrorCall = fieldType;
    int fieldSort = fieldType.getSort();
    String suffix = "";
    if (fieldSort == Type.ARRAY || fieldSort == Type.OBJECT) {
        fieldTypeForMirrorCall = hologramType;
    } else {
        suffix = HologramClassGenerator.getSortName(fieldSort);
    }

    // Call the appropriate getter/setter method on the mirror
    String methodDesc;
    if (isSet) {
        methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, hologramType, fieldTypeForMirrorCall,
                classMirrorType, stringType);
    } else {
        methodDesc = Type.getMethodDescriptor(fieldTypeForMirrorCall, hologramType, classMirrorType,
                stringType);
    }
    invokestatic(instanceHologramType.getInternalName(), (isSet ? "set" : "get") + suffix + "Field",
            methodDesc);

    if (!isSet && fieldTypeForMirrorCall.equals(hologramType)) {
        checkcast(fieldType);
    }
}

From source file:jaspex.speculation.newspec.FlowFrame.java

License:Open Source License

/** Converte lista de tipos no formato do visitFrame em BasicValues **/
private UtilList<BasicValue> convertFromFrame(List<Object> values, boolean locals) {
    UtilList<BasicValue> outList = new UtilArrayList<BasicValue>();

    for (Object o : values) {
        if (o instanceof Integer) {
            Integer i = (Integer) o;
            if (i.equals(Opcodes.TOP)) {
                outList.add(BasicValue.UNINITIALIZED_VALUE);
            } else if (i.equals(Opcodes.INTEGER)) {
                outList.add(BasicValue.INT_VALUE);
            } else if (i.equals(Opcodes.FLOAT)) {
                outList.add(BasicValue.FLOAT_VALUE);
            } else if (i.equals(Opcodes.LONG)) {
                outList.add(BasicValue.LONG_VALUE);
                if (locals)
                    outList.add(BasicValue.UNINITIALIZED_VALUE);
            } else if (i.equals(Opcodes.DOUBLE)) {
                outList.add(BasicValue.DOUBLE_VALUE);
                if (locals)
                    outList.add(BasicValue.UNINITIALIZED_VALUE);
            } else if (i.equals(Opcodes.NULL)) {
                outList.add(BasicValue.REFERENCE_VALUE);
            } else if (i.equals(Opcodes.UNINITIALIZED_THIS)) {
                throw new AssertionError("FIXME");
            } else {
                throw new AssertionError();
            }//w  w w. j a va 2s . co  m
        } else if (o instanceof String) {
            String s = (String) o;
            outList.add(_interpreter.newValue(Type.getObjectType(s)));
        } else if (o instanceof Label) {
            throw new AssertionError("FIXME");
        } else {
            throw new AssertionError("FIXME");
        }
    }

    return outList;
}

From source file:org.copperengine.core.instrument.StackInfo.java

License:Apache License

static Type deferLocalDesc(Object object) {
    if (object instanceof String)
        return Type.getObjectType((String) object);
    // TODO: analyze opcode at pos label
    if (object instanceof Label)
        return Type.getType(Object.class);
    int intObject = (Integer) object;
    if (intObject == Opcodes.TOP)
        return null;
    if (intObject == Opcodes.INTEGER)
        return Type.INT_TYPE;
    if (intObject == Opcodes.FLOAT)
        return Type.FLOAT_TYPE;
    if (intObject == Opcodes.LONG)
        return Type.LONG_TYPE;
    if (intObject == Opcodes.DOUBLE)
        return Type.getType(double.class);
    if (intObject == Opcodes.LONG)
        return Type.getType(long.class);
    if (intObject == Opcodes.NULL)
        return Type.getType(Object.class);
    // TODO: defer from containing class
    if (intObject == Opcodes.UNINITIALIZED_THIS)
        return Type.getType(Object.class);
    throw new BuildStackFrameException("Couldnt defer desc for " + object);
}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

public FrameTracker(final String owner, final int access, final String name, final String desc,
        final MethodVisitor mv) {
    super(Opcodes.ASM4, mv);
    this.owner = owner;
    local = new Object[8];
    localSize = 0;/*from w  w  w .ja  v a2s  .com*/
    stack = new Object[8];
    stackSize = 0;

    if ((access & Opcodes.ACC_STATIC) == 0) {
        if ("<init>".equals(name)) {
            set(localSize, Opcodes.UNINITIALIZED_THIS);
        } else {
            set(localSize, owner);
        }
    }
    for (final Type t : Type.getArgumentTypes(desc)) {
        set(localSize, t);
    }

}

From source file:org.jacoco.core.internal.instr.FrameTracker.java

License:Open Source License

@Override
public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc) {
    for (final Type t : Type.getArgumentTypes(desc)) {
        pop(t);//  w w w.  j  av a  2 s  . c om
    }
    if (opcode != Opcodes.INVOKESTATIC) {
        final Object target = pop();
        if (target == Opcodes.UNINITIALIZED_THIS) {
            replace(Opcodes.UNINITIALIZED_THIS, this.owner);
        } else if (target instanceof Label) {
            replace(target, owner);
        }
    }
    push(Type.getReturnType(desc));

    mv.visitMethodInsn(opcode, owner, name, desc);
}

From source file:org.jboss.byteman.agent.adapter.RuleGeneratorAdapter.java

License:Open Source License

private void dumpType(StringBuffer buffer, Object t) {

    if (t == Opcodes.TOP) {
        buffer.append("TOP");
    } else if (t == null) {
        buffer.append("null");
    } else if (t == Opcodes.INTEGER) {
        buffer.append("int");
    } else if (t == Opcodes.FLOAT) {
        buffer.append("float");
    } else if (t == Opcodes.DOUBLE) {
        buffer.append("double");
    } else if (t == Opcodes.LONG) {
        buffer.append("long");
    } else if (t == Opcodes.NULL) {
        buffer.append("null");
    } else if (t == Opcodes.UNINITIALIZED_THIS) {
        buffer.append("uninit_this");
    } else if (t instanceof String) {
        buffer.append((String) t);
    } else {/*from w  ww . j ava  2 s.  co m*/
        buffer.append(((Label) t).getOffset());
    }
}