On Mon, 16 Mar 2026 15:52:20 GMT, David Beaumont <[email protected]> wrote:
>> "Preview mode is not only controlled by --enable-preview because Javac needs >> to have different values from its runtime during compilation". That is >> correct. It's normal for preview features *disabled* in the execution >> environment when compiling with `--enable-preview`. I think I need a good >> summary on why this impacts class loading with the boot class loader as >> class loader as I would expect javac to use jrtfs to locate the class bytes, >> not the boot class loader. > > 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. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29414#discussion_r2941409414
