equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
39 #include <sys/mount.h> |
39 #include <sys/mount.h> |
40 #include <mach/mach.h> |
40 #include <mach/mach.h> |
41 #include <sys/proc_info.h> |
41 #include <sys/proc_info.h> |
42 #include <libproc.h> |
42 #include <libproc.h> |
43 #endif |
43 #endif |
44 #else |
44 #elif !defined(_AIX) |
45 #include <sys/swap.h> |
45 #include <sys/swap.h> |
46 #endif |
46 #endif |
47 #include <sys/resource.h> |
47 #include <sys/resource.h> |
48 #include <sys/times.h> |
48 #include <sys/times.h> |
49 #ifndef _ALLBSD_SOURCE |
49 #ifndef _ALLBSD_SOURCE |
55 #include <fcntl.h> |
55 #include <fcntl.h> |
56 #include <limits.h> |
56 #include <limits.h> |
57 #include <stdlib.h> |
57 #include <stdlib.h> |
58 #include <unistd.h> |
58 #include <unistd.h> |
59 |
59 |
|
60 #if defined(_AIX) |
|
61 #include <libperfstat.h> |
|
62 #endif |
|
63 |
60 static jlong page_size = 0; |
64 static jlong page_size = 0; |
61 |
65 |
62 #if defined(_ALLBSD_SOURCE) |
66 #if defined(_ALLBSD_SOURCE) || defined(_AIX) |
63 #define MB (1024UL * 1024UL) |
67 #define MB (1024UL * 1024UL) |
64 #else |
68 #else |
65 |
69 |
66 /* This gets us the new structured proc interfaces of 5.6 & later */ |
70 /* This gets us the new structured proc interfaces of 5.6 & later */ |
67 /* - see comment in <sys/procfs.h> */ |
71 /* - see comment in <sys/procfs.h> */ |
324 /* |
328 /* |
325 * XXBSDL no way to do it in FreeBSD |
329 * XXBSDL no way to do it in FreeBSD |
326 */ |
330 */ |
327 // throw_internal_error(env, "unimplemented in FreeBSD") |
331 // throw_internal_error(env, "unimplemented in FreeBSD") |
328 return (128 * MB); |
332 return (128 * MB); |
|
333 #elif defined(_AIX) |
|
334 perfstat_memory_total_t memory_info; |
|
335 if (-1 != perfstat_memory_total(NULL, &memory_info, sizeof(perfstat_memory_total_t), 1)) { |
|
336 return (jlong)(memory_info.real_free * 4L * 1024L); |
|
337 } |
|
338 return -1; |
329 #else // solaris / linux |
339 #else // solaris / linux |
330 jlong num_avail_physical_pages = sysconf(_SC_AVPHYS_PAGES); |
340 jlong num_avail_physical_pages = sysconf(_SC_AVPHYS_PAGES); |
331 return (num_avail_physical_pages * page_size); |
341 return (num_avail_physical_pages * page_size); |
332 #endif |
342 #endif |
333 } |
343 } |
347 if (sysctl(mib, 2, &result, &rlen, NULL, 0) != 0) { |
357 if (sysctl(mib, 2, &result, &rlen, NULL, 0) != 0) { |
348 throw_internal_error(env, "sysctl failed"); |
358 throw_internal_error(env, "sysctl failed"); |
349 return -1; |
359 return -1; |
350 } |
360 } |
351 return result; |
361 return result; |
|
362 #elif defined(_AIX) |
|
363 perfstat_memory_total_t memory_info; |
|
364 if (-1 != perfstat_memory_total(NULL, &memory_info, sizeof(perfstat_memory_total_t), 1)) { |
|
365 return (jlong)(memory_info.real_total * 4L * 1024L); |
|
366 } |
|
367 return -1; |
352 #else // solaris / linux |
368 #else // solaris / linux |
353 jlong num_physical_pages = sysconf(_SC_PHYS_PAGES); |
369 jlong num_physical_pages = sysconf(_SC_PHYS_PAGES); |
354 return (num_physical_pages * page_size); |
370 return (num_physical_pages * page_size); |
355 #endif |
371 #endif |
356 } |
372 } |