M.T
M.T

Reputation: 901

Does JVM interpret bytecode to assembly language

I am confused with jvm.
what does exactly jvm do takes bytycode and interpret to native code is native code assembly language?

Upvotes: 5

Views: 4204

Answers (3)

Vaibhavi Prajapati
Vaibhavi Prajapati

Reputation: 23

  • JVM isn't platform independent, instead JVM provides platform independent feature to Java code(byte code).
  • When byte code is generated after compiling your written code, it can be taken to any operating system for running it which is possible due to JVM (specific to OS) which converts the byte code into the machine language depending on the OS.
  • So, yes, bytecode(.class file) is converted to machine language (native code) by JVM by interpreting the bytecode.

Upvotes: 0

T.J. Crowder
T.J. Crowder

Reputation: 1074028

is native code assembly language?

Assembly language is a way of writing code that will be assembled (by an assembler) into machine code, which is what is written to executable files and such. That is, assembly code is source code for humans, just at a very low level; machine code is the result of running an assembler on that source code. (This is analogous to when you write a higher-level language like C++ and compile it to machine code with a compiler.)

what does exactly jvm do takes bytycode and interpret to native code

A JVM could be written that just interpreted bytecode, but modern JVMs don't do that; they have a built-in Just-In-Time Compiler (JIT) which takes the bytecode and, effectively, assembles it on the-fly into machine code. In fact, Sun's JVM has a two-stage JIT: One stage that runs really quickly (so apps and classes get converted to machine code quickly when run, to avoid startup delays), and another stage it kicks in that does aggressive optimization, which it uses when it identifies "hot spots" (code that runs a lot) in the code (so that performance-critical code runs quickly).

So modern JVMs read bytecode from .class files, run it through the JIT to compile it to machine code, and have the computer run that machine code. While doing that, a good one monitors hot spots and aggressively optimizes them, creating new, replacement machine code that's more efficient.

Upvotes: 11

Elliott Frisch
Elliott Frisch

Reputation: 201409

Native code (or machine code) is what assembly language is compiled into. Macros are expanded, and then mnemonic OP codes are translated into binary machine code. The JIT doesn't use macros, it generates machine code directly (without an assembler).

Upvotes: 8

Related Questions