Gaming JVM
Just an innocent question, don't throw any rocks... Do you guys think that Java would need an optimized JVM for games, at least the more CPU-intensive ones, or the existing one does fine? I'm not talking about changing the language, but changing the JVM specification, maybe by allowing control of the garbage collector, among other stuff. Is it possible? Reasonable? Making sense? Or it's just a stupid idea?
the current one does perfectly fine.
There is no need to control the GC as it already optimised (and can be further optimised by supplying the correct command line flags) to garbage collect when there is minimal load. Also, coding correctly in the first place would stop the GC kicking in the first place. I.e. only creating new objects in constructors and in the start of the game and not in the middle. Also re-use variables, i.e. if your planning on doing this every frame:
Vector3f f = sprite2.getLocalTranslation();
f.x += 2;
sprite2.setLocalTranslation(f);
It would be better to either make that final or have a pre-made final vector:
private static final Vector3f tempVa = new Vector3f();
public void someMethod() {
tempVa = sprite2.getLocalTranslation();
tempVa.x+= 2;
sprite2.setLocalTranslation(tempVa);
}
That would basically stop the GC dead in its tracks. Also, that method can probably be inlined later if called enough times, so you can have ASM speed!
DP
erm digi,That example you have posted will give no performance benefit *at all*. (and infact will be slightly slower)
Abusea at 2007-7-10 14:14:45 >

I never said it would be faster....I said that it would prevent new objects being created in the loop, to stop the GC kicking in.-Digiwired
I understand what you were trying to show in your example -but the example you have posted does not eliminate garbage creation at all.Infact, it generates 1 *extra* garbage object.
Abusea at 2007-7-10 14:14:45 >

Well right now it doesn't compile, but I assume you meant to do:
private static final Vector3f tempVa = new Vector3f();
public void someMethod() {
tempVa.set(sprite2.getLocalTranslation());
tempVa.x+= 2;
sprite2.setLocalTranslation(tempVa);
}
This would require getLocalTranslation() to return its internal Vector3f, rather than a copy.
or....
private static final Vector3f tempVa = new Vector3f();
public void someMethod() {
tempVa = sprite2.getLocalTranslation(tempVa);
tempVa.x+= 2;
sprite2.setLocalTranslation(tempVa);
}
// and within sprite
public Vector3f getLocalTranslation(Vector3f dst)
{
if(dst==null) dst = new Vector3f();
localTrans.copyInto(dst);
return dst;
}
Abusea at 2007-7-10 14:14:45 >

and perhaps even better ...
public Vector3f getLocalTranslation(Vector3f dst)
{
if(dst==null) dst = new Vector3f();
dst.set(localTrans);
return dst;
}
Abusea at 2007-7-10 14:14:45 >
