On Mon, 27 Apr 2026 14:45:53 GMT, Frederic Parain <[email protected]> wrote:

> This patch adds a simple policy to put a limit on field flattening to prevent 
> instances from becoming too large. It is easy to generate very huge instances 
> with nested flat values, so huge that the JVM struggles to allocate its 
> internal data structure to handle such classes. The new policy allocates a 
> flattening budget to each class, and field flattening in this class stops 
> when the budget is exhausted. The limit can be tuned with a VM parameter.
> 
> Tested on Mach5 tier1-4
> 
> ---------
> - [X] I confirm that I make this contribution in accordance with the [OpenJDK 
> Interim AI Policy](https://openjdk.org/legal/ai).

The concept looks good. I am wondering about a few interactions and corner 
cases.

src/hotspot/share/runtime/globals.hpp line 837:

> 835:   product(intx, FlatteningBudget, 1024,                                  
>    \
> 836:           "Maximum size dedicated to flat fields in an instance")        
>    \
> 837:           range(0, 1024 * 1024)                                          
>    \

Should this be part of the `DISABLE_FLAG_AND_WARN_IF_NOT_DEFAULT` type 
mechanism ?

Also I have not digged to deep into AOT / CDS. But it seems like this property 
should be stable from dump and load. `CDS_MUST_MATCH_FLAGS_DO`. However this 
might limit things to much. But I am guess if this flag affected layout 
decisions between dump and run, things would not work.

test/hotspot/jtreg/runtime/valhalla/inlinetypes/TestFlatteningBudget.java line 
31:

> 29:  * @library /test/lib
> 30:  * @enablePreview
> 31:  * @run main runtime.valhalla.inlinetypes.TestFlatteningBudget

Should this be a driver tests as it creates new instances for the each test?

Not sure if this test should be flagless as it assumes it does not get in 
external flags that disable flattening. Alternatively have main method do a 
quick test for flattening, then throw a skipped exception if fields are not 
flattened as expected.

Maybe there is already some shared test utility for doing this sort of thing.

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

PR Review: 
https://git.openjdk.org/valhalla/pull/2372#pullrequestreview-4182753463
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2372#discussion_r3148936511
PR Review Comment: 
https://git.openjdk.org/valhalla/pull/2372#discussion_r3148924035

Reply via email to