Skip to content

JDK-8301493: Replace NULL with nullptr in cpu/aarch64 #12321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from

Conversation

jdksjolen
Copy link
Contributor

@jdksjolen jdksjolen commented Jan 31, 2023

Hi, this PR changes all occurrences of NULL to nullptr for the subdirectory cpu/aarch64. Unfortunately the script that does the change isn't perfect, and so we
need to comb through these manually to make sure nothing has gone wrong. I also review these changes but things slip past my eyes sometimes.

Here are some typical things to look out for:

  1. No changes but copyright header changed (probably because I reverted some changes but forgot the copyright).
  2. Macros having their NULL changed to nullptr, these are added to the script when I find them. They should be NULL.
  3. nullptr in comments and logs. We try to use lower case "null" in these cases as it reads better. An exception is made when code expressions are in a comment.

An example of this:

// This function returns null
void* ret_null();
// This function returns true if *x == nullptr
bool is_nullptr(void** x);

Note how nullptr participates in a code expression here, we really are talking about the specific value nullptr.

Thanks!


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8301493: Replace NULL with nullptr in cpu/aarch64

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/12321/head:pull/12321
$ git checkout pull/12321

Update a local copy of the PR:
$ git checkout pull/12321
$ git pull https://git.openjdk.org/jdk.git pull/12321/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 12321

View PR using the GUI difftool:
$ git pr show -t 12321

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12321.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 31, 2023

👋 Welcome back jsjolen! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jan 31, 2023

@jdksjolen The following labels will be automatically applied to this pull request:

  • hotspot
  • shenandoah

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added hotspot hotspot-dev@openjdk.org shenandoah shenandoah-dev@openjdk.org labels Jan 31, 2023
Copy link
Contributor Author

@jdksjolen jdksjolen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some simple fixes here

