• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JVM (Bytecode to Machine Code)

 
Greenhorn
Posts: 11
Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
aryan sahu
Greenhorn
Posts: 11
Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 11
Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Yup, yup, yup. Tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic