Call RetroLambda during AOT compilation jdk8
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Sat, 13 Sep 2014 16:11:42 +0200
branchjdk8
changeset 16843238bffeaf12
parent 1683 17f95ced156b
child 1685 35e68f37ca88
Call RetroLambda during AOT compilation
rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java
rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/RetroLambda.java
rt/vm8/pom.xml
     1.1 --- a/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java	Sat Sep 13 15:41:35 2014 +0200
     1.2 +++ b/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/Bck2BrwsrJars.java	Sat Sep 13 16:11:42 2014 +0200
     1.3 @@ -18,6 +18,7 @@
     1.4  package org.apidesign.bck2brwsr.aot;
     1.5  
     1.6  import java.io.BufferedReader;
     1.7 +import java.io.ByteArrayInputStream;
     1.8  import java.io.File;
     1.9  import java.io.FileInputStream;
    1.10  import java.io.IOException;
    1.11 @@ -199,6 +200,11 @@
    1.12  
    1.13          @Override
    1.14          public InputStream get(String name) throws IOException {
    1.15 +            byte[] arr = converted.get(name);
    1.16 +            if (arr != null) {
    1.17 +                return new ByteArrayInputStream(arr);
    1.18 +            }
    1.19 +            
    1.20              Enumeration<URL> en = Bck2BrwsrJars.class.getClassLoader().getResources(name);
    1.21              URL u = null;
    1.22              while (en.hasMoreElements()) {
    1.23 @@ -227,7 +233,7 @@
    1.24                              if (res.equals(n)) {
    1.25                                  found = true;
    1.26                              }
    1.27 -                            assert res.endsWith(".class");
    1.28 +                            assert res.endsWith(".class") : "Wrong resource: " + res;
    1.29                              converted.put(res, bytes);
    1.30                              classes.add(res.substring(0, res.length() - 6));
    1.31                          }
     2.1 --- a/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/RetroLambda.java	Sat Sep 13 15:41:35 2014 +0200
     2.2 +++ b/rt/aot/src/main/java/org/apidesign/bck2brwsr/aot/RetroLambda.java	Sat Sep 13 16:11:42 2014 +0200
     2.3 @@ -47,9 +47,8 @@
     2.4      public void saveIfLambda(String className, byte[] bytecode) {
     2.5          if (LambdaReifier.isLambdaClassToReify(className)) {
     2.6              try {
     2.7 -                System.out.println("Saving lambda class: " + className);
     2.8                  byte[] backportedBytecode = LambdaClassBackporter.transform(bytecode, Opcodes.V1_7);
     2.9 -                putBytecode(className, backportedBytecode);
    2.10 +                putBytecode(className + ".class", backportedBytecode);
    2.11              } catch (Throwable t) {
    2.12                  // print to stdout to keep in sync with other log output
    2.13                  throw new IllegalStateException("ERROR: Failed to backport lambda class: " + className);
    2.14 @@ -58,6 +57,7 @@
    2.15      }
    2.16  
    2.17      private void putBytecode(String className, byte[] backportedBytecode) {
    2.18 +        assert className.endsWith(".class") : "Full resource: " + className;
    2.19          if (converted == null) {
    2.20              converted = new HashMap<>();
    2.21          }
    2.22 @@ -84,6 +84,8 @@
    2.23              if (!Arrays.equals(newB, byteCode)) {
    2.24                  putBytecode(className, newB);
    2.25              }
    2.26 +        } catch (Throwable t) {
    2.27 +            t.printStackTrace();
    2.28          } finally {
    2.29              Thread.currentThread().setContextClassLoader(prev);
    2.30          }
    2.31 @@ -106,6 +108,9 @@
    2.32              if (c != null) {
    2.33                  return c;
    2.34              }
    2.35 +            if (name.startsWith("java.")) {
    2.36 +                return super.loadClass(name);
    2.37 +            }
    2.38              String r = name.replace('.', '/') + ".class";
    2.39              try (InputStream is = res.get(r)) {
    2.40                  if (is == null) {
     3.1 --- a/rt/vm8/pom.xml	Sat Sep 13 15:41:35 2014 +0200
     3.2 +++ b/rt/vm8/pom.xml	Sat Sep 13 16:11:42 2014 +0200
     3.3 @@ -29,21 +29,6 @@
     3.4                      </systemProperties>
     3.5                  </configuration>
     3.6              </plugin>
     3.7 -            <plugin>
     3.8 -                <groupId>net.orfjackal.retrolambda</groupId>
     3.9 -                <artifactId>retrolambda-maven-plugin</artifactId>
    3.10 -                <version>1.5.0</version>
    3.11 -                <executions>
    3.12 -                    <execution>
    3.13 -                        <goals>
    3.14 -                            <goal>process-test</goal>
    3.15 -                        </goals>
    3.16 -                    </execution>
    3.17 -                </executions>
    3.18 -                <configuration>
    3.19 -                    <target>1.8</target>
    3.20 -                </configuration>
    3.21 -            </plugin>
    3.22          </plugins>
    3.23      </build>
    3.24      <dependencies>