Search in sources :

Example 6 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class JniEnv method CallNonvirtualObjectMethodVarargs.

// endregion Call*Method
// region CallNonvirtual*Method
@JniImpl
@JavaType(Object.class)
public StaticObject CallNonvirtualObjectMethodVarargs(@JavaType(Object.class) StaticObject receiver, @JavaType(Class.class) StaticObject clazz, @Handle(Method.class) long methodId, @Pointer TruffleObject varargsPtr) {
    Method method = methodIds.getObject(methodId);
    assert !method.isStatic();
    assert (clazz.getMirrorKlass()) == method.getDeclaringKlass();
    Object result = method.invokeDirect(receiver, popVarArgs(varargsPtr, method.getParsedSignature()));
    return getMeta().asObject(result);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Method(com.oracle.truffle.espresso.impl.Method) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 7 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class JniEnv method NewString.

@JniImpl
@TruffleBoundary
@JavaType(String.class)
public StaticObject NewString(@Pointer TruffleObject unicodePtr, int len) {
    // TODO(garcia) : works only for UTF16 encoded strings.
    final char[] array = new char[len];
    StaticObject value = StaticObject.wrap(array, getMeta());
    SetCharArrayRegion(value, 0, len, unicodePtr);
    return getMeta().toGuestString(new String(array));
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 8 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class JniEnv method GetFieldID.

// Checkstyle: stop method name check
// region Get*ID
/**
 * <h3>jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig);</h3>
 * <p>
 * Returns the field ID for an instance (nonstatic) field of a class. The field is specified by
 * its name and signature. The Get<type>Field and Set<type>Field families of accessor functions
 * use field IDs to retrieve object fields. GetFieldID() causes an uninitialized class to be
 * initialized. GetFieldID() cannot be used to obtain the length field of an array. Use
 * GetArrayLength() instead.
 *
 * @param clazz a Java class object.
 * @param namePtr the field name in a 0-terminated modified UTF-8 string.
 * @param typePtr the field signature in a 0-terminated modified UTF-8 string.
 * @return a field ID, or NULL if the operation fails.
 * @throws NoSuchFieldError: if the specified field 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(Field.class)
public long GetFieldID(@JavaType(Class.class) StaticObject clazz, @Pointer TruffleObject namePtr, @Pointer TruffleObject typePtr) {
    String name = NativeUtils.interopPointerToString(namePtr);
    String type = NativeUtils.interopPointerToString(typePtr);
    assert name != null && type != null;
    Klass klass = clazz.getMirrorKlass();
    Field field = null;
    Symbol<Name> fieldName = getNames().lookup(name);
    if (fieldName != null) {
        Symbol<Type> fieldType = getTypes().lookup(type);
        if (fieldType != null) {
            // Lookup only if name and type are known symbols.
            klass.safeInitialize();
            field = klass.lookupField(fieldName, fieldType);
            assert field == null || field.getType().equals(fieldType);
        }
    }
    if (field == null || field.isStatic()) {
        Meta meta = getMeta();
        throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchFieldError, name);
    }
    assert !field.isStatic();
    return fieldIds.handlify(field);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) Meta(com.oracle.truffle.espresso.meta.Meta) NativeType(com.oracle.truffle.espresso.ffi.NativeType) Type(com.oracle.truffle.espresso.descriptors.Symbol.Type) JavaType(com.oracle.truffle.espresso.substitutions.JavaType) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) Name(com.oracle.truffle.espresso.descriptors.Symbol.Name)

Example 9 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class ConstantPool method classFormatError.

@JavaType(ClassFormatError.class)
public static EspressoException classFormatError(String message) {
    CompilerDirectives.transferToInterpreter();
    Meta meta = EspressoContext.get(null).getMeta();
    throw meta.throwExceptionWithMessage(meta.java_lang_ClassFormatError, message);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Example 10 with JavaType

use of com.oracle.truffle.espresso.substitutions.JavaType in project graal by oracle.

the class ConstantPool method noClassDefFoundError.

@JavaType(NoClassDefFoundError.class)
static EspressoException noClassDefFoundError(String message) {
    CompilerDirectives.transferToInterpreter();
    Meta meta = EspressoContext.get(null).getMeta();
    throw meta.throwExceptionWithMessage(meta.java_lang_NoClassDefFoundError, message);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) JavaType(com.oracle.truffle.espresso.substitutions.JavaType)

Aggregations

JavaType (com.oracle.truffle.espresso.substitutions.JavaType)58 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)44 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)28 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)24 Klass (com.oracle.truffle.espresso.impl.Klass)24 Meta (com.oracle.truffle.espresso.meta.Meta)20 Method (com.oracle.truffle.espresso.impl.Method)19 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)15 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)13 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)8 NativeType (com.oracle.truffle.espresso.ffi.NativeType)8 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)5 Field (com.oracle.truffle.espresso.impl.Field)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)4 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)4 ArrayList (java.util.ArrayList)4 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)3 EnclosingMethodAttribute (com.oracle.truffle.espresso.classfile.attributes.EnclosingMethodAttribute)3 MethodParametersAttribute (com.oracle.truffle.espresso.classfile.attributes.MethodParametersAttribute)3