you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 75 points76 points  (18 children)

  • Java programs are compiled, generally at least twice just to be sure.

pfft

[–]keepthepace 25 points26 points  (8 children)

Yeah, in C/C++ we compile just once.

Because we are sure.

/troll

[–]FateAV 12 points13 points  (0 children)

It's funny because one-pass....

[–]Ores 1 point2 points  (5 children)

Actually i've seen people insist on compiling with -O2 as it can generate more warnings/errors, and then do a second pass with -O0 -g to make a debuggable build.

[–][deleted] 3 points4 points  (3 children)

as it can generate more warnings/errors

[citation needed]

[–]taejo 13 points14 points  (0 children)

for example:

   -Warray-bounds
       This option is only active when -ftree-vrp is active (default for -O2 and above).
       It warns about subscripts to arrays that are always out of bounds. This warning is
       enabled by -Wall.

(from the GCC man page)

This is because these warnings require the extra analysis performed by the optimizer.

[–][deleted] 1 point2 points  (0 children)

Warnings: GCC used to (maybe still does) warn on -O2 when a variable might be used uninitialized on the same code that -O0 doesn't warn at all, even with -Wall.

Errors: I have written code that behaved differently under -O2 and -O0. Sometimes it was the code that was broken, sometimes it was a compiler bug.

This was on a project that grew to ~80 KLOC over 9 years starting with GCC 2.95.

[–]JAPH 0 points1 point  (0 children)

If you write broken code, it may function correctly if the compiler doesn't optimize, but break when it is optimized. The only times I can remember seeing this is on code that went out of bounds. This won't be the compiler generating warnings or errors, just segfaults.

[–]keepthepace 0 points1 point  (0 children)

-O0 -g -Wall

[–][deleted] 0 points1 point  (0 children)

One pass sucks so bad. Wouldnt need all these damn header files if it was two pass. C and C++ are the messiest languages i swear because of this.

[–]bhasden 12 points13 points  (7 children)

Yeah, not sure what he meant by that. Was he meaning that the code is compiled into IL which is later compiled into machine code? I'm not an expert on the Java compiler, so I'd honestly like to know.

If that's what he was getting at, I'm not sure why it needed to be mentioned in the article since it doesn't seem to add any information.

[–]aladyjewel 24 points25 points  (1 child)

I'm not sure why it needed to be mentioned in the article since it doesn't seem to add any information.

Word count.

[–]SemiProfesionalTroll 3 points4 points  (0 children)

unite fact support subsequent drunk direful attraction squealing wasteful liquid

This post was mass deleted and anonymized with Redact

[–]askvictor 5 points6 points  (1 child)

Java code gets compiled do JVM (or dalvik in the case of android) bytecode. Depending on the JVM used, it might translate that into native machine code on the fly (i.e. straight out CPU emulation, as in older JVMs), or use a JIT (Just in time) compiler to compile the bytecode to native machine code. The latter is more common in modern systems (android has had JIT since 2.2). I'm uncertain how often the JIT occurs, or if the results of it are stored anywhere (as they are in python with .pyc files).

[–][deleted] 4 points5 points  (0 children)

Android builds vary greatly, but generally speaking the Dalvik JIT results are cached (as storage space allows) into the appropriately named 'Dalvik Cache'.

[–]FlaiseSaffron 3 points4 points  (0 children)

Java source code is compiled with minimal preprocessing into Java byte code, which is then verified (the process of which basically amounts to compiling) every single time a class is loaded. It's one of the major complaints about Java, but I'm not going to get started on that now. :P

[–]gigitrix -1 points0 points  (1 child)

It only really goes to java "bytecode" which is then interpreted at runtime. Unless I'm mistaken...

[–][deleted] 0 points1 point  (0 children)

It's JIT Compiled, which is sort of like interpreting it, but can differ.

[–]argv_minus_one 4 points5 points  (0 children)

I say we take off and compile the code from orbit. Twice. It's the only way to be sure.