RFR: 8312262: Klass::array_klass() should return ArrayKlass pointer

Calvin Cheung ccheung at openjdk.org
Thu Jul 27 21:56:53 UTC 2023


On Thu, 27 Jul 2023 19:22:52 GMT, Coleen Phillimore <coleenp at openjdk.org> wrote:

> This is a simple change to make array_klass() return ArrayKlass (the first dimension of TypeArrayKlass is a TypeArrayKlass so can't use ObjArrayKlass), higher_dimension is always an ObjArrayKlass and lower_dimension can be a TypeArrayKlass.  The change removes some casts.
> Tested with tier1 linux/macosx/windows on x86 and aarch64.

Looks good. Just couple of nits.

I think there are some changes could be made under the `sun.jvm.hotspot.oops` package to reduce the amount of type casting.
For example:
`./sun/jvm/hotspot/oops/ArrayKlass.java:  public Klass getHigherDimension() { return (Klass) higherDimension.getValue(this); }`
The above method could return a ObjArrayKlass so the following typecasts are not needed:

./sun/jvm/hotspot/oops/ObjArrayKlass.java:    ObjArrayKlass ak = (ObjArrayKlass) getHigherDimension();
./sun/jvm/hotspot/oops/TypeArrayKlass.java:    ObjArrayKlass ak = (ObjArrayKlass) getHigherDimension();

src/hotspot/share/oops/arrayKlass.cpp line 130:

> 128:   check_array_allocation_length(length, arrayOopDesc::max_array_length(T_ARRAY), CHECK_NULL);
> 129:   size_t size = objArrayOopDesc::object_size(length);
> 130:   ArrayKlass* ak = array_klass(n+dimension(), CHECK_NULL);

Please add a blank space before and after the '+'.

src/hotspot/share/oops/objArrayKlass.cpp line 179:

> 177:     if (length != 0) {
> 178:       for (int index = 0; index < length; index++) {
> 179:         oop sub_array = ld_klass->multi_allocate(rank-1, &sizes[1], CHECK_NULL);

Please add a blank space before and after the '-'.

-------------

PR Review: https://git.openjdk.org/jdk/pull/15059#pullrequestreview-1550859087
PR Review Comment: https://git.openjdk.org/jdk/pull/15059#discussion_r1276849391
PR Review Comment: https://git.openjdk.org/jdk/pull/15059#discussion_r1276850058


More information about the hotspot-dev mailing list