Search in sources :

Example 6 with PoolConstant

use of com.oracle.truffle.espresso.classfile.constantpool.PoolConstant in project graal by oracle.

the class BytecodeNode method putPoolConstant.

private void putPoolConstant(VirtualFrame frame, int top, char cpi, int opcode) {
    assert opcode == LDC || opcode == LDC_W || opcode == LDC2_W;
    RuntimeConstantPool pool = getConstantPool();
    PoolConstant constant = pool.at(cpi);
    if (constant instanceof IntegerConstant) {
        assert opcode == LDC || opcode == LDC_W;
        putInt(frame, top, ((IntegerConstant) constant).value());
    } else if (constant instanceof LongConstant) {
        assert opcode == LDC2_W;
        putLong(frame, top, ((LongConstant) constant).value());
    } else if (constant instanceof DoubleConstant) {
        assert opcode == LDC2_W;
        putDouble(frame, top, ((DoubleConstant) constant).value());
    } else if (constant instanceof FloatConstant) {
        assert opcode == LDC || opcode == LDC_W;
        putFloat(frame, top, ((FloatConstant) constant).value());
    } else if (constant instanceof StringConstant) {
        assert opcode == LDC || opcode == LDC_W;
        StaticObject internedString = pool.resolvedStringAt(cpi);
        putObject(frame, top, internedString);
    } else if (constant instanceof ClassConstant) {
        assert opcode == LDC || opcode == LDC_W;
        Klass klass = pool.resolvedKlassAt(getDeclaringKlass(), cpi);
        putObject(frame, top, klass.mirror());
    } else if (constant instanceof MethodHandleConstant) {
        assert opcode == LDC || opcode == LDC_W;
        StaticObject methodHandle = pool.resolvedMethodHandleAt(getDeclaringKlass(), cpi);
        putObject(frame, top, methodHandle);
    } else if (constant instanceof MethodTypeConstant) {
        assert opcode == LDC || opcode == LDC_W;
        StaticObject methodType = pool.resolvedMethodTypeAt(getDeclaringKlass(), cpi);
        putObject(frame, top, methodType);
    } else if (constant instanceof DynamicConstant) {
        DynamicConstant.Resolved dynamicConstant = pool.resolvedDynamicConstantAt(getDeclaringKlass(), cpi);
        dynamicConstant.putResolved(frame, top, this);
    } else {
        CompilerDirectives.transferToInterpreter();
        throw EspressoError.unimplemented(constant.toString());
    }
}
Also used : LongConstant(com.oracle.truffle.espresso.classfile.constantpool.LongConstant) DoubleConstant(com.oracle.truffle.espresso.classfile.constantpool.DoubleConstant) PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant) FloatConstant(com.oracle.truffle.espresso.classfile.constantpool.FloatConstant) MethodHandleConstant(com.oracle.truffle.espresso.classfile.constantpool.MethodHandleConstant) IntegerConstant(com.oracle.truffle.espresso.classfile.constantpool.IntegerConstant) InvokeDynamicConstant(com.oracle.truffle.espresso.classfile.constantpool.InvokeDynamicConstant) DynamicConstant(com.oracle.truffle.espresso.classfile.constantpool.DynamicConstant) RuntimeConstantPool(com.oracle.truffle.espresso.classfile.RuntimeConstantPool) Klass(com.oracle.truffle.espresso.impl.Klass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) StringConstant(com.oracle.truffle.espresso.classfile.constantpool.StringConstant) ClassConstant(com.oracle.truffle.espresso.classfile.constantpool.ClassConstant) MethodTypeConstant(com.oracle.truffle.espresso.classfile.constantpool.MethodTypeConstant)

Example 7 with PoolConstant

use of com.oracle.truffle.espresso.classfile.constantpool.PoolConstant in project graal by oracle.

the class ConstantPoolImpl method getRawBytes.

@Override
public byte[] getRawBytes() {
    byte[] bytes = new byte[totalPoolBytes];
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    for (PoolConstant pc : constants) {
        pc.dumpBytes(bb);
    }
    return bytes;
}
Also used : PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant) ByteBuffer(java.nio.ByteBuffer)

Example 8 with PoolConstant

use of com.oracle.truffle.espresso.classfile.constantpool.PoolConstant in project graal by oracle.

the class MethodVerifier method verifyPutField.

