reactor / reactor-netty

TCP/HTTP/UDP/QUIC client/server with Reactor over Netty

Home Page:https://projectreactor.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Classes that should be initialized at run time got initialized during image building: io.netty.buffer.UnpooledDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.UnpooledDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledDirectByteBuf io.netty.buffer.AbstractReferenceCountedByteBuf the

1ssqq1lxr opened this issue · comments

jdk21 graalvm native image build error

Expected Behavior

jdk21 graalvm native image build success

Actual Behavior

Error: Classes that should be initialized at run time got initialized during image building:
 io.netty.buffer.UnpooledDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.UnpooledDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledDirectByteBuf
io.netty.buffer.AbstractReferenceCountedByteBuf the class was requested to be initialized at run time (from 'META-INF\native-image\io.netty\netty-buffer\native-image.properties' in 'file:///E:/jt808-netty-master/jdk21Test/target/libs/netty-buffer-4.1.100.Final.jar' with 'io.netty.buffer.AbstractReferenceCountedByteBuf' and from 'META-INF\native-image\io.netty\netty-buffer\native-image.properties' in 'file:///E:/jt808-netty-master/jdk21Test/target/jdk21Test-1.0-SNAPSHOT.jar' with 'io.netty.buffer.AbstractReferenceCountedByteBuf' and from 'META-INF\native-image\io.netty\netty-buffer\native-image.properties' in 'file:///E:/maven-jar/io/netty/netty-buffer/4.1.100.Final/netty-buffer-4.1.100.Final.jar' with 'io.netty.buffer.AbstractReferenceCountedByteBuf' and from command line with 'io.netty.buffer.AbstractReferenceCountedByteBuf'). To see why io.netty.buffer.AbstractReferenceCountedByteBuf got initialized use --trace-class-initialization=io.netty.buffer.AbstractReferenceCountedByteBuf
io.netty.handler.codec.http2.Http2CodecUtil the class was requested to be initialized at run time (from 'META-INF\native-image\io.netty\netty-codec-http2\native-image.properties' in 'file:///E:/jt808-netty-master/jdk21Test/target/libs/netty-codec-http2-4.1.100.Final.jar' with 'io.netty.handler.codec.http2.Http2CodecUtil' and from 'META-INF\native-image\io.netty\netty-codec-http2\native-image.properties' in 'file:///E:/maven-jar/io/netty/netty-codec-http2/4.1.100.Final/netty-codec-http2-4.1.100.Final.jar' with 'io.netty.handler.codec.http2.Http2CodecUtil'). To see why io.netty.handler.codec.http2.Http2CodecUtil got initialized use --trace-class-initialization=io.netty.handler.codec.http2.Http2CodecUtil
io.netty.buffer.UnpooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.UnpooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledUnsafeDirectByteBuf
io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf
To see how the classes got initialized, use --trace-class-initialization=io.netty.buffer.UnpooledDirectByteBuf,io.netty.buffer.AbstractReferenceCountedByteBuf,io.netty.handler.codec.http2.Http2CodecUtil,io.netty.buffer.UnpooledUnsafeDirectByteBuf,io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf
------------------------------------------------------------------------------------------------------------------------
                        2.4s (8.3% of total time) in 117 GCs | Peak RSS: 1.36GB | CPU load: 6.71
========================================================================================================================

Steps to Reproduce

public class App 
{
    public static void main( String[] args ) throws InterruptedException {

        HttpServer.create()
                .port(8080)
                .handle((req, res) ->
                        res.sendString(Mono.just("Hello World!")))
                .bindNow();
        Thread.sleep(400000000);
    }
}

Possible Solution

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>jdk21Test</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>jdk21Test</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>21</maven.compiler.source>
        <maven.compiler.target>21</maven.compiler.target>
        <native.maven.plugin.version>0.9.27</native.maven.plugin.version>
        <maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty</artifactId>
            <version>1.1.12</version>
        </dependency>
<!--        <dependency>-->
<!--            <groupId>org.graalvm.sdk</groupId>-->
<!--            <artifactId>nativeimage</artifactId>-->
<!--            <version>23.1.0</version>-->
<!--        </dependency>-->
    </dependencies>
    <build>
        <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>${maven-jar-plugin.version}</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>org.example.App</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>

            </plugins>
        </pluginManagement>
    </build>
    <profiles>
        <profile>
            <id>native</id>
            <build>
                <plugins>

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <executions>
                            <execution>
                                <id>copy-dependencies</id>
                                <phase>prepare-package</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>
                                        ${project.build.directory}/libs
                                    </outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>${maven-jar-plugin.version}</version>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                    <classpathPrefix>libs</classpathPrefix>
                                    <mainClass>org.example.App</mainClass>
                                </manifest>
                            </archive>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.graalvm.buildtools</groupId>
                        <artifactId>native-maven-plugin</artifactId>
                        <version>${native.maven.plugin.version}</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>build-native</id>
                                <goals>
                                    <goal>build</goal>
                                </goals>
                                <phase>package</phase>
                            </execution>
                            <execution>
                                <id>test-native</id>
                                <goals>
                                    <goal>test</goal>
                                </goals>
                                <phase>test</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <imageName>fluxmq</imageName>

                            <fallback>false</fallback>
                            <buildArgs>
                                <arg>-H:DashboardDump=fortune -H:+DashboardAll</arg>
                            </buildArgs>
                        </configuration>
                    </plugin>

                </plugins>
            </build>
        </profile>
    </profiles>
