Encapsulate AllocKind range checks in a few functions

RESOLVED FIXED in Firefox 39

Status

()

RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: ehoogeveen, Assigned: ehoogeveen)

Tracking

Trunk
mozilla39
Points:
---

Firefox Tracking Flags

(firefox39 fixed)

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Assignee)

Description

4 years ago
With all the range-based for loops in place we barely use specific AllocKinds directly anymore except to set a variable or pass into a function. The notable exceptions to this are the various assertions and other range checks we have scattered around to ensure that we're not holding on to some invalid AllocKind.
(Assignee)

Comment 1

4 years ago
Created attachment 8584185 [details] [diff] [review]
Replace manual AllocKind range checks with a few centralized functions.

I went with IsValidAllocKind() for the common check of |< AllocKind::LIMIT|, and IsAllocKind() for the less common |<= AllocKind::LIMIT|. AllocKind::LIMIT is obviously a 'valid' AllocKind in some sense, but where we allow it at all, we use it to mean 'not allocated' or 'not initialized'. I put IsValidAllocKind() higher up in Heap.h so people will hopefully see it first and consider which variant they want.

As for the implementation, I chose to go with >= and <= everywhere for consistency, and added back the |>= AllocKind::FIRST| and |>= AllocKind::OBJECT0| parts. Now that the underlying type of AllocKind is |int| again, it makes sense to check for negative values.
Attachment #8584185 - Flags: review?(terrence)
(Assignee)

Comment 2

4 years ago
This only depends on bug 1146662 in that it touches the same code, and has to land after that bug.

I did change the assertions in SomeAllocKinds() a bit - checking |first| to make sure it isn't negative, and removing the |first <= limit| check since MakeEnumeratedRange already has an assertion for that.
Depends on: 1146662
Comment on attachment 8584185 [details] [diff] [review]
Replace manual AllocKind range checks with a few centralized functions.

Review of attachment 8584185 [details] [diff] [review]:
-----------------------------------------------------------------

Very nice!
Attachment #8584185 - Flags: review?(terrence) → review+
(Assignee)

Updated

4 years ago
Keywords: checkin-needed
(Assignee)

Comment 5

4 years ago
Created attachment 8585047 [details] [diff] [review]
v1.1 - Replace manual AllocKind range checks with a few centralized functions.

Carrying forward r=terrence. The mass SM restyle meant this needed some rebasing.
Attachment #8584185 - Attachment is obsolete: true
Attachment #8585047 - Flags: review+
Attachment #8585047 - Attachment is obsolete: true
Comment on attachment 8584185 [details] [diff] [review]
Replace manual AllocKind range checks with a few centralized functions.

The SM restyle got backed out.
Attachment #8584185 - Attachment is obsolete: false
(Assignee)

Comment 8

4 years ago
Thanks for landing the right one for me, Ryan!
https://hg.mozilla.org/mozilla-central/rev/db80ac5a48aa
Status: ASSIGNED → RESOLVED
Last Resolved: 4 years ago
status-firefox39: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla39
You need to log in before you can comment on or make changes to this bug.