Search in sources :

Example 6 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class ObjectGetFieldNode method doForeignValue.

@Specialization(guards = { "receiver.isForeignObject()", "isValueField(context)" })
char doForeignValue(StaticObject receiver, @CachedLibrary(limit = "CACHED_LIBRARY_LIMIT") InteropLibrary interopLibrary, @Bind("getContext()") EspressoContext context, @Cached BranchProfile error) {
    try {
        String foreignString = interopLibrary.asString(receiver.rawForeignObject());
        if (foreignString.length() != 1) {
            error.enter();
            Meta meta = context.getMeta();
            throw meta.throwExceptionWithMessage(meta.java_lang_ClassCastException, "Multicharacter foreign string cannot be cast to char");
        }
        return foreignString.charAt(0);
    } catch (UnsupportedMessageException e) {
        error.enter();
        Meta meta = context.getMeta();
        throw meta.throwExceptionWithMessage(meta.java_lang_ClassCastException, "Non-string foreign object cannot be cast to character");
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) UnsupportedMessageException(com.oracle.truffle.api.interop.UnsupportedMessageException) Specialization(com.oracle.truffle.api.dsl.Specialization)

Example 7 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class EspressoReferenceArrayStoreNode method arrayStore.

public void arrayStore(EspressoContext context, StaticObject value, int index, StaticObject array) {
    if (Integer.compareUnsigned(index, array.length()) >= 0) {
        enterOutOfBound();
        Meta meta = context.getMeta();
        throw meta.throwException(meta.java_lang_ArrayIndexOutOfBoundsException);
    }
    if (!StaticObject.isNull(value) && !instanceOfDynamic.execute(value.getKlass(), ((ArrayKlass) array.getKlass()).getComponentType())) {
        enterArrayStoreEx();
        Meta meta = context.getMeta();
        throw meta.throwException(meta.java_lang_ArrayStoreException);
    }
    (array.<StaticObject[]>unwrap())[index] = value;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject)

Example 8 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class InvokeVirtual method methodLookup.

static Method.MethodVersion methodLookup(Method resolutionSeed, Klass receiverKlass) {
    if (resolutionSeed.isRemovedByRedefition()) {
        /*
             * Accept a slow path once the method has been removed put method behind a boundary to
             * avoid a deopt loop.
             */
        return resolutionSeed.getContext().getClassRedefinition().handleRemovedMethod(resolutionSeed, receiverKlass).getMethodVersion();
    }
    /*
         * Surprisingly, INVOKEVIRTUAL can try to invoke interface methods, even non-default ones.
         * Good thing is, miranda methods are taken care of at vtable creation !
         */
    int vtableIndex = resolutionSeed.getVTableIndex();
    Method.MethodVersion target;
    if (receiverKlass.isArray()) {
        target = receiverKlass.getSuperKlass().vtableLookup(vtableIndex).getMethodVersion();
    } else {
        target = receiverKlass.vtableLookup(vtableIndex).getMethodVersion();
    }
    if (!target.getMethod().hasCode()) {
        Meta meta = receiverKlass.getMeta();
        throw meta.throwException(meta.java_lang_AbstractMethodError);
    }
    return target;
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Method(com.oracle.truffle.espresso.impl.Method)

Example 9 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class EspressoBindings method readMember.

@ExportMessage
Object readMember(String member, @CachedLibrary("this") InteropLibrary self, @Exclusive @Cached BranchProfile error) throws UnknownIdentifierException {
    if (!isMemberReadable(member)) {
        error.enter();
        throw UnknownIdentifierException.create(member);
    }
    EspressoContext context = EspressoContext.get(self);
    if (withNativeJavaVM && JAVA_VM.equals(member)) {
        return context.getVM().getJavaVM();
    }
    Meta meta = context.getMeta();
    try {
        StaticObject clazz = (StaticObject) meta.java_lang_Class_forName_String_boolean_ClassLoader.invokeDirect(null, meta.toGuestString(member), false, loader);
        return clazz.getMirrorKlass();
    } catch (EspressoException e) {
        error.enter();
        if (InterpreterToVM.instanceOf(e.getGuestException(), meta.java_lang_ClassNotFoundException)) {
            throw UnknownIdentifierException.create(member, e);
        }
        // exception during class loading
        throw e;
    }
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) EspressoException(com.oracle.truffle.espresso.runtime.EspressoException) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 10 with Meta

use of com.oracle.truffle.espresso.meta.Meta in project graal by oracle.

the class JniEnv method GetMethodID.

/**
 * <h3>jmethodID GetMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig);</h3>
 * <p>
 * Returns the method ID for an instance (nonstatic) method of a class or interface. The method
 * may be defined in one of the clazz’s superclasses and inherited by clazz. The method is
 * determined by its name and signature.
 * <p>
 * GetMethodID() causes an uninitialized class to be initialized.
 * <p>
 * To obtain the method ID of a constructor, supply <init> as the method name and void (V) as
 * the return type.
 *
 * @param clazz a Java class object.
 * @param namePtr the method name in a 0-terminated modified UTF-8 string.
 * @param signaturePtr the method signature in 0-terminated modified UTF-8 string.
 * @return a method ID, or NULL if the specified method cannot be found.
 * @throws NoSuchMethodError if the specified method cannot be found.
 * @throws ExceptionInInitializerError if the class initializer fails due to an exception.
 * @throws OutOfMemoryError if the system runs out of memory.
 */
@JniImpl
@Handle(Method.class)
public long GetMethodID(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject namePtr, @Pointer TruffleObject signaturePtr) {
    String name = NativeUtils.interopPointerToString(namePtr);
    String signature = NativeUtils.interopPointerToString(signaturePtr);
    assert name != null && signature != null;
    Method method = null;
    Symbol<Name> methodName = getNames().lookup(name);
    if (methodName != null) {
        Symbol<Signature> methodSignature = getSignatures().lookupValidSignature(signature);
        if (methodSignature != null) {
            Klass klass = clazz.getMirrorKlass();
            klass.safeInitialize();
            // Lookup only if name and type are known symbols.
            method = klass.lookupMethod(methodName, methodSignature, klass);
        }
    }
    if (method == null || method.isStatic()) {
        Meta meta = getMeta();
        throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchMethodError, name);
    }
    return methodIds.handlify(method);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) NativeSignature(com.oracle.truffle.espresso.ffi.NativeSignature) Signature(com.oracle.truffle.espresso.descriptors.Symbol.Signature) Method(com.oracle.truffle.espresso.impl.Method) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Aggregations

Meta (com.oracle.truffle.espresso.meta.Meta)82 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)29 Method (com.oracle.truffle.espresso.impl.Method)27 ExportMessage (com.oracle.truffle.api.library.ExportMessage)24 Klass (com.oracle.truffle.espresso.impl.Klass)21 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)21 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)21 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)20 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)17 ArityException (com.oracle.truffle.api.interop.ArityException)9 UnsupportedTypeException (com.oracle.truffle.api.interop.UnsupportedTypeException)9 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)9 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)8 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)6 NativeType (com.oracle.truffle.espresso.ffi.NativeType)4 Field (com.oracle.truffle.espresso.impl.Field)4 ArrayList (java.util.ArrayList)4 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 UnsupportedMessageException (com.oracle.truffle.api.interop.UnsupportedMessageException)3 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)3