-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8367989: Remove InstanceKlass::allocate_objArray #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
base: master
Are you sure you want to change the base?
Conversation
👋 Welcome back coleenp! A progress list of the required criteria for merging this PR into |
❗ This change is not yet ready to be integrated. |
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.
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
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