Wouldn't this be nice?
Ulf Zibis
Ulf.Zibis at gmx.de
Thu Nov 12 08:53:44 PST 2009
Oops, I oversaw the intermediate step, as Iterator#next() always returns
an Object, regardless if CharSequence contains simple char array.
... but I'm happy that I've triggered the discussion about HotSpot
compiler optimization, as I had this in my mind too after solving my
question.
-Ulf
Am 12.11.2009 16:37, Reinier Zwitserloot schrieb:
> Yes, java should absolutely gain @NonNull as a JVM primitive, and the JVM
> should be smart enough to treat @NonNull PrimitiveWrapper as primitives, so
> that you can for example create:
>
> List<@NonNull Byte> list = new ArrayList<>();
>
> and have it be as fast as a byte array, and take ~1 byte per byte stored
> instead of ~24 bytes per byte stored which happens when you try this now, on
> a 64-bit VM. (8 bytes for the byte itself, 8 bytes for the reference stored
> in the array, and 8 bytes overhead for the object, which is probably
> lowballing it).
>
>
> Practically speaking though, that's very hard to get right. The hot spot
> compiler is not going to be able to figure out that e.g. ArrayList's 'new
> Object[size]' array construction should actually make a byte[] array unless
> there's reification, and that's just a glimmer of the complications you're
> going to run into with this.
>
>
> Keeping it somewhat simpler, the hotspot compiler might just be able to
> recognize that this flow is happening:
>
> A calls method B, which has called invokestatic on method:
>
> java/lang/Character - valueOf - (C)Ljava/lang/Character;
>
> right before every ARETURN instruction.
>
> A, immediately after invoking method B, always runs invokevirtual on method:
>
> java/lang/Character - charValue - ()C
>
> If this is true, then it should always be legal to ignore both method calls;
> they are each other's opposite.
>
> No need for JVM awareness of @NonNull annotations; if the above situation
> occurs, then the Character object in question that is never made could never
> have been null.
>
> --Reinier Zwitserloot
>
>
>
> On Thu, Nov 12, 2009 at 4:08 PM, Mark Mahieu <markmahieu at googlemail.com>wrote:
>
>
>> And back again:
>>
>> char -> Character -> char
>>
>> or perhaps an Iterable<@NonNull Character> would be more interesting:
>>
>> char -> @NonNull Character -> char
>>
>>
>> Which begs the question - if one were to optimise this, would the language
>> spec or the VM be a better place to do so?
>>
>>
>> Mark
>>
>>
>>
>>
>> On 12 Nov 2009, at 14:39, Reinier Zwitserloot wrote:
>>
>> char to Character, obviously.
>>
More information about the coin-dev
mailing list