Is it possible for the same javac compiler to compile the same set of source files, but create class files of different checksums?

I tried to compare the results of this: (in ant)

<javac target="1.5" source="1.5" deprecation="on" fork="yes" optimize="true" debug="true" debuglevel="lines,vars,source"> <classpath> <fileset dir="${project.basedir}/../lib"> <include name="**/*.jar" /> <include name="**/*.zip" /> </fileset> </classpath> </javac> 

... against this: (in maven)

  <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <executions> <execution> <id>compile</id> <phase>compile</phase> <goals> <goal>compile</goal> </goals> <configuration> <target>1.5</target> <source>1.5</source> <debug>true</debug> <debuglevel>lines,vars,source</debuglevel> <showDeprecation>true</showDeprecation> <optimize>true</optimize> <fork>true</fork> <includes> ... </includes> </configuration> </execution> </executions> </plugin> 

... only to find that 2 of the resulting class files have slightly different checksums, and the rest are identical. I believe that multithreading plays a role, but the checksums created for any of the options seem consistent on repeated attempts. What can explain this result?

Update:

I looked at one set of files with different checksums using javap -verbose and noticed that the only difference is this:

 const #16 = class #108; // java/lang/Exception const #17 = Method #102.#109; // java/io/Writer.close:()V const #18 = Method #7.#109; // java/io/FileWriter.close:()V 

Unlike:

 const #16 = Method #102.#108; // java/io/Writer.close:()V const #17 = Method #7.#108; // java/io/FileWriter.close:()V const #18 = class #109; // java/lang/Exception 
+2
source share
2 answers

as you have shown, the difference lies in the generated persistent pool, which is really not a problem, but it is troubling because you expect the same output with the same compiler and parameters. I would argue that the compiler is called with java files in a different order between two situations, and the compilation order affects the result.

+2
source

I use a javac compiler and I find that it creates different resulting .class binaries depending on the order of the source files passed as a parameter. There are differences between maven and ant. The order of the files was not the same.

In any case, there were differences between the two compilations. I parsed the code and I found that javac (the optimizer?) Removes obsolete java jsr / ret assembly instructions from one of the compilations.

I don't know if this behavior was the result of an "implicit" compilation: http://docs.oracle.com/javase/1.5.0/docs/tooldocs/solaris/javac.html#searching

0
source

Source: https://habr.com/ru/post/911954/


All Articles