Suresh S
Suresh S

Reputation: 61

Garbage collection implementation

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

Upvotes: 6

Views: 3379

Answers (5)

Jörg W Mittag
Jörg W Mittag

Reputation: 369458

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++.

Upvotes: 8

jasonmp85
jasonmp85

Reputation: 6817

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.

Upvotes: 2

Jesper
Jesper

Reputation: 206816

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.

Upvotes: 1

polygenelubricants
polygenelubricants

Reputation: 383746

The JVM can be implemented in any language, but Sun's HotSpot is written in C/C++ and assembly.

See also

  • Frequently Asked Questions about Garbage Collection in the HotspotTM JavaTM Virtual Machine
  • OpenJDK/The HotSpot Group

    The HotSpot code base has been worked on by dozens of people, over the course of 10 years, so far. (That's good and bad.) It's big. There are nearly 1500 C/C++ header and source files, comprising almost 250,000 lines of code. In addition to the expected class loader, bytecode interpreter, and supporting runtime routines, you get two runtime compilers from bytecode to native instructions, 3 (or so) garbage collectors, and a set of high-performance runtime libraries for synchronization, etc.

Upvotes: 7

Bozhidar Batsov
Bozhidar Batsov

Reputation: 56595

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

Upvotes: 3

Related Questions