Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-34476] Add member interop objects and declared member APIs. #9783

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
import org.junit.Before;
import org.junit.Test;

import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Cached;
import com.oracle.truffle.api.dsl.Cached.Shared;
import com.oracle.truffle.api.dsl.GenerateUncached;
import com.oracle.truffle.api.dsl.NodeChild;
import com.oracle.truffle.api.dsl.ReportPolymorphism;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnknownMemberException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.CachedLibrary;
import com.oracle.truffle.api.library.DynamicDispatchLibrary;
Expand Down Expand Up @@ -186,8 +187,8 @@ static boolean isMemberReadable(DynamicallyDispatchedObject receiver, String mem

@ExportMessage
@SuppressWarnings("unused")
static Object getMembers(DynamicallyDispatchedObject receiver, boolean includeInternal) {
return receiver;
static Object getMemberObjects(DynamicallyDispatchedObject receiver) {
throw CompilerDirectives.shouldNotReachHere("Not implemented, not called.");
}

@SuppressWarnings("static-method")
Expand All @@ -200,18 +201,18 @@ public Class<?> dispatch() {
@ReportPolymorphism
abstract static class ReadMember {

static final String CACHED_NAME = "cached";
static final Object CACHED_NAME = "cached";

@Specialization(guards = "name == CACHED_NAME")
@Specialization(guards = "member == CACHED_NAME")
@ReportPolymorphism.Exclude
static Object readStaticCached(DynamicallyDispatchedObject receiver, @SuppressWarnings("unused") String name,
@SuppressWarnings("unused") @Cached(value = "name", neverDefault = false) String cachedName) {
static Object readStaticCached(DynamicallyDispatchedObject receiver, @SuppressWarnings("unused") Object member,
@SuppressWarnings("unused") @Cached(value = "member", neverDefault = false) Object cachedMember) {
return receiver;
}

@Specialization(limit = "3", guards = "name == cachedName")
static Object readCached(DynamicallyDispatchedObject receiver, @SuppressWarnings("unused") String name,
@SuppressWarnings("unused") @Cached("name") String cachedName) {
@Specialization(limit = "3", guards = "member == cachedMember")
static Object readCached(DynamicallyDispatchedObject receiver, @SuppressWarnings("unused") Object member,
@SuppressWarnings("unused") @Cached("member") Object cachedMember) {
return receiver;
}
}
Expand All @@ -224,11 +225,11 @@ abstract static class SplitReadPropertyNode extends SplittingTestNode {
static final int LIBRARY_LIMIT = 3;

@Specialization(guards = "objects.hasMembers(receiver)", limit = "LIBRARY_LIMIT")
protected Object readObject(Object receiver, String name,
protected Object readObject(Object receiver, Object member,
@CachedLibrary("receiver") InteropLibrary objects) {
try {
return objects.readMember(receiver, name);
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
return objects.readMember(receiver, member);
} catch (UnsupportedMessageException | UnknownMemberException e) {
throw new AssertionError("Should not reach here");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.NodeLibrary;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnknownMemberException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
Expand Down Expand Up @@ -177,23 +177,23 @@ boolean hasMembers() {

@ExportMessage
@SuppressWarnings("static-method")
boolean isMemberReadable(String name) {
boolean isMemberReadable(Object name) {
return name.equals(VAR);
}

@ExportMessage
Object readMember(String name) throws UnknownIdentifierException {
Object readMember(Object name) throws UnknownMemberException {
if (name.equals(VAR)) {
return readNode.execute((VirtualFrame) frame);
} else {
CompilerDirectives.transferToInterpreter();
throw UnknownIdentifierException.create(name);
throw UnknownMemberException.create(name);
}
}

@ExportMessage
@SuppressWarnings("static-method")
Object getMembers(@SuppressWarnings("unused") boolean includeInternal) throws UnsupportedMessageException {
Object getMemberObjects() throws UnsupportedMessageException {
throw UnsupportedMessageException.create();
}
}
Expand Down Expand Up @@ -276,9 +276,9 @@ private ReadVarExecNode(EventContext context) {
protected void onReturnValue(VirtualFrame frame, Object result) {
try {
Object scope = nodeLibrary.getScope(node, frame, false);
Object val = interop.readMember(scope, VAR);
Object val = interop.readMember(scope, (Object) VAR);
throw context.createUnwind(val);
} catch (UnsupportedMessageException | UnknownIdentifierException e) {
} catch (UnsupportedMessageException | UnknownMemberException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import com.oracle.truffle.api.instrumentation.SourceSectionFilter;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.NodeLibrary;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnknownMemberException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.nodes.Node;
Expand Down Expand Up @@ -106,10 +106,10 @@ protected void onEnter(VirtualFrame frame) {
try {
Object scope = nodeLibrary.getScope(instrumentedNode, frame, true);
assert interop.hasMembers(scope);
long x = interop.asLong(interop.readMember(scope, "x"));
long y = interop.asLong(interop.readMember(scope, "y"));
interop.writeMember(scope, "z", x + y);
} catch (UnsupportedMessageException | UnknownIdentifierException | UnsupportedTypeException e) {
long x = interop.asLong(interop.readMember(scope, (Object) "x"));
long y = interop.asLong(interop.readMember(scope, (Object) "y"));
interop.writeMember(scope, (Object) "z", x + y);
} catch (UnsupportedMessageException | UnknownMemberException | UnsupportedTypeException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import com.oracle.truffle.api.interop.ExceptionType;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnknownMemberException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
Expand Down Expand Up @@ -114,22 +114,22 @@ boolean hasMembers() {

@ExportMessage
@SuppressWarnings({"unused", "static-method"})
Object getMembers(boolean includeInternal) throws UnsupportedMessageException {
Object getMemberObjects() throws UnsupportedMessageException {
throw UnsupportedMessageException.create();
}

@ExportMessage
@SuppressWarnings("static-method")
boolean isMemberReadable(String member) {
boolean isMemberReadable(Object member) {
return member.equals("property");
}

@ExportMessage
Object readMember(String member) throws UnknownIdentifierException {
Object readMember(Object member) throws UnknownMemberException {
if (member.equals("property")) {
return property;
}
throw UnknownIdentifierException.create(member);
throw UnknownMemberException.create(member);
}
}

Expand All @@ -149,10 +149,10 @@ public int execute(VirtualFrame frame) {
return child.execute(frame);
} catch (AbstractTruffleException e) {
try {
if ((boolean) exceptions.readMember(e, "property")) {
if ((boolean) exceptions.readMember(e, (Object) "property")) {
return 42;
}
} catch (UnsupportedMessageException | UnknownIdentifierException interopException) {
} catch (UnsupportedMessageException | UnknownMemberException interopException) {
throw CompilerDirectives.shouldNotReachHere(interopException);
}
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import com.oracle.truffle.api.interop.ArityException;
import com.oracle.truffle.api.interop.InteropLibrary;
import com.oracle.truffle.api.interop.TruffleObject;
import com.oracle.truffle.api.interop.UnknownIdentifierException;
import com.oracle.truffle.api.interop.UnknownMemberException;
import com.oracle.truffle.api.interop.UnsupportedMessageException;
import com.oracle.truffle.api.interop.UnsupportedTypeException;
import com.oracle.truffle.api.library.CachedLibrary;
Expand Down Expand Up @@ -126,8 +126,8 @@ protected boolean match(Object compiledRegex, byte[] array, int inputLen, int fr
@Cached TruffleString.FromByteArrayNode fromByteArrayNode) {
try {
TruffleString input = fromByteArrayNode.execute(array, 0, inputLen, encoding, false);
return (boolean) tregexEngine.invokeMember(compiledRegex, "execBoolean", input, from);
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException | UnknownIdentifierException e) {
return (boolean) tregexEngine.invokeMember(compiledRegex, (Object) "execBoolean", input, from);
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException | UnknownMemberException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
Expand All @@ -143,8 +143,8 @@ protected boolean match(Object compiledRegex, ByteBuffer buffer, int inputLen, i
@Cached TruffleString.FromNativePointerNode fromNativePointerNode) {
try {
TruffleString input = fromNativePointerNode.execute(new PointerObject(buffer), 0, inputLen, encoding, false);
return (boolean) tregexEngine.invokeMember(compiledRegex, "execBoolean", input, from);
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException | UnknownIdentifierException e) {
return (boolean) tregexEngine.invokeMember(compiledRegex, (Object) "execBoolean", input, from);
} catch (UnsupportedMessageException | UnsupportedTypeException | ArityException | UnknownMemberException e) {
throw CompilerDirectives.shouldNotReachHere(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public RootNode getRootNode() {
return rootNode;
}

@SuppressWarnings("deprecation") // GR-58181
public Object getThisValue() {
Object theScope = getScope();
if (theScope == null) {
Expand All @@ -131,11 +132,13 @@ public Object getThisValue() {
}
}

@SuppressWarnings("deprecation") // GR-58181
public Object getVariable(String identifier) throws InteropException {
Object theScope = getScope();
return theScope != null ? INTEROP.readMember(theScope, identifier) : null;
}

@SuppressWarnings("deprecation") // GR-58181
public void setVariable(Object value, String identifier) {
Object theScope = getScope();
if (theScope == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public boolean onFieldAccess(FieldRef field, Object receiver) {

@Override
@TruffleBoundary
@SuppressWarnings("deprecation") // GR-58181
public boolean onMethodEntry(MethodRef method, Object scope) {
boolean active = false;
// collect variable information from scope
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@
*
* <p>
* Classes cannot be enumerated; and in this implementation, not even the ones already loaded. e.g.
* {@link InteropLibrary#getMembers(Object) Peeking all memebers} will return an empty interop
* {@link InteropLibrary#getMemberObjects(Object) Peeking all memebers} will return an empty interop
* collection. <br>
* {@link InteropLibrary#readMember(Object, String) Reading a member} will trigger class loading; it
* {@link InteropLibrary#readMember(Object, Object) Reading a member} will trigger class loading; it
* is equivalent to calling {@link Class#forName(String, boolean, ClassLoader)} with the provided
* guest class loader. <br>
* {@link ClassNotFoundException} is translated into interop's {@link UnknownIdentifierException
Expand All @@ -64,6 +64,7 @@
* {@link InteropLibrary#isString(Object) interop string} as argument, the path to add.
*/
@ExportLibrary(InteropLibrary.class)
@SuppressWarnings({"truffle-abstract-export", "deprecation"}) // GR-58181
public final class EspressoBindings implements TruffleObject {
public static final String JAVA_VM = "<JavaVM>";
public static final String ADD_PATH = "addPath";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static Object createVariables(Local[] liveLocals, Frame frame, Symbol<Sym
// variable names through the Interop API. Clients which are bytecode based, e.g. JDWP that use
// slot numbers as identifiers must operate directly by using read/write member methods.
@ExportLibrary(InteropLibrary.class)
@SuppressWarnings({"truffle-abstract-export", "deprecation"}) // GR-58181
static final class VariablesMapObject implements TruffleObject {

final Map<String, FrameSlotInfo> slots;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private TruffleObject rtldDefault() {
}

@ExportLibrary(InteropLibrary.class)
@SuppressWarnings({"truffle-abstract-export", "deprecation"}) // GR-58181
static class DefaultLibrary implements TruffleObject {

final @Pointer TruffleObject dlsym;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public void unloadLibrary(@Pointer TruffleObject library) {
}

@Override
@SuppressWarnings("deprecation") // GR-58181
public @Pointer TruffleObject lookupSymbol(@Pointer TruffleObject library, String symbolName) {
try {
TruffleObject symbol = (TruffleObject) uncachedInterop.readMember(library, symbolName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import com.oracle.truffle.espresso.vm.VM;

@ExportLibrary(InteropLibrary.class)
@SuppressWarnings({"truffle-abstract-export", "deprecation"}) // GR-58181
public abstract class Klass extends ContextAccessImpl implements ModifiersProvider, KlassRef, TruffleObject {

// region Interop
Expand Down Expand Up @@ -1216,6 +1217,7 @@ public Klass[] getImplementedInterfaces() {
/**
* Returns {@code true} if the type is a member type.
*/
@ExportMessage.Ignore // GR-58181
public abstract boolean isMember();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import com.oracle.truffle.espresso.impl.Method;

@ExportLibrary(InteropLibrary.class)
@SuppressWarnings({"truffle-abstract-export", "deprecation"}) // GR-58181
final class SubstitutionScope implements TruffleObject {
@CompilationFinal(dimensions = 1) private final Object[] args;
private final Method method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public static AbstractGetFieldNode create(Field f) {
// @formatter:on
}

@SuppressWarnings("deprecation") // GR-58181
protected Object getForeignField(StaticObject receiver, InteropLibrary interopLibrary, EspressoLanguage language, Meta meta, BranchProfile error) {
assert getField().getDeclaringKlass().isAssignableFrom(receiver.getKlass());
assert !getField().isStatic();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static AbstractSetFieldNode create(Field f) {
// @formatter:on
}

@SuppressWarnings("deprecation") // GR-58181
protected void setForeignField(StaticObject receiver, Object fieldValue, InteropLibrary interopLibrary, EspressoLanguage language, EspressoContext context, BranchProfile error) {
assert field.getDeclaringKlass().isAssignableFrom(receiver.getKlass());
assert receiver.isForeignObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ public Object convert(StaticObject foreign) {
public static final class OptionalTypeConverter implements InternalTypeConverter {

@Override
@SuppressWarnings("deprecation") // GR-58181
public StaticObject convertInternal(InteropLibrary interop, Object value, Meta meta, ToReference.DynamicToReference toEspresso) throws UnsupportedTypeException {
try {
Object result = interop.invokeMember(value, "orElse", StaticObject.NULL);
Expand All @@ -356,6 +357,7 @@ public StaticObject convertInternal(InteropLibrary interop, Object value, Meta m
public static final class BigDecimalTypeConverter implements InternalTypeConverter {

@Override
@SuppressWarnings("deprecation") // GR-58181
public StaticObject convertInternal(InteropLibrary interop, Object value, Meta meta, ToReference.DynamicToReference toEspresso) throws UnsupportedTypeException {
try {
// state required to reconstruct in guest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ public static String getMetaName(Object metaObject, InteropLibrary interop) {
}

@TruffleBoundary
@SuppressWarnings("deprecation") // GR-58181
public static void checkHasAllFieldsOrThrow(Object value, ObjectKlass klass, InteropLibrary interopLibrary, Meta meta) throws UnsupportedTypeException {
CompilerAsserts.partialEvaluationConstant(klass);
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ private ExternalPluginHandler(StaticObject handler, InteropLibrary library) {
this.interopLibrary = library;
}

@SuppressWarnings("deprecation") // GR-58181
public static ExternalPluginHandler create(StaticObject guestHandler) throws IllegalArgumentException {
InteropLibrary library = InteropLibrary.getUncached(guestHandler);

Expand All @@ -57,6 +58,7 @@ public static ExternalPluginHandler create(StaticObject guestHandler) throws Ill
return new ExternalPluginHandler(guestHandler, library);
}

@SuppressWarnings("deprecation") // GR-58181
public boolean shouldRerunClassInitializer(Klass klass, boolean changed, DebuggerController controller) {
try {
return (boolean) interopLibrary.invokeMember(guestHandler, RERUN_CLINIT, klass.mirror(), changed);
Expand All @@ -66,6 +68,7 @@ public boolean shouldRerunClassInitializer(Klass klass, boolean changed, Debugge
return false;
}

@SuppressWarnings("deprecation") // GR-58181
public void postHotSwap(Klass[] changedKlasses, DebuggerController controller) {
try {
StaticObject[] guestClasses = new StaticObject[changedKlasses.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

@GenerateInteropNodes
@ExportLibrary(value = InteropLibrary.class, receiverType = StaticObject.class)
@SuppressWarnings("truffle-abstract-export") // GR-58181
public class ByteBufferInterop extends EspressoInterop {

@ExportMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
@GenerateInteropNodes
@ExportLibrary(value = InteropLibrary.class, receiverType = StaticObject.class)
@Shareable
@SuppressWarnings({"truffle-abstract-export", "deprecation"}) // GR-58181
public class EspressoInterop extends BaseInterop {
// region ### is/as checks/conversions

Expand Down
Loading