/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "jni_util.h"
#include "jlong.h"
#include "jvm.h"
#include "management.h"
#include "com_sun_management_UnixOperatingSystem.h"
#if defined(_ALLBSD_SOURCE)
#ifdef __APPLE__
#include <sys/proc_info.h>
#include <libproc.h>
#endif
#else
#endif
#include <sys/resource.h>
#ifndef _ALLBSD_SOURCE
#endif
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdlib.h>
#include <unistd.h>
#if defined(_ALLBSD_SOURCE)
#else
/* This gets us the new structured proc interfaces of 5.6 & later */
#endif /* _ALLBSD_SOURCE */
#ifdef __solaris__
return dbuf;
#else /* __linux__ || _ALLBSD_SOURCE */
struct dirent* p;
return p;
} else {
return NULL;
}
#endif
}
// true = get available swap in bytes
// false = get total swap in bytes
#ifdef __solaris__
char *strtab;
// First get the number of swap resource entries
return -1;
}
if (nswap == 0) {
return 0;
}
// Allocate storage for resource entries
sizeof(struct swaptable));
return -1;
}
// Allocate storage for the table
return -1;
}
for (i = 0; i < (nswap + 1); i++) {
}
// Get the entries
return -1;
}
// Sum the entries to get total and free swap
total = 0;
avail = 0;
for (i = 0; i < count; i++) {
}
int ret;
if (ret != 0) {
}
}
#else /* _ALLBSD_SOURCE */
/*
* XXXBSD: there's no way available to get swap info in
* FreeBSD. Usage of libkvm is not an option here
*/
// throw_internal_error(env, "Unimplemented in FreeBSD");
return (0);
#endif
}
{
}
{
#ifdef __solaris__
char* addr;
int fd;
if (fd < 0) {
return -1;
}
if (result < 0) {
return -1;
}
}
unsigned long vsize = 0;
return -1;
}
// Ignore everything except the vsize entry
if (fscanf(fp, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*d %*d %*d %*d %*d %*d %*u %*u %*d %lu %*[^\n]\n", &vsize) == EOF) {
return -1;
}
struct task_basic_info t_info;
kern_return_t res = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
if (res != KERN_SUCCESS) {
}
return t_info.virtual_size;
#else /* _ALLBSD_SOURCE */
/*
* XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
*/
// throw_internal_error(env, "Unimplemented in FreeBSD");
return (64 * MB);
#endif
}
{
}
{
}
{
#ifdef __APPLE__
return -1;
}
return microsecs * 1000;
#else
/*
* 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 = 100;
#endif
if (clk_tck == -1) {
"sysconf failed - not able to get clock tick");
return -1;
}
return cpu_time_ns;
#endif
}
{
#ifdef __APPLE__
if (res != KERN_SUCCESS) {
return -1;
}
#elif defined(_ALLBSD_SOURCE)
/*
* XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
*/
// throw_internal_error(env, "Unimplemented in FreeBSD");
return (128 * MB);
#else // solaris / linux
return (num_avail_physical_pages * page_size);
#endif
}
{
#ifdef _ALLBSD_SOURCE
return -1;
}
return result;
#else // solaris / linux
return (num_physical_pages * page_size);
#endif
}
{
#ifdef __APPLE__
// This code is influenced by the darwin lsof source
int nfiles;
int res;
if (kres != KERN_SUCCESS) {
return -1;
}
// get the maximum number of file descriptors
if (res <= 0) {
return -1;
}
// allocate memory to hold the fd information (we don't acutally use this information
// but need it to get the number of open files)
return -1;
}
// get the list of open files - the return value is the number of bytes
// proc_pidinfo filled in
if (res <= 0) {
return -1;
}
return nfiles;
#elif defined(_ALLBSD_SOURCE)
/*
* XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
*/
// throw_internal_error(env, "Unimplemented in FreeBSD");
return (100);
return -1;
}
// iterate through directory entries, skipping '.' and '..'
// each entry represents an open file descriptor.
fds++;
}
}
// subtract by 1 which was the fd open for this implementation
return (fds - 1);
#endif
}
{
return -1;
}
}