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

8256865: Foreign Memory Access and Linker API are missing NPE checks #1388

Closed
wants to merge 13 commits into from

Conversation

mcimadamore
Copy link
Contributor

@mcimadamore mcimadamore commented Nov 23, 2020

Both the Foreign Memory Access and the Foreign Linker APIs leave something to be desired when it comes to handling NPEs - first, most of the API javadoc is oblivious to NPEs being thrown. Secondly, not all API method implementations add expicit NPE checks - with the result of NPE often being thrown very deep in the call chain - if at all. Third, test for API coverage of nulls is ad-hoc.

This patch rectifies all these issues. To increase coverage for null injected into APIs, this patch introduces a new framework for testing an API in bulk, so that all methods are reflectively called with some values replaced with nulls, so that all combinations are tried.

I've also added, as part of this patch, a test to cover the statics in MemoryAccess which were not covered throughly.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Testing

Linux x64 Linux x86 Windows x64 macOS x64
Build ❌ (1/6 failed) ❌ (2/2 failed) ✔️ (2/2 passed) ✔️ (2/2 passed)
Test (tier1) ✔️ (9/9 passed) ✔️ (9/9 passed)

Failed test tasks

Issue

  • JDK-8256865: Foreign Memory Access and Linker API are missing NPE checks

Reviewers

Download

$ git fetch https://git.openjdk.java.net/jdk pull/1388/head:pull/1388
$ git checkout pull/1388

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 23, 2020

👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into master 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 Pull request is ready for review label Nov 23, 2020
@openjdk
Copy link

openjdk bot commented Nov 23, 2020

@mcimadamore The following label will be automatically applied to this pull request:

  • core-libs

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the core-libs core-libs-dev@openjdk.org label Nov 23, 2020
@mlbridge
Copy link

mlbridge bot commented Nov 23, 2020

Webrevs

@mcimadamore
Copy link
Contributor Author

/csr

@openjdk openjdk bot added the csr Pull request needs approved CSR before integration label Nov 23, 2020
@openjdk
Copy link

openjdk bot commented Nov 23, 2020

@mcimadamore this pull request will not be integrated until the CSR request JDK-8256866 for issue JDK-8256865 has been approved.

Copy link
Member

@JornVernee JornVernee left a comment

Choose a reason for hiding this comment

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

Already looked at this in panama-foreign, but found one minor issue.

@@ -140,9 +148,11 @@ public static FunctionDescriptor ofVoid(MemoryLayout... argLayouts) {
* of this function descriptor.
* @param addedLayouts the argument layouts to append.
* @return the new function descriptor.
* @throws NullPointerException if any of the new argument layouts is null.
* @throws NullPointerException if either {@code addedLayouts == null}, or any of the
* layouts in {@code addedLayouts} is null.@throws NullPointerException if any of the new argument layouts is null.
Copy link
Member

Choose a reason for hiding this comment

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

Spurious @throws tag here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch

@dholmes-ora
Copy link
Member

Just an observation but there are precedents for just placing a generic statement in the package and/or class javadoc:

"Unless specified otherwise any method that is passed a null reference will throw NullPointerException"

rather than adding @throws NPE all over the place.

Copy link
Member

@sundararajana sundararajana left a comment

Choose a reason for hiding this comment

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

Unused imports in TestLayouts.java?

@mcimadamore
Copy link
Contributor Author

Following @dholmes-ora suggestion and also @jddarcy (in CSR review), I've uploaded a new iteration which instead of adding a @throws tag at every method, adds a general statement on each class which gets the treatment. I think specifying at package-level seems a bit too loose, so I went for per-class basis.

@openjdk openjdk bot removed the csr Pull request needs approved CSR before integration label Nov 25, 2020
@openjdk
Copy link

openjdk bot commented Nov 25, 2020

@mcimadamore 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:

8256865: Foreign Memory Access and Linker API are missing NPE checks

Reviewed-by: jvernee, sundar, chegar

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 43 new commits pushed to the master branch:

  • 8cd2e0f: 8243315: ParallelScavengeHeap::initialize() passes GenAlignment as page size to os::trace_page_sizes instead of actual page size
  • cdb41ba: 8255904: Remove superfluous use of reflection in Class::isRecord
  • c45725e: 8256747: GitHub Actions: decouple the hotspot build-only jobs from Linux x64 testing
  • 79e57ac: 8256643: Terminally deprecate ThreadGroup stop, destroy, isDestroyed, setDaemon and isDaemon
  • 0d91f0a: 8252848: Optimize small primitive arrayCopy operations through partial inlining using AVX-512 masked instructions
  • 66943fe: 8256517: (ref) Reference.clear during reference processing may lose notification
  • 3c230b8: 8256993: Clarify Package::isSealed javadoc about package sealing vs sealed class or interface
  • 1b7a61f: 8254999: Move G1RemSetSamplingTask to more appropriate location
  • 695117f: 8255479: [aarch64] assert(src->section_index_of(target) == CodeBuffer::SECT_NONE) failed: sanity
  • dbfeb90: 8243559: Remove root certificates with 1024-bit keys
  • ... and 33 more: https://git.openjdk.java.net/jdk/compare/84429cd944b771f5da5d1f1903bf2248f22fd8c7...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 25, 2020
@mcimadamore
Copy link
Contributor Author

/integrate

@openjdk openjdk bot closed this Nov 25, 2020
@openjdk openjdk bot added integrated Pull request has been integrated and removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 25, 2020
@openjdk
Copy link

openjdk bot commented Nov 25, 2020

@mcimadamore Since your change was applied there have been 43 commits pushed to the master branch:

  • 8cd2e0f: 8243315: ParallelScavengeHeap::initialize() passes GenAlignment as page size to os::trace_page_sizes instead of actual page size
  • cdb41ba: 8255904: Remove superfluous use of reflection in Class::isRecord
  • c45725e: 8256747: GitHub Actions: decouple the hotspot build-only jobs from Linux x64 testing
  • 79e57ac: 8256643: Terminally deprecate ThreadGroup stop, destroy, isDestroyed, setDaemon and isDaemon
  • 0d91f0a: 8252848: Optimize small primitive arrayCopy operations through partial inlining using AVX-512 masked instructions
  • 66943fe: 8256517: (ref) Reference.clear during reference processing may lose notification
  • 3c230b8: 8256993: Clarify Package::isSealed javadoc about package sealing vs sealed class or interface
  • 1b7a61f: 8254999: Move G1RemSetSamplingTask to more appropriate location
  • 695117f: 8255479: [aarch64] assert(src->section_index_of(target) == CodeBuffer::SECT_NONE) failed: sanity
  • dbfeb90: 8243559: Remove root certificates with 1024-bit keys
  • ... and 33 more: https://git.openjdk.java.net/jdk/compare/84429cd944b771f5da5d1f1903bf2248f22fd8c7...master

Your commit was automatically rebased without conflicts.

Pushed as commit 9aeadbb.

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

openjdk-notifier bot referenced this pull request Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
5 participants