author | kvn |
Tue, 28 Jan 2014 14:57:41 -0800 | |
changeset 22607 | ba232b417248 |
parent 22583 | e7d5af0b11e9 |
parent 22605 | dba3d6b22818 |
child 23054 | 9ce297e5f4a2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include "jni.h" |
|
27 |
#include "jni_util.h" |
|
28 |
#include "jlong.h" |
|
29 |
#include "jvm.h" |
|
30 |
#include "management.h" |
|
21633
6cc4c9a56216
8025985: com.sun.management.OSMBeanFactory should not be public
mchung
parents:
17173
diff
changeset
|
31 |
#include "sun_management_OperatingSystemImpl.h" |
2 | 32 |
|
33 |
#include <sys/types.h> |
|
34 |
#include <sys/stat.h> |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
35 |
#if defined(_ALLBSD_SOURCE) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
36 |
#include <sys/sysctl.h> |
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
37 |
#ifdef __APPLE__ |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
38 |
#include <sys/param.h> |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
39 |
#include <sys/mount.h> |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
40 |
#include <mach/mach.h> |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
41 |
#include <sys/proc_info.h> |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
42 |
#include <libproc.h> |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
43 |
#endif |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
44 |
#elif !defined(_AIX) |
2 | 45 |
#include <sys/swap.h> |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
46 |
#endif |
2 | 47 |
#include <sys/resource.h> |
48 |
#include <sys/times.h> |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
49 |
#ifndef _ALLBSD_SOURCE |
2 | 50 |
#include <sys/sysinfo.h> |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
51 |
#endif |
2 | 52 |
#include <ctype.h> |
53 |
#include <dirent.h> |
|
54 |
#include <errno.h> |
|
55 |
#include <fcntl.h> |
|
56 |
#include <limits.h> |
|
57 |
#include <stdlib.h> |
|
58 |
#include <unistd.h> |
|
59 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
60 |
#if defined(_AIX) |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
61 |
#include <libperfstat.h> |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
62 |
#endif |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
63 |
|
2 | 64 |
static jlong page_size = 0; |
65 |
||
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
66 |
#if defined(_ALLBSD_SOURCE) || defined(_AIX) |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
67 |
#define MB (1024UL * 1024UL) |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
68 |
#else |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
69 |
|
2 | 70 |
/* This gets us the new structured proc interfaces of 5.6 & later */ |
71 |
/* - see comment in <sys/procfs.h> */ |
|
72 |
#define _STRUCTURED_PROC 1 |
|
73 |
#include <sys/procfs.h> |
|
74 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
75 |
#endif /* _ALLBSD_SOURCE */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
76 |
|
2 | 77 |
static struct dirent* read_dir(DIR* dirp, struct dirent* entry) { |
78 |
#ifdef __solaris__ |
|
79 |
struct dirent* dbuf = readdir(dirp); |
|
80 |
return dbuf; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
81 |
#else /* __linux__ || _ALLBSD_SOURCE */ |
2 | 82 |
struct dirent* p; |
83 |
if (readdir_r(dirp, entry, &p) == 0) { |
|
84 |
return p; |
|
85 |
} else { |
|
86 |
return NULL; |
|
87 |
} |
|
88 |
#endif |
|
89 |
} |
|
90 |
||
91 |
// true = get available swap in bytes |
|
92 |
// false = get total swap in bytes |
|
93 |
static jlong get_total_or_available_swap_space_size(JNIEnv* env, jboolean available) { |
|
94 |
#ifdef __solaris__ |
|
95 |
long total, avail; |
|
96 |
int nswap, i, count; |
|
97 |
swaptbl_t *stbl; |
|
98 |
char *strtab; |
|
99 |
||
100 |
// First get the number of swap resource entries |
|
101 |
if ((nswap = swapctl(SC_GETNSWP, NULL)) == -1) { |
|
102 |
throw_internal_error(env, "swapctl failed to get nswap"); |
|
103 |
return -1; |
|
104 |
} |
|
105 |
if (nswap == 0) { |
|
106 |
return 0; |
|
107 |
} |
|
108 |
||
109 |
// Allocate storage for resource entries |
|
110 |
stbl = (swaptbl_t*) malloc(nswap * sizeof(swapent_t) + |
|
111 |
sizeof(struct swaptable)); |
|
112 |
if (stbl == NULL) { |
|
113 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
114 |
return -1; |
|
115 |
} |
|
116 |
||
117 |
// Allocate storage for the table |
|
118 |
strtab = (char*) malloc((nswap + 1) * MAXPATHLEN); |
|
119 |
if (strtab == NULL) { |
|
120 |
free(stbl); |
|
121 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
122 |
return -1; |
|
123 |
} |
|
124 |
||
125 |
for (i = 0; i < (nswap + 1); i++) { |
|
126 |
stbl->swt_ent[i].ste_path = strtab + (i * MAXPATHLEN); |
|
127 |
} |
|
128 |
stbl->swt_n = nswap + 1; |
|
129 |
||
130 |
// Get the entries |
|
131 |
if ((count = swapctl(SC_LIST, stbl)) < 0) { |
|
132 |
free(stbl); |
|
133 |
free(strtab); |
|
134 |
throw_internal_error(env, "swapctl failed to get swap list"); |
|
135 |
return -1; |
|
136 |
} |
|
137 |
||
138 |
// Sum the entries to get total and free swap |
|
139 |
total = 0; |
|
140 |
avail = 0; |
|
141 |
for (i = 0; i < count; i++) { |
|
142 |
total += stbl->swt_ent[i].ste_pages; |
|
143 |
avail += stbl->swt_ent[i].ste_free; |
|
144 |
} |
|
145 |
||
146 |
free(stbl); |
|
147 |
free(strtab); |
|
148 |
return available ? ((jlong)avail * page_size) : |
|
149 |
((jlong)total * page_size); |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
150 |
#elif defined(__linux__) |
2 | 151 |
int ret; |
152 |
FILE *fp; |
|
153 |
jlong total = 0, avail = 0; |
|
154 |
||
155 |
struct sysinfo si; |
|
156 |
ret = sysinfo(&si); |
|
157 |
if (ret != 0) { |
|
158 |
throw_internal_error(env, "sysinfo failed to get swap size"); |
|
159 |
} |
|
160 |
total = (jlong)si.totalswap * si.mem_unit; |
|
161 |
avail = (jlong)si.freeswap * si.mem_unit; |
|
162 |
||
163 |
return available ? avail : total; |
|
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
164 |
#elif defined(__APPLE__) |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
165 |
struct xsw_usage vmusage; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
166 |
size_t size = sizeof(vmusage); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
167 |
if (sysctlbyname("vm.swapusage", &vmusage, &size, NULL, 0) != 0) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
168 |
throw_internal_error(env, "sysctlbyname failed"); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
169 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
170 |
return available ? (jlong)vmusage.xsu_avail : (jlong)vmusage.xsu_total; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
171 |
#else /* _ALLBSD_SOURCE */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
172 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
173 |
* XXXBSD: there's no way available to get swap info in |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
174 |
* FreeBSD. Usage of libkvm is not an option here |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
175 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
176 |
// throw_internal_error(env, "Unimplemented in FreeBSD"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
177 |
return (0); |
2 | 178 |
#endif |
179 |
} |
|
180 |
||
181 |
JNIEXPORT void JNICALL |
|
22583
e7d5af0b11e9
8022323: [JavaSecurityScanner] review package com.sun.management.* Native methods should be private
dsamersoff
parents:
21633
diff
changeset
|
182 |
Java_sun_management_OperatingSystemImpl_initialize0 |
2 | 183 |
(JNIEnv *env, jclass cls) |
184 |
{ |
|
185 |
page_size = sysconf(_SC_PAGESIZE); |
|
186 |
} |
|
187 |
||
188 |
JNIEXPORT jlong JNICALL |
|
22583
e7d5af0b11e9
8022323: [JavaSecurityScanner] review package com.sun.management.* Native methods should be private
dsamersoff
parents:
21633
diff
changeset
|
189 |
Java_sun_management_OperatingSystemImpl_getCommittedVirtualMemorySize0 |
2 | 190 |
(JNIEnv *env, jobject mbean) |
191 |
{ |
|
192 |
#ifdef __solaris__ |
|
193 |
psinfo_t psinfo; |
|
194 |
ssize_t result; |
|
195 |
size_t remaining; |
|
196 |
char* addr; |
|
197 |
int fd; |
|
198 |
||
199 |
fd = JVM_Open("/proc/self/psinfo", O_RDONLY, 0); |
|
200 |
if (fd < 0) { |
|
201 |
throw_internal_error(env, "Unable to open /proc/self/psinfo"); |
|
202 |
return -1; |
|
203 |
} |
|
204 |
||
205 |
addr = (char *)&psinfo; |
|
206 |
for (remaining = sizeof(psinfo_t); remaining > 0;) { |
|
207 |
result = JVM_Read(fd, addr, remaining); |
|
208 |
if (result < 0) { |
|
209 |
JVM_Close(fd); |
|
210 |
throw_internal_error(env, "Unable to read /proc/self/psinfo"); |
|
211 |
return -1; |
|
212 |
} |
|
213 |
remaining -= result; |
|
214 |
addr += result; |
|
215 |
} |
|
216 |
||
217 |
JVM_Close(fd); |
|
218 |
return (jlong) psinfo.pr_size * 1024; |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
219 |
#elif defined(__linux__) |
2 | 220 |
FILE *fp; |
221 |
unsigned long vsize = 0; |
|
222 |
||
223 |
if ((fp = fopen("/proc/self/stat", "r")) == NULL) { |
|
224 |
throw_internal_error(env, "Unable to open /proc/self/stat"); |
|
225 |
return -1; |
|
226 |
} |
|
227 |
||
228 |
// Ignore everything except the vsize entry |
|
229 |
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) { |
|
230 |
throw_internal_error(env, "Unable to get virtual memory usage"); |
|
231 |
fclose(fp); |
|
232 |
return -1; |
|
233 |
} |
|
234 |
||
235 |
fclose(fp); |
|
236 |
return (jlong)vsize; |
|
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
237 |
#elif defined(__APPLE__) |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
238 |
struct task_basic_info t_info; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
239 |
mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
240 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
241 |
kern_return_t res = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
242 |
if (res != KERN_SUCCESS) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
243 |
throw_internal_error(env, "task_info failed"); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
244 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
245 |
return t_info.virtual_size; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
246 |
#else /* _ALLBSD_SOURCE */ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
247 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
248 |
* XXXBSD: there's no way available to do it in FreeBSD, AFAIK. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
249 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
250 |
// throw_internal_error(env, "Unimplemented in FreeBSD"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
251 |
return (64 * MB); |
2 | 252 |
#endif |
253 |
} |
|
254 |
||
255 |
JNIEXPORT jlong JNICALL |
|
22583
e7d5af0b11e9
8022323: [JavaSecurityScanner] review package com.sun.management.* Native methods should be private
dsamersoff
parents:
21633
diff
changeset
|
256 |
Java_sun_management_OperatingSystemImpl_getTotalSwapSpaceSize0 |
2 | 257 |
(JNIEnv *env, jobject mbean) |
258 |
{ |
|
259 |
return get_total_or_available_swap_space_size(env, JNI_FALSE); |
|
260 |
} |
|
261 |
||
262 |
JNIEXPORT jlong JNICALL |
|
22583
e7d5af0b11e9
8022323: [JavaSecurityScanner] review package com.sun.management.* Native methods should be private
dsamersoff
parents:
21633
diff
changeset
|
263 |
Java_sun_management_OperatingSystemImpl_getFreeSwapSpaceSize0 |
2 | 264 |
(JNIEnv *env, jobject mbean) |
265 |
{ |
|
266 |
return get_total_or_available_swap_space_size(env, JNI_TRUE); |
|
267 |
} |
|
268 |
||
269 |
JNIEXPORT jlong JNICALL |
|
22583
e7d5af0b11e9
8022323: [JavaSecurityScanner] review package com.sun.management.* Native methods should be private
dsamersoff
parents:
21633
diff
changeset
|
270 |
Java_sun_management_OperatingSystemImpl_getProcessCpuTime0 |
2 | 271 |
(JNIEnv *env, jobject mbean) |
272 |
{ |
|
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
273 |
#ifdef __APPLE__ |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
274 |
struct rusage usage; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
275 |
if (getrusage(RUSAGE_SELF, &usage) != 0) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
276 |
throw_internal_error(env, "getrusage failed"); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
277 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
278 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
279 |
jlong microsecs = |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
280 |
usage.ru_utime.tv_sec * 1000 * 1000 + usage.ru_utime.tv_usec + |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
281 |
usage.ru_stime.tv_sec * 1000 * 1000 + usage.ru_stime.tv_usec; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
282 |
return microsecs * 1000; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
283 |
#else |
2 | 284 |
jlong clk_tck, ns_per_clock_tick; |
285 |
jlong cpu_time_ns; |
|
286 |
struct tms time; |
|
287 |
||
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
288 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
289 |
* BSDNOTE: FreeBSD implements _SC_CLK_TCK since FreeBSD 5, so |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
290 |
* add a magic to handle it |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
291 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
292 |
#if defined(__solaris__) || defined(_SC_CLK_TCK) |
2 | 293 |
clk_tck = (jlong) sysconf(_SC_CLK_TCK); |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
294 |
#elif defined(__linux__) || defined(_ALLBSD_SOURCE) |
2 | 295 |
clk_tck = 100; |
296 |
#endif |
|
297 |
if (clk_tck == -1) { |
|
298 |
throw_internal_error(env, |
|
299 |
"sysconf failed - not able to get clock tick"); |
|
300 |
return -1; |
|
301 |
} |
|
302 |
||
303 |
times(&time); |
|
304 |
ns_per_clock_tick = (jlong) 1000 * 1000 * 1000 / (jlong) clk_tck; |
|
305 |
cpu_time_ns = ((jlong)time.tms_utime + (jlong) time.tms_stime) * |
|
306 |
ns_per_clock_tick; |
|
307 |
return cpu_time_ns; |
|
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
308 |
#endif |
2 | 309 |
} |
310 |
||
311 |
JNIEXPORT jlong JNICALL |
|
22583
e7d5af0b11e9
8022323: [JavaSecurityScanner] review package com.sun.management.* Native methods should be private
dsamersoff
parents:
21633
diff
changeset
|
312 |
Java_sun_management_OperatingSystemImpl_getFreePhysicalMemorySize0 |
2 | 313 |
(JNIEnv *env, jobject mbean) |
314 |
{ |
|
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
315 |
#ifdef __APPLE__ |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
316 |
mach_msg_type_number_t count; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
317 |
vm_statistics_data_t vm_stats; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
318 |
kern_return_t res; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
319 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
320 |
count = HOST_VM_INFO_COUNT; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
321 |
res = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_stats, &count); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
322 |
if (res != KERN_SUCCESS) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
323 |
throw_internal_error(env, "host_statistics failed"); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
324 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
325 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
326 |
return (jlong)vm_stats.free_count * page_size; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
327 |
#elif defined(_ALLBSD_SOURCE) |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
328 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
329 |
* XXBSDL no way to do it in FreeBSD |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
330 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
331 |
// throw_internal_error(env, "unimplemented in FreeBSD") |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
332 |
return (128 * MB); |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
333 |
#elif defined(_AIX) |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
334 |
perfstat_memory_total_t memory_info; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
335 |
if (-1 != perfstat_memory_total(NULL, &memory_info, sizeof(perfstat_memory_total_t), 1)) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
336 |
return (jlong)(memory_info.real_free * 4L * 1024L); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
337 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
338 |
return -1; |
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
339 |
#else // solaris / linux |
2 | 340 |
jlong num_avail_physical_pages = sysconf(_SC_AVPHYS_PAGES); |
341 |
return (num_avail_physical_pages * page_size); |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
342 |
#endif |
2 | 343 |
} |
344 |
||
345 |
JNIEXPORT jlong JNICALL |
|
22583
e7d5af0b11e9
8022323: [JavaSecurityScanner] review package com.sun.management.* Native methods should be private
dsamersoff
parents:
21633
diff
changeset
|
346 |
Java_sun_management_OperatingSystemImpl_getTotalPhysicalMemorySize0 |
2 | 347 |
(JNIEnv *env, jobject mbean) |
348 |
{ |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
349 |
#ifdef _ALLBSD_SOURCE |
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
350 |
jlong result = 0; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
351 |
int mib[2]; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
352 |
size_t rlen; |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
353 |
|
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
354 |
mib[0] = CTL_HW; |
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
355 |
mib[1] = HW_MEMSIZE; |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
356 |
rlen = sizeof(result); |
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
357 |
if (sysctl(mib, 2, &result, &rlen, NULL, 0) != 0) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
358 |
throw_internal_error(env, "sysctl failed"); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
359 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
360 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
361 |
return result; |
22597
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
362 |
#elif defined(_AIX) |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
363 |
perfstat_memory_total_t memory_info; |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
364 |
if (-1 != perfstat_memory_total(NULL, &memory_info, sizeof(perfstat_memory_total_t), 1)) { |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
365 |
return (jlong)(memory_info.real_total * 4L * 1024L); |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
366 |
} |
7515a991bb37
8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents:
21633
diff
changeset
|
367 |
return -1; |
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
368 |
#else // solaris / linux |
2 | 369 |
jlong num_physical_pages = sysconf(_SC_PHYS_PAGES); |
370 |
return (num_physical_pages * page_size); |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
371 |
#endif |
2 | 372 |
} |
373 |
||
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
374 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
375 |
|
2 | 376 |
JNIEXPORT jlong JNICALL |
22583
e7d5af0b11e9
8022323: [JavaSecurityScanner] review package com.sun.management.* Native methods should be private
dsamersoff
parents:
21633
diff
changeset
|
377 |
Java_sun_management_OperatingSystemImpl_getOpenFileDescriptorCount0 |
2 | 378 |
(JNIEnv *env, jobject mbean) |
379 |
{ |
|
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
380 |
#ifdef __APPLE__ |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
381 |
// This code is influenced by the darwin lsof source |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
382 |
pid_t my_pid; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
383 |
struct proc_bsdinfo bsdinfo; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
384 |
struct proc_fdinfo *fds; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
385 |
int nfiles; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
386 |
kern_return_t kres; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
387 |
int res; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
388 |
size_t fds_size; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
389 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
390 |
kres = pid_for_task(mach_task_self(), &my_pid); |
17173
ce6a6d533139
8009985: [parfait] Uninitialised variable at jdk/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c
sla
parents:
14342
diff
changeset
|
391 |
if (kres != KERN_SUCCESS) { |
12442
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
392 |
throw_internal_error(env, "pid_for_task failed"); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
393 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
394 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
395 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
396 |
// get the maximum number of file descriptors |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
397 |
res = proc_pidinfo(my_pid, PROC_PIDTBSDINFO, 0, &bsdinfo, PROC_PIDTBSDINFO_SIZE); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
398 |
if (res <= 0) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
399 |
throw_internal_error(env, "proc_pidinfo with PROC_PIDTBSDINFO failed"); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
400 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
401 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
402 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
403 |
// allocate memory to hold the fd information (we don't acutally use this information |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
404 |
// but need it to get the number of open files) |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
405 |
fds_size = bsdinfo.pbi_nfiles * sizeof(struct proc_fdinfo); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
406 |
fds = malloc(fds_size); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
407 |
if (fds == NULL) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
408 |
JNU_ThrowOutOfMemoryError(env, "could not allocate space for file descriptors"); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
409 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
410 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
411 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
412 |
// get the list of open files - the return value is the number of bytes |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
413 |
// proc_pidinfo filled in |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
414 |
res = proc_pidinfo(my_pid, PROC_PIDLISTFDS, 0, fds, fds_size); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
415 |
if (res <= 0) { |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
416 |
free(fds); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
417 |
throw_internal_error(env, "proc_pidinfo failed for PROC_PIDLISTFDS"); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
418 |
return -1; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
419 |
} |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
420 |
nfiles = res / sizeof(struct proc_fdinfo); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
421 |
free(fds); |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
422 |
|
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
423 |
return nfiles; |
c42ceb64ffb2
7147848: com.sun.management.UnixOperatingSystem uses hardcoded dummy values [macosx]
sla
parents:
12047
diff
changeset
|
424 |
#elif defined(_ALLBSD_SOURCE) |
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
425 |
/* |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
426 |
* XXXBSD: there's no way available to do it in FreeBSD, AFAIK. |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
427 |
*/ |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
428 |
// throw_internal_error(env, "Unimplemented in FreeBSD"); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
429 |
return (100); |
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
430 |
#else /* solaris/linux */ |
2 | 431 |
DIR *dirp; |
432 |
struct dirent dbuf; |
|
433 |
struct dirent* dentp; |
|
434 |
jlong fds = 0; |
|
435 |
||
22605
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
436 |
#if defined(_AIX) |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
437 |
/* AIX does not understand '/proc/self' - it requires the real process ID */ |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
438 |
#define FD_DIR aix_fd_dir |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
439 |
char aix_fd_dir[32]; /* the pid has at most 19 digits */ |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
440 |
snprintf(aix_fd_dir, 32, "/proc/%d/fd", getpid()); |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
441 |
#else |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
442 |
#define FD_DIR "/proc/self/fd" |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
443 |
#endif |
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
444 |
|
dba3d6b22818
8031581: PPC64: Addons and fixes for AIX to pass the jdk regression tests
simonis
parents:
22597
diff
changeset
|
445 |
dirp = opendir(FD_DIR); |
2 | 446 |
if (dirp == NULL) { |
447 |
throw_internal_error(env, "Unable to open directory /proc/self/fd"); |
|
448 |
return -1; |
|
449 |
} |
|
450 |
||
451 |
// iterate through directory entries, skipping '.' and '..' |
|
452 |
// each entry represents an open file descriptor. |
|
453 |
while ((dentp = read_dir(dirp, &dbuf)) != NULL) { |
|
454 |
if (isdigit(dentp->d_name[0])) { |
|
455 |
fds++; |
|
456 |
} |
|
457 |
} |
|
458 |
||
459 |
closedir(dirp); |
|
460 |
// subtract by 1 which was the fd open for this implementation |
|
461 |
return (fds - 1); |
|
12047
320a714614e9
7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
5506
diff
changeset
|
462 |
#endif |
2 | 463 |
} |
464 |
||
465 |
JNIEXPORT jlong JNICALL |
|
22583
e7d5af0b11e9
8022323: [JavaSecurityScanner] review package com.sun.management.* Native methods should be private
dsamersoff
parents:
21633
diff
changeset
|
466 |
Java_sun_management_OperatingSystemImpl_getMaxFileDescriptorCount0 |
2 | 467 |
(JNIEnv *env, jobject mbean) |
468 |
{ |
|
469 |
struct rlimit rlp; |
|
470 |
||
471 |
if (getrlimit(RLIMIT_NOFILE, &rlp) == -1) { |
|
472 |
throw_internal_error(env, "getrlimit failed"); |
|
473 |
return -1; |
|
474 |
} |
|
475 |
return (jlong) rlp.rlim_cur; |
|
476 |
} |