src/os/linux/vm/os_linux.cpp

changeset 9291
a2c8195708cc
parent 9013
18366fa39fe0
parent 9289
427b2fb1944f
child 9348
cb9634ab2906
     1.1 --- a/src/os/linux/vm/os_linux.cpp	Mon Jan 22 11:11:36 2018 -0800
     1.2 +++ b/src/os/linux/vm/os_linux.cpp	Wed Feb 07 10:45:15 2018 -0800
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -946,8 +946,8 @@
    1.11      }
    1.12    }
    1.13  
    1.14 -  if (os::Linux::is_initial_thread()) {
    1.15 -    // If current thread is initial thread, its stack is mapped on demand,
    1.16 +  if (os::is_primordial_thread()) {
    1.17 +    // If current thread is primordial thread, its stack is mapped on demand,
    1.18      // see notes about MAP_GROWSDOWN. Here we try to force kernel to map
    1.19      // the entire stack region to avoid SEGV in stack banging.
    1.20      // It is also useful to get around the heap-stack-gap problem on SuSE
    1.21 @@ -1032,21 +1032,24 @@
    1.22  }
    1.23  
    1.24  //////////////////////////////////////////////////////////////////////////////
    1.25 -// initial thread
    1.26 -
    1.27 -// Check if current thread is the initial thread, similar to Solaris thr_main.
    1.28 -bool os::Linux::is_initial_thread(void) {
    1.29 +// primordial thread
    1.30 +
    1.31 +// Check if current thread is the primordial thread, similar to Solaris thr_main.
    1.32 +bool os::is_primordial_thread(void) {
    1.33    char dummy;
    1.34    // If called before init complete, thread stack bottom will be null.
    1.35    // Can be called if fatal error occurs before initialization.
    1.36 -  if (initial_thread_stack_bottom() == NULL) return false;
    1.37 -  assert(initial_thread_stack_bottom() != NULL &&
    1.38 -         initial_thread_stack_size()   != 0,
    1.39 -         "os::init did not locate initial thread's stack region");
    1.40 -  if ((address)&dummy >= initial_thread_stack_bottom() &&
    1.41 -      (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size())
    1.42 +  if (os::Linux::initial_thread_stack_bottom() == NULL) return false;
    1.43 +  assert(os::Linux::initial_thread_stack_bottom() != NULL &&
    1.44 +         os::Linux::initial_thread_stack_size()   != 0,
    1.45 +         "os::init did not locate primordial thread's stack region");
    1.46 +  if ((address)&dummy >= os::Linux::initial_thread_stack_bottom() &&
    1.47 +      (address)&dummy < os::Linux::initial_thread_stack_bottom() +
    1.48 +                        os::Linux::initial_thread_stack_size()) {
    1.49         return true;
    1.50 -  else return false;
    1.51 +  } else {
    1.52 +       return false;
    1.53 +  }
    1.54  }
    1.55  
    1.56  // Find the virtual memory area that contains addr
    1.57 @@ -1073,7 +1076,7 @@
    1.58    return false;
    1.59  }
    1.60  
    1.61 -// Locate initial thread stack. This special handling of initial thread stack
    1.62 +// Locate primordial thread stack. This special handling of primordial thread stack
    1.63  // is needed because pthread_getattr_np() on most (all?) Linux distros returns
    1.64  // bogus value for the primordial process thread. While the launcher has created
    1.65  // the VM in a new thread since JDK 6, we still have to allow for the use of the
    1.66 @@ -1097,7 +1100,10 @@
    1.67    // 6308388: a bug in ld.so will relocate its own .data section to the
    1.68    //   lower end of primordial stack; reduce ulimit -s value a little bit
    1.69    //   so we won't install guard page on ld.so's data section.
    1.70 -  stack_size -= 2 * page_size();
    1.71 +  //   But ensure we don't underflow the stack size - allow 1 page spare
    1.72 +  if (stack_size >= (size_t)(3 * page_size())) {
    1.73 +    stack_size -= 2 * page_size();
    1.74 +  }
    1.75  
    1.76    // Try to figure out where the stack base (top) is. This is harder.
    1.77    //
    1.78 @@ -1218,16 +1224,16 @@
    1.79  
    1.80        if (i != 28 - 2) {
    1.81           assert(false, "Bad conversion from /proc/self/stat");
    1.82 -         // product mode - assume we are the initial thread, good luck in the
    1.83 +         // product mode - assume we are the primordial thread, good luck in the
    1.84           // embedded case.
    1.85 -         warning("Can't detect initial thread stack location - bad conversion");
    1.86 +         warning("Can't detect primordial thread stack location - bad conversion");
    1.87           stack_start = (uintptr_t) &rlim;
    1.88        }
    1.89      } else {
    1.90        // For some reason we can't open /proc/self/stat (for example, running on
    1.91        // FreeBSD with a Linux emulator, or inside chroot), this should work for
    1.92        // most cases, so don't abort:
    1.93 -      warning("Can't detect initial thread stack location - no /proc/self/stat");
    1.94 +      warning("Can't detect primordial thread stack location - no /proc/self/stat");
    1.95        stack_start = (uintptr_t) &rlim;
    1.96      }
    1.97    }
    1.98 @@ -1247,7 +1253,7 @@
    1.99      stack_top = (uintptr_t)high;
   1.100    } else {
   1.101      // failed, likely because /proc/self/maps does not exist
   1.102 -    warning("Can't detect initial thread stack location - find_vma failed");
   1.103 +    warning("Can't detect primordial thread stack location - find_vma failed");
   1.104      // best effort: stack_start is normally within a few pages below the real
   1.105      // stack top, use it as stack top, and reduce stack size so we won't put
   1.106      // guard page outside stack.
   1.107 @@ -3066,11 +3072,11 @@
   1.108  // where we're going to put our guard pages, truncate the mapping at
   1.109  // that point by munmap()ping it.  This ensures that when we later
   1.110  // munmap() the guard pages we don't leave a hole in the stack
   1.111 -// mapping. This only affects the main/initial thread
   1.112 +// mapping. This only affects the main/primordial thread
   1.113  
   1.114  bool os::pd_create_stack_guard_pages(char* addr, size_t size) {
   1.115  
   1.116 -  if (os::Linux::is_initial_thread()) {
   1.117 +  if (os::is_primordial_thread()) {
   1.118      // As we manually grow stack up to bottom inside create_attached_thread(),
   1.119      // it's likely that os::Linux::initial_thread_stack_bottom is mapped and
   1.120      // we don't need to do anything special.
   1.121 @@ -3095,14 +3101,14 @@
   1.122  
   1.123  // If this is a growable mapping, remove the guard pages entirely by
   1.124  // munmap()ping them.  If not, just call uncommit_memory(). This only
   1.125 -// affects the main/initial thread, but guard against future OS changes
   1.126 -// It's safe to always unmap guard pages for initial thread because we
   1.127 -// always place it right after end of the mapped region
   1.128 +// affects the main/primordial thread, but guard against future OS changes.
   1.129 +// It's safe to always unmap guard pages for primordial thread because we
   1.130 +// always place it right after end of the mapped region.
   1.131  
   1.132  bool os::remove_stack_guard_pages(char* addr, size_t size) {
   1.133    uintptr_t stack_extent, stack_base;
   1.134  
   1.135 -  if (os::Linux::is_initial_thread()) {
   1.136 +  if (os::is_primordial_thread()) {
   1.137      return ::munmap(addr, size) == 0;
   1.138    }
   1.139  
   1.140 @@ -4877,10 +4883,9 @@
   1.141    }
   1.142  }
   1.143  
   1.144 -// this is called _before_ the most of global arguments have been parsed
   1.145 +// this is called _before_ most of the global arguments have been parsed
   1.146  void os::init(void) {
   1.147    char dummy;   /* used to get a guess on initial stack address */
   1.148 -//  first_hrtime = gethrtime();
   1.149  
   1.150    // With LinuxThreads the JavaMain thread pid (primordial thread)
   1.151    // is different than the pid of the java launcher thread.
   1.152 @@ -4907,7 +4912,7 @@
   1.153  
   1.154    Linux::initialize_system_info();
   1.155  
   1.156 -  // main_thread points to the aboriginal thread
   1.157 +  // _main_thread points to the thread that created/loaded the JVM.
   1.158    Linux::_main_thread = pthread_self();
   1.159  
   1.160    Linux::clock_init();

mercurial