2174
2175 thread->java_suspend_self();
2176 }
2177 } while (threadIsSuspended);
2178 }
2179 }
2180
2181 int os::signal_lookup() {
2182 return check_pending_signals(false);
2183 }
2184
2185 int os::signal_wait() {
2186 return check_pending_signals(true);
2187 }
2188
2189 ////////////////////////////////////////////////////////////////////////////////
2190 // Virtual Memory
2191
2192 static int page_size = -1;
2193
2194 // The mmap MAP_ALIGN flag is supported on Solaris 9 and later. init_2() will
2195 // clear this var if support is not available.
2196 static bool has_map_align = true;
2197
2198 int os::vm_page_size() {
2199 assert(page_size != -1, "must call os::init");
2200 return page_size;
2201 }
2202
2203 // Solaris allocates memory by pages.
2204 int os::vm_allocation_granularity() {
2205 assert(page_size != -1, "must call os::init");
2206 return page_size;
2207 }
2208
2209 static bool recoverable_mmap_error(int err) {
2210 // See if the error is one we can let the caller handle. This
2211 // list of errno values comes from the Solaris mmap(2) man page.
2212 switch (err) {
2213 case EBADF:
2214 case EINVAL:
2215 case ENOTSUP:
2216 // let the caller deal with these errors
2217 return true;
2544
2545 char* os::Solaris::mmap_chunk(char *addr, size_t size, int flags, int prot) {
2546 char *b = (char *)mmap(addr, size, prot, flags, os::Solaris::_dev_zero_fd, 0);
2547
2548 if (b == MAP_FAILED) {
2549 return NULL;
2550 }
2551 return b;
2552 }
2553
2554 char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes,
2555 size_t alignment_hint, bool fixed) {
2556 char* addr = requested_addr;
2557 int flags = MAP_PRIVATE | MAP_NORESERVE;
2558
2559 assert(!(fixed && (alignment_hint > 0)),
2560 "alignment hint meaningless with fixed mmap");
2561
2562 if (fixed) {
2563 flags |= MAP_FIXED;
2564 } else if (has_map_align && (alignment_hint > (size_t) vm_page_size())) {
2565 flags |= MAP_ALIGN;
2566 addr = (char*) alignment_hint;
2567 }
2568
2569 // Map uncommitted pages PROT_NONE so we fail early if we touch an
2570 // uncommitted page. Otherwise, the read/write might succeed if we
2571 // have enough swap space to back the physical page.
2572 return mmap_chunk(addr, bytes, flags, PROT_NONE);
2573 }
2574
2575 char* os::pd_reserve_memory(size_t bytes, char* requested_addr,
2576 size_t alignment_hint) {
2577 char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint,
2578 (requested_addr != NULL));
2579
2580 guarantee(requested_addr == NULL || requested_addr == addr,
2581 "OS failed to return requested mmap address.");
2582 return addr;
2583 }
2584
4205 // dynamic lookup of functions that may not be available in our lowest
4206 // supported Solaris release
4207 void * handle = dlopen("libc.so.1", RTLD_LAZY);
4208 if (handle != NULL) {
4209 Solaris::_pthread_setname_np = // from 11.3
4210 (Solaris::pthread_setname_np_func_t)dlsym(handle, "pthread_setname_np");
4211 }
4212 }
4213
4214 // To install functions for atexit system call
4215 extern "C" {
4216 static void perfMemory_exit_helper() {
4217 perfMemory_exit();
4218 }
4219 }
4220
4221 // this is called _after_ the global arguments have been parsed
4222 jint os::init_2(void) {
4223 // try to enable extended file IO ASAP, see 6431278
4224 os::Solaris::try_enable_extended_io();
4225
4226 // Allocate a single page and mark it as readable for safepoint polling. Also
4227 // use this first mmap call to check support for MAP_ALIGN.
4228 address polling_page = (address)Solaris::mmap_chunk((char*)page_size,
4229 page_size,
4230 MAP_PRIVATE | MAP_ALIGN,
4231 PROT_READ);
4232 if (polling_page == NULL) {
4233 has_map_align = false;
4234 polling_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE,
4235 PROT_READ);
4236 }
4237
4238 os::set_polling_page(polling_page);
4239 log_info(os)("SafePoint Polling address: " INTPTR_FORMAT, p2i(polling_page));
4240
4241 if (!UseMembar) {
4242 address mem_serialize_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE, PROT_READ | PROT_WRITE);
4243 guarantee(mem_serialize_page != NULL, "mmap Failed for memory serialize page");
4244 os::set_memory_serialize_page(mem_serialize_page);
4245 log_info(os)("Memory Serialize Page address: " INTPTR_FORMAT, p2i(mem_serialize_page));
4246 }
4247
4248 // Check and sets minimum stack sizes against command line options
4249 if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
4250 return JNI_ERR;
4251 }
4252
4253 Solaris::libthread_init();
4254
4255 if (UseNUMA) {
4256 if (!Solaris::liblgrp_init()) {
4257 UseNUMA = false;
4258 } else {
4259 size_t lgrp_limit = os::numa_get_groups_num();
4260 int *lgrp_ids = NEW_C_HEAP_ARRAY(int, lgrp_limit, mtInternal);
4261 size_t lgrp_num = os::numa_get_leaf_groups(lgrp_ids, lgrp_limit);
4262 FREE_C_HEAP_ARRAY(int, lgrp_ids);
4263 if (lgrp_num < 2) {
4264 // There's only one locality group, disable NUMA.
4265 UseNUMA = false;
4266 }
|
2174
2175 thread->java_suspend_self();
2176 }
2177 } while (threadIsSuspended);
2178 }
2179 }
2180
2181 int os::signal_lookup() {
2182 return check_pending_signals(false);
2183 }
2184
2185 int os::signal_wait() {
2186 return check_pending_signals(true);
2187 }
2188
2189 ////////////////////////////////////////////////////////////////////////////////
2190 // Virtual Memory
2191
2192 static int page_size = -1;
2193
2194 int os::vm_page_size() {
2195 assert(page_size != -1, "must call os::init");
2196 return page_size;
2197 }
2198
2199 // Solaris allocates memory by pages.
2200 int os::vm_allocation_granularity() {
2201 assert(page_size != -1, "must call os::init");
2202 return page_size;
2203 }
2204
2205 static bool recoverable_mmap_error(int err) {
2206 // See if the error is one we can let the caller handle. This
2207 // list of errno values comes from the Solaris mmap(2) man page.
2208 switch (err) {
2209 case EBADF:
2210 case EINVAL:
2211 case ENOTSUP:
2212 // let the caller deal with these errors
2213 return true;
2540
2541 char* os::Solaris::mmap_chunk(char *addr, size_t size, int flags, int prot) {
2542 char *b = (char *)mmap(addr, size, prot, flags, os::Solaris::_dev_zero_fd, 0);
2543
2544 if (b == MAP_FAILED) {
2545 return NULL;
2546 }
2547 return b;
2548 }
2549
2550 char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes,
2551 size_t alignment_hint, bool fixed) {
2552 char* addr = requested_addr;
2553 int flags = MAP_PRIVATE | MAP_NORESERVE;
2554
2555 assert(!(fixed && (alignment_hint > 0)),
2556 "alignment hint meaningless with fixed mmap");
2557
2558 if (fixed) {
2559 flags |= MAP_FIXED;
2560 } else if (alignment_hint > (size_t) vm_page_size()) {
2561 flags |= MAP_ALIGN;
2562 addr = (char*) alignment_hint;
2563 }
2564
2565 // Map uncommitted pages PROT_NONE so we fail early if we touch an
2566 // uncommitted page. Otherwise, the read/write might succeed if we
2567 // have enough swap space to back the physical page.
2568 return mmap_chunk(addr, bytes, flags, PROT_NONE);
2569 }
2570
2571 char* os::pd_reserve_memory(size_t bytes, char* requested_addr,
2572 size_t alignment_hint) {
2573 char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint,
2574 (requested_addr != NULL));
2575
2576 guarantee(requested_addr == NULL || requested_addr == addr,
2577 "OS failed to return requested mmap address.");
2578 return addr;
2579 }
2580
4201 // dynamic lookup of functions that may not be available in our lowest
4202 // supported Solaris release
4203 void * handle = dlopen("libc.so.1", RTLD_LAZY);
4204 if (handle != NULL) {
4205 Solaris::_pthread_setname_np = // from 11.3
4206 (Solaris::pthread_setname_np_func_t)dlsym(handle, "pthread_setname_np");
4207 }
4208 }
4209
4210 // To install functions for atexit system call
4211 extern "C" {
4212 static void perfMemory_exit_helper() {
4213 perfMemory_exit();
4214 }
4215 }
4216
4217 // this is called _after_ the global arguments have been parsed
4218 jint os::init_2(void) {
4219 // try to enable extended file IO ASAP, see 6431278
4220 os::Solaris::try_enable_extended_io();
4221
4222 // Check and sets minimum stack sizes against command line options
4223 if (Posix::set_minimum_stack_sizes() == JNI_ERR) {
4224 return JNI_ERR;
4225 }
4226
4227 Solaris::libthread_init();
4228
4229 if (UseNUMA) {
4230 if (!Solaris::liblgrp_init()) {
4231 UseNUMA = false;
4232 } else {
4233 size_t lgrp_limit = os::numa_get_groups_num();
4234 int *lgrp_ids = NEW_C_HEAP_ARRAY(int, lgrp_limit, mtInternal);
4235 size_t lgrp_num = os::numa_get_leaf_groups(lgrp_ids, lgrp_limit);
4236 FREE_C_HEAP_ARRAY(int, lgrp_ids);
4237 if (lgrp_num < 2) {
4238 // There's only one locality group, disable NUMA.
4239 UseNUMA = false;
4240 }
|