Skip to content

Commit 9bfffa0

Browse files
committed
8291945: Add OSInfo API for static OS information
Reviewed-by: dholmes, stuefe
1 parent bd58553 commit 9bfffa0

File tree

17 files changed

+145
-105
lines changed

17 files changed

+145
-105
lines changed

src/hotspot/os/aix/os_aix.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#include "runtime/mutexLocker.hpp"
6161
#include "runtime/objectMonitor.hpp"
6262
#include "runtime/os.hpp"
63+
#include "runtime/osInfo.hpp"
6364
#include "runtime/osThread.hpp"
6465
#include "runtime/perfMemory.hpp"
6566
#include "runtime/safefetch.hpp"
@@ -160,7 +161,6 @@ static void vmembk_print_on(outputStream* os);
160161
julong os::Aix::_physical_memory = 0;
161162

162163
pthread_t os::Aix::_main_thread = ((pthread_t)0);
163-
int os::Aix::_page_size = -1;
164164

165165
// -1 = uninitialized, 0 if AIX, 1 if OS/400 pase
166166
int os::Aix::_on_pase = -1;
@@ -1751,18 +1751,6 @@ static bool uncommit_mmaped_memory(char* addr, size_t size) {
17511751
return rc;
17521752
}
17531753

1754-
int os::vm_page_size() {
1755-
// Seems redundant as all get out.
1756-
assert(os::Aix::page_size() != -1, "must call os::init");
1757-
return os::Aix::page_size();
1758-
}
1759-
1760-
// Aix allocates memory by pages.
1761-
int os::vm_allocation_granularity() {
1762-
assert(os::Aix::page_size() != -1, "must call os::init");
1763-
return os::Aix::page_size();
1764-
}
1765-
17661754
#ifdef PRODUCT
17671755
static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
17681756
int err) {
@@ -2228,6 +2216,11 @@ extern "C" {
22282216
}
22292217
}
22302218

