Search in sources :

Example 31 with Klass

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

the class EspressoInterop method fitsInLong.

@ExportMessage
static boolean fitsInLong(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    if (isAtMostLong(klass)) {
        return true;
    }
    Meta meta = klass.getMeta();
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return inSafeIntegerRange(content) && !isNegativeZero(content) && (long) content == content;
    }
    if (klass == meta.java_lang_Double) {
        double content = meta.java_lang_Double_value.getDouble(receiver);
        return inSafeIntegerRange(content) && !isNegativeZero(content) && (long) content == content;
    }
    return false;
}
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) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 32 with Klass

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

the class EspressoInterop method fitsInInt.

@ExportMessage
static boolean fitsInInt(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    if (isAtMostInt(klass)) {
        return true;
    }
    Meta meta = klass.getMeta();
    if (klass == meta.java_lang_Long) {
        long content = meta.java_lang_Long_value.getLong(receiver);
        return (int) content == content;
    }
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return inSafeIntegerRange(content) && !isNegativeZero(content) && (int) content == content;
    }
    if (klass == meta.java_lang_Double) {
        double content = meta.java_lang_Double_value.getDouble(receiver);
        return (int) content == content && !isNegativeZero(content);
    }
    return false;
}
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) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 33 with Klass

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

the class EspressoInterop method fitsInDouble.

@ExportMessage
static boolean fitsInDouble(StaticObject receiver) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    Klass klass = receiver.getKlass();
    Meta meta = klass.getMeta();
    if (isAtMostInt(klass) || klass == meta.java_lang_Double) {
        return true;
    }
    if (klass == meta.java_lang_Long) {
        long content = meta.java_lang_Long_value.getLong(receiver);
        double doubleContent = content;
        return (long) doubleContent == content;
    }
    if (klass == meta.java_lang_Float) {
        float content = meta.java_lang_Float_value.getFloat(receiver);
        return !Float.isFinite(content) || (double) content == content;
    }
    return false;
}
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) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 34 with Klass

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

the class Target_java_lang_Class method getSuperclass.

@Substitution(hasReceiver = true)
@JavaType(Class.class)
public static StaticObject getSuperclass(@JavaType(Class.class) StaticObject self, @Inject Meta meta) {
    Klass k = self.getMirrorKlass(meta);
    if (k.isInterface()) {
        return StaticObject.NULL;
    }
    Klass superclass = k.getSuperKlass();
    if (superclass == null) {
        return StaticObject.NULL;
    }
    return superclass.mirror();
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass)

Example 35 with Klass

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

the class Target_sun_misc_Unsafe method defineClass.

@TruffleBoundary
@Substitution(hasReceiver = true, nameProvider = SharedUnsafeAppend0.class)
@JavaType(Class.class)
public static StaticObject defineClass(@SuppressWarnings("unused") @JavaType(Unsafe.class) StaticObject self, @JavaType(String.class) StaticObject name, @JavaType(byte[].class) StaticObject guestBuf, int offset, int len, @JavaType(ClassLoader.class) StaticObject loader, @JavaType(ProtectionDomain.class) StaticObject pd, @Inject Meta meta) {
    byte[] buf = guestBuf.unwrap();
    byte[] bytes = Arrays.copyOfRange(buf, offset, len);
    Klass klass = meta.getRegistries().defineKlass(meta.getTypes().fromClassGetName(meta.toHostString(name)), bytes, loader, new ClassRegistry.ClassDefinitionInfo(pd));
    return klass.mirror();
}
Also used : Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ClassRegistry(com.oracle.truffle.espresso.impl.ClassRegistry) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

Klass (com.oracle.truffle.espresso.impl.Klass)71 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)54 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)49 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)33 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)24 Meta (com.oracle.truffle.espresso.meta.Meta)21 Method (com.oracle.truffle.espresso.impl.Method)19 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)10 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)10 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)10 ExportMessage (com.oracle.truffle.api.library.ExportMessage)8 Field (com.oracle.truffle.espresso.impl.Field)7 ArrayList (java.util.ArrayList)7 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)6 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)6 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)5 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)5 NativeType (com.oracle.truffle.espresso.ffi.NativeType)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)3 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)3