Search in sources :

Example 36 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class MHLinkToNode method call.

@Override
public Object call(Object[] args) {
    assert (getMethod().isStatic());
    Method.MethodVersion resolutionSeed = getTarget(args);
    Object[] basicArgs = unbasic(args, resolutionSeed.getMethod().getParsedSignature(), 0, argCount - 1, hasReceiver);
    // method might have been redefined or removed by redefinition
    if (!resolutionSeed.getRedefineAssumption().isValid()) {
        if (resolutionSeed.getMethod().isRemovedByRedefition()) {
            Klass receiverKlass = hasReceiver ? ((StaticObject) basicArgs[0]).getKlass() : resolutionSeed.getMethod().getDeclaringKlass();
            resolutionSeed = resolutionSeed.getMethod().getContext().getClassRedefinition().handleRemovedMethod(resolutionSeed.getMethod(), receiverKlass).getMethodVersion();
        }
    }
    Method target = linker.linkTo(resolutionSeed.getMethod(), args);
    Object result = executeCall(basicArgs, target.getMethodVersion());
    return rebasic(result, target.getReturnKind());
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method)

Example 37 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class Substitutions method registerStaticSubstitution.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static void registerStaticSubstitution(JavaSubstitution.Factory substitutorFactory) {
    List<Symbol<Type>> parameterTypes = new ArrayList<>();
    for (int i = substitutorFactory.hasReceiver() ? 1 : 0; i < substitutorFactory.parameterTypes().length; i++) {
        String type = substitutorFactory.parameterTypes()[i];
        parameterTypes.add(StaticSymbols.putType(type));
    }
    Symbol<Type> returnType = StaticSymbols.putType(substitutorFactory.returnType());
    Symbol<Signature> signature = StaticSymbols.putSignature(returnType, parameterTypes.toArray(Symbol.EMPTY_ARRAY));
    EspressoRootNodeFactory factory = new EspressoRootNodeFactory() {

        @Override
        public EspressoRootNode createNodeIfValid(Method methodToSubstitute, boolean forceValid) {
            if (!substitutorFactory.isValidFor(methodToSubstitute.getJavaVersion())) {
                return null;
            }
            StaticObject classLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
            if (forceValid || ClassRegistry.loaderIsBootOrPlatform(classLoader, methodToSubstitute.getMeta())) {
                return EspressoRootNode.create(null, new IntrinsicSubstitutorNode(substitutorFactory, methodToSubstitute));
            }
            getLogger().warning(new Supplier<String>() {

                @Override
                public String get() {
                    StaticObject givenLoader = methodToSubstitute.getDeclaringKlass().getDefiningClassLoader();
                    return "Static substitution for " + methodToSubstitute + " does not apply.\n" + "\tExpected class loader: Boot (null) or platform class loader\n" + "\tGiven class loader: " + EspressoInterop.toDisplayString(givenLoader, false) + "\n";
                }
            });
            return null;
        }
    };
    String[] classNames = substitutorFactory.substitutionClassNames();
    String[] methodNames = substitutorFactory.getMethodNames();
    for (int i = 0; i < classNames.length; i++) {
        assert classNames[i].startsWith("Target_");
        Symbol<Type> classType = StaticSymbols.putType("L" + classNames[i].substring("Target_".length()).replace('_', '/') + ";");
        Symbol<Name> methodName = StaticSymbols.putName(methodNames[i]);
        registerStaticSubstitution(classType, methodName, signature, factory, true);
    }
}
Also used : Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ArrayList(java.util.ArrayList) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) IntrinsicSubstitutorNode(com.oracle.truffle.espresso.nodes.IntrinsicSubstitutorNode)

Example 38 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class Target_java_lang_invoke_MethodHandleNatives method plantInvokeBasic.

