< prev index next >

src/os/linux/vm/os_linux.cpp

Print this page




 910       if (fscanf(fp, "%p-%p", &low, &high) == 2) {
 911         if (low <= addr && addr < high) {
 912           if (vma_low)  *vma_low  = low;
 913           if (vma_high) *vma_high = high;
 914           fclose(fp);
 915           return true;
 916         }
 917       }
 918       for (;;) {
 919         int ch = fgetc(fp);
 920         if (ch == EOF || ch == (int)'\n') break;
 921       }
 922     }
 923     fclose(fp);
 924   }
 925   return false;
 926 }
 927 
 928 // Locate initial thread stack. This special handling of initial thread stack
 929 // is needed because pthread_getattr_np() on most (all?) Linux distros returns
 930 // bogus value for initial thread.


 931 void os::Linux::capture_initial_stack(size_t max_size) {
 932   // stack size is the easy part, get it from RLIMIT_STACK










 933   struct rlimit rlim;
 934   getrlimit(RLIMIT_STACK, &rlim);
 935   size_t stack_size = rlim.rlim_cur;
 936 
 937   // 6308388: a bug in ld.so will relocate its own .data section to the
 938   //   lower end of primordial stack; reduce ulimit -s value a little bit
 939   //   so we won't install guard page on ld.so's data section.
 940   stack_size -= 2 * page_size();
 941 
 942   // 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat
 943   //   7.1, in both cases we will get 2G in return value.
 944   // 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0,
 945   //   SuSE 7.2, Debian) can not handle alternate signal stack correctly
 946   //   for initial thread if its stack size exceeds 6M. Cap it at 2M,
 947   //   in case other parts in glibc still assumes 2M max stack size.
 948   // FIXME: alt signal stack is gone, maybe we can relax this constraint?
 949   // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small
 950   if (stack_size > 2 * K * K IA64_ONLY(*2)) {
 951     stack_size = 2 * K * K IA64_ONLY(*2);
 952   }
 953   // Try to figure out where the stack base (top) is. This is harder.
 954   //
 955   // When an application is started, glibc saves the initial stack pointer in
 956   // a global variable "__libc_stack_end", which is then used by system
 957   // libraries. __libc_stack_end should be pretty close to stack top. The
 958   // variable is available since the very early days. However, because it is
 959   // a private interface, it could disappear in the future.
 960   //
 961   // Linux kernel saves start_stack information in /proc/<pid>/stat. Similar
 962   // to __libc_stack_end, it is very close to stack top, but isn't the real
 963   // stack top. Note that /proc may not exist if VM is running as a chroot
 964   // program, so reading /proc/<pid>/stat could fail. Also the contents of
 965   // /proc/<pid>/stat could change in the future (though unlikely).
 966   //
 967   // We try __libc_stack_end first. If that doesn't work, look for
 968   // /proc/<pid>/stat. If neither of them works, we use current stack pointer
 969   // as a hint, which should work well in most cases.
 970 
 971   uintptr_t stack_start;
 972 


1092 
1093   uintptr_t stack_top;
1094   address low, high;
1095   if (find_vma((address)stack_start, &low, &high)) {
1096     // success, "high" is the true stack top. (ignore "low", because initial
1097     // thread stack grows on demand, its real bottom is high - RLIMIT_STACK.)
1098     stack_top = (uintptr_t)high;
1099   } else {
1100     // failed, likely because /proc/self/maps does not exist
1101     warning("Can't detect initial thread stack location - find_vma failed");
1102     // best effort: stack_start is normally within a few pages below the real
1103     // stack top, use it as stack top, and reduce stack size so we won't put
1104     // guard page outside stack.
1105     stack_top = stack_start;
1106     stack_size -= 16 * page_size();
1107   }
1108 
1109   // stack_top could be partially down the page so align it
1110   stack_top = align_size_up(stack_top, page_size());
1111 
1112   if (max_size && stack_size > max_size) {

1113     _initial_thread_stack_size = max_size;
1114   } else {
1115     _initial_thread_stack_size = stack_size;
1116   }
1117 
1118   _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size());
1119   _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size;
1120 }
1121 
1122 ////////////////////////////////////////////////////////////////////////////////
1123 // time support
1124 
1125 // Time since start-up in seconds to a fine granularity.
1126 // Used by VMSelfDestructTimer and the MemProfiler.
1127 double os::elapsedTime() {
1128 
1129   return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
1130 }
1131 
1132 jlong os::elapsed_counter() {




 910       if (fscanf(fp, "%p-%p", &low, &high) == 2) {
 911         if (low <= addr && addr < high) {
 912           if (vma_low)  *vma_low  = low;
 913           if (vma_high) *vma_high = high;
 914           fclose(fp);
 915           return true;
 916         }
 917       }
 918       for (;;) {
 919         int ch = fgetc(fp);
 920         if (ch == EOF || ch == (int)'\n') break;
 921       }
 922     }
 923     fclose(fp);
 924   }
 925   return false;
 926 }
 927 
 928 // Locate initial thread stack. This special handling of initial thread stack
 929 // is needed because pthread_getattr_np() on most (all?) Linux distros returns
 930 // bogus value for the primordial process thread. While the launcher has created
 931 // the VM in a new thread since JDK 6, we still have to allow for the use of the
 932 // JNI invocation API from a primordial thread.
 933 void os::Linux::capture_initial_stack(size_t max_size) {
 934 
 935   // max_size is either 0 (which means accept OS default for thread stacks) or
 936   // a user-specified value known to be greater than the minimum needed. If we
 937   // are actually on the primordial thread we can make it appear that we have a
 938   // smaller max_size stack by inserting the guard pages at that location. But we
 939   // can not do anything to emulate a larger stack than what has been provided by
 940   // the OS or threading library. In fact if we try to use a stack greater than
 941   // what is set by rlimit then we will crash the hosting process.
 942 
 943   // Mamimum stack size is the easy part, get it from RLIMIT_STACK
 944   // If this is "unlimited" then it will be a huge value.
 945   struct rlimit rlim;
 946   getrlimit(RLIMIT_STACK, &rlim);
 947   size_t stack_size = rlim.rlim_cur;
 948 
 949   // 6308388: a bug in ld.so will relocate its own .data section to the
 950   //   lower end of primordial stack; reduce ulimit -s value a little bit
 951   //   so we won't install guard page on ld.so's data section.
 952   stack_size -= 2 * page_size();
 953 











 954   // Try to figure out where the stack base (top) is. This is harder.
 955   //
 956   // When an application is started, glibc saves the initial stack pointer in
 957   // a global variable "__libc_stack_end", which is then used by system
 958   // libraries. __libc_stack_end should be pretty close to stack top. The
 959   // variable is available since the very early days. However, because it is
 960   // a private interface, it could disappear in the future.
 961   //
 962   // Linux kernel saves start_stack information in /proc/<pid>/stat. Similar
 963   // to __libc_stack_end, it is very close to stack top, but isn't the real
 964   // stack top. Note that /proc may not exist if VM is running as a chroot
 965   // program, so reading /proc/<pid>/stat could fail. Also the contents of
 966   // /proc/<pid>/stat could change in the future (though unlikely).
 967   //
 968   // We try __libc_stack_end first. If that doesn't work, look for
 969   // /proc/<pid>/stat. If neither of them works, we use current stack pointer
 970   // as a hint, which should work well in most cases.
 971 
 972   uintptr_t stack_start;
 973 


1093 
1094   uintptr_t stack_top;
1095   address low, high;
1096   if (find_vma((address)stack_start, &low, &high)) {
1097     // success, "high" is the true stack top. (ignore "low", because initial
1098     // thread stack grows on demand, its real bottom is high - RLIMIT_STACK.)
1099     stack_top = (uintptr_t)high;
1100   } else {
1101     // failed, likely because /proc/self/maps does not exist
1102     warning("Can't detect initial thread stack location - find_vma failed");
1103     // best effort: stack_start is normally within a few pages below the real
1104     // stack top, use it as stack top, and reduce stack size so we won't put
1105     // guard page outside stack.
1106     stack_top = stack_start;
1107     stack_size -= 16 * page_size();
1108   }
1109 
1110   // stack_top could be partially down the page so align it
1111   stack_top = align_size_up(stack_top, page_size());
1112 
1113   // Allowed stack value is minimum of max_size and what we derived from rlimit
1114   if (max_size > 0 && stack_size > max_size) {
1115     _initial_thread_stack_size = max_size;
1116   } else {
1117     _initial_thread_stack_size = stack_size;
1118   }
1119 
1120   _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size());
1121   _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size;
1122 }
1123 
1124 ////////////////////////////////////////////////////////////////////////////////
1125 // time support
1126 
1127 // Time since start-up in seconds to a fine granularity.
1128 // Used by VMSelfDestructTimer and the MemProfiler.
1129 double os::elapsedTime() {
1130 
1131   return ((double)os::elapsed_counter()) / os::elapsed_frequency(); // nanosecond resolution
1132 }
1133 
1134 jlong os::elapsed_counter() {


< prev index next >