Skip to content

Commit a7ea29b

Browse files
committed
Reset JDKs cgroup subsystem instances
This is needed in order to get correct memory limits detected for some code paths (one of which is JFR). Reset containerMetrics and initializationTriggered static variables in JDKEvents class so as to not carry over build-time information to runtime. Similarly, reset RequestEngine.entries list to an empty list so that initialization doesn't re-add hooks added at build time. Closes: #5396
1 parent e794eb5 commit a7ea29b

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2022, 2022, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package com.oracle.svm.core.jdk;
27+
28+
import org.graalvm.nativeimage.Platform.LINUX;
29+
30+
import java.util.List;
31+
import java.util.concurrent.CopyOnWriteArrayList;
32+
33+
import org.graalvm.nativeimage.Platforms;
34+
35+
import com.oracle.svm.core.annotate.Alias;
36+
import com.oracle.svm.core.annotate.RecomputeFieldValue;
37+
import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
38+
39+
import com.oracle.svm.core.annotate.TargetClass;
40+
41+
@TargetClass(className = "jdk.internal.platform.cgroupv1.CgroupV1Subsystem")
42+
@Platforms(LINUX.class)
43+
final class Target_jdk_internal_platform_cgroupv1_CgroupV1Subsystem {
44+
@Alias //
45+
@RecomputeFieldValue(kind = Kind.Reset) //
46+
private static volatile Target_jdk_internal_platform_cgroupv1_CgroupV1Subsystem INSTANCE;
47+
}
48+
49+
@TargetClass(className = "jdk.internal.platform.cgroupv2.CgroupV2Subsystem")
50+
@Platforms(LINUX.class)
51+
final class Target_jdk_internal_platform_cgroupv2_CgroupV2Subsystem {
52+
@Alias //
53+
@RecomputeFieldValue(kind = Kind.Reset) //
54+
private static volatile Target_jdk_internal_platform_cgroupv2_CgroupV2Subsystem INSTANCE;
55+
}
56+
57+
@TargetClass(className = "jdk.jfr.internal.instrument.JDKEvents")
58+
@Platforms(LINUX.class)
59+
final class Target_jdk_jfr_internal_instrument_JDKEvents {
60+
@Alias //
61+
@RecomputeFieldValue(kind = Kind.Reset) //
62+
private static Target_jdk_internal_platform_Metrics containerMetrics;
63+
64+
@Alias //
65+
@RecomputeFieldValue(kind = Kind.Reset) //
66+
private static boolean initializationTriggered;
67+
}
68+
69+
@TargetClass(className = "jdk.jfr.internal.RequestEngine")
70+
@Platforms(LINUX.class)
71+
final class Target_jdk_jfr_internal_RequestEngine {
72+
@Alias //
73+
@RecomputeFieldValue(kind = Kind.NewInstance, declClass = CopyOnWriteArrayList.class) //
74+
private static List<?> entries;
75+
}
76+
77+
// Only present in JDKs without JDK-8268398
78+
@TargetClass(className = "jdk.jfr.internal.Utils", onlyWith = {JDK17OrEarlier.class, JDK17OrLater.class})
79+
@Platforms(LINUX.class)
80+
final class Target_jdk_jfr_internal_Utils {
81+
@Alias //
82+
@RecomputeFieldValue(kind = Kind.Reset) //
83+
private static Target_jdk_internal_platform_Metrics[] metrics;
84+
}
85+
86+
@TargetClass(className = "jdk.internal.platform.Metrics")
87+
@Platforms(LINUX.class)
88+
final class Target_jdk_internal_platform_Metrics {
89+
}
90+
91+
/** Dummy class to have a class with the file's name. */
92+
public final class JDKContainerSubstitutions {
93+
}

0 commit comments

Comments
 (0)