Java Code Examples for org.objectweb.asm.Type#BOOLEAN_TYPE

The following examples show how to use org.objectweb.asm.Type#BOOLEAN_TYPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpressionIsNull.java    From datakernel with Apache License 2.0 6 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();

	Label labelNull = new Label();
	Label labelExit = new Label();

	expression.load(ctx);
	g.ifNull(labelNull);
	g.push(false);
	g.goTo(labelExit);

	g.mark(labelNull);
	g.push(true);

	g.mark(labelExit);

	return Type.BOOLEAN_TYPE;
}
 
Example 2
Source File: ExpressionIsNotNull.java    From datakernel with Apache License 2.0 6 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();

	Label labelNotNull = new Label();
	Label labelExit = new Label();

	expression.load(ctx);
	g.ifNonNull(labelNotNull);
	g.push(false);
	g.goTo(labelExit);

	g.mark(labelNotNull);
	g.push(true);

	g.mark(labelExit);

	return Type.BOOLEAN_TYPE;
}
 
Example 3
Source File: TypeUtils.java    From cglib with Apache License 2.0 6 votes vote down vote up
public static Type getUnboxedType(Type type) {
    if (Constants.TYPE_INTEGER.equals(type)) {
        return Type.INT_TYPE;
    } else if (Constants.TYPE_BOOLEAN.equals(type)) {
        return Type.BOOLEAN_TYPE;
    } else if (Constants.TYPE_DOUBLE.equals(type)) {
        return Type.DOUBLE_TYPE;
    } else if (Constants.TYPE_LONG.equals(type)) {
        return Type.LONG_TYPE;
    } else if (Constants.TYPE_CHARACTER.equals(type)) {
        return Type.CHAR_TYPE;
    } else if (Constants.TYPE_BYTE.equals(type)) {
        return Type.BYTE_TYPE;
    } else if (Constants.TYPE_FLOAT.equals(type)) {
        return Type.FLOAT_TYPE;
    } else if (Constants.TYPE_SHORT.equals(type)) {
        return Type.SHORT_TYPE;
    } else {
        return type;
    }
}
 
Example 4
Source File: AnalyzedMethod.java    From glowroot with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
static Type getType(String type) {
    if (type.equals(Void.TYPE.getName())) {
        return Type.VOID_TYPE;
    } else if (type.equals(Boolean.TYPE.getName())) {
        return Type.BOOLEAN_TYPE;
    } else if (type.equals(Character.TYPE.getName())) {
        return Type.CHAR_TYPE;
    } else if (type.equals(Byte.TYPE.getName())) {
        return Type.BYTE_TYPE;
    } else if (type.equals(Short.TYPE.getName())) {
        return Type.SHORT_TYPE;
    } else if (type.equals(Integer.TYPE.getName())) {
        return Type.INT_TYPE;
    } else if (type.equals(Float.TYPE.getName())) {
        return Type.FLOAT_TYPE;
    } else if (type.equals(Long.TYPE.getName())) {
        return Type.LONG_TYPE;
    } else if (type.equals(Double.TYPE.getName())) {
        return Type.DOUBLE_TYPE;
    } else if (type.endsWith("[]")) {
        return getArrayType(type);
    } else {
        return Type.getObjectType(type.replace('.', '/'));
    }
}
 
Example 5
Source File: BuildStackInfoAdapter.java    From copper-engine with Apache License 2.0 6 votes vote down vote up
Type getArrayElementType(int type) {
    switch (type) {
        case T_BOOLEAN:
            return Type.BOOLEAN_TYPE;
        case T_BYTE:
            return Type.BYTE_TYPE;
        case T_CHAR:
            return Type.CHAR_TYPE;
        case T_DOUBLE:
            return Type.DOUBLE_TYPE;
        case T_FLOAT:
            return Type.FLOAT_TYPE;
        case T_INT:
            return Type.INT_TYPE;
        case T_LONG:
            return Type.LONG_TYPE;
        case T_SHORT:
            return Type.SHORT_TYPE;
    }
    throw new BuildStackFrameException("Illegal array type code: " + type);
}
 
