use of com.oracle.truffle.espresso.impl.Field in project graal by oracle.
the class JniEnv method SetDoubleField.
@JniImpl
public void SetDoubleField(@JavaType(Object.class) StaticObject obj, @Handle(Field.class) long fieldId, double val) {
Field field = fieldIds.getObject(fieldId);
field.set(obj, val);
}
use of com.oracle.truffle.espresso.impl.Field 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);
}
use of com.oracle.truffle.espresso.impl.Field in project graal by oracle.
the class VM method getGuestReflectiveFieldRoot.
@JavaType(java.lang.reflect.Field.class)
private static StaticObject getGuestReflectiveFieldRoot(@JavaType(java.lang.reflect.Field.class) StaticObject seed, Meta meta) {
assert InterpreterToVM.instanceOf(seed, meta.java_lang_reflect_Field);
StaticObject curField = seed;
Field target = null;
while (target == null) {
target = (Field) meta.HIDDEN_FIELD_KEY.getHiddenObject(curField);
if (target == null) {
curField = meta.java_lang_reflect_Field_root.getObject(curField);
}
}
return curField;
}
use of com.oracle.truffle.espresso.impl.Field in project graal by oracle.
the class Target_sun_misc_Unsafe method putOrderedObject.
@Substitution(hasReceiver = true)
public static void putOrderedObject(@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).putOrderedObject(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.setObject(holder, value, true);
}
use of com.oracle.truffle.espresso.impl.Field in project graal by oracle.
the class Target_sun_misc_Unsafe method putLong.
@Substitution(hasReceiver = true)
public static void putLong(@SuppressWarnings("unused") @JavaType(Unsafe.class) StaticObject self, @JavaType(Object.class) StaticObject holder, long offset, long value, @Inject Meta meta) {
if (isNullOrArray(holder)) {
UnsafeAccess.getIfAllowed(meta).putLong(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;
f.setLong(holder, value);
}
Aggregations