Skip to content

Conversation

@coleenp
Copy link
Contributor

@coleenp coleenp commented Sep 18, 2025

This change removes InstanceKlass::allocate_objArray and has its caller call ObjArrayKlass::allocate_instance directly from oopFactory, like the other array allocations do. See CR for more information why we should have this change. I also removed element_klass_addr() and moved element_klass_offset() to be in a more logical place near element_klass() functions. This upstreams a tiny valhalla diff.
Tested with tier1-4.


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-8367989: Remove InstanceKlass::allocate_objArray and ArrayKlass::allocate_arrayArray (Enhancement - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 27372

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 18, 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 Sep 18, 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:

8367989: Remove InstanceKlass::allocate_objArray and ArrayKlass::allocate_arrayArray

Reviewed-by: stefank, fparain

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 85 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 Sep 18, 2025

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

  • hotspot

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 hotspot [email protected] rfr Pull request is ready for review labels Sep 18, 2025
@mlbridge
Copy link

mlbridge bot commented Sep 18, 2025

Webrevs

Comment on lines 111 to 112
ArrayKlass* ak = InstanceKlass::cast(klass)->array_klass(CHECK_NULL);
return ObjArrayKlass::cast(ak)->allocate_instance(length, THREAD);
Copy link
Member

Choose a reason for hiding this comment

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

Before this change the two if/else branches had a symmetry that is lost with the proposed change. It makes you look at the code and wonder what the reason is for this asymmetry. Could the symmetry be retained by changing this to:

objArrayOop oopFactory::new_objArray(Klass* klass, int length, TRAPS) {
  ArrayKlass* ak;

  if (klass->is_array_klass()) {
    ak = ArrayKlass::cast(klass)->array_klass(CHECK_NULL);
  } else {
    ak = InstanceKlass::cast(klass)->array_klass(CHECK_NULL);
  }
  
  return ak->allocate_instance(length, THREAD);
}

Or if you dare to use a virtual call instead of the if branch:

objArrayOop oopFactory::new_objArray(Klass* klass, int length, TRAPS) {
  ArrayKlass* ak = klass->array_klass(CHECK_NULL);
  return ak->allocate_instance(length, THREAD);
}

If the virtual call is unwanted then we could add a new "faster" (unclear how much faster this actually is):

ArrayKlass* Klass::array_klass_fast(TRAPS) {
  ArrayKlass* ak;

  if (klass->is_array_klass()) {
    ak = ArrayKlass::cast(klass)->array_klass(CHECK_NULL);
  } else {
    ak = InstanceKlass::cast(klass)->array_klass(CHECK_NULL);
  }
 
  assert(ak == array_klass(), "The two functions should return the same result");
  return ak;
}
...
objArrayOop oopFactory::new_objArray(Klass* klass, int length, TRAPS) {
  ArrayKlass* ak = klass->array_klass_fast(CHECK_NULL);
  return ak->allocate_instance(length, THREAD);
}

(I've not compiled nor tested the above)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't really symmetric except number of lines. One branch calls ArrayKlass::allocate_arrayArray, the other calls allocate_instance for ObjArray. Unless I refactor allocate_arrayArray into this, it still won't be symmetrical, and it's quite a bit different in the valhalla repo.

Copy link
Contributor Author

@coleenp coleenp Sep 19, 2025

Choose a reason for hiding this comment

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

It might make sense to refactor allocate_arrayArray into this though and remove that too.
Yes, I like suggestion #1. There are too many array allocation functions.

Copy link
Member

Choose a reason for hiding this comment

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

It wasn't really symmetric except number of lines.

Given that you refuted my statement about symmetry I want to try to explain what symmetry I saw but you didn't:

The old code called allocate_xArray function in both branches. That was the symmetry. It was quite clear that the two functions accomplished similar goals, in similar ways. Yes, the functions called are named differently, but I didn't talk about absolute symmetry in characters of number of lines.

In the first proposed patch both branches call its corresponding array_klass function, but only one of the legs make it explicit, and the other has that deferred to the call to allocate_xArray function. I find that this kind of asymmetry often hurts readability and makes code harder to maintain. Hence my proposal. My 2c.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your suggested changes are really good. Thanks.

return ArrayKlass::cast(klass)->allocate_arrayArray(1, length, THREAD);
} else {
return InstanceKlass::cast(klass)->allocate_objArray(1, length, THREAD);
}
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 suppose this has symmetry in the mainline, except both of these functions do the same thing as ObjArrayKlass.allocate_instance do. The goal is to hide allocate_instance and only make this class a friend, and not InstanceKlass. This isn't the case in the current repository but it is in the valhalla repo and I want them to be the same at this level.

So this isolates the CollectedHeap::array_allocate call to less places now.

@openjdk openjdk bot changed the title 8367989: Remove InstanceKlass::allocate_objArray 8367989: Remove InstanceKlass::allocate_objArray and ArrayKlass::allocate_arrayArray Sep 19, 2025
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. Please test this thoroughly given the complexity inside the called functions.

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

coleenp commented Sep 22, 2025

Thanks Stefan. I'm running tier1-8 testing now.

@coleenp
Copy link
Contributor Author

coleenp commented Sep 24, 2025

Thanks for reviewing Stefan and Fred. Testing was clean.
/integrate

@openjdk
Copy link

openjdk bot commented Sep 24, 2025

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

openjdk bot commented Sep 24, 2025

@coleenp Pushed as commit e8adc1f.

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

@coleenp coleenp deleted the oopFactory branch September 24, 2025 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot [email protected] integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants