Skip to content

Commit 2746c1a

Browse files
toxaarttstuefe
authored andcommitted
8367485: os::physical_memory is broken in 32-bit JVMs when running on 64-bit OSes
Reviewed-by: jsikstro, sgehwolf, stefank, stuefe, aph
1 parent 89af6e1 commit 2746c1a

File tree

20 files changed

+152
-145
lines changed

20 files changed

+152
-145
lines changed

src/hotspot/os/aix/os_aix.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ static void vmembk_print_on(outputStream* os);
169169
////////////////////////////////////////////////////////////////////////////////
170170
// global variables (for a description see os_aix.hpp)
171171

172-
size_t os::Aix::_physical_memory = 0;
172+
physical_memory_size_type os::Aix::_physical_memory = 0;
173173

174174
pthread_t os::Aix::_main_thread = ((pthread_t)0);
175175

@@ -254,43 +254,43 @@ static bool is_close_to_brk(address a) {
254254
return false;
255255
}
256256

257-
bool os::free_memory(size_t& value) {
257+
bool os::free_memory(physical_memory_size_type& value) {
258258
return Aix::available_memory(value);
259259
}
260260

261-
bool os::available_memory(size_t& value) {
261+
bool os::available_memory(physical_memory_size_type& value) {
262262
return Aix::available_memory(value);
263263
}
264264

265-
bool os::Aix::available_memory(size_t& value) {
265+
bool os::Aix::available_memory(physical_memory_size_type& value) {
266266
os::Aix::meminfo_t mi;
267267
if (os::Aix::get_meminfo(&mi)) {
268-
value = static_cast<size_t>(mi.real_free);
268+
value = static_cast<physical_memory_size_type>(mi.real_free);
269269
return true;
270270
} else {
271271
return false;
272272
}
273273
}
274274

275-
bool os::total_swap_space(size_t& value) {
275+
bool os::total_swap_space(physical_memory_size_type& value) {
276276
perfstat_memory_total_t memory_info;
277277
if (libperfstat::perfstat_memory_total(nullptr, &memory_info, sizeof(perfstat_memory_total_t), 1) == -1) {
278278
return false;
279279
}
280-
value = static_cast<size_t>(memory_info.pgsp_total * 4 * K);
280+
value = static_cast<physical_memory_size_type>(memory_info.pgsp_total * 4 * K);
281281
return true;
282282
}
283283

284-
bool os::free_swap_space(size_t& value) {
284+
bool os::free_swap_space(physical_memory_size_type& value) {
285285
perfstat_memory_total_t memory_info;
286286
if (libperfstat::perfstat_memory_total(nullptr, &memory_info, sizeof(perfstat_memory_total_t), 1) == -1) {
287287
return false;
288288
}
289-
value = static_cast<size_t>(memory_info.pgsp_free * 4 * K);
289+
value = static_cast<physical_memory_size_type>(memory_info.pgsp_free * 4 * K);
290290
return true;
291291
}
292292

293-
size_t os::physical_memory() {
293+
physical_memory_size_type os::physical_memory() {
294294
return Aix::physical_memory();
295295
}
296296

@@ -329,7 +329,7 @@ void os::Aix::initialize_system_info() {
329329
if (!os::Aix::get_meminfo(&mi)) {
330330
assert(false, "os::Aix::get_meminfo failed.");
331331
}
332-
_physical_memory = static_cast<size_t>(mi.real_total);
332+
_physical_memory = static_cast<physical_memory_size_type>(mi.real_total);
333333
}
334334

335335
// Helper function for tracing page sizes.
@@ -2192,7 +2192,7 @@ jint os::init_2(void) {
21922192
os::Posix::init_2();
21932193

21942194
trcVerbose("processor count: %d", os::_processor_count);
2195-
trcVerbose("physical memory: %zu", Aix::_physical_memory);
2195+
trcVerbose("physical memory: " PHYS_MEM_TYPE_FORMAT, Aix::_physical_memory);
21962196

21972197
// Initially build up the loaded dll map.
21982198
LoadedLibraries::reload();

src/hotspot/os/aix/os_aix.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class os::Aix {
3535

3636
private:
3737

38-
static size_t _physical_memory;
38+
static physical_memory_size_type _physical_memory;
3939
static pthread_t _main_thread;
4040

4141
// 0 = uninitialized, otherwise 16 bit number:
@@ -54,9 +54,9 @@ class os::Aix {
5454
// 1 - EXTSHM=ON
5555
static int _extshm;
5656

57-
static bool available_memory(size_t& value);
58-
static bool free_memory(size_t& value);
59-
static size_t physical_memory() { return _physical_memory; }
57+
static bool available_memory(physical_memory_size_type& value);
58+
static bool free_memory(physical_memory_size_type& value);
59+
static physical_memory_size_type physical_memory() { return _physical_memory; }
6060
static void initialize_system_info();
6161

6262
// OS recognitions (AIX OS level) call this before calling Aix::os_version().

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114

115115
////////////////////////////////////////////////////////////////////////////////
116116
// global variables
117-
size_t os::Bsd::_physical_memory = 0;
117+
physical_memory_size_type os::Bsd::_physical_memory = 0;
118118

119119
#ifdef __APPLE__
120120
mach_timebase_info_data_t os::Bsd::_timebase_info = {0, 0};
@@ -133,19 +133,19 @@ static volatile int processor_id_next = 0;
133133
////////////////////////////////////////////////////////////////////////////////
134134
// utility functions
135135

136-
bool os::available_memory(size_t& value) {
136+
bool os::available_memory(physical_memory_size_type& value) {
137137
return Bsd::available_memory(value);
138138
}
139139

140-
bool os::free_memory(size_t& value) {
140+
bool os::free_memory(physical_memory_size_type& value) {
141141
return Bsd::available_memory(value);
142142
}
143143

144144
// Available here means free. Note that this number is of no much use. As an estimate
145145
// for future memory pressure it is far too conservative, since MacOS will use a lot
146146
// of unused memory for caches, and return it willingly in case of needs.
147-
bool os::Bsd::available_memory(size_t& value) {
148-
uint64_t available = static_cast<uint64_t>(physical_memory() >> 2);
147+
bool os::Bsd::available_memory(physical_memory_size_type& value) {
148+
physical_memory_size_type available = physical_memory() >> 2;
149149
#ifdef __APPLE__
150150
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
151151
vm_statistics64_data_t vmstat;
@@ -160,7 +160,7 @@ bool os::Bsd::available_memory(size_t& value) {
160160
return false;
161161
}
162162
#endif
163-
value = static_cast<size_t>(available);
163+
value = available;
164164
return true;
165165
}
166166

@@ -180,35 +180,35 @@ void os::Bsd::print_uptime_info(outputStream* st) {
180180
}
181181
}
182182

183-
bool os::total_swap_space(size_t& value) {
183+
bool os::total_swap_space(physical_memory_size_type& value) {
184184
#if defined(__APPLE__)
185185
struct xsw_usage vmusage;
186186
size_t size = sizeof(vmusage);
187187
if (sysctlbyname("vm.swapusage", &vmusage, &size, nullptr, 0) != 0) {
188188
return false;
189189
}
190-
value = static_cast<size_t>(vmusage.xsu_total);
190+
value = static_cast<physical_memory_size_type>(vmusage.xsu_total);
191191
return true;
192192
#else
193193
return false;
194194
#endif
195195
}
196196

197-
bool os::free_swap_space(size_t& value) {
197+
bool os::free_swap_space(physical_memory_size_type& value) {
198198
#if defined(__APPLE__)
199199
struct xsw_usage vmusage;
200200
size_t size = sizeof(vmusage);
201201
if (sysctlbyname("vm.swapusage", &vmusage, &size, nullptr, 0) != 0) {
202202
return false;
203203
}
204-
value = static_cast<size_t>(vmusage.xsu_avail);
204+
value = static_cast<physical_memory_size_type>(vmusage.xsu_avail);
205205
return true;
206206
#else
207207
return false;
208208
#endif
209209
}
210210

211-
size_t os::physical_memory() {
211+
physical_memory_size_type os::physical_memory() {
212212
return Bsd::physical_memory();
213213
}
214214

@@ -286,7 +286,7 @@ void os::Bsd::initialize_system_info() {
286286
len = sizeof(mem_val);
287287
if (sysctl(mib, 2, &mem_val, &len, nullptr, 0) != -1) {
288288
assert(len == sizeof(mem_val), "unexpected data size");
289-
_physical_memory = static_cast<size_t>(mem_val);
289+
_physical_memory = static_cast<physical_memory_size_type>(mem_val);
290290
} else {
291291
_physical_memory = 256 * 1024 * 1024; // fallback (XXXBSD?)
292292
}
@@ -297,7 +297,7 @@ void os::Bsd::initialize_system_info() {
297297
// datasize rlimit restricts us anyway.
298298
struct rlimit limits;
299299
getrlimit(RLIMIT_DATA, &limits);
300-
_physical_memory = MIN2(_physical_memory, static_cast<size_t>(limits.rlim_cur));
300+
_physical_memory = MIN2(_physical_memory, static_cast<physical_memory_size_type>(limits.rlim_cur));
301301
}
302302
#endif
303303
}
@@ -1469,12 +1469,12 @@ void os::print_memory_info(outputStream* st) {
14691469

14701470
st->print("Memory:");
14711471
st->print(" %zuk page", os::vm_page_size()>>10);
1472-
size_t phys_mem = os::physical_memory();
1473-
st->print(", physical %zuk",
1472+
physical_memory_size_type phys_mem = os::physical_memory();
1473+
st->print(", physical " PHYS_MEM_TYPE_FORMAT "k",
14741474
phys_mem >> 10);
1475-
size_t avail_mem = 0;
1475+
physical_memory_size_type avail_mem = 0;
14761476
(void)os::available_memory(avail_mem);
1477-
st->print("(%zuk free)",
1477+
st->print("(" PHYS_MEM_TYPE_FORMAT "k free)",
14781478
avail_mem >> 10);
14791479

14801480
if((sysctlbyname("vm.swapusage", &swap_usage, &size, nullptr, 0) == 0) || (errno == ENOMEM)) {

src/hotspot/os/bsd/os_bsd.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ class os::Bsd {
4242

4343
protected:
4444

45-
static size_t _physical_memory;
45+
static physical_memory_size_type _physical_memory;
4646
static pthread_t _main_thread;
4747

48-
static bool available_memory(size_t& value);
49-
static bool free_memory(size_t& value);
50-
static size_t physical_memory() { return _physical_memory; }
48+
static bool available_memory(physical_memory_size_type& value);
49+
static bool free_memory(physical_memory_size_type& value);
50+
static physical_memory_size_type physical_memory() { return _physical_memory; }
5151
static void initialize_system_info();
5252

5353
static void rebuild_cpu_to_node_map();

0 commit comments

Comments
 (0)