Example 6
Source File: ConstantExpr.java    From maple-ir with GNU General Public License v3.0 5 votes vote down vote up
public ConstantExpr(Object cst, Type type, boolean check) {
	super(CONST_LOAD);
	
	if (cst instanceof ConstantExpr) {
		throw new IllegalArgumentException("nice try cowboy");
	}
	if(type == Type.BOOLEAN_TYPE) {
		throw new RuntimeException("TODO");
	}
	
	Type ctype = null;
	if(check) {
		if (!(cst == null && (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY))) {
			if (!type.equals(ctype = computeType(cst)) && !isAcceptableSupertype(ctype, type))
				throw new IllegalStateException(cst + ", " + type + ", " + ctype);
		}
	}
	
	if(cst instanceof Number && !TypeUtils.unboxType(cst).equals(type)) {
		if(ctype == null) {
			ctype = computeType(cst);
		}
		cst = TypeUtils.rebox((Number) cst, ctype);
		// throw new RuntimeException(String.format("rebox: %s (%s) to %s (%s)", cst, cst.getClass(), type, TypeUtils.rebox((Number)cst, computeType(cst)).getClass()));
	}

	this.cst = cst;
	this.type = type;
}
 
Example 7
Source File: TypeUtil.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * @param arg
 * 		Operand value of a NEWARRAY instruction.
 *
 * @return Array element type.
 */
public static Type newArrayArgToType(int arg) {
	switch(arg) {
		case 4: return Type.BOOLEAN_TYPE;
		case 5: return Type.CHAR_TYPE;
		case 6: return Type.FLOAT_TYPE;
		case 7: return Type.DOUBLE_TYPE;
		case 8: return Type.BYTE_TYPE;
		case 9: return Type.SHORT_TYPE;
		case 10: return Type.INT_TYPE;
		case 11: return Type.LONG_TYPE;
		default: break;
	}
	throw new IllegalArgumentException("Unexpected NEWARRAY arg: " + arg);
}
 
Example 8
Source File: ExpressionBooleanNot.java    From datakernel with Apache License 2.0 5 votes vote down vote up
@Override
public Type load(Context ctx) {
	GeneratorAdapter g = ctx.getGeneratorAdapter();
	Label labelFalse = g.newLabel();
	Label labelExit = g.newLabel();
	expression.load(ctx);
	g.ifZCmp(GeneratorAdapter.EQ, labelFalse);
	g.push(false);
	g.goTo(labelExit);
	g.visitLabel(labelFalse);
	g.push(true);
	g.visitLabel(labelExit);
	return Type.BOOLEAN_TYPE;
}
 
Example 9
Source File: ScottyMethodAdapter.java    From copper-engine with Apache License 2.0 5 votes vote down vote up
void pushLocals(StackInfo info) {
    super.visitIntInsn(SIPUSH, info.localsSize());
    super.visitTypeInsn(ANEWARRAY, "java/lang/Object");
    for (int i = 0; i < info.localsSize(); ++i) {
        Type t = info.getLocal(i);
        if (t != null) {
            super.visitInsn(DUP);
            super.visitIntInsn(SIPUSH, i);
            if (t == Type.BOOLEAN_TYPE || t == Type.BYTE_TYPE || t == Type.SHORT_TYPE || t == Type.INT_TYPE || t == Type.CHAR_TYPE) {
                super.visitVarInsn(ILOAD, i);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
            } else if (t == Type.FLOAT_TYPE) {
                super.visitVarInsn(FLOAD, i);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false);
            } else if (t == Type.LONG_TYPE) {
                super.visitVarInsn(LLOAD, i);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
            } else if (t == Type.DOUBLE_TYPE) {
                super.visitVarInsn(DLOAD, i);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
            } else if (t == StackInfo.AconstNullType) {
                super.visitInsn(ACONST_NULL);
            } else {
                super.visitVarInsn(ALOAD, i);
            }
            super.visitInsn(AASTORE);
        }
    }
}
 
Example 10
Source File: InstanceofExpr.java    From maple-ir with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Type getType() {
	return Type.BOOLEAN_TYPE;
}
 
