Skip to content

Commit 006b59b

Browse files
committed
svm: reapply the libcontainer changes
1 parent 652bca9 commit 006b59b

31 files changed

+332
-67
lines changed

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/cgroupSubsystem_linux.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*
55
* This code is free software; you can redistribute it and/or modify it
66
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation.
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.
810
*
911
* This code is distributed in the hope that it will be useful, but WITHOUT
1012
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -19,7 +21,6 @@
1921
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2022
* or visit www.oracle.com if you need additional information or have any
2123
* questions.
22-
*
2324
*/
2425

2526
#include <string.h>
@@ -893,7 +894,9 @@ jlong CgroupSubsystem::cpu_usage_in_micros() {
893894
return cpuacct_controller()->cpu_usage_in_micros();
894895
}
895896

897+
#ifndef NATIVE_IMAGE
896898
void CgroupSubsystem::print_version_specific_info(outputStream* st) {
897899
julong phys_mem = os::Linux::physical_memory();
898900
memory_controller()->controller()->print_version_specific_info(st, phys_mem);
899901
}
902+
#endif // !NATIVE_IMAGE

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/cgroupSubsystem_linux.hpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*
55
* This code is free software; you can redistribute it and/or modify it
66
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation.
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.
810
*
911
* This code is distributed in the hope that it will be useful, but WITHOUT
1012
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -19,7 +21,6 @@
1921
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2022
* or visit www.oracle.com if you need additional information or have any
2123
* questions.
22-
*
2324
*/
2425

2526
#ifndef CGROUP_SUBSYSTEM_LINUX_HPP
@@ -172,17 +173,24 @@ class CachedMetric : public CHeapObj<mtInternal>{
172173
_next_check_counter = min_jlong;
173174
}
174175
bool should_check_metric() {
176+
#ifdef NATIVE_IMAGE
177+
// NOTE (chaeubl): we do all caching on the Java-side instead of the C-side
178+
return true;
179+
#else
175180
return os::elapsed_counter() > _next_check_counter;
181+
#endif // NATIVE_IMAGE
176182
}
177183
jlong value() { return _metric; }
178184
void set_value(jlong value, jlong timeout) {
179185
_metric = value;
186+
#ifndef NATIVE_IMAGE
180187
// Metric is unlikely to change, but we want to remain
181188
// responsive to configuration changes. A very short grace time
182189
// between re-read avoids excessive overhead during startup without
183190
// significantly reducing the VMs ability to promptly react to changed
184191
// metric config
185192
_next_check_counter = os::elapsed_counter() + timeout;
193+
#endif // !NATIVE_IMAGE
186194
}
187195
};
188196

