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
39 changes: 17 additions & 22 deletions src/hotspot/os/bsd/os_bsd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,17 @@ physical_memory_size_type os::Machine::physical_memory() {
return Bsd::physical_memory();
}

static int bsd_get_procinfo(pid_t pid, struct KINFO_PROC_T *kp, size_t *bufSize) {
int mib[] = {CTL_KERN, KERN_PROC_MIB, KERN_PROC_PID, pid,
# if !defined(__FreeBSD__) && !defined(__APPLE__)
static_cast<int>(*bufSize), 1
# endif
};
const u_int namelen = sizeof(mib)/sizeof(mib[0]);

return sysctl(mib, namelen, kp, bufSize, nullptr, 0);
}

size_t os::rss() {
size_t rss = 0;
#ifdef __APPLE__
Expand All @@ -366,19 +377,11 @@ size_t os::rss() {
rss = info.resident_size;
}
#else
pid_t pid = getpid();
struct KINFO_PROC_T kp;
size_t bufSize = sizeof kp;
#ifndef __FreeBSD__
u_int namelen = 6;
int mib[6] = {CTL_KERN, KERN_PROC_MIB, KERN_PROC_PID, pid,
static_cast<int>(bufSize), 1};
#else
u_int namelen = 4;
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, pid};
#endif
if (sysctl(mib, namelen, &kp, &bufSize, nullptr, 0) != -1) {
return kp.KI_RSS * getpagesize();
size_t bufSize = sizeof(kp);

if (bsd_get_procinfo(getpid(), &kp, &bufSize) != -1) {
rss = kp.KI_RSS * getpagesize();
}
#endif // __APPLE__

Expand Down Expand Up @@ -1034,17 +1037,9 @@ pid_t os::Bsd::gettid() {

// Returns the uid of a process or -1 on error.
uid_t os::Bsd::get_process_uid(pid_t pid) {
struct KINFO_PROC_T kp;
struct kinfo_proc kp;
size_t size = sizeof kp;
#if defined(__FreeBSD__) || defined(__APPLE__)
u_int namelen = 4;
int mib_kern[4] = {CTL_KERN, KERN_PROC_MIB, KERN_PROC_PID, pid};
#else
u_int namelen = 6;
int mib_kern[6] = {CTL_KERN, KERN_PROC_MIB, KERN_PROC_PID, pid,
static_cast<int>(size), 1};
#endif
if (sysctl(mib_kern, namelen, &kp, &size, nullptr, 0) == 0) {
if (bsd_get_procinfo(pid, &kp, &size) == 0) {
if (size > 0 && kp.KI_PID == pid) {
return kp.KI_UID;
}
Expand Down
Loading