by pavanky · 10y ago · 0 comments
Anyway the biggest issue I have seen in my line of work (building GPU software, and people want GPU acceleration from their language of choice) is that JVM does not provide a way to handle external resources properly. Calling garbage collection does not guarantee that the out of scope objects will be finalized. This results in either code that uses up a lot of memory or code that is very un-java like.
Yes I know try with resources exist, but the problem still exists for any temporary variables you create within the block.
If anyone here has a better solution, I am all ears.
JNI and P/Invoke are not really that different except that P/Invoke is a lot easier to implement. But CLR does not know how to cleanup unmanaged resources automagically.
edit: I removed my notes about "try with resource" and AutoCloseable
I was talking about people not wanting to move away from their language of choice which results in us having to try and support them as well.
try (ObjectPool pool = new ObjectPool()) {
...
Foo foo = pool.register(new Foo());
...
Bar bar = pool.register(new Bar());
}
When ObjectPool is closed, it closes all its registered objects too.Note that this would be a lot easier with a language like Scala or Kotlin.
Array C = Array.Add(A, Array.sin(B))
The output C and the output of Array.sin(B) have not been allocated from the object pool.``` ArrBuilder = arrs; arrs.add(A, arrs.sin(B)); Array C = arrs.get(); ```
Otherwise if you're willing to do Lombok style AST manipulation you could of course do most anything you wanted, perhaps even proper operator overloading:
``` @Arrays public void test() { Array C = A + sin(B); } ```
(Just be ready for the Java programmers to rebel on you and your "dark arts" ;) )
There are actually three implementations of C on top of Graal/Truffle by now.
TruffleC was the first and it maps malloc to the JVM's Unsafe malloc equivalent. So if you double free you trash the VM basically.
ManagedC ignores calls to free() and garbage collects the C programs heap.
Sulong interprets LLVM bytecode. I don't know how it does memory management.