|
1 | 1 | package datadog.trace.api; |
2 | 2 |
|
3 | | -import java.lang.management.GarbageCollectorMXBean; |
4 | | -import java.lang.management.ManagementFactory; |
5 | 3 | import java.util.ArrayList; |
6 | 4 | import java.util.List; |
7 | 5 | import java.util.Locale; |
8 | 6 |
|
| 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 | + */ |
9 | 11 | public final class Platform { |
10 | 12 | // A helper class to capture whether the executable is a native image or not. |
11 | 13 | // This class needs to be iniatlized at build only during the AOT compilation and build. |
12 | 14 | private static class Captured { |
13 | 15 | public static final boolean isNativeImage = checkForNativeImageBuilder(); |
14 | 16 | } |
15 | 17 |
|
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 | | - |
46 | 18 | private static final Version JAVA_VERSION = parseJavaVersion(System.getProperty("java.version")); |
47 | 19 | private static final JvmRuntime RUNTIME = new JvmRuntime(); |
48 | 20 |
|
49 | | - private static final GC GARBAGE_COLLECTOR = GC.current(); |
50 | | - |
51 | 21 | private static final boolean HAS_JFR = checkForJfr(); |
52 | 22 | private static final boolean IS_NATIVE_IMAGE_BUILDER = checkForNativeImageBuilder(); |
53 | 23 | private static final boolean IS_NATIVE_IMAGE = Captured.isNativeImage; |
54 | 24 |
|
55 | | - public static GC activeGarbageCollector() { |
56 | | - return GARBAGE_COLLECTOR; |
57 | | - } |
58 | | - |
59 | 25 | public static boolean hasJfr() { |
60 | 26 | return HAS_JFR; |
61 | 27 | } |
|
0 commit comments