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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations