使用Java Microbenchmarking Harness对原生图像进行基准测试

时间:2019-07-08 17:02:13

标签: java graalvm substratevm graalvm-native-image

我想对用GraalVM本机映像生成的SubstrateVM本机映像进行基准测试,但是如果它不是需要运行JVM的后备映像,则无法生成它。

我知道其中涉及到很多反射,所以我编写了一个Reflection.json配置文件,在其中指定了受影响的类,但是这并没有达到我的预期。

现在,我仅想对BubbleSort进行示例测试,因此我尝试使用本机图像对其进行编译,并使用错误消息使用通配符编写了Reflection.json配置文件。我在这里找到了一个示例:https://github.com/oracle/graal/blob/master/substratevm/REFLECTION.md#manual-configuration

这是我尝试从我的基准.jar中编译本机映像时收到的错误消息的一部分:

Build on Server(pid:4265,port:44443)
[benchmarks:4265]classlist:829.96ms
[benchmarks:4265](cap):1,416.06ms
[benchmarks:4265]setup:3,027.77ms
Warning:RecomputeFieldValue.FieldOffset automatic substitution failed.The automatic substitution registration was attempted because a call to sun.misc.Unsafe.objectFieldOffset(Field)was detected in the static initializer of org.openjdk.jmh.runner.InfraControl.Detailed failure reason(s):The argument of Unsafe.objectFieldOffset(Field)is not a constant field.,Could not determine the field where the value produced by the call to sun.misc.Unsafe.objectFieldOffset(Field)for the field offset computation is stored.The call is not directly followed by a field store or by a sign extend node followed directly by a field store.
Warning:RecomputeFieldValue.FieldOffset automatic substitution failed.The automatic substitution registration was attempted because a call to sun.misc.Unsafe.objectFieldOffset(Field)was detected in the static initializer of org.openjdk.jmh.runner.InfraControl.Detailed failure reason(s):The argument of Unsafe.objectFieldOffset(Field)is not a constant field.,Could not determine the field where the value produced by the call to sun.misc.Unsafe.objectFieldOffset(Field)for the field offset computation is stored.The call is not directly followed by a field store or by a sign extend node followed directly by a field store.
Warning:RecomputeFieldValue.FieldOffset automatic substitution failed.The automatic substitution registration was attempted because a call to sun.misc.Unsafe.objectFieldOffset(Field)was detected in the static initializer of org.openjdk.jmh.runner.InfraControl.Detailed failure reason(s):The argument of Unsafe.objectFieldOffset(Field)is not a constant field.,Could not determine the field where the value produced by the call to sun.misc.Unsafe.objectFieldOffset(Field)for the field offset computation is stored.The call is not directly followed by a field store or by a sign extend node followed directly by a field store.
Warning:RecomputeFieldValue.FieldOffset automatic substitution failed.The automatic substitution registration was attempted because a call to sun.misc.Unsafe.objectFieldOffset(Field)was detected in the static initializer of org.openjdk.jmh.runner.InfraControl.Detailed failure reason(s):The argument of Unsafe.objectFieldOffset(Field)is not a constant field.,Could not determine the field where the value produced by the call to sun.misc.Unsafe.objectFieldOffset(Field)for the field offset computation is stored.The call is not directly followed by a field store or by a sign extend node followed directly by a field store.
Warning:RecomputeFieldValue.FieldOffset automatic substitution failed.The automatic substitution registration was attempted because a call to sun.misc.Unsafe.objectFieldOffset(Field)was detected in the static initializer of org.openjdk.jmh.runner.InfraControl.Detailed failure reason(s):The argument of Unsafe.objectFieldOffset(Field)is not a constant field.,Could not determine the field where the value produced by the call to sun.misc.Unsafe.objectFieldOffset(Field)for the field offset computation is stored.The call is not directly followed by a field store or by a sign extend node followed directly by a field store.
Warning:RecomputeFieldValue.FieldOffset automatic substitution failed.The automatic substitution registration was attempted because a call to sun.misc.Unsafe.objectFieldOffset(Field)was detected in the static initializer of org.openjdk.jmh.runner.InfraControl.Detailed failure reason(s):The argument of Unsafe.objectFieldOffset(Field)is not a constant field.,Could not determine the field where the value produced by the call to sun.misc.Unsafe.objectFieldOffset(Field)for the field offset computation is stored.The call is not directly followed by a field store or by a sign extend node followed directly by a field store.
[benchmarks:4265](typeflow):13,296.89ms
[benchmarks:4265](objects):7,427.24ms
[benchmarks:4265](features):441.05ms
[benchmarks:4265]analysis:21,481.63ms
[benchmarks:4265]universe:544.03ms
Warning:Reflection method java.lang.Class.forName invoked at org.openjdk.jmh.runner.BenchmarkHandler$ExecutorType$5.createExecutor(BenchmarkHandler.java:243)
Warning:Reflection method java.lang.Class.forName invoked at org.openjdk.jmh.profile.ProfilerFactory.getProfiler(ProfilerFactory.java:76)
Warning:Reflection method java.lang.Class.forName invoked at org.openjdk.jmh.util.ClassUtils.loadClass(ClassUtils.java:72)
Warning:Reflection method java.lang.Class.getDeclaredMethod invoked at joptsimple.internal.Reflection.valueOfConverter(Reflection.java:71)
Warning:Reflection method java.lang.Class.getMethods invoked at org.openjdk.jmh.runner.link.BinaryLinkServer.<init>(BinaryLinkServer.java:88)
Warning:Reflection method java.lang.Class.getDeclaredMethods invoked at org.openjdk.jmh.util.ClassUtils.enumerateMethods(ClassUtils.java:63)
Warning:Reflection method java.lang.Class.getConstructor invoked at org.openjdk.jmh.profile.ProfilerFactory.instantiate(ProfilerFactory.java:88)
Warning:Reflection method java.lang.Class.getConstructor invoked at org.openjdk.jmh.profile.ProfilerFactory.instantiate(ProfilerFactory.java:82)
Warning:Reflection method java.lang.Class.getConstructor invoked at org.openjdk.jmh.runner.BenchmarkHandler$ExecutorType$5.createExecutor(BenchmarkHandler.java:243)
Warning:Reflection method java.lang.Class.getConstructor invoked at joptsimple.internal.Reflection.constructorConverter(Reflection.java:84)
Warning:Reflection method java.lang.Class.getConstructor invoked at org.openjdk.jmh.runner.BenchmarkHandler$1.initialValue(BenchmarkHandler.java:82)
Warning:Reflection method java.lang.ClassLoader.loadClass invoked at org.openjdk.jmh.util.ClassUtils.loadClass(ClassUtils.java:88)
Warning:Aborting stand-alone image build due to reflection use without configuration.
Warning:Use-H:+ReportExceptionStackTraces to print stacktrace of underlying exception

这是我使用的reflect-config.json

[
    {
        "name": "org.openjdk.jmh.runner.BenchmarkHandler",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "org.openjdk.jmh.util.ClassUtils",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "org.openjdk.jmh.profile.ProfilerFactory",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "joptsimple.internal.Reflection",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "org.openjdk.jmh.runner.link.BinaryLinkServer",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "org.openjdk.jmh.util.ClassUtils",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "org.openjdk.jmh.runner.BenchmarkHandler",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "org.openjdk.jmh.profile.ProfilerFactory",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "joptsimple.internal.Reflection",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "org.openjdk.jmh.runner.BenchmarkHandler",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "org.openjdk.jmh.profile.ProfilerFactory",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    },
    {
        "name": "org.openjdk.jmh.util.ClassUtils",
        "allDeclaredConstructors": true,
        "allPublicConstructors": true,
        "allDeclaredMethods": true,
        "allPublicMethods": true,
        "allDeclaredClasses": true,
        "allPublicClasses": true
    }
]

我希望它能够在配置文件中定义受影响的类时进行编译。 我执行此操作以生成图像:     native-image -jar Benchmarks.jar H:ReflectionConfigurationFiles = reflection-config.json

0 个答案:

没有答案