30 #include "runtime/frame.inline.hpp"
31 #include "runtime/interfaceSupport.inline.hpp"
32 #include "services/memTracker.hpp"
33 #include "utilities/align.hpp"
34 #include "utilities/events.hpp"
35 #include "utilities/formatBuffer.hpp"
36 #include "utilities/macros.hpp"
37 #include "utilities/vmError.hpp"
38
39 #include <dirent.h>
40 #include <dlfcn.h>
41 #include <grp.h>
42 #include <pwd.h>
43 #include <pthread.h>
44 #include <signal.h>
45 #include <sys/mman.h>
46 #include <sys/resource.h>
47 #include <sys/utsname.h>
48 #include <time.h>
49 #include <unistd.h>
50
51 // Todo: provide a os::get_max_process_id() or similar. Number of processes
52 // may have been configured, can be read more accurately from proc fs etc.
53 #ifndef MAX_PID
54 #define MAX_PID INT_MAX
55 #endif
56 #define IS_VALID_PID(p) (p > 0 && p < MAX_PID)
57
58 #define ROOT_UID 0
59
60 #ifndef MAP_ANONYMOUS
61 #define MAP_ANONYMOUS MAP_ANON
62 #endif
63
64 #define check_with_errno(check_type, cond, msg) \
65 do { \
66 int err = errno; \
67 check_type(cond, "%s; error='%s' (errno=%s)", msg, os::strerror(err), \
68 os::errno_name(err)); \
69 } while (false)
359
360 int os::get_fileno(FILE* fp) {
361 return NOT_AIX(::)fileno(fp);
362 }
363
364 struct tm* os::gmtime_pd(const time_t* clock, struct tm* res) {
365 return gmtime_r(clock, res);
366 }
367
368 void os::Posix::print_load_average(outputStream* st) {
369 st->print("load average:");
370 double loadavg[3];
371 int res = os::loadavg(loadavg, 3);
372 if (res != -1) {
373 st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
374 } else {
375 st->print(" Unavailable");
376 }
377 st->cr();
378 }
379
380 void os::Posix::print_rlimit_info(outputStream* st) {
381 st->print("rlimit:");
382 struct rlimit rlim;
383
384 st->print(" STACK ");
385 getrlimit(RLIMIT_STACK, &rlim);
386 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
387 else st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_cur) / 1024);
388
389 st->print(", CORE ");
390 getrlimit(RLIMIT_CORE, &rlim);
391 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
392 else st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_cur) / 1024);
393
394 // Isn't there on solaris
395 #if defined(AIX)
396 st->print(", NPROC ");
397 st->print("%d", sysconf(_SC_CHILD_MAX));
398 #elif !defined(SOLARIS)
|
30 #include "runtime/frame.inline.hpp"
31 #include "runtime/interfaceSupport.inline.hpp"
32 #include "services/memTracker.hpp"
33 #include "utilities/align.hpp"
34 #include "utilities/events.hpp"
35 #include "utilities/formatBuffer.hpp"
36 #include "utilities/macros.hpp"
37 #include "utilities/vmError.hpp"
38
39 #include <dirent.h>
40 #include <dlfcn.h>
41 #include <grp.h>
42 #include <pwd.h>
43 #include <pthread.h>
44 #include <signal.h>
45 #include <sys/mman.h>
46 #include <sys/resource.h>
47 #include <sys/utsname.h>
48 #include <time.h>
49 #include <unistd.h>
50 #include <utmpx.h>
51
52 // Todo: provide a os::get_max_process_id() or similar. Number of processes
53 // may have been configured, can be read more accurately from proc fs etc.
54 #ifndef MAX_PID
55 #define MAX_PID INT_MAX
56 #endif
57 #define IS_VALID_PID(p) (p > 0 && p < MAX_PID)
58
59 #define ROOT_UID 0
60
61 #ifndef MAP_ANONYMOUS
62 #define MAP_ANONYMOUS MAP_ANON
63 #endif
64
65 #define check_with_errno(check_type, cond, msg) \
66 do { \
67 int err = errno; \
68 check_type(cond, "%s; error='%s' (errno=%s)", msg, os::strerror(err), \
69 os::errno_name(err)); \
70 } while (false)
360
361 int os::get_fileno(FILE* fp) {
362 return NOT_AIX(::)fileno(fp);
363 }
364
365 struct tm* os::gmtime_pd(const time_t* clock, struct tm* res) {
366 return gmtime_r(clock, res);
367 }
368
369 void os::Posix::print_load_average(outputStream* st) {
370 st->print("load average:");
371 double loadavg[3];
372 int res = os::loadavg(loadavg, 3);
373 if (res != -1) {
374 st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
375 } else {
376 st->print(" Unavailable");
377 }
378 st->cr();
379 }
380
381 // boot/uptime information;
382 // unfortunately it does not work on macOS because the utx chain has no entry
383 // for reboot at least on my test machines
384 void os::Posix::print_uptime_info(outputStream* st) {
385 int bootsec = -1;
386 int currsec = time(NULL);
387 struct utmpx* ent;
388 setutxent();
389 while ((ent = getutxent())) {
390 if (!strcmp("system boot", ent->ut_line)) {
391 bootsec = ent->ut_tv.tv_sec;
392 break;
393 }
394 }
395
396 if (bootsec != -1) {
397 st->print_cr("OS uptime (in days): %.2lf", (double) (currsec-bootsec)/(60*60*24));
398 }
399 }
400
401
402 void os::Posix::print_rlimit_info(outputStream* st) {
403 st->print("rlimit:");
404 struct rlimit rlim;
405
406 st->print(" STACK ");
407 getrlimit(RLIMIT_STACK, &rlim);
408 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
409 else st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_cur) / 1024);
410
411 st->print(", CORE ");
412 getrlimit(RLIMIT_CORE, &rlim);
413 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
414 else st->print(UINT64_FORMAT "k", uint64_t(rlim.rlim_cur) / 1024);
415
416 // Isn't there on solaris
417 #if defined(AIX)
418 st->print(", NPROC ");
419 st->print("%d", sysconf(_SC_CHILD_MAX));
420 #elif !defined(SOLARIS)
|