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

8266626: Check that the target address of a native call is not NULL #530

Closed

Conversation

@JornVernee
Copy link
Member

@JornVernee JornVernee commented May 7, 2021

This patch adds a check when unboxing the target address of a native call to check that the address is not NULL. Additionally, it adds checks earlier when an address is specified with a linking request, to check that that address is not NULL.

I didn't see any regressions on the CallOverhead* benchmarks.

Thanks,
Jorn


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Issue

  • JDK-8266626: Check that the target address of a native call is not NULL

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/panama-foreign pull/530/head:pull/530
$ git checkout pull/530

Update a local copy of the PR:
$ git checkout pull/530
$ git pull https://git.openjdk.java.net/panama-foreign pull/530/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 530

View PR using the GUI difftool:
$ git pr show -t 530

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/panama-foreign/pull/530.diff

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented May 7, 2021

👋 Welcome back jvernee! A progress list of the required criteria for merging this PR into foreign-memaccess+abi will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label May 7, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented May 7, 2021

Webrevs

Copy link
Collaborator

@mcimadamore mcimadamore left a comment

Added some comments

private static void checkSymbol(Addressable symbol) {
MemoryAddress symbolAddr = symbol.address();
if (symbolAddr.equals(MemoryAddress.NULL))
throw new IllegalArgumentException("Symbol is NULL: " + symbolAddr);
Copy link
Collaborator

@mcimadamore mcimadamore May 7, 2021

Choose a reason for hiding this comment

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

IAE or NPE?

Copy link
Member Author

@JornVernee JornVernee May 7, 2021

Choose a reason for hiding this comment

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

I think IAE, in order to avoid confusion with the case where symbol is null (This is also why I added the MA instance to the error message). NPE seems more appropriate for the null case I think.

@openjdk
Copy link

@openjdk openjdk bot commented May 10, 2021

@JornVernee this pull request can not be integrated into foreign-memaccess+abi due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout Check_NULL
git fetch https://git.openjdk.java.net/panama-foreign foreign-memaccess+abi
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge foreign-memaccess+abi"
git push

@JornVernee
Copy link
Member Author

@JornVernee JornVernee commented May 10, 2021

I've addressed review comments:

  • Move symbol check into shared code, this also makes sure we do a more explicit null check in the virtual case.
  • added some documentation about the thrown exceptions.

@openjdk openjdk bot removed the merge-conflict label May 10, 2021
Copy link
Collaborator

@mcimadamore mcimadamore left a comment

Looks good - some minor quibbles over javadoc

@@ -196,7 +196,8 @@ static CLinker getInstance() {
* @param type the method type.
* @param function the function descriptor.
* @return the downcall method handle.
* @throws IllegalArgumentException in the case of a method type and function descriptor mismatch.
* @throws IllegalArgumentException in the case of a method type and function descriptor mismatch, or if the symbol
* is {@link MemoryAddress#NULL}
Copy link
Collaborator

@mcimadamore mcimadamore May 10, 2021

Choose a reason for hiding this comment

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

Is the indentation deliberate? What about NPE?

Copy link
Member Author

@JornVernee JornVernee May 10, 2021

Choose a reason for hiding this comment

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

Yes, the indentation is deliberate.

I'll add the NPE as well, looks like that was missing from before.

Copy link
Member Author

@JornVernee JornVernee May 10, 2021

Choose a reason for hiding this comment

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

Actually, I think the NPE is covered by this comment on the class

 * <p> Unless otherwise specified, passing a {@code null} argument, or an array argument containing one or more {@code null}
 * elements to a method in this class causes a {@link NullPointerException NullPointerException} to be thrown. </p>

Copy link
Collaborator

@mcimadamore mcimadamore May 10, 2021

Choose a reason for hiding this comment

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

ah true

@openjdk
Copy link

@openjdk openjdk bot commented May 10, 2021

@JornVernee This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8266626: Check that the target address of a native call is not NULL

Reviewed-by: mcimadamore

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been no new commits pushed to the foreign-memaccess+abi branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the foreign-memaccess+abi branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label May 10, 2021
@JornVernee
Copy link
Member Author

@JornVernee JornVernee commented May 10, 2021

/integrate

@openjdk openjdk bot closed this May 10, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels May 10, 2021
@openjdk
Copy link

@openjdk openjdk bot commented May 10, 2021

@JornVernee Pushed as commit 872b126.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@JornVernee JornVernee deleted the Check_NULL branch Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants