This is a design document for JDK-8236988 - Modular Design for JVM Flags
- Lots of files have changed. Please read this document first before heading over to the webrev
- Preliminary webrev: http://cr.openjdk.java.net/~iklam/jdk15/vm_flags_overhaul.008/
Improve the implementation of JVM command-line flags (such as -XX:+UseCompressedOops)
Break up monolithic globals.hpp
- Future: subdivide globals.hpp into individual components:
- (Not in this patch, but possible)
- #include "memory/metaspaceShared_globals.hpp" (just flags related to CDS).
- Remove complex macros for flags manipulation
- Hotspot command line switches should have multiple type attributes
- See JDK-7123237
E.g., one can have a "manageable" switch and an "experimental" switch, but not a "manageable_experimental" switch.
- See JDK-7123237
- Templatize duplicated flag processing code:
- E.g., .jvmFlags.cpp
- Speed up range/constraint checking for flags
- Avoid linear search for every -XX:NumericFlag=value argument in the command-line (jvmFlagRangeList.cpp)
(Design contribution by Erik Österlund, Stefan Karlsson, Coleen Phillimore)
- Most of the current patch is generated by a script, so it's easy to change the design
- Summary of changes: 14333 lines changed: 6443 ins; 5024 del; 2866 mod; 34730 unchg
- Flags are specified via macros like
- Flags are specified using a pair of files xxx_globals.hpp, xxx_globals.cpp
- The HPP file is the "declaration" of the flags. It has a description of all the features for each flag.
HotSpot developers should consult the HPP for information about the flags (same as before).
- Example: c2_globals.hpp:
Macros in the HPP files are expanded to
The main goal of the inline functions is to avoid duplicating the information between the HPP and CPP files, so the CPP files contains just boilerplate code.
Macros in the CPP files are expanded to
The consistency between the .hpp/.cpp files are mostly statically enforced at compile time. E.g.,
- It's impossible to set a different default or range than as specified in the HPP file.
- It's impossible to define StressLCM as a different type than declared in the HPP file.
However, it's possible to forget to put
DEFN_PRODUCT_RANGE(MaxLoopPad) in c2_globals.cpp. I can't think of a way to statically check for that, so I added a runtime check (debug builds only). See JVMFlag::validate_flags().
Meta-information of the flags
As seen above, meta-information about each flag
XYZ is stored in the structure
FLAG_XYZ. This structure can be used directly to access the flag. E.g.,
As a result, we no longer need to do a linear search for range/constraint checking.
Iterating over all flags:
The FLAG_XXXs are constructed using C++ global constructors, and are appended to a global list. This list can be used for iterating over all the flags (e.g., for implementing
- Declare flags in template files with custom syntax
flag type = bool, name = UseCompressedOops, default = false, help = "Use 32-bit object references in 64-bit VM.", type = product | lp64;
Or XML, or ....
Auto-generation of header files from templates
- Can generate more compact code that current proposal (see below)
- Flags can be pre-sorted, hashed, etc