-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8367989: Remove InstanceKlass::allocate_objArray and ArrayKlass::allocate_arrayArray #27372
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
Conversation
|
👋 Welcome back coleenp! A progress list of the required criteria for merging this PR into |
|
@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: 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
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 |
Webrevs
|
| ArrayKlass* ak = InstanceKlass::cast(klass)->array_klass(CHECK_NULL); | ||
| return ObjArrayKlass::cast(ak)->allocate_instance(length, THREAD); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); | ||
| } |
There was a problem hiding this comment.
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.
stefank
left a comment
There was a problem hiding this 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.
|
Thanks Stefan. I'm running tier1-8 testing now. |
|
Thanks for reviewing Stefan and Fred. Testing was clean. |
|
Going to push as commit e8adc1f.
Your commit was automatically rebased without conflicts. |
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
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/27372/head:pull/27372$ git checkout pull/27372Update a local copy of the PR:
$ git checkout pull/27372$ git pull https://git.openjdk.org/jdk.git pull/27372/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 27372View PR using the GUI difftool:
$ git pr show -t 27372Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/27372.diff
Using Webrev
Link to Webrev Comment