diff --git a/src/os/aix/vm/os_aix.cpp b/src/os/aix/vm/os_aix.cpp index 4cd28b86874b446bca30a217c2167598e6334b57..9ff3f88e9dbc133e469aee6da831aafc38379995 100644 --- a/src/os/aix/vm/os_aix.cpp +++ b/src/os/aix/vm/os_aix.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright 2012, 2014 SAP AG. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -410,7 +410,7 @@ void os::Aix::query_multipage_support() { // thread (because primordial thread's stack may have different page size than // pthread thread stacks). Running a VM on the primordial thread won't work for a // number of reasons so we may just as well guarantee it here - guarantee(!os::Aix::is_primordial_thread(), "Must not be called for primordial thread"); + guarantee(!os::is_primordial_thread(), "Must not be called for primordial thread"); // query stack page size { @@ -3835,7 +3835,7 @@ void os::init(void) { ThreadCritical::initialize(); - // Main_thread points to the aboriginal thread. + // _main_thread points to the thread that created/loaded the JVM. Aix::_main_thread = pthread_self(); initial_time_count = os::elapsed_counter(); @@ -4511,7 +4511,7 @@ void os::pause() { } } -bool os::Aix::is_primordial_thread() { +bool os::is_primordial_thread(void) { if (pthread_self() == (pthread_t)1) { return true; } else { @@ -4646,7 +4646,7 @@ static void query_stack_dimensions(address* p_stack_base, size_t* p_stack_size) // This only works when invoked on a pthread. As we agreed not to use // primordial threads anyway, I assert here - guarantee(!os::Aix::is_primordial_thread(), "not allowed on the primordial thread"); + guarantee(!os::is_primordial_thread(), "not allowed on the primordial thread"); // information about this api can be found (a) in the pthread.h header and // (b) in http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/pthread_getthrds_np.htm diff --git a/src/os/aix/vm/os_aix.hpp b/src/os/aix/vm/os_aix.hpp index 01831fb7cbc0cf4bd74e707167669d8f088653fd..1fa350d326ce6740f45245beca7d0318c6cf96bd 100644 --- a/src/os/aix/vm/os_aix.hpp +++ b/src/os/aix/vm/os_aix.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright 2013 SAP AG. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -170,12 +170,6 @@ class Aix { // Given an address, returns the size of the page backing that address static size_t query_pagesize(void* p); - // Return `true' if the calling thread is the primordial thread. The - // primordial thread is the thread which contains the main function, - // *not* necessarily the thread which initialized the VM by calling - // JNI_CreateJavaVM. - static bool is_primordial_thread(void); - static int page_size(void) { assert(_page_size != -1, "not initialized"); return _page_size; diff --git a/src/os/bsd/vm/os_bsd.cpp b/src/os/bsd/vm/os_bsd.cpp index fb81191557a9adf128f6232fc578f532e3791f01..7d931f9afc60dffd10d67e646e98c1c57ef9140f 100644 --- a/src/os/bsd/vm/os_bsd.cpp +++ b/src/os/bsd/vm/os_bsd.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2015, 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 @@ -3611,7 +3611,7 @@ void os::init(void) { Bsd::initialize_system_info(); - // main_thread points to the aboriginal thread + // _main_thread points to the thread that created/loaded the JVM. Bsd::_main_thread = pthread_self(); Bsd::clock_init(); diff --git a/src/os/bsd/vm/os_bsd.hpp b/src/os/bsd/vm/os_bsd.hpp index f9803c0914ca0373b90b25b513f9c2798d746d80..f67d192dc62a3fb25be0bbf7adaed4dce474c888 100644 --- a/src/os/bsd/vm/os_bsd.hpp +++ b/src/os/bsd/vm/os_bsd.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, 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 @@ -92,7 +92,6 @@ class Bsd { static void hotspot_sigmask(Thread* thread); - static bool is_initial_thread(void); static pid_t gettid(); static int page_size(void) { return _page_size; } diff --git a/src/os/linux/vm/os_linux.cpp b/src/os/linux/vm/os_linux.cpp index 044a70a6dde2ee76370d2e22d1b424a3d2909e9d..f545709d19070b719644c3fdcc0343cd24306f4f 100644 --- a/src/os/linux/vm/os_linux.cpp +++ b/src/os/linux/vm/os_linux.cpp @@ -1,5 +1,5 @@ /* - * 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 @@ -946,8 +946,8 @@ bool os::create_attached_thread(JavaThread* thread) { } } - 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 @@ -1032,21 +1032,24 @@ extern "C" Thread* get_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 @@ -1073,7 +1076,7 @@ static bool find_vma(address addr, address* vma_low, address* vma_high) { 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 @@ -1097,7 +1100,10 @@ void os::Linux::capture_initial_stack(size_t max_size) { // 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. - stack_size -= 2 * page_size(); + // 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. // @@ -1218,16 +1224,16 @@ void os::Linux::capture_initial_stack(size_t max_size) { 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; } } @@ -1247,7 +1253,7 @@ void os::Linux::capture_initial_stack(size_t max_size) { 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. @@ -3066,11 +3072,11 @@ address get_stack_commited_bottom(address bottom, size_t size) { // 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. @@ -3095,14 +3101,14 @@ bool os::pd_create_stack_guard_pages(char* addr, size_t size) { // 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; } @@ -4877,10 +4883,9 @@ const char* os::exception_name(int exception_code, char* buf, size_t size) { } } -// 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. @@ -4907,7 +4912,7 @@ void os::init(void) { 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(); diff --git a/src/os/linux/vm/os_linux.hpp b/src/os/linux/vm/os_linux.hpp index c56983cdd1a5bcf632b28edc92016dc942b7a577..7825a6f811629421cf6168786e6580ecf0678f51 100644 --- a/src/os/linux/vm/os_linux.hpp +++ b/src/os/linux/vm/os_linux.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, 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 @@ -137,7 +137,6 @@ class Linux { static address initial_thread_stack_bottom(void) { return _initial_thread_stack_bottom; } static uintptr_t initial_thread_stack_size(void) { return _initial_thread_stack_size; } - static bool is_initial_thread(void); static int page_size(void) { return _page_size; } static void set_page_size(int val) { _page_size = val; } diff --git a/src/os/solaris/vm/os_solaris.cpp b/src/os/solaris/vm/os_solaris.cpp index 2b4e33c66ccdde8850f99eb3bb7f6c5f35eb6f90..ff4b1938ae9823116638f2e6534bfd240b2e4f35 100644 --- a/src/os/solaris/vm/os_solaris.cpp +++ b/src/os/solaris/vm/os_solaris.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -200,17 +200,21 @@ static inline stack_t get_stack_info() { return st; } -address os::current_stack_base() { +bool os::is_primordial_thread(void) { int r = thr_main() ; guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ; - bool is_primordial_thread = r; + return r == 1; +} + +address os::current_stack_base() { + bool _is_primordial_thread = is_primordial_thread(); // Workaround 4352906, avoid calls to thr_stksegment by // thr_main after the first one (it looks like we trash // some data, causing the value for ss_sp to be incorrect). - if (!is_primordial_thread || os::Solaris::_main_stack_base == NULL) { + if (!_is_primordial_thread || os::Solaris::_main_stack_base == NULL) { stack_t st = get_stack_info(); - if (is_primordial_thread) { + if (_is_primordial_thread) { // cache initial value of stack base os::Solaris::_main_stack_base = (address)st.ss_sp; } @@ -224,9 +228,7 @@ address os::current_stack_base() { size_t os::current_stack_size() { size_t size; - int r = thr_main() ; - guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ; - if(!r) { + if (!is_primordial_thread()) { size = get_stack_info().ss_size; } else { struct rlimit limits; @@ -1277,9 +1279,7 @@ void _handle_uncaught_cxx_exception() { // First crack at OS-specific initialization, from inside the new thread. void os::initialize_thread(Thread* thr) { - int r = thr_main() ; - guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ; - if (r) { + if (is_primordial_thread()) { JavaThread* jt = (JavaThread *)thr; assert(jt != NULL,"Sanity check"); size_t stack_size; @@ -4904,6 +4904,7 @@ void os::init(void) { // (Solaris only) this switches to calls that actually do locking. ThreadCritical::initialize(); + // main_thread points to the thread that created/loaded the JVM. main_thread = thr_self(); // Constant minimum stack size allowed. It must be at least diff --git a/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp b/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp index 1192f551d3a770b20f70085e7d629c0dba01bf2a..0816696bc759fe8cae3df098d23dec42f9c2fe07 100644 --- a/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp +++ b/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright 2012, 2015 SAP AG. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -510,8 +510,8 @@ size_t os::Linux::default_guard_size(os::ThreadType thr_type) { // pthread_attr_getstack() static void current_stack_region(address * bottom, size_t * size) { - if (os::Linux::is_initial_thread()) { - // initial thread needs special handling because pthread_getattr_np() + if (os::is_primordial_thread()) { + // primordial thread needs special handling because pthread_getattr_np() // may return bogus value. *bottom = os::Linux::initial_thread_stack_bottom(); *size = os::Linux::initial_thread_stack_size(); diff --git a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp index f8165a188589af5b21e3b6394c9cf82b00519fb9..2a07de42ef6558eaa9d67f633af34bb1ed3dcff2 100644 --- a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp +++ b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, 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 @@ -162,8 +162,8 @@ address os::current_stack_pointer() { } static void current_stack_region(address* bottom, size_t* size) { - if (os::Linux::is_initial_thread()) { - // initial thread needs special handling because pthread_getattr_np() + if (os::is_primordial_thread()) { + // primordial thread needs special handling because pthread_getattr_np() // may return bogus value. *bottom = os::Linux::initial_thread_stack_bottom(); *size = os::Linux::initial_thread_stack_size(); diff --git a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp index fb96738a6c64296e924747a6f9d6bb41e1ab77d5..0f38292c644e01caf60389d9b1c948100a5cf958 100644 --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, 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 @@ -712,8 +712,8 @@ size_t os::Linux::default_guard_size(os::ThreadType thr_type) { // pthread_attr_getstack() static void current_stack_region(address * bottom, size_t * size) { - if (os::Linux::is_initial_thread()) { - // initial thread needs special handling because pthread_getattr_np() + if (os::is_primordial_thread()) { + // primordial thread needs special handling because pthread_getattr_np() // may return bogus value. *bottom = os::Linux::initial_thread_stack_bottom(); *size = os::Linux::initial_thread_stack_size(); diff --git a/src/os_cpu/linux_zero/vm/os_linux_zero.cpp b/src/os_cpu/linux_zero/vm/os_linux_zero.cpp index 1d069c6de0dd8ff79657c992245fd93d726e3324..8b243778883be74d301244e0d930902c3fbf7322 100644 --- a/src/os_cpu/linux_zero/vm/os_linux_zero.cpp +++ b/src/os_cpu/linux_zero/vm/os_linux_zero.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * @@ -360,7 +360,7 @@ static void current_stack_region(address *bottom, size_t *size) { // The initial thread has a growable stack, and the size reported // by pthread_attr_getstack is the maximum size it could possibly // be given what currently mapped. This can be huge, so we cap it. - if (os::Linux::is_initial_thread()) { + if (os::is_primordial_thread()) { stack_bytes = stack_top - stack_bottom; if (stack_bytes > JavaThread::stack_size_at_create()) diff --git a/src/share/vm/memory/threadLocalAllocBuffer.cpp b/src/share/vm/memory/threadLocalAllocBuffer.cpp index 06033439c5a8b0d93d02e92cc7dba71b67beb54a..ecb2ab7fc2c6c14d831967dc8b58c74e84c7a3b8 100644 --- a/src/share/vm/memory/threadLocalAllocBuffer.cpp +++ b/src/share/vm/memory/threadLocalAllocBuffer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, 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 @@ -200,7 +200,7 @@ void ThreadLocalAllocBuffer::initialize() { set_desired_size(initial_desired_size()); - // Following check is needed because at startup the main (primordial) + // Following check is needed because at startup the main // thread is initialized before the heap is. The initialization for // this thread is redone in startup_initialization below. if (Universe::heap() != NULL) { @@ -223,7 +223,7 @@ void ThreadLocalAllocBuffer::startup_initialization() { _global_stats = new GlobalTLABStats(); - // During jvm startup, the main (primordial) thread is initialized + // During jvm startup, the main thread is initialized // before the heap is initialized. So reinitialize it now. guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread"); Thread::current()->tlab().initialize(); diff --git a/src/share/vm/runtime/globals.hpp b/src/share/vm/runtime/globals.hpp index 6c9bd3b05cc99c19d73d251288124c51d167d714..0619284c1cc934c80c9dacba4237ad3d02c11824 100644 --- a/src/share/vm/runtime/globals.hpp +++ b/src/share/vm/runtime/globals.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -1124,6 +1124,10 @@ class CommandLineFlags { "Use detached threads that are recycled upon termination " \ "(for Solaris only)") \ \ + experimental(bool, DisablePrimordialThreadGuardPages, false, \ + "Disable the use of stack guard pages if the JVM is loaded " \ + "on the primordial process thread") \ + \ product(bool, UseLWPSynchronization, true, \ "Use LWP-based instead of libthread-based synchronization " \ "(SPARC only)") \ diff --git a/src/share/vm/runtime/os.hpp b/src/share/vm/runtime/os.hpp index e008b9c64f98c862649fe0f1756feb5c2d1cb3d6..6f85ff9c1251bac9252e8da93d975cacde9ab9ea 100644 --- a/src/share/vm/runtime/os.hpp +++ b/src/share/vm/runtime/os.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -449,7 +449,24 @@ class os: AllStatic { static bool create_thread(Thread* thread, ThreadType thr_type, size_t stack_size = 0); + + // The "main thread", also known as "starting thread", is the thread + // that loads/creates the JVM via JNI_CreateJavaVM. static bool create_main_thread(JavaThread* thread); + + // The primordial thread is the initial process thread. The java + // launcher never uses the primordial thread as the main thread, but + // applications that host the JVM directly may do so. Some platforms + // need special-case handling of the primordial thread if it attaches + // to the VM. + static bool is_primordial_thread(void) +#if defined(_WINDOWS) || defined(BSD) + // No way to identify the primordial thread. + { return false; } +#else + ; +#endif + static bool create_attached_thread(JavaThread* thread); static void pd_start_thread(Thread* thread); static void start_thread(Thread* thread); diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp index 71b3b2d68e14ec9154012702563b77e06ce7d8d8..9839f288ea780fb49caace7d1798c562fbe4d39d 100644 --- a/src/share/vm/runtime/thread.cpp +++ b/src/share/vm/runtime/thread.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -2485,7 +2485,15 @@ void JavaThread::java_resume() { } void JavaThread::create_stack_guard_pages() { - if (! os::uses_stack_guard_pages() || _stack_guard_state != stack_guard_unused) return; + if (!os::uses_stack_guard_pages() || + _stack_guard_state != stack_guard_unused || + (DisablePrimordialThreadGuardPages && os::is_primordial_thread())) { + if (TraceThreadEvents) { + tty->print_cr("Stack guard page creation for thread " + UINTX_FORMAT " disabled", os::current_thread_id()); + } + return; + } address low_addr = stack_base() - stack_size(); size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size(); diff --git a/src/share/vm/runtime/thread.hpp b/src/share/vm/runtime/thread.hpp index 1117c872bf1533f4e700548aabc9e2adadfcd335..9824febabf8b9d753fd4d255295ee8c250bff6db 100644 --- a/src/share/vm/runtime/thread.hpp +++ b/src/share/vm/runtime/thread.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -1801,7 +1801,8 @@ inline bool JavaThread::stack_yellow_zone_disabled() { inline bool JavaThread::stack_yellow_zone_enabled() { #ifdef ASSERT - if (os::uses_stack_guard_pages()) { + if (os::uses_stack_guard_pages() && + !(DisablePrimordialThreadGuardPages && os::is_primordial_thread())) { assert(_stack_guard_state != stack_guard_unused, "guard pages must be in use"); } #endif