38 #if defined(HAVE_DIRENT_H)
42 #if defined(HAVE_DLFCN_H)
46 #if defined(HAVE_ERRNO_H)
50 #if defined(HAVE_EXECINFO_H)
51 # include <execinfo.h>
54 #if defined(HAVE_FCNTL_H)
58 #if defined(ENABLE_JRE_LAYOUT)
59 # if defined(HAVE_LIBGEN_H)
64 #if defined(HAVE_SIGNAL_H)
68 #if defined(HAVE_STDARG_H)
72 #if defined(HAVE_STDINT_H)
76 #if defined(HAVE_STDIO_H)
80 #if defined(HAVE_STDLIB_H)
84 #if defined(HAVE_STRING_H)
88 #if defined(HAVE_UNISTD_H)
92 #if defined(__DARWIN__)
93 # if defined(HAVE_MACH_MACH_H)
94 # include <mach/mach.h>
98 #if defined(HAVE_SYS_LOADAVG_H)
99 # include <sys/loadavg.h>
102 #if defined(HAVE_SYS_MMAN_H)
103 # include <sys/mman.h>
106 #if defined(HAVE_SYS_SOCKET_H)
107 # include <sys/socket.h>
110 #if defined(HAVE_SYS_STAT_H)
111 # include <sys/stat.h>
114 #if defined(HAVE_SYS_TYPES_H)
115 # include <sys/types.h>
118 #if defined(HAVE_SYS_UTSNAME_H)
119 # include <sys/utsname.h>
126 static inline void abort();
127 static inline int accept(
int sockfd,
struct sockaddr* addr, socklen_t* addrlen);
128 static inline int access(
const char *pathname,
int mode);
129 static inline int atoi(
const char* nptr);
132 static inline void*
calloc(
size_t nmemb,
size_t size);
133 static inline int close(
int fd);
134 static inline int connect(
int sockfd,
const struct sockaddr* serv_addr, socklen_t addrlen);
135 #if defined(ENABLE_JRE_LAYOUT)
136 static inline char* dirname(
char* path);
138 static inline int dlclose(
void* handle);
139 static inline char*
dlerror(
void);
140 static inline void*
dlopen(
const char* filename,
int flag);
141 static inline void*
dlsym(
void* handle,
const char* symbol);
143 static inline FILE*
fopen(
const char* path,
const char* mode);
144 static inline int vfprintf ( FILE * stream,
const char * format, va_list
arg );
145 static inline size_t fread(
void* ptr,
size_t size,
size_t nmemb, FILE* stream);
146 static inline void free(
void* ptr);
147 static inline char*
getcwd(
char* buf,
size_t size);
149 static inline int gethostname(
char* name,
size_t len);
150 static inline int getloadavg(
double loadavg[],
int nelem);
152 static inline pid_t
getpid(
void);
153 static inline int getsockname(
int s,
struct sockaddr* name, socklen_t* namelen);
154 static inline int getsockopt(
int s,
int level,
int optname,
void* optval, socklen_t* optlen);
155 static inline int listen(
int sockfd,
int backlog);
156 static inline void*
malloc(
size_t size);
157 static inline void*
memcpy(
void* dest,
const void* src,
size_t n);
158 static inline void*
memset(
void* s,
int c,
size_t n);
159 static inline int mprotect(
void* addr,
size_t len,
int prot);
160 static inline ssize_t
readlink(
const char* path,
char* buf,
size_t bufsiz);
161 static inline int scandir(
const char* dir,
struct dirent*** namelist,
int(*filter)(
const struct dirent*),
int(*compar)(
const void*,
const void*));
162 static inline ssize_t
send(
int s,
const void* buf,
size_t len,
int flags);
163 static inline int setsockopt(
int s,
int level,
int optname,
const void* optval, socklen_t optlen);
164 static inline int shutdown(
int s,
int how);
165 static inline int socket(
int domain,
int type,
int protocol);
166 static inline int stat(
const char* path,
struct stat* buf);
167 #if defined(__SOLARIS__)
168 static inline int str2sig(
const char*
str,
int* signum);
170 static inline char*
strcat(
char* dest,
const char* src);
171 static inline int strcmp(
const char*
s1,
const char*
s2);
172 static inline char*
strcpy(
char* dest,
const char* src);
173 static inline char*
strdup(
const char* s);
174 static inline size_t strlen(
const char* s);
175 static inline char*
strerror(
int errnum);
178 static void abort(
const char* text, ...);
179 static void abort_errnum(
int errnum,
const char* text, ...);
181 static char*
getcwd(
void);
182 static void*
mmap_anonymous(
void *addr,
size_t len,
int prot,
int flags);
191 template<
class _F1,
class _F2>
192 static int call_scandir(
int (*scandir)(
const char *,
struct dirent ***, _F1, _F2),
const char *dir,
struct dirent ***namelist,
int(*filter)(
const struct dirent *),
int(*compar)(
const void *,
const void *));
198 #if defined(HAVE_ABORT)
201 # error abort not available
205 inline int os::accept(
int sockfd,
struct sockaddr* addr, socklen_t* addrlen)
207 #if defined(HAVE_ACCEPT)
208 return ::accept(sockfd, addr, addrlen);
210 # error accept not available
216 #if defined(HAVE_ACCESS)
217 return ::access(pathname, mode);
219 # error access not available
225 #if defined(HAVE_ATOI)
228 # error atoi not available
234 #if defined(HAVE_BACKTRACE)
235 return ::backtrace(array, size);
237 fprintf(stderr,
"os::backtrace: Not available.");
244 #if defined(HAVE_BACKTRACE_SYMBOLS)
245 return ::backtrace_symbols(array,
size);
247 fprintf(stderr,
"os::backtrace_symbols: Not available.");
254 #if defined(HAVE_CALLOC)
255 return ::calloc(nmemb, size);
257 # error calloc not available
263 #if defined(HAVE_CLOSE)
266 # error close not available
270 inline int os::connect(
int sockfd,
const struct sockaddr* serv_addr, socklen_t addrlen)
272 #if defined(HAVE_CONNECT)
273 return ::connect(sockfd, serv_addr, addrlen);
275 # error connect not available
279 #if defined(ENABLE_JRE_LAYOUT)
280 inline char* os::dirname(
char* path)
282 #if defined(HAVE_DIRNAME)
283 return ::dirname(path);
285 # error dirname not available
292 #if defined(HAVE_DLCLOSE)
293 return ::dlclose(handle);
295 # error dlclose not available
301 #if defined(HAVE_DLERROR)
306 # error dlerror not available
312 #if defined(HAVE_DLOPEN)
313 return ::dlopen(filename, flag);
315 # error dlopen not available
319 inline void*
os::dlsym(
void* handle,
const char* symbol)
321 #if defined(HAVE_DLSYM)
322 return ::dlsym(handle, symbol);
324 # error dlsym not available
330 #if defined(HAVE_FCLOSE)
333 # error fclose not available
337 inline FILE*
os::fopen(
const char* path,
const char* mode)
339 #if defined(HAVE_FOPEN)
340 return ::fopen(path, mode);
342 # error fopen not available
347 #if !defined (HAVE_FPRINTF)
348 #error fprintf not available
353 #if defined(HAVE_VFPRINTF)
357 # error vfprintf not available
363 #if defined(HAVE_FREAD)
364 return ::fread(ptr, size, nmemb, stream);
366 # error fread not available
372 #if defined(HAVE_FREE)
375 # error free not available
381 #if defined(HAVE_FSYNC)
384 # error fsync not available
390 #if defined(HAVE_FTRUNCATE)
391 return ftruncate(fd, length);
393 # error ftruncate not available
399 #if defined(HAVE_GETCWD)
400 return ::getcwd(buf, size);
402 # error getcwd not available
408 #if defined(HAVE_GETENV)
409 return ::getenv(name);
411 # error getenv not available
417 #if defined(HAVE_GETHOSTNAME)
418 return ::gethostname(name, len);
420 # error gethostname not available
426 #if defined(HAVE_GETLOADAVG)
427 return ::getloadavg(loadavg, nelem);
429 # error getloadavg not available
435 return ::sysconf(_SC_PAGESIZE);
440 #if defined(HAVE_GETPID)
443 # error getpid not available
449 #if defined(HAVE_GETSOCKNAME)
450 return ::getsockname(s, name, namelen);
452 # error getsockname not available
456 inline int os::getsockopt(
int s,
int level,
int optname,
void* optval, socklen_t* optlen)
458 #if defined(HAVE_GETSOCKOPT)
459 return ::getsockopt(s, level, optname, optval, optlen);
461 # error getsockopt not available
467 #if defined(HAVE_LISTEN)
468 return ::listen(sockfd, backlog);
470 # error listen not available
476 #if defined(HAVE_LSEEK)
477 return lseek(fildes, offset, whence);
479 # error lseek not available
485 #if defined(HAVE_MALLOC)
486 return ::malloc(size);
488 # error malloc not available
492 inline void*
os::memcpy(
void* dest,
const void* src,
size_t n)
494 #if defined(HAVE_MEMCPY)
495 return ::memcpy(dest, src, n);
497 # error memcpy not available
503 #if defined(HAVE_MEMSET)
504 return ::memset(s, c, n);
506 # error memset not available
512 #if defined(HAVE_MPROTECT)
513 return ::mprotect(addr, len, prot);
515 # error mprotect not available
519 inline static int system_open(
const char *pathname,
int flags, mode_t mode)
521 #if defined(HAVE_OPEN)
522 return open(pathname, flags, mode);
524 # error open not available
528 inline static ssize_t
system_read(
int fd,
void *buf,
size_t count)
530 #if defined(HAVE_READ)
531 return read(fd, buf, count);
533 # error read not available
537 inline ssize_t
os::readlink(
const char* path,
char* buf,
size_t bufsiz)
539 #if defined(HAVE_READLINK)
540 return ::readlink(path, buf, bufsiz);
542 # error readlink not available
548 #if defined(HAVE_REALLOC)
549 return realloc(ptr, size);
551 # error realloc not available
555 template<
class _F1,
class _F2>
556 inline int os::call_scandir(
int (*scandir)(
const char *,
struct dirent ***, _F1, _F2),
const char *dir,
struct dirent ***namelist,
int(*filter)(
const struct dirent *),
int(*compar)(
const void *,
const void *))
558 return scandir(dir, namelist, (_F1) filter, (_F2) compar);
561 inline int os::scandir(
const char *dir,
struct dirent ***namelist,
int(*filter)(
const struct dirent *),
int(*compar)(
const void *,
const void *))
563 #if defined(HAVE_SCANDIR)
566 # error scandir not available
570 inline ssize_t
os::send(
int s,
const void* buf,
size_t len,
int flags)
573 #if defined(HAVE_SEND)
574 return ::send(s, buf, len, flags);
576 # error send not available
580 inline int os::setsockopt(
int s,
int level,
int optname,
const void* optval, socklen_t optlen)
582 #if defined(HAVE_SETSOCKOPT)
583 return ::setsockopt(s, level, optname, optval, optlen);
585 # error setsockopt not available
591 #if defined(HAVE_SHUTDOWN)
592 return ::shutdown(s, how);
594 # error shutdown not available
600 #if defined(HAVE_SOCKET)
601 return ::socket(domain, type, protocol);
603 # error socket not available
607 inline int os::stat(
const char* path,
struct stat* buf)
609 #if defined(HAVE_STAT)
610 return ::stat(path, buf);
612 # error stat not available
616 #if defined(__SOLARIS__)
617 inline int os::str2sig(
const char*
str,
int* signum)
619 #if defined(HAVE_STR2SIG)
620 return ::str2sig(str, signum);
622 # error str2sig not available
629 #if defined(HAVE_STRCAT)
630 return ::strcat(dest, src);
632 # error strcat not available
638 #if defined(HAVE_STRCMP)
639 return ::strcmp(s1, s2);
641 # error strcmp not available
647 #if defined(HAVE_STRCPY)
648 return ::strcpy(dest, src);
650 # error strcpy not available
656 #if defined(HAVE_STRDUP)
659 # error strdup not available
665 #if defined(HAVE_STRERROR)
666 return ::strerror(errnum);
668 # error strerror not available
674 #if defined(HAVE_STRLEN)
677 # error strlen not available
681 inline static ssize_t
system_write(
int fd,
const void *buf,
size_t count)
683 #if defined(HAVE_WRITE)
684 return write(fd, buf, count);
686 # error write not available
static void * memset(void *s, int c, size_t n)
static char * strerror(int errnum)
static FILE * fopen(const char *path, const char *mode)
static size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
static int processors_online()
Returns the number of online processors in the system.
static void * calloc(size_t nmemb, size_t size)
static int socket(int domain, int type, int protocol)
static int backtrace(void **array, int size)
static pid_t getpid(void)
static void abort_errno(const char *text,...)
Equal to abort_errnum, but uses errno to get the error number.
static char * getenv(const char *name)
static int listen(int sockfd, int backlog)
static void unimplemented()
static void * system_realloc(void *ptr, size_t size)
static void print_backtrace()
Print a C backtrace.
static int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen)
static int stat(const char *path, struct stat *buf)
static int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen)
JNIEnv jclass jobject const char * name
static void free(void *ptr)
JNIEnv jthread jobject jclass jlong size
static int call_scandir(int(*scandir)(const char *, struct dirent ***, _F1, _F2), const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *))
static char * strcpy(char *dest, const char *src)
static int mprotect(void *addr, size_t len, int prot)
static size_t strlen(const char *s)
static void abort_errnum(int errnum, const char *text,...)
Prints an error message, appends ":" plus the strerror-message of errnum and aborts the VM...
static int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen)
static int atoi(const char *nptr)
static void * dlsym(void *handle, const char *symbol)
static int getsockname(int s, struct sockaddr *name, socklen_t *namelen)
static int system_open(const char *pathname, int flags, mode_t mode)
static ssize_t readlink(const char *path, char *buf, size_t bufsiz)
static void * dlopen(const char *filename, int flag)
static int fclose(FILE *fp)
static int getpagesize(void)
static char ** backtrace_symbols(void *const *array, int size)
static int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen)
static int system_ftruncate(int fd, off_t length)
static char * dlerror(void)
static char * getcwd(void)
Return the current working directory.
static ssize_t system_read(int fd, void *buf, size_t count)
static void * memcpy(void *dest, const void *src, size_t n)
static ssize_t system_write(int fd, const void *buf, size_t count)
static void * mmap_anonymous(void *addr, size_t len, int prot, int flags)
Maps anonymous memory, even on systems not defining MAP_ANON(YMOUS).
static off_t system_lseek(int fildes, off_t offset, int whence)
static int system_fsync(int fd)
static ssize_t send(int s, const void *buf, size_t len, int flags)
static void * malloc(size_t size)
static int access(const char *pathname, int mode)
static int shutdown(int s, int how)
static int vfprintf(FILE *stream, const char *format, va_list arg)
static void shouldnotreach()
static int scandir(const char *dir, struct dirent ***namelist, int(*filter)(const struct dirent *), int(*compar)(const void *, const void *))
static int getloadavg(double loadavg[], int nelem)
const char const void jint length
static int gethostname(char *name, size_t len)
static int strcmp(const char *s1, const char *s2)
static int dlclose(void *handle)
static char * strdup(const char *s)
static char * strcat(char *dest, const char *src)