From 88c493cc7682ca5c31efc7b26284803aa7f55743 Mon Sep 17 00:00:00 2001 From: Stuart McCulloch Date: Thu, 19 Dec 2024 19:26:05 +0000 Subject: [PATCH] Remove unused Platform.GC code (#8115) * Remove unused Platform.GC code; add warning about accessing JMX too early * temporarily turn off DDProf due to PROF-11066 --- .../smoketest/Java9ModulesSmokeTest.groovy | 3 ++ internal-api/build.gradle | 1 - .../main/java/datadog/trace/api/Platform.java | 42 ++----------------- 3 files changed, 7 insertions(+), 39 deletions(-) diff --git a/dd-smoke-tests/java9-modules/src/test/groovy/datadog/smoketest/Java9ModulesSmokeTest.groovy b/dd-smoke-tests/java9-modules/src/test/groovy/datadog/smoketest/Java9ModulesSmokeTest.groovy index dd9dbef7275..d5d57f9b45e 100644 --- a/dd-smoke-tests/java9-modules/src/test/groovy/datadog/smoketest/Java9ModulesSmokeTest.groovy +++ b/dd-smoke-tests/java9-modules/src/test/groovy/datadog/smoketest/Java9ModulesSmokeTest.groovy @@ -15,6 +15,9 @@ class Java9ModulesSmokeTest extends AbstractSmokeTest { List command = new ArrayList<>() command.add(imageDir + "/bin/java") command.addAll(defaultJavaProperties) + // temporarily turn off DDProf due to PROF-11066 + command.removeAll { it.startsWith("-Ddd.profiling.ddprof.enabled") } + command.add("-Ddd.profiling.ddprof.enabled=false") command.addAll((String[]) ["-m", "datadog.smoketest.moduleapp/datadog.smoketest.moduleapp.ModuleApplication"]) ProcessBuilder processBuilder = new ProcessBuilder(command) processBuilder.directory(new File(buildDirectory)) diff --git a/internal-api/build.gradle b/internal-api/build.gradle index 7176c43d500..f62b6ec81a3 100644 --- a/internal-api/build.gradle +++ b/internal-api/build.gradle @@ -27,7 +27,6 @@ minimumInstructionCoverage = 0.8 excludedClassesCoverage += [ "datadog.trace.api.EndpointTracker", "datadog.trace.api.Platform", - "datadog.trace.api.Platform.GC", "datadog.trace.api.StatsDClient", "datadog.trace.api.NoOpStatsDClient", "datadog.trace.api.TraceSegment.NoOp", diff --git a/internal-api/src/main/java/datadog/trace/api/Platform.java b/internal-api/src/main/java/datadog/trace/api/Platform.java index bda9b965e6b..f14eac480bd 100644 --- a/internal-api/src/main/java/datadog/trace/api/Platform.java +++ b/internal-api/src/main/java/datadog/trace/api/Platform.java @@ -1,11 +1,13 @@ package datadog.trace.api; -import java.lang.management.GarbageCollectorMXBean; -import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.List; import java.util.Locale; +/** + * This class is used early on during premain; it must not touch features like JMX or JUL in case + * they trigger early loading/binding. + */ public final class Platform { // A helper class to capture whether the executable is a native image or not. // This class needs to be iniatlized at build only during the AOT compilation and build. @@ -13,49 +15,13 @@ private static class Captured { public static final boolean isNativeImage = checkForNativeImageBuilder(); } - public enum GC { - SERIAL("marksweep"), - PARALLEL("ps"), - CMS("concurrentmarksweep"), - G1("g1"), - SHENANDOAH("shenandoah"), - Z("z"), - UNKNOWN(""); - - private final String identifierPrefix; - - GC(String identifierPrefix) { - this.identifierPrefix = identifierPrefix; - } - - static GC current() { - for (GarbageCollectorMXBean mxBean : ManagementFactory.getGarbageCollectorMXBeans()) { - if (mxBean.isValid()) { - String name = mxBean.getName().toLowerCase(Locale.ROOT); - for (GC gc : GC.values()) { - if (gc != UNKNOWN && name.startsWith(gc.identifierPrefix)) { - return gc; - } - } - } - } - return UNKNOWN; - } - } - private static final Version JAVA_VERSION = parseJavaVersion(System.getProperty("java.version")); private static final JvmRuntime RUNTIME = new JvmRuntime(); - private static final GC GARBAGE_COLLECTOR = GC.current(); - private static final boolean HAS_JFR = checkForJfr(); private static final boolean IS_NATIVE_IMAGE_BUILDER = checkForNativeImageBuilder(); private static final boolean IS_NATIVE_IMAGE = Captured.isNativeImage; - public static GC activeGarbageCollector() { - return GARBAGE_COLLECTOR; - } - public static boolean hasJfr() { return HAS_JFR; }