@@ -240,7 +248,9 @@ class CgroupMemoryController: public CHeapObj<mtInternal> {
240248
virtual jlong memory_max_usage_in_bytes() = 0;
241249
virtual jlong rss_usage_in_bytes() = 0;
242250
virtual jlong cache_usage_in_bytes() = 0;
251+
#ifndef NATIVE_IMAGE
243252
virtual void print_version_specific_info(outputStream* st, julong host_mem) = 0;
253+
#endif // !NATIVE_IMAGE
244254
virtual bool needs_hierarchy_adjustment() = 0;
245255
virtual bool is_read_only() = 0;
246256
virtual const char* subsystem_path() = 0;
@@ -279,7 +289,9 @@ class CgroupSubsystem: public CHeapObj<mtInternal> {
279289
jlong memory_max_usage_in_bytes();
280290
jlong rss_usage_in_bytes();
281291
jlong cache_usage_in_bytes();
292+
#ifndef NATIVE_IMAGE
282293
void print_version_specific_info(outputStream* st);
294+
#endif // !NATIVE_IMAGE
283295
};
284296

285297
// Utility class for storing info retrieved from /proc/cgroups,

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/cgroupUtil_linux.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/*
2-
* Copyright (c) 2024, 2025, Red Hat, Inc.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2024, 2025, Red Hat Inc. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
67
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation.
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
811
*
912
* This code is distributed in the hope that it will be useful, but WITHOUT
1013
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -19,7 +22,6 @@
1922
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2023
* or visit www.oracle.com if you need additional information or have any
2124
* questions.
22-
*
2325
*/
2426

2527
#include "os_linux.hpp"

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/cgroupUtil_linux.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
/*
2-
* Copyright (c) 2024, Red Hat, Inc.
2+
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2024, 2024, Red Hat Inc. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
67
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation.
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
811
*
912
* This code is distributed in the hope that it will be useful, but WITHOUT
1013
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -19,7 +22,6 @@
1922
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2023
* or visit www.oracle.com if you need additional information or have any
2124
* questions.
22-
*
2325
*/
2426

2527
#ifndef CGROUP_UTIL_LINUX_HPP

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*
55
* This code is free software; you can redistribute it and/or modify it
66
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation.
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.
810
*
911
* This code is distributed in the hope that it will be useful, but WITHOUT
1012
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -19,7 +21,6 @@
1921
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2022
* or visit www.oracle.com if you need additional information or have any
2123
* questions.
22-
*
2324
*/
2425

2526
#include <string.h>
@@ -350,6 +351,7 @@ jlong CgroupV1MemoryController::kernel_memory_max_usage_in_bytes() {
350351
return (jlong)kmem_max_usage;
351352
}
352353

354+
#ifndef NATIVE_IMAGE
353355
void CgroupV1MemoryController::print_version_specific_info(outputStream* st, julong phys_mem) {
354356
jlong kmem_usage = kernel_memory_usage_in_bytes();
355357
jlong kmem_limit = kernel_memory_limit_in_bytes(phys_mem);
@@ -359,6 +361,7 @@ void CgroupV1MemoryController::print_version_specific_info(outputStream* st, jul
359361
OSContainer::print_container_helper(st, kmem_usage, "kernel_memory_usage_in_bytes");
360362
OSContainer::print_container_helper(st, kmem_max_usage, "kernel_memory_max_usage_in_bytes");
361363
}
364+
#endif // !NATIVE_IMAGE
362365

363366
char* CgroupV1Subsystem::cpu_cpuset_cpus() {
364367
char cpus[1024];

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/cgroupV1Subsystem_linux.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*
55
* This code is free software; you can redistribute it and/or modify it
66
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation.
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.
810
*
911
* This code is distributed in the hope that it will be useful, but WITHOUT
1012
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -19,7 +21,6 @@
1921
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2022
* or visit www.oracle.com if you need additional information or have any
2123
* questions.
22-
*
2324
*/
2425

2526
#ifndef CGROUP_V1_SUBSYSTEM_LINUX_HPP
@@ -89,7 +90,9 @@ class CgroupV1MemoryController final : public CgroupMemoryController {
8990
jlong kernel_memory_usage_in_bytes();
9091
jlong kernel_memory_limit_in_bytes(julong host_mem);
9192
jlong kernel_memory_max_usage_in_bytes();
93+
#ifndef NATIVE_IMAGE
9294
void print_version_specific_info(outputStream* st, julong host_mem) override;
95+
#endif // !NATIVE_IMAGE
9396
bool needs_hierarchy_adjustment() override {
9497
return reader()->needs_hierarchy_adjustment();
9598
}

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/cgroupV2Subsystem_linux.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
2-
* Copyright (c) 2020, 2025, Red Hat Inc.
32
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2020, 2025, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
77
* under the terms of the GNU General Public License version 2 only, as
8-
* published by the Free Software Foundation.
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
911
*
1012
* This code is distributed in the hope that it will be useful, but WITHOUT
1113
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -20,7 +22,6 @@
2022
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2123
* or visit www.oracle.com if you need additional information or have any
2224
* questions.
23-
*
2425
*/
2526

2627
#include "cgroupV2Subsystem_linux.hpp"
@@ -327,13 +328,15 @@ bool CgroupV2Controller::needs_hierarchy_adjustment() {
327328
return strcmp(_cgroup_path, "/") != 0;
328329
}
329330

331+
#ifndef NATIVE_IMAGE
330332
void CgroupV2MemoryController::print_version_specific_info(outputStream* st, julong phys_mem) {
331333
jlong swap_current = memory_swap_current_value(reader());
332334
jlong swap_limit = memory_swap_limit_value(reader());
333335

334336
OSContainer::print_container_helper(st, swap_current, "memory_swap_current_in_bytes");
335337
OSContainer::print_container_helper(st, swap_limit, "memory_swap_max_limit_in_bytes");
336338
}
339+
#endif // !NATIVE_IMAGE
337340

338341
char* CgroupV2Controller::construct_path(char* mount_path, const char* cgroup_path) {
339342
stringStream ss;

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/cgroupV2Subsystem_linux.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
2-
* Copyright (c) 2020, 2024, Red Hat Inc.
32
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2020, 2024, Red Hat Inc. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
66
* This code is free software; you can redistribute it and/or modify it
77
* under the terms of the GNU General Public License version 2 only, as
8-
* published by the Free Software Foundation.
8+
* published by the Free Software Foundation. Oracle designates this
9+
* particular file as subject to the "Classpath" exception as provided
10+
* by Oracle in the LICENSE file that accompanied this code.
911
*
1012
* This code is distributed in the hope that it will be useful, but WITHOUT
1113
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -20,7 +22,6 @@
2022
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2123
* or visit www.oracle.com if you need additional information or have any
2224
* questions.
23-
*
2425
*/
2526

2627
#ifndef CGROUP_V2_SUBSYSTEM_LINUX_HPP
@@ -123,7 +124,9 @@ class CgroupV2MemoryController final: public CgroupMemoryController {
123124
jlong memory_max_usage_in_bytes() override;
124125
jlong rss_usage_in_bytes() override;
125126
jlong cache_usage_in_bytes() override;
127+
#ifndef NATIVE_IMAGE
126128
void print_version_specific_info(outputStream* st, julong host_mem) override;
129+
#endif // !NATIVE_IMAGE
127130
bool is_read_only() override {
128131
return reader()->is_read_only();
129132
}

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/osContainer_linux.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*
55
* This code is free software; you can redistribute it and/or modify it
66
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation.
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.
810
*
911
* This code is distributed in the hope that it will be useful, but WITHOUT
1012
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -19,7 +21,6 @@
1921
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2022
* or visit www.oracle.com if you need additional information or have any
2123
* questions.
22-
*
2324
*/
2425

2526
#include <string.h>
@@ -147,10 +148,12 @@ jlong OSContainer::cache_usage_in_bytes() {
147148
return cgroup_subsystem->cache_usage_in_bytes();
148149
}
149150

151+
#ifndef NATIVE_IMAGE
150152
void OSContainer::print_version_specific_info(outputStream* st) {
151153
assert(cgroup_subsystem != nullptr, "cgroup subsystem not available");
152154
cgroup_subsystem->print_version_specific_info(st);
153155
}
156+
#endif // !NATIVE_IMAGE
154157

155158
char * OSContainer::cpu_cpuset_cpus() {
156159
assert(cgroup_subsystem != nullptr, "cgroup subsystem not available");
@@ -197,6 +200,7 @@ jlong OSContainer::pids_current() {
197200
return cgroup_subsystem->pids_current();
198201
}
199202

203+
#ifndef NATIVE_IMAGE
200204
void OSContainer::print_container_helper(outputStream* st, jlong j, const char* metrics) {
201205
st->print("%s: ", metrics);
202206
if (j >= 0) {
@@ -209,3 +213,4 @@ void OSContainer::print_container_helper(outputStream* st, jlong j, const char*
209213
st->print_cr("%s", j == OSCONTAINER_ERROR ? "not supported" : "unlimited");
210214
}
211215
}
216+
#endif // !NATIVE_IMAGE

substratevm/src/com.oracle.svm.native.libcontainer/src/hotspot/os/linux/osContainer_linux.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
*
55
* This code is free software; you can redistribute it and/or modify it
66
* under the terms of the GNU General Public License version 2 only, as
7-
* published by the Free Software Foundation.
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.
810
*
911
* This code is distributed in the hope that it will be useful, but WITHOUT
1012
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
@@ -19,7 +21,6 @@
1921
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2022
* or visit www.oracle.com if you need additional information or have any
2123
* questions.
22-
*
2324
*/
2425

2526
#ifndef OS_LINUX_OSCONTAINER_LINUX_HPP
@@ -44,8 +45,10 @@ class OSContainer: AllStatic {
4445

4546
public:
4647
static void init();
48+
#ifndef NATIVE_IMAGE
4749
static void print_version_specific_info(outputStream* st);
4850
static void print_container_helper(outputStream* st, jlong j, const char* metrics);
51+
#endif // !NATIVE_IMAGE
4952

5053
static inline bool is_containerized();
5154
static const char * container_type();

0 commit comments

Comments
 (0)