Graal: [native-image] can't compile on docker

Created on 21 Apr 2018  ·  3Comments  ·  Source: oracle/graal

I tried to build simple code with native-image on docker + graalvm-ce-1.0.0-rc1, but native-image throwed NullpinterException.
And same program is sucess on MacOS + graalvm-ee-1.0.0-rc1.
Haven't yet native-image support Docker? Or should I need some configuration to Dockerfile?

[root@c74702bf3869 /]# javac HelloWorld.java
[root@c74702bf3869 /]# java HelloWorld 
Hello, World
[root@c74702bf3869 /]# native-image --verbose HelloWorld
Build on Server(pid: 167, port: 26681)
SendBuildRequest [
-task=com.oracle.svm.hosted.NativeImageGeneratorRunner
-imagecp
/usr/graalvm-1.0.0-rc1/jre/lib/svm/builder/pointsto.jar:/usr/graalvm-1.0.0-rc1/jre/lib/svm/builder/objectfile.jar:/usr/graalvm-1.0.0-rc1/jre/lib/svm/builder/svm.jar:/usr/graalvm-1.0.0-rc1/jre/lib/jvmci/jvmci-api.jar:/usr/graalvm-1.0.0-rc1/jre/lib/jvmci/graal.jar:/usr/graalvm-1.0.0-rc1/jre/lib/jvmci/jvmci-hotspot.jar:/usr/graalvm-1.0.0-rc1/jre/lib/boot/graal-sdk.jar:/usr/graalvm-1.0.0-rc1/jre/lib/boot/graaljs-scriptengine.jar:/usr/graalvm-1.0.0-rc1/jre/lib/svm/library-support.jar:/
-H:Path=/
-H:CLibraryPath=/usr/graalvm-1.0.0-rc1/jre/lib/svm/clibraries/linux-amd64
-H:Class=HelloWorld
-H:Name=helloworld
]
fatal error: java.lang.NullPointerException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
    at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677)
    at java.util.concurrent.ForkJoinTask.invoke(ForkJoinTask.java:735)
    at java.util.stream.ForEachOps$ForEachOp.evaluateParallel(ForEachOps.java:160)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateParallel(ForEachOps.java:174)
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:233)
    at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:418)
    at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:583)
    at com.oracle.svm.hosted.ImageClassLoader.initAllClasses(ImageClassLoader.java:120)
    at com.oracle.svm.hosted.ImageClassLoader.create(ImageClassLoader.java:103)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:150)
    at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:337)
    at com.oracle.svm.hosted.server.NativeImageBuildServer.executeCompilation(NativeImageBuildServer.java:378)
    at com.oracle.svm.hosted.server.NativeImageBuildServer.lambda$processCommand$8(NativeImageBuildServer.java:315)
    at com.oracle.svm.hosted.server.NativeImageBuildServer.withJVMContext(NativeImageBuildServer.java:396)
    at com.oracle.svm.hosted.server.NativeImageBuildServer.processCommand(NativeImageBuildServer.java:312)
    at com.oracle.svm.hosted.server.NativeImageBuildServer.processRequest(NativeImageBuildServer.java:256)
    at com.oracle.svm.hosted.server.NativeImageBuildServer.lambda$serve$7(NativeImageBuildServer.java:216)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException
    at com.oracle.svm.hosted.ImageClassLoader.loadClassesFromPath(ImageClassLoader.java:127)
    at com.oracle.svm.hosted.ImageClassLoader.lambda$initAllClasses$2(ImageClassLoader.java:120)
    at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:184)
    at java.util.TreeMap$KeySpliterator.forEachRemaining(TreeMap.java:2746)
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
    at java.util.stream.ForEachOps$ForEachTask.compute(ForEachOps.java:291)
    at java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:731)
    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
    at java.util.concurrent.ForkJoinPool$WorkQueue.execLocalTasks(ForkJoinPool.java:1040)
    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1058)
    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Error: Processing image build request failed

I use following Dockerfile.

FROM centos:7
MAINTAINER koduki

