10. ネイティブコンパイルを試みる
●
Undertow
●
WildFlyのWebサーバ実装
●
Java SEでも動く
import io.undertow.Undertow;
import io.undertow.util.Headers;
public class Main {
public static void main(final String[] args) {
Undertow server = Undertow.builder()
.addHttpListener(8080, "localhost")
.setHandler(exchange -> {
exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
exchange.getResponseSender().send("Hello World");
}).build();
server.start();
}
}
11. native-imageが通らない
●
ネイティブイメージ作成時の制約事項に引っかかる
●
java.nio.ByteBuffer#allocateDirectは使えない
●
Undertowの内部実装AjpServerRequestConduitクラスで利用
$ native-image -jar undertow-standalone.jar
Warning: Abort stand-alone image build. Unsupported features in 3 methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException:
Detected a direct/mapped ByteBuffer in the image heap. A direct ByteBuffer has a pointer
to unmanaged C memory, and C memory from the image generator is not available at image run time. A mapped
ByteBuffer references a file descriptor, which is no longer open and mapped at run time. The object was probably
created by a class initializer and is reachable from a static field. By default, all class initialization is done during
native image building.You can manually delay class initialization to image run time by using the option --delay-
class-initialization-to-runtime=<class-name>. Or you can write your own initialization methods and call them
explicitly from your main entry point.
Trace:
at parsing io.undertow.server.protocol.ajp.AjpServerRequestConduit.read
(AjpServerRequestConduit.java:195)
Call path from entry point to io.undertow.server.protocol.ajp.AjpServerRequestConduit.read(ByteBuffer):
at io.undertow.server.protocol.ajp.AjpServerRequestConduit.read(AjpServerRequestConduit.java:183)
at org.xnio.conduits.ConduitStreamSourceChannel.read(ConduitStreamSourceChannel.java:127)