Bug 841801 - Keep finalizable objects out of the nursery r=billm

--HG--
extra : rebase_source : ea13c882c82554a1510df47aadbc1bb1c6b6e569
This commit is contained in:
Jon Coppeard 2013-02-21 18:51:14 +00:00
parent 93c72cfb15
commit fd830891e6
7 changed files with 20 additions and 12 deletions

View File

@ -2666,7 +2666,7 @@ NewArray(JSContext *cx, uint32_t length, RawObject protoArg, NewObjectKind newKi
if (newKind != SingletonObject &&
cache.lookupGlobal(&ArrayClass, cx->global(), allocKind, &entry))
{
RootedObject obj(cx, cache.newObjectFromHit(cx, entry, InitialHeapForNewKind(newKind)));
RootedObject obj(cx, cache.newObjectFromHit(cx, entry, GetInitialHeap(newKind, &ArrayClass)));
if (obj) {
/* Fixup the elements pointer and length, which may be incorrect. */
obj->setFixedElements();

View File

@ -385,12 +385,14 @@ NewPropertyIteratorObject(JSContext *cx, unsigned flags)
if (!type)
return NULL;
RootedShape shape(cx, EmptyShape::getInitialShape(cx, &PropertyIteratorObject::class_,
NULL, NULL, ITERATOR_FINALIZE_KIND));
Class *clasp = &PropertyIteratorObject::class_;
RootedShape shape(cx, EmptyShape::getInitialShape(cx, clasp, NULL, NULL,
ITERATOR_FINALIZE_KIND));
if (!shape)
return NULL;
RawObject obj = JSObject::create(cx, ITERATOR_FINALIZE_KIND, gc::DefaultHeap, shape, type, NULL);
RawObject obj = JSObject::create(cx, ITERATOR_FINALIZE_KIND,
GetInitialHeap(GenericObject, clasp), shape, type, NULL);
if (!obj)
return NULL;

View File

@ -1197,7 +1197,7 @@ NewObject(JSContext *cx, Class *clasp, types::TypeObject *type_, JSObject *paren
if (!PreallocateObjectDynamicSlots(cx, shape, &slots))
return NULL;
gc::InitialHeap heap = InitialHeapForNewKind(newKind);
gc::InitialHeap heap = GetInitialHeap(newKind, clasp);
JSObject *obj = JSObject::create(cx, kind, heap, shape, type, slots);
if (!obj) {
js_free(slots);
@ -1242,7 +1242,7 @@ js::NewObjectWithGivenProto(JSContext *cx, js::Class *clasp,
(!parent || parent == proto.toObject()->getParent()) && !proto.toObject()->isGlobal())
{
if (cache.lookupProto(clasp, proto.toObject(), allocKind, &entry)) {
JSObject *obj = cache.newObjectFromHit(cx, entry, InitialHeapForNewKind(newKind));
JSObject *obj = cache.newObjectFromHit(cx, entry, GetInitialHeap(newKind, clasp));
if (obj)
return obj;
}
@ -1298,7 +1298,7 @@ js::NewObjectWithClassProtoCommon(JSContext *cx, js::Class *clasp, JSObject *pro
NewObjectCache::EntryIndex entry = -1;
if (parentArg->isGlobal() && protoKey != JSProto_Null && newKind != SingletonObject) {
if (cache.lookupGlobal(clasp, &parentArg->asGlobal(), allocKind, &entry)) {
JSObject *obj = cache.newObjectFromHit(cx, entry, InitialHeapForNewKind(newKind));
JSObject *obj = cache.newObjectFromHit(cx, entry, GetInitialHeap(newKind, clasp));
if (obj)
return obj;
}
@ -1340,7 +1340,7 @@ js::NewObjectWithType(JSContext *cx, HandleTypeObject type, JSObject *parent, gc
NewObjectCache::EntryIndex entry = -1;
if (parent == type->proto->getParent() && newKind != SingletonObject) {
if (cache.lookupType(&ObjectClass, type, allocKind, &entry)) {
JSObject *obj = cache.newObjectFromHit(cx, entry, InitialHeapForNewKind(newKind));
JSObject *obj = cache.newObjectFromHit(cx, entry, GetInitialHeap(newKind, &ObjectClass));
if (obj)
return obj;
}

View File

@ -1199,9 +1199,11 @@ enum NewObjectKind {
};
inline gc::InitialHeap
InitialHeapForNewKind(NewObjectKind newKind)
GetInitialHeap(NewObjectKind newKind, const Class *clasp)
{
return newKind == GenericObject ? gc::DefaultHeap : gc::TenuredHeap;
if (clasp->finalize || newKind != GenericObject)
return gc::TenuredHeap;
return gc::DefaultHeap;
}
// Specialized call for constructing |this| with a known function callee,

View File

@ -939,6 +939,7 @@ JSObject::create(JSContext *cx, js::gc::AllocKind kind, js::gc::InitialHeap heap
JS_ASSERT(js::gc::GetGCKindSlots(kind, type->clasp) == shape->numFixedSlots());
JS_ASSERT(cx->compartment == type->compartment());
JS_ASSERT_IF(type->clasp->flags & JSCLASS_BACKGROUND_FINALIZE, IsBackgroundFinalized(kind));
JS_ASSERT_IF(type->clasp->finalize, heap == js::gc::TenuredHeap);
JSObject *obj = js_NewGCObject<js::CanGC>(cx, kind, heap);
if (!obj)
@ -969,6 +970,7 @@ JSObject::createArray(JSContext *cx, js::gc::AllocKind kind, js::gc::InitialHeap
JS_ASSERT(type->clasp == shape->getObjectClass());
JS_ASSERT(type->clasp == &js::ArrayClass);
JS_ASSERT(cx->compartment == type->compartment());
JS_ASSERT_IF(type->clasp->finalize, heap == js::gc::TenuredHeap);
/*
* Arrays use their fixed slots to store elements, and must have enough

View File

@ -158,7 +158,8 @@ ArgumentsObject::create(JSContext *cx, HandleScript script, HandleFunction calle
data->deletedBits = reinterpret_cast<size_t *>(dstEnd);
ClearAllBitArrayElements(data->deletedBits, numDeletedWords);
RawObject obj = JSObject::create(cx, FINALIZE_KIND, gc::DefaultHeap, shape, type, NULL);
RawObject obj = JSObject::create(cx, FINALIZE_KIND, GetInitialHeap(GenericObject, clasp),
shape, type, NULL);
if (!obj) {
js_free(data);
return NULL;

View File

@ -146,7 +146,8 @@ CallObject::create(JSContext *cx, HandleShape shape, HandleTypeObject type, Heap
JS_ASSERT(CanBeFinalizedInBackground(kind, &CallClass));
kind = gc::GetBackgroundAllocKind(kind);
JSObject *obj = JSObject::create(cx, kind, gc::DefaultHeap, shape, type, slots);
JSObject *obj = JSObject::create(cx, kind, GetInitialHeap(GenericObject, &CallClass),
shape, type, slots);
if (!obj)
return NULL;
return &obj->asCall();