Skip to content

Commit 2573f44

Browse files
committed
Remove unused Platform.GC code; add warning about accessing JMX too early
1 parent 90899e0 commit 2573f44

File tree

2 files changed

+4
-39
lines changed

2 files changed

+4
-39
lines changed

internal-api/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ minimumInstructionCoverage = 0.8
2727
excludedClassesCoverage += [
2828
"datadog.trace.api.EndpointTracker",
2929
"datadog.trace.api.Platform",
30-
"datadog.trace.api.Platform.GC",
3130
"datadog.trace.api.StatsDClient",
3231
"datadog.trace.api.NoOpStatsDClient",
3332
"datadog.trace.api.TraceSegment.NoOp",

internal-api/src/main/java/datadog/trace/api/Platform.java

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,27 @@
11
package datadog.trace.api;
22

3-
import java.lang.management.GarbageCollectorMXBean;
4-
import java.lang.management.ManagementFactory;
53
import java.util.ArrayList;
64
import java.util.List;
75
import java.util.Locale;
86

7+
/**
8+
* This class is used early on during premain; it must not touch features like JMX or JUL in case
9+
* they trigger early loading/binding.
10+
*/
911
public final class Platform {
1012
// A helper class to capture whether the executable is a native image or not.
1113
// This class needs to be iniatlized at build only during the AOT compilation and build.
1214
private static class Captured {
1315
public static final boolean isNativeImage = checkForNativeImageBuilder();
1416
}
1517

16-
public enum GC {
17-
SERIAL("marksweep"),
18-
PARALLEL("ps"),
19-
CMS("concurrentmarksweep"),
20-
G1("g1"),
21-
SHENANDOAH("shenandoah"),
22-
Z("z"),
23-
UNKNOWN("");
24-
25-
private final String identifierPrefix;
26-
27-
GC(String identifierPrefix) {
28-
this.identifierPrefix = identifierPrefix;
29-
}
30-
31-
static GC current() {
32-
for (GarbageCollectorMXBean mxBean : ManagementFactory.getGarbageCollectorMXBeans()) {
33-
if (mxBean.isValid()) {
34-
String name = mxBean.getName().toLowerCase(Locale.ROOT);
35-
for (GC gc : GC.values()) {
36-
if (gc != UNKNOWN && name.startsWith(gc.identifierPrefix)) {
37-
return gc;
38-
}
39-
}
40-
}
41-
}
42-
return UNKNOWN;
43-
}
44-
}
45-
4618
private static final Version JAVA_VERSION = parseJavaVersion(System.getProperty("java.version"));
4719
private static final JvmRuntime RUNTIME = new JvmRuntime();
4820

49-
private static final GC GARBAGE_COLLECTOR = GC.current();
50-
5121
private static final boolean HAS_JFR = checkForJfr();
5222
private static final boolean IS_NATIVE_IMAGE_BUILDER = checkForNativeImageBuilder();
5323
private static final boolean IS_NATIVE_IMAGE = Captured.isNativeImage;
5424

55-
public static GC activeGarbageCollector() {
56-
return GARBAGE_COLLECTOR;
57-
}
58-
5925
public static boolean hasJfr() {
6026
return HAS_JFR;
6127
}

0 commit comments

Comments
 (0)