Structs

There is a memory savings because there is no memory overhead per object. Since structs would exist in the byte buffer. Bounds checks would be a little more efficient because they would only be need for the struct boundary, not individual members.

I’m not sure that there will be big savings in the actual machine code produced, but it will be a significant programming convenience and memory savings.

NB: I am a strong advocate of preventing java from ever having full C++ style pointers, for reasons e.g. simlar to those that I don’t program in assembler any more - it’s unmaintainable and unnecessary. However…

Your reaction is reactionary - it sounds like a knee-jerk “oh, this involves pointers! Pointers are bad! This must be bad!” without thinking about hte details. I feel tempted to say that before making such comments, you should go and learn more of Java. Pointer arithmetic is here, now, and it’s not going anywhere (it’s a fundamental concept provided by NIO - and I’ve seen several people use it as such); structs would promote a subset of pointer arithmetic into object management. IMHO, this is a good thing - java has had no syntax-level pointers for 10 years, and now we are in a position to know very well where and how it is necessary for a systems language to gradually introduce some uses of poitners in a controlled way - and are able to do so without suddenly opening a can of worms.

Structs can be (and, as far as I can see, probably already are being) implemented by individuals right now, but you have to do all the setup and management yourself and lose much help you could have had from the compiler and from the JVM if they were “supported” more by the language.

Please tell me how to manage my 100 million objects, all of which I’ll be accessing during the next few milliseconds? No, really. I would like to know! How many decades will it be before Sun’s heuristic-based object management has a hope of catching up with the tricks I could do when I - as the app developer - actually know for totally unpredictable (at the execution level) but totally predictable (at the app design level) reasons which objects I want when and in what order?

100 million is NOT an exaggeration…I have game apps that generate that many (not vanilla stuff, but nevertheless (to do with background AI)). I’m not using any big BSP trees myself at the moment, but it’s clear that they are going to have rather a lot too on modern game levels with many polygons, no?

[quote]There is a memory savings because there is no memory overhead per object.
[/quote]
It is also worth pointing out that when you have very large datasets a lot of the java data structures become useless; creating and managing custom data structures which contain objects using indexes into a big struct is a safe and easy way of working around this (and if you need that many object you probably are skilled enough at DS to be able to make whatever custom DS you need).

For instance, try using an ArrayList with 50,000 objects in it…things that scaled poorly with N but started fast enough were usable at 1,000 objects but now are useless.

Don’t get me wrong. I am not against you, but the descriptions in the RFE and this thread are muddy.

The flyweight pattern “solves” the 100 million object problem.

So please clarify:

What facilities should the new VM and API’s provide?

What patterns/attributes/annotations/marker-interface signals that the class should be optimized, and what optimizations can be provided?

What are the constraints for objects of this kind. Can the class be part of an inheritance hierarchy? Can it participate in composite structures? Can it have other members than the primitives.

I am eager to hear how - according to you - my objects, which do not contain any shared information beyond their method bodies, are solved by flyweights. I thought flyweights were only useful where many of the objects were object-equivalent, or where significant numbers had identically-valued variables for some subset of the set of vars in the object?

The flyweight pattern shares object instances by making object state extrinsic.

In this particular case, object state is stored in a ByteBuffer.
The only intrinsic state that is needed per instance is the start offset in the bytebuffer.

As PrinseC pointed out, you can probably get away with having a single instance of your ‘struct’ flyweight object, and modify the offset on demand.

[quote]Giddy said;
In this particular case, object state is stored in a ByteBuffer.
The only intrinsic state that is needed per instance is the start offset in the bytebuffer.

As PrinseC pointed out, you can probably get away with having a single instance of your ‘struct’ flyweight object, and modify the offset on demand.
[/quote]
I think thats what blah meant when he said this:

[quote]blah said;
Structs can be (and, as far as I can see, probably already are being) implemented by individuals right now,
[/quote]
Isn’t this the array-of-objects vs the object-of-arrays argument all over again?

Still no sign of anyone looking at this RFE. Perhaps a Sun VM engineer would care to join in the discussion…?

Cas :slight_smile:

IMHO, this thread should have been appropriately started in the Performance Tuning section for greater visibility - a thought much in hinsight though I must admit !

Probably could try Azeem Jiva or even Jeff (where is he ?) in the Tuning section to see if someone would pick up the bait.

Surely there must be more than 300 members in this Forum eligible to cast their votes. If not anything more, just go vote to get Sun to come up with counterpoints/counter-proposals.

Yeah, but with the extreme sparsity of mods around here we can’t move threads around much…

Cas :slight_smile:

Cas, you could join the JCP (now free for an individual), and submit a JSR proposing the addition of something like http://jade.dautelle.com/api/com/dautelle/util/Struct.html to the java.nio package with the intention of it being included in J2SE 6.0 (Mustang) which is now the earliest possible point for such a change.
Of course adding such a class is the easy bit, you then have to hope that JIT writers give some attention to it so that performance is optimised.
As this does not require a language change, there ought to be a reasonable chance of success.

Dautelle’s class isn’t perfect for this purpose, but it does represent a reasonable starting point (and is public domain).

I’m a bit thinly stretched atm… would need a few others to pull the rope with me. Such as yourself and shawnkendall and blah3 perhaps.

Cas :slight_smile:

[quote]I’m a bit thinly stretched atm… would need a few others to pull the rope with me. Such as yourself and shawnkendall and blah3 perhaps.

Cas :slight_smile:
[/quote]
Same here. I could certainly participate, but for the next few months only passively (i.e. mainly responding, rather than starting things).

Is it just me or does the dautelle class look a bit disturbingly complicated?

[quote]Is it just me or does the dautelle class look a bit disturbingly complicated?
[/quote]
The public interface seems reasonably simple to me.

Way more complicated than it needs to be. It’s got to be simple enough to implement in the VM in both software (as a fallback) and using clever optimisations into machine code.

Cas :slight_smile:

I’ve added my 3 votes to it…

Shame this missed Tiger.

Will.

Well, Structs have made it into the Top 10 RFEs, and still no REPLY from Sun.

On the up side, Java 6 (Mustang) is having some discussion.
Let’s get those votes in, tell your friends!!!

Top 25 RFEs:
http://bugs.sun.com/bugdatabase/top25_rfes.do

Structs RFE:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4820062

Errggh. Reading the comments at the bug parade really sets my teeth on edge. It’s like Slashdot. Only not as funny.

When is Sun going to implement a rule that says you can’t submit comments on an RFE unless you:

a) have been developing more than just in VB before you moved to Java
b) have more than 3 brain cells to rub together at any one moment in time.

Frankly I wish I had a spaceship so I could start tracking down these people and telling them just what I thought of them (pathetic Douglas Adams reference, in case it wasn’t completely obvious)

Assuming things continue like this, we should organise a party on the 18th Feb to celebrate 2 years of Sun ignoring their community.

They’re really quite busy you know. :wink: