On Mon, 16 Mar 2026 16:10:00 GMT, Alan Bateman <[email protected]> wrote:

>> It's possible I'm mistaken in that regard, but we still need to read from 
>> jimage before we've parsed the arguments and can know if `--enable-preview` 
>> was set (or at least I think that's the case).
>> 
>> `set_enable_preview()` is called in `parse_each_vm_init_arg()` <-- 
>> `parse_vm_init_args()` <-- `parse()` and reflects only the command line 
>> flag, as far as I can tell.
>> 
>> `ClassLoader::set_preview_mode()` is set in `finalize_vm_init_args()` <-- 
>> `parse_vm_init_args()`, but after `parse_each_vm_init_arg()`.
>> 
>> `ClassLoader::lookup_vm_options()` is called in `Arguments::parse()`, 
>> *before* the call to `parse_vm_init_args()`.
>> 
>> So, before any command line has been parsed, we must be able to read from 
>> the jimage file.
>> This is when the class-loader is in the uninitialized state, and only the 
>> options lookup code can succeed at that point (other calls for 
>> `jimage_read()` correctly fail because of the check).
>> 
>> After parsing the flag, we set the preview mode for the class-loader and 
>> "normal" reading can begin.
>> 
>> Does this make sense, or do you have a specific suggestion as to how to 
>> change it?
>
> javac + execution environment vs. compilation environment should have no 
> impact on the boot class loader.
> 
> Instead I think it's just that the jimage file is being opened/accessing 
> before arguments are fully parsed. The jimage file may contain an "options" 
> resource that contributes to the set of arguments so that is one case where 
> the argument to enable preview features may be in the options file. I need to 
> study it more to see if there are other cases.

There definitely are no other cases in terms of when jimage is accessed, 
because if there were, my code would fail (because of the "uninitialized" state 
check). Assuming nothing can ever reset the enable-preview flag in `Arguments` 
(which I'm sure is the case) there cannot any reads which could accidentally 
use the wrong value. And all the direct reads of the jimage are encapsulated.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/29414#discussion_r2946138316

Reply via email to