JDK-8080656 : javac 1.8 very slow with nested generics expressions
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8u45
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-05-05
  • Updated: 2015-06-10
  • Resolved: 2015-06-09
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Javac 1.8 compiler is running very slow when sompiling a class with several generic methods.
The compilation of the class from the test case takes 11 seconds. 
Adding one additional generic method like this
 public static <T> PropertyValue<T> with(Property<T> property, Donor<T> valueDonor) {
        return null;
    }
increases compilation time by a factor of 5!
Adding additional type parameter to some of the methods also increases the compilation time by a single-digit factor.

Compilation of the same code using language level of 1.7 takes less than one second.

In a real project (like mine) after migration from 1.7 to 1.8 language level the compilation takes more than 15 minutes per class.

ADDITIONAL REGRESSION INFORMATION: 
Using 1.7 language level compilation of the same class takes less than one second:
javac -source 1.7 src/main/java/frol/NestedExpressionBug_011.java

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile provided test class:
javac NestedExpressionBug_011.java


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Compilation takes less than one second on Intel Xeon CPU E3-1240 @ 3.40 GHz

ACTUAL -
Compilation takes more than 10 seconds on Intel Xeon CPU E3-1240 @ 3.40 GHz

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package frol;

import java.util.List;

/**
 * Compilation takes 11 Seconds.
 */
public class NestedExpressionBug_011 {
    public interface PropertyLookup<T> {}
    public interface Instantiator<T> {}
    public class Property<T> {}
    public class PropertyValue<T> {}
    public interface Donor<T> {}
    public class Maker<T> implements PropertyLookup<T>, Donor<T> {}

    public static <T> T make(Maker<T> maker) {
        return null;
    }

    public static <T> Maker<T> a(Instantiator<T> instantiator, PropertyValue... propertyProviders) {
        return null;
    }

    public static <T> PropertyValue<T> with(Property<T> property, T value) {
        return null;
    }

    public static <T> Donor<List<T>> listOf(final Donor... donors) {
        return null;
    }
    public void setUp() {
        make(
                a(null,
                        with((Property<Object>) null,
                                listOf(a(null,
                                        with((Property<Object>) null,
                                                listOf(a(null,
                                                        with(
                                                                (Property<Object>) null,
                                                                listOf(
                                                                        a(null,
                                                                                with((Property<Object>) null,
                                                                                        (List<Object>) null
                                                                                ))
                                                                )
                                                        )))
                                        )))
                        )
                ));

    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
package frol;



import java.util.List;

/**
 * Compilation takes 1 second.
 */
public class NestedExpressionBug_011_workaround {
    public interface PropertyLookup<T> {}
    public interface Instantiator<T> {}
    public class Property<T> {}
    public class PropertyValue<T> {}
    public interface Donor<T> {}
    public class Maker<T> implements PropertyLookup<T>, Donor<T> {}

    public static <T> T make(Maker<T> maker) {
        return null;
    }

    public static <T> Maker<T> a(Instantiator<T> instantiator, PropertyValue... propertyProviders) {
        return null;
    }

    public static <T> PropertyValue<T> with(Property<T> property, T value) {
        return null;
    }

    public static <T> Donor<List<T>> listOf(final Donor... donors) {
        return null;
    }
    public void setUp() {

        Maker<Object> maker = a(null,
                with((Property<Object>) null,
                        (List<Object>) null
                ));

        Donor<List<Object>> listDonor = listOf(a(null,
                with(
                        (Property<Object>) null,
                        listOf(
                                maker
                        )
                )));

        make(
                a(null,
                        with((Property<Object>) null,
                                listOf(a(null,
                                        with((Property<Object>) null,
                                                listDonor
                                        )))
                        )
                ));

    }
}


SUPPORT :
YES


Comments
This is a duplicate of JDK-8051946 with fix targeted for JDK 9 build.
09-06-2015

Please see JDK-8051946.
09-06-2015

1. Run the attached test case NestedExpressionBug_011.java in Windows 7 2. Checked this for JDK 7u80, 8u45, 8u60 ea b17 and 9 ea b67. 3. The code compiles quickly within a second in JDK 7u80, however with JDK 8u45, 8u60 ea b17 and 9 ea b67 it take more then 20 seconds. Moving this up for further evaluation.
09-06-2015