Bug 726429 - Handle GC during string table initialization (r=luke)

This commit is contained in:
Bill McCloskey 2012-02-23 14:34:06 -08:00
parent e81969c7a7
commit 9a4c1b313e
4 changed files with 37 additions and 13 deletions

View File

@ -67,6 +67,7 @@ CPPSRCS = \
testFuncCallback.cpp \ testFuncCallback.cpp \
testFunctionProperties.cpp \ testFunctionProperties.cpp \
testGCOutOfMemory.cpp \ testGCOutOfMemory.cpp \
testOOM.cpp \
testGetPropertyDefault.cpp \ testGetPropertyDefault.cpp \
testIndexToString.cpp \ testIndexToString.cpp \
testIntString.cpp \ testIntString.cpp \

View File

@ -0,0 +1,19 @@
#include "tests.h"
BEGIN_TEST(testOOM)
{
JSString *jsstr = JS_ValueToString(cx, INT_TO_JSVAL(9));
jsval tmp = STRING_TO_JSVAL(jsstr);
JS_SetProperty(cx, global, "rootme", &tmp);
const jschar *s = JS_GetStringCharsZ(cx, jsstr);
JS_ASSERT(s[0] == '9' && s[1] == '\0');
return true;
}
virtual JSRuntime * createRuntime()
{
JSRuntime *rt = JS_NewRuntime(0);
JS_SetGCParameter(rt, JSGC_MAX_BYTES, (uint32_t)-1);
return rt;
}
END_TEST(testOOM)

View File

@ -491,27 +491,29 @@ StaticStrings::init(JSContext *cx)
} }
} }
initialized = true;
return true; return true;
} }
void void
StaticStrings::trace(JSTracer *trc) StaticStrings::trace(JSTracer *trc)
{ {
if (!initialized)
return;
/* These strings never change, so barriers are not needed. */ /* These strings never change, so barriers are not needed. */
for (uint32_t i = 0; i < UNIT_STATIC_LIMIT; i++) for (uint32_t i = 0; i < UNIT_STATIC_LIMIT; i++) {
MarkStringUnbarriered(trc, unitStaticTable[i], "unit-static-string"); if (JSAtom *atom = unitStaticTable[i])
MarkStringUnbarriered(trc, atom, "unit-static-string");
}
for (uint32_t i = 0; i < NUM_SMALL_CHARS * NUM_SMALL_CHARS; i++) for (uint32_t i = 0; i < NUM_SMALL_CHARS * NUM_SMALL_CHARS; i++) {
MarkStringUnbarriered(trc, length2StaticTable[i], "length2-static-string"); if (JSAtom *atom = length2StaticTable[i])
MarkStringUnbarriered(trc, atom, "length2-static-string");
}
/* This may mark some strings more than once, but so be it. */ /* This may mark some strings more than once, but so be it. */
for (uint32_t i = 0; i < INT_STATIC_LIMIT; i++) for (uint32_t i = 0; i < INT_STATIC_LIMIT; i++) {
MarkStringUnbarriered(trc, intStaticTable[i], "int-static-string"); if (JSAtom *atom = intStaticTable[i])
MarkStringUnbarriered(trc, atom, "int-static-string");
}
} }
bool bool

View File

@ -696,8 +696,6 @@ namespace js {
class StaticStrings class StaticStrings
{ {
private: private:
bool initialized;
/* Bigger chars cannot be in a length-2 string. */ /* Bigger chars cannot be in a length-2 string. */
static const size_t SMALL_CHAR_LIMIT = 128U; static const size_t SMALL_CHAR_LIMIT = 128U;
static const size_t NUM_SMALL_CHARS = 64U; static const size_t NUM_SMALL_CHARS = 64U;
@ -712,7 +710,11 @@ class StaticStrings
static const size_t UNIT_STATIC_LIMIT = 256U; static const size_t UNIT_STATIC_LIMIT = 256U;
JSAtom *unitStaticTable[UNIT_STATIC_LIMIT]; JSAtom *unitStaticTable[UNIT_STATIC_LIMIT];
StaticStrings() : initialized(false) {} StaticStrings() {
PodArrayZero(unitStaticTable);
PodArrayZero(length2StaticTable);
PodArrayZero(intStaticTable);
}
bool init(JSContext *cx); bool init(JSContext *cx);
void trace(JSTracer *trc); void trace(JSTracer *trc);