Click here to Skip to main content
15,887,135 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: I wonder what will give me the best performance Pin
englebart12-Nov-23 5:00
professionalenglebart12-Nov-23 5:00 
GeneralRe: I wonder what will give me the best performance Pin
k505412-Nov-23 6:00
mvek505412-Nov-23 6:00 
GeneralRe: I wonder what will give me the best performance Pin
Jan Heckman12-Nov-23 21:01
professionalJan Heckman12-Nov-23 21:01 
GeneralRe: I wonder what will give me the best performance Pin
Cp-Coder13-Nov-23 0:42
Cp-Coder13-Nov-23 0:42 
GeneralRe: I wonder what will give me the best performance Pin
jweled13-Nov-23 1:35
jweled13-Nov-23 1:35 
GeneralRe: I wonder what will give me the best performance Pin
obermd13-Nov-23 3:43
obermd13-Nov-23 3:43 
GeneralRe: I wonder what will give me the best performance Pin
jschell13-Nov-23 7:19
jschell13-Nov-23 7:19 
GeneralRe: I wonder what will give me the best performance Pin
trΓΈnderen13-Nov-23 10:04
trΓΈnderen13-Nov-23 10:04 
jschell wrote:
obermd wrote:I checked jar files are compiled into machine executables on the first run

I don't believe so.
Unless Java has changed a lot the last few years, and I am quite sure it hasn't, you are right. But in the beginning, there was Java bytecode, and bytecode was interpreted directly. Just like the Pascal "P4" bytecode, which is said to be an essential inspiration for Java bytecode. I never heard of any compiler for Pascal P-code; it was always interpreted (as far as I know - correct me if I am wrong).

Bytecode is just like any other binary instruction set. 'Compiling' Java bytecode for, say, Aarch64 is functionally identical to compiling x86 binary code into Aarch64 binaries, except that x86 is so messy that it is no simple task Smile | :) . When Apple Mac switched from PPC to x64, lots of code was compiled from binary PPC to x64. PPC is far tidier than x86, so I guess that job was simpler.

A binary instruction set, whether a 'real' one or bytecode for a virtual machine, usually carry a minimum of 'why-information', limited to 'what-information'. If the compiler could know why so-and-so binary code was generated, it would have greater opportunities to generate more optimal code for the target machine. Or rather: It would be a lot easier. If you compare Java binary bytecode with .net IL (Intermediate Language), IL is not suitable for (or intended for) direct interpretation, but it contains a lot more of 'why-information', making it easier to generate optimal target code. .net IL has always been compiled to native code before execution.

When compilation of Java bytecode was introduced, the essential reason was to keep up to speed with .net, which claimed the same 'compile once, execute everywhere'. (For all directly compilation from source code to native code, noone expected interpretation of bytecode to be able to complete.) At about the same time, we also got Java compilers generating native code executables, rather than bytecode, to obtain maximum execution speed, but sacrifying the 'compile once, execute everywhere.
First of course it would not do that to a jar file.
If you refer to the compilation to add to the jar file, you are most certainly correct. The compiler could do like the .net IL compiler: It maintains a persistent cache (in the file system) of compiled assemblies. Before starting compilation of an assembly, the jitter ('Just-In-Time compiler') checks the cache for the assembly. If a compiled version of the assembly is found, it is used and the compilation cancelled.

When I last used Java actively, some years ago, the bytecode compiler did not maintain any similar cache of compiled modules. I have not heard of being introduced, but it might have been without me noticing. The bytecode-to-native is (/was) done at every execution of program, incrementally: The compilation was done once as module was taken into use. So there is no 'long' delay at program start. .net is similar: The IL-to-native compilation is not performed until an uncompiled method is called. (It is the method call itself that activates the jitter: As long as the method is uncompiled, the method is a stub that calls the jitter, which places the native compiled code in memory and patches up the code so that it for the next call goes directly to the native code rather than to the stub invoking the jitter.)

