< prev index next >
src/os/linux/vm/os_linux.cpp
Print this page
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
@@ -944,12 +944,12 @@
if (lgrp_id != -1) {
thread->set_lgrp_id(lgrp_id);
}
}
- if (os::Linux::is_initial_thread()) {
- // If current thread is initial thread, its stack is mapped on demand,
+ if (os::is_primordial_thread()) {
+ // If current thread is primordial thread, its stack is mapped on demand,
// see notes about MAP_GROWSDOWN. Here we try to force kernel to map
// the entire stack region to avoid SEGV in stack banging.
// It is also useful to get around the heap-stack-gap problem on SuSE
// kernel (see 4821821 for details). We first expand stack to the top
// of yellow zone, then enable stack yellow zone (order is significant,
@@ -1030,25 +1030,28 @@
extern "C" Thread* get_thread() {
return ThreadLocalStorage::thread();
}
//////////////////////////////////////////////////////////////////////////////
-// initial thread
+// primordial thread
-// Check if current thread is the initial thread, similar to Solaris thr_main.
-bool os::Linux::is_initial_thread(void) {
+// Check if current thread is the primordial thread, similar to Solaris thr_main.
+bool os::is_primordial_thread(void) {
char dummy;
// If called before init complete, thread stack bottom will be null.
// Can be called if fatal error occurs before initialization.
- if (initial_thread_stack_bottom() == NULL) return false;
- assert(initial_thread_stack_bottom() != NULL &&
- initial_thread_stack_size() != 0,
- "os::init did not locate initial thread's stack region");
- if ((address)&dummy >= initial_thread_stack_bottom() &&
- (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size())
+ if (os::Linux::initial_thread_stack_bottom() == NULL) return false;
+ assert(os::Linux::initial_thread_stack_bottom() != NULL &&
+ os::Linux::initial_thread_stack_size() != 0,
+ "os::init did not locate primordial thread's stack region");
+ if ((address)&dummy >= os::Linux::initial_thread_stack_bottom() &&
+ (address)&dummy < os::Linux::initial_thread_stack_bottom() +
+ os::Linux::initial_thread_stack_size()) {
return true;
- else return false;
+ } else {
+ return false;
+ }
}
// Find the virtual memory area that contains addr
static bool find_vma(address addr, address* vma_low, address* vma_high) {
FILE *fp = fopen("/proc/self/maps", "r");
@@ -1071,11 +1074,11 @@
fclose(fp);
}
return false;
}
-// Locate initial thread stack. This special handling of initial thread stack
+// Locate primordial thread stack. This special handling of primordial thread stack
// is needed because pthread_getattr_np() on most (all?) Linux distros returns
// bogus value for the primordial process thread. While the launcher has created
// the VM in a new thread since JDK 6, we still have to allow for the use of the
// JNI invocation API from a primordial thread.
void os::Linux::capture_initial_stack(size_t max_size) {
@@ -1095,11 +1098,14 @@
size_t stack_size = rlim.rlim_cur;
// 6308388: a bug in ld.so will relocate its own .data section to the
// lower end of primordial stack; reduce ulimit -s value a little bit
// so we won't install guard page on ld.so's data section.
+ // But ensure we don't underflow the stack size - allow 1 page spare
+ if (stack_size >= (size_t)(3 * page_size())) {
stack_size -= 2 * page_size();
+ }
// Try to figure out where the stack base (top) is. This is harder.
//
// When an application is started, glibc saves the initial stack pointer in
// a global variable "__libc_stack_end", which is then used by system
@@ -1216,20 +1222,20 @@
#undef _UFM
#undef _DFM
if (i != 28 - 2) {
assert(false, "Bad conversion from /proc/self/stat");
- // product mode - assume we are the initial thread, good luck in the
+ // product mode - assume we are the primordial thread, good luck in the
// embedded case.
- warning("Can't detect initial thread stack location - bad conversion");
+ warning("Can't detect primordial thread stack location - bad conversion");
stack_start = (uintptr_t) &rlim;
}
} else {
// For some reason we can't open /proc/self/stat (for example, running on
// FreeBSD with a Linux emulator, or inside chroot), this should work for
// most cases, so don't abort:
- warning("Can't detect initial thread stack location - no /proc/self/stat");
+ warning("Can't detect primordial thread stack location - no /proc/self/stat");
stack_start = (uintptr_t) &rlim;
}
}
// Now we have a pointer (stack_start) very close to the stack top, the
@@ -1245,11 +1251,11 @@
// success, "high" is the true stack top. (ignore "low", because initial
// thread stack grows on demand, its real bottom is high - RLIMIT_STACK.)
stack_top = (uintptr_t)high;
} else {
// failed, likely because /proc/self/maps does not exist
- warning("Can't detect initial thread stack location - find_vma failed");
+ warning("Can't detect primordial thread stack location - find_vma failed");
// best effort: stack_start is normally within a few pages below the real
// stack top, use it as stack top, and reduce stack size so we won't put
// guard page outside stack.
stack_top = stack_start;
stack_size -= 16 * page_size();
@@ -3064,15 +3070,15 @@
// 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
// munmap() the guard pages we don't leave a hole in the stack
-// mapping. This only affects the main/initial thread
+// mapping. This only affects the main/primordial thread
bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
- if (os::Linux::is_initial_thread()) {
+ if (os::is_primordial_thread()) {
// As we manually grow stack up to bottom inside create_attached_thread(),
// it's likely that os::Linux::initial_thread_stack_bottom is mapped and
// we don't need to do anything special.
// Check it first, before calling heavy function.
uintptr_t stack_extent = (uintptr_t) os::Linux::initial_thread_stack_bottom();
@@ -3093,18 +3099,18 @@
return os::commit_memory(addr, size, !ExecMem);
}
// If this is a growable mapping, remove the guard pages entirely by
// munmap()ping them. If not, just call uncommit_memory(). This only
-// affects the main/initial thread, but guard against future OS changes
-// It's safe to always unmap guard pages for initial thread because we
-// always place it right after end of the mapped region
+// affects the main/primordial thread, but guard against future OS changes.
+// It's safe to always unmap guard pages for primordial thread because we
+// always place it right after end of the mapped region.
bool os::remove_stack_guard_pages(char* addr, size_t size) {
uintptr_t stack_extent, stack_base;
- if (os::Linux::is_initial_thread()) {
+ if (os::is_primordial_thread()) {
return ::munmap(addr, size) == 0;
}
return os::uncommit_memory(addr, size);
}
@@ -4875,14 +4881,13 @@
} else {
return NULL;
}
}
-// this is called _before_ the most of global arguments have been parsed
+// this is called _before_ most of the global arguments have been parsed
void os::init(void) {
char dummy; /* used to get a guess on initial stack address */
-// first_hrtime = gethrtime();
// With LinuxThreads the JavaMain thread pid (primordial thread)
// is different than the pid of the java launcher thread.
// So, on Linux, the launcher thread pid is passed to the VM
// via the sun.java.launcher.pid property.
@@ -4905,11 +4910,11 @@
}
init_page_sizes((size_t) Linux::page_size());
Linux::initialize_system_info();
- // main_thread points to the aboriginal thread
+ // _main_thread points to the thread that created/loaded the JVM.
Linux::_main_thread = pthread_self();
Linux::clock_init();
initial_time_count = javaTimeNanos();
< prev index next >