Сравнительный тест Native-Image с использованием микробенчмаркинга Java - PullRequest
0 голосов
/ 08 июля 2019

Я хочу сравнить исходное изображение SubstrateVM, созданное с помощью собственного изображения GraalVM, но не смогу сгенерировать его, если оно не является запасным изображением, для работы которого требуется JVM.

Я знаю, что здесь задействовано много рефлексии, поэтому я написал конфигурационный файл Reflection.json, в котором я указал классы, на которые влияют, но это не работает, как я ожидаю.

А пока я просто хочу сравнить BubbleSort для примера, поэтому я попытался скомпилировать его с собственным изображением и использовал сообщение об ошибке, чтобы записать файл конфигурации reflections.json с подстановочными знаками. Я нашел пример здесь: https://github.com/oracle/graal/blob/master/substratevm/REFLECTION.md#manual-configuration

Это часть сообщения об ошибке, которое я получаю, когда пытаюсь скомпилировать собственное изображение из моего benchmark.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

Это отражение-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 = mirror-config.json

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...