Bug 1178581 - Interning does not and should not imply infinite lifetime; r=sfink

This commit is contained in:
Terrence Cole
2015-06-30 07:58:31 -07:00
parent b865214844
commit 88f9bc5932
24 changed files with 115 additions and 122 deletions

View File

@@ -143,7 +143,7 @@ JSRuntime::initializeAtoms(JSContext* cx)
ImmutablePropertyNamePtr* names = reinterpret_cast<ImmutablePropertyNamePtr*>(commonNames);
for (size_t i = 0; i < ArrayLength(cachedNames); i++, names++) {
JSAtom* atom = Atomize(cx, cachedNames[i].str, cachedNames[i].length, InternAtom);
JSAtom* atom = Atomize(cx, cachedNames[i].str, cachedNames[i].length, PinAtom);
if (!atom)
return false;
names->init(atom->asPropertyName());
@@ -197,11 +197,11 @@ js::MarkAtoms(JSTracer* trc)
JSRuntime* rt = trc->runtime();
for (AtomSet::Enum e(rt->atoms()); !e.empty(); e.popFront()) {
const AtomStateEntry& entry = e.front();
if (!entry.isTagged())
if (!entry.isPinned())
continue;
JSAtom* atom = entry.asPtr();
bool tagged = entry.isTagged();
bool tagged = entry.isPinned();
TraceRoot(trc, &atom, "interned_atom");
if (entry.asPtr() != atom)
e.rekeyFront(AtomHasher::Lookup(atom), AtomStateEntry(atom, tagged));
@@ -257,7 +257,7 @@ JSRuntime::sweepAtoms()
bool isDying = IsAboutToBeFinalizedUnbarriered(&atom);
/* Pinned or interned key cannot be finalized. */
MOZ_ASSERT_IF(hasContexts() && entry.isTagged(), !isDying);
MOZ_ASSERT_IF(hasContexts() && entry.isPinned(), !isDying);
if (isDying)
e.removeFront();
@@ -289,7 +289,7 @@ JSRuntime::transformToPermanentAtoms(JSContext* cx)
}
bool
AtomIsInterned(JSContext* cx, JSAtom* atom)
AtomIsPinned(JSContext* cx, JSAtom* atom)
{
/* We treat static strings as interned because they're never collected. */
if (StaticStrings::isStatic(atom))
@@ -309,14 +309,14 @@ AtomIsInterned(JSContext* cx, JSAtom* atom)
if (!p)
return false;
return p->isTagged();
return p->isPinned();
}
/* |tbchars| must not point into an inline or short string. */
template <typename CharT>
MOZ_ALWAYS_INLINE
static JSAtom*
AtomizeAndCopyChars(ExclusiveContext* cx, const CharT* tbchars, size_t length, InternBehavior ib)
AtomizeAndCopyChars(ExclusiveContext* cx, const CharT* tbchars, size_t length, PinningBehavior pin)
{
if (JSAtom* s = cx->staticStrings().lookup(tbchars, length))
return s;
@@ -340,7 +340,7 @@ AtomizeAndCopyChars(ExclusiveContext* cx, const CharT* tbchars, size_t length, I
AtomSet::AddPtr p = atoms.lookupForAdd(lookup);
if (p) {
JSAtom* atom = p->asPtr();
p->setTagged(bool(ib));
p->setPinned(bool(pin));
return atom;
}
@@ -360,7 +360,7 @@ AtomizeAndCopyChars(ExclusiveContext* cx, const CharT* tbchars, size_t length, I
// We have held the lock since looking up p, and the operations we've done
// since then can't GC; therefore the atoms table has not been modified and
// p is still valid.
if (!atoms.add(p, AtomStateEntry(atom, bool(ib)))) {
if (!atoms.add(p, AtomStateEntry(atom, bool(pin)))) {
ReportOutOfMemory(cx); /* SystemAllocPolicy does not report OOM. */
return nullptr;
}
@@ -369,19 +369,19 @@ AtomizeAndCopyChars(ExclusiveContext* cx, const CharT* tbchars, size_t length, I
}
template JSAtom*
AtomizeAndCopyChars(ExclusiveContext* cx, const char16_t* tbchars, size_t length, InternBehavior ib);
AtomizeAndCopyChars(ExclusiveContext* cx, const char16_t* tbchars, size_t length, PinningBehavior pin);
template JSAtom*
AtomizeAndCopyChars(ExclusiveContext* cx, const Latin1Char* tbchars, size_t length, InternBehavior ib);
AtomizeAndCopyChars(ExclusiveContext* cx, const Latin1Char* tbchars, size_t length, PinningBehavior pin);
JSAtom*
js::AtomizeString(ExclusiveContext* cx, JSString* str,
js::InternBehavior ib /* = js::DoNotInternAtom */)
js::PinningBehavior pin /* = js::DoNotPinAtom */)
{
if (str->isAtom()) {
JSAtom& atom = str->asAtom();
/* N.B. static atoms are effectively always interned. */
if (ib != InternAtom || js::StaticStrings::isStatic(&atom))
if (pin != PinAtom || js::StaticStrings::isStatic(&atom))
return &atom;
AtomHasher::Lookup lookup(&atom);
@@ -397,8 +397,8 @@ js::AtomizeString(ExclusiveContext* cx, JSString* str,
p = cx->atoms().lookup(lookup);
MOZ_ASSERT(p); /* Non-static atom must exist in atom state set. */
MOZ_ASSERT(p->asPtr() == &atom);
MOZ_ASSERT(ib == InternAtom);
p->setTagged(bool(ib));
MOZ_ASSERT(pin == PinAtom);
p->setPinned(bool(pin));
return &atom;
}
@@ -408,12 +408,12 @@ js::AtomizeString(ExclusiveContext* cx, JSString* str,
JS::AutoCheckCannotGC nogc;
return linear->hasLatin1Chars()
? AtomizeAndCopyChars(cx, linear->latin1Chars(nogc), linear->length(), ib)
: AtomizeAndCopyChars(cx, linear->twoByteChars(nogc), linear->length(), ib);
? AtomizeAndCopyChars(cx, linear->latin1Chars(nogc), linear->length(), pin)
: AtomizeAndCopyChars(cx, linear->twoByteChars(nogc), linear->length(), pin);
}
JSAtom*
js::Atomize(ExclusiveContext* cx, const char* bytes, size_t length, InternBehavior ib)
js::Atomize(ExclusiveContext* cx, const char* bytes, size_t length, PinningBehavior pin)
{
CHECK_REQUEST(cx);
@@ -421,26 +421,26 @@ js::Atomize(ExclusiveContext* cx, const char* bytes, size_t length, InternBehavi
return nullptr;
const Latin1Char* chars = reinterpret_cast<const Latin1Char*>(bytes);
return AtomizeAndCopyChars(cx, chars, length, ib);
return AtomizeAndCopyChars(cx, chars, length, pin);
}
template <typename CharT>
JSAtom*
js::AtomizeChars(ExclusiveContext* cx, const CharT* chars, size_t length, InternBehavior ib)
js::AtomizeChars(ExclusiveContext* cx, const CharT* chars, size_t length, PinningBehavior pin)
{
CHECK_REQUEST(cx);
if (!JSString::validateLength(cx, length))
return nullptr;
return AtomizeAndCopyChars(cx, chars, length, ib);
return AtomizeAndCopyChars(cx, chars, length, pin);
}
template JSAtom*
js::AtomizeChars(ExclusiveContext* cx, const Latin1Char* chars, size_t length, InternBehavior ib);
js::AtomizeChars(ExclusiveContext* cx, const Latin1Char* chars, size_t length, PinningBehavior pin);
template JSAtom*
js::AtomizeChars(ExclusiveContext* cx, const char16_t* chars, size_t length, InternBehavior ib);
js::AtomizeChars(ExclusiveContext* cx, const char16_t* chars, size_t length, PinningBehavior pin);
bool
js::IndexToIdSlow(ExclusiveContext* cx, uint32_t index, MutableHandleId idp)