RFR: 8378086: [lworld] duplication between ObjArrayKlass and refined classes
Stefan Karlsson
stefank at openjdk.org
Tue Feb 17 12:20:33 UTC 2026
On Tue, 17 Feb 2026 12:13:31 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:
> I have a bunch of patches to remove some code duplication, redundant setting of fields, unneeded dispatch code.
>
> I've tested this with tier1-3.
>
> I'm opening this up as one PR, depending on #2033, but it could be split up into multiple dependent PRs. It could be good to look at each commit individually when making a first pass of over this PR.
>
> I'll add a guide to the individual commits as a comment after the summary.
Guide to the individual commits:
[Deduplicate array klass code](https://github.com/openjdk/valhalla/commit/2ee29739abcf364d8224c5722086cbbd631fa87a)
* Remove duplicated `package()` and `module()`
* Some setters are called twice. Once in the `ObjArrayKlass` constructor and once in the refined klass' constructor. I've changed the code to set the fields in the member initializer list. The setters were then removed.
* Removed the virtual dispatch around `element_klass()` and `set_element_klass()`.
* Remove dependency from `markWord` to `LayoutKind` and moved the `prototype_header` calculation (which used the removed code) to the array klasses. This gives a bit easier constructor parameters.
* Removed extra (slightly different) `compute_secondary_supers`. This should have been a separate commit.
[Fix incorrect reference to RefArrayKlass::](https://github.com/openjdk/valhalla/commit/9059ea5f3e535c5f62b81a3a393c9031762d2aab)
* Simple change of type
[Remove ObjArrayKlass::copy_array](https://github.com/openjdk/valhalla/commit/36f581f0dc9040501ed87075a0236fd4920b1f19)
* copy_array is always called from a klass fetched via the object header, which always points to the refined array klass. Removed the ObjArrayKlass (unrefined and abstract klass) implementation. Fixed asserts and code to check for the refined version. Removed some unused fields.
[Remove ObjArrayKlass::oop_size](https://github.com/openjdk/valhalla/commit/da062cf3861f4120d6667adadd62f2c6bdcd0369)
* oop_size is always called from a klass fetched via the object header.
[Remove ObjArrayKlass::oop_verify_on implementation](https://github.com/openjdk/valhalla/commit/ce5d63cfebaf6da0dde78fc5d36e212665de0e77)
* oop_size is always called from a klass fetched via the object header.
[Remove create_element_klass_array_name duplication](https://github.com/openjdk/valhalla/commit/6371b238d86e50d60b73c2c14457033b023e364a)
* I think this is could be an old mis-merge. Removed one version and adjusted the code to look like the upstream code. (I'm realizing now that the parameter order is different in valhalla)
[Restore ObjArrayKlass private](https://github.com/openjdk/valhalla/commit/af00a1e80bc599e59b31dae46cbbe729ef184295)
* After restructuring the array constructors we can now reshuffle the code so that it diffs better with the mainline.
[Add temporary assert](https://github.com/openjdk/valhalla/commit/afa01e3508a45ce0a58feb4b2800cfd98effe394)
This is a patch that I temporarily put in place to show that there are some inconsistencies how class loaders are installed in these two calls:
ak = RefArrayKlass::allocate_refArray_klass(class_loader_data(), dimension(),
...
ak = FlatArrayKlass::allocate_klass(element_klass(), ad._properties, ad._layout_kind, CHECK_NULL);
-------------
PR Comment: https://git.openjdk.org/valhalla/pull/2117#issuecomment-3914380843
More information about the valhalla-dev
mailing list