Search in sources :

Example 46 with Field

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

the class Target_sun_misc_Unsafe method putObjectVolatile.

// endregion get*(long offset)
// region put*Volatile(Object holder, long offset)
@TruffleBoundary(allowInlining = true)
@Substitution(hasReceiver = true, nameProvider = SharedUnsafeObjectAccessToReference.class)
public static void putObjectVolatile(@SuppressWarnings("unused") @JavaType(Unsafe.class) StaticObject self, @JavaType(Object.class) StaticObject holder, long offset, @JavaType(Object.class) StaticObject value, @Inject Meta meta) {
    if (isNullOrArray(holder)) {
        UnsafeAccess.getIfAllowed(meta).putObjectVolatile(unwrapNullOrArray(holder), offset, value);
        return;
    }
    // TODO(peterssen): Current workaround assumes it's a field access, encoding is offset <->
    // field index.
    Field f = getInstanceFieldFromIndex(holder, Math.toIntExact(offset) - SAFETY_FIELD_OFFSET);
    assert f != null;
    assert !f.getKind().isSubWord();
    f.setObject(holder, value, true);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 47 with Field

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

the class Target_sun_misc_Unsafe method park.

/**
 * Block current thread, returning when a balancing <tt>unpark</tt> occurs, or a balancing
 * <tt>unpark</tt> has already occurred, or the thread is interrupted, or, if not absolute and
 * time is not zero, the given time nanoseconds have elapsed, or if absolute, the given deadline
 * in milliseconds since Epoch has passed, or spuriously (i.e., returning for no "reason").
 * Note: This operation is in the Unsafe class only because <tt>unpark</tt> is, so it would be
 * strange to place it elsewhere.
 */
@TruffleBoundary
@Substitution(hasReceiver = true)
@SuppressWarnings("try")
public static void park(@JavaType(Unsafe.class) StaticObject self, boolean isAbsolute, long time, @Inject Meta meta) {
    if (time < 0 || (isAbsolute && time == 0)) {
        // don't wait at all
        return;
    }
    EspressoContext context = meta.getContext();
    StaticObject thread = context.getCurrentThread();
    if (meta.getThreadAccess().isInterrupted(thread, false)) {
        return;
    }
    Unsafe unsafe = UnsafeAccess.getIfAllowed(meta);
    Thread hostThread = Thread.currentThread();
    Object blocker = LockSupport.getBlocker(hostThread);
    State state = time > 0 ? State.TIMED_WAITING : State.WAITING;
    try (Transition transition = Transition.transition(context, state)) {
        Field parkBlocker = meta.java_lang_Thread.lookupDeclaredField(Symbol.Name.parkBlocker, Type.java_lang_Object);
        StaticObject guestBlocker = parkBlocker.getObject(thread);
        // LockSupport.park(/* guest blocker */);
        if (!StaticObject.isNull(guestBlocker)) {
            unsafe.putObject(hostThread, PARK_BLOCKER_OFFSET, guestBlocker);
        }
        parkBoundary(self, isAbsolute, time, meta);
    }
    unsafe.putObject(hostThread, PARK_BLOCKER_OFFSET, blocker);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) State(com.oracle.truffle.espresso.threads.State) Transition(com.oracle.truffle.espresso.threads.Transition) EspressoContext(com.oracle.truffle.espresso.runtime.EspressoContext) Unsafe(sun.misc.Unsafe) TruffleObject(com.oracle.truffle.api.interop.TruffleObject) StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 48 with Field

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

the class Target_sun_misc_Unsafe method putOrderedInt.

@Substitution(hasReceiver = true)
public static void putOrderedInt(@SuppressWarnings("unused") @JavaType(Unsafe.class) StaticObject self, @JavaType(Object.class) StaticObject holder, long offset, int value, @Inject Meta meta) {
    if (isNullOrArray(holder)) {
        UnsafeAccess.getIfAllowed(meta).putOrderedInt(unwrapNullOrArray(holder), offset, value);
        return;
    }
    // TODO(peterssen): Current workaround assumes it's a field access, encoding is offset <->
    // field index.
    Field f = getInstanceFieldFromIndex(holder, Math.toIntExact(offset) - SAFETY_FIELD_OFFSET);
    assert f != null;
    // TODO(peterssen): Volatile is stronger than needed.
    f.setInt(holder, value, true);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field)

Example 49 with Field

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

the class Target_sun_misc_Unsafe method putIntVolatile.

@TruffleBoundary(allowInlining = true)
@Substitution(hasReceiver = true)
public static void putIntVolatile(@SuppressWarnings("unused") @JavaType(Unsafe.class) StaticObject self, @JavaType(Object.class) StaticObject holder, long offset, int value, @Inject Meta meta) {
    if (isNullOrArray(holder)) {
        UnsafeAccess.getIfAllowed(meta).putIntVolatile(unwrapNullOrArray(holder), offset, value);
        return;
    }
    // TODO(peterssen): Current workaround assumes it's a field access, encoding is offset <->
    // field index.
    Field f = getInstanceFieldFromIndex(holder, Math.toIntExact(offset) - SAFETY_FIELD_OFFSET);
    assert f != null;
    assert f.getKind().isSubWord();
    f.setInt(holder, value, true);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 50 with Field

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

the class Target_sun_misc_Unsafe method objectFieldOffset1.

@Substitution(hasReceiver = true, nameProvider = Unsafe11.class)
@SuppressWarnings("unused")
public static long objectFieldOffset1(@JavaType(Unsafe.class) StaticObject self, @JavaType(value = Class.class) StaticObject cl, @JavaType(value = String.class) StaticObject guestName, @Inject Meta meta) {
    Klass k = cl.getMirrorKlass();
    String hostName = meta.toHostString(guestName);
    if (k instanceof ObjectKlass) {
        ObjectKlass kl = (ObjectKlass) k;
        for (Field f : kl.getFieldTable()) {
            if (!f.isRemoved() && f.getNameAsString().equals(hostName)) {
                return SAFETY_FIELD_OFFSET + f.getSlot();
            }
        }
        for (Field f : kl.getStaticFieldTable()) {
            if (!f.isRemoved() && f.getNameAsString().equals(hostName)) {
                return SAFETY_FIELD_OFFSET + f.getSlot();
            }
        }
    }
    throw meta.throwException(meta.java_lang_InternalError);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) Klass(com.oracle.truffle.espresso.impl.Klass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass)

Aggregations

Field (com.oracle.truffle.espresso.impl.Field)60 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)14 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)8 Klass (com.oracle.truffle.espresso.impl.Klass)7 Method (com.oracle.truffle.espresso.impl.Method)5 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)5 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)5 ExportMessage (com.oracle.truffle.api.library.ExportMessage)4 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)4 Meta (com.oracle.truffle.espresso.meta.Meta)4 ArrayList (java.util.ArrayList)4 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)3 ParserField (com.oracle.truffle.espresso.impl.ParserField)3 REF_getField (com.oracle.truffle.espresso.classfile.Constants.REF_getField)2 REF_putField (com.oracle.truffle.espresso.classfile.Constants.REF_putField)2 Type (com.oracle.truffle.espresso.descriptors.Symbol.Type)2 NativeType (com.oracle.truffle.espresso.ffi.NativeType)2 ParserKlass (com.oracle.truffle.espresso.impl.ParserKlass)2 ParserMethod (com.oracle.truffle.espresso.impl.ParserMethod)2 RedefineAddedField (com.oracle.truffle.espresso.impl.RedefineAddedField)2