src/hotspot/os/bsd/os_bsd.cpp
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 55044 d3afe760b392
child 58679 9c3209ff7550
equal deleted inserted replaced
58677:13588c901957 58678:9cf78a70fa4f
   134 
   134 
   135 // For diagnostics to print a message once. see run_periodic_checks
   135 // For diagnostics to print a message once. see run_periodic_checks
   136 static sigset_t check_signal_done;
   136 static sigset_t check_signal_done;
   137 static bool check_signals = true;
   137 static bool check_signals = true;
   138 
   138 
   139 static pid_t _initial_pid = 0;
       
   140 
       
   141 // Signal number used to suspend/resume a thread
   139 // Signal number used to suspend/resume a thread
   142 
   140 
   143 // do not use any signal number less than SIGSEGV, see 4355769
   141 // do not use any signal number less than SIGSEGV, see 4355769
   144 static int SR_signum = SIGUSR2;
   142 static int SR_signum = SIGUSR2;
   145 sigset_t SR_sigset;
   143 sigset_t SR_sigset;
   335   // Note that the space for the colon and the trailing null are provided
   333   // Note that the space for the colon and the trailing null are provided
   336   // by the nulls included by the sizeof operator.
   334   // by the nulls included by the sizeof operator.
   337   const size_t bufsize =
   335   const size_t bufsize =
   338     MAX2((size_t)MAXPATHLEN,  // For dll_dir & friends.
   336     MAX2((size_t)MAXPATHLEN,  // For dll_dir & friends.
   339          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir
   337          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir
   340   char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
   338   char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
   341 
   339 
   342   // sysclasspath, java_home, dll_dir
   340   // sysclasspath, java_home, dll_dir
   343   {
   341   {
   344     char *pslash;
   342     char *pslash;
   345     os::jvm_path(buf, bufsize);
   343     os::jvm_path(buf, bufsize);
   385     // addressed).
   383     // addressed).
   386     const char *v = ::getenv("LD_LIBRARY_PATH");
   384     const char *v = ::getenv("LD_LIBRARY_PATH");
   387     const char *v_colon = ":";
   385     const char *v_colon = ":";
   388     if (v == NULL) { v = ""; v_colon = ""; }
   386     if (v == NULL) { v = ""; v_colon = ""; }
   389     // That's +1 for the colon and +1 for the trailing '\0'.
   387     // That's +1 for the colon and +1 for the trailing '\0'.
   390     char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
   388     char *ld_library_path = NEW_C_HEAP_ARRAY(char,
   391                                                      strlen(v) + 1 +
   389                                              strlen(v) + 1 +
   392                                                      sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1,
   390                                              sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1,
   393                                                      mtInternal);
   391                                              mtInternal);
   394     sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib/%s:" DEFAULT_LIBPATH, v, v_colon, cpu_arch);
   392     sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib/%s:" DEFAULT_LIBPATH, v, v_colon, cpu_arch);
   395     Arguments::set_library_path(ld_library_path);
   393     Arguments::set_library_path(ld_library_path);
   396     FREE_C_HEAP_ARRAY(char, ld_library_path);
   394     FREE_C_HEAP_ARRAY(char, ld_library_path);
   397   }
   395   }
   398 
   396 
   416   // Note that the space for the colon and the trailing null are provided
   414   // Note that the space for the colon and the trailing null are provided
   417   // by the nulls included by the sizeof operator.
   415   // by the nulls included by the sizeof operator.
   418   const size_t bufsize =
   416   const size_t bufsize =
   419     MAX2((size_t)MAXPATHLEN,  // for dll_dir & friends.
   417     MAX2((size_t)MAXPATHLEN,  // for dll_dir & friends.
   420          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + system_ext_size); // extensions dir
   418          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + system_ext_size); // extensions dir
   421   char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
   419   char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
   422 
   420 
   423   // sysclasspath, java_home, dll_dir
   421   // sysclasspath, java_home, dll_dir
   424   {
   422   {
   425     char *pslash;
   423     char *pslash;
   426     os::jvm_path(buf, bufsize);
   424     os::jvm_path(buf, bufsize);
   478     // at all. To ease the transition from Apple's Java6 to OpenJDK7,
   476     // at all. To ease the transition from Apple's Java6 to OpenJDK7,
   479     // "." is appended to the end of java.library.path. Yes, this
   477     // "." is appended to the end of java.library.path. Yes, this
   480     // could cause a change in behavior, but Apple's Java6 behavior
   478     // could cause a change in behavior, but Apple's Java6 behavior
   481     // can be achieved by putting "." at the beginning of the
   479     // can be achieved by putting "." at the beginning of the
   482     // JAVA_LIBRARY_PATH environment variable.
   480     // JAVA_LIBRARY_PATH environment variable.
   483     char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
   481     char *ld_library_path = NEW_C_HEAP_ARRAY(char,
   484                                                      strlen(v) + 1 + strlen(l) + 1 +
   482                                              strlen(v) + 1 + strlen(l) + 1 +
   485                                                      system_ext_size + 3,
   483                                              system_ext_size + 3,
   486                                                      mtInternal);
   484                                              mtInternal);
   487     sprintf(ld_library_path, "%s%s%s%s%s" SYS_EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS ":.",
   485     sprintf(ld_library_path, "%s%s%s%s%s" SYS_EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS ":.",
   488             v, v_colon, l, l_colon, user_home_dir);
   486             v, v_colon, l, l_colon, user_home_dir);
   489     Arguments::set_library_path(ld_library_path);
   487     Arguments::set_library_path(ld_library_path);
   490     FREE_C_HEAP_ARRAY(char, ld_library_path);
   488     FREE_C_HEAP_ARRAY(char, ld_library_path);
   491   }
   489   }
   877 jlong os::elapsed_frequency() {
   875 jlong os::elapsed_frequency() {
   878   return NANOSECS_PER_SEC; // nanosecond resolution
   876   return NANOSECS_PER_SEC; // nanosecond resolution
   879 }
   877 }
   880 
   878 
   881 bool os::supports_vtime() { return true; }
   879 bool os::supports_vtime() { return true; }
   882 bool os::enable_vtime()   { return false; }
       
   883 bool os::vtime_enabled()  { return false; }
       
   884 
   880 
   885 double os::elapsedVTime() {
   881 double os::elapsedVTime() {
   886   // better than nothing, but not much
   882   // better than nothing, but not much
   887   return elapsedTime();
   883   return elapsedTime();
   888 }
   884 }
  1071 
  1067 
  1072   ::exit(1);
  1068   ::exit(1);
  1073 }
  1069 }
  1074 
  1070 
  1075 // Die immediately, no exit hook, no abort hook, no cleanup.
  1071 // Die immediately, no exit hook, no abort hook, no cleanup.
       
  1072 // Dump a core file, if possible, for debugging.
  1076 void os::die() {
  1073 void os::die() {
  1077   // _exit() on BsdThreads only kills current thread
  1074   if (TestUnresponsiveErrorHandler && !CreateCoredumpOnCrash) {
  1078   ::abort();
  1075     // For TimeoutInErrorHandlingTest.java, we just kill the VM
       
  1076     // and don't take the time to generate a core file.
       
  1077     os::signal_raise(SIGKILL);
       
  1078   } else {
       
  1079     // _exit() on BsdThreads only kills current thread
       
  1080     ::abort();
       
  1081   }
  1079 }
  1082 }
  1080 
  1083 
  1081 // Information of current thread in variety of formats
  1084 // Information of current thread in variety of formats
  1082 pid_t os::Bsd::gettid() {
  1085 pid_t os::Bsd::gettid() {
  1083   int retval = -1;
  1086   int retval = -1;
  1115   return (intx)::pthread_self();
  1118   return (intx)::pthread_self();
  1116 #endif
  1119 #endif
  1117 }
  1120 }
  1118 
  1121 
  1119 int os::current_process_id() {
  1122 int os::current_process_id() {
  1120 
  1123   return (int)(getpid());
  1121   // Under the old bsd thread library, bsd gives each thread
       
  1122   // its own process id. Because of this each thread will return
       
  1123   // a different pid if this method were to return the result
       
  1124   // of getpid(2). Bsd provides no api that returns the pid
       
  1125   // of the launcher thread for the vm. This implementation
       
  1126   // returns a unique pid, the pid of the launcher thread
       
  1127   // that starts the vm 'process'.
       
  1128 
       
  1129   // Under the NPTL, getpid() returns the same pid as the
       
  1130   // launcher thread rather than a unique pid per thread.
       
  1131   // Use gettid() if you want the old pre NPTL behaviour.
       
  1132 
       
  1133   // if you are looking for the result of a call to getpid() that
       
  1134   // returns a unique pid for the calling thread, then look at the
       
  1135   // OSThread::thread_id() method in osThread_bsd.hpp file
       
  1136 
       
  1137   return (int)(_initial_pid ? _initial_pid : getpid());
       
  1138 }
  1124 }
  1139 
  1125 
  1140 // DLL functions
  1126 // DLL functions
  1141 
  1127 
  1142 const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; }
  1128 const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; }
  1254 #ifdef __APPLE__
  1240 #ifdef __APPLE__
  1255 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
  1241 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
  1256 #ifdef STATIC_BUILD
  1242 #ifdef STATIC_BUILD
  1257   return os::get_default_process_handle();
  1243   return os::get_default_process_handle();
  1258 #else
  1244 #else
       
  1245   log_info(os)("attempting shared library load of %s", filename);
       
  1246 
  1259   void * result= ::dlopen(filename, RTLD_LAZY);
  1247   void * result= ::dlopen(filename, RTLD_LAZY);
  1260   if (result != NULL) {
  1248   if (result != NULL) {
       
  1249     Events::log(NULL, "Loaded shared library %s", filename);
  1261     // Successful loading
  1250     // Successful loading
       
  1251     log_info(os)("shared library load of %s was successful", filename);
  1262     return result;
  1252     return result;
  1263   }
  1253   }
  1264 
  1254 
  1265   // Read system error message into ebuf
  1255   const char* error_report = ::dlerror();
  1266   ::strncpy(ebuf, ::dlerror(), ebuflen-1);
  1256   if (error_report == NULL) {
  1267   ebuf[ebuflen-1]='\0';
  1257     error_report = "dlerror returned no error description";
       
  1258   }
       
  1259   if (ebuf != NULL && ebuflen > 0) {
       
  1260     // Read system error message into ebuf
       
  1261     ::strncpy(ebuf, error_report, ebuflen-1);
       
  1262     ebuf[ebuflen-1]='\0';
       
  1263   }
       
  1264   Events::log(NULL, "Loading shared library %s failed, %s", filename, error_report);
       
  1265   log_info(os)("shared library load of %s failed, %s", filename, error_report);
  1268 
  1266 
  1269   return NULL;
  1267   return NULL;
  1270 #endif // STATIC_BUILD
  1268 #endif // STATIC_BUILD
  1271 }
  1269 }
  1272 #else
  1270 #else
  1273 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
  1271 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
  1274 #ifdef STATIC_BUILD
  1272 #ifdef STATIC_BUILD
  1275   return os::get_default_process_handle();
  1273   return os::get_default_process_handle();
  1276 #else
  1274 #else
       
  1275   log_info(os)("attempting shared library load of %s", filename);
  1277   void * result= ::dlopen(filename, RTLD_LAZY);
  1276   void * result= ::dlopen(filename, RTLD_LAZY);
  1278   if (result != NULL) {
  1277   if (result != NULL) {
       
  1278     Events::log(NULL, "Loaded shared library %s", filename);
  1279     // Successful loading
  1279     // Successful loading
       
  1280     log_info(os)("shared library load of %s was successful", filename);
  1280     return result;
  1281     return result;
  1281   }
  1282   }
  1282 
  1283 
  1283   Elf32_Ehdr elf_head;
  1284   Elf32_Ehdr elf_head;
  1284 
  1285 
  1285   // Read system error message into ebuf
  1286   const char* const error_report = ::dlerror();
  1286   // It may or may not be overwritten below
  1287   if (error_report == NULL) {
  1287   ::strncpy(ebuf, ::dlerror(), ebuflen-1);
  1288     error_report = "dlerror returned no error description";
  1288   ebuf[ebuflen-1]='\0';
  1289   }
       
  1290   if (ebuf != NULL && ebuflen > 0) {
       
  1291     // Read system error message into ebuf
       
  1292     ::strncpy(ebuf, error_report, ebuflen-1);
       
  1293     ebuf[ebuflen-1]='\0';
       
  1294   }
       
  1295   Events::log(NULL, "Loading shared library %s failed, %s", filename, error_report);
       
  1296   log_info(os)("shared library load of %s failed, %s", filename, error_report);
       
  1297 
  1289   int diag_msg_max_length=ebuflen-strlen(ebuf);
  1298   int diag_msg_max_length=ebuflen-strlen(ebuf);
  1290   char* diag_msg_buf=ebuf+strlen(ebuf);
  1299   char* diag_msg_buf=ebuf+strlen(ebuf);
  1291 
  1300 
  1292   if (diag_msg_max_length==0) {
  1301   if (diag_msg_max_length==0) {
  1293     // No more space in ebuf for additional diagnostics message
  1302     // No more space in ebuf for additional diagnostics message
  1750 }
  1759 }
  1751 
  1760 
  1752 ////////////////////////////////////////////////////////////////////////////////
  1761 ////////////////////////////////////////////////////////////////////////////////
  1753 // sun.misc.Signal support
  1762 // sun.misc.Signal support
  1754 
  1763 
  1755 static volatile jint sigint_count = 0;
       
  1756 
       
  1757 static void UserHandler(int sig, void *siginfo, void *context) {
  1764 static void UserHandler(int sig, void *siginfo, void *context) {
  1758   // 4511530 - sem_post is serialized and handled by the manager thread. When
       
  1759   // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We
       
  1760   // don't want to flood the manager thread with sem_post requests.
       
  1761   if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) {
       
  1762     return;
       
  1763   }
       
  1764 
       
  1765   // Ctrl-C is pressed during error reporting, likely because the error
  1765   // Ctrl-C is pressed during error reporting, likely because the error
  1766   // handler fails to abort. Let VM die immediately.
  1766   // handler fails to abort. Let VM die immediately.
  1767   if (sig == SIGINT && VMError::is_error_reported()) {
  1767   if (sig == SIGINT && VMError::is_error_reported()) {
  1768     os::die();
  1768     os::die();
  1769   }
  1769   }
  1829     assert(ReduceSignalUsage, "signal semaphore should be created");
  1829     assert(ReduceSignalUsage, "signal semaphore should be created");
  1830   }
  1830   }
  1831 }
  1831 }
  1832 
  1832 
  1833 static int check_pending_signals() {
  1833 static int check_pending_signals() {
  1834   Atomic::store(0, &sigint_count);
       
  1835   for (;;) {
  1834   for (;;) {
  1836     for (int i = 0; i < NSIG + 1; i++) {
  1835     for (int i = 0; i < NSIG + 1; i++) {
  1837       jint n = pending_signals[i];
  1836       jint n = pending_signals[i];
  1838       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
  1837       if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) {
  1839         return i;
  1838         return i;
  2164 
  2163 
  2165 // Reserve memory at an arbitrary address, only if that area is
  2164 // Reserve memory at an arbitrary address, only if that area is
  2166 // available (and not reserved for something else).
  2165 // available (and not reserved for something else).
  2167 
  2166 
  2168 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
  2167 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) {
  2169   const int max_tries = 10;
       
  2170   char* base[max_tries];
       
  2171   size_t size[max_tries];
       
  2172   const size_t gap = 0x000000;
       
  2173 
       
  2174   // Assert only that the size is a multiple of the page size, since
  2168   // Assert only that the size is a multiple of the page size, since
  2175   // that's all that mmap requires, and since that's all we really know
  2169   // that's all that mmap requires, and since that's all we really know
  2176   // about at this low abstraction level.  If we need higher alignment,
  2170   // about at this low abstraction level.  If we need higher alignment,
  2177   // we can either pass an alignment to this method or verify alignment
  2171   // we can either pass an alignment to this method or verify alignment
  2178   // in one of the methods further up the call chain.  See bug 5044738.
  2172   // in one of the methods further up the call chain.  See bug 5044738.
  2191   if (addr != NULL) {
  2185   if (addr != NULL) {
  2192     // mmap() is successful but it fails to reserve at the requested address
  2186     // mmap() is successful but it fails to reserve at the requested address
  2193     anon_munmap(addr, bytes);
  2187     anon_munmap(addr, bytes);
  2194   }
  2188   }
  2195 
  2189 
  2196   int i;
  2190   return NULL;
  2197   for (i = 0; i < max_tries; ++i) {
       
  2198     base[i] = reserve_memory(bytes);
       
  2199 
       
  2200     if (base[i] != NULL) {
       
  2201       // Is this the block we wanted?
       
  2202       if (base[i] == requested_addr) {
       
  2203         size[i] = bytes;
       
  2204         break;
       
  2205       }
       
  2206 
       
  2207       // Does this overlap the block we wanted? Give back the overlapped
       
  2208       // parts and try again.
       
  2209 
       
  2210       size_t top_overlap = requested_addr + (bytes + gap) - base[i];
       
  2211       if (top_overlap >= 0 && top_overlap < bytes) {
       
  2212         unmap_memory(base[i], top_overlap);
       
  2213         base[i] += top_overlap;
       
  2214         size[i] = bytes - top_overlap;
       
  2215       } else {
       
  2216         size_t bottom_overlap = base[i] + bytes - requested_addr;
       
  2217         if (bottom_overlap >= 0 && bottom_overlap < bytes) {
       
  2218           unmap_memory(requested_addr, bottom_overlap);
       
  2219           size[i] = bytes - bottom_overlap;
       
  2220         } else {
       
  2221           size[i] = bytes;
       
  2222         }
       
  2223       }
       
  2224     }
       
  2225   }
       
  2226 
       
  2227   // Give back the unused reserved pieces.
       
  2228 
       
  2229   for (int j = 0; j < i; ++j) {
       
  2230     if (base[j] != NULL) {
       
  2231       unmap_memory(base[j], size[j]);
       
  2232     }
       
  2233   }
       
  2234 
       
  2235   if (i < max_tries) {
       
  2236     return requested_addr;
       
  2237   } else {
       
  2238     return NULL;
       
  2239   }
       
  2240 }
  2191 }
  2241 
  2192 
  2242 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
  2193 // Sleep forever; naked call to OS-specific sleep; use with CAUTION
  2243 void os::infinite_sleep() {
  2194 void os::infinite_sleep() {
  2244   while (true) {    // sleep forever ...
  2195   while (true) {    // sleep forever ...
  3113 
  3064 
  3114 // this is called _before_ the most of global arguments have been parsed
  3065 // this is called _before_ the most of global arguments have been parsed
  3115 void os::init(void) {
  3066 void os::init(void) {
  3116   char dummy;   // used to get a guess on initial stack address
  3067   char dummy;   // used to get a guess on initial stack address
  3117 
  3068 
  3118   // With BsdThreads the JavaMain thread pid (primordial thread)
       
  3119   // is different than the pid of the java launcher thread.
       
  3120   // So, on Bsd, the launcher thread pid is passed to the VM
       
  3121   // via the sun.java.launcher.pid property.
       
  3122   // Use this property instead of getpid() if it was correctly passed.
       
  3123   // See bug 6351349.
       
  3124   pid_t java_launcher_pid = (pid_t) Arguments::sun_java_launcher_pid();
       
  3125 
       
  3126   _initial_pid = (java_launcher_pid > 0) ? java_launcher_pid : getpid();
       
  3127 
       
  3128   clock_tics_per_sec = CLK_TCK;
  3069   clock_tics_per_sec = CLK_TCK;
  3129 
  3070 
  3130   init_random(1234567);
  3071   init_random(1234567);
  3131 
  3072 
  3132   Bsd::set_page_size(getpagesize());
  3073   Bsd::set_page_size(getpagesize());
  3261   }
  3202   }
  3262 
  3203 
  3263   return _processor_count;
  3204   return _processor_count;
  3264 }
  3205 }
  3265 
  3206 
       
  3207 #ifdef __APPLE__
       
  3208 uint os::processor_id() {
       
  3209   static volatile int* volatile apic_to_cpu_mapping = NULL;
       
  3210   static volatile int next_cpu_id = 0;
       
  3211 
       
  3212   volatile int* mapping = OrderAccess::load_acquire(&apic_to_cpu_mapping);
       
  3213   if (mapping == NULL) {
       
  3214     // Calculate possible number space for APIC ids. This space is not necessarily
       
  3215     // in the range [0, number_of_cpus).
       
  3216     uint total_bits = 0;
       
  3217     for (uint i = 0;; ++i) {
       
  3218       uint eax = 0xb; // Query topology leaf
       
  3219       uint ebx;
       
  3220       uint ecx = i;
       
  3221       uint edx;
       
  3222 
       
  3223       __asm__ ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
       
  3224 
       
  3225       uint level_type = (ecx >> 8) & 0xFF;
       
  3226       if (level_type == 0) {
       
  3227         // Invalid level; end of topology
       
  3228         break;
       
  3229       }
       
  3230       uint level_apic_id_shift = eax & ((1u << 5) - 1);
       
  3231       total_bits += level_apic_id_shift;
       
  3232     }
       
  3233 
       
  3234     uint max_apic_ids = 1u << total_bits;
       
  3235     mapping = NEW_C_HEAP_ARRAY(int, max_apic_ids, mtInternal);
       
  3236 
       
  3237     for (uint i = 0; i < max_apic_ids; ++i) {
       
  3238       mapping[i] = -1;
       
  3239     }
       
  3240 
       
  3241     if (!Atomic::replace_if_null(mapping, &apic_to_cpu_mapping)) {
       
  3242       FREE_C_HEAP_ARRAY(int, mapping);
       
  3243       mapping = OrderAccess::load_acquire(&apic_to_cpu_mapping);
       
  3244     }
       
  3245   }
       
  3246 
       
  3247   uint eax = 0xb;
       
  3248   uint ebx;
       
  3249   uint ecx = 0;
       
  3250   uint edx;
       
  3251 
       
  3252   asm ("cpuid\n\t" : "+a" (eax), "+b" (ebx), "+c" (ecx), "+d" (edx) : );
       
  3253 
       
  3254   // Map from APIC id to a unique logical processor ID in the expected
       
  3255   // [0, num_processors) range.
       
  3256 
       
  3257   uint apic_id = edx;
       
  3258   int cpu_id = Atomic::load(&mapping[apic_id]);
       
  3259 
       
  3260   while (cpu_id < 0) {
       
  3261     if (Atomic::cmpxchg(-2, &mapping[apic_id], -1)) {
       
  3262       Atomic::store(Atomic::add(1, &next_cpu_id) - 1, &mapping[apic_id]);
       
  3263     }
       
  3264     cpu_id = Atomic::load(&mapping[apic_id]);
       
  3265   }
       
  3266 
       
  3267   return (uint)cpu_id;
       
  3268 }
       
  3269 #endif
       
  3270 
  3266 void os::set_native_thread_name(const char *name) {
  3271 void os::set_native_thread_name(const char *name) {
  3267 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  3272 #if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  3268   // This is only supported in Snow Leopard and beyond
  3273   // This is only supported in Snow Leopard and beyond
  3269   if (name != NULL) {
  3274   if (name != NULL) {
  3270     // Add a "Java: " prefix to the name
  3275     // Add a "Java: " prefix to the name
  3271     char buf[MAXTHREADNAMESIZE];
  3276     char buf[MAXTHREADNAMESIZE];
  3272     snprintf(buf, sizeof(buf), "Java: %s", name);
  3277     snprintf(buf, sizeof(buf), "Java: %s", name);
  3273     pthread_setname_np(buf);
  3278     pthread_setname_np(buf);
  3274   }
  3279   }
  3275 #endif
  3280 #endif
  3276 }
       
  3277 
       
  3278 bool os::distribute_processes(uint length, uint* distribution) {
       
  3279   // Not yet implemented.
       
  3280   return false;
       
  3281 }
  3281 }
  3282 
  3282 
  3283 bool os::bind_to_processor(uint processor_id) {
  3283 bool os::bind_to_processor(uint processor_id) {
  3284   // Not yet implemented.
  3284   // Not yet implemented.
  3285   return false;
  3285   return false;
  3662 }
  3662 }
  3663 
  3663 
  3664 void os::pause() {
  3664 void os::pause() {
  3665   char filename[MAX_PATH];
  3665   char filename[MAX_PATH];
  3666   if (PauseAtStartupFile && PauseAtStartupFile[0]) {
  3666   if (PauseAtStartupFile && PauseAtStartupFile[0]) {
  3667     jio_snprintf(filename, MAX_PATH, PauseAtStartupFile);
  3667     jio_snprintf(filename, MAX_PATH, "%s", PauseAtStartupFile);
  3668   } else {
  3668   } else {
  3669     jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
  3669     jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id());
  3670   }
  3670   }
  3671 
  3671 
  3672   int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  3672   int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
  3765   n = MIN2(n, (int)bufferSize);
  3765   n = MIN2(n, (int)bufferSize);
  3766 
  3766 
  3767   return n;
  3767   return n;
  3768 }
  3768 }
  3769 
  3769 
       
  3770 bool os::supports_map_sync() {
       
  3771   return false;
       
  3772 }
       
  3773 
  3770 #ifndef PRODUCT
  3774 #ifndef PRODUCT
  3771 void TestReserveMemorySpecial_test() {
  3775 void TestReserveMemorySpecial_test() {
  3772   // No tests available for this platform
  3776   // No tests available for this platform
  3773 }
  3777 }
  3774 #endif
  3778 #endif