RFR: 8303485: Replacing os.name for operating system customization

Roger Riggs rriggs at openjdk.org
Thu Mar 9 16:17:29 UTC 2023


On Wed, 8 Mar 2023 23:11:34 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> Improvements to support OS specific customization for JDK internal use:
>>  - To select values and code; allowing elimination of unused code and values
>>  - Optionally evaluated by build processes, compilation, or archiving (i.e. CDS)
>>  - Simple API to replace adhoc comparisons with `os.name`
>>  - Clear and consistent use across build, runtime, and JDK modules
>>  
>> The PR includes updates within java.base to use the new API.
>
> src/java.base/share/classes/jdk/internal/misc/OperatingSystem.java line 98:
> 
>> 96:     @ForceInline
>> 97:     public static boolean isLinux() {
>> 98:         return OperatingSystemProps.TARGET_OS_IS_LINUX;
> 
> Suggestion:
> 
>         return OperatingSystemProps.CURRENT_OS_ORDINAL == Linux.ordinal();
> 
> 
> This will also simplify the template file as `TARGET_OS_IS_XXX` constants are not needed.
> 
> Also suggest to rename `TARGET_OS_ORDINAL` to `CURRENT_OS_ORDINAL` since it represents the current OS (vs the build target).

That would not yield a compile time constant.
The TARGET_IS_XXX values must evaluate to compile time constants as evaluated by javac.

> src/java.base/share/classes/jdk/internal/misc/OperatingSystemProps.java.template line 29:
> 
>> 27:  * @see OperatingSystem
>> 28:  */
>> 29: class OperatingSystemProps {
> 
> Have you considered to include OS architecture here for future use?  So this file be  `PlatformProps.java.template` instead.
> 
> `jdk.tools.jlink.internal.Platform` needs to get the runtime OS and architecture.

I plan to come back to os.arch, it has a similar but not identical requirements.

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

PR: https://git.openjdk.org/jdk/pull/12931



More information about the build-dev mailing list