Performance of direct buffer constructor

23 views
Skip to first unread message

Oscar Besga

unread,
Mar 27, 2025, 6:24:29 PMMar 27
to Netty discussions
Hi

We are planning to migrate our project from Java8 to Java11/17, while using netty (version 4.1.60)

We see that in Java8, 'direct buffer constructor' is available, where in Java11 is not.

We don't know if having this function disabled can impact performance, do you have any experience in this situation ?

Thanks

Oscar Besga

unread,
May 21, 2025, 5:02:33 AMMay 21
to Netty discussions
This is the debug log I'm having in my application, now executed under Java21 (compiled under Java11) with netty 4.1.60


2025-04-24 14:29:09,085 main DEBUG [i.n.u.i.PlatformDependent0:897] javaVersion0 | Java version: 21
2025-04-24 14:29:09,086 main DEBUG [i.n.u.i.PlatformDependent0:130] <clinit> | sun.misc.Unsafe.theUnsafe: available
2025-04-24 14:29:09,086 main DEBUG [i.n.u.i.PlatformDependent0:154] <clinit> | sun.misc.Unsafe.copyMemory: available
2025-04-24 14:29:09,087 main DEBUG [i.n.u.i.PlatformDependent0:192] <clinit> | java.nio.Buffer.address: available
2025-04-24 14:29:09,088 main DEBUG [i.n.u.i.PlatformDependent0:266] <clinit> | direct buffer constructor: unavailable
java.lang.NoSuchMethodException: java.nio.DirectByteBuffer.<init>(long,int)
        at java.base/java.lang.Class.getConstructor0(Class.java:3761)
        at java.base/java.lang.Class.getDeclaredConstructor(Class.java:2930)
        at io.netty.util.internal.PlatformDependent0$4.run(PlatformDependent0.java:237)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:319)
        at io.netty.util.internal.PlatformDependent0.<clinit>(PlatformDependent0.java:232)
        at io.netty.util.internal.PlatformDependent.isAndroid(PlatformDependent.java:294)
        at io.netty.util.internal.PlatformDependent.<clinit>(PlatformDependent.java:93)
        at io.netty.util.AsciiString.<init>(AsciiString.java:223)
        at io.netty.util.AsciiString.<init>(AsciiString.java:210)
        at io.netty.util.AsciiString.cached(AsciiString.java:1401)
        at io.netty.util.AsciiString.<clinit>(AsciiString.java:48)
        at io.grpc.netty.Utils.<clinit>(Utils.java:72)
        at io.grpc.netty.NettyChannelBuilder.<clinit>(NettyChannelBuilder.java:74)
        at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:37)
        at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:23)
        at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:39)
        at com.telefonica.m2m.common.grpc.client.GrpcConnection.<init>(GrpcConnection.java:31)
        at com.telefonica.m2m.common.grpc.client.GrpcConnection.<init>(GrpcConnection.java:25)
        at com.ericsson.m2m.components.udc.impl.client.UdcGrpcConnection.<init>(UdcGrpcConnection.java:21)
        at com.ericsson.m2m.components.udc.impl.client.UdcGrpcClient.createConnections(UdcGrpcClient.java:74)
        at com.ericsson.m2m.components.udc.impl.client.UdcGrpcClient.build(UdcGrpcClient.java:54)
        at com.ericsson.m2m.planner.server.PlannerMain.initialize(PlannerMain.java:1279)
        at com.ericsson.m2m.planner.server.PlannerMain.initializaPlanner(PlannerMain.java:3060)
        at com.ericsson.m2m.planner.server.PlannerMain.main(PlannerMain.java:1202)
2025-04-24 14:29:09,089 main DEBUG [i.n.u.i.PlatformDependent0:331] <clinit> | java.nio.Bits.unaligned: available, true
2025-04-24 14:29:09,094 main DEBUG [i.n.u.i.PlatformDependent0:393] <clinit> | jdk.internal.misc.Unsafe.allocateUninitializedArray(int): available
2025-04-24 14:29:09,094 main DEBUG [i.n.u.i.PlatformDependent0:403] <clinit> | java.nio.DirectByteBuffer.<init>(long, int): unavailable
2025-04-24 14:29:09,094 main DEBUG [i.n.u.i.PlatformDependent:1080] unsafeUnavailabilityCause0 | sun.misc.Unsafe: available

With this parameters in the launch configuration

"--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/sun.security.util=ALL-UNNAMED --add-opens java.base/sun.security.util.math=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.management/javax.management.openmbean=ALL-UNNAMED --add-opens java.management/javax.management=ALL-UNNAMED --add-opens java.xml/com.sun.org.apache.xerces.internal.impl.dv.util=ALL-UNNAMED --add-opens java.management/com.sun.jmx.remote.util=ALL-UNNAMED --add-opens java.base/sun.security.action=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true"

Is something I can do to avoid this problem ?
Thanks

Oscar Besga

unread,
May 21, 2025, 7:10:51 AMMay 21
to Netty discussions
For what I've gathered, my netty version is old; and there has been a change in the JVM method; so I should upgrade to netty 4.1/4.2 
(I can't at the moment but looking foward to it)

The more you know

Thank you, problem solved

Reply all
Reply to author
Forward
0 new messages