</project>

Your Environment

      <dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty</artifactId>
            <version>1.1.12</version>
        </dependency>
  • Reactor version(s) used:
  • Other relevant libraries versions (eg. netty, ...): 4.1.100.final
  • JVM version (java -version): graalvm-jdk21
  • OS and version (eg. uname -a): x86

@1ssqq1lxr I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.

@1ssqq1lxr Netty 4.1 needs the metadata from https://github.com/oracle/graalvm-reachability-metadata (see more information here netty/netty#13596 (comment))

When you package your dependencies in the application, this prevents the GraalVM tooling to remove the old Netty 4.1 configuration (see more information here netty/netty#13500 (reply in thread))

I changed the profile in your pom.xml to this and I do not see any issues

<profiles>
	<profile>
		<id>native</id>
		<build>
			<plugins>
				<plugin>
					<groupId>org.graalvm.buildtools</groupId>
					<artifactId>native-maven-plugin</artifactId>
					<version>${native.maven.plugin.version}</version>
					<extensions>true</extensions>
					<executions>
						<execution>
							<id>build-native</id>
							<goals>
								<goal>build</goal>
							</goals>
							<phase>package</phase>
						</execution>
						<execution>
							<id>test-native</id>
							<goals>
								<goal>test</goal>
							</goals>
							<phase>test</phase>
						</execution>
					</executions>
					<configuration>
						<imageName>fluxmq</imageName>
						<mainClass>org.example.App</mainClass>
						<fallback>false</fallback>
						<buildArgs>
							<arg>-H:DashboardDump=fortune -H:+DashboardAll</arg>
						</buildArgs>
						<metadataRepository>
							<enabled>true</enabled>
						</metadataRepository>
					</configuration>
				</plugin>
			</plugins>
		</build>
	</profile>
</profiles>

I executed the following command mvn -P native install

Java version is

openjdk version "21" 2023-09-19
OpenJDK Runtime Environment GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15)
OpenJDK 64-Bit Server VM GraalVM CE 21+35.1 (build 21+35-jvmci-23.1-b15, mixed mode, sharing)

My JDK version is:
java 21 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21+35-LTS-2513)
Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing)

Running the command you provided still reports an error

Error: Classes that should be initialized at run time got initialized during image building:
 io.netty.handler.codec.http2.Http2CodecUtil the class was requested to be initialized at run time (from 'META-INF\native-image\io.netty\netty-codec-http2\native-image.properties' in '
file:///E:/jt808-netty-master/jdk21Test/target/libs/netty-codec-http2-4.1.100.Final.jar' with 'io.netty.handler.codec.http2.Http2CodecUtil'). To see why io.netty.handler.codec.http2.Ht
tp2CodecUtil got initialized use --trace-class-initialization=io.netty.handler.codec.http2.Http2CodecUtil
io.netty.buffer.AbstractReferenceCountedByteBuf the class was requested to be initialized at run time (from 'META-INF\native-image\io.netty\netty-buffer\native-image.properties' in 'fi
le:///E:/jt808-netty-master/jdk21Test/target/libs/netty-buffer-4.1.100.Final.jar' with 'io.netty.buffer.AbstractReferenceCountedByteBuf' and from 'META-INF\native-image\io.netty\netty-
buffer\native-image.properties' in 'file:///E:/jt808-netty-master/jdk21Test/target/jdk21Test-1.0-SNAPSHOT.jar' with 'io.netty.buffer.AbstractReferenceCountedByteBuf'). To see why io.ne
tty.buffer.AbstractReferenceCountedByteBuf got initialized use --trace-class-initialization=io.netty.buffer.AbstractReferenceCountedByteBuf
io.netty.buffer.UnpooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buff
er.UnpooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledUnsafeDirectByteBuf
io.netty.buffer.UnpooledDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCountedByteBuf). To see why io.netty.buffer.Unp
ooledDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledDirectByteBuf
io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf the class was requested to be initialized at run time (subtype of io.netty.buffer.AbstractReferenceCoun
tedByteBuf). To see why io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf got initialized use --trace-class-initialization=io.netty.buffer.UnpooledByteBu
fAllocator$InstrumentedUnpooledUnsafeDirectByteBuf
To see how the classes got initialized, use --trace-class-initialization=io.netty.handler.codec.http2.Http2CodecUtil,io.netty.buffer.AbstractReferenceCountedByteBuf,io.netty.buffer.Unp
ooledUnsafeDirectByteBuf,io.netty.buffer.UnpooledDirectByteBuf,io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeDirectByteBuf
------------------------------------------------------------------------------------------------------------------------
                        2.7s (8.8% of total time) in 128 GCs | Peak RSS: 1.43GB | CPU load: 6.70
========================================================================================================================
Finished generating 'fluxmq' in 29.5s.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  38.920 s

@1ssqq1lxr Please provide a reproducible example as a project that we can run.

@1ssqq1lxr I'm seeing that you are using Windows OS. I added Windows OS to the matrix that we have for our GraalVM CI and the build is successful.
https://github.com/reactor/reactor-netty/actions/runs/6728843373/job/18288779438

I'm closing this issue, we can reopen it if you are able to provide a reproducible example.