> > (I can think
> > of at least two good reason why a VM designer might decide to "split"
[quoted text clipped - 5 lines]
> Out of curiosity, can you state these reasons? All I can think of is
> issues with RMI.
What I had in mind:
Some GC-ed languages use an object representation where the "object" is split
into a header of, say, 8 to 16 bytes, which itself contains a pointer to the
body, where the object's non-static fields, etc, are stored. This permits
easier implementation of moving GC, and has other benefits for languages with
less crippled semantics than Java (e.g. dynamic resizing of objects, or
Smalltalk's #become: operation).
There has been some research on the benefits of splitting objects so that their
frequently used fields are stored separately from their less frequently used
ones. That has the benefit that more of the /useful/ data will fit into the
data caches (on-chip, or wherever) so the program on the whole may run faster
(at the cost that infrequently used fields take longer to access).
It may be worth splitting large arrays into "pages"; memory fragmentation can
be avoided by ensuring that there is a single, fixed, maximum size of any
allocation.
Incidentally, any/all the above might have greater benefit on a JVM designed to
make best use of a loosely-coupled multi-CPU architecture. (Though whether it
would be actually /worth/ the effort of creating a special implementation for
such an application is a different question). You point about RMI may reflect
the same thinking -- if you can split an object so that you don't have to copy
/all/ of the object's state in order to use /any/ of its state, then you may
see a nett gain.
-- chris
Jeff Schwab - 13 Aug 2005 16:37 GMT
>>>(I can think
>>>of at least two good reason why a VM designer might decide to "split"
[quoted text clipped - 32 lines]
> /all/ of the object's state in order to use /any/ of its state, then you may
> see a nett gain.
When I first started using C, it was not uncommon to group data
according to type so one wouldn't waste "padding" bytes necessary for
alignment. For example:
struct S {
char c; /* OK, arbitrary address. */
/* Often three bytes of padding required
* here to provide for proper alignment of int.
*/
int i; /* Requires special alignment. */
};
An array of 1000 such structs might waste 3KB. It seemed more efficient
to break the data into two arrays: One of 1000 chars, and another of
1000 ints. Each "struct" was then retrieved by a single index that
related locations in the multiple arrays.
I don't know whether this technique is ever used by Java implementations.
Jeff Schwab - 13 Aug 2005 16:39 GMT
> When I first started using C...
> struct S {
/* ... */
> };
Whoops! Too much C++. :) Should have said:
typedef struct { /* ... */ } S;
Tor Iver Wilhelmsen - 14 Aug 2005 08:46 GMT
> I don't know whether this technique is ever used by Java implementations.
From the JVM spec:
3.7 Representation of Objects
The Java virtual machine does not mandate any particular internal
structure for objects.
So it's conceivable they could; using 32-bit words makes the
addressable memory four times as large as when using 8-bit words. (I
am talking about J2SE here, J2ME and JavaCard implementations would be
different.)
On the stack frame, a local variable is a 32-bit word. "long" or
"double" values occupy two local variables (JVMS §3.6.1).