<div dir="auto">On your last point.<div dir="auto">Identity != memory location</div><div dir="auto">Identity only means that you can identify the object and all references point to the same location in memory (heap or stack).</div><div dir="auto">Everything has a memory address period. Rather something lives on the stack or heap every byte of data has a memory address. The runtime is already free to keep a current standard reference type on the stack if it can confirm that it will a) benefit performance and or memory efficiency and b) a situation where a reference to this stack value outside its stackframe exist is impossible. The big benefit of having no identity and therefore being immutable is that the object can be copied without any analysis of multiple references. Since different references to the same object can actually point to different spots in memory. This might sound memory inefficient but remember, stack memory is cheap heap isn't. The idea is that objects without identity can be allocated on the stack most of the time and packed in objects since they don't need to track their references since copies of themselves are interchangeable and indistinguishable.</div><div dir="auto">Please correct me if I'm wrong with something I'm still learning.</div><div dir="auto"><br></div><div dir="auto">Great regards </div><div dir="auto">RedIODev </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Jan 11, 2023, 23:03 <<a href="mailto:forax@univ-mlv.fr">forax@univ-mlv.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:#000000"><div><br></div><div><br></div><hr id="m_2654577501732657604zwchr"><div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From: </b>"Brian Goetz" <<a href="mailto:brian.goetz@oracle.com" target="_blank" rel="noreferrer">brian.goetz@oracle.com</a>><br><b>To: </b>"Anderson Vasconcelos Pires" <<a href="mailto:andvasp@gmail.com" target="_blank" rel="noreferrer">andvasp@gmail.com</a>><br><b>Cc: </b>"Remi Forax" <<a href="mailto:forax@univ-mlv.fr" target="_blank" rel="noreferrer">forax@univ-mlv.fr</a>>, "valhalla-dev" <<a href="mailto:valhalla-dev@openjdk.java.net" target="_blank" rel="noreferrer">valhalla-dev@openjdk.java.net</a>><br><b>Sent: </b>Wednesday, January 11, 2023 6:35:01 PM<br><b>Subject: </b>Re: Civilizer - let's civilize those primitive types !<br></blockquote></div><div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt">
I think you may be missing out on the goal here. This is not an exploration of the user model (value vs primitive class, val/ref/bang/etc), this is an exploration of the underlying translation / implementation scheme *that might inform* future evolution of
the user model.
</blockquote><div><br></div><div>yes,<br></div><div><br></div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><br>
<div><br>
<blockquote>
<div>On Jan 11, 2023, at 12:29 PM, Anderson Vasconcelos Pires <<a href="mailto:andvasp@gmail.com" target="_blank" rel="noreferrer">andvasp@gmail.com</a>> wrote:</div>
<br>
<div>
<div dir="ltr">
<div dir="ltr">Thanks for the prompt response!<br>
</div>
<div class="gmail_quote"><br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt">
<div>
<blockquote style="border-left-width:2px;border-left-style:solid;border-left-color:rgb(16,16,255);margin-left:5px;padding-left:5px;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt">
<div dir="ltr"><span style="font-family:arial,helvetica,sans-serif;font-size:12pt">Mostly prototyping a proposal to remove Q-types (descriptor that starts with Q...;) and replace them by an attribute on methods and fields indicating if the
value can be null.</span><br>
</div>
</blockquote>
<div>see <a href="https://mail.openjdk.org/pipermail/valhalla-spec-experts/2023-January/002217.html" target="_blank" rel="noreferrer">
https://mail.openjdk.org/pipermail/valhalla-spec-experts/2023-January/002217.html</a><br></div>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>So if you want to remove Q types it means that L type does not need the identity information, right? </div></div></div></div></blockquote></div></div></blockquote><div><br></div><div>Currently when you have a primitive class, you need to declare the class as a private class *and* you need to use a Q-type each time you mention that class (in a method descriptor, a field descriptor, in a checkcast, see JEP 401). <br></div><div>The idea here is when you need to declare the class as a private class but instead of using a Q-type, you use a side attribute that indicates if null is a valid value or not.<br></div><div><br></div><div>To answer your question, you do not need the identity information at use site, what you need to know is if it is a zero-default value class and if null is not a valid value. Previous both information where grouped together inside the Q-type, i'm proposing to keep them into two location and let the VM gathers those information together.<br></div><div><br></div><div><br></div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div><blockquote><div><div dir="ltr"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt">
<blockquote style="border-left-width:2px;border-left-style:solid;border-left-color:rgb(16,16,255);margin-left:5px;padding-left:5px;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt">
<div dir="ltr">
<div><br>
</div>
</div>
</blockquote>
<div>There is no notion of .val or .ref, if you want a field to be flattened, use a @Zero-Default and declare the field @NonNull.<br>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Pretty good if we do not need to use .val or .ref!</div>
<div>
<div><br>
Could the @NonNull be replaced by "!" but writing the attribute in the class file?<br>
</div>
<div><br>
</div>
<div>I Like @NonNull but I believe the "!" would be more practical.</div></div></div></div></div></blockquote></div></div></blockquote><div><br></div><div>See Brian answer,<br></div><div><br></div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div><blockquote><div><div dir="ltr"><div class="gmail_quote"><div>
<div> <br>
</div>
<div>As @Nullable is the default, maybe it would not be necessary to have it.</div></div></div></div></div></blockquote></div></div></blockquote><div><br></div><div>We will need a way to say that Map<String, @NonNull Foo>.get() return type is a nullable Foo, even if the V (in Map<K,V>) is a non-null Foo.<br></div><div><br></div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div><blockquote><div><div dir="ltr"><div class="gmail_quote"><div>
</div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt">
<div>
<blockquote style="border-left-width:2px;border-left-style:solid;border-left-color:rgb(16,16,255);margin-left:5px;padding-left:5px;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt">
<div dir="ltr"><span style="font-family:arial,helvetica,sans-serif;font-size:12pt">yes, the prototype does not do any verification that the compiler does, i'm too lazy for that but the VM will catch you and throw an Error</span></div>
</blockquote>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Pretty good for a prototype! </div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div>
<div style="font-family:arial,helvetica,sans-serif;font-size:12pt">
<div>
<div>About the mutability of fields, fundamentally, value type is about saying, i give up the notion of identity, if you have no identity, you have no location in memory (you can have more than one if you prefer) so the VM is free to pass by reference
or pass by value. So you can not mutate a field, because you can only do that if you have one location in memory.<br>
</div>
<div><br>
</div>
</div>
</div>
</div>
</blockquote>
<div><br>
</div>
<div>Ok for mutability but now I am a little bit confused about references, identity and memory location. </div></div></div></div></blockquote></div></div></blockquote><div><br></div><div>You are not alone :)<br></div><div><br></div><div>In Java, all classes have references / instances / objects. This does not change with the introduction of value class.<br></div><div>Identity class have references which have an identity, so == will compare the address in memory.<br></div><div>Value class have references which does not have an identity, so == will compare the content on the object.<br></div><div><br></div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div><blockquote><div><div dir="ltr"><div class="gmail_quote"><div>Value class is a reference type that does not have identity. So it means that it can be allocated in the heap, right? </div></div></div></div></blockquote></div></div></blockquote><div><br></div><div>No, it means the opposite. Having an identity is equivalent to saying having an address in memory in the heap.</div><div>So having no identity means that the VM is free to chose to allocate it in the heap, to not allocate it in the heap, or even to allocate it multiple time in the heap, because from the user POV all these objects can not be distinguished one from another, thus they are one.<br></div><blockquote style="border-left:2px solid #1010ff;margin-left:5px;padding-left:5px;color:#000;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><div><div><blockquote><div><div dir="ltr"><div class="gmail_quote"></div></div></div></blockquote></div></div></blockquote><div>Rémi<br></div><div><br></div></div></div></div></blockquote></div>