Search in sources :

Example 31 with Field

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

the class ClassRedefinition method createDelegationFrom.

public synchronized Field createDelegationFrom(Field field) {
    Field delegationField = RedefineAddedField.createDelegationField(field);
    if (currentDelegationFields == null) {
        currentDelegationFields = new ArrayList<>(1);
    }
    currentDelegationFields.add(delegationField);
    return delegationField;
}
Also used : RedefineAddedField(com.oracle.truffle.espresso.impl.RedefineAddedField) Field(com.oracle.truffle.espresso.impl.Field) ParserField(com.oracle.truffle.espresso.impl.ParserField)

Example 32 with Field

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

the class StaticObject method toVerboseString.

@TruffleBoundary
public final String toVerboseString() {
    if (this == NULL) {
        return "null";
    }
    if (isForeignObject()) {
        return String.format("foreign object: %s\n%s", getKlass().getTypeAsString(), InteropLibrary.getUncached().toDisplayString(rawForeignObject()));
    }
    if (getKlass() == getKlass().getMeta().java_lang_String) {
        Meta meta = getKlass().getMeta();
        StaticObject value = meta.java_lang_String_value.getObject(this);
        if (value == null || isNull(value)) {
            // Prevents debugger crashes when trying to inspect a string in construction.
            return "<UNINITIALIZED>";
        }
        return Meta.toHostStringStatic(this);
    }
    if (isArray()) {
        return unwrap().toString();
    }
    if (getKlass() == getKlass().getMeta().java_lang_Class) {
        return "mirror: " + getMirrorKlass().toString();
    }
    StringBuilder str = new StringBuilder(getKlass().getType().toString());
    for (Field f : ((ObjectKlass) getKlass()).getFieldTable()) {
        // Also prints hidden fields
        if (!f.isRemoved()) {
            str.append("\n    ").append(f.getName()).append(": ").append(f.get(this).toString());
        }
    }
    return str.toString();
}
Also used : Meta(com.oracle.truffle.espresso.meta.Meta) Field(com.oracle.truffle.espresso.impl.Field) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Example 33 with Field

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

the class Target_java_lang_invoke_MethodHandleNatives method plantFieldMemberName.

private static void plantFieldMemberName(StaticObject memberName, Klass resolutionKlass, Symbol<Name> name, Symbol<Type> type, int refKind, Klass callerKlass, boolean constraintsCheck, Meta meta) {
    Field field = resolutionKlass.lookupField(name, type);
    if (field == null) {
        throw meta.throwExceptionWithMessage(meta.java_lang_NoSuchFieldError, cat("Failed lookup for field ", resolutionKlass.getName(), "#", name, ":", type));
    }
    if (constraintsCheck) {
        field.checkLoadingConstraints(callerKlass.getDefiningClassLoader(), resolutionKlass.getDefiningClassLoader());
    }
    plantResolvedField(memberName, field, refKind, meta);
}
Also used : REF_getField(com.oracle.truffle.espresso.classfile.Constants.REF_getField) Field(com.oracle.truffle.espresso.impl.Field) REF_putField(com.oracle.truffle.espresso.classfile.Constants.REF_putField)

Example 34 with Field

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

the class EspressoInterop method writeMember.

@ExportMessage
static void writeMember(StaticObject receiver, String member, Object value, @Cached @Exclusive LookupInstanceFieldNode lookup, @Cached ToEspressoNode toEspresso, @Shared("error") @Cached BranchProfile error) throws UnsupportedTypeException, UnknownIdentifierException, UnsupportedMessageException {
    receiver.checkNotForeign();
    Field f = lookup.execute(getInteropKlass(receiver), member);
    if (f != null) {
        if (f.isFinalFlagSet()) {
            error.enter();
            throw UnsupportedMessageException.create();
        }
        f.set(receiver, toEspresso.execute(value, f.resolveTypeKlass()));
        return;
    }
    error.enter();
    throw UnknownIdentifierException.create(member);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Example 35 with Field

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

the class Target_sun_misc_Unsafe method putCharVolatile.

@TruffleBoundary(allowInlining = true)
@Substitution(hasReceiver = true)
public static void putCharVolatile(@SuppressWarnings("unused") @JavaType(Unsafe.class) StaticObject self, @JavaType(Object.class) StaticObject holder, long offset, char value, @Inject Meta meta) {
    if (isNullOrArray(holder)) {
        UnsafeAccess.getIfAllowed(meta).putCharVolatile(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.setChar(holder, value, true);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

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