< prev index next >

src/os_cpu/linux_x86/vm/os_linux_x86.cpp

Print this page


   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 695 //    |                        |/
 696 // P2 +------------------------+ Thread::stack_base()
 697 //
 698 // Non-Java thread:
 699 //
 700 //   Low memory addresses
 701 //    +------------------------+
 702 //    |                        |\
 703 //    |  glibc guard page      | - usually 1 page
 704 //    |                        |/
 705 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
 706 //    |                        |\
 707 //    |      Normal Stack      | -
 708 //    |                        |/
 709 // P2 +------------------------+ Thread::stack_base()
 710 //
 711 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
 712 //    pthread_attr_getstack()
 713 
 714 static void current_stack_region(address * bottom, size_t * size) {
 715   if (os::Linux::is_initial_thread()) {
 716      // initial thread needs special handling because pthread_getattr_np()
 717      // may return bogus value.
 718      *bottom = os::Linux::initial_thread_stack_bottom();
 719      *size   = os::Linux::initial_thread_stack_size();
 720   } else {
 721      pthread_attr_t attr;
 722 
 723      int rslt = pthread_getattr_np(pthread_self(), &attr);
 724 
 725      // JVM needs to know exact stack location, abort if it fails
 726      if (rslt != 0) {
 727        if (rslt == ENOMEM) {
 728          vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
 729        } else {
 730          fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
 731        }
 732      }
 733 
 734      if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
 735          fatal("Can not locate current stack attributes!");
 736      }


   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


 695 //    |                        |/
 696 // P2 +------------------------+ Thread::stack_base()
 697 //
 698 // Non-Java thread:
 699 //
 700 //   Low memory addresses
 701 //    +------------------------+
 702 //    |                        |\
 703 //    |  glibc guard page      | - usually 1 page
 704 //    |                        |/
 705 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
 706 //    |                        |\
 707 //    |      Normal Stack      | -
 708 //    |                        |/
 709 // P2 +------------------------+ Thread::stack_base()
 710 //
 711 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
 712 //    pthread_attr_getstack()
 713 
 714 static void current_stack_region(address * bottom, size_t * size) {
 715   if (os::is_primordial_thread()) {
 716      // primordial thread needs special handling because pthread_getattr_np()
 717      // may return bogus value.
 718      *bottom = os::Linux::initial_thread_stack_bottom();
 719      *size   = os::Linux::initial_thread_stack_size();
 720   } else {
 721      pthread_attr_t attr;
 722 
 723      int rslt = pthread_getattr_np(pthread_self(), &attr);
 724 
 725      // JVM needs to know exact stack location, abort if it fails
 726      if (rslt != 0) {
 727        if (rslt == ENOMEM) {
 728          vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
 729        } else {
 730          fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
 731        }
 732      }
 733 
 734      if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
 735          fatal("Can not locate current stack attributes!");
 736      }


< prev index next >