aspose file tools*
The moose likes Java in General and the fly likes JVM (Bytecode to Machine Code) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "JVM (Bytecode to Machine Code)" Watch "JVM (Bytecode to Machine Code)" New topic
Author

JVM (Bytecode to Machine Code)

aryan sahu
Greenhorn

Joined: Oct 12, 2011
Posts: 11

can anyone please explain how does the jvm generate machine code of a particular processor family.i am quite confused how does it know if it is a AMD or Intel.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

aryan sahu wrote:can anyone please explain how does the jvm generate machine code of a particular processor family.i am quite confused how does it know if it is a AMD or Intel.

It is very straight-forward. From JVM perspective (and from most operations' perspective), there is no major difference between AMD and Intel, but I assume that you are aware of the fact that JVM is not platform independent (i.e. you cannot install JVM meant for 64 bit architecture on 32 bit processor).

So, JVM doesn't need to identify anything(because its not 'one JVM for all architectures' kind of thing).

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

It's very simple: The JIT (Just In Time) compiler, which is part of the JVM, converts Java bytecode to native machine code at runtime. At that moment it can detect the exact brand and model of the CPU that the program it is running on, so it can generate native machine code that is optimal for that particular CPU.

Note that both AMD and Intel x86-compatible CPUs implement the same instruction set, with minor differences. Newer processors often have enhancements, such as SSE instructions, etc.

When you use a traditional ahead-of-time compiler to compile for example C or C++ source code to native machine code, then the compiler can't make use of CPU-model specific enhancements, at least not if you want the resulting executable to be useable for most people. Suppose you'd compile the code with Intel Core-family specific enhanced native machine code, then it will not run on older CPUs that don't have those extra instructions.

An advantage of having a JIT is that it can (in principle) generate machine code with those extra instructions, since it knows exactly what the target CPU is at runtime - so it can optimize the code very specifically for that CPU.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
aryan sahu
Greenhorn

Joined: Oct 12, 2011
Posts: 11

Anayonkar Shivalkar wrote:
aryan sahu wrote:can anyone please explain how does the jvm generate machine code of a particular processor family.i am quite confused how does it know if it is a AMD or Intel.

It is very straight-forward. From JVM perspective (and from most operations' perspective), there is no major difference between AMD and Intel, but I assume that you are aware of the fact that JVM is not platform independent (i.e. you cannot install JVM meant for 64 bit architecture on 32 bit processor).

So, JVM doesn't need to identify anything(because its not 'one JVM for all architectures' kind of thing).

I hope this helps.


Thank you very much..
aryan sahu
Greenhorn

Joined: Oct 12, 2011
Posts: 11

Jesper de Jong wrote:It's very simple: The JIT (Just In Time) compiler, which is part of the JVM, converts Java bytecode to native machine code at runtime. At that moment it can detect the exact brand and model of the CPU that the program it is running on, so it can generate native machine code that is optimal for that particular CPU.

Note that both AMD and Intel x86-compatible CPUs implement the same instruction set, with minor differences. Newer processors often have enhancements, such as SSE instructions, etc.

When you use a traditional ahead-of-time compiler to compile for example C or C++ source code to native machine code, then the compiler can't make use of CPU-model specific enhancements, at least not if you want the resulting executable to be useable for most people. Suppose you'd compile the code with Intel Core-family specific enhanced native machine code, then it will not run on older CPUs that don't have those extra instructions.

An advantage of having a JIT is that it can (in principle) generate machine code with those extra instructions, since it knows exactly what the target CPU is at runtime - so it can optimize the code very specifically for that CPU.


Thank you very much. It is very informative.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JVM (Bytecode to Machine Code)