8334489: Add function os::used_memory

Reviewed-by: eosterlund, dholmes, stuefe
This commit is contained in:
Johan Sjölen 2024-06-24 07:51:01 +00:00
parent edf7f055ee
commit 05a63d80b9
2 changed files with 18 additions and 0 deletions

View File

@ -78,6 +78,10 @@
#include "utilities/macros.hpp"
#include "utilities/powerOfTwo.hpp"
#ifdef LINUX
#include "osContainer_linux.hpp"
#endif
#ifndef _WINDOWS
# include <poll.h>
#endif
@ -2064,6 +2068,19 @@ static void assert_nonempty_range(const char* addr, size_t bytes) {
p2i(addr), p2i(addr) + bytes);
}
julong os::used_memory() {
#ifdef LINUX
if (OSContainer::is_containerized()) {
jlong mem_usage = OSContainer::memory_usage_in_bytes();
if (mem_usage > 0) {
return mem_usage;
}
}
#endif
return os::physical_memory() - os::available_memory();
}
bool os::commit_memory(char* addr, size_t bytes, bool executable) {
assert_nonempty_range(addr, bytes);
bool res = pd_commit_memory(addr, bytes, executable);

View File

@ -336,6 +336,7 @@ class os: AllStatic {
// than "free" memory (`MemFree` in `/proc/meminfo`) because Linux can free memory
// aggressively (e.g. clear caches) so that it becomes available.
static julong available_memory();
static julong used_memory();
static julong free_memory();
static jlong total_swap_space();