-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[GR-45893] jdk.net.ExtendedSocketOptions.TCP_KEEPIDLE not available in native-image application #6457
Comments
I added some more output to my repro application, which better explains the current behaviour and points more to a bug: AsynchronousSocketChannel socket = AsynchronousSocketChannel.open();
Set<SocketOption<?>> options = socket.supportedOptions();
System.out.println("Has TCP_KEEPIDLE (obj)? " + options.contains(jdk.net.ExtendedSocketOptions.TCP_KEEPIDLE));
System.out.println("Has TCP_KEEPIDLE (string)? " + options.stream().anyMatch(s -> s.name().equals(jdk.net.ExtendedSocketOptions.TCP_KEEPIDLE.name())));
System.out.println("Options: " + options);
SocketOption<?> so = options.stream().filter(s -> s.name().equals(jdk.net.ExtendedSocketOptions.TCP_KEEPIDLE.name())).findFirst().get();
System.out.println("Constant identity: " + System.identityHashCode(jdk.net.ExtendedSocketOptions.TCP_KEEPIDLE));
System.out.println("Set identity: " + System.identityHashCode(so));
socket.setOption(jdk.net.ExtendedSocketOptions.TCP_KEEPIDLE, 100); The code above produces the following output when run on the JVM:
In a native-image it produces the following output:
As you can see there exist two object instances for |
Thank you for reporting this, This is tracked internally on GR 45893 |
Hey, just wanted to ask if there is any update on this issue? |
Because one instance was created at build-time, and the other at run-time. More specifically, it is
If you want to try this out now, you need to build Native Image from source with my patch. Soon after #7440 is merged, the latest dev build will ship the fix. Hope this helps! -- Fabio |
Awesome! Thanks for looking into this :) |
Yes, I believe you can use <buildArgs>
<buildArg>--initialize-at-run-time=sun.nio.ch.AsynchronousSocketChannelImpl$DefaultOptionsHolder</buildArg>
</buildArgs> |
Removes previous workaround and replaces it with workaround suggested in oracle/graal#6457
Thanks, yes this works! |
Removes previous workaround and replaces it with workaround suggested in oracle/graal#6457
Removes previous workaround and replaces it with workaround suggested in oracle/graal#6457
I am facing issues using
jdk.net.ExtendedSocketOptions.TCP_KEEPIDLE
in native images. The following code runs fine on a JVM, but fails in a native image:Error in native-image:
The class
jdk.net.ExtendedSocketOptions
registers some platform-dependent optionally available socket options. All of this is orchestrated bysun.net.ext.ExtendedSocketOptions
, which dynamically loadsjdk.net.ExtendedSocketOptions
if available.jdk.net.ExtendedSocketOptions
then performs initialization of these additional options in a static code block.For some reason, this static code block is not properly executed in the native-image. I know about build-time initialization of classes in native-images, but do not fully understand if this has an impact here.
To enable dynamic lookup of
jdk.net.ExtendedSocketOptions
I also put the following information into areflect-config.json
:Below I have provided a simple application to reproduce the issue. There I have provided additional debug output, which checks the conditions that check some boundary conditions for the exception to occur:
Interestingly this produces the following output in a native-image:
Notice that the
contains
check evaluates to false, however the stringified options DO INCLUDETCP_KEEPIDLE
. Maybe this helps in finding the issue. My guess is this has something to do with build-time class initialization and code optimization, but I don't fully understand this behaviour.Steps to reproduce the issue
Please include both build steps as well as run steps
mvn native:compile
java -jar target/tcp-keepaliveidle-0.0.1-SNAPSHOT.jar
-> workstarget/tcp-keepaliveidle
-> failsDescribe GraalVM and your environment:
OpenJDK 64-Bit Server VM GraalVM CE 17.0.7-dev+4.1 (build 17.0.7+4-jvmci-23.0-b10, mixed mode, sharing)
17
The text was updated successfully, but these errors were encountered: