Search in sources :

Example 1 with KeysArray

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

the class EspressoInterop method getMembers.

@ExportMessage
@TruffleBoundary
static Object getMembers(StaticObject receiver, @SuppressWarnings("unused") boolean includeInternal) {
    receiver.checkNotForeign();
    if (isNull(receiver)) {
        return EmptyKeysArray.INSTANCE;
    }
    ArrayList<String> members = new ArrayList<>();
    if (receiver.getKlass() == receiver.getKlass().getMeta().java_lang_Class) {
        // SVM does not like ArrayList.addAll(). Do manual copy.
        for (String s : CLASS_KEYS) {
            members.add(s);
        }
    }
    ObjectKlass k = getInteropKlass(receiver);
    for (Field f : k.getFieldTable()) {
        if (f.isPublic() && !f.isRemoved()) {
            members.add(f.getNameAsString());
        }
    }
    for (Method.MethodVersion m : k.getVTable()) {
        if (LookupVirtualMethodNode.isCandidate(m.getMethod())) {
            // Note: If there are overloading, the same key may appear twice.
            // TODO: Cache the keys array in the Klass.
            members.add(m.getMethod().getInteropString());
        }
    }
    // SVM does not like ArrayList.toArray(). Do manual copy.
    String[] array = new String[members.size()];
    int pos = 0;
    for (String str : members) {
        array[pos++] = str;
    }
    return new KeysArray(array);
}
Also used : Field(com.oracle.truffle.espresso.impl.Field) ArrayList(java.util.ArrayList) EmptyKeysArray(com.oracle.truffle.espresso.impl.EmptyKeysArray) KeysArray(com.oracle.truffle.espresso.impl.KeysArray) ObjectKlass(com.oracle.truffle.espresso.impl.ObjectKlass) Method(com.oracle.truffle.espresso.impl.Method) ExportMessage(com.oracle.truffle.api.library.ExportMessage) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)

Aggregations

TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 ExportMessage (com.oracle.truffle.api.library.ExportMessage)1 EmptyKeysArray (com.oracle.truffle.espresso.impl.EmptyKeysArray)1 Field (com.oracle.truffle.espresso.impl.Field)1 KeysArray (com.oracle.truffle.espresso.impl.KeysArray)1 Method (com.oracle.truffle.espresso.impl.Method)1 ObjectKlass (com.oracle.truffle.espresso.impl.ObjectKlass)1 ArrayList (java.util.ArrayList)1