Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Java agent work with JDK 9+ #148

Merged
merged 1 commit into from
Nov 30, 2018
Merged

Make Java agent work with JDK 9+ #148

merged 1 commit into from
Nov 30, 2018

Conversation

dmitri-gb
Copy link
Contributor

Hi!

I would like to propose an alternative strategy for getting the lambda class bytes. Starting with JDK 9, class file transformers are not invoked for generated lambda classes anymore [1], which is the reason Retrolambda currently fails when run with Java 11 with the -javaagent option. This PR makes Retrolambda patch JDK's InnerClassLambdaMetafactory instead, getting the bytes directly from its spinInnerClass method. This way, one can run Retrolambda with both Java 8 as well as Java 11 (input classes must still be compiled to Java 8 of course).

The primary motivation for this change was to be able to run a Maven build with Java 11 (with --release 8 or -source 8 -target 8) and have the Retrolambda Maven plugin transform the classes to Java 6 bytecode, without needing to also have JDK 8 available and passing its path in the <java8home> plugin configuration option.

[1] http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-January/038199.html

Starting with JDK 9, class file transformers are not invoked for
generated lambda classes anymore [1]. This commit makes Retrolambda
patch JDK's InnerClassLambdaMetafactory instead, getting the bytes
directly from its spinInnerClass method. This way, one can run
Retrolambda with both Java 8 as well as Java 11 (input classes must
still be compiled to Java 8 of course).

[1] http://mail.openjdk.java.net/pipermail/core-libs-dev/2016-January/038199.html
@luontola
Copy link
Owner

Thanks for the PR.

Instead of the <java8home> option, you can also use the maven-toolchains-plugin. Though you'll still need JDK 8 installed on the machine.

        <plugin>
            <artifactId>maven-toolchains-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>toolchain</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <toolchains>
                    <jdk>
                        <version>1.8</version>
                    </jdk>
                </toolchains>
            </configuration>
        </plugin>

@luontola luontola merged commit f099ac0 into luontola:master Nov 30, 2018
@luontola
Copy link
Owner

This has been included in Retrolambda 2.5.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants