Skip to content

Instantly share code, notes, and snippets.

@tstuefe
Last active July 19, 2023 12:32
Show Gist options
  • Save tstuefe/8a0fd30618f1d0e085b5ca12d7c156cd to your computer and use it in GitHub Desktop.
Save tstuefe/8a0fd30618f1d0e085b5ca12d7c156cd to your computer and use it in GitHub Desktop.
commit 60dc9adee66e6f83ccb406a965e61c49e2541d28
Author: tstuefe <thomas.stuefe@gmail.com>
Date: Wed Jul 19 14:29:12 2023 +0200
remove TLS stuff
diff --git a/src/hotspot/os/linux/os_linux.cpp b/src/hotspot/os/linux/os_linux.cpp
index 9f357d8e6b0..3dd44c1e0d2 100644
--- a/src/hotspot/os/linux/os_linux.cpp
+++ b/src/hotspot/os/linux/os_linux.cpp
@@ -835,67 +835,10 @@ static void *thread_native_entry(Thread *thread) {
return 0;
}
-// On Linux, glibc places static TLS blocks (for __thread variables) on
-// the thread stack. This decreases the stack size actually available
-// to threads.
-//
-// For large static TLS sizes, this may cause threads to malfunction due
-// to insufficient stack space. This is a well-known issue in glibc:
-// http://sourceware.org/bugzilla/show_bug.cgi?id=11787.
-//
-// As a workaround, we call a private but assumed-stable glibc function,
-// __pthread_get_minstack() to obtain the minstack size and derive the
-// static TLS size from it. We then increase the user requested stack
-// size by this TLS size. The same function is used to determine whether
-// adjustStackSizeForGuardPages() needs to be true.
-//
-// Due to compatibility concerns, this size adjustment is opt-in and
-// controlled via AdjustStackSizeForTLS.
typedef size_t (*GetMinStack)(const pthread_attr_t *attr);
GetMinStack _get_minstack_func = NULL; // Initialized via os::init_2()
-// Returns the size of the static TLS area glibc puts on thread stacks.
-// The value is cached on first use, which occurs when the first thread
-// is created during VM initialization.
-static size_t get_static_tls_area_size(const pthread_attr_t *attr) {
- size_t tls_size = 0;
- if (_get_minstack_func != NULL) {
- // Obtain the pthread minstack size by calling __pthread_get_minstack.
- size_t minstack_size = _get_minstack_func(attr);
-
- // Remove non-TLS area size included in minstack size returned
- // by __pthread_get_minstack() to get the static TLS size.
- // If adjustStackSizeForGuardPages() is true, minstack size includes
- // guard_size. Otherwise guard_size is automatically added
- // to the stack size by pthread_create and is no longer included
- // in minstack size. In both cases, the guard_size is taken into
- // account, so there is no need to adjust the result for that.
- //
- // Although __pthread_get_minstack() is a private glibc function,
- // it is expected to have a stable behavior across future glibc
- // versions while glibc still allocates the static TLS blocks off
- // the stack. Following is glibc 2.28 __pthread_get_minstack():
- //
- // size_t
- // __pthread_get_minstack (const pthread_attr_t *attr)
- // {
- // return GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN;
- // }
- //
- //
- // The following 'minstack_size > os::vm_page_size() + PTHREAD_STACK_MIN'
- // if check is done for precaution.
- if (minstack_size > (size_t)os::vm_page_size() + PTHREAD_STACK_MIN) {
- tls_size = minstack_size - (size_t)os::vm_page_size() - PTHREAD_STACK_MIN;
- }
- }
-
- log_info(os, thread)("Stack size adjustment for TLS is " SIZE_FORMAT,
- tls_size);
- return tls_size;
-}
-
// In glibc versions prior to 2.27 the guard size mechanism
// was not implemented properly. The POSIX standard requires adding
// the size of the guard pages to the stack size, instead glibc
@@ -909,7 +852,6 @@ bool os::Linux::adjustStackSizeForGuardPages() {
}
#if defined(__GLIBC__) // TLS not in jdk11
-static bool AdjustStackSizeForTLS = false; // Dumy decl as substitute for cmdline parameter
static void init_adjust_stacksize_for_guard_pages() {
assert(_get_minstack_func == NULL, "initialization error");
_get_minstack_func =(GetMinStack)dlsym(RTLD_DEFAULT, "__pthread_get_minstack");
@@ -966,10 +908,7 @@ bool os::create_thread(Thread* thread, ThreadType thr_type,
// Apply stack size adjustments if needed. However, be careful not to end up
// with a size of zero due to overflow. Don't add the adjustment in that case.
size_t stack_adjust_size = 0;
- if (AdjustStackSizeForTLS) {
- // Adjust the stack_size for on-stack TLS - see get_static_tls_area_size().
- stack_adjust_size += get_static_tls_area_size(&attr);
- } else if (os::Linux::adjustStackSizeForGuardPages()) {
+ if (os::Linux::adjustStackSizeForGuardPages()) {
stack_adjust_size += guard_size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment