With Kitkat release, Android supports Android Run Time(ART) in addition to the Dalvik VM. In ART, the java code is compiled to native code during installation instead of the JIT performed in case of Dalvik VM. I am not able to figure out the component that handles the Garbage Collection functions of a JVM. If you have a sure idea of how it is done, share it with the community.
Asked
Active
Viewed 992 times
3

Charles
- 50,943
- 13
- 104
- 142

user3388324
- 572
- 5
- 18
-
Why should there be a big difference in garbage collection? The Just-In-Time compilation is just done ahead of time so execution of native code is nothing new. – zapl Mar 31 '14 at 19:40
-
So the code still runs on a VM ? I thought it goes unmanaged like the c code, where the programmer has to free the memory. – user3388324 Mar 31 '14 at 20:18
-
Java wouldn't work without a GC as there are too many places where things get allocated. Actually everything including for-each loops and all libraries would be unusable if there was nobody to clean up. – maaartinus Apr 01 '14 at 04:41
-
1The fact that code is transformed into native code does not change it to unmanaged C, it is still fully managed Java. The difference is that the VM does not have to interpret bytecode (a bit like `if(currentByteCodeInstruction == ADD && valueOnStack == 5) { virtualRegister += 5 }`, it just executes pre-compiled pieces (in this example, instead of executing an `if` with two comparisons and then the actual addition the processor executes just the operations). – zapl Apr 01 '14 at 10:19
-
@zapl I have a clear understanding now. Does the performance abilities of native code in a VM match that of unmanaged c(assuming c pointers are efficiently freed). – user3388324 Apr 01 '14 at 14:03
-
It's close. The resulting native code is as fast as if you had writting it in C, the processor does not care where it's instructions come from. On the other hand, Java can't be as fast as an optimized C program because every abstraction removes the ability to do dirty lower level tricks (you can only rely on the VM to do them), it also has to keep some Language guarantees like type and array bound checks which you could simply remove if it was C, then additional management tasks (e.g. GC) during runtime that can be done faster in unmanaged code. Also http://stackoverflow.com/a/2163570/995891 – zapl Apr 02 '14 at 08:39