From 4ec6db48dd63463cdb4d23eb40c76e9bd5bcf311 Mon Sep 17 00:00:00 2001 From: Codrut Stancu Date: Mon, 7 Oct 2019 09:10:46 +0300 Subject: [PATCH] Register sun.nio.ch.SelectorImpl fields for unsafe access. (#9631) Motivation: On JDK > 9 Netty uses Unsafe to write two internal JDK fields: sun.nio.ch.SelectorImp.selectedKeys and sun.nio.ch.SelectorImpl.publicSelectedKeys. This is done in transport/src/main/java/io/netty/channel/nio/NioEventLoop.java:225, in openSelector() method. The GraalVM analysis cannot do the Unsafe registration automatically because the object field offset computation is hidden behind two layers of calls. Modifications: This PR updates the Netty GraalVM configuration by registering those fields for unsafe access. Result: Improved support for Netty on GraalVM with JDK > 9. --- .../native-image/io.netty/transport/reflection-config.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/transport/src/main/resources/META-INF/native-image/io.netty/transport/reflection-config.json b/transport/src/main/resources/META-INF/native-image/io.netty/transport/reflection-config.json index 929eb40be8..1ebbb43dc0 100644 --- a/transport/src/main/resources/META-INF/native-image/io.netty/transport/reflection-config.json +++ b/transport/src/main/resources/META-INF/native-image/io.netty/transport/reflection-config.json @@ -4,5 +4,12 @@ "methods": [ { "name": "", "parameterTypes": [] } ] + }, + { + "name": "sun.nio.ch.SelectorImpl", + "fields": [ + { "name": "selectedKeys", "allowUnsafeAccess" : true}, + { "name": "publicSelectedKeys", "allowUnsafeAccess" : true} + ] } ]