On Mon, 16 Mar 2026 13:20:24 GMT, Alan Bateman <[email protected]> wrote:
>> Preview mode is not only controlled by --enable-preview because Javac needs >> to have different values from its runtime during compilation. >> >> PREVIEW_MODE_UNINITIALIZED is more of an internal guard to prevent a future >> change from reading the jimage file "too early" and getting the non-preview >> version of something by accident. >> >> Some options are read from the jimage itself, and are read without reference >> to "preview mode", and they must be processed before anyone starts reading >> anything else. The "raw" read of the options from the jimage file is the >> only read allowed while PREVIEW_MODE_UNINITIALIZED is set, and any "normal" >> reads must be done after initialisation is complete. >> >> See `lookup_vm_options()` for where the "raw" read is performed *before* >> preview mode can be set. >> >> `Arguments::parse()` calls `lookup_vm_options()` and we can't access the >> preview mode flag until that's complete (even if in theory >> `lookup_vm_options()` wouldn't be able to affect the preview mode flag >> itself). > > "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? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/29414#discussion_r2941292599