ENV GRAALVM_URL=https://github.com/oracle/graal/releases/download/vm-1.0.0-rc1/graalvm-ce-1.0.0-rc1-linux-amd64.tar.gz \
    GRAALVM_PKG=graalvm-ce-1.0.0-rc1-linux-amd64.tar.gz \
    GRAALVM_HOME=/usr/graalvm-1.0.0-rc1

ENV JAVA_HOME=${GRAALVM_HOME} \
    PATH=${GRAALVM_HOME}/bin:$PATH

RUN curl -L -o $GRAALVM_PKG $GRAALVM_URL &&  \
    tar xfvz $GRAALVM_PKG -C /usr/ &&  \
    rm $GRAALVM_PKG

RUN yum -y install gcc openssl-devel && rm -rf /var/cache/yum && \
    alternatives --install /usr/bin/java  java  $JAVA_HOME/bin/java  20000 && \
    alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 20000 && \
    alternatives --install /usr/bin/jar   jar   $JAVA_HOME/bin/jar   20000

CMD ["java", "-version"]
bug native-image

Most helpful comment

@koduki this a bug in the classpath handling of image building when the classpath contains the root directory (/). I'm going to fix this ASAP. In the meantime as a workaround I suggest image building in a subdirectory:

[root@f00d70fe6273 /]# mkdir foo
[root@f00d70fe6273 /]# cd foo 
[root@f00d70fe6273 foo]# echo "public class HelloWorld { public static void main(String[] args) { System.out.println(\"Hello World\"); } }" > HelloWorld.java
[root@f00d70fe6273 foo]# javac HelloWorld.java
[root@f00d70fe6273 foo]# java HelloWorld
Hello World
[root@f00d70fe6273 foo]# native-image HelloWorld
Build on Server(pid: 84, port: 26681)
   classlist:     122.21 ms
       (cap):     745.28 ms
       setup:   1,328.18 ms
  (typeflow):   3,250.40 ms
   (objects):   1,347.87 ms
  (features):      36.42 ms
    analysis:   4,755.03 ms
    universe:     265.19 ms
     (parse):     640.09 ms
    (inline):     640.26 ms
   (compile):   2,568.08 ms
     compile:   4,156.92 ms
       image:     623.75 ms
       write:     175.28 ms
     [total]:  11,485.61 ms
[root@f00d70fe6273 foo]# ./helloworld 
Hello World

All 3 comments

@koduki this a bug in the classpath handling of image building when the classpath contains the root directory (/). I'm going to fix this ASAP. In the meantime as a workaround I suggest image building in a subdirectory:

[root@f00d70fe6273 /]# mkdir foo
[root@f00d70fe6273 /]# cd foo 
[root@f00d70fe6273 foo]# echo "public class HelloWorld { public static void main(String[] args) { System.out.println(\"Hello World\"); } }" > HelloWorld.java
[root@f00d70fe6273 foo]# javac HelloWorld.java
[root@f00d70fe6273 foo]# java HelloWorld
Hello World
[root@f00d70fe6273 foo]# native-image HelloWorld
Build on Server(pid: 84, port: 26681)
   classlist:     122.21 ms
       (cap):     745.28 ms
       setup:   1,328.18 ms
  (typeflow):   3,250.40 ms
   (objects):   1,347.87 ms
  (features):      36.42 ms
    analysis:   4,755.03 ms
    universe:     265.19 ms
     (parse):     640.09 ms
    (inline):     640.26 ms
   (compile):   2,568.08 ms
     compile:   4,156.92 ms
       image:     623.75 ms
       write:     175.28 ms
     [total]:  11,485.61 ms
[root@f00d70fe6273 foo]# ./helloworld 
Hello World

Thank you for your information.
I can build & run on a sub-directory.

BTW, I have fixed this on master: https://github.com/oracle/graal/commit/f53341bdb1db374b0f2f47e4f323e31430562a96
So if you really want to build with / on the classpath it will no more be a problem in future releases (but I still recommend not to do so).

Was this page helpful?
0 / 5 - 0 ratings