Is there a difference in compilers - java

Are there any differences in code optimization made in the same versions: Oracle Java Compiler Java Apache Compiler IBM Java Compiler OpenJDK Java Compiler. Should any code demonstrate various optimizations? Or do they use the same compiler? If there are no known differences in optimization, where can I find resources on how to test compilers for different optimizations?

+4
source share
3 answers

Are there any differences in code optimization performed by the same versions: Oracle Java compiler Apache Java compiler IBM Java compiler OpenJDK Java compiler.

Although the compiler may be completely different, it javachardly optimizes. The main optimization is constant insertion, and this is indicated in JLS and, thus, is standard (except for any errors)

If some code demonstrates various optimizations?

You can do it.

final String w = "world";
String a = "hello " + w;
String b = "hello world";
String c = w;
String d = "hello " + c;
System.out.prinlnt(a == b); // these are the same String
System.out.prinlnt(c == b); // these are NOT the same String

In the first case, the constant was embedded and the string was merged at compile time. In the second case, concatenation was performed at run time and a new line was created.

Or do they use the same compiler?

No, but 99% of the optimizations are performed during JIT execution, so they are the same for this version of the JVM.

, ?

, , . , JIT , , JIT . JVM, .

+3

, . , , .

public class Test {
    public static void main(String[] args) {
        int x = 1L;  // <- this cannot compile
    }
}

java-, , .

eclipse java ECJ, , ( , , ECJ, , ), .

public static void main(String[] paramArrayOfString)
{
    throw new Error("Unresolved compilation problem: \n\tType mismatch: cannot convert from long to int.\n");
}

, 2 . .

P.S: .

+3

, , javac (, , ) Eclipse.

Java ( ) , Eclipse , . . :

  • Eclipse, -, , , . ( ?) , , . , javac ; . , , switch. (, , ), . (, inlining), , . , , JIT. (grrr).

  • javac. , , , . , JIT, , , javac.

0
source

All Articles