@@ -171,13 +171,13 @@ inline frame::frame(intptr_t* sp, intptr_t* fp) {
// call a specilaized frame constructor instead of this one.
// Then we could use the assert below. However this assert is of somewhat dubious
// value.
// assert(_pc != NULL, "no pc?");
// assert(_pc != null, "no pc?");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

@@ -159,7 +159,7 @@ void G1BarrierSetAssembler::g1_write_barrier_pre(MacroAssembler* masm,

// Calling the runtime using the regular call_VM_leaf mechanism generates
// code (generated by InterpreterMacroAssember::call_VM_leaf_base)
// that checks that the *(rfp+frame::interpreter_frame_last_sp) == NULL.
// that checks that the *(rfp+frame::interpreter_frame_last_sp) == null.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

@@ -157,7 +157,7 @@ void ShenandoahBarrierSetAssembler::satb_write_barrier_pre(MacroAssembler* masm,

// Calling the runtime using the regular call_VM_leaf mechanism generates
// code (generated by InterpreterMacroAssember::call_VM_leaf_base)
// that checks that the *(rfp+frame::interpreter_frame_last_sp) == NULL.
// that checks that the *(rfp+frame::interpreter_frame_last_sp) == null.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

@@ -47,7 +47,7 @@ void InlineCacheBuffer::assemble_ic_buffer_code(address code_begin, void* cached
// because
// (1) the value is old (i.e., doesn't matter for scavenges)
// (2) these ICStubs are removed *before* a GC happens, so the roots disappear
// assert(cached_value == NULL || cached_oop->is_perm(), "must be perm oop");
// assert(cached_value == null || cached_oop->is_perm(), "must be perm oop");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

@@ -140,7 +140,7 @@ void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread)
if (JvmtiExport::can_force_early_return()) {
Label L;
ldr(rscratch1, Address(rthread, JavaThread::jvmti_thread_state_offset()));
cbz(rscratch1, L); // if (thread->jvmti_thread_state() == NULL) exit;
cbz(rscratch1, L); // if (thread->jvmti_thread_state() == null) exit;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

@@ -1155,7 +1155,7 @@ void MacroAssembler::lookup_interface_method(Register recv_klass,
add(recv_klass, recv_klass, itentry_off);
}

// for (scan = klass->itable(); scan->interface() != NULL; scan += scan_step) {
// for (scan = klass->itable(); scan->interface() != null; scan += scan_step) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

@@ -4788,15 +4788,15 @@ address MacroAssembler::arrays_equals(Register a1, Register a2, Register tmp3,
br(EQ, SAME);

if (UseSimpleArrayEquals) {
Label NEXT_WORD, SHORT, TAIL03, TAIL01, A_MIGHT_BE_NULL, A_IS_NOT_NULL;
Label NEXT_WORD, SHORT, TAIL03, TAIL01, A_MIGHT_BE_nullptr, A_IS_NOT_NULL;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this macro

Comment on lines 2053 to 2059
// if (src == NULL) return -1;
// if (src == null) return -1;
__ cbz(src, L_failed);

// if (src_pos < 0) return -1;
__ tbnz(src_pos, 31, L_failed); // i.e. sign bit set

// if (dst == NULL) return -1;
// if (dst == null) return -1;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

Comment on lines 2076 to 2077
// assert(src->klass() != NULL);
// assert(src->klass() != null);
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

@@ -3694,8 +3694,8 @@ void TemplateTable::instanceof() {
__ bind(is_null); // same as 'done'
}
__ bind(done);
// r0 = 0: obj == NULL or obj is not an instanceof the specified klass
// r0 = 1: obj != NULL and obj is an instanceof the specified klass
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullptr

@jdksjolen jdksjolen marked this pull request as ready for review February 6, 2023 10:17
@openjdk openjdk bot added the rfr Pull request is ready for review label Feb 6, 2023
@mlbridge
Copy link

mlbridge bot commented Feb 6, 2023

Webrevs

@openjdk
Copy link

openjdk bot commented Feb 17, 2023

@jdksjolen this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout JDK-8301493
git fetch https://git.openjdk.org/jdk master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Feb 17, 2023
@bridgekeeper
Copy link

bridgekeeper bot commented Mar 17, 2023

@jdksjolen This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@jdksjolen
Copy link
Contributor Author

Not yet.

@stooart-mon
Copy link
Contributor

This looks OK so far.
However, is it your intention to also do aarch64.ad?
aarch64_ad.m4 and aarch64_vector(.ad|_ad.m4) files look clean.

@@ -267,7 +267,7 @@ class SlowSignatureHandler

virtual void pass_object() {
intptr_t* addr = single_slot_addr();
intptr_t value = *addr == 0 ? NULL : (intptr_t)addr;
intptr_t value = *addr == 0 ? nullptr : (intptr_t)addr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't compile - perhaps replace nullptr with zero? Unless casting it is more appropriate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's similar code in other patches, I did casting in those.

@openjdk openjdk bot removed the rfr Pull request is ready for review label Apr 3, 2023
@openjdk openjdk bot removed the merge-conflict Pull request has merge conflict with target branch label Apr 11, 2023
@jdksjolen
Copy link
Contributor Author

This looks OK so far. However, is it your intention to also do aarch64.ad? aarch64_ad.m4 and aarch64_vector(.ad|_ad.m4) files look clean.

I'm only touching the .cpp/.hpp files in these PRs. The NULL count of all .ad files is only 339, so if I do those it'll all be in one commit (probably).

@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 11, 2023
@jdksjolen
Copy link
Contributor Author

Hi @stooart-mon , would you be interested in approving this :)? Thanks!

@stooart-mon
Copy link
Contributor

As I'm only an author, I can't sponsor this patch, but it looks OK to me. It is consistent with the NULL->nullptr changes you have been doing elsewhere.

There might always be this problem, but there are some missing instances NULL that may have appeared since you started this - I've listed them below.

codeBuffer_aarch64.cpp:  if (cb->stubs()->maybe_expand_to_ensure_remaining(total_requested_size) && cb->blob() == NULL) {
gc/shared/barrierSetAssembler_aarch64.cpp:  __ cbz(obj, error);      // if klass is NULL it is broken
stubGenerator_aarch64.cpp:    if (bs_nm != NULL) {
vm_version_aarch64.cpp:    if (virt2 != NULL && strcasestr(line, virt2) != 0) {
vm_version_aarch64.cpp:  check_info_file(tname_file, "Xen", XenPVHVM, NULL, NoDetectedVirtualization);

Copy link
Contributor

@tschatzl tschatzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining NULL in

gc/shared/BarrierSetAssembler::check_oop()
codeBuffer_aarch64.cpp/emit_shared_trampolines()
stubGenerator_aarch64.cpp/generate_final_stubs()
vm_version_aarch64.cpp/check_info_file()

Copy link

@gerard-ziemski gerard-ziemski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only looked at the changes that you did make, not what you could have done and it LGTM.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - thanks!

Three minor suggested changes and three opportunities to remove casts (that I spotted).

@@ -29,7 +29,7 @@
void ICacheStubGenerator::generate_icache_flush(
ICache::flush_icache_stub_t* flush_icache_stub) {
// Give anyone who calls this a surprise
*flush_icache_stub = (ICache::flush_icache_stub_t)NULL;
*flush_icache_stub = (ICache::flush_icache_stub_t)nullptr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully don't need the cast any more.

@@ -267,7 +267,7 @@ class SlowSignatureHandler

virtual void pass_object() {
intptr_t* addr = single_slot_addr();
intptr_t value = *addr == 0 ? NULL : (intptr_t)addr;
intptr_t value = *addr == 0 ? (intptr_t)nullptr : (intptr_t)addr;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it should be using 0 (zero) not NULL/nullptr?

@@ -968,7 +968,7 @@ void MacroAssembler::emit_static_call_stub() {
// exact layout of this stub.

isb();
mov_metadata(rmethod, (Metadata*)NULL);
mov_metadata(rmethod, (Metadata*)nullptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need cast any more.

@@ -1639,13 +1639,13 @@ void MacroAssembler::super_call_VM_leaf(address entry_point, Register arg_0, Reg

void MacroAssembler::null_check(Register reg, int offset) {
if (needs_explicit_null_check(offset)) {
// provoke OS NULL exception if reg = NULL by
// provoke OS null exception if reg = null by
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest reg is null

// accessing M[reg] w/o changing any registers
// NOTE: this is plenty to provoke a segv
ldr(zr, Address(reg));
} else {
// nothing to do, (later) access of M[reg + offset]
// will provoke OS NULL exception if reg = NULL
// will provoke OS null exception if reg = null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest reg is null

@@ -1421,10 +1421,10 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
stack_slots / VMRegImpl::slots_per_word,
in_ByteSize(-1),
in_ByteSize(-1),
(OopMapSet*)NULL);
(OopMapSet*)nullptr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need cast any more

@openjdk
Copy link

openjdk bot commented May 4, 2023

@jdksjolen This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8301493: Replace NULL with nullptr in cpu/aarch64

Reviewed-by: tschatzl, gziemski, dholmes

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 341 new commits pushed to the master branch:

  • e19cf26: 8307196: Dangling pointer warning for MetadataAllocationRequest
  • 1b143ba: 8307378: Allow collectors to provide specific values for GC notifications' actions
  • a44e890: 8307308: Add serviceability_ttf_virtual group to exclude jvmti tests developed for virtual threads
  • 46df171: 8304948: [vectorapi] C2 crashes when expanding VectorBox
  • 111858f: 8307489: ProblemList jdk/incubator/vector/LoadJsvmlTest.java on windows-x64
  • 197d0cc: 8294983: SSLEngine throws ClassCastException during handshake
  • a87262e: 8307295: Add warning to not create new ACC flags
  • 0c6529d: 8307156: native_thread not protected by TLH
  • 5ca0b08: 8307133: Open source some JTable jtreg tests
  • 2adb3b4: 8306943: Open source several dnd AWT tests
  • ... and 331 more: https://git.openjdk.org/jdk/compare/cd7d53c88c27eedbe16020b88c2219708d170a1e...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 4, 2023
@jdksjolen
Copy link
Contributor Author

Thanks @tschatzl, probably new code from when I merged that didn't get a conflict. I did a grep for NULL and checked that no more occurrences are in the code. Running tier1 testing.

Copy link
Contributor

@tschatzl tschatzl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm.

@jdksjolen
Copy link
Contributor Author

Alright, tier1 looks good. Integrating. Thank you for the reviews, good people.

/integrate

@openjdk
Copy link

openjdk bot commented May 5, 2023

Going to push as commit 948f3b3.
Since your change was applied there have been 343 commits pushed to the master branch:

  • f94f957: 8307331: Correctly update line maps when class redefine rewrites bytecodes
  • 302bc2f: 8307421: Fix comment in g1CollectionSetChooser.hpp after JDK-8306836
  • e19cf26: 8307196: Dangling pointer warning for MetadataAllocationRequest
  • 1b143ba: 8307378: Allow collectors to provide specific values for GC notifications' actions
  • a44e890: 8307308: Add serviceability_ttf_virtual group to exclude jvmti tests developed for virtual threads
  • 46df171: 8304948: [vectorapi] C2 crashes when expanding VectorBox
  • 111858f: 8307489: ProblemList jdk/incubator/vector/LoadJsvmlTest.java on windows-x64
  • 197d0cc: 8294983: SSLEngine throws ClassCastException during handshake
  • a87262e: 8307295: Add warning to not create new ACC flags
  • 0c6529d: 8307156: native_thread not protected by TLH
  • ... and 333 more: https://git.openjdk.org/jdk/compare/cd7d53c88c27eedbe16020b88c2219708d170a1e...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label May 5, 2023
@openjdk openjdk bot closed this May 5, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 5, 2023
@openjdk
Copy link

openjdk bot commented May 5, 2023

@jdksjolen Pushed as commit 948f3b3.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated shenandoah shenandoah-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

5 participants