Search in sources :

Example 1 with FieldRefConstant

use of com.oracle.truffle.espresso.classfile.constantpool.FieldRefConstant 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 2 with FieldRefConstant

use of com.oracle.truffle.espresso.classfile.constantpool.FieldRefConstant 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)

Example 3 with FieldRefConstant

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

the class MethodVerifier method checkProtectedMember.

// Helper methods
private void checkProtectedMember(Operand stackOp, Symbol<Type> holderType, MemberRefConstant mrc, boolean method) {
    /*
         * 4.10.1.8.
         *
         * If the name of a class is not the name of any superclass, it cannot be a superclass, and
         * so it can safely be ignored.
         */
    if (stackOp.getType() == thisKlass.getType()) {
        return;
    }
    /*
         * If the MemberClassName is the same as the name of a superclass, the class being resolved
         * may indeed be a superclass. In this case, if no superclass named MemberClassName in a
         * different run-time package has a protected member named MemberName with descriptor
         * MemberDescriptor, the protected check does not apply.
         */
    Klass superKlass = thisKlass.getSuperKlass();
    while (superKlass != null) {
        if (superKlass.getType() == holderType) {
            Operand holderOp = kindToOperand(holderType);
            Member<?> member;
            if (method) {
                /* Non-failing method lookup. */
                member = holderOp.getKlass().lookupMethod(mrc.getName(pool), ((MethodRefConstant) mrc).getSignature(pool));
            } else {
                /* Non-failing field lookup. */
                member = holderOp.getKlass().lookupField(mrc.getName(pool), ((FieldRefConstant) mrc).getType(pool));
            }
            /*
                 * If there does exist a protected superclass member in a different run-time
                 * package, then load MemberClassName; if the member in question is not protected,
                 * the check does not apply. (Using a superclass member that is not protected is
                 * trivially correct.)
                 */
            if (member == null || !member.isProtected()) {
                return;
            }
            if (!thisKlass.getRuntimePackage().contentEquals(Types.getRuntimePackage(holderType))) {
                if (method) {
                    if (stackOp.isArrayType() && Type.java_lang_Object.equals(holderType) && Name.clone.equals(member.getName())) {
                        // Special case: Arrays pretend to implement Object.clone().
                        return;
                    }
                }
                verifyGuarantee(stackOp.compliesWith(thisOperand), "Illegal protected field access");
            }
            return;
        }
        superKlass = superKlass.getSuperKlass();
    }
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) FieldRefConstant(com.oracle.truffle.espresso.classfile.constantpool.FieldRefConstant) MethodRefConstant(com.oracle.truffle.espresso.classfile.constantpool.MethodRefConstant)

Aggregations

FieldRefConstant (com.oracle.truffle.espresso.classfile.constantpool.FieldRefConstant)3 PoolConstant (com.oracle.truffle.espresso.classfile.constantpool.PoolConstant)2 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)2 MethodRefConstant (com.oracle.truffle.espresso.classfile.constantpool.MethodRefConstant)1 Klass (com.oracle.truffle.espresso.impl.Klass)1