Skip to content

Commit d5d94db

Browse files
toxaartDavid Holmes
authored andcommitted
8357086: os::xxx functions returning memory size should return size_t
Reviewed-by: stefank, dholmes
1 parent dbac620 commit d5d94db

File tree

22 files changed

+254
-162
lines changed

22 files changed

+254
-162
lines changed

src/hotspot/os/aix/os_aix.cpp

Lines changed: 20 additions & 17 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-
julong os::Aix::_physical_memory = 0;
172+
size_t os::Aix::_physical_memory = 0;
173173

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

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

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

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

265-
julong os::Aix::available_memory() {
265+
bool os::Aix::available_memory(size_t& value) {
266266
os::Aix::meminfo_t mi;
267267
if (os::Aix::get_meminfo(&mi)) {
268-
return mi.real_free;
268+
value = static_cast<size_t>(mi.real_free);
269+
return true;
269270
} else {
270-
return ULONG_MAX;
271+
return false;
271272
}
272273
}
273274

274-
jlong os::total_swap_space() {
275+
bool os::total_swap_space(size_t& value) {
275276
perfstat_memory_total_t memory_info;
276277
if (libperfstat::perfstat_memory_total(nullptr, &memory_info, sizeof(perfstat_memory_total_t), 1) == -1) {
277-
return -1;
278+
return false;
278279
}
279-
return (jlong)(memory_info.pgsp_total * 4 * K);
280+
value = static_cast<size_t>(memory_info.pgsp_total * 4 * K);
281+
return true;
280282
}
281283

282-
jlong os::free_swap_space() {
284+
bool os::free_swap_space(size_t& value) {
283285
perfstat_memory_total_t memory_info;
284286
if (libperfstat::perfstat_memory_total(nullptr, &memory_info, sizeof(perfstat_memory_total_t), 1) == -1) {
285-
return -1;
287+
return false;
286288
}
287-
return (jlong)(memory_info.pgsp_free * 4 * K);
289+
value = static_cast<size_t>(memory_info.pgsp_free * 4 * K);
290+
return true;
288291
}
289292

290-
julong os::physical_memory() {
293+
size_t os::physical_memory() {
291294
return Aix::physical_memory();
292295
}
293296

@@ -326,7 +329,7 @@ void os::Aix::initialize_system_info() {
326329
if (!os::Aix::get_meminfo(&mi)) {
327330
assert(false, "os::Aix::get_meminfo failed.");
328331
}
329-
_physical_memory = (julong) mi.real_total;
332+
_physical_memory = static_cast<size_t>(mi.real_total);
330333
}
331334

332335
// Helper function for tracing page sizes.
@@ -2193,7 +2196,7 @@ jint os::init_2(void) {
21932196
os::Posix::init_2();
21942197

21952198
trcVerbose("processor count: %d", os::_processor_count);
2196-
trcVerbose("physical memory: %lu", Aix::_physical_memory);
2199+
trcVerbose("physical memory: %zu", Aix::_physical_memory);
21972200

21982201
// Initially build up the loaded dll map.
21992202
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 julong _physical_memory;
38+
static size_t _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 julong available_memory();
58-
static julong free_memory();
59-
static julong physical_memory() { return _physical_memory; }
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; }
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: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114

115115
////////////////////////////////////////////////////////////////////////////////
116116
// global variables
117-
julong os::Bsd::_physical_memory = 0;
117+
size_t 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-
julong os::available_memory() {
137-
return Bsd::available_memory();
136+
bool os::available_memory(size_t& value) {
137+
return Bsd::available_memory(value);
138138
}
139139

140-
julong os::free_memory() {
141-
return Bsd::available_memory();
140+
bool os::free_memory(size_t& value) {
141+
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-
julong os::Bsd::available_memory() {
148-
uint64_t available = physical_memory() >> 2;
147+
bool os::Bsd::available_memory(size_t& value) {
148+
uint64_t available = static_cast<uint64_t>(physical_memory() >> 2);
149149
#ifdef __APPLE__
150150
mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
151151
vm_statistics64_data_t vmstat;
@@ -156,9 +156,12 @@ julong os::Bsd::available_memory() {
156156
if (kerr == KERN_SUCCESS) {
157157
// free_count is just a lowerbound, other page categories can be freed too and make memory available
158158
available = (vmstat.free_count + vmstat.inactive_count + vmstat.purgeable_count) * os::vm_page_size();
159+
} else {
160+
return false;
159161
}
160162
#endif
161-
return available;
163+
value = static_cast<size_t>(available);
164+
return true;
162165
}
163166

164167
// for more info see :
@@ -177,33 +180,35 @@ void os::Bsd::print_uptime_info(outputStream* st) {
177180
}
178181
}
179182

180-
jlong os::total_swap_space() {
183+
bool os::total_swap_space(size_t& value) {
181184
#if defined(__APPLE__)
182185
struct xsw_usage vmusage;
183186
size_t size = sizeof(vmusage);
184187
if (sysctlbyname("vm.swapusage", &vmusage, &size, nullptr, 0) != 0) {
185-
return -1;
188+
return false;
186189
}
187-
return (jlong)vmusage.xsu_total;
190+
value = static_cast<size_t>(vmusage.xsu_total);
191+
return true;
188192
#else
189-
return -1;
193+
return false;
190194
#endif
191195
}
192196

193-
jlong os::free_swap_space() {
197+
bool os::free_swap_space(size_t& value) {
194198
#if defined(__APPLE__)
195199
struct xsw_usage vmusage;
196200
size_t size = sizeof(vmusage);
197201
if (sysctlbyname("vm.swapusage", &vmusage, &size, nullptr, 0) != 0) {
198-
return -1;
202+
return false;
199203
}
200-
return (jlong)vmusage.xsu_avail;
204+
value = static_cast<size_t>(vmusage.xsu_avail);
205+
return true;
201206
#else
202-
return -1;
207+
return false;
203208
#endif
204209
}
205210

206-
julong os::physical_memory() {
211+
size_t os::physical_memory() {
207212
return Bsd::physical_memory();
208213
}
209214

@@ -281,7 +286,7 @@ void os::Bsd::initialize_system_info() {
281286
len = sizeof(mem_val);
282287
if (sysctl(mib, 2, &mem_val, &len, nullptr, 0) != -1) {
283288
assert(len == sizeof(mem_val), "unexpected data size");
284-
_physical_memory = mem_val;
289+
_physical_memory = static_cast<size_t>(mem_val);
285290
} else {
286291
_physical_memory = 256 * 1024 * 1024; // fallback (XXXBSD?)
287292
}
@@ -292,7 +297,7 @@ void os::Bsd::initialize_system_info() {
292297
// datasize rlimit restricts us anyway.
293298
struct rlimit limits;
294299
getrlimit(RLIMIT_DATA, &limits);
295-
_physical_memory = MIN2(_physical_memory, (julong)limits.rlim_cur);
300+
_physical_memory = MIN2(_physical_memory, static_cast<size_t>(limits.rlim_cur));
296301
}
297302
#endif
298303
}
@@ -1464,11 +1469,13 @@ void os::print_memory_info(outputStream* st) {
14641469

14651470
st->print("Memory:");
14661471
st->print(" %zuk page", os::vm_page_size()>>10);
1467-
1468-
st->print(", physical " UINT64_FORMAT "k",
1469-
os::physical_memory() >> 10);
1470-
st->print("(" UINT64_FORMAT "k free)",
1471-
os::available_memory() >> 10);
1472+
size_t phys_mem = os::physical_memory();
1473+
st->print(", physical %zuk",
1474+
phys_mem >> 10);
1475+
size_t avail_mem = 0;
1476+
(void)os::available_memory(avail_mem);
1477+
st->print("(%zuk free)",
1478+
avail_mem >> 10);
14721479

14731480
if((sysctlbyname("vm.swapusage", &swap_usage, &size, nullptr, 0) == 0) || (errno == ENOMEM)) {
14741481
if (size >= offset_of(xsw_usage, xsu_used)) {

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 julong _physical_memory;
45+
static size_t _physical_memory;
4646
static pthread_t _main_thread;
4747

48-
static julong available_memory();
49-
static julong free_memory();
50-
static julong physical_memory() { return _physical_memory; }
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; }
5151
static void initialize_system_info();
5252

5353
static void rebuild_cpu_to_node_map();

src/hotspot/os/linux/cgroupSubsystem_linux.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ jlong CgroupSubsystem::memory_limit_in_bytes() {
670670
if (!memory_limit->should_check_metric()) {
671671
return memory_limit->value();
672672
}
673-
jlong phys_mem = os::Linux::physical_memory();
674-
log_trace(os, container)("total physical memory: " JLONG_FORMAT, phys_mem);
673+
julong phys_mem = static_cast<julong>(os::Linux::physical_memory());
674+
log_trace(os, container)("total physical memory: " JULONG_FORMAT, phys_mem);
675675
jlong mem_limit = contrl->controller()->read_memory_limit_in_bytes(phys_mem);
676676
// Update cached metric to avoid re-reading container settings too often
677677
memory_limit->set_value(mem_limit, OSCONTAINER_CACHE_TIMEOUT);
@@ -841,19 +841,19 @@ jlong CgroupController::limit_from_str(char* limit_str) {
841841
// CgroupSubsystem implementations
842842

843843
jlong CgroupSubsystem::memory_and_swap_limit_in_bytes() {
844-
julong phys_mem = os::Linux::physical_memory();
844+
julong phys_mem = static_cast<julong>(os::Linux::physical_memory());
845845
julong host_swap = os::Linux::host_swap();
846846
return memory_controller()->controller()->memory_and_swap_limit_in_bytes(phys_mem, host_swap);
847847
}
848848

849849
jlong CgroupSubsystem::memory_and_swap_usage_in_bytes() {
850-
julong phys_mem = os::Linux::physical_memory();
850+
julong phys_mem = static_cast<julong>(os::Linux::physical_memory());
851851
julong host_swap = os::Linux::host_swap();
852852
return memory_controller()->controller()->memory_and_swap_usage_in_bytes(phys_mem, host_swap);
853853
}
854854

855855
jlong CgroupSubsystem::memory_soft_limit_in_bytes() {
856-
julong phys_mem = os::Linux::physical_memory();
856+
julong phys_mem = static_cast<julong>(os::Linux::physical_memory());
857857
return memory_controller()->controller()->memory_soft_limit_in_bytes(phys_mem);
858858
}
859859

@@ -894,6 +894,6 @@ jlong CgroupSubsystem::cpu_usage_in_micros() {
894894
}
895895

896896
void CgroupSubsystem::print_version_specific_info(outputStream* st) {
897-
julong phys_mem = os::Linux::physical_memory();
897+
julong phys_mem = static_cast<julong>(os::Linux::physical_memory());
898898
memory_controller()->controller()->print_version_specific_info(st, phys_mem);
899899
}

src/hotspot/os/linux/cgroupUtil_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void CgroupUtil::adjust_controller(CgroupMemoryController* mem) {
6565
char* cg_path = os::strdup(orig);
6666
char* last_slash;
6767
assert(cg_path[0] == '/', "cgroup path must start with '/'");
68-
julong phys_mem = os::Linux::physical_memory();
68+
julong phys_mem = static_cast<julong>(os::Linux::physical_memory());
6969
char* limit_cg_path = nullptr;
7070
jlong limit = mem->read_memory_limit_in_bytes(phys_mem);
7171
jlong lowest_limit = limit < 0 ? phys_mem : limit;

0 commit comments

Comments
 (0)