< prev index next >
src/jdk.management/unix/native/libmanagement_ext/OperatingSystemImpl.c
Print this page
rev 59383 : [mq]: final
*** 1,7 ****
/*
! * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 83,149 ****
#endif
// true = get available swap in bytes
// false = get total swap in bytes
static jlong get_total_or_available_swap_space_size(JNIEnv* env, jboolean available) {
! #ifdef __solaris__
! long total, avail;
! int nswap, i, count;
! swaptbl_t *stbl;
! char *strtab;
!
! // First get the number of swap resource entries
! if ((nswap = swapctl(SC_GETNSWP, NULL)) == -1) {
! throw_internal_error(env, "swapctl failed to get nswap");
! return -1;
! }
! if (nswap == 0) {
! return 0;
! }
!
! // Allocate storage for resource entries
! stbl = (swaptbl_t*) malloc(nswap * sizeof(swapent_t) +
! sizeof(struct swaptable));
! if (stbl == NULL) {
! JNU_ThrowOutOfMemoryError(env, 0);
! return -1;
! }
!
! // Allocate storage for the table
! strtab = (char*) malloc((nswap + 1) * MAXPATHLEN);
! if (strtab == NULL) {
! free(stbl);
! JNU_ThrowOutOfMemoryError(env, 0);
! return -1;
! }
!
! for (i = 0; i < (nswap + 1); i++) {
! stbl->swt_ent[i].ste_path = strtab + (i * MAXPATHLEN);
! }
! stbl->swt_n = nswap + 1;
!
! // Get the entries
! if ((count = swapctl(SC_LIST, stbl)) < 0) {
! free(stbl);
! free(strtab);
! throw_internal_error(env, "swapctl failed to get swap list");
! return -1;
! }
!
! // Sum the entries to get total and free swap
! total = 0;
! avail = 0;
! for (i = 0; i < count; i++) {
! total += stbl->swt_ent[i].ste_pages;
! avail += stbl->swt_ent[i].ste_free;
! }
!
! free(stbl);
! free(strtab);
! return available ? ((jlong)avail * page_size) :
! ((jlong)total * page_size);
! #elif defined(__linux__)
int ret;
FILE *fp;
jlong total = 0, avail = 0;
struct sysinfo si;
--- 83,93 ----
#endif
// true = get available swap in bytes
// false = get total swap in bytes
static jlong get_total_or_available_swap_space_size(JNIEnv* env, jboolean available) {
! #if defined(__linux__)
int ret;
FILE *fp;
jlong total = 0, avail = 0;
struct sysinfo si;
*** 181,221 ****
JNIEXPORT jlong JNICALL
Java_com_sun_management_internal_OperatingSystemImpl_getCommittedVirtualMemorySize0
(JNIEnv *env, jobject mbean)
{
! #ifdef __solaris__
! psinfo_t psinfo;
! ssize_t result;
! size_t remaining;
! char* addr;
! int fd;
!
! fd = open64("/proc/self/psinfo", O_RDONLY, 0);
! if (fd < 0) {
! throw_internal_error(env, "Unable to open /proc/self/psinfo");
! return -1;
! }
!
! addr = (char *)&psinfo;
! for (remaining = sizeof(psinfo_t); remaining > 0;) {
! result = read(fd, addr, remaining);
! if (result < 0) {
! if (errno != EINTR) {
! close(fd);
! throw_internal_error(env, "Unable to read /proc/self/psinfo");
! return -1;
! }
! } else {
! remaining -= result;
! addr += result;
! }
! }
!
! close(fd);
! return (jlong) psinfo.pr_size * 1024;
! #elif defined(__linux__)
FILE *fp;
unsigned long vsize = 0;
if ((fp = fopen("/proc/self/stat", "r")) == NULL) {
throw_internal_error(env, "Unable to open /proc/self/stat");
--- 125,135 ----
JNIEXPORT jlong JNICALL
Java_com_sun_management_internal_OperatingSystemImpl_getCommittedVirtualMemorySize0
(JNIEnv *env, jobject mbean)
{
! #if defined(__linux__)
FILE *fp;
unsigned long vsize = 0;
if ((fp = fopen("/proc/self/stat", "r")) == NULL) {
throw_internal_error(env, "Unable to open /proc/self/stat");
*** 284,294 ****
/*
* BSDNOTE: FreeBSD implements _SC_CLK_TCK since FreeBSD 5, so
* add a magic to handle it
*/
! #if defined(__solaris__) || defined(_SC_CLK_TCK)
clk_tck = (jlong) sysconf(_SC_CLK_TCK);
#elif defined(__linux__) || defined(_ALLBSD_SOURCE)
clk_tck = 100;
#endif
if (clk_tck == -1) {
--- 198,208 ----
/*
* BSDNOTE: FreeBSD implements _SC_CLK_TCK since FreeBSD 5, so
* add a magic to handle it
*/
! #if defined(_SC_CLK_TCK)
clk_tck = (jlong) sysconf(_SC_CLK_TCK);
#elif defined(__linux__) || defined(_ALLBSD_SOURCE)
clk_tck = 100;
#endif
if (clk_tck == -1) {
< prev index next >