Search in sources :

Example 16 with ObjectKlass

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

the class JDKCacheRedefinitionPlugin method postClassRedefinition.

@Override
public void postClassRedefinition(ObjectKlass[] changedKlasses) {
    synchronized (threadGroupContexts) {
        for (ObjectKlass changedKlass : changedKlasses) {
            if (flushFromCachesMethod != null) {
                flushFromCachesMethod.invokeDirect(null, changedKlass.mirror());
            }
            Iterator<WeakReference<StaticObject>> iterator = threadGroupContexts.iterator();
            while (iterator.hasNext()) {
                WeakReference<StaticObject> ref = iterator.next();
                StaticObject context = ref.get();
                if (context != null) {
                    removeBeanInfoMethod.invokeDirect(context, changedKlass.mirror());
                } else {
                    // clean up list when context was reclaimed
                    iterator.remove();
                }
            }
        }
    }
}
Also used : StaticObject(com.oracle.truffle.espresso.runtime.StaticObject) WeakReference(java.lang.ref.WeakReference) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass)

Example 17 with ObjectKlass

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

the class JDWPContextImpl method getNestedTypes.

@Override
public KlassRef[] getNestedTypes(KlassRef klass) {
    if (klass instanceof ObjectKlass) {
        ArrayList<KlassRef> result = new ArrayList<>();
        ObjectKlass objectKlass = (ObjectKlass) klass;
        List<Symbol<Symbol.Name>> nestedTypeNames = objectKlass.getNestedTypeNames();
        StaticObject classLoader = objectKlass.getDefiningClassLoader();
        for (Symbol<Symbol.Name> nestedType : nestedTypeNames) {
            Symbol<Symbol.Type> type = context.getTypes().fromClassGetName(nestedType.toString());
            KlassRef loadedKlass = context.getRegistries().findLoadedClass(type, classLoader);
            if (loadedKlass != null && loadedKlass != klass) {
                result.add(loadedKlass);
            }
        }
        return result.toArray(new KlassRef[0]);
    }
    return null;
}
Also used : Symbol(com.oracle.truffle.espresso.descriptors.Symbol) ArrayList(java.util.ArrayList) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) KlassRef(com.oracle.truffle.espresso.jdwp.api.KlassRef)

Example 18 with ObjectKlass

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

the class StaticObject method createClass.

public static StaticObject createClass(Klass klass) {
    assert klass != null;
    ObjectKlass guestClass = klass.getMeta().java_lang_Class;
    StaticObject newObj = guestClass.getLinkedKlass().getShape(false).getFactory().create(guestClass);
    newObj.initInstanceFields(guestClass);
    klass.getMeta().java_lang_Class_classLoader.setObject(newObj, klass.getDefiningClassLoader());
    if (klass.getContext().getJavaVersion().modulesEnabled()) {
        newObj.setModule(klass);
    }
    if (klass.isArray() && klass.getMeta().java_lang_Class_componentType != null) {
        klass.getMeta().java_lang_Class_componentType.setObject(newObj, ((ArrayKlass) klass).getComponentType().mirror());
    }
    // Will be overriden if necessary, but should be initialized to non-host null.
    klass.getMeta().HIDDEN_PROTECTION_DOMAIN.setHiddenObject(newObj, StaticObject.NULL);
    // Final hidden field assignment
    klass.getMeta().HIDDEN_MIRROR_KLASS.setHiddenObject(newObj, klass);
    return trackAllocation(klass, newObj);
}
Also used : ArrayKlass(com.oracle.truffle.espresso.impl.ArrayKlass) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass)

Example 19 with ObjectKlass

use of com.oracle.truffle.espresso.impl.ObjectKlass 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 20 with ObjectKlass

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

the class EspressoInterop method isMemberInvocable.

@ExportMessage
static boolean isMemberInvocable(StaticObject receiver, String member, @Exclusive @Cached LookupVirtualMethodNode lookupMethod) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return false;
    }
    ObjectKlass k = getInteropKlass(receiver);
    return lookupMethod.isInvocable(k, member);
}
Also used : ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) ExportMessage(com.oracle.truffle.api.library.ExportMessage)

Aggregations

ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)35 Klass (com.oracle.truffle.espresso.impl.Klass)15 StaticObject (com.oracle.truffle.espresso.runtime.StaticObject)12 JavaType (com.oracle.truffle.espresso.substitutions.JavaType)10 ArrayKlass (com.oracle.truffle.espresso.impl.ArrayKlass)9 ArrayList (java.util.ArrayList)8 Method (com.oracle.truffle.espresso.impl.Method)7 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)6 RuntimeConstantPool (com.oracle.truffle.espresso.classfile.RuntimeConstantPool)5 Field (com.oracle.truffle.espresso.impl.Field)5 ParserKlass (com.oracle.truffle.espresso.impl.ParserKlass)5 NoSafepoint (com.oracle.truffle.espresso.jni.NoSafepoint)5 Symbol (com.oracle.truffle.espresso.descriptors.Symbol)4 Name (com.oracle.truffle.espresso.descriptors.Symbol.Name)4 ClassRegistry (com.oracle.truffle.espresso.impl.ClassRegistry)4 Meta (com.oracle.truffle.espresso.meta.Meta)4 Matcher (java.util.regex.Matcher)4 InnerClassesAttribute (com.oracle.truffle.espresso.classfile.attributes.InnerClassesAttribute)3 EspressoException (com.oracle.truffle.espresso.runtime.EspressoException)3 FrameInstance (com.oracle.truffle.api.frame.FrameInstance)2