use of com.oracle.truffle.espresso.impl.Field in project graal by oracle.
the class Target_sun_misc_Unsafe method putByte.
@Substitution(hasReceiver = true)
public static void putByte(@SuppressWarnings("unused") @JavaType(Unsafe.class) StaticObject self, @JavaType(Object.class) StaticObject holder, long offset, byte value, @Inject Meta meta) {
if (isNullOrArray(holder)) {
UnsafeAccess.getIfAllowed(meta).putByte(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.setByte(holder, value);
}
use of com.oracle.truffle.espresso.impl.Field in project graal by oracle.
the class VM method JVM_GetClassDeclaredFields.
@VmImpl(isJni = true)
@JavaType(java.lang.reflect.Field[].class)
public StaticObject JVM_GetClassDeclaredFields(@JavaType(Class.class) StaticObject self, boolean publicOnly) {
// TODO(peterssen): From Hostpot: 4496456 We need to filter out
// java.lang.Throwable.backtrace.
Meta meta = getMeta();
ArrayList<Field> collectedMethods = new ArrayList<>();
Klass klass = self.getMirrorKlass();
klass.ensureLinked();
for (Field f : klass.getDeclaredFields()) {
if (!publicOnly || f.isPublic()) {
collectedMethods.add(f);
}
}
final Field[] fields = collectedMethods.toArray(Field.EMPTY_ARRAY);
EspressoContext context = meta.getContext();
// TODO(peterssen): Cache guest j.l.reflect.Field constructor.
// Calling the constructor is just for validation, manually setting the fields would be
// faster.
Method fieldInit;
if (meta.getJavaVersion().java15OrLater()) {
fieldInit = meta.java_lang_reflect_Field.lookupDeclaredMethod(Name._init_, context.getSignatures().makeRaw(Type._void, /* declaringClass */
Type.java_lang_Class, /* name */
Type.java_lang_String, /* type */
Type.java_lang_Class, /* modifiers */
Type._int, /* trustedFinal */
Type._boolean, /* slot */
Type._int, /* signature */
Type.java_lang_String, /* annotations */
Type._byte_array));
} else {
fieldInit = meta.java_lang_reflect_Field.lookupDeclaredMethod(Name._init_, context.getSignatures().makeRaw(Type._void, /* declaringClass */
Type.java_lang_Class, /* name */
Type.java_lang_String, /* type */
Type.java_lang_Class, /* modifiers */
Type._int, /* slot */
Type._int, /* signature */
Type.java_lang_String, /* annotations */
Type._byte_array));
}
StaticObject fieldsArray = meta.java_lang_reflect_Field.allocateReferenceArray(fields.length, new IntFunction<StaticObject>() {
@Override
public StaticObject apply(int i) {
final Field f = fields[i];
StaticObject instance = meta.java_lang_reflect_Field.allocateInstance();
Attribute rawRuntimeVisibleAnnotations = f.getAttribute(Name.RuntimeVisibleAnnotations);
StaticObject runtimeVisibleAnnotations = rawRuntimeVisibleAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleAnnotations.getData(), meta) : StaticObject.NULL;
Attribute rawRuntimeVisibleTypeAnnotations = f.getAttribute(Name.RuntimeVisibleTypeAnnotations);
StaticObject runtimeVisibleTypeAnnotations = rawRuntimeVisibleTypeAnnotations != null ? StaticObject.wrap(rawRuntimeVisibleTypeAnnotations.getData(), meta) : StaticObject.NULL;
if (meta.getJavaVersion().java15OrLater()) {
fieldInit.invokeDirect(/* this */
instance, /* declaringKlass */
f.getDeclaringKlass().mirror(), /* name */
context.getStrings().intern(f.getName()), /* type */
f.resolveTypeKlass().mirror(), /* modifiers */
f.getModifiers(), /* trustedFinal */
f.isTrustedFinal(), /* slot */
f.getSlot(), /* signature */
meta.toGuestString(f.getGenericSignature()), /* annotations */
runtimeVisibleAnnotations);
} else {
fieldInit.invokeDirect(/* this */
instance, /* declaringKlass */
f.getDeclaringKlass().mirror(), /* name */
context.getStrings().intern(f.getName()), /* type */
f.resolveTypeKlass().mirror(), /* modifiers */
f.getModifiers(), /* slot */
f.getSlot(), /* signature */
meta.toGuestString(f.getGenericSignature()), /* annotations */
runtimeVisibleAnnotations);
}
meta.HIDDEN_FIELD_KEY.setHiddenObject(instance, f);
meta.HIDDEN_FIELD_RUNTIME_VISIBLE_TYPE_ANNOTATIONS.setHiddenObject(instance, runtimeVisibleTypeAnnotations);
return instance;
}
});
return fieldsArray;
}
use of com.oracle.truffle.espresso.impl.Field in project graal by oracle.
the class InterpreterToVM method contendedMonitorEnter.
@TruffleBoundary
/*- Throwable.addSuppressed blacklisted by SVM (from try-with-resources) */
@SuppressWarnings("try")
private static void contendedMonitorEnter(StaticObject obj, Meta meta, EspressoLock lock, EspressoContext context) {
StaticObject thread = context.getCurrentThread();
try (Transition transition = Transition.transition(context, State.BLOCKED)) {
if (context.EnableManagement) {
// Locks bookkeeping.
meta.HIDDEN_THREAD_BLOCKED_OBJECT.setHiddenObject(thread, obj);
Field blockedCount = meta.HIDDEN_THREAD_BLOCKED_COUNT;
Target_java_lang_Thread.incrementThreadCounter(thread, blockedCount);
}
final boolean report = context.shouldReportVMEvents();
if (report) {
context.reportOnContendedMonitorEnter(obj);
}
monitorUnsafeEnter(lock);
if (report) {
context.reportOnContendedMonitorEntered(obj);
}
if (context.EnableManagement) {
meta.HIDDEN_THREAD_BLOCKED_OBJECT.setHiddenObject(thread, null);
}
}
}
use of com.oracle.truffle.espresso.impl.Field in project graal by oracle.
the class JniEnv method SetStaticShortField.
@JniImpl
public void SetStaticShortField(@SuppressWarnings("unused") @JavaType(Class.class) StaticObject unused, @Handle(Field.class) long fieldId, short val) {
Field field = fieldIds.getObject(fieldId);
assert field.isStatic();
field.set(field.getDeclaringKlass().tryInitializeAndGetStatics(), val);
}
use of com.oracle.truffle.espresso.impl.Field in project graal by oracle.
the class JniEnv method GetStaticFieldID.
/**
* <h3>jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig);
* </h3>
* <p>
* Returns the field ID for a static field of a class. The field is specified by its name and
* signature. The GetStatic<type>Field and SetStatic<type>Field families of accessor functions
* use field IDs to retrieve static fields.
* <p>
* GetStaticFieldID() causes an uninitialized class to be initialized.
*
* @param clazz a Java class object.
* @param namePtr the static 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 specified static field cannot be found.
* @throws NoSuchFieldError if the specified static 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 GetStaticFieldID(@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;
Field field = null;
Symbol<Name> fieldName = getNames().lookup(name);
if (fieldName != null) {
Symbol<Type> fieldType = getTypes().lookup(type);
if (fieldType != null) {
Klass klass = clazz.getMirrorKlass();
klass.safeInitialize();
// Lookup only if name and type are known symbols.
field = klass.lookupField(fieldName, fieldType, Klass.LookupMode.STATIC_ONLY);
assert field == null || field.getType().equals(fieldType);
}
}
if (field == null || !field.isStatic()) {
Meta meta = getMeta();
throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchFieldError, name);
}
return fieldIds.handlify(field);
}
Aggregations