Skip to content

Conversation

@coleenp
Copy link
Contributor

@coleenp coleenp commented Feb 11, 2025

Class.isInterface() can check modifier flags, Class.isArray() can check whether component mirror is non-null and Class.isPrimitive() needs a new final transient boolean in java.lang.Class that the JVM code initializes.
Tested with tier1-4 and performance tests.


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-8349860: Make Class.isArray(), Class.isInterface() and Class.isPrimitive() non-native (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 23572

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 11, 2025

👋 Welcome back coleenp! 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 Feb 11, 2025

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

8349860: Make Class.isArray(), Class.isInterface() and Class.isPrimitive() non-native

Reviewed-by: dlong, rriggs, vlivanov, yzheng, 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 124 new commits pushed to the master branch:

  • 39cb493: 8348106: Catch C++ exception in Java_sun_awt_windows_WTaskbarPeer_setOverlayIcon
  • ddb2569: 8280682: Refactor AOT code source validation checks
  • 65f79c1: 8347335: ZGC: Use limitless mark stack memory
  • e410af0: 8342393: Promote commutative vector IR node sharing
  • f755fad: 8349653: Clarify the docs for MemorySegment::reinterpret
  • a5c9a4d: 8349032: C2: Parse Predicate refactoring in Loop Unswitching broke fix for JDK-8290850
  • 302bed0: 8350499: Minimal build fails with slowdebug builds
  • 0795d11: 8350464: The flags to set the native priority for the VMThread and Java threads need a broader range
  • 05b4812: 8350041: Skip test/jdk/java/lang/String/nativeEncoding/StringPlatformChars.java on static JDK
  • a891630: 8350480: RISC-V: Relax assertion about registers in C2_MacroAssembler::minmax_fp
  • ... and 114 more: https://git.openjdk.org/jdk/compare/ed17c55ea34b3b6009dab11d64f21e0b7af3d701...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 changed the title 8349860 Make Class.isArray(), Class.isInterface() and Class.isPrimitive() non-native 8349860: Make Class.isArray(), Class.isInterface() and Class.isPrimitive() non-native Feb 11, 2025
@openjdk
Copy link

openjdk bot commented Feb 11, 2025

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

  • core-libs
  • graal
  • hotspot

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.

@openjdk openjdk bot added graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Feb 11, 2025
@liach
Copy link
Member

liach commented Feb 12, 2025

We often need to determine what primitive type a class is. Currently we do it through Wrapper.forPrimitiveType. Do you see potential value in encoding the primitive status in a byte, so primitive info also knows what primitive type this class is instead of doing identity comparisons?

@coleenp
Copy link
Contributor Author

coleenp commented Feb 14, 2025

I had a look at Wrapper.forPrimitiveType() and it's not an intrinsic so I don't really know how hot it is. It's a comparison, vs getting a field out of Class<?>. Not sure how to measure it. So I can't address it in this change.

@liach
Copy link
Member

liach commented Feb 14, 2025

@cl4es Can you offer some insight here?

@cl4es
Copy link
Member

cl4es commented Feb 17, 2025

Touching Wrapper seems out of scope for this PR, but if Class.isPrimitive gets cheaper from this then Wrapper.forPrimitiveType should definitely be examined in a follow-up.

@coleenp coleenp marked this pull request as ready for review February 18, 2025 23:43
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 18, 2025
@mlbridge
Copy link

mlbridge bot commented Feb 18, 2025

// Otherwise it returns its argument value which is the _the_class Klass*.
// Please, refer to the description in the jvmtiThreadSate.hpp.
// Please, refer to the description in the jvmtiThreadState.hpp.

Copy link
Member

Choose a reason for hiding this comment

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

Does this "RedefineClasses support" comment still belong 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.

I think so. The comment in jvmtiThreadState.hpp has details why this is. We do a mirror switch before verification apparently because of bug 6214132 it says.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Just a few passing comments as this is mainly compiler stuff.

Does the SA not need any updates in relation to this?

Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

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

Is the change to isInterface and isPrimitive performance neutral?
As @IntrinsicCandidates, there would be some performance gain.

// Please, refer to the description in the jvmtiThreadSate.hpp.
// Please, refer to the description in the jvmtiThreadState.hpp.

JVM_ENTRY(jboolean, JVM_IsInterface(JNIEnv *env, jclass cls))
Copy link
Contributor

Choose a reason for hiding this comment

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

JVM_IsInteface is deleted in Class.c, what purpose is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The old classfile verifier uses JVM_IsInterface.

@liach
Copy link
Member

liach commented Feb 19, 2025

Re roger's IntrinsicCandidate remark: One behavior that might be affected would be C2's inlining preferences. Some inline-sensitive workloads like FFM API might be affected if some Class attribute access cannot be inlined because the incoming Class object is not constant. See #23460 and #23628.

Copy link
Contributor Author

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

Thanks for looking at this change.

// Otherwise it returns its argument value which is the _the_class Klass*.
// Please, refer to the description in the jvmtiThreadSate.hpp.
// Please, refer to the description in the jvmtiThreadState.hpp.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so. The comment in jvmtiThreadState.hpp has details why this is. We do a mirror switch before verification apparently because of bug 6214132 it says.

Co-authored-by: David Holmes <62092539+dholmes-ora@users.noreply.github.com>
@openjdk openjdk bot removed the rfr Pull request is ready for review label Feb 20, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 20, 2025
Copy link
Contributor

@iwanowww iwanowww left a comment

Choose a reason for hiding this comment

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

Looks good!

Regarding @IntrinsicCandidate and its effects on JIT-compiler inlining decisions, @ForceInline could be added, but IMO it's not necessary since new implementations are small.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 20, 2025
@coleenp
Copy link
Contributor Author

coleenp commented Feb 20, 2025

Thanks Vladimir for review and for answering my earlier questions on this change.

Copy link
Contributor

@mur47x111 mur47x111 left a comment

Choose a reason for hiding this comment

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

LGTM! As @iwanowww said, not inlining such trivial methods seems more like an inliner bug/enhancement opportunity.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Feb 21, 2025
@coleenp
Copy link
Contributor Author

coleenp commented Feb 24, 2025

Does the SA not need any updates in relation to this?

No, the SA doesn't know about these compiler intrinsics.

Copy link
Member

@liach liach left a comment

Choose a reason for hiding this comment

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

The limited changes to the Java codebase looks reasonable. We should probably get a double check from Alan or some other architect.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 24, 2025
Copy link
Contributor

@RogerRiggs RogerRiggs left a comment

Choose a reason for hiding this comment

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

A nice simplification.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Feb 24, 2025
@coleenp
Copy link
Contributor Author

coleenp commented Feb 24, 2025

Thanks for reviewing Roger.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Feb 24, 2025
@coleenp
Copy link
Contributor Author

coleenp commented Feb 25, 2025

Thanks for reviewing Dean, Roger, Vladimir, Yudi and Chen, and comments David.
/integrate

@openjdk
Copy link

openjdk bot commented Feb 25, 2025

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

  • a9c9f7f: 8192647: GClocker induced GCs can starve threads requiring memory leading to OOME
  • aa70f0a: 8347348: Clarify that the HTTP server in jdk.httpserver module is not a full featured server
  • d551dac: 8350103: Test containers/systemd/SystemdMemoryAwarenessTest.java fails on Linux ppc64le SLES15 SP6
  • ab86a13: 8350548: java.lang.classfile package javadoc has errors
  • e1081cf: 8348536: Remove remain SIZE_FORMAT usage after JDK-8347990
  • a6cc37f: 8349888: AOTMode=create crashes with EpsilonGC
  • 990d40e: 8350476: Fix typo introduced in JDK-8350147
  • 39cb493: 8348106: Catch C++ exception in Java_sun_awt_windows_WTaskbarPeer_setOverlayIcon
  • ddb2569: 8280682: Refactor AOT code source validation checks
  • 65f79c1: 8347335: ZGC: Use limitless mark stack memory
  • ... and 121 more: https://git.openjdk.org/jdk/compare/ed17c55ea34b3b6009dab11d64f21e0b7af3d701...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Feb 25, 2025

@coleenp Pushed as commit c413549.

💡 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

Labels

core-libs core-libs-dev@openjdk.org graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

9 participants