Value Types for Java

Ben Hutchison benh at ibsglobalweb.com
Tue Jun 17 22:15:54 PDT 2008


Miles Sabin wrote:
> On Tue, Jun 17, 2008 at 5:42 AM, Ben Hutchison <benh at ibsglobalweb.com> wrote:
>   
>> Ive written up a post outlining my case for value type support:
>> http://benhutchison.wordpress.com/2008/06/15/the-jvm-needs-value-types/
>>     
>
> Surely, in that very article you describe the exact encoding that's
> needed to get almost all of the benefits of value types that you list
> without any JVM changes: inline value type fields into the enclosing
> object, stack frame or argument list.
>
> Arrays are a little less natural, but one array per field would seem
> likely to do most of the job on the assumption that most value types
> have few fields (so, eg. an array of (String, int) would be encoded as
> an array of string and an array of Int). [snip]
>
> So doesn't this get you what you want? What am I missing?
>   
It seems to do 90% of what I want. Its definitely an option I'd consider 
as last resort. It's just really awkward.

The awkwardness is that the programmers view has to be so divergent from 
the underlying representation, particularly in the difficult-but-crucial 
array case

Where the discontinuity is revealed, the effect on the programmer could 
be jarring:

1. Reflection APIs. What would one see in reflection? How could one 
reflectively invoke a method on an array-contained value type, where the 
actual fields are smeared across a series of arrays?

2. Debugging. A typical Java debugger would expose the underlying 
"mangled" array form, which looks horrible in the case of nested arrays 
of value types. True debugger support would need to perform the reverse 
translation from inlined representation back to a value type based 
representation.

My gut feeling is that the awkwardness of the representation would limit 
the widespread adoption of such a scheme.

Also, in terms of what it doesn't do:

1. Hard to see any way to extend to interpret a ByteBuffer region as an 
array of some value type, a feature ultimately needed for bulk interop 
with external IO/processes, I feel.
2. Separate arrays per field is less cache friendly than true value types

-Ben
-- 

	

*Ben Hutchison
Senior Developer
* Level 2 476 St Kilda Road Melbourne VIC 3004
T 613 8807 5252 | F 613 8807 5203 | M 0423 879 534 | 
www.ibsglobalweb.com <http://www.ibsglobalweb.com/>

This e-mail (and any attachments to this e-mail) is for the exclusive 
use of the person, firm or corporation to which it is addressed and may 
contain information that by law is privileged, confidential or protected 
by copyright. If you are not the intended recipient or the person 
responsible for delivering this e-mail to the intended recipient, you 
are notified that any use, disclosure, distribution, printing or copying 
of this e-mail transmission is prohibited by law and that the contents 
must be kept strictly confidential. If you have received this e-mail in 
error, kindly notify us immediately on + 613 8807 0168 or respond to the 
sender by return e-mail. The original transmission of this e-mail must 
be destroyed.

Internet Business Systems Australia Pty Ltd accepts no responsibility 
for any viruses this e-mail may contain. This notice should not be removed.





More information about the mlvm-dev mailing list