Search in sources :

Example 26 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject 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 27 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject 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 28 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class JniEnv method ReleasePrimitiveArrayElements.

// endregion Get*ArrayElements
// region Release*ArrayElements
private void ReleasePrimitiveArrayElements(StaticObject object, @Pointer TruffleObject bufPtr, int mode) {
    if (mode == 0 || mode == JNI_COMMIT) {
        // Update array contents.
        StaticObject array = object;
        StaticObject clazz = GetObjectClass(array);
        JavaKind componentKind = ((ArrayKlass) clazz.getMirrorKlass()).getComponentType().getJavaKind();
        assert componentKind.isPrimitive();
        int length = GetArrayLength(array);
        // @formatter:off
        switch(componentKind) {
            case Boolean:
                SetBooleanArrayRegion(array, 0, length, bufPtr);
                break;
            case Byte:
                SetByteArrayRegion(array, 0, length, bufPtr);
                break;
            case Short:
                SetShortArrayRegion(array, 0, length, bufPtr);
                break;
            case Char:
                SetCharArrayRegion(array, 0, length, bufPtr);
                break;
            case Int:
                SetIntArrayRegion(array, 0, length, bufPtr);
                break;
            case Float:
                SetFloatArrayRegion(array, 0, length, bufPtr);
                break;
            case Long:
                SetLongArrayRegion(array, 0, length, bufPtr);
                break;
            case Double:
                SetDoubleArrayRegion(array, 0, length, bufPtr);
                break;
            default:
                throw EspressoError.shouldNotReachHere();
        }
    // @formatter:on
    }
    if (mode == 0 || mode == JNI_ABORT) {
        // Dispose copy.
        releasePtr(bufPtr);
    }
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) JavaKind(com.oracle.truffle.espresso.meta.JavaKind)

Example 29 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class JniEnv method CallStaticCharMethodVarargs.

@JniImpl
public char CallStaticCharMethodVarargs(@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(null, popVarArgs(varargsPtr, method.getParsedSignature()));
    return getMeta().asChar(result, true);
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) Method(com.oracle.truffle.espresso.impl.Method)

Example 30 with StaticObject

use of com.oracle.truffle.espresso.runtime.StaticObject in project graal by oracle.

the class RedefineAddedField method getObject.

@Override
protected StaticObject getObject(StaticObject obj, boolean forceVolatile) {
    if (hasCompatibleField()) {
        return getCompatibleField().getObject(obj, forceVolatile);
    } else {
        FieldStorageObject storageObject = getStorageObject(obj);
        StaticObject result;
        if (forceVolatile) {
            result = (StaticObject) linkedField.getObjectVolatile(storageObject);
        } else {
            result = (StaticObject) linkedField.getObject(storageObject);
        }
        if (result == StaticObject.NULL) {
            return result;
        }
        if (getDeclaringKlass().getContext().anyHierarchyChanged()) {
            return checkGetValueValidity(result);
        }
        return result;
    }
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject)

Aggregations

StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)199 Method (com.oracle.truffle.espresso.impl.Method)57 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)44 Klass (com.oracle.truffle.espresso.impl.Klass)32 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)32 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)30 Meta (com.oracle.truffle.espresso.meta.Meta)29 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)26 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)23 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)17 ArrayList (java.util.ArrayList)13 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)9 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)8 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)7 ExportMessage (com.oracle.truffle.api.library.ExportMessage)7 BytecodeNode (com.oracle.truffle.espresso.nodes.BytecodeNode)7 TruffleSafepoint (com.oracle.truffle.api.TruffleSafepoint)6 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)6 EspressoContext (com.oracle.truffle.espresso.runtime.EspressoContext)6 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)5