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

Use of LambdaMetafactory broken in Java 17 while working on Java 11 #4006

Closed
zakkak opened this issue Nov 11, 2021 · 6 comments
Closed

Use of LambdaMetafactory broken in Java 17 while working on Java 11 #4006

zakkak opened this issue Nov 11, 2021 · 6 comments
Assignees
Milestone

Comments

@zakkak
Copy link
Collaborator

zakkak commented Nov 11, 2021

Describe the issue

Applications using LambdaMetafactory.metafactory() fail to compile with java17-21.3.0 due to java.lang.Class.protectionDomain() being reached. The issue does not manifest with java11-21.3.0.

Steps to reproduce the issue

cd /tmp
git clone --branch avro-protectiondomain-java17 https://github.com/zakkak/issue-reproducers reproducers
cd reproducers
export JAVA_HOME=/opt/jvms/graalvm-ce-java17-21.3.0
mvn package
$JAVA_HOME/bin/native-image \
  --no-fallback -H:+ReportExceptionStackTraces \
  -jar target/reproducer-1.0-SNAPSHOT.jar
./reproducer-1.0-SNAPSHOT

Describe GraalVM and your environment:

  • GraalVM version: 21.3
  • JDK major version: 17
  • OS: Fedora 34
  • Architecture: AMD64

More details
Note: The provided reproducer is extracted from apache avro.

The build fails with:

Error: com.oracle.svm.hosted.substitute.DeletedElementException: Unsupported method java.lang.Class.protectionDomain() is reachable: The declaring class of this element has been substituted, but this element is not present in the substitution class
To diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The unsupported element is then reported at run time when it is accessed the first time.
Detailed message:
Trace: 
	at parsing java.lang.System$2.protectionDomain(System.java:2418)
Call path from entry point to java.lang.System$2.protectionDomain(Class): 
	at java.lang.System$2.protectionDomain(System.java:2418)
	at java.lang.invoke.MethodHandles$Lookup.lookupClassProtectionDomain(MethodHandles.java:2457)
	at java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2437)
	at java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClassAsLookup(MethodHandles.java:2420)
	at java.lang.invoke.MethodHandles$Lookup.defineHiddenClass(MethodHandles.java:2127)
	at java.lang.invoke.InnerClassLambdaMetafactory.generateInnerClass(InnerClassLambdaMetafactory.java:407)
	at java.lang.invoke.InnerClassLambdaMetafactory.spinInnerClass(InnerClassLambdaMetafactory.java:315)
	at java.lang.invoke.LambdaMetafactory.metafactory(LambdaMetafactory.java:341)
	at Main.main(Main.java:16)
	at com.oracle.svm.core.JavaMainWrapper.runCore(JavaMainWrapper.java:147)
	at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:183)
...
@munishchouhan
Copy link
Contributor

@zakkak thanks for reporting the issue, we will check it out and get back to you

@munishchouhan
Copy link
Contributor

@zakkak I am getting below, while trying to clone

github/4006$ git clone --branch avro-protectiondomain-java17 https://github.com/zakkak/issue-reproducers reproducers
Cloning into 'reproducers'...
fatal: Remote branch avro-protectiondomain-java17 not found in upstream origin

@zakkak
Copy link
Collaborator Author

zakkak commented Nov 16, 2021

@mcraj017 sorry for that. The clone command should now work!

@christianwimmer christianwimmer added this to the 22.0 milestone Dec 2, 2021
@zakkak zakkak added the Java17 label Feb 4, 2022
@vukzeka
Copy link

vukzeka commented Mar 25, 2022

hi @mcraj017 i see this is marked as milestone 22 but not sure when this one is expected to be released?

@jerboaa
Copy link
Collaborator

jerboaa commented Mar 25, 2022

@zakkak This seems fixed:

$ $JAVA_HOME/bin/native-image   --no-fallback -H:+ReportExceptionStackTraces   -jar target/reproducer-1.0-SNAPSHOT.jar
========================================================================================================================
GraalVM Native Image: Generating 'reproducer-1.0-SNAPSHOT'...
========================================================================================================================
[1/7] Initializing...                                                                                    (2.8s @ 0.19GB)
 Version info: 'GraalVM 22.0.0.2 Java 17 CE'
[2/7] Performing analysis...  [*******]                                                                 (11.2s @ 1.18GB)
   2,952 (74.62%) of  3,956 classes reachable
   3,825 (60.80%) of  6,291 fields reachable
  14,135 (45.04%) of 31,381 methods reachable
      28 classes,    30 fields, and   274 methods registered for reflection
      57 classes,    58 fields, and    51 methods registered for JNI access
[3/7] Building universe...                                                                               (1.0s @ 0.55GB)
[4/7] Parsing methods...      [*]                                                                        (0.8s @ 0.82GB)
[5/7] Inlining methods...     [****]                                                                     (0.9s @ 1.60GB)
[6/7] Compiling methods...    [***]                                                                      (9.1s @ 2.35GB)
[7/7] Creating image...                                                                                  (1.6s @ 0.39GB)
   4.84MB (36.91%) for code area:    8,587 compilation units
   7.07MB (53.90%) for image heap:   1,807 classes and 98,986 objects
   1.20MB ( 9.19%) for other data
  13.11MB in total
------------------------------------------------------------------------------------------------------------------------
Top 10 packages in code area:                               Top 10 object types in image heap:
 663.85KB java.util                                            1.97MB byte[] for general heap data
 358.79KB java.lang.invoke                                   861.03KB java.lang.String
 308.53KB java.lang                                          640.88KB java.lang.Class
 297.59KB jdk.internal.org.objectweb.asm                     534.91KB byte[] for java.lang.String
 286.97KB java.text                                          420.66KB java.util.HashMap$Node
 233.44KB java.util.regex                                    221.69KB java.util.HashMap$Node[]
 193.16KB com.oracle.svm.jni                                 159.97KB java.lang.String[]
 185.54KB java.util.concurrent                               154.78KB java.util.concurrent.ConcurrentHashMap$Node
 160.77KB com.oracle.svm.core.reflect                        143.73KB char[]
 145.47KB java.math                                          139.78KB sun.util.locale.LocaleObjectCache$CacheEntry
      ... 120 additional packages                                 ... 831 additional object types
                                           (use GraalVM Dashboard to see all)
------------------------------------------------------------------------------------------------------------------------
                        1.3s (4.4% of total time) in 18 GCs | Peak RSS: 3.50GB | CPU load: 6.55
------------------------------------------------------------------------------------------------------------------------
Produced artifacts:
 /home/sgehwolf/Documents/mandrel/bugs/upstream-graal/issue_4006_lambdametafactory/reproducers/reproducer-1.0-SNAPSHOT (executable)
 /home/sgehwolf/Documents/mandrel/bugs/upstream-graal/issue_4006_lambdametafactory/reproducers/reproducer-1.0-SNAPSHOT.build_artifacts.txt
========================================================================================================================
Finished generating 'reproducer-1.0-SNAPSHOT' in 28.6s.

Build issue is gone, but fails at runtime with

$ ./reproducer-1.0-SNAPSHOT 
java.lang.InternalError: com.oracle.svm.core.jdk.UnsupportedFeatureError: Defining hidden classes at runtime is not supported.
...

which seems similar to a JDK 11-based build:

$ ./reproducer-1.0-SNAPSHOT 
com.oracle.svm.core.jdk.UnsupportedFeatureError: Defining anonymous classes at runtime is not supported.
...

@zakkak
Copy link
Collaborator Author

zakkak commented Apr 6, 2022

Thanks for checking @jerboaa it looks like this falls under the invokedynamic Bytecode and Method Handles related limitations of native image, so I am closing this as the build error has been resolved and the actual test is not native-image compatible.

@zakkak zakkak closed this as completed Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants