How impossible would it be to add a delete keyword to the JVM, and why?
How impossible would it be to add a delete keyword to the JVM, and why?
A "delete now" operation imposes requirements on implementations that are not strictly required.
Any advantages gained from destructors can be realized via explicit cleanup methods and (as a hedge against mis-use) state checking for initialized and destroyed objects. A delete operation also adds risk that an object that has been deleted may be referenced again (although with esoteric stuff like PhantomReferences you can almost do it).
http://www.docjar.com/docs/api/sun/misc/Unsafe.html#freeMemo...
If you want manual memory allocation then you should instead look at sun.misc.Unsafe.
http://www.docjar.com/html/api/sun/misc/Unsafe.java.html
public native long allocateMemory(long bytes);
public native void freeMemory(long address);
Of course you still have to calculate the field offsets and all that stuff manually because it's not a part of the java language but you only asked about the JVM.Manual memory management is a good choice if you have both worst-case latency concerns as well as very restricted RAM and/or severe energy constraints (basically, the kind of applications that Rust was designed to handle).
That’s horrible to use for game development.
why would some kind of that be problematic? I mean graphics programmic is kind of new to me, but considering that you could offload that to a c/c++ engine via jni (that's another horrible thing of some kind), but just the game code itself doesn't seems to be to bad, does it?
The whole point is not to offload anything. If you need to offload anything, even the render loop, the language has failed.
That's not the RTSJ solution. RTSJ uses arenas, which are great if you have regular allocation/deallocation cycles, like, say, a frame in a game.
So how do I get a user’s Oracle JRE installation to use arenas? The only realistic scenario is to preallocate and reuse.
[1]: https://www.ibm.com/support/knowledgecenter/en/SSSTCZ_3.0.0/...
(Keep in mind that Java is a memory-safe language.)
If those 11 threads would share the same heap and 1 thread still doesn't use the gc because it's using manual memory management then you'd still suffer from stop the world pauses.
What you want is isolated heaps like erlang does, not manual memory management. I'm still wondering why we have no other programming languages with multiple heaps. You could probably achieve something similar with D and use of memory mapped files to efficiently share memory without copying bewteen processes. Alternatively you could call into C to spawn OS threads that don't suffer from stop the world pauses. But those two options are a hack. You're not supposed to use D like that.
I chose D as an example because it's a programming language with both a garbage collector and manual memory management that still suffers from stop the world pauses.