Empty value type ?

Remi Forax forax at univ-mlv.fr
Fri Jun 29 19:49:29 UTC 2018



----- Mail original -----
> De: "Frederic Parain" <frederic.parain at oracle.com>
> À: "Brian Goetz" <brian.goetz at oracle.com>
> Cc: "valhalla-dev" <valhalla-dev at openjdk.java.net>
> Envoyé: Vendredi 29 Juin 2018 21:31:21
> Objet: Re: Empty value type ?

> I’d be cautious about “zero-length” values, especially if the assumption is that
> they will be flattened and their memory cost would be strictly equal to zero.
> 
> Several components or API implementations in the JVM are using the field
> offset as a unique ID for fields, which works fine because today there’s a 1:1
> mapping between offsets and fields. It’s also convenient because the offset
> uniquely identify a field in the declaring class and also in all its
> sub-classes.
> One example of this is the jFieldID used by JNI and JVMTI. Other usages
> are in MethodHandles code (MethodHandles::expand_MemberName()) and
> reflection code (jvm_get_field_common()).
> 
> Zero-length flattened fields would break this property (if they really have
> zero-length, several fields could have the same offset).
> 
> Flattened empty value types might look appealing, but we have to look
> carefully about the impact they will have on our code base.

I agree,
First, you can export a fake id has a negative value or use another high bit, having a flag bit is useful because you can test easily if you can extract the value or not.  
Also, most of these empty types are mostly used on stack but not as field, at least until we can use them to specialize a generics class, so perhaps they can be allowed only on stack first ?

> 
> Fred

Rémi

> 
> 
>> On Jun 26, 2018, at 15:43, Brian Goetz <brian.goetz at oracle.com> wrote:
>> 
>> Zero-length values can be quite useful, just not directly.  Look at the current
>> implementations of Set that delegate to HashMap; all that wasted space.  When
>> we have specialized generics, they can specialize to HashMap<T, empty>, and
>> that space gets squeezed away to zero.
>> 
>>> On Jun 26, 2018, at 11:36 AM, Kirk Pepperdine <kirk.pepperdine at gmail.com> wrote:
>>> 
>>> How can a value type be empty.. what is an empty integer? An empty string? Just
>>> curious.
>>> 
>>> Kind regards,
>>> Kirk
>>> 
>>> 
>>> 
>>>> On Jun 26, 2018, at 3:28 PM, forax at univ-mlv.fr wrote:
>>>> 
>>>> ok,
>>>> in that case, i think zero field value types should be rejected by the compiler.
>>>> 
>>>> Rémi
>>>> 
>>>> ----- Mail original -----
>>>>> De: "Tobias Hartmann" <tobias.hartmann at oracle.com>
>>>>> À: "Remi Forax" <forax at univ-mlv.fr>, "valhalla-dev"
>>>>> <valhalla-dev at openjdk.java.net>
>>>>> Envoyé: Mardi 26 Juin 2018 15:23:46
>>>>> Objet: Re: Empty value type ?
>>>> 
>>>>> Hi Remi,
>>>>> 
>>>>> no, empty value types are not planned to be supported for LW1.
>>>>> 
>>>>> Best regards,
>>>>> Tobias
>>>>> 
>>>>> On 26.06.2018 15:19, Remi Forax wrote:
>>>>>> Is empty value type targeted for LW1 ?
>>>>>> 
>>>>>> Error: LinkageError occurred while loading main class GenBug
>>>>>> 	java.lang.ClassFormatError: class: GenBug - Value Types do not support zero
>>>>>> 	instance size yet
>>>>>> 
>>>>>> Rémi
>>> 



More information about the valhalla-dev mailing list