RFR: 8304915: Create jdk.internal.util.Architecture enum and apply [v4]

Roger Riggs rriggs at openjdk.org
Thu Apr 6 16:29:09 UTC 2023


On Thu, 6 Apr 2023 15:27:49 GMT, David M. Lloyd <duke at openjdk.org> wrote:

>> src/java.base/share/classes/jdk/internal/util/Architecture.java line 47:
>> 
>>> 45: 
>>> 46:     // Cache a copy of the array for lightweight indexing
>>> 47:     private static final Architecture[] archValues = Architecture.values();
>> 
>> This needs to be annotated with `@jdk.internal.vm.annotation.Stable` for `Architecture.current()` to be constant foldable:
>> Suggestion:
>> 
>>     private static final @Stable Architecture[] archValues = Architecture.values();
>
> Even if it's `static` *and* `final`? I thought `@Stable` exists to "...process non-null stable fields (final or otherwise) in a similar manner to static final fields with respect to promoting the field's value to a constant", implying that `static final` fields already have this property.

The use here is not particularly performance sensitive. So it doesn't provide much value.
In this case, it allows each array element to be considered stable.

>From the @Stable javadoc:

 * Fields which are declared {@code final} may also be annotated as stable.
 * Since final fields already behave as stable values, such an annotation
 * conveys no additional information regarding change of the field's value, but
 * still conveys information regarding change of additional components values if
 * the type of the field is an array type (as described above).

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13357#discussion_r1160018375


More information about the serviceability-dev mailing list