How to add a garbage collector of an older version to a JRE of newer version

I was asked a question as below in a recent interview.

How to add a garbage collector of an older version to a JRE of newer version

Couldn't get a proper answer from internet. Can anyone explain this to me?

Thanks in advance

Jon Skeet
people
quotationmark

You can't. The garbage collector is part of the JVM, and can't just be moved around. If you have the source code for both you could consider trying to patch the collector back in - but it would probably be a very large task, and I'd be incredibly wary of the reliability of the result... other bits of the JVM may well depend on assumptions about the garbage collectors available.

Assuming these are different versions of the same VM, I'd expect a garbage collector only to be retired if the available ones were superior in most ways, so I don't expect you'd get significant benefit anyway - at least outside some very specialized situations.

(I'm glad that this was just an interview question rather than a real life situation. Although as Jigar says, maybe they weren't actually thinking of adding a particular collector to a VM that didn't really support it. Either way, it seems like a pretty bizarre interview question.)

people

See more on this question at Stackoverflow