Closed Bug 1046529 Opened 10 years ago Closed 10 years ago

Not all static atoms end up in gStaticAtomTable

Categories

(Core :: DOM: HTML Parser, defect)

x86_64
Linux
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla34

People

(Reporter: n.nethercote, Assigned: n.nethercote)

Details

Attachments

(3 files)

I found what I think is a bug with the static atoms table, and bz agrees.

When adding a new static atom, RegisterStaticAtoms() looks in the normal atoms table first. There are two cases.

(a) If the atom is already there, it is marked as permanent.

(b) Otherwise, RegisterStaticAtoms() installs (permanently) the new static atom in the normal atoms table, and also puts it in the static atoms table.

The bug is that in case (a), the "and also puts it in the static atoms table" step is missing. Which means that subsequent calls to NS_GetStaticAtom() with the corresponding string will fail.

It looks like the "and also puts it in the static atoms table" code should be moved below the if/else, so it always runs.

hsivonen, does this diagnosis and proposed fix sound correct to you?
Flags: needinfo?(hsivonen)
Here's a list of all the inserted static atoms, and whether it falls into case (a) or case (b). There are 1127 in case (a), which is the buggy one, and 2604 in case (b), which is the ok one.
Hmm... here's case (a):

>    if (he->mAtom) {
>      fprintf(stderr, "a\n");
>      if (!he->mAtom->IsPermanent()) {
>        // We wanted to create a static atom but there is already one there. So
>        // convert it to a non-refcounting permanent atom.
>        fprintf(stderr, "promote\n");
>        PromoteToPermanent(he->mAtom);
>      }
> 
>      *aAtoms[i].mAtom = he->mAtom;

The "We wanted to..." sub-case doesn't occur when I start Firefox. I think that explains why things aren't horribly broken -- most of those 1127 case (a) occurrences in the attachment must be re-insertions of static atoms.

Still, the possibility that a static atom doesn't get inserted in the static atoms table remains, and seems worth fixing.
Some preliminary clean-up: each of AtomTableKey's constructors has two modes:
one where |aHash| is an inparam, and one where it's an outparam. This is really
confusing, so this patch splits each one in two. This allows UpdateHashKey() to
be inline, which makes everything clearer.
Attachment #8465203 - Flags: review?(bzbarsky)
Assignee: nobody → n.nethercote
Status: NEW → ASSIGNED
With this change, atoms can be inserted multiple times into gStaticAtomTable,
but that's ok.
Attachment #8465204 - Flags: review?(hsivonen)
Attachment #8465204 - Flags: review?(bzbarsky)
Something that still leaves me uncomfortable is that "static atom" has two, subtly different meanings.

- The first meaning is the same as "permanent". I.e. IsStaticAtom() is the same as IsPermanent(). Both NS_NewPermanentAtom() and RegisterStaticAtoms() create static atoms with this meaning.

- The second meaning is narrower, and is implied by NS_GetStaticAtom(). Atoms registered with RegisterStaticAtoms() qualify, but those registered with NS_NewPermanentAtom() do not.
Comment on attachment 8465203 [details] [diff] [review]
(part 1) - Split and simplify AtomTableKey's constructors

r=me
Attachment #8465203 - Flags: review?(bzbarsky) → review+
Comment on attachment 8465204 [details] [diff] [review]
(part 2) - Ensure static atoms always end up in gStaticAtomTable

Seems reasonable.
Attachment #8465204 - Flags: review?(bzbarsky) → review+
Attachment #8465204 - Flags: review?(hsivonen) → review+
Flags: needinfo?(hsivonen)
(In reply to Nicholas Nethercote [:njn] from comment #0)
> hsivonen, does this diagnosis and proposed fix sound correct to you?

Yes, but I haven't worked with the static atom table on this level of detail. IIRC, sicking has.
https://hg.mozilla.org/mozilla-central/rev/5903b0f685fc
https://hg.mozilla.org/mozilla-central/rev/d9e21fe84c02
Status: ASSIGNED → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: