Wed, 31 Jan 2018 19:24:57 -0500
8189170: Add option to disable stack overflow checking in primordial thread for use with JNI_CreateJavaJVM
Reviewed-by: dcubed
1.1 --- a/src/os/aix/vm/os_aix.cpp Tue Jan 16 04:20:19 2018 -0500 1.2 +++ b/src/os/aix/vm/os_aix.cpp Wed Jan 31 19:24:57 2018 -0500 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 1.7 * Copyright 2012, 2014 SAP AG. All rights reserved. 1.8 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.9 * 1.10 @@ -410,7 +410,7 @@ 1.11 // thread (because primordial thread's stack may have different page size than 1.12 // pthread thread stacks). Running a VM on the primordial thread won't work for a 1.13 // number of reasons so we may just as well guarantee it here 1.14 - guarantee(!os::Aix::is_primordial_thread(), "Must not be called for primordial thread"); 1.15 + guarantee(!os::is_primordial_thread(), "Must not be called for primordial thread"); 1.16 1.17 // query stack page size 1.18 { 1.19 @@ -3835,7 +3835,7 @@ 1.20 1.21 ThreadCritical::initialize(); 1.22 1.23 - // Main_thread points to the aboriginal thread. 1.24 + // _main_thread points to the thread that created/loaded the JVM. 1.25 Aix::_main_thread = pthread_self(); 1.26 1.27 initial_time_count = os::elapsed_counter(); 1.28 @@ -4511,7 +4511,7 @@ 1.29 } 1.30 } 1.31 1.32 -bool os::Aix::is_primordial_thread() { 1.33 +bool os::is_primordial_thread(void) { 1.34 if (pthread_self() == (pthread_t)1) { 1.35 return true; 1.36 } else { 1.37 @@ -4646,7 +4646,7 @@ 1.38 1.39 // This only works when invoked on a pthread. As we agreed not to use 1.40 // primordial threads anyway, I assert here 1.41 - guarantee(!os::Aix::is_primordial_thread(), "not allowed on the primordial thread"); 1.42 + guarantee(!os::is_primordial_thread(), "not allowed on the primordial thread"); 1.43 1.44 // information about this api can be found (a) in the pthread.h header and 1.45 // (b) in http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/pthread_getthrds_np.htm
2.1 --- a/src/os/aix/vm/os_aix.hpp Tue Jan 16 04:20:19 2018 -0500 2.2 +++ b/src/os/aix/vm/os_aix.hpp Wed Jan 31 19:24:57 2018 -0500 2.3 @@ -1,5 +1,5 @@ 2.4 /* 2.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 2.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 2.7 * Copyright 2013 SAP AG. All rights reserved. 2.8 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.9 * 2.10 @@ -170,12 +170,6 @@ 2.11 // Given an address, returns the size of the page backing that address 2.12 static size_t query_pagesize(void* p); 2.13 2.14 - // Return `true' if the calling thread is the primordial thread. The 2.15 - // primordial thread is the thread which contains the main function, 2.16 - // *not* necessarily the thread which initialized the VM by calling 2.17 - // JNI_CreateJavaVM. 2.18 - static bool is_primordial_thread(void); 2.19 - 2.20 static int page_size(void) { 2.21 assert(_page_size != -1, "not initialized"); 2.22 return _page_size;
3.1 --- a/src/os/bsd/vm/os_bsd.cpp Tue Jan 16 04:20:19 2018 -0500 3.2 +++ b/src/os/bsd/vm/os_bsd.cpp Wed Jan 31 19:24:57 2018 -0500 3.3 @@ -1,5 +1,5 @@ 3.4 /* 3.5 - * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. 3.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 3.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3.8 * 3.9 * This code is free software; you can redistribute it and/or modify it 3.10 @@ -3611,7 +3611,7 @@ 3.11 3.12 Bsd::initialize_system_info(); 3.13 3.14 - // main_thread points to the aboriginal thread 3.15 + // _main_thread points to the thread that created/loaded the JVM. 3.16 Bsd::_main_thread = pthread_self(); 3.17 3.18 Bsd::clock_init();
4.1 --- a/src/os/bsd/vm/os_bsd.hpp Tue Jan 16 04:20:19 2018 -0500 4.2 +++ b/src/os/bsd/vm/os_bsd.hpp Wed Jan 31 19:24:57 2018 -0500 4.3 @@ -1,5 +1,5 @@ 4.4 /* 4.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 4.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 4.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.8 * 4.9 * This code is free software; you can redistribute it and/or modify it 4.10 @@ -92,7 +92,6 @@ 4.11 4.12 static void hotspot_sigmask(Thread* thread); 4.13 4.14 - static bool is_initial_thread(void); 4.15 static pid_t gettid(); 4.16 4.17 static int page_size(void) { return _page_size; }
5.1 --- a/src/os/linux/vm/os_linux.cpp Tue Jan 16 04:20:19 2018 -0500 5.2 +++ b/src/os/linux/vm/os_linux.cpp Wed Jan 31 19:24:57 2018 -0500 5.3 @@ -1,5 +1,5 @@ 5.4 /* 5.5 - * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved. 5.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 5.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5.8 * 5.9 * This code is free software; you can redistribute it and/or modify it 5.10 @@ -946,8 +946,8 @@ 5.11 } 5.12 } 5.13 5.14 - if (os::Linux::is_initial_thread()) { 5.15 - // If current thread is initial thread, its stack is mapped on demand, 5.16 + if (os::is_primordial_thread()) { 5.17 + // If current thread is primordial thread, its stack is mapped on demand, 5.18 // see notes about MAP_GROWSDOWN. Here we try to force kernel to map 5.19 // the entire stack region to avoid SEGV in stack banging. 5.20 // It is also useful to get around the heap-stack-gap problem on SuSE 5.21 @@ -1032,21 +1032,24 @@ 5.22 } 5.23 5.24 ////////////////////////////////////////////////////////////////////////////// 5.25 -// initial thread 5.26 - 5.27 -// Check if current thread is the initial thread, similar to Solaris thr_main. 5.28 -bool os::Linux::is_initial_thread(void) { 5.29 +// primordial thread 5.30 + 5.31 +// Check if current thread is the primordial thread, similar to Solaris thr_main. 5.32 +bool os::is_primordial_thread(void) { 5.33 char dummy; 5.34 // If called before init complete, thread stack bottom will be null. 5.35 // Can be called if fatal error occurs before initialization. 5.36 - if (initial_thread_stack_bottom() == NULL) return false; 5.37 - assert(initial_thread_stack_bottom() != NULL && 5.38 - initial_thread_stack_size() != 0, 5.39 - "os::init did not locate initial thread's stack region"); 5.40 - if ((address)&dummy >= initial_thread_stack_bottom() && 5.41 - (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size()) 5.42 + if (os::Linux::initial_thread_stack_bottom() == NULL) return false; 5.43 + assert(os::Linux::initial_thread_stack_bottom() != NULL && 5.44 + os::Linux::initial_thread_stack_size() != 0, 5.45 + "os::init did not locate primordial thread's stack region"); 5.46 + if ((address)&dummy >= os::Linux::initial_thread_stack_bottom() && 5.47 + (address)&dummy < os::Linux::initial_thread_stack_bottom() + 5.48 + os::Linux::initial_thread_stack_size()) { 5.49 return true; 5.50 - else return false; 5.51 + } else { 5.52 + return false; 5.53 + } 5.54 } 5.55 5.56 // Find the virtual memory area that contains addr 5.57 @@ -1073,7 +1076,7 @@ 5.58 return false; 5.59 } 5.60 5.61 -// Locate initial thread stack. This special handling of initial thread stack 5.62 +// Locate primordial thread stack. This special handling of primordial thread stack 5.63 // is needed because pthread_getattr_np() on most (all?) Linux distros returns 5.64 // bogus value for the primordial process thread. While the launcher has created 5.65 // the VM in a new thread since JDK 6, we still have to allow for the use of the 5.66 @@ -1097,7 +1100,10 @@ 5.67 // 6308388: a bug in ld.so will relocate its own .data section to the 5.68 // lower end of primordial stack; reduce ulimit -s value a little bit 5.69 // so we won't install guard page on ld.so's data section. 5.70 - stack_size -= 2 * page_size(); 5.71 + // But ensure we don't underflow the stack size - allow 1 page spare 5.72 + if (stack_size >= (size_t)(3 * page_size())) { 5.73 + stack_size -= 2 * page_size(); 5.74 + } 5.75 5.76 // Try to figure out where the stack base (top) is. This is harder. 5.77 // 5.78 @@ -1218,16 +1224,16 @@ 5.79 5.80 if (i != 28 - 2) { 5.81 assert(false, "Bad conversion from /proc/self/stat"); 5.82 - // product mode - assume we are the initial thread, good luck in the 5.83 + // product mode - assume we are the primordial thread, good luck in the 5.84 // embedded case. 5.85 - warning("Can't detect initial thread stack location - bad conversion"); 5.86 + warning("Can't detect primordial thread stack location - bad conversion"); 5.87 stack_start = (uintptr_t) &rlim; 5.88 } 5.89 } else { 5.90 // For some reason we can't open /proc/self/stat (for example, running on 5.91 // FreeBSD with a Linux emulator, or inside chroot), this should work for 5.92 // most cases, so don't abort: 5.93 - warning("Can't detect initial thread stack location - no /proc/self/stat"); 5.94 + warning("Can't detect primordial thread stack location - no /proc/self/stat"); 5.95 stack_start = (uintptr_t) &rlim; 5.96 } 5.97 } 5.98 @@ -1247,7 +1253,7 @@ 5.99 stack_top = (uintptr_t)high; 5.100 } else { 5.101 // failed, likely because /proc/self/maps does not exist 5.102 - warning("Can't detect initial thread stack location - find_vma failed"); 5.103 + warning("Can't detect primordial thread stack location - find_vma failed"); 5.104 // best effort: stack_start is normally within a few pages below the real 5.105 // stack top, use it as stack top, and reduce stack size so we won't put 5.106 // guard page outside stack. 5.107 @@ -3066,11 +3072,11 @@ 5.108 // where we're going to put our guard pages, truncate the mapping at 5.109 // that point by munmap()ping it. This ensures that when we later 5.110 // munmap() the guard pages we don't leave a hole in the stack 5.111 -// mapping. This only affects the main/initial thread 5.112 +// mapping. This only affects the main/primordial thread 5.113 5.114 bool os::pd_create_stack_guard_pages(char* addr, size_t size) { 5.115 5.116 - if (os::Linux::is_initial_thread()) { 5.117 + if (os::is_primordial_thread()) { 5.118 // As we manually grow stack up to bottom inside create_attached_thread(), 5.119 // it's likely that os::Linux::initial_thread_stack_bottom is mapped and 5.120 // we don't need to do anything special. 5.121 @@ -3095,14 +3101,14 @@ 5.122 5.123 // If this is a growable mapping, remove the guard pages entirely by 5.124 // munmap()ping them. If not, just call uncommit_memory(). This only 5.125 -// affects the main/initial thread, but guard against future OS changes 5.126 -// It's safe to always unmap guard pages for initial thread because we 5.127 -// always place it right after end of the mapped region 5.128 +// affects the main/primordial thread, but guard against future OS changes. 5.129 +// It's safe to always unmap guard pages for primordial thread because we 5.130 +// always place it right after end of the mapped region. 5.131 5.132 bool os::remove_stack_guard_pages(char* addr, size_t size) { 5.133 uintptr_t stack_extent, stack_base; 5.134 5.135 - if (os::Linux::is_initial_thread()) { 5.136 + if (os::is_primordial_thread()) { 5.137 return ::munmap(addr, size) == 0; 5.138 } 5.139 5.140 @@ -4877,10 +4883,9 @@ 5.141 } 5.142 } 5.143 5.144 -// this is called _before_ the most of global arguments have been parsed 5.145 +// this is called _before_ most of the global arguments have been parsed 5.146 void os::init(void) { 5.147 char dummy; /* used to get a guess on initial stack address */ 5.148 -// first_hrtime = gethrtime(); 5.149 5.150 // With LinuxThreads the JavaMain thread pid (primordial thread) 5.151 // is different than the pid of the java launcher thread. 5.152 @@ -4907,7 +4912,7 @@ 5.153 5.154 Linux::initialize_system_info(); 5.155 5.156 - // main_thread points to the aboriginal thread 5.157 + // _main_thread points to the thread that created/loaded the JVM. 5.158 Linux::_main_thread = pthread_self(); 5.159 5.160 Linux::clock_init();
6.1 --- a/src/os/linux/vm/os_linux.hpp Tue Jan 16 04:20:19 2018 -0500 6.2 +++ b/src/os/linux/vm/os_linux.hpp Wed Jan 31 19:24:57 2018 -0500 6.3 @@ -1,5 +1,5 @@ 6.4 /* 6.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 6.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 6.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.8 * 6.9 * This code is free software; you can redistribute it and/or modify it 6.10 @@ -137,7 +137,6 @@ 6.11 6.12 static address initial_thread_stack_bottom(void) { return _initial_thread_stack_bottom; } 6.13 static uintptr_t initial_thread_stack_size(void) { return _initial_thread_stack_size; } 6.14 - static bool is_initial_thread(void); 6.15 6.16 static int page_size(void) { return _page_size; } 6.17 static void set_page_size(int val) { _page_size = val; }
7.1 --- a/src/os/solaris/vm/os_solaris.cpp Tue Jan 16 04:20:19 2018 -0500 7.2 +++ b/src/os/solaris/vm/os_solaris.cpp Wed Jan 31 19:24:57 2018 -0500 7.3 @@ -1,5 +1,5 @@ 7.4 /* 7.5 - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 7.6 + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 7.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.8 * 7.9 * This code is free software; you can redistribute it and/or modify it 7.10 @@ -200,17 +200,21 @@ 7.11 return st; 7.12 } 7.13 7.14 -address os::current_stack_base() { 7.15 +bool os::is_primordial_thread(void) { 7.16 int r = thr_main() ; 7.17 guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ; 7.18 - bool is_primordial_thread = r; 7.19 + return r == 1; 7.20 +} 7.21 + 7.22 +address os::current_stack_base() { 7.23 + bool _is_primordial_thread = is_primordial_thread(); 7.24 7.25 // Workaround 4352906, avoid calls to thr_stksegment by 7.26 // thr_main after the first one (it looks like we trash 7.27 // some data, causing the value for ss_sp to be incorrect). 7.28 - if (!is_primordial_thread || os::Solaris::_main_stack_base == NULL) { 7.29 + if (!_is_primordial_thread || os::Solaris::_main_stack_base == NULL) { 7.30 stack_t st = get_stack_info(); 7.31 - if (is_primordial_thread) { 7.32 + if (_is_primordial_thread) { 7.33 // cache initial value of stack base 7.34 os::Solaris::_main_stack_base = (address)st.ss_sp; 7.35 } 7.36 @@ -224,9 +228,7 @@ 7.37 size_t os::current_stack_size() { 7.38 size_t size; 7.39 7.40 - int r = thr_main() ; 7.41 - guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ; 7.42 - if(!r) { 7.43 + if (!is_primordial_thread()) { 7.44 size = get_stack_info().ss_size; 7.45 } else { 7.46 struct rlimit limits; 7.47 @@ -1277,9 +1279,7 @@ 7.48 7.49 // First crack at OS-specific initialization, from inside the new thread. 7.50 void os::initialize_thread(Thread* thr) { 7.51 - int r = thr_main() ; 7.52 - guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ; 7.53 - if (r) { 7.54 + if (is_primordial_thread()) { 7.55 JavaThread* jt = (JavaThread *)thr; 7.56 assert(jt != NULL,"Sanity check"); 7.57 size_t stack_size; 7.58 @@ -4904,6 +4904,7 @@ 7.59 // (Solaris only) this switches to calls that actually do locking. 7.60 ThreadCritical::initialize(); 7.61 7.62 + // main_thread points to the thread that created/loaded the JVM. 7.63 main_thread = thr_self(); 7.64 7.65 // Constant minimum stack size allowed. It must be at least
8.1 --- a/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp Tue Jan 16 04:20:19 2018 -0500 8.2 +++ b/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp Wed Jan 31 19:24:57 2018 -0500 8.3 @@ -1,5 +1,5 @@ 8.4 /* 8.5 - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 8.6 + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 8.7 * Copyright 2012, 2015 SAP AG. All rights reserved. 8.8 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.9 * 8.10 @@ -510,8 +510,8 @@ 8.11 // pthread_attr_getstack() 8.12 8.13 static void current_stack_region(address * bottom, size_t * size) { 8.14 - if (os::Linux::is_initial_thread()) { 8.15 - // initial thread needs special handling because pthread_getattr_np() 8.16 + if (os::is_primordial_thread()) { 8.17 + // primordial thread needs special handling because pthread_getattr_np() 8.18 // may return bogus value. 8.19 *bottom = os::Linux::initial_thread_stack_bottom(); 8.20 *size = os::Linux::initial_thread_stack_size();
9.1 --- a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Tue Jan 16 04:20:19 2018 -0500 9.2 +++ b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Wed Jan 31 19:24:57 2018 -0500 9.3 @@ -1,5 +1,5 @@ 9.4 /* 9.5 - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. 9.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 9.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9.8 * 9.9 * This code is free software; you can redistribute it and/or modify it 9.10 @@ -162,8 +162,8 @@ 9.11 } 9.12 9.13 static void current_stack_region(address* bottom, size_t* size) { 9.14 - if (os::Linux::is_initial_thread()) { 9.15 - // initial thread needs special handling because pthread_getattr_np() 9.16 + if (os::is_primordial_thread()) { 9.17 + // primordial thread needs special handling because pthread_getattr_np() 9.18 // may return bogus value. 9.19 *bottom = os::Linux::initial_thread_stack_bottom(); 9.20 *size = os::Linux::initial_thread_stack_size();
10.1 --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Tue Jan 16 04:20:19 2018 -0500 10.2 +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Wed Jan 31 19:24:57 2018 -0500 10.3 @@ -1,5 +1,5 @@ 10.4 /* 10.5 - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 10.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 10.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.8 * 10.9 * This code is free software; you can redistribute it and/or modify it 10.10 @@ -712,8 +712,8 @@ 10.11 // pthread_attr_getstack() 10.12 10.13 static void current_stack_region(address * bottom, size_t * size) { 10.14 - if (os::Linux::is_initial_thread()) { 10.15 - // initial thread needs special handling because pthread_getattr_np() 10.16 + if (os::is_primordial_thread()) { 10.17 + // primordial thread needs special handling because pthread_getattr_np() 10.18 // may return bogus value. 10.19 *bottom = os::Linux::initial_thread_stack_bottom(); 10.20 *size = os::Linux::initial_thread_stack_size();
11.1 --- a/src/os_cpu/linux_zero/vm/os_linux_zero.cpp Tue Jan 16 04:20:19 2018 -0500 11.2 +++ b/src/os_cpu/linux_zero/vm/os_linux_zero.cpp Wed Jan 31 19:24:57 2018 -0500 11.3 @@ -1,5 +1,5 @@ 11.4 /* 11.5 - * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. 11.6 + * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. 11.7 * Copyright 2007, 2008, 2009, 2010 Red Hat, Inc. 11.8 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.9 * 11.10 @@ -360,7 +360,7 @@ 11.11 // The initial thread has a growable stack, and the size reported 11.12 // by pthread_attr_getstack is the maximum size it could possibly 11.13 // be given what currently mapped. This can be huge, so we cap it. 11.14 - if (os::Linux::is_initial_thread()) { 11.15 + if (os::is_primordial_thread()) { 11.16 stack_bytes = stack_top - stack_bottom; 11.17 11.18 if (stack_bytes > JavaThread::stack_size_at_create())
12.1 --- a/src/share/vm/memory/threadLocalAllocBuffer.cpp Tue Jan 16 04:20:19 2018 -0500 12.2 +++ b/src/share/vm/memory/threadLocalAllocBuffer.cpp Wed Jan 31 19:24:57 2018 -0500 12.3 @@ -1,5 +1,5 @@ 12.4 /* 12.5 - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. 12.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved. 12.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.8 * 12.9 * This code is free software; you can redistribute it and/or modify it 12.10 @@ -200,7 +200,7 @@ 12.11 12.12 set_desired_size(initial_desired_size()); 12.13 12.14 - // Following check is needed because at startup the main (primordial) 12.15 + // Following check is needed because at startup the main 12.16 // thread is initialized before the heap is. The initialization for 12.17 // this thread is redone in startup_initialization below. 12.18 if (Universe::heap() != NULL) { 12.19 @@ -223,7 +223,7 @@ 12.20 12.21 _global_stats = new GlobalTLABStats(); 12.22 12.23 - // During jvm startup, the main (primordial) thread is initialized 12.24 + // During jvm startup, the main thread is initialized 12.25 // before the heap is initialized. So reinitialize it now. 12.26 guarantee(Thread::current()->is_Java_thread(), "tlab initialization thread not Java thread"); 12.27 Thread::current()->tlab().initialize();
13.1 --- a/src/share/vm/runtime/globals.hpp Tue Jan 16 04:20:19 2018 -0500 13.2 +++ b/src/share/vm/runtime/globals.hpp Wed Jan 31 19:24:57 2018 -0500 13.3 @@ -1,5 +1,5 @@ 13.4 /* 13.5 - * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. 13.6 + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 13.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 13.8 * 13.9 * This code is free software; you can redistribute it and/or modify it 13.10 @@ -1124,6 +1124,10 @@ 13.11 "Use detached threads that are recycled upon termination " \ 13.12 "(for Solaris only)") \ 13.13 \ 13.14 + experimental(bool, DisablePrimordialThreadGuardPages, false, \ 13.15 + "Disable the use of stack guard pages if the JVM is loaded " \ 13.16 + "on the primordial process thread") \ 13.17 + \ 13.18 product(bool, UseLWPSynchronization, true, \ 13.19 "Use LWP-based instead of libthread-based synchronization " \ 13.20 "(SPARC only)") \
14.1 --- a/src/share/vm/runtime/os.hpp Tue Jan 16 04:20:19 2018 -0500 14.2 +++ b/src/share/vm/runtime/os.hpp Wed Jan 31 19:24:57 2018 -0500 14.3 @@ -1,5 +1,5 @@ 14.4 /* 14.5 - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. 14.6 + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 14.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 14.8 * 14.9 * This code is free software; you can redistribute it and/or modify it 14.10 @@ -449,7 +449,24 @@ 14.11 static bool create_thread(Thread* thread, 14.12 ThreadType thr_type, 14.13 size_t stack_size = 0); 14.14 + 14.15 + // The "main thread", also known as "starting thread", is the thread 14.16 + // that loads/creates the JVM via JNI_CreateJavaVM. 14.17 static bool create_main_thread(JavaThread* thread); 14.18 + 14.19 + // The primordial thread is the initial process thread. The java 14.20 + // launcher never uses the primordial thread as the main thread, but 14.21 + // applications that host the JVM directly may do so. Some platforms 14.22 + // need special-case handling of the primordial thread if it attaches 14.23 + // to the VM. 14.24 + static bool is_primordial_thread(void) 14.25 +#if defined(_WINDOWS) || defined(BSD) 14.26 + // No way to identify the primordial thread. 14.27 + { return false; } 14.28 +#else 14.29 + ; 14.30 +#endif 14.31 + 14.32 static bool create_attached_thread(JavaThread* thread); 14.33 static void pd_start_thread(Thread* thread); 14.34 static void start_thread(Thread* thread);
15.1 --- a/src/share/vm/runtime/thread.cpp Tue Jan 16 04:20:19 2018 -0500 15.2 +++ b/src/share/vm/runtime/thread.cpp Wed Jan 31 19:24:57 2018 -0500 15.3 @@ -1,5 +1,5 @@ 15.4 /* 15.5 - * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved. 15.6 + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 15.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.8 * 15.9 * This code is free software; you can redistribute it and/or modify it 15.10 @@ -2485,7 +2485,15 @@ 15.11 } 15.12 15.13 void JavaThread::create_stack_guard_pages() { 15.14 - if (! os::uses_stack_guard_pages() || _stack_guard_state != stack_guard_unused) return; 15.15 + if (!os::uses_stack_guard_pages() || 15.16 + _stack_guard_state != stack_guard_unused || 15.17 + (DisablePrimordialThreadGuardPages && os::is_primordial_thread())) { 15.18 + if (TraceThreadEvents) { 15.19 + tty->print_cr("Stack guard page creation for thread " 15.20 + UINTX_FORMAT " disabled", os::current_thread_id()); 15.21 + } 15.22 + return; 15.23 + } 15.24 address low_addr = stack_base() - stack_size(); 15.25 size_t len = (StackYellowPages + StackRedPages) * os::vm_page_size(); 15.26
16.1 --- a/src/share/vm/runtime/thread.hpp Tue Jan 16 04:20:19 2018 -0500 16.2 +++ b/src/share/vm/runtime/thread.hpp Wed Jan 31 19:24:57 2018 -0500 16.3 @@ -1,5 +1,5 @@ 16.4 /* 16.5 - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 16.6 + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 16.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 16.8 * 16.9 * This code is free software; you can redistribute it and/or modify it 16.10 @@ -1801,7 +1801,8 @@ 16.11 16.12 inline bool JavaThread::stack_yellow_zone_enabled() { 16.13 #ifdef ASSERT 16.14 - if (os::uses_stack_guard_pages()) { 16.15 + if (os::uses_stack_guard_pages() && 16.16 + !(DisablePrimordialThreadGuardPages && os::is_primordial_thread())) { 16.17 assert(_stack_guard_state != stack_guard_unused, "guard pages must be in use"); 16.18 } 16.19 #endif