< prev index next >

src/os/linux/vm/os_linux.cpp

Print this page


   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  *


  87 # include <sys/utsname.h>
  88 # include <sys/socket.h>
  89 # include <sys/wait.h>
  90 # include <pwd.h>
  91 # include <poll.h>
  92 # include <semaphore.h>
  93 # include <fcntl.h>
  94 # include <string.h>
  95 # include <syscall.h>
  96 # include <sys/sysinfo.h>
  97 # include <gnu/libc-version.h>
  98 # include <sys/ipc.h>
  99 # include <sys/shm.h>
 100 # include <link.h>
 101 # include <stdint.h>
 102 # include <inttypes.h>
 103 # include <sys/ioctl.h>
 104 
 105 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
 106 








 107 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
 108 // getrusage() is prepared to handle the associated failure.
 109 #ifndef RUSAGE_THREAD
 110 #define RUSAGE_THREAD   (1)               /* only the calling thread */
 111 #endif
 112 
 113 #define MAX_PATH    (2 * K)
 114 
 115 #define MAX_SECS 100000000
 116 
 117 // for timer info max values which include all bits
 118 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 119 
 120 #define LARGEPAGES_BIT (1 << 6)
 121 ////////////////////////////////////////////////////////////////////////////////
 122 // global variables
 123 julong os::Linux::_physical_memory = 0;
 124 
 125 address   os::Linux::_initial_thread_stack_bottom = NULL;
 126 uintptr_t os::Linux::_initial_thread_stack_size   = 0;


4999 
5000   // initialize thread priority policy
5001   prio_init();
5002 
5003   return JNI_OK;
5004 }
5005 
5006 // Mark the polling page as unreadable
5007 void os::make_polling_page_unreadable(void) {
5008   if( !guard_memory((char*)_polling_page, Linux::page_size()) )
5009     fatal("Could not disable polling page");
5010 };
5011 
5012 // Mark the polling page as readable
5013 void os::make_polling_page_readable(void) {
5014   if( !linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) {
5015     fatal("Could not enable polling page");
5016   }
5017 };
5018 
















5019 int os::active_processor_count() {
5020   // Linux doesn't yet have a (official) notion of processor sets,
5021   // so just return the number of online processors.
5022   int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
5023   assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
5024   return online_cpus;














5025 }
5026 
5027 void os::set_native_thread_name(const char *name) {
5028   // Not yet implemented.
5029   return;
5030 }
5031 
5032 bool os::distribute_processes(uint length, uint* distribution) {
5033   // Not yet implemented.
5034   return false;
5035 }
5036 
5037 bool os::bind_to_processor(uint processor_id) {
5038   // Not yet implemented.
5039   return false;
5040 }
5041 
5042 ///
5043 
5044 void os::SuspendedThreadTask::internal_do_task() {


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


  87 # include <sys/utsname.h>
  88 # include <sys/socket.h>
  89 # include <sys/wait.h>
  90 # include <pwd.h>
  91 # include <poll.h>
  92 # include <semaphore.h>
  93 # include <fcntl.h>
  94 # include <string.h>
  95 # include <syscall.h>
  96 # include <sys/sysinfo.h>
  97 # include <gnu/libc-version.h>
  98 # include <sys/ipc.h>
  99 # include <sys/shm.h>
 100 # include <link.h>
 101 # include <stdint.h>
 102 # include <inttypes.h>
 103 # include <sys/ioctl.h>
 104 
 105 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
 106 
 107 #ifndef _GNU_SOURCE
 108   #define _GNU_SOURCE
 109   #include <sched.h>
 110   #undef _GNU_SOURCE
 111 #else
 112   #include <sched.h>
 113 #endif
 114 
 115 // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling
 116 // getrusage() is prepared to handle the associated failure.
 117 #ifndef RUSAGE_THREAD
 118 #define RUSAGE_THREAD   (1)               /* only the calling thread */
 119 #endif
 120 
 121 #define MAX_PATH    (2 * K)
 122 
 123 #define MAX_SECS 100000000
 124 
 125 // for timer info max values which include all bits
 126 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
 127 
 128 #define LARGEPAGES_BIT (1 << 6)
 129 ////////////////////////////////////////////////////////////////////////////////
 130 // global variables
 131 julong os::Linux::_physical_memory = 0;
 132 
 133 address   os::Linux::_initial_thread_stack_bottom = NULL;
 134 uintptr_t os::Linux::_initial_thread_stack_size   = 0;


5007 
5008   // initialize thread priority policy
5009   prio_init();
5010 
5011   return JNI_OK;
5012 }
5013 
5014 // Mark the polling page as unreadable
5015 void os::make_polling_page_unreadable(void) {
5016   if( !guard_memory((char*)_polling_page, Linux::page_size()) )
5017     fatal("Could not disable polling page");
5018 };
5019 
5020 // Mark the polling page as readable
5021 void os::make_polling_page_readable(void) {
5022   if( !linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) {
5023     fatal("Could not enable polling page");
5024   }
5025 };
5026 
5027 static int os_cpu_count(const cpu_set_t* cpus) {
5028   int count = 0;
5029   // only look up to the number of configured processors
5030   for (int i = 0; i < os::processor_count(); i++) {
5031     if (CPU_ISSET(i, cpus)) {
5032       count++;
5033     }
5034   }
5035   return count;
5036 }
5037 
5038 // Get the current number of available processors for this process.
5039 // This value can change at any time during a process's lifetime.
5040 // sched_getaffinity gives an accurate answer as it accounts for cpusets.
5041 // If anything goes wrong we fallback to returning the number of online
5042 // processors - which can be greater than the number available to the process.
5043 int os::active_processor_count() {
5044   cpu_set_t cpus;  // can represent at most 1024 (CPU_SETSIZE) processors
5045   int cpus_size = sizeof(cpu_set_t);
5046   int cpu_count = 0;
5047 
5048   // pid 0 means the current thread - which we have to assume represents the process
5049   if (sched_getaffinity(0, cpus_size, &cpus) == 0) {
5050     cpu_count = os_cpu_count(&cpus);
5051     if(PrintActiveCpus) {
5052       tty->print_cr("active_processor_count: sched_getaffinity processor count: %d", cpu_count);
5053     }
5054   }
5055   else {
5056     cpu_count = ::sysconf(_SC_NPROCESSORS_ONLN);
5057     warning("sched_getaffinity failed (%s)- using online processor count (%d) "
5058             "which may exceed available processors", strerror(errno), cpu_count);
5059   }
5060 
5061   assert(cpu_count > 0 && cpu_count <= processor_count(), "sanity check");
5062   return cpu_count;
5063 }
5064 
5065 void os::set_native_thread_name(const char *name) {
5066   // Not yet implemented.
5067   return;
5068 }
5069 
5070 bool os::distribute_processes(uint length, uint* distribution) {
5071   // Not yet implemented.
5072   return false;
5073 }
5074 
5075 bool os::bind_to_processor(uint processor_id) {
5076   // Not yet implemented.
5077   return false;
5078 }
5079 
5080 ///
5081 
5082 void os::SuspendedThreadTask::internal_do_task() {


< prev index next >