Skip to content
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

Add some more global operator new / delete overrides #4465

Merged
merged 3 commits into from
Feb 26, 2024

Conversation

asl
Copy link
Contributor

@asl asl commented Feb 25, 2024

  • Aligned new / delete
  • Nothrow variants

Note that the former is required if e.g. LLVM is used with P4C (for backend).

Some cleanups here as well

@asl asl requested review from vlstill and fruffy February 25, 2024 20:11
@asl asl added run-ubuntu18 Use this tag to trigger a Ubuntu-18 CI run. run-sanitizer Use this tag to run a Clang+Sanitzers CI run. labels Feb 25, 2024
Copy link
Collaborator

@fruffy fruffy left a comment

Choose a reason for hiding this comment

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

Tentative approval, will run P4Testgen with this and check whether I see any difference in memory usage.

@asl
Copy link
Contributor Author

asl commented Feb 26, 2024

Tentative approval, will run P4Testgen with this and check whether I see any difference in memory usage.

It shouldn't be. It's just a correctness thing.

@fruffy
Copy link
Collaborator

fruffy commented Feb 26, 2024

Tentative approval, will run P4Testgen with this and check whether I see any difference in memory usage.

It shouldn't be. It's just a correctness thing.

Yes, not expecting any differences, but it is sensitive to gc change since it is one of the few tools using the garbage collector over longer stretches of time.

@asl
Copy link
Contributor Author

asl commented Feb 26, 2024

Tentative approval, will run P4Testgen with this and check whether I see any difference in memory usage.

It shouldn't be. It's just a correctness thing.

Yes, not expecting any differences, but it is sensitive to gc change since it is one of the few tools using the garbage collector over longer stretches of time.

Right. You can just throw abort() there to see if there any use of these. Or maybe just printf :)

lib/gc.cpp Outdated
auto *rv = ::operator new(size, UseGC, 0, 0);
if (!rv && emergency_ptr && emergency_ptr + size < emergency_pool + sizeof(emergency_pool)) {
rv = emergency_ptr;
size += -size & 0xf; // align to 16 bytes
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not your code but this particular piece looks a little funky to me. I had to pause a bit to think what negating an unsigned means and what this is trying to do. Testing for the right behavior in case of a bad alloc seems tricky.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You'd just need to get used to calculate masks on-fly :) I changed this thing, is it more clear now?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, thanks for indulging me!

@asl asl enabled auto-merge February 26, 2024 16:18
@asl asl added this pull request to the merge queue Feb 26, 2024
Merged via the queue into p4lang:main with commit 11e3bf3 Feb 26, 2024
16 checks passed
@asl asl deleted the aligned-new-gc branch February 26, 2024 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-sanitizer Use this tag to run a Clang+Sanitzers CI run. run-ubuntu18 Use this tag to trigger a Ubuntu-18 CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants