Skip to content

8358326: Use oopFactory array allocation #25590

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 2 commits into from

Conversation

coleenp
Copy link
Contributor

@coleenp coleenp commented Jun 2, 2025

This patch removes cases of direct calls to {type,obj}ArrayKlass->allocate() and calls oopFactory::new_*array instead. It also renames {type,obj}ArrayKlass->allocate functions to allocate_klass and allocate_instance so it's more clear which allocation it's doing and to match InstanceKlass allocate functions, and makes these functions private with friends for Deoptimization and oopFactory. For JEP 401, arrays are being extended to support new formats and attributes and this reduces the call sites.
Tested with tier1-7.


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-8358326: Use oopFactory array allocation (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25590

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 2, 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 Jun 2, 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:

8358326: Use oopFactory array allocation

Reviewed-by: fparain, stefank

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 13 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.

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

@openjdk
Copy link

openjdk bot commented Jun 2, 2025

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

  • 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.

@coleenp coleenp changed the title 8358326: Use oopFactory array allocation for jni 8358326: Use oopFactory array allocation Jun 3, 2025
@coleenp coleenp marked this pull request as ready for review June 6, 2025 12:02
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 6, 2025
@mlbridge
Copy link

mlbridge bot commented Jun 6, 2025

Webrevs

Copy link
Member

@stefank stefank left a comment

Choose a reason for hiding this comment

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

This looks good to me. I a few suggestions that you could take if you want to.

Comment on lines +350 to +352
if (type == T_VOID) {
THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
}
Copy link
Member

@stefank stefank Jun 9, 2025

Choose a reason for hiding this comment

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

I was first wondering where this came from but I now see that this was duplicated from basic_type_mirror_to_arrayklass. I wonder if this could could be deduplicated by moving this check into basic_type_mirror_to_basic_type and then removed from -basic_type_mirror_to_arrayklass:

static BasicType basic_type_mirror_to_basic_type(oop basic_type_mirror, TRAPS) {
  assert(java_lang_Class::is_primitive(basic_type_mirror),
    "just checking");
  
  if (type == T_VOID) {
    THROW_NULL(vmSymbols::java_lang_IllegalArgumentException());
  }

  return java_lang_Class::primitive_type(basic_type_mirror);
}

static Klass* basic_type_mirror_to_arrayklass(oop basic_type_mirror, TRAPS) {
  BasicType type = basic_type_mirror_to_basic_type(basic_type_mirror, CHECK_NULL);
  return Universe::typeArrayKlass(type);
}

And then this code could be a two-liner again:

if (java_lang_Class::is_primitive(element_mirror)) {
    BasicType type = basic_type_mirror_to_basic_type(element_mirror, CHECK_NULL);
  return oopFactory::new_typeArray(type, length, CHECK_NULL);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately the caller to basic_type_mirror_to_basic_type() can legitimately return T_VOID for the caller in reflect_method, so that's why I had to duplicate the exception code. Maybe a future enhancement would be to move these to javaClasses.hpp in java_lang_Class, where it knows all about is_primitive types, and boxing classes, which I guess boxing T_VOID is a thing.

Comment on lines 38 to 39
friend class oopFactory;
friend class Deoptimization;
Copy link
Member

Choose a reason for hiding this comment

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

If you want you could consider sorting the friend declarations (here and in the other place where you added it)

Copy link
Contributor Author

@coleenp coleenp Jun 9, 2025

Choose a reason for hiding this comment

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

Do we sort friends? The sorting looks funny since VMStructs is usually at the beginning.

 class ObjArrayKlass : public ArrayKlass {
-  friend class VMStructs;
+  friend class Deoptimization;
   friend class JVMCIVMStructs;
   friend class oopFactory;
-  friend class Deoptimization;
+  friend class VMStructs;

@@ -78,7 +82,6 @@ class ObjArrayKlass : public ArrayKlass {
static ObjArrayKlass* allocate_objArray_klass(ClassLoaderData* loader_data,
int n, Klass* element_klass, TRAPS);

objArrayOop allocate(int length, TRAPS);
Copy link
Member

Choose a reason for hiding this comment

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

Do you think multi_allocate will need a better name in the future?

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 thought if changing multi_allocate_instance so that it's clear that it's an instance, but decided to limit this. Maybe this would be helpful but the allocate() function was the most confusing to me, that's why I picked that one.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 9, 2025
@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Jun 9, 2025
Copy link
Contributor

@fparain fparain left a comment

Choose a reason for hiding this comment

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

LGTM.
Thank you for this cleanup.

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

coleenp commented Jun 9, 2025

Thanks for reviewing Stefan and Frederic.
/integrate

@openjdk
Copy link

openjdk bot commented Jun 9, 2025

Going to push as commit eb256de.
Since your change was applied there have been 15 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 Jun 9, 2025
@openjdk openjdk bot closed this Jun 9, 2025
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jun 9, 2025
@openjdk
Copy link

openjdk bot commented Jun 9, 2025

@coleenp Pushed as commit eb256de.

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

@coleenp coleenp deleted the jni-array branch June 12, 2025 12:32
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