Search in sources :

Example 16 with Meta

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

the class JniEnv method GetStringRegion.

/**
 * <h3>void GetStringRegion(JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf);</h3>
 * <p>
 * Copies len number of Unicode characters beginning at offset start to the given buffer buf.
 * <p>
 * Throws StringIndexOutOfBoundsException on index overflow.
 */
@JniImpl
@TruffleBoundary
public void GetStringRegion(@JavaType(String.class) StaticObject str, int start, int len, @Pointer TruffleObject bufPtr) {
    char[] chars;
    if (getJavaVersion().compactStringsEnabled()) {
        chars = getMeta().toHostString(str).toCharArray();
    } else {
        chars = getMeta().java_lang_String_value.getObject(str).unwrap();
    }
    if (start < 0 || start + (long) len > chars.length) {
        Meta meta = getMeta();
        throw meta.throwException(meta.java_lang_StringIndexOutOfBoundsException);
    }
    CharBuffer buf = NativeUtils.directByteBuffer(bufPtr, len, JavaKind.Char).asCharBuffer();
    buf.put(chars, start, len);
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) CharBuffer(java.nio.CharBuffer) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 17 with Meta

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

the class JniEnv method setPendingException.

public void setPendingException(StaticObject ex) {
    Meta meta = getMeta();
    assert StaticObject.notNull(ex) && meta.java_lang_Throwable.isAssignableFrom(ex.getKlass());
    setPendingException(EspressoException.wrap(ex, meta));
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta)

Example 18 with Meta

use of com.oracle.truffle.espresso.meta.Meta 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 19 with Meta

use of com.oracle.truffle.espresso.meta.Meta 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 20 with Meta

use of com.oracle.truffle.espresso.meta.Meta 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

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