5

I wonder if ART is virtual machine. The dex2oat compiles dalvik byte code into the native (specific for platform) code, elf file. So as mentioned in android developer article it still has garbage collector. I don't understand how does it work, we have native compiled elf file, but it still runs in virtual machine environment ? How does GC work in this case ? Please give a good reference to read about this or please explain this. Thanks in advance.

Seki
  • 11,135
  • 7
  • 46
  • 70

1 Answers1

2

GC is just a way the memory is managed. In any Java VM GC is the entity responsible for both memory allocation AND garbage collection. when you allocate an object GC check for available memory and collects garbage if there is no free space. You can implement the same algorithm in native language like C or C++. So it doesn't matter if you compile java to bytecode and then bytecode calls GC and GC runs inside JVM or you compile java to native code and link it with GC which may be a shared library. There was a VM from Miriad Group (ex Esmertec) which did it way before ART but for Java ME

mishmashru
  • 459
  • 5
  • 8
  • but it still runs inside virtual machine, i mean that each process of third-party apps is virtual machine instance ? And when I want to allocate memory, I am going to ask virtual machine responsible part to allocate memory in native memory space ( in linux ) am I right ? –  Jan 07 '15 at 22:43
  • yes, you are right in general. But when you say 'allocate memory in linux' it doesn't make a lot of sense. VM still has its own heap and heap is allocated from system memory of course. Application or VM doesn't allocate objects in system memory because GC is doing not only collection but also compaction: objects are being moved. – mishmashru Jan 11 '15 at 22:28