• Post Reply Bookmark Topic Watch Topic
  • New Topic

A doubt on JVM  RSS feed

 
rajaraman navaneethan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I understand that JVM is written in a platform dependent language like C.Does the JVM intrepret the bytecodes to convert them into machince code understandable by the hardware?


regards,
Raja
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I might be incorrect.

JVM is written in some language that can make use of system calls of OS(so we go for C).To allocate memory and stuffs like that.

So JVM doesn't need to convert the bytes codes to machine language , rather JVM interprets the byte codes and works according to the instructions.As OS interacts with the actual hardware ,so it takes the pain of make instructions in machine code.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The JVM can do both bytecode interpretation and compilation to native code. The decision which code to interpret and which code to compile is made at runtime, but generally, most of the code will be compiled.

While it's possible to run the JVM in a mode that only does bytecode interpretation and no compilation (the "-Xint" switch does that), this is many times slower than the default which does both.

You can find more information about this under the term HotSpot.
[ June 27, 2007: Message edited by: Ulf Dittmer ]
 
rajaraman navaneethan
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf Dittmer,Rahul,
Thanks for your replies.
Ulf, from your reply,

"The JVM can do both bytecode interpretation and compilation to native code. The decision which code to interpret and which code to compile is made at runtime, but generally, most of the code will be compiled."


Do you mean, that JVM can compile the .class file to native machine code?Can I compare this with microprocessor, opcode to mnemonics, similarly bytecodes(.class) to machine code?

regards,
Raja
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you mean, that JVM can compile the .class file to native machine code?

Yes.
Can I compare this with microprocessor, opcode to mnemonics, similarly bytecodes(.class) to machine code?

Not quite. The mnemonic maps to a CPU opcode one to one - it's just a human-readable name for it.

A JVM bytecode, on the other hand, can (and generally will) produce several (or even many) CPU instructions - it operates on a higher level. If you look at the JVM specification you'll see that bytecodes also have their own mnemonics.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!