0

How can we run a Java or C# program without JIT help?

pseudocode:

for(int i=0; i<100; i++)
{
    // open file in append mode
    // remove last line
    // add a line
    // close the file
    // if any exception occurs, continue with next iteration
}

How to compare the performance of this program when JIT is enabled/disabled?

Azodious
  • 13,752
  • 1
  • 36
  • 71
  • 1
    **Moderator note** *There was no way I could surgically remove comments that were more noise than signal without leaving a completely broken conversation in my wake. Subsequently, comments under this question have been purged. If you want to have a constructive conversation about this question, please use chat. If you have constructive and friendly questions or points, feel free to post them here. The key words are constructive and friendly.* – Tim Post Feb 22 '12 at 10:30

4 Answers4

5

It is not possible to run .NET code without a JIT, even with Mono (its bytecode interpreter is not supported any more).

It is possible to turn the JIT off for many JVM implementations, e.g., -Xint for Sun JVM.

SK-logic
  • 9,605
  • 1
  • 23
  • 35
3

In .Net you can run a program without jit only by pre compiling the intermediate language to the target machine specific code first. NGen is a tool that does this for .net.

According to this post you can use GCJ to do something similar for java:

GCJ (the GNU Java compiler) can compile .class files into executable objects which can then be linked into a .exe file, or even C++ files. Of course, the final exe / library will end up with GC & Java runtime (statically / dynamically linked .LIB) dependencies.

Sam Holder
  • 32,535
  • 13
  • 101
  • 181
  • If i understand it correct, @Azodious wants to run the CIL in the .NET virtual machine (as opposed to compiling CIL to machine-specific code first and natively executing compiled code second). Your message is on the completely different matter: **when** there will be CIL to machine-specific code compilation (made in advance by NGen or on first run with JIT compiler). – penartur Feb 15 '12 at 09:30
  • @penartur on second reading maybe you are right... In which case the answer for .net is that you can't :) – Sam Holder Feb 15 '12 at 09:33
  • Isn't the jit deactivated/pretty limited if you start the code under the debugger? There's a pretty big difference between the produced code when starting it under the debugger, compared to attaching the debugger to the running process. – Voo Feb 16 '12 at 18:58
1

The Oracle JVM accepts -Djava.compiler=NONE to disable the JIT (-D sets the system property, java.compiler is the property name, NONE is the value). No idea about .Net (C#).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
1

When code is first run it is interpreted. Only after it has been run many times (typically 10,000) does it get compiled. For CPU intensive tasks this can make a big difference. However, for IO intensive tasks, the OS and the hardware you have make much more difference.

So for a loop of only 100, you can be sure it won't be compiled to native code, whether you enable the compiler or not. For an IO intensive task (and open/closing a file is very expensive) whether the code is compiled or not makes such a small difference you will have trouble measuring it.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130