Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/hotspot/os/linux/os_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
#include "utilities/globalDefinitions.hpp"
#include "utilities/growableArray.hpp"
#include "utilities/macros.hpp"
// SapMachine 2026-11-01
#include "utilities/permitForbiddenFunctions.hpp"
#include "utilities/powerOfTwo.hpp"
#include "utilities/vmError.hpp"
#if INCLUDE_JFR
Expand Down Expand Up @@ -2484,6 +2486,9 @@ static bool is_numerical_id(const char* s) {
bool os::Linux::get_total_procs_and_threads(uint64_t* procs, uint64_t* threads) {
TraceTime timer("Iterating all processes", TRACETIME_LOG(Trace, os, timer));
DIR* d = ::opendir("/proc");
size_t line_length = 256;
char* line_buf = threads == nullptr ? nullptr : (char*) permit_forbidden_function::malloc(line_length);
bool result = false;
if (d != nullptr) {
uint64_t procs_count = 0;
uint64_t threads_count = 0;
Expand All @@ -2503,8 +2508,15 @@ bool os::Linux::get_total_procs_and_threads(uint64_t* procs, uint64_t* threads)
// See man proc(5)
// (20) num_threads %ld
long num_threads = 0;
if (fscanf(fp, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %*d %*d %ld", &num_threads) == 1) {
threads_count += num_threads;
if (getline(&line_buf, &line_length, fp) > 0) {
char* prefix_end = strrchr(line_buf, ')');

if (prefix_end != nullptr) {
if (sscanf(prefix_end + 1, " %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %*d %*d %ld",
&num_threads) == 1) {
threads_count += num_threads;
}
}
}
::fclose(fp);
}
Expand All @@ -2519,10 +2531,12 @@ bool os::Linux::get_total_procs_and_threads(uint64_t* procs, uint64_t* threads)
*threads = threads_count;
}

return true;
result = true;
}

return false;
permit_forbidden_function::free(line_buf);

return result;
}

#ifdef __GLIBC__
Expand Down