From 7f50996cd95ee0e135fb6e1eb31fb8a153880f50 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 10 Oct 2022 12:28:04 +0200 Subject: [PATCH 1/8] Adds Graal hints for the shaded dependencies --- .../META-INF/native-image/reflect-config.json | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/reflect-config.json diff --git a/sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/reflect-config.json b/sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/reflect-config.json new file mode 100644 index 00000000000..31b0add5edc --- /dev/null +++ b/sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/reflect-config.json @@ -0,0 +1,130 @@ +[ + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseLinkedQueueConsumerNodeRef" + }, + "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseLinkedQueueConsumerNodeRef", + "fields": [ + { + "name": "consumerNode" + } + ] + }, + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseLinkedQueueProducerNodeRef" + }, + "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseLinkedQueueProducerNodeRef", + "fields": [ + { + "name": "producerNode" + } + ] + }, + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields" + }, + "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields", + "fields": [ + { + "name": "producerLimit" + } + ] + }, + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields" + }, + "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields", + "fields": [ + { + "name": "consumerIndex" + } + ] + }, + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueProducerFields" + }, + "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueProducerFields", + "fields": [ + { + "name": "producerIndex" + } + ] + }, + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.LinkedQueueNode" + }, + "name": "io.opentelemetry.internal.shaded.jctools.queues.LinkedQueueNode", + "fields": [ + { + "name": "next" + } + ] + }, + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueConsumerIndexField" + }, + "name": "io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueConsumerIndexField", + "fields": [ + { + "name": "consumerIndex" + } + ] + }, + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerIndexField" + }, + "name": "io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerIndexField", + "fields": [ + { + "name": "producerIndex" + } + ] + }, + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerLimitField" + }, + "name": "io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueProducerLimitField", + "fields": [ + { + "name": "producerLimit" + } + ] + }, + { + "condition": { + "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.UnsafeAccess" + }, + "name": "sun.misc.Unsafe", + "fields": [ + { + "name": "theUnsafe" + } + ], + "queriedMethods": [ + { + "name": "getAndAddLong", + "parameterTypes": [ + "java.lang.Object", + "long", + "long" + ] + }, + { + "name": "getAndSetObject", + "parameterTypes": [ + "java.lang.Object", + "long", + "java.lang.Object" + ] + } + ] + } +] From 70b3ce185a4166c766a5d730a9585b3c45daf763 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 10 Oct 2022 13:22:55 +0200 Subject: [PATCH 2/8] Moved the file to the proper location --- .../opentelemetry-sdk-trace}/reflect-config.json | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/{ => io.opentelemetry/opentelemetry-sdk-trace}/reflect-config.json (100%) diff --git a/sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/reflect-config.json b/sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/io.opentelemetry/opentelemetry-sdk-trace/reflect-config.json similarity index 100% rename from sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/reflect-config.json rename to sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/io.opentelemetry/opentelemetry-sdk-trace/reflect-config.json From 92e0379e80857ce816080c2cc9888b241620fc08 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 11 Oct 2022 18:07:46 +0200 Subject: [PATCH 3/8] Added Graal VM Github Action build --- .github/workflows/build-graal.yml | 20 ++++ integration-tests/graal/build.gradle.kts | 33 +++++++ .../main/resources/simplelogger.properties | 2 + .../integrationtests/graal/JcToolsTest.java | 26 +++++ .../reflect-config.json | 95 ------------------- settings.gradle.kts | 1 + 6 files changed, 82 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/build-graal.yml create mode 100644 integration-tests/graal/build.gradle.kts create mode 100644 integration-tests/graal/src/main/resources/simplelogger.properties create mode 100644 integration-tests/graal/src/test/java/io/opentelemetry/integrationtests/graal/JcToolsTest.java diff --git a/.github/workflows/build-graal.yml b/.github/workflows/build-graal.yml new file mode 100644 index 00000000000..dc0a75b27a5 --- /dev/null +++ b/.github/workflows/build-graal.yml @@ -0,0 +1,20 @@ +name: GraalVM Community Edition build +on: [push, pull_request] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: graalvm/setup-graalvm@v1 + with: + version: 'latest' + java-version: '11' + components: 'native-image' + - name: Running test + run: | + echo "GRAALVM_HOME: $GRAALVM_HOME" + echo "JAVA_HOME: $JAVA_HOME" + java --version + gu --version + native-image --version + ./gradlew nativeTest \ No newline at end of file diff --git a/integration-tests/graal/build.gradle.kts b/integration-tests/graal/build.gradle.kts new file mode 100644 index 00000000000..e800f348a1d --- /dev/null +++ b/integration-tests/graal/build.gradle.kts @@ -0,0 +1,33 @@ +plugins { + id("otel.java-conventions") + id("java-library") + id("org.graalvm.buildtools.native") version "0.9.7.1" +} + +description = "OpenTelemetry Graal Integration Tests" +otelJava.moduleName.set("io.opentelemetry.graal.integration.tests") + +sourceSets { + main { + val traceShadedDeps = project(":sdk:trace-shaded-deps") + output.dir(traceShadedDeps.file("build/extracted/shadow"), "builtBy" to ":sdk:trace-shaded-deps:extractShadowJar") + } +} + +dependencies { + implementation(project(path = ":sdk:trace-shaded-deps")) + + testImplementation("org.junit.jupiter:junit-jupiter") +} + +graalvmNative { + binaries { + named("main") { + verbose.set(true) + } + } +} + +tasks.test { + useJUnitPlatform() +} \ No newline at end of file diff --git a/integration-tests/graal/src/main/resources/simplelogger.properties b/integration-tests/graal/src/main/resources/simplelogger.properties new file mode 100644 index 00000000000..a6233fa3461 --- /dev/null +++ b/integration-tests/graal/src/main/resources/simplelogger.properties @@ -0,0 +1,2 @@ +org.slf4j.simpleLogger.defaultLogLevel=info +org.slf4j.simpleLogger.log.org.eclipse.jetty=warn diff --git a/integration-tests/graal/src/test/java/io/opentelemetry/integrationtests/graal/JcToolsTest.java b/integration-tests/graal/src/test/java/io/opentelemetry/integrationtests/graal/JcToolsTest.java new file mode 100644 index 00000000000..55363a0487f --- /dev/null +++ b/integration-tests/graal/src/test/java/io/opentelemetry/integrationtests/graal/JcToolsTest.java @@ -0,0 +1,26 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.integrationtests.graal; + +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.sdk.trace.internal.JcTools; +import java.util.Queue; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledInNativeImage; + +class JcToolsTest { + + @Test + @EnabledInNativeImage + void insert_oneElementToTheQueue() { + Queue objects = JcTools.newFixedSizeQueue(10); + + objects.add(new Object()); + + assertThat(objects).hasSize(1); + } +} diff --git a/sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/io.opentelemetry/opentelemetry-sdk-trace/reflect-config.json b/sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/io.opentelemetry/opentelemetry-sdk-trace/reflect-config.json index 31b0add5edc..12d6b7a64b8 100644 --- a/sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/io.opentelemetry/opentelemetry-sdk-trace/reflect-config.json +++ b/sdk/trace-shaded-deps/src/main/resources/META-INF/native-image/io.opentelemetry/opentelemetry-sdk-trace/reflect-config.json @@ -1,70 +1,4 @@ [ - { - "condition": { - "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseLinkedQueueConsumerNodeRef" - }, - "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseLinkedQueueConsumerNodeRef", - "fields": [ - { - "name": "consumerNode" - } - ] - }, - { - "condition": { - "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseLinkedQueueProducerNodeRef" - }, - "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseLinkedQueueProducerNodeRef", - "fields": [ - { - "name": "producerNode" - } - ] - }, - { - "condition": { - "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields" - }, - "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueColdProducerFields", - "fields": [ - { - "name": "producerLimit" - } - ] - }, - { - "condition": { - "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields" - }, - "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueConsumerFields", - "fields": [ - { - "name": "consumerIndex" - } - ] - }, - { - "condition": { - "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueProducerFields" - }, - "name": "io.opentelemetry.internal.shaded.jctools.queues.BaseMpscLinkedArrayQueueProducerFields", - "fields": [ - { - "name": "producerIndex" - } - ] - }, - { - "condition": { - "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.LinkedQueueNode" - }, - "name": "io.opentelemetry.internal.shaded.jctools.queues.LinkedQueueNode", - "fields": [ - { - "name": "next" - } - ] - }, { "condition": { "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.MpscArrayQueueConsumerIndexField" @@ -97,34 +31,5 @@ "name": "producerLimit" } ] - }, - { - "condition": { - "typeReachable": "io.opentelemetry.internal.shaded.jctools.queues.UnsafeAccess" - }, - "name": "sun.misc.Unsafe", - "fields": [ - { - "name": "theUnsafe" - } - ], - "queriedMethods": [ - { - "name": "getAndAddLong", - "parameterTypes": [ - "java.lang.Object", - "long", - "long" - ] - }, - { - "name": "getAndSetObject", - "parameterTypes": [ - "java.lang.Object", - "long", - "java.lang.Object" - ] - } - ] } ] diff --git a/settings.gradle.kts b/settings.gradle.kts index abfef5336db..a3f1483c243 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -47,6 +47,7 @@ include(":exporters:zipkin") include(":integration-tests") include(":integration-tests:otlp") include(":integration-tests:tracecontext") +include(":integration-tests:graal") include(":opencensus-shim") include(":opentracing-shim") include(":perf-harness") From f22a024d24988e87ba5a41cd8f5c985c47b16c72 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 12 Oct 2022 09:32:18 +0200 Subject: [PATCH 4/8] Polish --- integration-tests/graal/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/graal/build.gradle.kts b/integration-tests/graal/build.gradle.kts index e800f348a1d..8ec3d43ba7c 100644 --- a/integration-tests/graal/build.gradle.kts +++ b/integration-tests/graal/build.gradle.kts @@ -30,4 +30,4 @@ graalvmNative { tasks.test { useJUnitPlatform() -} \ No newline at end of file +} From d304a948aed60e50ca8d462aee38df74b16a7b55 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 12 Oct 2022 10:26:39 +0200 Subject: [PATCH 5/8] Updated graal plugin --- integration-tests/graal/build.gradle.kts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/integration-tests/graal/build.gradle.kts b/integration-tests/graal/build.gradle.kts index 8ec3d43ba7c..5fe0fba7ef6 100644 --- a/integration-tests/graal/build.gradle.kts +++ b/integration-tests/graal/build.gradle.kts @@ -1,7 +1,7 @@ plugins { id("otel.java-conventions") id("java-library") - id("org.graalvm.buildtools.native") version "0.9.7.1" + id("org.graalvm.buildtools.native") version "0.9.8" } description = "OpenTelemetry Graal Integration Tests" @@ -28,6 +28,10 @@ graalvmNative { } } +tasks.withType().configureEach { + disableToolchainDetection.set(true) +} + tasks.test { useJUnitPlatform() } From 85ef541a977a753edb91a76800459edbfb58a6e4 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 12 Oct 2022 10:36:37 +0200 Subject: [PATCH 6/8] Updated graal plugin to 0.9.14 --- integration-tests/graal/build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration-tests/graal/build.gradle.kts b/integration-tests/graal/build.gradle.kts index 5fe0fba7ef6..a9613b9481c 100644 --- a/integration-tests/graal/build.gradle.kts +++ b/integration-tests/graal/build.gradle.kts @@ -1,7 +1,7 @@ plugins { id("otel.java-conventions") id("java-library") - id("org.graalvm.buildtools.native") version "0.9.8" + id("org.graalvm.buildtools.native") version "0.9.14" } description = "OpenTelemetry Graal Integration Tests" From 79cde3527f30203b48fab7bb96456eab08590018 Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Wed, 12 Oct 2022 10:39:37 +0200 Subject: [PATCH 7/8] Updated graal native plugin --- integration-tests/graal/build.gradle.kts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/integration-tests/graal/build.gradle.kts b/integration-tests/graal/build.gradle.kts index a9613b9481c..7c61eac27c3 100644 --- a/integration-tests/graal/build.gradle.kts +++ b/integration-tests/graal/build.gradle.kts @@ -26,10 +26,7 @@ graalvmNative { verbose.set(true) } } -} - -tasks.withType().configureEach { - disableToolchainDetection.set(true) + toolchainDetection.set(false) } tasks.test { From 0910f7a0bed00502e9ee381071a7dda25626580c Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Tue, 18 Oct 2022 10:25:08 +0200 Subject: [PATCH 8/8] Applied changes following the review --- integration-tests/graal/build.gradle.kts | 11 +++-------- settings.gradle.kts | 1 + 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/integration-tests/graal/build.gradle.kts b/integration-tests/graal/build.gradle.kts index 7c61eac27c3..78095f8905e 100644 --- a/integration-tests/graal/build.gradle.kts +++ b/integration-tests/graal/build.gradle.kts @@ -1,7 +1,6 @@ plugins { id("otel.java-conventions") - id("java-library") - id("org.graalvm.buildtools.native") version "0.9.14" + id("org.graalvm.buildtools.native") } description = "OpenTelemetry Graal Integration Tests" @@ -9,6 +8,8 @@ otelJava.moduleName.set("io.opentelemetry.graal.integration.tests") sourceSets { main { + // We need to ensure that we have the shadowed classes on the classpath, without this + // we will get the <:sdk:trace-shaded-deps> classes only, without the shadowed ones val traceShadedDeps = project(":sdk:trace-shaded-deps") output.dir(traceShadedDeps.file("build/extracted/shadow"), "builtBy" to ":sdk:trace-shaded-deps:extractShadowJar") } @@ -16,8 +17,6 @@ sourceSets { dependencies { implementation(project(path = ":sdk:trace-shaded-deps")) - - testImplementation("org.junit.jupiter:junit-jupiter") } graalvmNative { @@ -28,7 +27,3 @@ graalvmNative { } toolchainDetection.set(false) } - -tasks.test { - useJUnitPlatform() -} diff --git a/settings.gradle.kts b/settings.gradle.kts index a3f1483c243..1f0b887f197 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,6 +5,7 @@ pluginManagement { id("com.gradle.enterprise") version "3.11.1" id("io.github.gradle-nexus.publish-plugin") version "1.1.0" id("org.jetbrains.kotlin.jvm") version "1.7.20" + id("org.graalvm.buildtools.native") version "0.9.14" } }