Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Dirty Compiling

 
Ranch Hand
Posts: 126
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Friends,

I believed java supports Dirty Compiling(Where the class will be re-compiled only when the source has changed). But to my surprise I found it is compiling the sources each and every time we ask it to compile irrespective of whether it has changed or not.

Any reasons why Java does not support dirty Compilation ?

Cheers,

Nitin
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not SCJP. Moving to Java In General (Intermediate)
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nitin Dubey:
Hello Friends,

I believed java supports Dirty Compiling(Where the class will be re-compiled only when the source has changed). But to my surprise I found it is compiling the sources each and every time we ask it to compile irrespective of whether it has changed or not.

Any reasons why Java does not support dirty Compilation ?

Cheers,

Nitin



javac would compile all .java files specified on the command line, whether they are newer then the .class files or not.

There is a good reason for this, sometimes javac cannot correctly determine if a file needs to be recompiled, e.g. when it is referencing a static final of primitive type from a different class.
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The term you're looking for is "Incremental Compilation."

"Dirty Compiling" sounds like a now-forgotten movie starring Patrick Swayze and Ben Stein.
 
Nitin Dubey
Ranch Hand
Posts: 126
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hemal,

I didn't quite understand what you are trying to say. Can you give an example ?

Why do we think that javac should be concerned about the internal contents of the class. Can it not be done by comparing the last modified timestamp of .java and .class ? Obviously we cannot compare the actual timestamp of the class file but we can definately store the timestamp of the java file somewhere inside the file for further comparison.

Do you think it is possible ?

Cheers,

Nitin
 
Hemal Pandya
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nitin Dubey:
Hemal,

I didn't quite understand what you are trying to say. Can you give an example ?

Why do we think that javac should be concerned about the internal contents of the class. Can it not be done by comparing the last modified timestamp of .java and .class ? Obviously we cannot compare the actual timestamp of the class file but we can definately store the timestamp of the java file somewhere inside the file for further comparison.

Do you think it is possible ?

Cheers,

Nitin



Create the following three files. Now compile and run Main.java, as follows.
javac Main.java
java Main

Now modify Settings.java and make DEBUG false.
Compile and run again:
javac Main.java
java Main

Notice that Worker.foo is still using the old value (true) of Settings.DEBUG. This is because compile time constants get inlined in the client classes. Now, compile everything and run:
javac *.java
java Main

And note that the debug output no longer appears in the output. This is because *.java forced Worker.java to be recompiled. When we compiled Main.java, javac did not realize that Worker.java needs to be recompiled.

hth.

 
Nitin Dubey
Ranch Hand
Posts: 126
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hemal,

The example shows us that if java compiler finds a class file then it will not re-compile the source. Nothing special about dirty compilation. However I still believe we can achieve Dirty Compilation in the following manner:

CASE #1
Somewhere in Java compiler. (Present Implementation)

if Main.class is not found
compile Main.java
end if

exec main() from Main.class

CASE #2
If header for class file is modified to keep the timestamp of respective Java file. The following condition
will be executed for all the class files referenced within Main.java.

if Main.class is not found
OR
(Main.class is found
AND TIMESTAMP in Main.class header != Last Modified Timestamp of Main.java)
compile Main.java
end if

exec main() from Main.class

Cheers,

Nitin
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ernest Friedman-Hill:
The term you're looking for is "Incremental Compilation."

"Dirty Compiling" sounds like a now-forgotten movie starring Patrick Swayze and Ben Stein.


And I thought it was an AC/DC song!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic