Skip to content

Commit

Permalink
Remove unused Platform.GC code (#8115)
Browse files Browse the repository at this point in the history
* Remove unused Platform.GC code; add warning about accessing JMX too early
* temporarily turn off DDProf due to PROF-11066
  • Loading branch information
mcculls authored Dec 19, 2024
1 parent 90899e0 commit 88c493c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ class Java9ModulesSmokeTest extends AbstractSmokeTest {
List<String> 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))
Expand Down
1 change: 0 additions & 1 deletion internal-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
42 changes: 4 additions & 38 deletions internal-api/src/main/java/datadog/trace/api/Platform.java
Original file line number Diff line number Diff line change
@@ -1,61 +1,27 @@
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.
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;
}
Expand Down

0 comments on commit 88c493c

Please sign in to comment.