Example 11
Source File: ConstantExpr.java    From maple-ir with GNU General Public License v3.0 4 votes vote down vote up
public static Type computeType(Object cst) {
		if (cst == null) {
			return Type.getType("Ljava/lang/Object;");
		} else if (cst instanceof Integer) {
			int val = ((Integer) cst).intValue();
			if (val >= Byte.MIN_VALUE && val <= Byte.MAX_VALUE) {
				return Type.BYTE_TYPE;
			} else if (val >= Short.MIN_VALUE && val <= Short.MAX_VALUE) {
				return Type.SHORT_TYPE;
			} else {
				return Type.INT_TYPE;
			}
//			return Type.INT_TYPE;
		} else if (cst instanceof Long) {
			return Type.LONG_TYPE;
		} else if (cst instanceof Float) {
			return Type.FLOAT_TYPE;
		} else if (cst instanceof Double) {
			return Type.DOUBLE_TYPE;
		} else if (cst instanceof String) {
			return Type.getType("Ljava/lang/String;");
		} else if (cst instanceof Type) {
			Type type = (Type) cst;
			if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
				return Type.getType("Ljava/lang/Class;");
			} else if (type.getSort() == Type.METHOD) {
				return Type.getType("Ljava/lang/invoke/MethodType;");
			} else {
				throw new RuntimeException("Invalid type: " + cst);
			}
		} else if (cst instanceof Handle) {
			return Type.getType("Ljava/lang/invoke/MethodHandle;");
		} else if (cst instanceof Boolean) {
			return Type.BOOLEAN_TYPE;
		} else if(cst instanceof Byte) {
			return Type.BYTE_TYPE;
		} else if (cst instanceof Character) {
			return Type.CHAR_TYPE;
		} else if(cst instanceof Short) {
			return Type.SHORT_TYPE;
		} else {
			throw new RuntimeException("Invalid type: " + cst);
		}
	}
 
Example 12
Source File: ConstantParameterPass.java    From maple-ir with GNU General Public License v3.0 4 votes vote down vote up
private void inlineConstant(ControlFlowGraph cfg, int argLocalIndex, Object o) {
	/* we don't actually demote the synthetic copy
	 * here as we would also need to change the
	 * method desc and we can't do that until
	 * later so we defer it. */
	LocalsPool pool = cfg.getLocals();

	/* create the spill variable but not the
	 * actual definition yet. */
	VersionedLocal argLocal = pool.get(argLocalIndex, 0, false);
	VersionedLocal spill = pool.makeLatestVersion(argLocal);

	AbstractCopyStmt synthParamCopy = pool.defs.get(argLocal);
	ConstantExpr rhsVal = new ConstantExpr(o, synthParamCopy.getType() == Type.BOOLEAN_TYPE ? Type.BYTE_TYPE : synthParamCopy.getType());
	
	/* we have to maintain local references in
	 * phis as opposed to direct constant refs,
	 * so we go through every use of the argLocal
	 * and either replace it with the constant or
	 * a reference to the spill local if it is in
	 * a phi. */

	Set<VarExpr> spillUses = new HashSet<>();
	boolean requireSpill = false;
	
	Iterator<VarExpr> it = pool.uses.get(argLocal).iterator();
	while(it.hasNext()) {
		VarExpr v = it.next();
		if(v.getParent() == null) {
			/* the use is in a phi, we can't
			 * remove the def. 
			 * 
			 * we also replace the old var
			 * with the new spill one so we
			 * have to add this as a use of
			 * the new spill local. */
			spillUses.add(v);
			v.setLocal(spill);
			
			requireSpill = true;
		} else {
			CodeUnit par = v.getParent();
			par.writeAt(rhsVal.copy(), par.indexOf(v));
		}
		
		/* this use is no longer associated
		 * with the old argLocal. */
		it.remove();
	}
	
	if(pool.uses.get(argLocal).size() != 0) {
		throw new IllegalStateException(String.format("l:%s, uses:%s", argLocal, pool.uses.get(argLocal)));
	}
	
	if(requireSpill) {
		/* generate the copy for the spill (v = const) */
		CopyVarStmt spillCopy = new CopyVarStmt(new VarExpr(spill, synthParamCopy.getVariable().getType()), rhsVal);
		synthParamCopy.getBlock().add(spillCopy);
		
		/* initialise data entries for the new spill
		 * variable. */
		pool.defs.put(spill, spillCopy);
		pool.uses.put(spill, spillUses);
	}
}
 
