<div dir="ltr">[Apologies if this is the wrong list. I was hoping to find something more user-focused (e.g. a valhalla-users@), but this seems to be the recommended place to ask questions. Please LMK if there's somewhere more appropriate].<div><br><div>I've been reading the JEPs and messing around with the early access build, trying to create a mental model for myself about how JVMs will typically be able to optimize value classes. It seems like a goal is effectively to be able to dump object headers:</div><div>- no identity (no boxing/unboxing visibility, no gc)</div><div>- no synchronization</div><div>- restrictions on inheritance</div><div>etc</div><div><br></div><div>but this seems like it relies on the ability of the JIT to know the concrete value of the type at runtime. E.G. if I have the method:<br><br>public void print(java.lang.Number! n) {<br>  System.out.println(n.toString());<br>}<br><br>It seems that the JVM must require some kind of object header to be able to determine the appropriate toString to dispatch to. Similarly, if I have:<br><br>class X {<br>   Number![] nums = someNums();<br>}<br><br>It seems like every Number in nums must still require an object header, because the JIT doesn't know the concrete type of said objects. Reading JEP 401 more closely, I see now that scalarization can't be supported for supertypes:<br><br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="color:rgb(0,0,0);font-family:"DejaVu Sans","Bitstream Vera Sans","Luxi Sans",Verdana,Arial,Helvetica;font-size:13.3333px">One limitation of scalarization is that it is not typically applied to a variable with a type that is a </span><em style="color:rgb(0,0,0);font-family:"DejaVu Sans","Bitstream Vera Sans","Luxi Sans",Verdana,Arial,Helvetica;font-size:13.3333px">supertype</em><span style="color:rgb(0,0,0);font-family:"DejaVu Sans","Bitstream Vera Sans","Luxi Sans",Verdana,Arial,Helvetica;font-size:13.3333px"> of a value class type. </span></blockquote><br></div><div>Is heap flattening in the same category? Are there any optimizations that end up working with supertypes, or is the general premise that you'll mostly need to be working with the concrete classes for optimizations to kick in?</div><div><br></div></div></div>