Skip to content

Commit

Permalink
updated native image configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rashtao committed Jun 6, 2024
1 parent aaa1be2 commit 01d1725
Show file tree
Hide file tree
Showing 11 changed files with 1,166 additions and 4 deletions.
28 changes: 28 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<exec.mainClass>com.example.ApplicationKt</exec.mainClass>
<kotlinVersion>1.9.23</kotlinVersion>
<adb.version>7.7.0-SNAPSHOT</adb.version>
<graalvm.version>24.0.1</graalvm.version>
</properties>

<repositories>
Expand Down Expand Up @@ -316,7 +317,34 @@
<artifactId>arangodb-java-driver</artifactId>
<version>${adb.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>24.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/native/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>shaded</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
Args=\
--initialize-at-build-time=\
com.example,\
ch.qos.logback,\
org.slf4j
-Dio.netty.noUnsafe=true \
-Dio.netty.leakDetection.level=DISABLED \
--initialize-at-build-time=\
com.example,\
ch.qos.logback,\
org.slf4j,\
io.netty \
--initialize-at-run-time=\
io.netty.buffer.PooledByteBufAllocator,\
io.netty.buffer.ByteBufAllocator,\
io.netty.buffer.ByteBufUtil,\
io.netty.buffer.AbstractReferenceCountedByteBuf,\
io.netty.handler.ssl.JdkSslServerContext,\
io.netty.handler.codec.compression.BrotliDecoder,\
io.netty.handler.codec.compression.ZstdConstants,\
io.netty.handler.codec.http2.Http2CodecUtil,\
io.netty.handler.codec.http2.Http2ClientUpgradeCodec,\
io.netty.handler.codec.http2.Http2ConnectionHandler,\
io.netty.handler.codec.http2.DefaultHttp2FrameWriter,\
io.netty.handler.codec.http.HttpObjectEncoder,\
io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,\
io.netty.handler.codec.http.websocketx.extensions.compression.DeflateDecoder,\
io.netty.handler.codec.http2.CleartextHttp2ServerUpgradeHandler,\
io.netty.handler.codec.http2.Http2ServerUpgradeCodec,\
io.netty.handler.pcap.PcapWriteHandler$WildcardAddressHolder,\
io.netty.util.AbstractReferenceCounted,\
io.netty.util.concurrent.GlobalEventExecutor,\
io.netty.util.concurrent.ImmediateEventExecutor,\
io.netty.util.concurrent.ScheduledFutureTask,\
io.netty.util.internal.ThreadLocalRandom,\
io.netty.util.NetUtilSubstitutions$NetUtilLocalhost4LazyHolder,\
io.netty.util.NetUtilSubstitutions$NetUtilLocalhost6LazyHolder,\
io.netty.util.NetUtilSubstitutions$NetUtilLocalhostLazyHolder,\
io.netty.util.NetUtilSubstitutions$NetUtilNetworkInterfacesLazyHolder,\
io.netty.handler.ssl.util.ThreadLocalInsecureRandom,\
io.netty.resolver.dns.DefaultDnsServerAddressStreamProvider,\
io.netty.resolver.dns.DnsServerAddressStreamProviders$DefaultProviderHolder,\
io.netty.resolver.dns.DnsNameResolver,\
io.netty.resolver.HostsFileEntriesResolver,\
io.netty.resolver.dns.ResolvConf$ResolvConfLazy,\
io.netty.resolver.dns.DefaultDnsServerAddressStreamProvider,\
io.vertx.core.buffer.impl.VertxByteBufAllocator
20 changes: 20 additions & 0 deletions src/native/java/graal/BrotliSubstitutions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package graal;

import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

public class BrotliSubstitutions {

@TargetClass(className = "io.netty.handler.codec.compression.Brotli")
static final class Target_io_netty_handler_codec_compression_Brotli {
@Substitute
public static boolean isAvailable() {
return false;
}

@Substitute
public static void ensureAvailability() throws Throwable {
throw new UnsupportedOperationException();
}
}
}
98 changes: 98 additions & 0 deletions src/native/java/graal/graal/JdkSubstitutions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package graal.graal;

import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.InjectAccessors;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import java.io.IOException;
import java.net.URL;
import java.nio.channels.spi.AsynchronousChannelProvider;

@TargetClass(className = "jdk.internal.loader.URLClassPath$Loader")
final class Target_URLClassPath$Loader {

@Alias
public Target_URLClassPath$Loader(URL url) {
}
}

@TargetClass(className = "jdk.internal.loader.URLClassPath$FileLoader")
final class Target_URLClassPath$FileLoader {

@Alias
public Target_URLClassPath$FileLoader(URL url) throws IOException {
}
}

@TargetClass(className = "jdk.internal.loader.URLClassPath")
final class Target_jdk_internal_loader_URLClassPath {

@Substitute
private Target_URLClassPath$Loader getLoader(final URL url) throws IOException {
String file = url.getFile();
if (file != null && file.endsWith("/")) {
if ("file".equals(url.getProtocol())) {
return (Target_URLClassPath$Loader) (Object) new Target_URLClassPath$FileLoader(
url);
} else {
return new Target_URLClassPath$Loader(url);
}
} else {
// that must be wrong, but JarLoader is deleted by SVM
return (Target_URLClassPath$Loader) (Object) new Target_URLClassPath$FileLoader(
url);
}
}

}

@Substitute
@TargetClass(className = "sun.nio.ch.WindowsAsynchronousFileChannelImpl", innerClass = "DefaultIocpHolder")
@Platforms({ Platform.WINDOWS.class })
final class Target_sun_nio_ch_WindowsAsynchronousFileChannelImpl_DefaultIocpHolder {

@Alias
@InjectAccessors(DefaultIocpAccessor.class)
static Target_sun_nio_ch_Iocp defaultIocp;
}

@TargetClass(className = "sun.nio.ch.Iocp")
@Platforms({ Platform.WINDOWS.class })
final class Target_sun_nio_ch_Iocp {

@Alias
Target_sun_nio_ch_Iocp(AsynchronousChannelProvider provider, Target_sun_nio_ch_ThreadPool pool) throws IOException {
}

@Alias
Target_sun_nio_ch_Iocp start() {
return null;
}
}

@TargetClass(className = "sun.nio.ch.ThreadPool")
@Platforms({ Platform.WINDOWS.class })
final class Target_sun_nio_ch_ThreadPool {

@Alias
static Target_sun_nio_ch_ThreadPool createDefault() {
return null;
}
}

final class DefaultIocpAccessor {
static Target_sun_nio_ch_Iocp get() {
try {
return new Target_sun_nio_ch_Iocp(null, Target_sun_nio_ch_ThreadPool.createDefault()).start();
} catch (IOException ioe) {
throw new InternalError(ioe);
}
}
}

class JdkSubstitutions {

}
Loading

0 comments on commit 01d1725

Please sign in to comment.