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

Updated uq interpreter #4115

Open
wants to merge 64 commits into
base: master
Choose a base branch
from
Open

Conversation

utting
Copy link

@utting utting commented Dec 12, 2021

An interpreter for GraalVM IR graphs.
This can be useful for evaluating IR graphs during testing.

This implements 'interpret(InterpreterState)' methods in 30 of the most common subclasses of FixedNode in order to interpret those control-flow nodes, and 'interpretExpr(InterpreterState)' methods in most of the common data flow nodes in order to interpret expressions. The main entry point for the interpreter is the GraalInterpreter class and its executeGraph method.

The interpreter is based on a 2020-2021 UQ honours project by Leon Karstens plus further contributions by Kristian Thomassen and Mark Utting (UQ). Some current limitations are that it focusses mostly on high-level nodes rather than lowered nodes, supports only simple objects whose fields are primitive values, it attempts to interpret methods in ALL classes that are called (an alternative might be to treat some java.lang.* classes as pre-defined), and uses reflection to initialize static fields (which means that it cannot find some private fields).

kethomassen and others added 18 commits October 28, 2021 11:53
…with java.lang.reflect.InaccessibleObjectException issues.
…taFlow(_) to interpretExpr(_). And FixedNode provides a useful default implementation of the latter.
…. Make Node lookups total. Tag thrown exceptions with an unwinding flag to distinguish them from Exception objects returned normally.
Add IR Interpreter, with support for simple objects.
@graalvmbot
Copy link
Collaborator

  • Hello Kristian Thomassen, thanks for contributing a PR to our project!

We use the Oracle Contributor Agreement to make the copyright of contributions clear. We don't have a record of you having signed this yet, based on your email address k -(dot)- thomassen -(at)- uq -(dot)- edu -(dot)- au. You can sign it at that link.

If you think you've already signed it, please comment below and we'll check.

  • Hello Mark Utting, thanks for contributing a PR to our project!

We use the Oracle Contributor Agreement to make the copyright of contributions clear. We don't have a record of you having signed this yet, based on your email address m -(dot)- utting -(at)- uq -(dot)- edu -(dot)- au. You can sign it at that link.

If you think you've already signed it, please comment below and we'll check.

  • Hello Mark Utting, thanks for contributing a PR to our project!

We use the Oracle Contributor Agreement to make the copyright of contributions clear. We don't have a record of you having signed this yet, based on your email address bm -(dot)- utting -(at)- gmail -(dot)- com. You can sign it at that link.

If you think you've already signed it, please comment below and we'll check.

@GavinRay97
Copy link
Contributor

This is brilliant!

@graalvmbot
Copy link
Collaborator

Hello Brae Webb, thanks for contributing a PR to our project!

We use the Oracle Contributor Agreement to make the copyright of contributions clear. We don't have a record of you having signed this yet, based on your email address email -(at)- braewebb -(dot)- com. You can sign it at that link.

If you think you've already signed it, please comment below and we'll check.

@graalvmbot
Copy link
Collaborator

@graalvmbot
Copy link
Collaborator

  • Kristian Thomassen has signed the Oracle Contributor Agreement (based on email address k -(dot)- thomassen -(at)- uq -(dot)- edu -(dot)- au) so can contribute to this repository.
  • Mark Utting has signed the Oracle Contributor Agreement (based on email address m -(dot)- utting -(at)- uq -(dot)- edu -(dot)- au) so can contribute to this repository.
  • Brae Webb has signed the Oracle Contributor Agreement (based on email address email -(at)- braewebb -(dot)- com) so can contribute to this repository.

Copy link
Member

@dougxc dougxc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done a cursory review of this PR and left a few comments.
While it's a good start, it will need substantial work before it might be integrated. Namely, all the TODO's should be addressed and other unimplemented functionality should be completed.

return test(getInitialOptions(), name, args);
// return test(getInitialOptions(), name, args);
Result result = test(getInitialOptions(), name, args);
String interpret = System.getProperty("graal.Interpreter");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be test.graal.Interpreter to avoid clashing with the Graal options system which "owns" the graal. system property namespace.

return;
}
StructuredGraph methodGraph = parseForCompile(method, getOrCreateCompilationId(method, null), getInitialOptions());
// System.out.println("Method: " method.getName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete all commented out code.

@@ -0,0 1,80 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix copyright to be 2021 here and in all other new files.

/**
* Interpreter for Graal Intermediate Representation (IR) graphs.
*
* The main method is <code>executeGraph(g,args...)</code>, which interprets the graph <code>g</code>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use {@link ...} instead of <code> tags as the former will survive refactoring. Also, Use {@code ...} instead of <code>...</code>.

throw new UnsupportedOperationException("asPrimitiveConstant called on non primitive value");
}

public ResolvedJavaType getObjectType() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every method in this fundamental base class needs javadoc. Same goes for all other classes in this package.

@Override
public void setUnwindException() {
try {
if (!Exception.class.isAssignableFrom(Class.forName(type.toClassName()))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throwable is the base exception class, not Exception.
Instead of Class.forName, you should resolve Throwable.class to a ResolvedJavaType, caches it in a static, and use ResolvedJavaType.isAssignableFrom instead.

public abstract InterpreterValue getFieldValue(ResolvedJavaField field);

@Override
public boolean isUnwindException() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just throw an exception in the interpreter to model exception throwing?

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Jul 28, 2022
@oracle-contributor-agreement
Copy link

Thank you for your pull request and welcome to our community! To contribute, please sign the Oracle Contributor Agreement (OCA).
The following contributors of this PR have not signed the OCA:

To sign the OCA, please create an Oracle account and sign the OCA in Oracle's Contributor Agreement Application.

When singing the OCA, please provide your GitHub username. After signing the OCA and getting an OCA approval from Oracle, this PR will be automatically updated.

@oracle-contributor-agreement oracle-contributor-agreement bot removed the OCA Required At least one contributor does not have an approved Oracle Contributor Agreement. label Jul 28, 2022
Added a getTypeClass() method used by InterpreterValueMutableObject and InterpreterValueArray
Support primitive array. When accessing array elements, convert elements from native objects into InterpreterValue back and forth.
Use native objects to implement interpreter objects. Use reflection to construct native object, and VarHandles to access fields.
same with the orginal format
Added some static methods to convert primitive values into InterpreterValuePrimitive
Added this interface to support cross-module class loading and VarHandle use for InterpreterValueMutableObject.
Support null constant.
Support null constant.
Support null constant.
Removed getHeapValue() and setHeapValue().
Added this exception to distinguish interpretation exception and exception caused by interpreter malfunctioning.
Throws exception if the object is null in interpreter
Throws exception if the array is null in interpreter
setHeapValue() -> setNodeLookupValue()
setHeapValue() -> setNodeLookupValue()
setHeapValue() -> setNodeLookupValue()
Throws exception if the object is null in interpreter
Throws exception if the array is null in interpreter
Fixed object equality testing in interpreter.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OCA Verified All contributors have signed the Oracle Contributor Agreement. oca-signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants