Skip to content

Commit

Permalink
[GR-8509] Assert that interop types are used.
Browse files Browse the repository at this point in the history
PullRequest: graal/1128
  • Loading branch information
entlicher committed Mar 7, 2018
2 parents 6f13207 + fb1c7f4 commit f4ef1ad
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,13 @@ public void onReturnValue(AllocationEvent event) {
}
Node instrumentedNode = stack.getStack()[stack.getStackIndex()].getInstrumentedNode();
LanguageInfo languageInfo = instrumentedNode.getRootNode().getLanguageInfo();
String metaObjectString;
Object metaObject = env.findMetaObject(languageInfo, event.getValue());
String metaObjectString = env.toString(languageInfo, metaObject);
if (metaObject != null) {
metaObjectString = env.toString(languageInfo, metaObject);
} else {
metaObjectString = "null";
}
AllocationEventInfo info = new AllocationEventInfo(event.getLanguage(), event.getNewSize() - event.getOldSize(), event.getOldSize() != 0, metaObjectString);
handleEvent(stack, info);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void testBreakpointAfter() {
expectSuspended((SuspendedEvent event) -> {
assertSame(breakpoint3a, event.getBreakpoints().iterator().next());
assertSame(SuspendAnchor.BEFORE, event.getSuspendAnchor());
assertEquals("null", event.getReturnValue().as(String.class));
assertNull(event.getReturnValue());
});
expectSuspended((SuspendedEvent event) -> {
assertSame(breakpoint3b, event.getBreakpoints().iterator().next());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ public boolean isLanguageContextInitialized() {
* @since 0.17
*/
public DebugValue getReturnValue() {
return getTopStackFrame().wrapHeapValue(returnValue);
verifyValidState(false);
Object ret = returnValue;
if (ret == null) {
return null;
}
return getTopStackFrame().wrapHeapValue(ret);
}

// TODO CHumer: we also want to provide access to guest language errors. The API for that is not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ private static void allocateValueCheck(Object value) {

@TruffleBoundary
private void allocatedCheck(Object value, long oldSize, long newSize) {
assert value != null : "Allocated value must not be null.";
LinkedList<Reference<Object>> list = valueCheck.get();
assert list != null && !list.isEmpty() : "onEnter() was not called";
Object orig = list.removeLast().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ public void onEnter(VirtualFrame frame) {
/**
* Should get invoked after the node is invoked successfully.
*
* @param result the result value of the operation
* @param result the result value of the operation, must be an interop type (i.e. either
* implementing TruffleObject or be a primitive value), or <code>null</code>.
* @param frame the current frame of the execution.
* @since 0.12
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,18 @@ private static class GuardedExecutableNode extends ExecutableNode {
@Override
public Object execute(VirtualFrame frame) {
assert frameDescriptor == null || frameDescriptor == frame.getFrameDescriptor();
return fragment.execute(frame);
Object ret = fragment.execute(frame);
assert checkNullOrInterop(ret);
return ret;
}

private boolean checkNullOrInterop(Object obj) {
if (obj == null) {
return true;
}
AccessorInstrumentHandler.interopAccess().checkInteropType(obj);
return true;
}
}

/**
Expand Down Expand Up @@ -456,12 +465,14 @@ public String toString(Node node, Object value) {
* of this method is undefined if a type unknown to the language is passed as a value.
*
* @param language a language
* @param value a known value of that language
* @param value a known value of that language, must be an interop type (i.e. either
* implementing TruffleObject or be a primitive value)
* @return a human readable string representation of the value.
* @see #findLanguage(java.lang.Object)
* @since 0.27
*/
public String toString(LanguageInfo language, Object value) {
AccessorInstrumentHandler.interopAccess().checkInteropType(value);
final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language);
return AccessorInstrumentHandler.langAccess().toStringIfVisible(env, value, false);
}
Expand Down Expand Up @@ -496,12 +507,14 @@ public Object findMetaObject(Node node, Object value) {
* language}, if any.
*
* @param language a language
* @param value a value to find the meta-object of
* @param value a value to find the meta-object of, must be an interop type (i.e. either
* implementing TruffleObject or be a primitive value)
* @return the meta-object, or <code>null</code>
* @see #findLanguage(java.lang.Object)
* @since 0.27
*/
public Object findMetaObject(LanguageInfo language, Object value) {
AccessorInstrumentHandler.interopAccess().checkInteropType(value);
final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language);
return AccessorInstrumentHandler.langAccess().findMetaObject(env, value);
}
Expand Down Expand Up @@ -530,12 +543,14 @@ public SourceSection findSourceLocation(Node node, Object value) {
* if any.
*
* @param language a language
* @param value a value to get the source location for
* @param value a value to get the source location for, must be an interop type (i.e. either
* implementing TruffleObject or be a primitive value)
* @return a source location of the object, or <code>null</code>
* @see #findLanguage(java.lang.Object)
* @since 0.27
*/
public SourceSection findSourceLocation(LanguageInfo language, Object value) {
AccessorInstrumentHandler.interopAccess().checkInteropType(value);
final TruffleLanguage.Env env = AccessorInstrumentHandler.engineAccess().getEnvForInstrument(language);
return AccessorInstrumentHandler.langAccess().findSourceLocation(env, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ protected ExecutableNode(TruffleLanguage<?> language) {
* Execute this fragment at the place where it was parsed.
*
* @param frame the actual frame valid at the parsed location
* @return the result of the execution
* @return the result of the execution, must be an interop type (i.e. either implementing
* TruffleObject or be a primitive value), or <code>null</code>.
* @since 0.31
*/
public abstract Object execute(VirtualFrame frame);
Expand Down

0 comments on commit f4ef1ad

Please sign in to comment.