I have made informal timings trying to detect differences in startup time for the first run of a C# program modified so that a new jitter compiling was necessary, and successive runs. I have never managed to set up a program where any significant difference could be measured; the variation between the first execution and the following ten is not discernible.

Whether IL code or Java bytecode: The jitter's job is a small fraction of job of the source code compiler. I saw one statistic claiming that 70% of the (source code) compiler CPU time went to checking for syntactical and semantical errors. That part of the job is done; the jitter does next to zero additional error checking. It gets numbers in already-binary formats, strings with already-interpreted escapes. It doesn't look for code that can be moved out of loops, it doesn't look for dead code that can be removed, it doesn't handle defaulting of arguments. All of that is already done. So a jitter is fast.

If you were compiling and linking a multi-module program into a single executable module, you could do some optimizations not available when jitting. E.g. considering all involved assemblies, a flow analysis could tell you that for all possible calls of a given method in this composition of assemblies are made with arguments that causes a given if-statement to always take the 'false' path, so the 'true' path can be deleted as dead code, including the if-test (unless the test has other side effects). If you jitter the assembly into a cache, you never know which calls will be made to the method from other, yet unknown, assemblies.

As far as I know, compilers/linkers of today typically make quite restricted global flow analysis, nothing resembling that done by static code analyzers. So many of the optimizations a jitter is 'deprived of' is not done by the source compiler either, and it makes no real difference. Maybe tomorrow's compilers will do a more thorough flow analysis on/near the source code level.
GeneralRe: I wonder what will give me the best performance Pin
englebart13-Nov-23 7:27
professionalenglebart13-Nov-23 7:27 
GeneralRe: I wonder what will give me the best performance Pin
Shmoken9913-Nov-23 5:36
Shmoken9913-Nov-23 5:36 
GeneralRe: I wonder what will give me the best performance Pin
jschell13-Nov-23 7:22
jschell13-Nov-23 7:22 
GeneralVeterans Day PinPopular
Richard Andrew x6411-Nov-23 3:28
professionalRichard Andrew x6411-Nov-23 3:28 
GeneralRe: Veterans Day Pin
0x01AA11-Nov-23 7:36
mve0x01AA11-Nov-23 7:36 
GeneralRe: Veterans Day Pin
MSBassSinger13-Nov-23 5:43
professionalMSBassSinger13-Nov-23 5:43 
GeneralWordle 875 - 3 4 me Pin
pkfox10-Nov-23 21:07
professionalpkfox10-Nov-23 21:07 
GeneralRe: Wordle 875 - 3 4 me too Pin
Amarnath S10-Nov-23 22:00
professionalAmarnath S10-Nov-23 22:00 
GeneralRe: Wordle 875 Pin
Cp-Coder11-Nov-23 0:24
Cp-Coder11-Nov-23 0:24 
GeneralRe: Wordle 875 - 2! Pin
StarNamer@work11-Nov-23 1:19
professionalStarNamer@work11-Nov-23 1:19 
GeneralRe: Wordle 875 - 3 4 me Pin
Sander Rossel11-Nov-23 2:25
professionalSander Rossel11-Nov-23 2:25 
GeneralRe: Wordle 875 - 3 4 me Pin
GKP199211-Nov-23 4:55
professionalGKP199211-Nov-23 4:55 
GeneralWordle 875 4/6 Pin
jmaida11-Nov-23 11:55
jmaida11-Nov-23 11:55 
Generalworld 658 1/6 Pin
jmaida10-Nov-23 11:23
jmaida10-Nov-23 11:23 
GeneralSomething old, something new Pin
honey the codewitch10-Nov-23 10:20
mvahoney the codewitch10-Nov-23 10:20 
GeneralRe: Something old, something new Pin
Mike Hankey10-Nov-23 10:48
mveMike Hankey10-Nov-23 10:48 
GeneralRe: Something old, something new Pin
Mircea Neacsu10-Nov-23 14:30
Mircea Neacsu10-Nov-23 14:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.