Skip to content

Commit ac9e046

Browse files
committed
8301479: Replace NULL with nullptr in os/linux
Reviewed-by: coleenp, sgehwolf
1 parent cf68d9f commit ac9e046

17 files changed

+367
-367
lines changed

src/hotspot/os/linux/attachListener_linux.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -83,7 +83,7 @@ class LinuxAttachListener: AllStatic {
8383
};
8484

8585
static void set_path(char* path) {
86-
if (path == NULL) {
86+
if (path == nullptr) {
8787
_path[0] = '\0';
8888
_has_path = false;
8989
} else {
@@ -146,7 +146,7 @@ class ArgumentIterator : public StackObj {
146146
if (_pos < _end) {
147147
_pos += 1;
148148
}
149-
return NULL;
149+
return nullptr;
150150
}
151151
char* res = _pos;
152152
char* next_pos = strchr(_pos, '\0');
@@ -171,7 +171,7 @@ extern "C" {
171171
}
172172
if (LinuxAttachListener::has_path()) {
173173
::unlink(LinuxAttachListener::path());
174-
LinuxAttachListener::set_path(NULL);
174+
LinuxAttachListener::set_path(nullptr);
175175
}
176176
}
177177
}
@@ -275,7 +275,7 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
275275
assert(n <= left, "buffer was too small, impossible!");
276276
buf[max_len - 1] = '\0';
277277
if (n == -1) {
278-
return NULL; // reset by peer or other error
278+
return nullptr; // reset by peer or other error
279279
}
280280
if (n == 0) {
281281
break;
@@ -293,7 +293,7 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
293293
char msg[32];
294294
os::snprintf_checked(msg, sizeof(msg), "%d\n", ATTACH_ERROR_BADVERSION);
295295
write_fully(s, msg, strlen(msg));
296-
return NULL;
296+
return nullptr;
297297
}
298298
}
299299
}
@@ -303,7 +303,7 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
303303
} while (left > 0 && str_count < expected_str_count);
304304

305305
if (str_count != expected_str_count) {
306-
return NULL; // incomplete request
306+
return nullptr; // incomplete request
307307
}
308308

309309
// parse request
@@ -314,20 +314,20 @@ LinuxAttachOperation* LinuxAttachListener::read_request(int s) {
314314
char* v = args.next();
315315

316316
char* name = args.next();
317-
if (name == NULL || strlen(name) > AttachOperation::name_length_max) {
318-
return NULL;
317+
if (name == nullptr || strlen(name) > AttachOperation::name_length_max) {
318+
return nullptr;
319319
}
320320

321321
LinuxAttachOperation* op = new LinuxAttachOperation(name);
322322

323323
for (int i=0; i<AttachOperation::arg_count_max; i++) {
324324
char* arg = args.next();
325-
if (arg == NULL) {
326-
op->set_arg(i, NULL);
325+
if (arg == nullptr) {
326+
op->set_arg(i, nullptr);
327327
} else {
328328
if (strlen(arg) > AttachOperation::arg_length_max) {
329329
delete op;
330-
return NULL;
330+
return nullptr;
331331
}
332332
op->set_arg(i, arg);
333333
}
@@ -352,7 +352,7 @@ LinuxAttachOperation* LinuxAttachListener::dequeue() {
352352
socklen_t len = sizeof(addr);
353353
RESTARTABLE(::accept(listener(), &addr, &len), s);
354354
if (s == -1) {
355-
return NULL; // log a warning?
355+
return nullptr; // log a warning?
356356
}
357357

358358
// get the credentials of the peer and check the effective uid/guid
@@ -373,7 +373,7 @@ LinuxAttachOperation* LinuxAttachListener::dequeue() {
373373

374374
// peer credential look okay so we read the request
375375
LinuxAttachOperation* op = read_request(s);
376-
if (op == NULL) {
376+
if (op == nullptr) {
377377
::close(s);
378378
continue;
379379
} else {
@@ -548,7 +548,7 @@ void AttachListener::pd_data_dump() {
548548
}
549549

550550
AttachOperationFunctionInfo* AttachListener::pd_find_operation(const char* n) {
551-
return NULL;
551+
return nullptr;
552552
}
553553

554554
jint AttachListener::pd_set_flag(AttachOperation* op, outputStream* out) {

src/hotspot/os/linux/cgroupSubsystem_linux.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -39,11 +39,11 @@
3939
static const char* cg_controller_name[] = { "cpu", "cpuset", "cpuacct", "memory", "pids" };
4040

4141
CgroupSubsystem* CgroupSubsystemFactory::create() {
42-
CgroupV1MemoryController* memory = NULL;
43-
CgroupV1Controller* cpuset = NULL;
44-
CgroupV1Controller* cpu = NULL;
45-
CgroupV1Controller* cpuacct = NULL;
46-
CgroupV1Controller* pids = NULL;
42+
CgroupV1MemoryController* memory = nullptr;
43+
CgroupV1Controller* cpuset = nullptr;
44+
CgroupV1Controller* cpu = nullptr;
45+
CgroupV1Controller* cpuacct = nullptr;
46+
CgroupV1Controller* pids = nullptr;
4747
CgroupInfo cg_infos[CG_INFO_LENGTH];
4848
u1 cg_type_flags = INVALID_CGROUPS_GENERIC;
4949
const char* proc_cgroups = "/proc/cgroups";
@@ -54,7 +54,7 @@ CgroupSubsystem* CgroupSubsystemFactory::create() {
5454

5555
if (!valid_cgroup) {
5656
// Could not detect cgroup type
57-
return NULL;
57+
return nullptr;
5858
}
5959
assert(is_valid_cgroup(&cg_type_flags), "Expected valid cgroup type");
6060

@@ -128,7 +128,7 @@ void CgroupSubsystemFactory::set_controller_paths(CgroupInfo* cg_infos,
128128
const char* name,
129129
char* mount_path,
130130
char* root_path) {
131-
if (cg_infos[controller]._mount_path != NULL) {
131+
if (cg_infos[controller]._mount_path != nullptr) {
132132
// On some systems duplicate controllers get mounted in addition to
133133
// the main cgroup controllers most likely under /sys/fs/cgroup. In that
134134
// case pick the one under /sys/fs/cgroup and discard others.
@@ -154,9 +154,9 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
154154
const char* proc_self_cgroup,
155155
const char* proc_self_mountinfo,
156156
u1* flags) {
157-
FILE *mntinfo = NULL;
158-
FILE *cgroups = NULL;
159-
FILE *cgroup = NULL;
157+
FILE *mntinfo = nullptr;
158+
FILE *cgroups = nullptr;
159+
FILE *cgroup = nullptr;
160160
char buf[MAXPATHLEN+1];
161161
char *p;
162162
bool is_cgroupsV2;
@@ -174,13 +174,13 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
174174
* controllers must have hierarchy ID 0 and the unified controller mounted.
175175
*/
176176
cgroups = os::fopen(proc_cgroups, "r");
177-
if (cgroups == NULL) {
177+
if (cgroups == nullptr) {
178178
log_debug(os, container)("Can't open %s, %s", proc_cgroups, os::strerror(errno));
179179
*flags = INVALID_CGROUPS_GENERIC;
180180
return false;
181181
}
182182

183-
while ((p = fgets(buf, MAXPATHLEN, cgroups)) != NULL) {
183+
while ((p = fgets(buf, MAXPATHLEN, cgroups)) != nullptr) {
184184
char name[MAXPATHLEN+1];
185185
int hierarchy_id;
186186
int enabled;
@@ -242,15 +242,15 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
242242
* the host mount point to the local one via /proc/self/mountinfo below.
243243
*/
244244
cgroup = os::fopen(proc_self_cgroup, "r");
245-
if (cgroup == NULL) {
245+
if (cgroup == nullptr) {
246246
log_debug(os, container)("Can't open %s, %s",
247247
proc_self_cgroup, os::strerror(errno));
248248
cleanup(cg_infos);
249249
*flags = INVALID_CGROUPS_GENERIC;
250250
return false;
251251
}
252252

253-
while ((p = fgets(buf, MAXPATHLEN, cgroup)) != NULL) {
253+
while ((p = fgets(buf, MAXPATHLEN, cgroup)) != nullptr) {
254254
char *controllers;
255255
char *token;
256256
char *hierarchy_id_str;
@@ -263,11 +263,11 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
263263
controllers = strsep(&p, ":");
264264
cgroup_path = strsep(&p, "\n");
265265

266-
if (controllers == NULL) {
266+
if (controllers == nullptr) {
267267
continue;
268268
}
269269

270-
while (!is_cgroupsV2 && (token = strsep(&controllers, ",")) != NULL) {
270+
while (!is_cgroupsV2 && (token = strsep(&controllers, ",")) != nullptr) {
271271
if (strcmp(token, "memory") == 0) {
272272
assert(hierarchy_id == cg_infos[MEMORY_IDX]._hierarchy_id, "/proc/cgroups and /proc/self/cgroup hierarchy mismatch for memory");
273273
cg_infos[MEMORY_IDX]._cgroup_path = os::strdup(cgroup_path);
@@ -293,7 +293,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
293293
continue;
294294
}
295295
for (int i = 0; i < CG_INFO_LENGTH; i++) {
296-
assert(cg_infos[i]._cgroup_path == NULL, "cgroup path must only be set once");
296+
assert(cg_infos[i]._cgroup_path == nullptr, "cgroup path must only be set once");
297297
cg_infos[i]._cgroup_path = os::strdup(cgroup_path);
298298
}
299299
}
@@ -303,7 +303,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
303303
// Find various mount points by reading /proc/self/mountinfo
304304
// mountinfo format is documented at https://www.kernel.org/doc/Documentation/filesystems/proc.txt
305305
mntinfo = os::fopen(proc_self_mountinfo, "r");
306-
if (mntinfo == NULL) {
306+
if (mntinfo == nullptr) {
307307
log_debug(os, container)("Can't open %s, %s",
308308
proc_self_mountinfo, os::strerror(errno));
309309
cleanup(cg_infos);
@@ -313,7 +313,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
313313

314314
bool cgroupv2_mount_point_found = false;
315315
bool any_cgroup_mounts_found = false;
316-
while ((p = fgets(buf, MAXPATHLEN, mntinfo)) != NULL) {
316+
while ((p = fgets(buf, MAXPATHLEN, mntinfo)) != nullptr) {
317317
char tmp_fs_type[MAXPATHLEN+1];
318318
char tmproot[MAXPATHLEN+1];
319319
char tmpmount[MAXPATHLEN+1];
@@ -352,7 +352,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
352352
// Skip cgroup2 fs lines on hybrid or unified hierarchy.
353353
continue;
354354
}
355-
while ((token = strsep(&cptr, ",")) != NULL) {
355+
while ((token = strsep(&cptr, ",")) != nullptr) {
356356
if (strcmp(token, "memory") == 0) {
357357
any_cgroup_mounts_found = true;
358358
set_controller_paths(cg_infos, MEMORY_IDX, token, tmpmount, tmproot);
@@ -437,7 +437,7 @@ bool CgroupSubsystemFactory::determine_type(CgroupInfo* cg_infos,
437437
};
438438

439439
void CgroupSubsystemFactory::cleanup(CgroupInfo* cg_infos) {
440-
assert(cg_infos != NULL, "Invariant");
440+
assert(cg_infos != nullptr, "Invariant");
441441
for (int i = 0; i < CG_INFO_LENGTH; i++) {
442442
os::free(cg_infos[i]._name);
443443
os::free(cg_infos[i]._cgroup_path);
@@ -557,7 +557,7 @@ jlong CgroupSubsystem::memory_limit_in_bytes() {
557557
}
558558

559559
jlong CgroupSubsystem::limit_from_str(char* limit_str) {
560-
if (limit_str == NULL) {
560+
if (limit_str == nullptr) {
561561
return OSCONTAINER_ERROR;
562562
}
563563
// Unlimited memory in cgroups is the literal string 'max' for

src/hotspot/os/linux/cgroupSubsystem_linux.hpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -90,11 +90,11 @@ template <typename T> int subsystem_file_line_contents(CgroupController* c,
9090
const char *scan_fmt,
9191
T returnval) {
9292
if (c == nullptr) {
93-
log_debug(os, container)("subsystem_file_line_contents: CgroupController* is nullptr");
93+
log_debug(os, container)("subsystem_file_line_contents: CgroupController* is null");
9494
return OSCONTAINER_ERROR;
9595
}
9696
if (c->subsystem_path() == nullptr) {
97-
log_debug(os, container)("subsystem_file_line_contents: subsystem path is nullptr");
97+
log_debug(os, container)("subsystem_file_line_contents: subsystem path is null");
9898
return OSCONTAINER_ERROR;
9999
}
100100

@@ -166,7 +166,7 @@ PRAGMA_DIAG_POP
166166
int err; \
167167
err = subsystem_file_line_contents(subsystem, \
168168
filename, \
169-
NULL, \
169+
nullptr, \
170170
scan_fmt, \
171171
&variable); \
172172
if (err != 0) { \
@@ -184,11 +184,11 @@ PRAGMA_DIAG_POP
184184
int err; \
185185
err = subsystem_file_line_contents(subsystem, \
186186
filename, \
187-
NULL, \
187+
nullptr, \
188188
scan_fmt, \
189189
variable); \
190190
if (err != 0) \
191-
return (return_type) NULL; \
191+
return (return_type) nullptr; \
192192
\
193193
log_trace(os, container)(logstring, variable); \
194194
}
@@ -293,13 +293,13 @@ class CgroupInfo : public StackObj {
293293

294294
public:
295295
CgroupInfo() {
296-
_name = NULL;
296+
_name = nullptr;
297297
_hierarchy_id = -1;
298298
_enabled = false;
299299
_data_complete = false;
300-
_cgroup_path = NULL;
301-
_root_mount_path = NULL;
302-
_mount_path = NULL;
300+
_cgroup_path = nullptr;
301+
_root_mount_path = nullptr;
302+
_mount_path = nullptr;
303303
}
304304

305305
};

src/hotspot/os/linux/cgroupV1Subsystem_linux.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2019, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -39,7 +39,7 @@
3939
*/
4040
void CgroupV1Controller::set_subsystem_path(char *cgroup_path) {
4141
stringStream ss;
42-
if (_root != NULL && cgroup_path != NULL) {
42+
if (_root != nullptr && cgroup_path != nullptr) {
4343
if (strcmp(_root, "/") == 0) {
4444
ss.print_raw(_mount_point);
4545
if (strcmp(cgroup_path,"/") != 0) {
@@ -52,7 +52,7 @@ void CgroupV1Controller::set_subsystem_path(char *cgroup_path) {
5252
_path = os::strdup(ss.base());
5353
} else {
5454
char *p = strstr(cgroup_path, _root);
55-
if (p != NULL && p == _root) {
55+
if (p != nullptr && p == _root) {
5656
if (strlen(cgroup_path) > strlen(_root)) {
5757
ss.print_raw(_mount_point);
5858
const char* cg_path_sub = cgroup_path + strlen(_root);
@@ -297,7 +297,7 @@ char* CgroupV1Subsystem::pids_max_val() {
297297
* OSCONTAINER_ERROR for not supported
298298
*/
299299
jlong CgroupV1Subsystem::pids_max() {
300-
if (_pids == NULL) return OSCONTAINER_ERROR;
300+
if (_pids == nullptr) return OSCONTAINER_ERROR;
301301
char * pidsmax_str = pids_max_val();
302302
return limit_from_str(pidsmax_str);
303303
}
@@ -311,7 +311,7 @@ jlong CgroupV1Subsystem::pids_max() {
311311
* OSCONTAINER_ERROR for not supported
312312
*/
313313
jlong CgroupV1Subsystem::pids_current() {
314-
if (_pids == NULL) return OSCONTAINER_ERROR;
314+
if (_pids == nullptr) return OSCONTAINER_ERROR;
315315
GET_CONTAINER_INFO(jlong, _pids, "/pids.current",
316316
"Current number of tasks is: " JLONG_FORMAT, JLONG_FORMAT, pids_current);
317317
return pids_current;

0 commit comments

Comments
 (0)