/* * Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2021 SAP SE. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// According to the AIX OS doc #pragma alloca must be used // with C++ compiler before referencing the function alloca() #pragma alloca
// for timer info max values which include all bits #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) // for multipage initialization error analysis (in 'g_multipage_error') #define ERROR_MP_OS_TOO_OLD 100 #define ERROR_MP_EXTSHM_ACTIVE 101 #define ERROR_MP_VMGETINFO_FAILED 102 #define ERROR_MP_VMGETINFO_CLAIMS_NO_SUPPORT_FOR_64K 103
// excerpts from systemcfg.h that might be missing on older os levels #ifndef PV_7 #define PV_7 0x200000 /* Power PC 7 */ #endif #ifndef PV_7_Compat #define PV_7_Compat 0x208000 /* Power PC 7 */ #endif #ifndef PV_8 #define PV_8 0x300000 /* Power PC 8 */ #endif #ifndef PV_8_Compat #define PV_8_Compat 0x308000 /* Power PC 8 */ #endif #ifndef PV_9 #define PV_9 0x400000 /* Power PC 9 */ #endif #ifndef PV_9_Compat #define PV_9_Compat 0x408000 /* Power PC 9 */ #endif
//////////////////////////////////////////////////////////////////////////////// // global variables (for a description see os_aix.hpp)
julong os::Aix::_physical_memory = 0;
pthread_t os::Aix::_main_thread = ((pthread_t)0);
// -1 = uninitialized, 0 if AIX, 1 if OS/400 pase int os::Aix::_on_pase = -1;
// 0 = uninitialized, otherwise 32 bit number: // 0xVVRRTTSS // VV - major version // RR - minor version // TT - tech level, if known, 0 otherwise // SS - service pack, if known, 0 otherwise
uint32_t os::Aix::_os_version = 0;
// -1 = uninitialized, 0 - no, 1 - yes int os::Aix::_xpg_sus_mode = -1;
// -1 = uninitialized, 0 - no, 1 - yes int os::Aix::_extshm = -1;
//////////////////////////////////////////////////////////////////////////////// // local variables
staticvolatile jlong max_real_time = 0;
// Process break recorded at startup. static address g_brk_at_startup = NULL;
// This describes the state of multipage support of the underlying // OS. Note that this is of no interest to the outsize world and // therefore should not be defined in AIX class. // // AIX supports four different page sizes - 4K, 64K, 16MB, 16GB. The // latter two (16M "large" resp. 16G "huge" pages) require special // setup and are normally not available. // // AIX supports multiple page sizes per process, for: // - Stack (of the primordial thread, so not relevant for us) // - Data - data, bss, heap, for us also pthread stacks // - Text - text code // - shared memory // // Default page sizes can be set via linker options (-bdatapsize, -bstacksize, ...) // and via environment variable LDR_CNTRL (DATAPSIZE, STACKPSIZE, ...). // // For shared memory, page size can be set dynamically via // shmctl(). Different shared memory regions can have different page // sizes. // // More information can be found at AIBM info center: // http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=/com.ibm.aix.prftungd/doc/prftungd/multiple_page_size_app_support.htm // staticstruct {
size_t pagesize; // sysconf _SC_PAGESIZE (4K)
size_t datapsize; // default data page size (LDR_CNTRL DATAPSIZE)
size_t shmpsize; // default shared memory page size (LDR_CNTRL SHMPSIZE)
size_t pthr_stack_pagesize; // stack page size of pthread threads
size_t textpsize; // default text page size (LDR_CNTRL STACKPSIZE) bool can_use_64K_pages; // True if we can alloc 64K pages dynamically with Sys V shm. bool can_use_16M_pages; // True if we can alloc 16M pages dynamically with Sys V shm. int error; // Error describing if something went wrong at multipage init.
} g_multipage_support = {
(size_t) -1,
(size_t) -1,
(size_t) -1,
(size_t) -1,
(size_t) -1, false, false,
0
};
// We must not accidentally allocate memory close to the BRK - even if // that would work - because then we prevent the BRK segment from // growing which may result in a malloc OOM even though there is // enough memory. The problem only arises if we shmat() or mmap() at // a specific wish address, e.g. to place the heap in a // compressed-oops-friendly way. staticbool is_close_to_brk(address a) {
assert0(g_brk_at_startup != NULL); if (a >= g_brk_at_startup &&
a < (g_brk_at_startup + MaxExpectedDataSegmentSize)) { returntrue;
} returnfalse;
}
julong os::Aix::available_memory() { // Avoid expensive API call here, as returned value will always be null. if (os::Aix::on_pase()) { return 0x0LL;
}
os::Aix::meminfo_t mi; if (os::Aix::get_meminfo(&mi)) { return mi.real_free;
} else { return ULONG_MAX;
}
}
// Helper function, emulates disclaim64 using multiple 32bit disclaims // because we cannot use disclaim64() on AS/400 and old AIX releases. staticbool my_disclaim64(char* addr, size_t size) {
if (size == 0) { returntrue;
}
// Maximum size 32bit disclaim() accepts. (Theoretically 4GB, but I just do not trust that.) constunsignedint maxDisclaimSize = 0x40000000;
// Wrap the function "vmgetinfo" which is not available on older OS releases. staticint checked_vmgetinfo(void *out, int command, int arg) { if (os::Aix::on_pase() && os::Aix::os_version_short() < 0x0601) {
guarantee(false, "cannot call vmgetinfo on AS/400 older than V6R1");
} return ::vmgetinfo(out, command, arg);
}
// Given an address, returns the size of the page backing that address.
size_t os::Aix::query_pagesize(void* addr) {
if (os::Aix::on_pase() && os::Aix::os_version_short() < 0x0601) { // AS/400 older than V6R1: no vmgetinfo here, default to 4K return 4*K;
}
// Get the number of online(logical) cpus instead of configured.
os::_processor_count = sysconf(_SC_NPROCESSORS_ONLN);
assert(_processor_count > 0, "_processor_count must be > 0");
// Retrieve total physical storage.
os::Aix::meminfo_t mi; if (!os::Aix::get_meminfo(&mi)) {
assert(false, "os::Aix::get_meminfo failed.");
}
_physical_memory = (julong) mi.real_total;
}
// Helper function for tracing page sizes. staticconstchar* describe_pagesize(size_t pagesize) { switch (pagesize) { case 4*K : return"4K"; case 64*K: return"64K"; case 16*M: return"16M"; case 16*G: return"16G"; default:
assert(false, "surprise"); return"??";
}
}
// Probe OS for multipage support. // Will fill the global g_multipage_support structure. // Must be called before calling os::large_page_init(). staticvoid query_multipage_support() {
guarantee(g_multipage_support.pagesize == -1, "do not call twice");
// This really would surprise me.
assert(g_multipage_support.pagesize == 4*K, "surprise!");
// Query default data page size (default page size for C-Heap, pthread stacks and .bss). // Default data page size is defined either by linker options (-bdatapsize) // or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given, // default should be 4K.
{ void* p = ::malloc(16*M);
g_multipage_support.datapsize = os::Aix::query_pagesize(p);
::free(p);
}
// Query default shm page size (LDR_CNTRL SHMPSIZE). // Note that this is pure curiosity. We do not rely on default page size but set // our own page size after allocated.
{ constint shmid = ::shmget(IPC_PRIVATE, 1, IPC_CREAT | S_IRUSR | S_IWUSR);
guarantee(shmid != -1, "shmget failed"); void* p = ::shmat(shmid, NULL, 0);
::shmctl(shmid, IPC_RMID, NULL);
guarantee(p != (void*) -1, "shmat failed");
g_multipage_support.shmpsize = os::Aix::query_pagesize(p);
::shmdt(p);
}
// Before querying the stack page size, make sure we are not running as primordial // thread (because primordial thread's stack may have different page size than // pthread thread stacks). Running a VM on the primordial thread won't work for a // number of reasons so we may just as well guarantee it here.
guarantee0(!os::is_primordial_thread());
// Query pthread stack page size. Should be the same as data page size because // pthread stacks are allocated from C-Heap.
{ int dummy = 0;
g_multipage_support.pthr_stack_pagesize = os::Aix::query_pagesize(&dummy);
}
// Now probe for support of 64K pages and 16M pages.
// Before OS/400 V6R1, there is no support for pages other than 4K. if (os::Aix::on_pase_V5R4_or_older()) {
trcVerbose("OS/400 < V6R1 - no large page support.");
g_multipage_support.error = ERROR_MP_OS_TOO_OLD; goto query_multipage_support_end;
}
// Now check which page sizes the OS claims it supports, and of those, which actually can be used.
{ constint MAX_PAGE_SIZES = 4;
psize_t sizes[MAX_PAGE_SIZES]; constint num_psizes = checked_vmgetinfo(sizes, VMINFO_GETPSIZES, MAX_PAGE_SIZES); if (num_psizes == -1) {
trcVerbose("vmgetinfo(VMINFO_GETPSIZES) failed (errno: %d)", errno);
trcVerbose("disabling multipage support.");
g_multipage_support.error = ERROR_MP_VMGETINFO_FAILED; goto query_multipage_support_end;
}
guarantee(num_psizes > 0, "vmgetinfo(.., VMINFO_GETPSIZES, ...) failed.");
assert(num_psizes <= MAX_PAGE_SIZES, "Surprise! more than 4 page sizes?");
trcVerbose("vmgetinfo(.., VMINFO_GETPSIZES, ...) returns %d supported page sizes: ", num_psizes); for (int i = 0; i < num_psizes; i ++) {
trcVerbose(" %s ", describe_pagesize(sizes[i]));
}
// Can we use 64K, 16M pages? for (int i = 0; i < num_psizes; i ++) { const size_t pagesize = sizes[i]; if (pagesize != 64*K && pagesize != 16*M) { continue;
} bool can_use = false;
trcVerbose("Probing support for %s pages...", describe_pagesize(pagesize)); constint shmid = ::shmget(IPC_PRIVATE, pagesize,
IPC_CREAT | S_IRUSR | S_IWUSR);
guarantee0(shmid != -1); // Should always work. // Try to set pagesize. struct shmid_ds shm_buf = { 0 };
shm_buf.shm_pagesize = pagesize; if (::shmctl(shmid, SHM_PAGESIZE, &shm_buf) != 0) { constint en = errno;
::shmctl(shmid, IPC_RMID, NULL); // As early as possible!
trcVerbose("shmctl(SHM_PAGESIZE) failed with errno=%d", errno);
} else { // Attach and double check pageisze. void* p = ::shmat(shmid, NULL, 0);
::shmctl(shmid, IPC_RMID, NULL); // As early as possible!
guarantee0(p != (void*) -1); // Should always work. const size_t real_pagesize = os::Aix::query_pagesize(p); if (real_pagesize != pagesize) {
trcVerbose("real page size (" SIZE_FORMAT_X ") differs.", real_pagesize);
} else {
can_use = true;
}
::shmdt(p);
}
trcVerbose("Can use: %s", (can_use ? "yes" : "no")); if (pagesize == 64*K) {
g_multipage_support.can_use_64K_pages = can_use;
} elseif (pagesize == 16*M) {
g_multipage_support.can_use_16M_pages = can_use;
}
}
} // end: check which pages can be used for shared memory
// Buffer that fits several sprintfs. // Note that the space for the trailing null is provided // by the nulls included by the sizeof operator. const size_t bufsize =
MAX2((size_t)MAXPATHLEN, // For dll_dir & friends.
(size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR)); // extensions dir char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
// Found the full path to libjvm.so. // Now cut the path to <java_home>/jre if we can.
pslash = strrchr(buf, '/'); if (pslash != NULL) {
*pslash = '\0'; // Get rid of /libjvm.so.
}
pslash = strrchr(buf, '/'); if (pslash != NULL) {
*pslash = '\0'; // Get rid of /{client|server|hotspot}.
}
Arguments::set_dll_dir(buf);
if (pslash != NULL) {
pslash = strrchr(buf, '/'); if (pslash != NULL) {
*pslash = '\0'; // Get rid of /lib.
}
}
Arguments::set_java_home(buf); if (!set_boot_path('/', ':')) {
vm_exit_during_initialization("Failed setting boot class path.", NULL);
}
}
// Where to look for native libraries.
// On Aix we get the user setting of LIBPATH. // Eventually, all the library path setting will be done here. // Get the user setting of LIBPATH. constchar *v = ::getenv("LIBPATH"); constchar *v_colon = ":"; if (v == NULL) { v = ""; v_colon = ""; }
// Concatenate user and invariant part of ld_library_path. // That's +1 for the colon and +1 for the trailing '\0'. char *ld_library_path = NEW_C_HEAP_ARRAY(char, strlen(v) + 1 + sizeof(DEFAULT_LIBPATH) + 1, mtInternal);
sprintf(ld_library_path, "%s%s" DEFAULT_LIBPATH, v, v_colon);
Arguments::set_library_path(ld_library_path);
FREE_C_HEAP_ARRAY(char, ld_library_path);
//////////////////////////////////////////////////////////////////////////////// // breakpoint support
void os::breakpoint() {
BREAKPOINT;
}
extern"C"void breakpoint() { // use debugger to set breakpoint here
}
// retrieve memory information. // Returns false if something went wrong; // content of pmi undefined in this case. bool os::Aix::get_meminfo(meminfo_t* pmi) {
assert(pmi, "get_meminfo: invalid parameter");
memset(pmi, 0, sizeof(meminfo_t));
if (os::Aix::on_pase()) { // On PASE, use the libo4 porting library.
// excerpt from // http://publib.boulder.ibm.com/infocenter/systems/index.jsp // ?topic=/com.ibm.aix.files/doc/aixfiles/libperfstat.h.htm // The fields of perfstat_memory_total_t: // u_longlong_t virt_total Total virtual memory (in 4 KB pages). // u_longlong_t real_total Total real memory (in 4 KB pages). // u_longlong_t real_free Free real memory (in 4 KB pages). // u_longlong_t pgsp_total Total paging space (in 4 KB pages). // u_longlong_t pgsp_free Free paging space (in 4 KB pages).
// Normally, pthread stacks on AIX live in the data segment (are allocated with malloc() // by the pthread library). In rare cases, this may not be the case, e.g. when third-party // tools hook pthread_create(). In this case, we may run into problems establishing // guard pages on those stacks, because the stacks may reside in memory which is not // protectable (shmated). if (thread->stack_base() > ::sbrk(0)) {
log_warning(os, thread)("Thread stack not in data segment.");
}
// Try to randomize the cache line index of hot stack frames. // This helps when threads of the same stack traces evict each other's // cache lines. The threads can be either from the same JVM instance, or // from different JVM instances. The benefit is especially true for // processors with hyperthreading technology.
// Make sure we run in 1:1 kernel-user-thread mode. if (os::Aix::on_aix()) {
guarantee(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) == 0, "???");
guarantee(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0, "???");
}
// Start in suspended state, and in os::thread_start, wake the thread up.
guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???");
// Calculate stack size if it's not specified by caller.
size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
// JDK-8187028: It was observed that on some configurations (4K backed thread stacks) // the real thread stack size may be smaller than the requested stack size, by as much as 64K. // This very much looks like a pthread lib error. As a workaround, increase the stack size // by 64K for small thread stacks (arbitrarily chosen to be < 4MB) if (stack_size < 4096 * K) {
stack_size += 64 * K;
}
// On Aix, pthread_attr_setstacksize fails with huge values and leaves the // thread size in attr unchanged. If this is the minimal stack size as set // by pthread_attr_init this leads to crashes after thread creation. E.g. the // guard pages might not fit on the tiny stack created. int ret = pthread_attr_setstacksize(&attr, stack_size); if (ret != 0) {
log_warning(os, thread)("The %sthread stack size specified is invalid: " SIZE_FORMAT "k",
(thr_type == compiler_thread) ? "compiler " : ((thr_type == java_thread) ? "" : "VM "),
stack_size / K);
thread->set_osthread(NULL); delete osthread; returnfalse;
}
// Save some cycles and a page by disabling OS guard pages where we have our own // VM guard pages (in java threads). For other threads, keep system default guard // pages in place. if (thr_type == java_thread || thr_type == compiler_thread) {
ret = pthread_attr_setguardsize(&attr, 0);
}
ResourceMark rm;
pthread_t tid = 0;
if (ret == 0) { int limit = 3; do {
ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
} while (ret == EAGAIN && limit-- > 0);
}
if (ret == 0) { char buf[64];
log_info(os, thread)("Thread \"%s\" started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
thread->name(), (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
} else { char buf[64];
log_warning(os, thread)("Failed to start thread \"%s\" - pthread_create failed (%d=%s) for attributes: %s.",
thread->name(), ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr)); // Log some OS information which might explain why creating the thread failed.
log_info(os, thread)("Number of threads approx. running in the VM: %d", Threads::number_of_threads());
LogStream st(Log(os, thread)::info());
os::Posix::print_rlimit_info(&st);
os::print_memory_info(&st);
}
pthread_attr_destroy(&attr);
if (ret != 0) { // Need to clean up stuff we've allocated so far.
thread->set_osthread(NULL); delete osthread; returnfalse;
}
// OSThread::thread_id is the pthread id.
osthread->set_thread_id(tid);
// bootstrap the main thread bool os::create_main_thread(JavaThread* thread) {
assert(os::Aix::_main_thread == pthread_self(), "should be called inside main thread"); return create_attached_thread(thread);
}
void os::pd_start_thread(Thread* thread) { int status = pthread_continue_np(thread->osthread()->pthread_id());
assert(status == 0, "thr_continue failed");
}
// Free OS resources related to the OSThread void os::free_thread(OSThread* osthread) {
assert(osthread != NULL, "osthread not set");
// We are told to free resources of the argument thread, // but we can only really operate on the current thread.
assert(Thread::current()->osthread() == osthread, "os::free_thread but not current thread");
//////////////////////////////////////////////////////////////////////////////// // time support
double os::elapsedVTime() { struct rusage usage; int retval = getrusage(RUSAGE_THREAD, &usage); if (retval == 0) { return usage.ru_utime.tv_sec + usage.ru_stime.tv_sec + (usage.ru_utime.tv_usec + usage.ru_stime.tv_usec) / (1000.0 * 1000);
} else { // better than nothing, but not much return elapsedTime();
}
}
// We use mread_real_time here. // On AIX: If the CPU has a time register, the result will be RTC_POWER and // it has to be converted to real time. AIX documentations suggests to do // this unconditionally, so we do it. // // See: https://www.ibm.com/support/knowledgecenter/ssw_aix_61/com.ibm.aix.basetrf2/read_real_time.htm // // On PASE: mread_real_time will always return RTC_POWER_PC data, so no // conversion is necessary. However, mread_real_time will not return // monotonic results but merely matches read_real_time. So we need a tweak // to ensure monotonic results. // // For PASE no public documentation exists, just word by IBM
jlong os::javaTimeNanos() {
timebasestruct_t time; int rc = mread_real_time(&time, TIMEBASE_SZ); if (os::Aix::on_pase()) {
assert(rc == RTC_POWER, "expected time format RTC_POWER from mread_real_time in PASE");
jlong now = jlong(time.tb_high) * NANOSECS_PER_SEC + jlong(time.tb_low);
jlong prev = max_real_time; if (now <= prev) { return prev; // same or retrograde time;
}
jlong obsv = Atomic::cmpxchg(&max_real_time, prev, now);
assert(obsv >= prev, "invariant"); // Monotonicity // If the CAS succeeded then we're done and return "now". // If the CAS failed and the observed value "obsv" is >= now then // we should return "obsv". If the CAS failed and now > obsv > prv then // some other thread raced this thread and installed a new value, in which case // we could either (a) retry the entire operation, (b) retry trying to install now // or (c) just return obsv. We use (c). No loop is required although in some cases // we might discard a higher "now" value in deference to a slightly lower but freshly // installed obsv value. That's entirely benign -- it admits no new orderings compared // to (a) or (b) -- and greatly reduces coherence traffic. // We might also condition (c) on the magnitude of the delta between obsv and now. // Avoiding excessive CAS operations to hot RW locations is critical. // See https://blogs.oracle.com/dave/entry/cas_and_cache_trivia_invalidate return (prev == obsv) ? now : obsv;
} else { if (rc != RTC_POWER) {
rc = time_base_to_time(&time, TIMEBASE_SZ);
assert(rc != -1, "error calling time_base_to_time()");
} return jlong(time.tb_high) * NANOSECS_PER_SEC + jlong(time.tb_low);
}
}
void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) {
info_ptr->max_value = ALL_64_BITS; // mread_real_time() is monotonic (see 'os::javaTimeNanos()')
info_ptr->may_skip_backward = false;
info_ptr->may_skip_forward = false;
info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time
}
// This must be hard coded because it's the system's temporary // directory not the java application's temp directory, ala java.io.tmpdir. constchar* os::get_temp_directory() { return"/tmp"; }
// Check if addr is inside libjvm.so. bool os::address_is_in_vm(address addr) {
// Input could be a real pc or a function pointer literal. The latter // would be a function descriptor residing in the data segment of a module.
loaded_module_t lm; if (LoadedLibraries::find_for_text_address(addr, &lm) != NULL) { return lm.is_in_vm;
} elseif (LoadedLibraries::find_for_data_address(addr, &lm) != NULL) { return lm.is_in_vm;
} else { returnfalse;
}
}
// Resolve an AIX function descriptor literal to a code pointer. // If the input is a valid code pointer to a text segment of a loaded module, // it is returned unchanged. // If the input is a valid AIX function descriptor, it is resolved to the // code entry point. // If the input is neither a valid function descriptor nor a valid code pointer, // NULL is returned. static address resolve_function_descriptor_to_code_pointer(address p) {
if (LoadedLibraries::find_for_text_address(p, NULL) != NULL) { // It is a real code pointer. return p;
} elseif (LoadedLibraries::find_for_data_address(p, NULL) != NULL) { // Pointer to data segment, potential function descriptor.
address code_entry = (address)(((FunctionDescriptor*)p)->entry()); if (LoadedLibraries::find_for_text_address(code_entry, NULL) != NULL) { // It is a function descriptor. return code_entry;
}
}
return NULL;
}
bool os::dll_address_to_function_name(address addr, char *buf, int buflen, int *offset, bool demangle) { if (offset) {
*offset = -1;
} // Buf is not optional, but offset is optional.
assert(buf != NULL, "sanity check");
buf[0] = '\0';
// Resolve function ptr literals first.
addr = resolve_function_descriptor_to_code_pointer(addr); if (!addr) { returnfalse;
}
// Loads .dll/.so and in case of error it checks if .dll/.so was built // for the same architecture as Hotspot is running on. void *os::dll_load(constchar *filename, char *ebuf, int ebuflen) {
log_info(os)("attempting shared library load of %s", filename);
uint32_t ver = os::Aix::os_version();
st->print_cr("AIX kernel version %u.%u.%u.%u",
(ver >> 24) & 0xFF, (ver >> 16) & 0xFF, (ver >> 8) & 0xFF, ver & 0xFF);
os::Posix::print_uptime_info(st);
os::Posix::print_rlimit_info(st);
os::Posix::print_load_average(st);
// _SC_THREAD_THREADS_MAX is the maximum number of threads within a process. long tmax = sysconf(_SC_THREAD_THREADS_MAX);
st->print_cr("maximum #threads within a process:%ld", tmax);
st->print_cr(" Base page size (sysconf _SC_PAGESIZE): %s",
describe_pagesize(g_multipage_support.pagesize));
st->print_cr(" Data page size (C-Heap, bss, etc): %s",
describe_pagesize(g_multipage_support.datapsize));
st->print_cr(" Text page size: %s",
describe_pagesize(g_multipage_support.textpsize));
st->print_cr(" Thread stack page size (pthread): %s",
describe_pagesize(g_multipage_support.pthr_stack_pagesize));
st->print_cr(" Default shared memory page size: %s",
describe_pagesize(g_multipage_support.shmpsize));
st->print_cr(" Can use 64K pages dynamically with shared memory: %s",
(g_multipage_support.can_use_64K_pages ? "yes" :"no"));
st->print_cr(" Can use 16M pages dynamically with shared memory: %s",
(g_multipage_support.can_use_16M_pages ? "yes" :"no"));
st->print_cr(" Multipage error: %d",
g_multipage_support.error);
st->cr();
st->print_cr(" os::vm_page_size: %s", describe_pagesize(os::vm_page_size()));
// print out LDR_CNTRL because it affects the default page sizes constchar* const ldr_cntrl = ::getenv("LDR_CNTRL");
st->print_cr(" LDR_CNTRL=%s.", ldr_cntrl ? ldr_cntrl : "");
// Print out EXTSHM because it is an unsupported setting. constchar* const extshm = ::getenv("EXTSHM");
st->print_cr(" EXTSHM=%s.", extshm ? extshm : ""); if ( (strcmp(extshm, "on") == 0) || (strcmp(extshm, "ON") == 0) ) {
st->print_cr(" *** Unsupported! Please remove EXTSHM from your environment! ***");
}
// Print out AIXTHREAD_GUARDPAGES because it affects the size of pthread stacks. constchar* const aixthread_guardpages = ::getenv("AIXTHREAD_GUARDPAGES");
st->print_cr(" AIXTHREAD_GUARDPAGES=%s.",
aixthread_guardpages ? aixthread_guardpages : "");
st->cr();
os::Aix::meminfo_t mi; if (os::Aix::get_meminfo(&mi)) { if (os::Aix::on_aix()) {
st->print_cr("physical total : " SIZE_FORMAT, mi.real_total);
st->print_cr("physical free : " SIZE_FORMAT, mi.real_free);
st->print_cr("swap total : " SIZE_FORMAT, mi.pgsp_total);
st->print_cr("swap free : " SIZE_FORMAT, mi.pgsp_free);
} else { // PASE - Numbers are result of QWCRSSTS; they mean: // real_total: Sum of all system pools // real_free: always 0 // pgsp_total: we take the size of the system ASP // pgsp_free: size of system ASP times percentage of system ASP unused
st->print_cr("physical total : " SIZE_FORMAT, mi.real_total);
st->print_cr("system asp total : " SIZE_FORMAT, mi.pgsp_total);
st->print_cr("%% system asp used : %.2f",
mi.pgsp_total ? (100.0f * (mi.pgsp_total - mi.pgsp_free) / mi.pgsp_total) : -1.0f);
}
}
st->cr();
// Print program break.
st->print_cr("Program break at VM startup: " PTR_FORMAT ".", p2i(g_brk_at_startup));
address brk_now = (address)::sbrk(0); if (brk_now != (address)-1) {
st->print_cr("Program break now : " PTR_FORMAT " (distance: " SIZE_FORMAT "k).",
p2i(brk_now), (size_t)((brk_now - g_brk_at_startup) / K));
}
st->print_cr("MaxExpectedDataSegmentSize : " SIZE_FORMAT "k.", MaxExpectedDataSegmentSize / K);
st->cr();
// Print segments allocated with os::reserve_memory.
st->print_cr("internal virtual memory regions used by vm:");
vmembk_print_on(st);
}
// Get a string for the cpuinfo that is a summary of the cpu type void os::get_summary_cpu_info(char* buf, size_t buflen) { // read _system_configuration.version switch (_system_configuration.version) { case PV_9:
strncpy(buf, "Power PC 9", buflen); break; case PV_8:
strncpy(buf, "Power PC 8", buflen); break; case PV_7:
strncpy(buf, "Power PC 7", buflen); break; case PV_6_1:
strncpy(buf, "Power PC 6 DD1.x", buflen); break; case PV_6:
strncpy(buf, "Power PC 6", buflen); break; case PV_5:
strncpy(buf, "Power PC 5", buflen); break; case PV_5_2:
strncpy(buf, "Power PC 5_2", buflen); break; case PV_5_3:
strncpy(buf, "Power PC 5_3", buflen); break; case PV_5_Compat:
strncpy(buf, "PV_5_Compat", buflen); break; case PV_6_Compat:
strncpy(buf, "PV_6_Compat", buflen); break; case PV_7_Compat:
strncpy(buf, "PV_7_Compat", buflen); break; case PV_8_Compat:
strncpy(buf, "PV_8_Compat", buflen); break; case PV_9_Compat:
strncpy(buf, "PV_9_Compat", buflen); break; default:
strncpy(buf, "unknown", buflen);
}
}
void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) { // Nothing to do beyond of what os::print_cpu_info() does.
}
staticchar saved_jvm_path[MAXPATHLEN] = {0};
// Find the full path to the current module, libjvm.so. void os::jvm_path(char *buf, jint buflen) { // Error checking. if (buflen < MAXPATHLEN) {
assert(false, "must use a large-enough buffer");
buf[0] = '\0'; return;
} // Lazy resolve the path to current module. if (saved_jvm_path[0] != 0) {
strcpy(buf, saved_jvm_path); return;
}
Dl_info dlinfo; int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
assert(ret != 0, "cannot locate libjvm"); char* rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen);
assert(rp != NULL, "error in realpath(): maybe the 'path' argument is too long?");
if (Arguments::sun_java_launcher_is_altjvm()) { // Support for the java launcher's '-XXaltjvm=<path>' option. Typical // value for buf is "<JAVA_HOME>/jre/lib/<vmtype>/libjvm.so". // If "/jre/lib/" appears at the right place in the string, then // assume we are installed in a JDK and we're done. Otherwise, check // for a JAVA_HOME environment variable and fix up the path so it // looks like libjvm.so is installed there (append a fake suffix // hotspot/libjvm.so). constchar *p = buf + strlen(buf) - 1; for (int count = 0; p > buf && count < 4; ++count) { for (--p; p > buf && *p != '/'; --p) /* empty */ ;
}
if (strncmp(p, "/jre/lib/", 9) != 0) { // Look for JAVA_HOME in the environment. char* java_home_var = ::getenv("JAVA_HOME"); if (java_home_var != NULL && java_home_var[0] != 0) { char* jrelib_p; int len;
// Check the current module name "libjvm.so".
p = strrchr(buf, '/'); if (p == NULL) { return;
}
assert(strstr(p, "/libjvm") == p, "invalid library name");
rp = os::Posix::realpath(java_home_var, buf, buflen); if (rp == NULL) { return;
}
// determine if this is a legacy image or modules image // modules image doesn't have "jre" subdirectory
len = strlen(buf);
assert(len < buflen, "Ran out of buffer room");
jrelib_p = buf + len;
snprintf(jrelib_p, buflen-len, "/jre/lib"); if (0 != access(buf, F_OK)) {
snprintf(jrelib_p, buflen-len, "/lib");
}
if (0 == access(buf, F_OK)) { // Use current module name "libjvm.so"
len = strlen(buf);
snprintf(buf + len, buflen-len, "/hotspot/libjvm.so");
} else { // Go back to path of .so
rp = os::Posix::realpath((char *)dlinfo.dli_fname, buf, buflen); if (rp == NULL) { return;
}
}
}
}
}
// We need to keep small simple bookkeeping for os::reserve_memory and friends.
#define VMEM_MAPPED 1 #define VMEM_SHMATED 2
struct vmembk_t { int type; // 1 - mmap, 2 - shmat char* addr;
size_t size; // Real size, may be larger than usersize.
size_t pagesize; // page size of area
vmembk_t* next;
bool contains_addr(char* p) const { return p >= addr && p < (addr + size);
}
// Check that range is a sub range of memory block (or equal to memory block); // also check that range is fully page aligned to the page size if the block. void assert_is_valid_subrange(char* p, size_t s) const { if (!contains_range(p, s)) {
trcVerbose("[" PTR_FORMAT " - " PTR_FORMAT "] is not a sub " "range of [" PTR_FORMAT " - " PTR_FORMAT "].",
p2i(p), p2i(p + s), p2i(addr), p2i(addr + size));
guarantee0(false);
} if (!is_aligned_to(p, pagesize) || !is_aligned_to(p + s, pagesize)) {
trcVerbose("range [" PTR_FORMAT " - " PTR_FORMAT "] is not" " aligned to pagesize (%lu)", p2i(p), p2i(p + s), (unsignedlong) pagesize);
guarantee0(false);
}
}
};
// Reserve and attach a section of System V memory. // If <requested_addr> is not NULL, function will attempt to attach the memory at the given // address. Failing that, it will attach the memory anywhere. // If <requested_addr> is NULL, function will attach the memory anywhere. staticchar* reserve_shmated_memory (size_t bytes, char* requested_addr) {
// We must prevent anyone from attaching too close to the // BRK because that may cause malloc OOM. if (requested_addr != NULL && is_close_to_brk((address)requested_addr)) {
trcVerbose("Wish address " PTR_FORMAT " is too close to the BRK segment.", p2i(requested_addr)); // Since we treat an attach to the wrong address as an error later anyway, // we return NULL here return NULL;
}
// For old AS/400's (V5R4 and older) we should not even be here - System V shared memory is not // really supported (max size 4GB), so reserve_mmapped_memory should have been used instead. if (os::Aix::on_pase_V5R4_or_older()) {
ShouldNotReachHere();
}
// Align size of shm up to 64K to avoid errors if we later try to change the page size. const size_t size = align_up(bytes, 64*K);
// Important note: // It is very important that we, upon leaving this function, do not leave a shm segment alive. // We must right after attaching it remove it from the system. System V shm segments are global and // survive the process. // So, from here on: Do not assert, do not return, until we have called shmctl(IPC_RMID) (A).
struct shmid_ds shmbuf;
memset(&shmbuf, 0, sizeof(shmbuf));
shmbuf.shm_pagesize = 64*K; if (shmctl(shmid, SHM_PAGESIZE, &shmbuf) != 0) {
trcVerbose("Failed to set page size (need " UINTX_FORMAT " 64K pages) - shmctl failed with %d.",
size / (64*K), errno); // I want to know if this ever happens.
assert(false, "failed to set page size for shmat");
}
// Now attach the shared segment. // Note that I attach with SHM_RND - which means that the requested address is rounded down, if // needed, to the next lowest segment boundary. Otherwise the attach would fail if the address // were not a segment boundary. char* const addr = (char*) shmat(shmid, requested_addr, SHM_RND); constint errno_shmat = errno;
// (A) Right after shmat and before handing shmat errors delete the shm segment. if (::shmctl(shmid, IPC_RMID, NULL) == -1) {
trcVerbose("shmctl(%u, IPC_RMID) failed (%d)\n", shmid, errno);
assert(false, "failed to remove shared memory segment!");
}
// Handle shmat error. If we failed to attach, just return. if (addr == (char*)-1) {
trcVerbose("Failed to attach segment at " PTR_FORMAT " (%d).", p2i(requested_addr), errno_shmat); return NULL;
}
// Just for info: query the real page size. In case setting the page size did not // work (see above), the system may have given us something other then 4K (LDR_CNTRL). const size_t real_pagesize = os::Aix::query_pagesize(addr); if (real_pagesize != shmbuf.shm_pagesize) {
trcVerbose("pagesize is, surprisingly, " SIZE_FORMAT, real_pagesize);
}
if (addr) {
trcVerbose("shm-allocated " PTR_FORMAT " .. " PTR_FORMAT " (" UINTX_FORMAT " bytes, " UINTX_FORMAT " %s pages)",
p2i(addr), p2i(addr + size - 1), size, size/real_pagesize, describe_pagesize(real_pagesize));
} else { if (requested_addr != NULL) {
trcVerbose("failed to shm-allocate " UINTX_FORMAT " bytes at with address " PTR_FORMAT ".", size, p2i(requested_addr));
} else {
trcVerbose("failed to shm-allocate " UINTX_FORMAT " bytes at any address.", size);
}
}
// TODO: is there a way to verify shm size without doing bookkeeping? if (::shmdt(addr) != 0) {
trcVerbose("error (%d).", errno);
} else {
trcVerbose("ok.");
rc = true;
} return rc;
}
// Reserve memory via mmap. // If <requested_addr> is given, an attempt is made to attach at the given address. // Failing that, memory is allocated at any address. staticchar* reserve_mmaped_memory(size_t bytes, char* requested_addr) {
trcVerbose("reserve_mmaped_memory " UINTX_FORMAT " bytes, wishaddress " PTR_FORMAT "...",
bytes, p2i(requested_addr));
if (requested_addr && !is_aligned_to(requested_addr, os::vm_page_size()) != 0) {
trcVerbose("Wish address " PTR_FORMAT " not aligned to page boundary.", p2i(requested_addr)); return NULL;
}
// We must prevent anyone from attaching too close to the // BRK because that may cause malloc OOM. if (requested_addr != NULL && is_close_to_brk((address)requested_addr)) {
trcVerbose("Wish address " PTR_FORMAT " is too close to the BRK segment.", p2i(requested_addr)); // Since we treat an attach to the wrong address as an error later anyway, // we return NULL here return NULL;
}
// In 64K mode, we lie and claim the global page size (os::vm_page_size()) is 64K // (complicated story). This mostly works just fine since 64K is a multiple of the // actual 4K lowest page size. Only at a few seams light shines thru, e.g. when // calling mmap. mmap will return memory aligned to the lowest pages size - 4K - // so we must make sure - transparently - that the caller only ever sees 64K // aligned mapping start addresses. const size_t alignment = os::vm_page_size();
// Size shall always be a multiple of os::vm_page_size (esp. in 64K mode). const size_t size = align_up(bytes, os::vm_page_size());
// alignment: Allocate memory large enough to include an aligned range of the right size and // cut off the leading and trailing waste pages.
assert0(alignment != 0 && is_aligned_to(alignment, os::vm_page_size())); // see above const size_t extra_size = size + alignment;
// Note: MAP_SHARED (instead of MAP_PRIVATE) needed to be able to // later use msync(MS_INVALIDATE) (see os::uncommit_memory). int flags = MAP_ANONYMOUS | MAP_SHARED;
// MAP_FIXED is needed to enforce requested_addr - manpage is vague about what // it means if wishaddress is given but MAP_FIXED is not set. // // Important! Behaviour differs depending on whether SPEC1170 mode is active or not. // SPEC1170 mode active: behaviour like POSIX, MAP_FIXED will clobber existing mappings. // SPEC1170 mode not active: behaviour, unlike POSIX, is that no existing mappings will // get clobbered. if (requested_addr != NULL) { if (!os::Aix::xpg_sus_mode()) { // not SPEC1170 Behaviour
flags |= MAP_FIXED;
}
}
if (UseExplicitCommit) { // AIX commits memory on touch. So, touch all pages to be committed. for (char* p = addr; p < (addr + size); p += 4*K) {
*p = '\0';
}
}
void os::pd_commit_memory_or_exit(char* addr, size_t size,
size_t alignment_hint, bool exec, constchar* mesg) { // Alignment_hint is ignored on this OS.
pd_commit_memory_or_exit(addr, size, exec, mesg);
}
bool os::pd_uncommit_memory(char* addr, size_t size, bool exec) {
assert(is_aligned_to(addr, os::vm_page_size()), "addr " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
p2i(addr), os::vm_page_size());
assert(is_aligned_to(size, os::vm_page_size()), "size " PTR_FORMAT " not aligned to vm_page_size (" PTR_FORMAT ")",
size, os::vm_page_size());
// Dynamically do different things for mmap/shmat. const vmembk_t* const vmi = vmembk_find(addr);
guarantee0(vmi);
vmi->assert_is_valid_subrange(addr, size);
bool os::pd_create_stack_guard_pages(char* addr, size_t size) { // Do not call this; no need to commit stack pages on AIX.
ShouldNotReachHere(); returntrue;
}
bool os::remove_stack_guard_pages(char* addr, size_t size) { // Do not call this; no need to commit stack pages on AIX.
ShouldNotReachHere(); returntrue;
}
// Reserves and attaches a shared memory segment. char* os::pd_reserve_memory(size_t bytes, bool exec) { // Always round to os::vm_page_size(), which may be larger than 4K.
bytes = align_up(bytes, os::vm_page_size());
// In 4K mode always use mmap. // In 64K mode allocate small sizes with mmap, large ones with 64K shmatted.
--> --------------------
--> maximum size reached
--> --------------------
¤ Dauer der Verarbeitung: 0.36 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.