Skip to content

8353840: JNativeScan should not abort for missing classes #24499

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

Closed
wants to merge 3 commits into from

Conversation

danishnawab
Copy link
Contributor

@danishnawab danishnawab commented Apr 8, 2025

Description

https://bugs.openjdk.org/browse/JDK-8353840

Existing behavior

Log the error message and terminate in case of missing system class

$ jnativescan --class-path reactor-core-3.7.4.jar; echo "Exit code: $?"

ERROR: Error while processing method: reactor.core.publisher.CallSiteSupplierFactory$SharedSecretsCallSiteSupplierFactory$TracingException::get()String
CAUSED BY: System class can not be found: sun.misc.JavaLangAccess
Exit code: 1

New behavior

Still log the error message about the missing system class, but continue the analysis

$ build/macosx-aarch64-server-release/jdk/bin/jnativescan --class-path reactor-core-3.7.4.jar; echo "Exit code: $?" 

  <no restricted methods>
Error while processing method: reactor.core.publisher.CallSiteSupplierFactory$SharedSecretsCallSiteSupplierFactory$TracingException::get()String: System class can not be found: sun.misc.JavaLangAccess
Error while processing method: reactor.core.publisher.CallSiteSupplierFactory$SharedSecretsCallSiteSupplierFactory$TracingException::<clinit>()void: System class can not be found: sun.misc.SharedSecrets
Error while processing method: reactor.core.publisher.CallSiteSupplierFactory$SharedSecretsCallSiteSupplierFactory::<clinit>()void: System class can not be found: sun.misc.SharedSecrets
Exit code: 0

Design choices

Propagate err all the way to NativeMethodFinder which can log the error to it, but continue with the analysis

Alternatives considered

  • Instead of propagating err downstream, adapt the outer try-catch in com.sun.tools.jnativescan.Main#run.
    • Con: This would require complicated error recovery synchronization between Main and JNativeScanTask to resume the scanning after the exception
  • Instead of adapting the catch block in com.sun.tools.jnativescan.NativeMethodFinder#findAll, don't even surface the exception from com.sun.tools.jnativescan.ClassResolver.SystemModuleClassResolver#lookup rather log it right in ClassResolver
    • Con: We don't have access to MethodRef/MethodModel in ClassResolver#lookup which will make the error message less detailed/useful

stdout vs stderr

One could argue that since this is a non-terminal error, perhaps it should be logged to stdout. However, my thinking was that while it may be non-terminal, it is still an "error", and thus should be logged to stderr. I am happy to revisit this decision, if needed.

Testing

The existing test TestMissingSystemClass#testSingleJarClassPath has been adapted to test for successful execution, as well as verify the stdout output.
I considered briefly to update the test setup in a way that we see some restricted methods on the stdout instead of just <no restricted methods>, but it was unclear if that would really add any additional value since the main purpose of this test is just to ascertain the missing system class (with successful execution from now onward).


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8353840: JNativeScan should not abort for missing classes (Enhancement - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/24499/head:pull/24499
$ git checkout pull/24499

Update a local copy of the PR:
$ git checkout pull/24499
$ git pull https://git.openjdk.org/jdk.git pull/24499/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24499

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/24499.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 8, 2025

👋 Welcome back danishnawab! 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
Copy link

openjdk bot commented Apr 8, 2025

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

8353840: JNativeScan should not abort for missing classes

Reviewed-by: jvernee, liach

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

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.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@JornVernee, @liach) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 8, 2025
@openjdk
Copy link

openjdk bot commented Apr 8, 2025

@danishnawab The following labels will be automatically applied to this pull request:

  • compiler
  • core-libs

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

@danishnawab danishnawab changed the title 8353840: jnativescan should not throw error for missing system classes 8353840: Jnativescan should not throw error for missing system classes Apr 8, 2025
@openjdk openjdk bot changed the title 8353840: Jnativescan should not throw error for missing system classes 8353840: jnativescan should not throw error for missing system classes Apr 8, 2025
@mlbridge
Copy link

mlbridge bot commented Apr 8, 2025

Webrevs

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.

I've updated the issue title to start with a capital letter.

@openjdk openjdk bot changed the title 8353840: jnativescan should not throw error for missing system classes 8353840: JNativeScan should not throw error for missing system classes Apr 8, 2025
@JornVernee
Copy link
Member

Also, note that there was some other cleanup I wanted to do in this area first: #24493 which will likely result in merge conflicts.

@danishnawab danishnawab requested a review from JornVernee April 8, 2025 13:42
.stderrShouldContain("java.lang.Compiler")
.stderrAsLines();

assertEquals(2, stderr.size(), "Unexpected number of lines in stderr");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To ensure that the two calls to java.lang.Compiler.enable have been de-duped into one.

@@ -192,4 +201,8 @@ public static String qualName(ClassDesc desc) {
String packagePrefix = desc.packageName().isEmpty() ? "" : desc.packageName() + ".";
return packagePrefix + desc.displayName();
}

interface Diagnostics {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added as an inner type since there was already precedence for that with com.sun.tools.jnativescan.JNativeScanTask.Action

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.

Changes look good, thanks!

Please note that we will have to wait 24 hours before integrating, in order to give other reviews time to look as well.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 8, 2025
@danishnawab
Copy link
Contributor Author

Changes look good, thanks!

Please note that we will have to wait 24 hours before integrating, in order to give other reviews time to look as well.

Great, thanks for your review!
I will wait until tomorrow to issue the /integrate (as instructed by openjdk[bot]). Since I am not an OpenJDK committer, I will request you to please sponsor it.

@danishnawab
Copy link
Contributor Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label Apr 9, 2025
@openjdk
Copy link

openjdk bot commented Apr 9, 2025

@danishnawab
Your change (at version 1de3fec) is now ready to be sponsored by a Committer.

@liach
Copy link
Member

liach commented Apr 9, 2025

Hello @danishnawab, I have updated the issue title to "JNativeScan should not abort for missing classes" to be more accurate for the changes done. Can you update the PR title here too?

@openjdk openjdk bot removed sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated labels Apr 9, 2025
@danishnawab danishnawab changed the title 8353840: JNativeScan should not throw error for missing system classes 8353840: JNativeScan should not abort for missing classes Apr 9, 2025
@danishnawab
Copy link
Contributor Author

Hello @danishnawab, I have updated the issue title to "JNativeScan should not abort for missing classes" to be more accurate for the changes done. Can you update the PR title here too?

@liach it's done.

@openjdk openjdk bot added sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated labels Apr 9, 2025
@liach
Copy link
Member

liach commented Apr 9, 2025

Thanks!

/sponsor

@openjdk
Copy link

openjdk bot commented Apr 9, 2025

Going to push as commit 5f2a604.
Since your change was applied there have been 50 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 9, 2025
@openjdk openjdk bot closed this Apr 9, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review sponsor Pull request is ready to be sponsored labels Apr 9, 2025
@openjdk
Copy link

openjdk bot commented Apr 9, 2025

@liach @danishnawab Pushed as commit 5f2a604.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants