Search in sources :

Example 1 with InvokeHandleNode

use of com.oracle.truffle.espresso.nodes.quick.invoke.InvokeHandleNode in project graal by oracle.

the class BytecodeNode method dispatchQuickened.

// endregion quickenForeign
private BaseQuickNode dispatchQuickened(int top, int curBCI, char cpi, int opcode, int statementIndex, Method resolutionSeed, boolean allowFieldAccessInlining) {
    assert !allowFieldAccessInlining || getContext().InlineFieldAccessors;
    BaseQuickNode invoke;
    Method resolved = resolutionSeed;
    switch(opcode) {
        case INVOKESTATIC:
            // instruction throws an IncompatibleClassChangeError.
            if (!resolved.isStatic()) {
                CompilerDirectives.transferToInterpreter();
                Meta meta = getMeta();
                throw meta.throwException(meta.java_lang_IncompatibleClassChangeError);
            }
            break;
        case INVOKEINTERFACE:
            // invokeinterface instruction throws an IncompatibleClassChangeError.
            if (resolved.isStatic() || (getContext().getJavaVersion().java8OrEarlier() && resolved.isPrivate())) {
                CompilerDirectives.transferToInterpreter();
                Meta meta = getMeta();
                throw meta.throwException(meta.java_lang_IncompatibleClassChangeError);
            }
            break;
        case INVOKEVIRTUAL:
            // instruction throws an IncompatibleClassChangeError.
            if (resolved.isStatic()) {
                CompilerDirectives.transferToInterpreter();
                Meta meta = getMeta();
                throw meta.throwException(meta.java_lang_IncompatibleClassChangeError);
            }
            break;
        case INVOKESPECIAL:
            // instruction, a NoSuchMethodError is thrown.
            if (resolved.isConstructor()) {
                if (resolved.getDeclaringKlass().getName() != getConstantPool().methodAt(cpi).getHolderKlassName(getConstantPool())) {
                    CompilerDirectives.transferToInterpreter();
                    Meta meta = getMeta();
                    throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, meta.toGuestString(resolved.getDeclaringKlass().getNameAsString() + "." + resolved.getName() + resolved.getRawSignature()));
                }
            }
            // instruction throws an IncompatibleClassChangeError.
            if (resolved.isStatic()) {
                CompilerDirectives.transferToInterpreter();
                Meta meta = getMeta();
                throw meta.throwException(meta.java_lang_IncompatibleClassChangeError);
            }
            // version of the class file.
            if (!resolved.isConstructor()) {
                Klass declaringKlass = getMethod().getDeclaringKlass();
                Klass symbolicRef = ((MethodRefConstant.Indexes) getConstantPool().methodAt(cpi)).getResolvedHolderKlass(declaringKlass, getConstantPool());
                if (!symbolicRef.isInterface() && symbolicRef != declaringKlass && declaringKlass.getSuperKlass() != null && symbolicRef != declaringKlass.getSuperKlass() && symbolicRef.isAssignableFrom(declaringKlass)) {
                    resolved = declaringKlass.getSuperKlass().lookupMethod(resolved.getName(), resolved.getRawSignature(), declaringKlass);
                }
            }
            break;
        default:
            CompilerDirectives.transferToInterpreter();
            throw EspressoError.unimplemented("Quickening for " + Bytecodes.nameOf(opcode));
    }
    if (allowFieldAccessInlining && resolved.isInlinableGetter()) {
        invoke = InlinedGetterNode.create(resolved, top, opcode, curBCI, statementIndex);
    } else if (allowFieldAccessInlining && resolved.isInlinableSetter()) {
        invoke = InlinedSetterNode.create(resolved, top, opcode, curBCI, statementIndex);
    } else if (resolved.isPolySignatureIntrinsic()) {
        invoke = new InvokeHandleNode(resolved, getDeclaringKlass(), top, curBCI);
    } else if (opcode == INVOKEINTERFACE && resolved.getITableIndex() < 0) {
        if (resolved.isPrivate()) {
            assert getJavaVersion().java9OrLater();
            // Interface private methods do not appear in itables.
            invoke = new InvokeSpecialQuickNode(resolved, top, curBCI);
        } else {
            // Can happen in old classfiles that calls j.l.Object on interfaces.
            invoke = new InvokeVirtualQuickNode(resolved, top, curBCI);
        }
    } else if (opcode == INVOKEVIRTUAL && (resolved.isFinalFlagSet() || resolved.getDeclaringKlass().isFinalFlagSet() || resolved.isPrivate())) {
        invoke = new InvokeSpecialQuickNode(resolved, top, curBCI);
    } else {
        // @formatter:off
        switch(opcode) {
            case INVOKESTATIC:
                invoke = new InvokeStaticQuickNode(resolved, top, curBCI);
                break;
            case INVOKEINTERFACE:
                invoke = new InvokeInterfaceQuickNode(resolved, top, curBCI);
                break;
            case INVOKEVIRTUAL:
                invoke = new InvokeVirtualQuickNode(resolved, top, curBCI);
                break;
            case INVOKESPECIAL:
                invoke = new InvokeSpecialQuickNode(resolved, top, curBCI);
                break;
            default:
                CompilerDirectives.transferToInterpreter();
                throw EspressoError.unimplemented("Quickening for " + Bytecodes.nameOf(opcode));
        }
    // @formatter:on
    }
    return invoke;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) InvokeStaticQuickNode(com.oracle.truffle.espresso.nodes.quick.invoke.InvokeStaticQuickNode) InvokeHandleNode(com.oracle.truffle.espresso.nodes.quick.invoke.InvokeHandleNode) BaseQuickNode(com.oracle.truffle.espresso.nodes.quick.BaseQuickNode) Method(com.oracle.truffle.espresso.impl.Method) InvokeVirtualQuickNode(com.oracle.truffle.espresso.nodes.quick.invoke.InvokeVirtualQuickNode) InvokeSpecialQuickNode(com.oracle.truffle.espresso.nodes.quick.invoke.InvokeSpecialQuickNode) InvokeInterfaceQuickNode(com.oracle.truffle.espresso.nodes.quick.invoke.InvokeInterfaceQuickNode)

Aggregations

ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)1 Klass (com.oracle.truffle.espresso.impl.Klass)1 Method (com.oracle.truffle.espresso.impl.Method)1 Meta (com.oracle.truffle.espresso.meta.Meta)1 BaseQuickNode (com.oracle.truffle.espresso.nodes.quick.BaseQuickNode)1 InvokeHandleNode (com.oracle.truffle.espresso.nodes.quick.invoke.InvokeHandleNode)1 InvokeInterfaceQuickNode (com.oracle.truffle.espresso.nodes.quick.invoke.InvokeInterfaceQuickNode)1 InvokeSpecialQuickNode (com.oracle.truffle.espresso.nodes.quick.invoke.InvokeSpecialQuickNode)1 InvokeStaticQuickNode (com.oracle.truffle.espresso.nodes.quick.invoke.InvokeStaticQuickNode)1 InvokeVirtualQuickNode (com.oracle.truffle.espresso.nodes.quick.invoke.InvokeVirtualQuickNode)1