Skip to content

Commit bd5ca95

Browse files
committed
8300222: Replace NULL with nullptr in share/logging
Reviewed-by: coleenp, dholmes
1 parent 15a9186 commit bd5ca95

24 files changed

+144
-144
lines changed

src/hotspot/share/logging/log.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 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
@@ -164,7 +164,7 @@ class LogImpl {
164164
return is_level(LogLevel::level); \
165165
} \
166166
static LogTargetImpl<LogLevel::level, T0, T1, T2, T3, T4, GuardTag>* name() { \
167-
return (LogTargetImpl<LogLevel::level, T0, T1, T2, T3, T4, GuardTag>*)NULL; \
167+
return (LogTargetImpl<LogLevel::level, T0, T1, T2, T3, T4, GuardTag>*)nullptr; \
168168
}
169169
LOG_LEVEL_LIST
170170
#undef LOG_LEVEL

src/hotspot/share/logging/logAsyncWriter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,10 @@ void AsyncLogWriter::initialize() {
192192
AsyncLogWriter* self = new AsyncLogWriter();
193193
if (self->_initialized) {
194194
Atomic::release_store_fence(&AsyncLogWriter::_instance, self);
195-
// All readers of _instance after the fence see non-NULL.
195+
// All readers of _instance after the fence see non-nullptr.
196196
// We use LogOutputList's RCU counters to ensure all synchronous logsites have completed.
197197
// After that, we start AsyncLog Thread and it exclusively takes over all logging I/O.
198-
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
198+
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) {
199199
ts->wait_until_no_readers();
200200
}
201201
os::start_thread(self);

src/hotspot/share/logging/logConfiguration.cpp

+32-32
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 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
@@ -40,10 +40,10 @@
4040
#include "runtime/semaphore.hpp"
4141
#include "utilities/globalDefinitions.hpp"
4242

43-
LogOutput** LogConfiguration::_outputs = NULL;
43+
LogOutput** LogConfiguration::_outputs = nullptr;
4444
size_t LogConfiguration::_n_outputs = 0;
4545

46-
LogConfiguration::UpdateListenerFunction* LogConfiguration::_listener_callbacks = NULL;
46+
LogConfiguration::UpdateListenerFunction* LogConfiguration::_listener_callbacks = nullptr;
4747
size_t LogConfiguration::_n_listener_callbacks = 0;
4848

4949
// LogFileOutput is the default type of output, its type prefix should be used if no type was specified
@@ -105,7 +105,7 @@ void LogConfiguration::initialize(jlong vm_start_time) {
105105
StdoutLog = new LogStdoutOutput();
106106
StderrLog = new LogStderrOutput();
107107
LogFileOutput::set_file_name_parameters(vm_start_time);
108-
assert(_outputs == NULL, "Should not initialize _outputs before this function, initialize called twice?");
108+
assert(_outputs == nullptr, "Should not initialize _outputs before this function, initialize called twice?");
109109
_outputs = NEW_C_HEAP_ARRAY(LogOutput*, 2, mtLogging);
110110
_outputs[0] = StdoutLog;
111111
_outputs[1] = StderrLog;
@@ -114,7 +114,7 @@ void LogConfiguration::initialize(jlong vm_start_time) {
114114
_outputs[1]->set_config_string("all=off");
115115

116116
// Set the default output to warning and error level for all new tagsets.
117-
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
117+
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) {
118118
ts->set_output_level(StdoutLog, LogLevel::Default);
119119
}
120120
}
@@ -129,18 +129,18 @@ void LogConfiguration::finalize() {
129129
static bool normalize_output_name(const char* full_name, char* buffer, size_t len, outputStream* errstream) {
130130
const char* start_quote = strchr(full_name, '"');
131131
const char* equals = strchr(full_name, '=');
132-
const bool quoted = start_quote != NULL;
132+
const bool quoted = start_quote != nullptr;
133133
const bool is_stdout_or_stderr = (strcmp(full_name, "stdout") == 0 || strcmp(full_name, "stderr") == 0);
134134

135135
// ignore equals sign within quotes
136136
if (quoted && equals > start_quote) {
137-
equals = NULL;
137+
equals = nullptr;
138138
}
139139

140140
const char* prefix = "";
141141
size_t prefix_len = 0;
142142
const char* name = full_name;
143-
if (equals != NULL) {
143+
if (equals != nullptr) {
144144
// split on equals sign
145145
name = equals + 1;
146146
prefix = full_name;
@@ -153,7 +153,7 @@ static bool normalize_output_name(const char* full_name, char* buffer, size_t le
153153

154154
if (quoted) {
155155
const char* end_quote = strchr(start_quote + 1, '"');
156-
if (end_quote == NULL) {
156+
if (end_quote == nullptr) {
157157
errstream->print_cr("Output name has opening quote but is missing a terminating quote.");
158158
return false;
159159
}
@@ -190,14 +190,14 @@ LogOutput* LogConfiguration::new_output(const char* name,
190190
output = new LogFileOutput(name);
191191
} else {
192192
errstream->print_cr("Unsupported log output type: %s", name);
193-
return NULL;
193+
return nullptr;
194194
}
195195

196196
bool success = output->initialize(options, errstream);
197197
if (!success) {
198198
errstream->print_cr("Initialization of output '%s' using options '%s' failed.", name, options);
199199
delete output;
200-
return NULL;
200+
return nullptr;
201201
}
202202
return output;
203203
}
@@ -245,7 +245,7 @@ void LogConfiguration::configure_output(size_t idx, const LogSelectionList& sele
245245
size_t on_level[LogLevel::Count] = {0};
246246

247247
bool enabled = false;
248-
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
248+
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) {
249249
LogLevelType level = selections.level_for(*ts);
250250

251251
// Ignore tagsets that do not, and will not log on the output
@@ -285,7 +285,7 @@ void LogConfiguration::configure_output(size_t idx, const LogSelectionList& sele
285285
output->set_decorators(decorators);
286286

287287
// Update the decorators on all tagsets to get rid of unused decorators
288-
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
288+
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) {
289289
ts->update_decorators();
290290
}
291291

@@ -303,7 +303,7 @@ void LogConfiguration::disable_outputs() {
303303
size_t idx = _n_outputs;
304304

305305
// Remove all outputs from all tagsets.
306-
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
306+
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) {
307307
ts->disable_outputs();
308308
}
309309

@@ -328,7 +328,7 @@ void LogConfiguration::disable_logging() {
328328
ConfigurationLock cl;
329329
disable_outputs();
330330
// Update the decorators on all tagsets to get rid of unused decorators
331-
for (LogTagSet* ts = LogTagSet::first(); ts != NULL; ts = ts->next()) {
331+
for (LogTagSet* ts = LogTagSet::first(); ts != nullptr; ts = ts->next()) {
332332
ts->update_decorators();
333333
}
334334
notify_update_listeners();
@@ -376,15 +376,15 @@ bool LogConfiguration::parse_command_line_arguments(const char* opts) {
376376
#ifdef _WINDOWS
377377
// Skip over Windows paths such as "C:\..." and "C:/...".
378378
// Handles both "C:\..." and "file=C:\...".
379-
if (next != NULL && next[0] == ':' && (next[1] == '\\' || next[1] == '/')) {
379+
if (next != nullptr && next[0] == ':' && (next[1] == '\\' || next[1] == '/')) {
380380
if (next == str + 1 || (strncmp(str, "file=", 5) == 0)) {
381381
next = strpbrk(next + 1, ":\"");
382382
}
383383
}
384384
#endif
385-
while (next != NULL && *next == '"') {
385+
while (next != nullptr && *next == '"') {
386386
char* end_quote = strchr(next + 1, '"');
387-
if (end_quote == NULL) {
387+
if (end_quote == nullptr) {
388388
log_error(logging)("Missing terminating quote in -Xlog option '%s'", str);
389389
os::free(copy);
390390
return false;
@@ -393,16 +393,16 @@ bool LogConfiguration::parse_command_line_arguments(const char* opts) {
393393
next = strpbrk(end_quote + 1, ":\"");
394394
}
395395

396-
if (next != NULL) {
396+
if (next != nullptr) {
397397
*next = '\0';
398398
str = next + 1;
399399
} else {
400-
str = NULL;
400+
str = nullptr;
401401
break;
402402
}
403403
}
404404

405-
if (str != NULL) {
405+
if (str != nullptr) {
406406
log_warning(logging)("Ignoring excess -Xlog options: \"%s\"", str);
407407
}
408408

@@ -423,13 +423,13 @@ bool LogConfiguration::parse_command_line_arguments(const char* opts) {
423423
// (parse_log_arguments() will report an error), but we make an exception for
424424
// both StdoutLog and StderrLog as they're initialized automatically
425425
// very early in the boot process.
426-
if (output == NULL || strlen(output) == 0 ||
426+
if (output == nullptr || strlen(output) == 0 ||
427427
strcmp("stdout", output) == 0 || strcmp("#0", output) == 0) {
428428
if (!stdout_configured) {
429429
success = StdoutLog->parse_options(output_options, &ss);
430430
stdout_configured = true;
431431
// We no longer need to pass output options to parse_log_arguments().
432-
output_options = NULL;
432+
output_options = nullptr;
433433
}
434434
// else - fall-through to normal option processing which will be rejected
435435
// with a warning
@@ -438,7 +438,7 @@ bool LogConfiguration::parse_command_line_arguments(const char* opts) {
438438
success = StderrLog->parse_options(output_options, &ss);
439439
stderr_configured = true;
440440
// We no longer need to pass output options to parse_log_arguments().
441-
output_options = NULL;
441+
output_options = nullptr;
442442
}
443443
// else - fall-through to normal option processing which will be rejected
444444
// with a warning
@@ -456,7 +456,7 @@ bool LogConfiguration::parse_command_line_arguments(const char* opts) {
456456
Log(logging) log;
457457
char* start = errbuf;
458458
char* end = strchr(start, '\n');
459-
assert(end != NULL, "line must end with newline '%s'", start);
459+
assert(end != nullptr, "line must end with newline '%s'", start);
460460
do {
461461
assert(start < errbuf + sizeof(errbuf) &&
462462
end < errbuf + sizeof(errbuf),
@@ -465,8 +465,8 @@ bool LogConfiguration::parse_command_line_arguments(const char* opts) {
465465
log.write(level, "%s", start);
466466
start = end + 1;
467467
end = strchr(start, '\n');
468-
assert(end != NULL || *start == '\0', "line must end with newline '%s'", start);
469-
} while (end != NULL);
468+
assert(end != nullptr || *start == '\0', "line must end with newline '%s'", start);
469+
} while (end != nullptr);
470470
}
471471

472472
os::free(copy);
@@ -478,8 +478,8 @@ bool LogConfiguration::parse_log_arguments(const char* outputstr,
478478
const char* decoratorstr,
479479
const char* output_options,
480480
outputStream* errstream) {
481-
assert(errstream != NULL, "errstream can not be NULL");
482-
if (outputstr == NULL || strlen(outputstr) == 0) {
481+
assert(errstream != nullptr, "errstream can not be nullptr");
482+
if (outputstr == nullptr || strlen(outputstr) == 0) {
483483
outputstr = "stdout";
484484
}
485485

@@ -514,7 +514,7 @@ bool LogConfiguration::parse_log_arguments(const char* outputstr,
514514
if (idx == SIZE_MAX) {
515515
// Attempt to create and add the output
516516
LogOutput* output = new_output(normalized, output_options, errstream);
517-
if (output != NULL) {
517+
if (output != nullptr) {
518518
idx = add_output(output);
519519
added = true;
520520
}
@@ -525,7 +525,7 @@ bool LogConfiguration::parse_log_arguments(const char* outputstr,
525525
return false;
526526
}
527527
}
528-
if (!added && output_options != NULL && strlen(output_options) > 0) {
528+
if (!added && output_options != nullptr && strlen(output_options) > 0) {
529529
errstream->print_cr("Output options for existing outputs are ignored.");
530530
}
531531
configure_output(idx, selections, decorators);
@@ -690,7 +690,7 @@ void LogConfiguration::rotate_all_outputs() {
690690
}
691691

692692
void LogConfiguration::register_update_listener(UpdateListenerFunction cb) {
693-
assert(cb != NULL, "Should not register NULL as listener");
693+
assert(cb != nullptr, "Should not register nullptr as listener");
694694
ConfigurationLock cl;
695695
size_t idx = _n_listener_callbacks++;
696696
_listener_callbacks = REALLOC_C_HEAP_ARRAY(UpdateListenerFunction,

src/hotspot/share/logging/logConfiguration.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 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
@@ -61,7 +61,7 @@ class LogConfiguration : public AllStatic {
6161
static size_t _n_listener_callbacks;
6262
static bool _async_mode;
6363

64-
// Create a new output. Returns NULL if failed.
64+
// Create a new output. Returns nullptr if failed.
6565
static LogOutput* new_output(const char* name, const char* options, outputStream* errstream);
6666

6767
// Add an output to the list of configured outputs. Returns the assigned index.

src/hotspot/share/logging/logDecorations.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 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
@@ -30,17 +30,17 @@
3030
#include "runtime/os.hpp"
3131
#include "services/management.hpp"
3232

33-
const char* volatile LogDecorations::_host_name = NULL;
33+
const char* volatile LogDecorations::_host_name = nullptr;
3434
const int LogDecorations::_pid = os::current_process_id(); // This is safe to call during dynamic initialization.
3535

3636
const char* LogDecorations::host_name() {
3737
const char* host_name = Atomic::load_acquire(&_host_name);
38-
if (host_name == NULL) {
38+
if (host_name == nullptr) {
3939
char buffer[1024];
4040
if (os::get_host_name(buffer, sizeof(buffer))) {
4141
host_name = os::strdup_check_oom(buffer);
42-
const char* old_value = Atomic::cmpxchg(&_host_name, (const char*)NULL, host_name);
43-
if (old_value != NULL) {
42+
const char* old_value = Atomic::cmpxchg(&_host_name, (const char*)nullptr, host_name);
43+
if (old_value != nullptr) {
4444
os::free((void *) host_name);
4545
host_name = old_value;
4646
}

src/hotspot/share/logging/logDecorators.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 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
@@ -56,7 +56,7 @@ LogDecorators::Decorator LogDecorators::from_string(const char* str) {
5656
}
5757

5858
bool LogDecorators::parse(const char* decorator_args, outputStream* errstream) {
59-
if (decorator_args == NULL || strlen(decorator_args) == 0) {
59+
if (decorator_args == nullptr || strlen(decorator_args) == 0) {
6060
_decorators = DefaultDecoratorsMask;
6161
return true;
6262
}
@@ -73,20 +73,20 @@ bool LogDecorators::parse(const char* decorator_args, outputStream* errstream) {
7373
char* comma_pos;
7474
do {
7575
comma_pos = strchr(token, ',');
76-
if (comma_pos != NULL) {
76+
if (comma_pos != nullptr) {
7777
*comma_pos = '\0';
7878
}
7979
Decorator d = from_string(token);
8080
if (d == Invalid) {
81-
if (errstream != NULL) {
81+
if (errstream != nullptr) {
8282
errstream->print_cr("Invalid decorator '%s'.", token);
8383
}
8484
result = false;
8585
break;
8686
}
8787
tmp_decorators |= mask(d);
8888
token = comma_pos + 1;
89-
} while (comma_pos != NULL);
89+
} while (comma_pos != nullptr);
9090
os::free(args_copy);
9191
if (result) {
9292
_decorators = tmp_decorators;

src/hotspot/share/logging/logDecorators.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 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
@@ -113,7 +113,7 @@ class LogDecorators {
113113
return (_decorators & mask(decorator)) != 0;
114114
}
115115

116-
bool parse(const char* decorator_args, outputStream* errstream = NULL);
116+
bool parse(const char* decorator_args, outputStream* errstream = nullptr);
117117
};
118118

119119
#endif // SHARE_LOGGING_LOGDECORATORS_HPP

src/hotspot/share/logging/logDiagnosticCommand.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 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
@@ -47,8 +47,8 @@ LogDiagnosticCommand::LogDiagnosticCommand(outputStream* output, bool heap_alloc
4747

4848
int LogDiagnosticCommand::num_arguments() {
4949
ResourceMark rm;
50-
LogDiagnosticCommand* dcmd = new LogDiagnosticCommand(NULL, false);
51-
if (dcmd != NULL) {
50+
LogDiagnosticCommand* dcmd = new LogDiagnosticCommand(nullptr, false);
51+
if (dcmd != nullptr) {
5252
DCmdMark mark(dcmd);
5353
return dcmd->_dcmdparser.num_arguments();
5454
} else {

0 commit comments

Comments
 (0)