private void verifyPutField(int bci, OperandStack stack, int curOpcode) {
    // Check CP validity
    PoolConstant pc = poolAt(code.readCPI(bci));
    verifyGuarantee(pc.tag() == ConstantPool.Tag.FIELD_REF, "Invalid CP constant for PUTFIELD: " + pc.toString());
    pc.validate(pool);
    // Obtain field info
    FieldRefConstant frc = (FieldRefConstant) pc;
    assert Validation.validFieldDescriptor(frc.getType(pool));
    Symbol<Type> fieldDesc = frc.getType(pool);
    Operand toPut = stack.pop(kindToOperand(fieldDesc));
    checkInit(toPut);
    if (curOpcode == PUTFIELD) {
        // Pop and check verifier
        assert Validation.validClassNameEntry(frc.getHolderKlassName(pool));
        Symbol<Type> fieldHolderType = getTypes().fromName(frc.getHolderKlassName(pool));
        Operand fieldHolder = kindToOperand(fieldHolderType);
        Operand receiver = checkInitAccess(stack.popRef(fieldHolder), fieldHolder);
        verifyGuarantee(!receiver.isArrayType(), "Trying to access field of an array type: " + receiver);
        if (!receiver.isUninitThis()) {
            checkProtectedMember(receiver, fieldHolderType, frc, false);
        }
    }
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) FieldRefConstant(com.oracle.truffle.espresso.classfile.constantpool.FieldRefConstant) PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant)

Example 9 with PoolConstant

use of com.oracle.truffle.espresso.classfile.constantpool.PoolConstant in project graal by oracle.

the class MethodVerifier method getTypeFromPool.

private Symbol<Type> getTypeFromPool(int c, String s) {
    PoolConstant pc = poolAt(c);
    verifyGuarantee(pc.tag() == CLASS, s + pc.toString());
    pc.validate(pool);
    ClassConstant cc = (ClassConstant) pc;
    assert Validation.validClassNameEntry(cc.getName(pool));
    Symbol<Type> type = getTypes().fromName(cc.getName(pool));
    return type;
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant) ClassConstant(com.oracle.truffle.espresso.classfile.constantpool.ClassConstant)

Example 10 with PoolConstant

use of com.oracle.truffle.espresso.classfile.constantpool.PoolConstant in project graal by oracle.

the class MethodVerifier method verifyGetField.

private void verifyGetField(int bci, OperandStack stack, int curOpcode) {
    // Check CP validity
    PoolConstant pc = poolAt(code.readCPI(bci));
    verifyGuarantee(pc.tag() == ConstantPool.Tag.FIELD_REF, "Invalid CP constant for GETFIELD: " + pc.toString());
    pc.validate(pool);
    // Obtain field info
    FieldRefConstant frc = (FieldRefConstant) pc;
    assert Validation.validFieldDescriptor(frc.getType(pool));
    Symbol<Type> type = frc.getType(pool);
    if (curOpcode == GETFIELD) {
        // Pop and check receiver
        assert Validation.validClassNameEntry(frc.getHolderKlassName(pool));
        Symbol<Type> fieldHolderType = getTypes().fromName(frc.getHolderKlassName(pool));
        Operand fieldHolder = kindToOperand(fieldHolderType);
        Operand receiver = checkInitAccess(stack.popRef(fieldHolder), fieldHolder);
        checkProtectedMember(receiver, fieldHolderType, frc, false);
        verifyGuarantee(!receiver.isArrayType(), "Trying to access field of an array type: " + receiver);
    }
    // push result
    Operand op = kindToOperand(type);
    stack.push(op);
}
Also used : Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) FieldRefConstant(com.oracle.truffle.espresso.classfile.constantpool.FieldRefConstant) PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant)

Aggregations

PoolConstant (com.oracle.truffle.espresso.classfile.constantpool.PoolConstant)11 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)3 ClassConstant (com.oracle.truffle.espresso.classfile.constantpool.ClassConstant)2 FieldRefConstant (com.oracle.truffle.espresso.classfile.constantpool.FieldRefConstant)2 InvokeDynamicConstant (com.oracle.truffle.espresso.classfile.constantpool.InvokeDynamicConstant)2 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)1 DoubleConstant (com.oracle.truffle.espresso.classfile.constantpool.DoubleConstant)1 DynamicConstant (com.oracle.truffle.espresso.classfile.constantpool.DynamicConstant)1 FloatConstant (com.oracle.truffle.espresso.classfile.constantpool.FloatConstant)1 IntegerConstant (com.oracle.truffle.espresso.classfile.constantpool.IntegerConstant)1 LongConstant (com.oracle.truffle.espresso.classfile.constantpool.LongConstant)1 MethodHandleConstant (com.oracle.truffle.espresso.classfile.constantpool.MethodHandleConstant)1 MethodRefConstant (com.oracle.truffle.espresso.classfile.constantpool.MethodRefConstant)1 MethodTypeConstant (com.oracle.truffle.espresso.classfile.constantpool.MethodTypeConstant)1 StringConstant (com.oracle.truffle.espresso.classfile.constantpool.StringConstant)1 Utf8Constant (com.oracle.truffle.espresso.classfile.constantpool.Utf8Constant)1 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)1 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)1 Klass (com.oracle.truffle.espresso.impl.Klass)1 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)1