Mercurial > hg > truffle
diff src/os/linux/vm/os_linux.cpp @ 2491:0654ee04b214
Merge with OpenJDK.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 22 Apr 2011 15:30:53 +0200 |
parents | 0cd39a385a72 677234770800 |
children | be4ca325525a |
line wrap: on
line diff
--- a/src/os/linux/vm/os_linux.cpp Fri Apr 22 15:22:45 2011 +0200 +++ b/src/os/linux/vm/os_linux.cpp Fri Apr 22 15:30:53 2011 +0200 @@ -2213,7 +2213,7 @@ if (rp == NULL) return; - if (strcmp(Arguments::sun_java_launcher(), "gamma") == 0) { + if (Arguments::created_by_gamma_launcher()) { // Support for the gamma launcher. Typical value for buf is // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so". If "/jre/lib/" appears at // the right place in the string, then assume we are installed in a JDK and @@ -2648,45 +2648,39 @@ // writing thread stacks don't use growable mappings (i.e. those // creeated with MAP_GROWSDOWN), and aren't marked "[stack]", so this // only applies to the main thread. -static bool -get_stack_bounds(uintptr_t *bottom, uintptr_t *top) -{ - FILE *f = fopen("/proc/self/maps", "r"); - if (f == NULL) + +static +bool get_stack_bounds(uintptr_t *bottom, uintptr_t *top) { + + char buf[128]; + int fd, sz; + + if ((fd = ::open("/proc/self/maps", O_RDONLY)) < 0) { return false; - - while (!feof(f)) { - size_t dummy; - char *str = NULL; - ssize_t len = getline(&str, &dummy, f); - if (len == -1) { - fclose(f); - return false; - } - - if (len > 0 && str[len-1] == '\n') { - str[len-1] = 0; - len--; - } - - static const char *stack_str = "[stack]"; - if (len > (ssize_t)strlen(stack_str) - && (strcmp(str + len - strlen(stack_str), stack_str) == 0)) { - if (sscanf(str, "%" SCNxPTR "-%" SCNxPTR, bottom, top) == 2) { - uintptr_t sp = (uintptr_t)__builtin_frame_address(0); - if (sp >= *bottom && sp <= *top) { - free(str); - fclose(f); - return true; + } + + const char kw[] = "[stack]"; + const int kwlen = sizeof(kw)-1; + + // Address part of /proc/self/maps couldn't be more than 128 bytes + while ((sz = os::get_line_chars(fd, buf, sizeof(buf))) > 0) { + if (sz > kwlen && ::memcmp(buf+sz-kwlen, kw, kwlen) == 0) { + // Extract addresses + if (sscanf(buf, "%" SCNxPTR "-%" SCNxPTR, bottom, top) == 2) { + uintptr_t sp = (uintptr_t) __builtin_frame_address(0); + if (sp >= *bottom && sp <= *top) { + ::close(fd); + return true; + } } - } - } - free(str); + } } - fclose(f); + + ::close(fd); return false; } + // If the (growable) stack mapping already extends beyond the point // where we're going to put our guard pages, truncate the mapping at // that point by munmap()ping it. This ensures that when we later