// region MemberName planting
private static void plantInvokeBasic(StaticObject memberName, Klass resolutionKlass, Symbol<Name> name, Symbol<Signature> sig, Klass callerKlass, int refKind, Meta meta) {
    assert (name == Name.invokeBasic);
    Method target = resolutionKlass.lookupMethod(name, sig, callerKlass);
    meta.HIDDEN_VMTARGET.setHiddenObject(memberName, target);
    meta.java_lang_invoke_MemberName_flags.setInt(memberName, getMethodFlags(target, refKind));
}
Also used : Method(com.oracle.truffle.espresso.impl.Method)

Example 39 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class Target_java_lang_invoke_MethodHandleNatives method plantMethodMemberName.

private static void plantMethodMemberName(StaticObject memberName, Klass resolutionKlass, Symbol<Name> name, Symbol<Signature> sig, int refKind, Klass callerKlass, boolean accessCheck, boolean constraintsChecks, Meta meta) {
    Method target = resolutionKlass.lookupMethod(name, sig, callerKlass);
    if (target == null) {
        throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, cat("Failed lookup for method ", resolutionKlass.getName(), "#", name, ":", sig));
    }
    if (target.isStatic() != (refKind == REF_invokeStatic)) {
        String expected = (refKind == REF_invokeStatic) ? "Static" : "Instance";
        String actual = (refKind == REF_invokeStatic) ? "Instance" : "Static";
        throw meta.throwExceptionWithMessage(meta.java_lang_IncompatibleClassChangeError, cat(expected, " method lookup resulted in ", actual, " resolution for method ", resolutionKlass.getName(), "#", name, ":", sig));
    }
    if (accessCheck) {
        MemberRefConstant.doAccessCheck(callerKlass, target.getDeclaringKlass(), target, meta);
    }
    if (constraintsChecks) {
        target.checkLoadingConstraints(callerKlass.getDefiningClassLoader(), resolutionKlass.getDefiningClassLoader());
    }
    plantResolvedMethod(memberName, target, refKind, meta);
}
Also used : Method(com.oracle.truffle.espresso.impl.Method)

Example 40 with Method

use of com.oracle.truffle.espresso.impl.Method in project graal by oracle.

the class EspressoInterop method asInstant.

@ExportMessage
@TruffleBoundary
static Instant asInstant(StaticObject receiver, @CachedLibrary("receiver") InteropLibrary receiverLibrary, @Shared("error") @Cached BranchProfile error) throws UnsupportedMessageException {
    receiver.checkNotForeign();
    if (receiverLibrary.isInstant(receiver)) {
        StaticObject instant;
        Meta meta = receiver.getKlass().getMeta();
        if (instanceOf(receiver, meta.java_time_ZonedDateTime)) {
            instant = (StaticObject) meta.java_time_ZonedDateTime_toInstant.invokeDirect(receiver);
        } else if (instanceOf(receiver, meta.java_util_Date)) {
            int index = meta.java_util_Date_toInstant.getVTableIndex();
            Method virtualToInstant = receiver.getKlass().vtableLookup(index);
            instant = (StaticObject) virtualToInstant.invokeDirect(receiver);
        } else {
            instant = receiver;
        }
        assert instanceOf(instant, meta.java_time_Instant);
        long seconds = (long) meta.java_time_Instant_seconds.get(instant);
        int nanos = (int) meta.java_time_Instant_nanos.get(instant);
        return Instant.ofEpochSecond(seconds, nanos);
    }
    error.enter();
    throw UnsupportedMessageException.create();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) Method(com.oracle.truffle.espresso.impl.Method) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

Method (com.oracle.truffle.espresso.impl.Method)91 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)57 Meta (com.oracle.truffle.espresso.meta.Meta)27 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)22 Klass (com.oracle.truffle.espresso.impl.Klass)19 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)19 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)16 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)14 ExportMessage (com.oracle.truffle.api.library.ExportMessage)12 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)10 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)9 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)8 ArityException (com.oracle.truffle.api.interop.ArityException)8 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)8 ArrayList (java.util.ArrayList)8 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)7 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)5 Field (com.oracle.truffle.espresso.impl.Field)4 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)3 Signature (com.oracle.truffle.espresso.descriptors.Symbol.Signature)3