<div dir="ltr">Hello Alayachew,<div>Before we answer this question, let's first look at arrays, both in Java and in other more native languages like C.</div><div>We all know all Java arrays are stored in heap and variably-sized, while in native languages like C, there are stack-based arrays, but they have a constant length at compile time and can be non-null.</div><div>To make an array field itself to be non-null, it most likely will be handled as part of the more general-purpose non-null object pointer restriction; since in the inlined/flattened layout, the array field is going to be a pointer to the heap, like other non-value objects.</div><div><br></div><div>Compared to regular objects, there are 2 ways to achieve a non-null array:</div><div>1. You can probably generate a value record with a fixed number of fields to serve as a fixed-size array. And this is effectively the same as constant-sized arrays offered by C for stack usages, and Valhalla will be able to handle it like regular value classes (though it might refuse to inline because the object is too big)</div><div>2. All Java arrays have a zero-length value for its own type; we can potentially designate, say, any new Class[0] as the non-null default value of a Class[]. But this will hurt the existing identity assumptions around zero-length arrays.</div><div><br></div><div>Also make note that Java arrays are polymorphic, i.e. you can assign a new Class[0] to a field of type Object[] or ConstantDesc[], while value classes are not. Alternative 1 sacrifices this polymorphism, while alternative 2 might bring confusion over a new Class[0] and a new Object[0] in an Object[] field, and I'm not quite sure about the impact on their heap layout yet.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jan 12, 2024 at 6:55 PM David Alayachew <<a href="mailto:davidalayachew@gmail.com">davidalayachew@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-family:monospace">Hello Valhalla Dev Team,</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">I see the JEP Draft for Null-Restricted Value Class Types (<a href="https://openjdk.org/jeps/8316779" target="_blank">https://openjdk.org/jeps/8316779</a>), and it looks beautiful. I am extremely excited at the possibilities.</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">At the very bottom of the draft, there is a tiny snippet --- "More general support for nullness features will be explored in a future JEP."</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Any chance that we could be looking at arrays that cannot be null? </div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">And to be clear, I am not saying arrays that cannot contain null. This JEP Draft already confirms that that is not only a possibility, but might very well become reality (only if this draft goes live, and then the feature exits preview into GA).</div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">No, I mean that the array itself cannot be null. Any possibility? And apologies if the answer is obvious. I don't want to make any assumptions here, since I am still wrapping my mind around how Valhalla made all of this stuff possible. I figured it's better to just ask.<br></div><div class="gmail_default" style="font-family:monospace"><br></div><div class="gmail_default" style="font-family:monospace">Thank you for your time and help!</div><div class="gmail_default" style="font-family:monospace">David Alayachew<br></div></div>
</blockquote></div>