views:

194

answers:

5

In which language garbage collection algorithm is implemented for java.i think c, please confirm?

+3  A: 

AFAIK the Sun JVM is implemented mostly in C++ and assembler, so I'd guess that the GC is implemented in C++.

Bozhidar Batsov
+5  A: 
polygenelubricants
+1  A: 

If you want to see the source code, download the OpenJDK source code. Warning: It is not going to be easy to understand, there are a number of very sophisticated garbage collection algorithms implemented in the JVM.

Jesper
+2  A: 

As an example of my point that not all Java VMs are implemented in C++, consider Jikes, which is meta-circular. It is completely implemented in Java. A minimal bootstrap section of the code is written in C, but the rest of the VM—including the memory management (MMTk)—is written entirely in Java.

jasonmp85
+7  A: 

It depends on the JVM. Often, the garbage collector is implemented in the same language as the JVM, but that is not always the case.

In Maxine, both the JVM and the garbage collector are implemented in Java.

In Jikes, both the JVM and the garbage collector are implemented in Java.

In Rava, the JVM is implemented in Ruby and the garbage collector isn't implemented at all: Ruby already is a memory-managed language, there is no need to implement a separate garbage collector.

In IKVM, the JVM is implemented in C# and CIL and the garbage collector isn't implemented at all: the CLI VES already is a memory-managed environment, there is no need to implement a separate garbage collector.

In VisualAge for Java, the Java bytecode gets translated to Smalltalk bytecode and then executed by the Smalltalk environment. Smalltalk already is a memory-managed language, there is no need to implement a separate garbage collector.

In VMKit, both the VM and the garbage collector are written in C++.

In HotSpot, both the JVM and all 4 (or however many there currently are) garbage collectors are written in C++.

Jörg W Mittag