Search in sources :

Example 1 with PoolConstant

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

the class ConstantPool method toString.

// endregion unresolved constants
@Override
public String toString() {
    Formatter buf = new Formatter();
    for (int i = 0; i < length(); i++) {
        PoolConstant c = at(i);
        buf.format("#%d = %-15s // %s%n", i, c.tag(), c.toString(this));
    }
    return buf.toString();
}
Also used : Formatter(java.util.Formatter) PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant)

Example 2 with PoolConstant

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

the class ConstantPoolImpl method patchForHiddenClass.

@Override
ConstantPool patchForHiddenClass(int thisKlassIndex, Symbol<?> newName) {
    int newNamePos = constants.length;
    Utf8Constant newNameConstant = new Utf8Constant(newName);
    PoolConstant[] newEntries = Arrays.copyOf(constants, constants.length + 1);
    newEntries[newNamePos] = newNameConstant;
    newEntries[thisKlassIndex] = ClassConstant.create(newNamePos);
    int rawLengthIncrease = 2 + /* u2 length */
    newName.length();
    return new ConstantPoolImpl(newEntries, majorVersion, minorVersion, totalPoolBytes + rawLengthIncrease);
}
Also used : PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant) Utf8Constant(com.oracle.truffle.espresso.classfile.constantpool.Utf8Constant)

Example 3 with PoolConstant

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

the class MethodVerifier method getMethodRefConstant.

private MethodRefConstant getMethodRefConstant(int bci) {
    PoolConstant pc = poolAt(code.readCPI(bci));
    verifyGuarantee(pc instanceof MethodRefConstant, "Invalid CP constant for a MethodRef: " + pc.getClass().getName());
    pc.validate(pool);
    return (MethodRefConstant) pc;
}
Also used : PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant) MethodRefConstant(com.oracle.truffle.espresso.classfile.constantpool.MethodRefConstant)

Example 4 with PoolConstant

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

the class MethodVerifier method verifyInvokeDynamic.

private void verifyInvokeDynamic(int bci, OperandStack stack) {
    // Check padding
    verifyGuarantee(code.readByte(bci + 2) == 0 && code.readByte(bci + 3) == 0, "bytes 3 and 4 after invokedynamic must be 0.");
    PoolConstant pc = poolAt(code.readCPI(bci));
    // Check CP validity
    verifyGuarantee(pc.tag() == ConstantPool.Tag.INVOKEDYNAMIC, "Invalid CP constant for INVOKEDYNAMIC: " + pc.toString());
    pc.validate(pool);
    InvokeDynamicConstant idc = (InvokeDynamicConstant) pc;
    Symbol<Name> name = idc.getName(pool);
    // Check invokedynamic does not call initializers
    verifyGuarantee(!isInstanceInit(name) && !isClassInit(name), "Invalid bootstrap method name: " + name);
    // Check and pop arguments
    Operand[] parsedSig = getOperandSig(idc.getSignature(pool));
    assert parsedSig.length > 0 : "Empty descriptor for method";
    for (int i = parsedSig.length - 2; i >= 0; i--) {
        stack.pop(parsedSig[i]);
    }
    // push result
    Operand returnKind = parsedSig[parsedSig.length - 1];
    if (returnKind != Void) {
        stack.push(returnKind);
    }
}
Also used : PoolConstant(com.oracle.truffle.espresso.classfile.constantpool.PoolConstant) InvokeDynamicConstant(com.oracle.truffle.espresso.classfile.constantpool.InvokeDynamicConstant) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 5 with PoolConstant

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

the class ClassRedefinition method isSame.

private static boolean isSame(BytecodeStream oldCode, ConstantPool oldPool, BytecodeStream newCode, ConstantPool newPool) {
    int bci;
    int nextBCI = 0;
    while (nextBCI < oldCode.endBCI()) {
        bci = nextBCI;
        int opcode = oldCode.currentBC(bci);
        nextBCI = oldCode.nextBCI(bci);
        if (opcode == Bytecodes.LDC || opcode == Bytecodes.LDC2_W || opcode == Bytecodes.LDC_W || opcode == Bytecodes.NEW || opcode == Bytecodes.INVOKEDYNAMIC || opcode == Bytecodes.GETFIELD || opcode == Bytecodes.GETSTATIC || opcode == Bytecodes.PUTFIELD || opcode == Bytecodes.PUTSTATIC || Bytecodes.isInvoke(opcode)) {
            int oldCPI = oldCode.readCPI(bci);
            PoolConstant oldConstant = oldPool.at(oldCPI);
            int newCPI = newCode.readCPI(bci);
            PoolConstant newConstant = newPool.at(newCPI);
            if (!oldConstant.toString(oldPool).equals(newConstant.toString(newPool))) {
                return false;
            }
        }
    }
    return true;
}
Also used : 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