Skip to content

Commit 1317d89

Browse files
committed
use jdk21
1 parent 75c35fc commit 1317d89

File tree

11 files changed

+80
-35
lines changed

11 files changed

+80
-35
lines changed

conventions/src/main/kotlin/io/opentelemetry/instrumentation/gradle/OtelJavaExtension.kt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.gradle.api.provider.Property
1010

1111
abstract class OtelJavaExtension {
1212
abstract val minJavaVersionSupported: Property<JavaVersion>
13+
abstract val maxJavaVersionSupported: Property<JavaVersion>
1314

1415
abstract val maxJavaVersionForTests: Property<JavaVersion>
1516

conventions/src/main/kotlin/otel.java-conventions.gradle.kts

+12-2
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ afterEvaluate {
2727
}
2828

2929
// Version to use to compile code and run tests.
30-
val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_17
30+
val DEFAULT_JAVA_VERSION = JavaVersion.VERSION_21
3131

3232
java {
3333
toolchain {
3434
languageVersion.set(
35-
otelJava.minJavaVersionSupported.map { JavaLanguageVersion.of(Math.max(it.majorVersion.toInt(), DEFAULT_JAVA_VERSION.majorVersion.toInt())) }
35+
otelJava.minJavaVersionSupported.map {
36+
val defaultJavaVersion = otelJava.maxJavaVersionSupported.getOrElse(DEFAULT_JAVA_VERSION).majorVersion.toInt()
37+
JavaLanguageVersion.of(Math.max(it.majorVersion.toInt(), defaultJavaVersion))
38+
}
3639
)
3740
}
3841

@@ -69,11 +72,18 @@ tasks.withType<JavaCompile>().configureEach {
6972
"-Xlint:-processing",
7073
// We suppress the "options" warning because it prevents compilation on modern JDKs
7174
"-Xlint:-options",
75+
// jdk21 generates more serial warnings than previous versions
76+
"-Xlint:-serial",
7277

7378
// Fail build on any warning
7479
"-Werror"
7580
)
7681
)
82+
val defaultJavaVersion = otelJava.maxJavaVersionSupported.getOrElse(DEFAULT_JAVA_VERSION).majorVersion.toInt()
83+
if (Math.max(otelJava.minJavaVersionSupported.get().majorVersion.toInt(), defaultJavaVersion) >= 21) {
84+
// new warning in jdk21
85+
compilerArgs.add("-Xlint:-this-escape")
86+
}
7787
}
7888

7989
encoding = "UTF-8"

instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/ExecutorInstrumentationTest.java

-22
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
99
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
10-
import java.lang.reflect.InvocationTargetException;
11-
import java.lang.reflect.Method;
1210
import java.util.Collection;
1311
import java.util.Collections;
1412
import java.util.List;
@@ -26,8 +24,6 @@
2624
import java.util.concurrent.ThreadPoolExecutor;
2725
import java.util.concurrent.TimeUnit;
2826
import org.junit.jupiter.api.Test;
29-
import org.junit.jupiter.api.condition.EnabledForJreRange;
30-
import org.junit.jupiter.api.condition.JRE;
3127
import org.junit.jupiter.api.extension.RegisterExtension;
3228

3329
abstract class ExecutorInstrumentationTest<T extends ExecutorService>
@@ -51,24 +47,6 @@ static class ThreadPoolExecutorTest extends ExecutorInstrumentationTest<ThreadPo
5147
}
5248
}
5349

54-
@EnabledForJreRange(min = JRE.JAVA_21)
55-
static class VirtualThreadExecutorTest extends ExecutorInstrumentationTest<ExecutorService> {
56-
VirtualThreadExecutorTest() {
57-
super(newVirtualThreadPerTaskExecutor());
58-
}
59-
60-
private static ExecutorService newVirtualThreadPerTaskExecutor() {
61-
Method newVirtualThreadPerTaskExecutor;
62-
try {
63-
newVirtualThreadPerTaskExecutor =
64-
Executors.class.getMethod("newVirtualThreadPerTaskExecutor");
65-
return (ExecutorService) newVirtualThreadPerTaskExecutor.invoke(null);
66-
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
67-
throw new IllegalStateException("Should not happen on Java 21+", e);
68-
}
69-
}
70-
}
71-
7250
static class WorkStealingPoolTest extends ExecutorInstrumentationTest<ExecutorService> {
7351
public WorkStealingPoolTest() {
7452
super(Executors.newWorkStealingPool(2));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plugins {
2+
id("otel.javaagent-testing")
3+
}
4+
5+
dependencies {
6+
testInstrumentation(project(":instrumentation:executors:javaagent"))
7+
8+
testCompileOnly(project(":instrumentation:executors:bootstrap"))
9+
testImplementation(project(":instrumentation:executors:testing"))
10+
}
11+
12+
otelJava {
13+
minJavaVersionSupported.set(JavaVersion.VERSION_21)
14+
}
15+
16+
tasks.withType<Test>().configureEach {
17+
// needed for VirtualThreadTest
18+
jvmArgs("--add-opens=java.base/java.lang=ALL-UNNAMED")
19+
jvmArgs("-XX:+IgnoreUnrecognizedVMOptions")
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.executors;
7+
8+
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
9+
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
10+
import java.util.concurrent.ExecutorService;
11+
import java.util.concurrent.Executors;
12+
import org.junit.jupiter.api.extension.RegisterExtension;
13+
14+
class VirtualThreadExecutorTest
15+
extends AbstractExecutorServiceTest<ExecutorService, JavaAsyncChild> {
16+
17+
@RegisterExtension
18+
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();
19+
20+
VirtualThreadExecutorTest() {
21+
super(Executors.newVirtualThreadPerTaskExecutor(), testing);
22+
}
23+
24+
@Override
25+
protected JavaAsyncChild newTask(boolean doTraceableWork, boolean blockThread) {
26+
return new JavaAsyncChild(doTraceableWork, blockThread);
27+
}
28+
}

instrumentation/executors/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadTest.java instrumentation/executors/jdk21-testing/src/test/java/io/opentelemetry/javaagent/instrumentation/executors/VirtualThreadTest.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,13 @@
1212
import java.util.concurrent.Callable;
1313
import java.util.concurrent.atomic.AtomicBoolean;
1414
import org.junit.jupiter.api.Test;
15-
import org.junit.jupiter.api.condition.EnabledForJreRange;
16-
import org.junit.jupiter.api.condition.JRE;
1715

18-
@EnabledForJreRange(min = JRE.JAVA_21)
1916
class VirtualThreadTest {
2017

2118
@Test
2219
void testDisableContextPropagation() throws Exception {
2320
TestRunnable testRunnable = new TestRunnable();
24-
// Thread.ofVirtual().start(testRunnable);
25-
Method ofVirtualMethod = Thread.class.getMethod("ofVirtual");
26-
Object virtualThreadBuilder = ofVirtualMethod.invoke(null);
27-
Method startVirtualThread =
28-
Class.forName("java.lang.Thread$Builder").getMethod("start", Runnable.class);
29-
Thread thread = (Thread) startVirtualThread.invoke(virtualThreadBuilder, testRunnable);
21+
Thread thread = Thread.ofVirtual().start(testRunnable);
3022
thread.join();
3123

3224
assertThat(testRunnable.error).isNull();
+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.concurrent.ForkJoinTask;
1212
import java.util.concurrent.atomic.AtomicBoolean;
1313

14+
@SuppressWarnings("serial")
1415
final class JavaAsyncChild extends ForkJoinTask<Object> implements TestTask {
1516
private static final Tracer tracer = GlobalOpenTelemetry.getTracer("test");
1617

instrumentation/grails-3.0/javaagent/build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ muzzle {
1818
}
1919
}
2020

21+
otelJava {
22+
maxJavaVersionSupported.set(JavaVersion.VERSION_17)
23+
}
24+
2125
val grailsVersion = "3.0.6" // first version that the tests pass on
2226
val springBootVersion = "1.2.5.RELEASE"
2327

instrumentation/zio/zio-2.0/javaagent/build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ muzzle {
2828
}
2929
}
3030

31+
otelJava {
32+
maxJavaVersionSupported.set(JavaVersion.VERSION_17)
33+
}
34+
3135
dependencies {
3236
compileOnly("dev.zio:zio_$scalaVersion:$zioVersion")
3337

muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceMatcher.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,19 @@ private static MethodDescription.InDefinedShape findMethod(
294294
return null;
295295
}
296296

297+
TypeDescription superType = null;
297298
if (typeOnClasspath.getSuperClass() != null) {
298-
MethodDescription.InDefinedShape methodOnSupertype =
299-
findMethod(methodRef, typeOnClasspath.getSuperClass().asErasure());
299+
superType = typeOnClasspath.getSuperClass().asErasure();
300+
} else if (!"java.lang.Object".equals(typeOnClasspath.getName())) {
301+
superType = TypeDescription.ForLoadedType.of(Object.class);
302+
}
303+
if (superType != null) {
304+
MethodDescription.InDefinedShape methodOnSupertype = findMethod(methodRef, superType);
300305
if (methodOnSupertype != null) {
301306
return methodOnSupertype;
302307
}
303308
}
309+
304310
for (TypeDescription.Generic interfaceType : typeOnClasspath.getInterfaces()) {
305311
MethodDescription.InDefinedShape methodOnSupertype =
306312
findMethod(methodRef, interfaceType.asErasure());

settings.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ include(":instrumentation:elasticsearch:elasticsearch-transport-common:javaagent
225225
include(":instrumentation:elasticsearch:elasticsearch-transport-common:testing")
226226
include(":instrumentation:executors:bootstrap")
227227
include(":instrumentation:executors:javaagent")
228+
include(":instrumentation:executors:jdk21-testing")
228229
include(":instrumentation:executors:testing")
229230
include(":instrumentation:external-annotations:javaagent")
230231
include(":instrumentation:external-annotations:javaagent-unit-tests")

0 commit comments

Comments
 (0)