• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

JIT Compiler

 
Ranch Hand
Posts: 238
1
Eclipse IDE Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have read that the JIT compiler converts the bytecode into the native platform code so that the execution becomes faster.But if this is the case,why is the JIT compiler used optionally?I mean,how does the JVM works if JIT compiler is turned OFF?how is the bytecode converted to machine code then?
 
Saloon Keeper
Posts: 7645
178
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's not - the bytecode is then interpreted by the JVM. The reason JIT-compiling is optional is that compiling does not take place automatically. Only if the JVM (or rather, its HotSpot compiler) determines that first compiling a method and then executing it natively, is faster than interpreting it, only then is it compiled. For example, methods that are only run once generally are not compiled to native code. So at any given time, the JVM runs a mix of native and interpreted code.
 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim! Nice explanation.
Learnt something new!
 
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
The JIT compiler is normally on; it's not some optional feature that you explicitly have to turn on to be able to use it.

It is possible to turn it off, but normally you don't want to do that. Reasons for turning it off might be for debugging, if you suspect that a bug in the JIT might be causing your program to run incorrectly. (This would be a very unlikely cause for your program not running correctly).
 
Ranch Hand
Posts: 33
1
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sudarshan,

I think you might know that JVMs can be implemented in various ways. It can be implemented in software for some OS, in web browser or in hardware in a chip which is designed to run java programs. If JVM is implemented in software, the java interpreter interprets the bytecode operations one at a time. For faster execution JIT is used.

Here, the first time a Java method is invoked, the bytecodes for the method are turned into native machine language for the host system. These operations are then cached so that subsequent invocations of a method are performed using the native machine instructions and the bytecode operations need not be interpreted all over again.

However there's a faster method exists. It is faster to run JVM on hardware on special java chip which executes Java Byte code operations as native code. Hence interpreter or a JIT compiler not required.
 
Tim Moores
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Debajyoti Kundu wrote:the first time a Java method is invoked, the bytecodes for the method are turned into native machine language for the host system.


This is not correct; please see the previous posts.

It is faster to run JVM on hardware on special java chip which executes Java Byte code operations as native code.


While that is a theoretical possibility, it plays no significant role in practice, though.
 
Debajyoti Kundu
Ranch Hand
Posts: 33
1
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:

Debajyoti Kundu wrote:the first time a Java method is invoked, the bytecodes for the method are turned into native machine language for the host system.


This is not correct; please see the previous posts.


How can you tell it's not correct? When you compile a java program for the first time the .class file is generated. Unless there's no change in your code, subsequent compilation don't perform any modification to the class file.

It is faster to run JVM on hardware on special java chip which executes Java Byte code operations as native code.


While that is a theoretical possibility, it plays no significant role in practice, though.


This is also not true. You can google JVM implementation in hardware or you can also refer virtual machine section of Galvin.

 
Tim Moores
Saloon Keeper
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Debajyoti Kundu wrote:How can you tell it's not correct? When you compile a java program for the first time the .class file is generated. Unless there's no change in your code, subsequent compilation don't perform any modification to the class file.


The statement of yours I quoted said nothing at all about compiling Java source code to class files - it said that a method is turned to native code when it is first executed, which is 100% false. You need to check your facts more carefully.

This is also not true. You can google JVM implementation in hardware or you can also refer virtual machine section of Galvin.


It is absolutely true. Please read carefully what I wrote: I didn't say that hardware implementations weren't possible or that they didn't exist; I said that they played an insignificant role in practice. Do you really want to dispute that statement?
 
Debajyoti Kundu
Ranch Hand
Posts: 33
1
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:

Debajyoti Kundu wrote:How can you tell it's not correct? When you compile a java program for the first time the .class file is generated. Unless there's no change in your code, subsequent compilation don't perform any modification to the class file.


The statement of yours I quoted said nothing at all about compiling Java source code to class files - it said that a method is turned to native code when it is first executed, which is 100% false. You need to check your facts more carefully.


Sorry for the confusion. By the word method i did not mean java method. I should save been more specific about it.

This is also not true. You can google JVM implementation in hardware or you can also refer virtual machine section of Galvin.


It is absolutely true. Please read carefully what I wrote: I didn't say that hardware implementations weren't possible or that they didn't exist; I said that they played an insignificant role in practice. Do you really want to dispute that statement?


I don't completely agree with this notion, as it is one of the most hot topic. Surely there it's implementation is not very wide but there are some good example like PicoJava

 
Don't sweat petty things, or pet sweaty things. But cuddle this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic