зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1028358; r=terrence
--HG-- extra : rebase_source : 9a11ed18dc2a94ef2397eb61a24eb74d764f0df7
This commit is contained in:
Родитель
06bb27de7f
Коммит
f946c37a6e
|
@ -35,6 +35,7 @@ UNIFIED_SOURCES += [
|
|||
'testGCAllocator.cpp',
|
||||
'testGCExactRooting.cpp',
|
||||
'testGCFinalizeCallback.cpp',
|
||||
'testGCHeapPostBarriers.cpp',
|
||||
'testGCOutOfMemory.cpp',
|
||||
'testGCStoreBufferRemoval.cpp',
|
||||
'testHashTable.cpp',
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
*/
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifdef JSGC_GENERATIONAL
|
||||
|
||||
#include "js/RootingAPI.h"
|
||||
#include "jsapi-tests/tests.h"
|
||||
|
||||
BEGIN_TEST(testGCHeapPostBarriers)
|
||||
{
|
||||
/* Sanity check - objects start in the nursery and then become tenured. */
|
||||
JS_GC(cx->runtime());
|
||||
JS::RootedObject obj(cx, NurseryObject());
|
||||
CHECK(js::gc::IsInsideNursery(obj.get()));
|
||||
JS_GC(cx->runtime());
|
||||
CHECK(!js::gc::IsInsideNursery(obj.get()));
|
||||
JS::RootedObject tenuredObject(cx, obj);
|
||||
|
||||
/* Currently JSObject and JSFunction objects are nursery allocated. */
|
||||
CHECK(TestHeapPostBarriers(NurseryObject()));
|
||||
CHECK(TestHeapPostBarriers(NurseryFunction()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
bool
|
||||
TestHeapPostBarriers(T initalObj)
|
||||
{
|
||||
CHECK(initalObj != nullptr);
|
||||
CHECK(js::gc::IsInsideNursery(initalObj));
|
||||
|
||||
/* Construct Heap<> wrapper. */
|
||||
JS::Heap<T> *heapData = new JS::Heap<T>();
|
||||
CHECK(heapData);
|
||||
CHECK(heapData->get() == nullptr);
|
||||
heapData->set(initalObj);
|
||||
|
||||
/* Perform minor GC and check heap wrapper is udated with new pointer. */
|
||||
js::MinorGC(cx, JS::gcreason::API);
|
||||
CHECK(heapData->get() != initalObj);
|
||||
CHECK(!js::gc::IsInsideNursery(heapData->get()));
|
||||
|
||||
/* Check object is definitely still alive. */
|
||||
Rooted<T> obj(cx, heapData->get());
|
||||
RootedValue value(cx);
|
||||
CHECK(JS_GetProperty(cx, obj, "x", &value));
|
||||
CHECK(value.isInt32());
|
||||
CHECK(value.toInt32() == 42);
|
||||
|
||||
delete heapData;
|
||||
return true;
|
||||
}
|
||||
|
||||
JSObject *NurseryObject()
|
||||
{
|
||||
RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
|
||||
if (!obj)
|
||||
return nullptr;
|
||||
JS_DefineProperty(cx, obj, "x", 42, 0);
|
||||
return obj;
|
||||
}
|
||||
|
||||
JSFunction *NurseryFunction()
|
||||
{
|
||||
/*
|
||||
* We don't actually use the function as a function, so here we cheat and
|
||||
* cast a JSObject.
|
||||
*/
|
||||
return static_cast<JSFunction *>(NurseryObject());
|
||||
}
|
||||
|
||||
END_TEST(testGCHeapPostBarriers)
|
||||
|
||||
#endif
|
|
@ -9,13 +9,11 @@
|
|||
|
||||
#include "jsapi-tests/tests.h"
|
||||
|
||||
using namespace JS;
|
||||
|
||||
#ifdef JSGC_USE_EXACT_ROOTING
|
||||
|
||||
BEGIN_TEST(testWeakMap_basicOperations)
|
||||
{
|
||||
RootedObject map(cx, NewWeakMapObject(cx));
|
||||
RootedObject map(cx, JS::NewWeakMapObject(cx));
|
||||
CHECK(IsWeakMapObject(map));
|
||||
|
||||
RootedObject key(cx, newKey());
|
||||
|
@ -73,7 +71,7 @@ BEGIN_TEST(testWeakMap_keyDelegates)
|
|||
JS_SetGCParameter(rt, JSGC_MODE, JSGC_MODE_INCREMENTAL);
|
||||
JS_GC(rt);
|
||||
|
||||
RootedObject map(cx, NewWeakMapObject(cx));
|
||||
RootedObject map(cx, JS::NewWeakMapObject(cx));
|
||||
CHECK(map);
|
||||
|
||||
RootedObject key(cx, newKey());
|
||||
|
|
Загрузка…
Ссылка в новой задаче