< prev index next >

src/os_cpu/linux_x86/vm/os_linux_x86.cpp

Print this page
rev 8517 : 8078513: [linux]  Clean up code relevant to LinuxThreads implementation
Reviewed-by: dholmes, sla, coleenp
   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  *


 602 
 603   if (bytes < 2 * G) {
 604     return true;
 605   }
 606 
 607   char* addr = reserve_memory(bytes, NULL);
 608 
 609   if (addr != NULL) {
 610     release_memory(addr, bytes);
 611   }
 612 
 613   return addr != NULL;
 614 #endif // AMD64
 615 }
 616 
 617 ////////////////////////////////////////////////////////////////////////////////
 618 // thread stack
 619 
 620 #ifdef AMD64
 621 size_t os::Linux::min_stack_allowed  = 64 * K;
 622 
 623 // amd64: pthread on amd64 is always in floating stack mode
 624 bool os::Linux::supports_variable_stack_size() {  return true; }
 625 #else
 626 size_t os::Linux::min_stack_allowed  =  (48 DEBUG_ONLY(+4))*K;

 627 
 628 #ifdef __GNUC__
 629 #define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;})
 630 #endif
 631 
 632 // Test if pthread library can support variable thread stack size. LinuxThreads
 633 // in fixed stack mode allocates 2M fixed slot for each thread. LinuxThreads
 634 // in floating stack mode and NPTL support variable stack size.
 635 bool os::Linux::supports_variable_stack_size() {
 636   if (os::Linux::is_NPTL()) {
 637      // NPTL, yes
 638      return true;
 639 
 640   } else {
 641     // Note: We can't control default stack size when creating a thread.
 642     // If we use non-default stack size (pthread_attr_setstacksize), both
 643     // floating stack and non-floating stack LinuxThreads will return the
 644     // same value. This makes it impossible to implement this function by
 645     // detecting thread stack size directly.
 646     //
 647     // An alternative approach is to check %gs. Fixed-stack LinuxThreads
 648     // do not use %gs, so its value is 0. Floating-stack LinuxThreads use
 649     // %gs (either as LDT selector or GDT selector, depending on kernel)
 650     // to access thread specific data.
 651     //
 652     // Note that %gs is a reserved glibc register since early 2001, so
 653     // applications are not allowed to change its value (Ulrich Drepper from
 654     // Redhat confirmed that all known offenders have been modified to use
 655     // either %fs or TSD). In the worst case scenario, when VM is embedded in
 656     // a native application that plays with %gs, we might see non-zero %gs
 657     // even LinuxThreads is running in fixed stack mode. As the result, we'll
 658     // return true and skip _thread_safety_check(), so we may not be able to
 659     // detect stack-heap collisions. But otherwise it's harmless.
 660     //
 661 #ifdef __GNUC__
 662     return (GET_GS() != 0);
 663 #else
 664     return false;
 665 #endif
 666   }
 667 }
 668 #endif // AMD64
 669 
 670 // return default stack size for thr_type
 671 size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
 672   // default stack size (compiler thread needs larger stack)
 673 #ifdef AMD64
 674   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
 675 #else
 676   size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
 677 #endif // AMD64
 678   return s;
 679 }
 680 
 681 size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
 682   // Creating guard page is very expensive. Java thread has HotSpot
 683   // guard page, only enable glibc guard page for non-Java threads.
 684   return (thr_type == java_thread ? 0 : page_size());
 685 }
 686 
 687 // Java thread:
 688 //


   1 /*
   2  * Copyright (c) 1999, 2015, 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  *


 602 
 603   if (bytes < 2 * G) {
 604     return true;
 605   }
 606 
 607   char* addr = reserve_memory(bytes, NULL);
 608 
 609   if (addr != NULL) {
 610     release_memory(addr, bytes);
 611   }
 612 
 613   return addr != NULL;
 614 #endif // AMD64
 615 }
 616 
 617 ////////////////////////////////////////////////////////////////////////////////
 618 // thread stack
 619 
 620 #ifdef AMD64
 621 size_t os::Linux::min_stack_allowed  = 64 * K;



 622 #else
 623 size_t os::Linux::min_stack_allowed  =  (48 DEBUG_ONLY(+4))*K;
 624 #endif // AMD64
 625 
 626 // Test if pthread library can support variable thread stack size.






 627 bool os::Linux::supports_variable_stack_size() {


 628   return true;




























 629 }

 630 
 631 // return default stack size for thr_type
 632 size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
 633   // default stack size (compiler thread needs larger stack)
 634 #ifdef AMD64
 635   size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
 636 #else
 637   size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
 638 #endif // AMD64
 639   return s;
 640 }
 641 
 642 size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
 643   // Creating guard page is very expensive. Java thread has HotSpot
 644   // guard page, only enable glibc guard page for non-Java threads.
 645   return (thr_type == java_thread ? 0 : page_size());
 646 }
 647 
 648 // Java thread:
 649 //


< prev index next >