Example 13
Source File: ABICompilerClassVisitor.java    From AVM with MIT License 4 votes vote down vote up
private void callTheDecoder(MethodVisitor methodVisitor, Type type) {
    if (type == Type.BYTE_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneByte", "()B", false);
    } else if (type == Type.BOOLEAN_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneBoolean", "()Z", false);
    } else if (type == Type.CHAR_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneCharacter", "()C", false);
    } else if (type == Type.SHORT_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneShort", "()S", false);
    } else if (type == Type.INT_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneInteger", "()I", false);
    } else if (type == Type.LONG_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneLong", "()J", false);
    } else if (type == Type.FLOAT_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneFloat", "()F", false);
    } else if (type == Type.DOUBLE_TYPE) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneDouble", "()D", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.BYTE_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneByteArray", "()[B", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.BOOLEAN_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneBooleanArray", "()[Z", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.CHAR_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneCharacterArray", "()[C", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.SHORT_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneShortArray", "()[S", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.INT_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneIntegerArray", "()[I", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.LONG_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneLongArray", "()[J", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.FLOAT_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneFloatArray", "()[F", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.DOUBLE_TYPE, 1)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneDoubleArray", "()[D", false);
    } else if (isString(type)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneString", "()Ljava/lang/String;", false);
    } else if (isAddress(type)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneAddress", "()Lavm/Address;", false);
    } else if(isBigInteger(type)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneBigInteger", "()Ljava/math/BigInteger;", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.BYTE_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DByteArray", "()[[B", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.BOOLEAN_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DBooleanArray", "()[[Z", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.CHAR_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DCharacterArray", "()[[C", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.SHORT_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DShortArray", "()[[S", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.INT_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DIntegerArray", "()[[I", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.LONG_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DLongArray", "()[[J", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.FLOAT_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DFloatArray", "()[[F", false);
    } else if (isArrayOfTypeAndDimensions(type, Type.DOUBLE_TYPE, 2)) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOne2DDoubleArray", "()[[D", false);
    } else if (type.getSort() == Type.ARRAY && type.getDimensions() == 1 && isString(type.getElementType())) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneStringArray", "()[Ljava/lang/String;", false);
    } else if (type.getSort() == Type.ARRAY && type.getDimensions() == 1 && isAddress(type.getElementType())) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneAddressArray", "()[Lavm/Address;", false);
    } else if(type.getSort() == Type.ARRAY && type.getDimensions() == 1 && isBigInteger(type.getElementType())) {
        methodVisitor.visitMethodInsn(INVOKEVIRTUAL, "org/aion/avm/userlib/abi/ABIDecoder", "decodeOneBigIntegerArray", "()[Ljava/math/BigInteger;", false);
    } else {
        throw new ABICompilerException("Need to decode an unsupported ABI type");
    }
}
 
Example 14
Source File: ScottyMethodAdapter.java    From copper-engine with Apache License 2.0 4 votes vote down vote up
void recreateLocals(StackInfo info) {
    if (info.localsSize() == 0)
        return;
    visitVarInsn(ALOAD, 0);
    visitFieldInsn(GETFIELD, currentClassName, "__stack", "Ljava/util/Stack;");
    visitVarInsn(ALOAD, 0);
    visitFieldInsn(GETFIELD, currentClassName, "__stackPosition", "I");
    visitMethodInsn(INVOKEVIRTUAL, "java/util/Stack", "get", "(I)Ljava/lang/Object;");
    visitTypeInsn(CHECKCAST, "org/copperengine/core/StackEntry");
    visitFieldInsn(GETFIELD, "org/copperengine/core/StackEntry", "locals", "[Ljava/lang/Object;");
    for (int i = 0; i < info.localsSize(); ++i) {
        Type t = info.getLocal(i);
        if (t != null) {
            if (t != StackInfo.AconstNullType) {
                super.visitInsn(DUP);
                super.visitIntInsn(SIPUSH, i);
                super.visitInsn(AALOAD);
            } else {
                super.visitInsn(ACONST_NULL);
            }
            if (t == Type.BOOLEAN_TYPE || t == Type.BYTE_TYPE || t == Type.SHORT_TYPE || t == Type.INT_TYPE || t == Type.CHAR_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Integer.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
                super.visitVarInsn(ISTORE, i);
            } else if (t == Type.FLOAT_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Float.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false);
                super.visitVarInsn(FSTORE, i);
            } else if (t == Type.LONG_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Long.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
                super.visitVarInsn(LSTORE, i);
            } else if (t == Type.DOUBLE_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Double.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
                super.visitVarInsn(DSTORE, i);
            } else {
                if (!t.getInternalName().equals(Type.getInternalName(Object.class)) && t != StackInfo.AconstNullType)
                    super.visitTypeInsn(CHECKCAST, t.getInternalName());
                super.visitVarInsn(ASTORE, i);
            }
        }
    }
    visitInsn(POP);
}
 
Example 15
Source File: ScottyMethodAdapter.java    From copper-engine with Apache License 2.0 4 votes vote down vote up
void pushStack(StackInfo info) {
    super.visitIntInsn(SIPUSH, info.stackSize());
    super.visitTypeInsn(ANEWARRAY, "java/lang/Object");
    for (int i = info.stackSize() - 1; i >= 0; --i) {
        Type t = info.getStack(i);
        if (t != null) {
            if (t == Type.BOOLEAN_TYPE || t == Type.BYTE_TYPE || t == Type.SHORT_TYPE || t == Type.INT_TYPE || t == Type.CHAR_TYPE) {
                super.visitInsn(DUP_X1);
                super.visitInsn(SWAP);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
                super.visitIntInsn(SIPUSH, i);
                super.visitInsn(SWAP);
            } else if (t == Type.FLOAT_TYPE) {
                super.visitInsn(DUP_X1);
                super.visitInsn(SWAP);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false);
                super.visitIntInsn(SIPUSH, i);
                super.visitInsn(SWAP);
            } else if (t == Type.LONG_TYPE) {
                super.visitInsn(DUP_X2);
                super.visitInsn(DUP_X2);
                super.visitInsn(POP);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
                super.visitIntInsn(SIPUSH, i);
                super.visitInsn(SWAP);
            } else if (t == Type.DOUBLE_TYPE) {
                super.visitInsn(DUP_X2);
                super.visitInsn(DUP_X2);
                super.visitInsn(POP);
                super.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
                super.visitIntInsn(SIPUSH, i);
                super.visitInsn(SWAP);
            } else {
                super.visitInsn(DUP_X1);
                super.visitInsn(SWAP);
                super.visitIntInsn(SIPUSH, i);
                super.visitInsn(SWAP);
            }
            super.visitInsn(AASTORE);
        }
    }
}
 
Example 16
Source File: ScottyMethodAdapter.java    From copper-engine with Apache License 2.0 4 votes vote down vote up
private void recreateStack(StackInfo info) {
    if (info.stackSize() == 0)
        return;
    visitVarInsn(ALOAD, 0);
    visitFieldInsn(GETFIELD, currentClassName, "__stack", "Ljava/util/Stack;");
    visitVarInsn(ALOAD, 0);
    visitFieldInsn(GETFIELD, currentClassName, "__stackPosition", "I");
    visitMethodInsn(INVOKEVIRTUAL, "java/util/Stack", "get", "(I)Ljava/lang/Object;");
    visitTypeInsn(CHECKCAST, "org/copperengine/core/StackEntry");
    visitFieldInsn(GETFIELD, "org/copperengine/core/StackEntry", "stack", "[Ljava/lang/Object;");
    for (int i = 0; i < info.stackSize(); ++i) {
        Type t = info.getStack(i);
        if (t != null) {
            if (t != StackInfo.AconstNullType) {
                super.visitInsn(DUP);
                super.visitIntInsn(SIPUSH, i);
                super.visitInsn(AALOAD);
            } else {
                super.visitInsn(ACONST_NULL);
            }
            if (t == Type.BOOLEAN_TYPE || t == Type.BYTE_TYPE || t == Type.SHORT_TYPE || t == Type.INT_TYPE || t == Type.CHAR_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Integer.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Integer", "intValue", "()I", false);
                super.visitInsn(SWAP);
            } else if (t == Type.FLOAT_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Float.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Float", "floatValue", "()F", false);
                super.visitInsn(SWAP);
            } else if (t == Type.LONG_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Long.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Long", "longValue", "()J", false);
                super.visitInsn(DUP2_X1);
                super.visitInsn(POP2);
            } else if (t == Type.DOUBLE_TYPE) {
                super.visitTypeInsn(CHECKCAST, Type.getInternalName(Double.class));
                super.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D", false);
                super.visitInsn(DUP2_X1);
                super.visitInsn(POP2);
            } else {
                if (!t.getInternalName().equals(Type.getInternalName(Object.class)) && t != StackInfo.AconstNullType)
                    super.visitTypeInsn(CHECKCAST, t.getInternalName());
                super.visitInsn(SWAP);
            }
        }
    }
    super.visitInsn(POP);
}