johnny
johnny

Reputation: 19755

Are JVM implemented languages like Jython using Java underneath or are they using the JVM native?

In a language that uses the JVM, say Jython, JRuby or any language that isn't Java specifically, is Java the language being used "underneath" somewhere?

Does the implementation mean:

Language Ported to use the JVM + Java somewhere + JVM?

For example, was Jython written in Java or does it using something else to utilize the JVM?

Upvotes: 4

Views: 144

Answers (2)

ljleppan
ljleppan

Reputation: 366

No, they do not (in the general case) compile down to Java.

For example Jython compiles python to Java bytecode that is then run on the JVM. This is the same bytecode Java compiles to, as does JRuby. While it is true that both Jython and JRuby are themselves largely written in Java, the actual python/Ruby program being run is not compiled to Java but instantly to Java bytecode.

Upvotes: 3

the8472
the8472

Reputation: 43150

It depends.

Part of language's standard library may be implemented in java. Ditto for the compiler/interpreter. Other parts that are not essential for bootstrapping may even be written in the language itself.

The user code itself initially may be run through an interpreter but later compiled to bytecode. Additionally the generated bytecode may be optimized further based on type profiles gathered during runtime. And the bytecode may bail out back to the interpreter if some of its assumptions are invalidated. This is analogous - albeit at a higher abstraction level - to hotspot's interpreter/c1/c2 tiers and many other JIT environments.

But interpreter+JIT is just one possible approach. Scala for example is AOT-compiled to bytecode.

And they may also use C bindings to implement functions of the respective language's standard library that have no 1:1 mapping to the JDK standard library.

Upvotes: 5

Related Questions