2219+
static void set_page_size(int page_size) {
2220+
OSInfo::set_vm_page_size(page_size);
2221+
OSInfo::set_vm_allocation_granularity(page_size);
2222+
}
2223+
22312224
// This is called _before_ the most of global arguments have been parsed.
22322225
void os::init(void) {
22332226
// This is basic, we want to know if that ever changes.
@@ -2284,16 +2277,16 @@ void os::init(void) {
22842277
// -XX:-Use64KPages.
22852278
if (Use64KPages) {
22862279
trcVerbose("64K page mode (faked for data segment)");
2287-
Aix::_page_size = 64*K;
2280+
set_page_size(64*K);
22882281
} else {
22892282
trcVerbose("4K page mode (Use64KPages=off)");
2290-
Aix::_page_size = 4*K;
2283+
set_page_size(4*K);
22912284
}
22922285
} else {
22932286
// .. and not able to allocate 64k pages dynamically. Here, just
22942287
// fall back to 4K paged mode and use mmap for everything.
22952288
trcVerbose("4K page mode");
2296-
Aix::_page_size = 4*K;
2289+
set_page_size(4*K);
22972290
FLAG_SET_ERGO(Use64KPages, false);
22982291
}
22992292
} else {
@@ -2302,14 +2295,14 @@ void os::init(void) {
23022295
// (There is one special case where this may be false: EXTSHM=on.
23032296
// but we decided to not support that mode).
23042297
assert0(g_multipage_support.can_use_64K_pages);
2305-
Aix::_page_size = 64*K;
2298+
set_page_size(64*K);
23062299
trcVerbose("64K page mode");
23072300
FLAG_SET_ERGO(Use64KPages, true);
23082301
}
23092302

23102303
// For now UseLargePages is just ignored.
23112304
FLAG_SET_ERGO(UseLargePages, false);
2312-
_page_sizes.add(Aix::_page_size);
2305+
_page_sizes.add(os::vm_page_size);
23132306

23142307
// debug trace
23152308
trcVerbose("os::vm_page_size %s", describe_pagesize(os::vm_page_size()));

src/hotspot/os/aix/os_aix.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class os::Aix {
3737

3838
static julong _physical_memory;
3939
static pthread_t _main_thread;
40-
static int _page_size;
4140

4241
// -1 = uninitialized, 0 = AIX, 1 = OS/400 (PASE)
4342
static int _on_pase;
@@ -86,11 +85,6 @@ class os::Aix {
8685
// Given an address, returns the size of the page backing that address
8786
static size_t query_pagesize(void* p);
8887

89-
static int page_size(void) {
90-
assert(_page_size != -1, "not initialized");
91-
return _page_size;
92-
}
93-
9488
static intptr_t* ucontext_get_sp(const ucontext_t* uc);
9589
static intptr_t* ucontext_get_fp(const ucontext_t* uc);
9690

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "runtime/javaThread.hpp"
5050
#include "runtime/mutexLocker.hpp"
5151
#include "runtime/objectMonitor.hpp"
52+
#include "runtime/osInfo.hpp"
5253
#include "runtime/osThread.hpp"
5354
#include "runtime/perfMemory.hpp"
5455
#include "runtime/semaphore.hpp"
@@ -121,7 +122,6 @@ mach_timebase_info_data_t os::Bsd::_timebase_info = {0, 0};
121122
volatile uint64_t os::Bsd::_max_abstime = 0;
122123
#endif
123124
pthread_t os::Bsd::_main_thread;
124-
int os::Bsd::_page_size = -1;
125125

126126
#if defined(__APPLE__) && defined(__x86_64__)
127127
static const int processor_id_unassigned = -1;
@@ -1477,18 +1477,6 @@ void os::jvm_path(char *buf, jint buflen) {
14771477
////////////////////////////////////////////////////////////////////////////////
14781478
// Virtual Memory
14791479

1480-
int os::vm_page_size() {
1481-
// Seems redundant as all get out
1482-
assert(os::Bsd::page_size() != -1, "must call os::init");
1483-
return os::Bsd::page_size();
1484-
}
1485-
1486-
// Solaris allocates memory by pages.
1487-
int os::vm_allocation_granularity() {
1488-
assert(os::Bsd::page_size() != -1, "must call os::init");
1489-
return os::Bsd::page_size();
1490-
}
1491-
14921480
static void warn_fail_commit_memory(char* addr, size_t size, bool exec,
14931481
int err) {
14941482
warning("INFO: os::commit_memory(" INTPTR_FORMAT ", " SIZE_FORMAT
@@ -1666,7 +1654,7 @@ bool os::pd_release_memory(char* addr, size_t size) {
16661654

16671655
static bool bsd_mprotect(char* addr, size_t size, int prot) {
16681656
// Bsd wants the mprotect address argument to be page aligned.
1669-
char* bottom = (char*)align_down((intptr_t)addr, os::Bsd::page_size());
1657+
char* bottom = (char*)align_down((intptr_t)addr, os::vm_page_size());
16701658

16711659
// According to SUSv3, mprotect() should only be used with mappings
16721660
// established by mmap(), and mmap() always maps whole pages. Unaligned
@@ -1675,7 +1663,7 @@ static bool bsd_mprotect(char* addr, size_t size, int prot) {
16751663
// caller if you hit this assert.
16761664
assert(addr == bottom, "sanity check");
16771665

1678-
size = align_up(pointer_delta(addr, bottom, 1) + size, os::Bsd::page_size());
1666+
size = align_up(pointer_delta(addr, bottom, 1) + size, os::vm_page_size());
16791667
Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot);
16801668
return ::mprotect(bottom, size, prot) == 0;
16811669
}
@@ -1929,11 +1917,13 @@ extern void report_error(char* file_name, int line_no, char* title,
19291917
void os::init(void) {
19301918
char dummy; // used to get a guess on initial stack address
19311919

1932-
Bsd::set_page_size(getpagesize());
1933-
if (Bsd::page_size() == -1) {
1934-
fatal("os_bsd.cpp: os::init: sysconf failed (%s)", os::strerror(errno));
1920+
int page_size = getpagesize();
1921+
OSInfo::set_vm_page_size(page_size);
1922+
OSInfo::set_vm_allocation_granularity(page_size);
1923+
if (os::vm_page_size() <= 0) {
1924+
fatal("os_bsd.cpp: os::init: getpagesize() failed (%s)", os::strerror(errno));
19351925
}
1936-
_page_sizes.add(Bsd::page_size());
1926+
_page_sizes.add(os::vm_page_size());
19371927

19381928
Bsd::initialize_system_info();
19391929

src/hotspot/os/bsd/os_bsd.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class os::Bsd {
4444

4545
static julong _physical_memory;
4646
static pthread_t _main_thread;
47-
static int _page_size;
4847

4948
static julong available_memory();
5049
static julong physical_memory() { return _physical_memory; }
@@ -62,9 +61,6 @@ class os::Bsd {
6261

6362
static pid_t gettid();
6463

65-
static int page_size(void) { return _page_size; }
66-
static void set_page_size(int val) { _page_size = val; }
67-
6864
static intptr_t* ucontext_get_sp(const ucontext_t* uc);
6965
static intptr_t* ucontext_get_fp(const ucontext_t* uc);
7066

src/hotspot/os/linux/os_linux.cpp

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "runtime/javaThread.hpp"
5353
#include "runtime/mutexLocker.hpp"
5454
#include "runtime/objectMonitor.hpp"
55+
#include "runtime/osInfo.hpp"
5556
#include "runtime/osThread.hpp"
5657
#include "runtime/perfMemory.hpp"
5758
#include "runtime/sharedRuntime.hpp"
@@ -162,7 +163,6 @@ uintptr_t os::Linux::_initial_thread_stack_size = 0;
162163
int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
163164
int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL;
164165
pthread_t os::Linux::_main_thread;
165-
int os::Linux::_page_size = -1;
166166
bool os::Linux::_supports_fast_thread_cpu_time = false;
167167
const char * os::Linux::_libc_version = NULL;
168168
const char * os::Linux::_libpthread_version = NULL;
@@ -605,8 +605,8 @@ static void NOINLINE _expand_stack_to(address bottom) {
605605

606606
// Adjust bottom to point to the largest address within the same page, it
607607
// gives us a one-page buffer if alloca() allocates slightly more memory.
608-
bottom = (address)align_down((uintptr_t)bottom, os::Linux::page_size());
609-
bottom += os::Linux::page_size() - 1;
608+
bottom = (address)align_down((uintptr_t)bottom, os::vm_page_size());
609+
bottom += os::vm_page_size() - 1;
610610

611611
// sp might be slightly above current stack pointer; if that's the case, we
612612
// will alloca() a little more space than necessary, which is OK. Don't use
@@ -1078,8 +1078,8 @@ void os::Linux::capture_initial_stack(size_t max_size) {
10781078
// lower end of primordial stack; reduce ulimit -s value a little bit
10791079
// so we won't install guard page on ld.so's data section.
10801080
// But ensure we don't underflow the stack size - allow 1 page spare
1081-
if (stack_size >= (size_t)(3 * page_size())) {
1082-
stack_size -= 2 * page_size();
1081+
if (stack_size >= (size_t)(3 * os::vm_page_size())) {
1082+
stack_size -= 2 * os::vm_page_size();
10831083
}
10841084

10851085
// Try to figure out where the stack base (top) is. This is harder.
@@ -1235,11 +1235,11 @@ void os::Linux::capture_initial_stack(size_t max_size) {
12351235
// stack top, use it as stack top, and reduce stack size so we won't put
12361236
// guard page outside stack.
12371237
stack_top = stack_start;
1238-
stack_size -= 16 * page_size();
1238+
stack_size -= 16 * os::vm_page_size();
12391239
}
12401240

12411241
// stack_top could be partially down the page so align it
1242-
stack_top = align_up(stack_top, page_size());
1242+
stack_top = align_up(stack_top, os::vm_page_size());
12431243

12441244
// Allowed stack value is minimum of max_size and what we derived from rlimit
12451245
if (max_size > 0) {
@@ -1249,7 +1249,7 @@ void os::Linux::capture_initial_stack(size_t max_size) {
12491249
// clamp it at 8MB as we do on Solaris
12501250
_initial_thread_stack_size = MIN2(stack_size, 8*M);
12511251
}
1252-
_initial_thread_stack_size = align_down(_initial_thread_stack_size, page_size());
1252+
_initial_thread_stack_size = align_down(_initial_thread_stack_size, os::vm_page_size());
12531253
_initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size;
12541254

12551255
assert(_initial_thread_stack_bottom < (address)stack_top, "overflow!");
@@ -2594,18 +2594,6 @@ void os::jvm_path(char *buf, jint buflen) {
25942594
////////////////////////////////////////////////////////////////////////////////
25952595
// Virtual Memory
25962596

2597-
int os::vm_page_size() {
2598-
// Seems redundant as all get out
2599-
assert(os::Linux::page_size() != -1, "must call os::init");
2600-
return os::Linux::page_size();
2601-
}
2602-
2603-
// Solaris allocates memory by pages.
2604-
int os::vm_allocation_granularity() {
2605-
assert(os::Linux::page_size() != -1, "must call os::init");
2606-
return os::Linux::page_size();
2607-
}
2608-
26092597
// Rationale behind this function:
26102598
// current (Mon Apr 25 20:12:18 MSD 2005) oprofile drops samples without executable
26112599
// mapping for address (see lookup_dcookie() in the kernel module), thus we cannot get
@@ -3012,7 +3000,7 @@ size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
30123000
// Creating guard page is very expensive. Java thread has HotSpot
30133001
// guard pages, only enable glibc guard page for non-Java threads.
30143002
// (Remember: compiler thread is a Java thread, too!)
3015-
return ((thr_type == java_thread || thr_type == compiler_thread) ? 0 : page_size());
3003+
return ((thr_type == java_thread || thr_type == compiler_thread) ? 0 : os::vm_page_size());
30163004
}
30173005

30183006
void os::Linux::rebuild_nindex_to_node_map() {
@@ -3423,7 +3411,7 @@ extern char* g_assert_poison; // assertion poison page address
34233411

34243412
static bool linux_mprotect(char* addr, size_t size, int prot) {
34253413
// Linux wants the mprotect address argument to be page aligned.
3426-
char* bottom = (char*)align_down((intptr_t)addr, os::Linux::page_size());
3414+
char* bottom = (char*)align_down((intptr_t)addr, os::vm_page_size());
34273415

34283416
// According to SUSv3, mprotect() should only be used with mappings
34293417
// established by mmap(), and mmap() always maps whole pages. Unaligned
@@ -3432,7 +3420,7 @@ static bool linux_mprotect(char* addr, size_t size, int prot) {
34323420
// caller if you hit this assert.
34333421
assert(addr == bottom, "sanity check");
34343422

3435-
size = align_up(pointer_delta(addr, bottom, 1) + size, os::Linux::page_size());
3423+
size = align_up(pointer_delta(addr, bottom, 1) + size, os::vm_page_size());
34363424
// Don't log anything if we're executing in the poison page signal handling
34373425
// context. It can lead to reentrant use of other parts of the VM code.
34383426
#ifdef CAN_SHOW_REGISTERS_ON_ASSERT
@@ -4315,7 +4303,7 @@ extern void report_error(char* file_name, int line_no, char* title,
43154303
static void check_pax(void) {
43164304
// Zero doesn't generate code dynamically, so no need to perform the PaX check
43174305
#ifndef ZERO
4318-
size_t size = os::Linux::page_size();
4306+
size_t size = os::vm_page_size();
43194307

43204308
void* p = ::mmap(NULL, size, PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
43214309
if (p == MAP_FAILED) {
@@ -4340,12 +4328,14 @@ void os::init(void) {
43404328

43414329
clock_tics_per_sec = sysconf(_SC_CLK_TCK);
43424330

4343-
Linux::set_page_size(sysconf(_SC_PAGESIZE));
4344-
if (Linux::page_size() == -1) {
4331+
int page_size = sysconf(_SC_PAGESIZE);
4332+
OSInfo::set_vm_page_size(page_size);
4333+
OSInfo::set_vm_allocation_granularity(page_size);
4334+
if (os::vm_page_size() <= 0) {
43454335
fatal("os_linux.cpp: os::init: sysconf failed (%s)",
43464336
os::strerror(errno));
43474337
}
4348-
_page_sizes.add(Linux::page_size());
4338+
_page_sizes.add(os::vm_page_size());
43494339

43504340
Linux::initialize_system_info();
43514341

src/hotspot/os/linux/os_linux.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ class os::Linux {
5555

5656
static julong _physical_memory;
5757
static pthread_t _main_thread;
58-
static int _page_size;
5958

6059
static julong available_memory();
6160
static julong physical_memory() { return _physical_memory; }
@@ -132,9 +131,6 @@ class os::Linux {
132131
static address initial_thread_stack_bottom(void) { return _initial_thread_stack_bottom; }
133132
static uintptr_t initial_thread_stack_size(void) { return _initial_thread_stack_size; }
134133

135-
static int page_size(void) { return _page_size; }
136-
static void set_page_size(int val) { _page_size = val; }
137-
138134
static intptr_t* ucontext_get_sp(const ucontext_t* uc);
139135
static intptr_t* ucontext_get_fp(const ucontext_t* uc);
140136

0 commit comments

Comments
 (0)