js/src/jsapi-tests/testGCStoreBufferRemoval.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 */
michael@0 4 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 5 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 7
michael@0 8 #ifdef JSGC_GENERATIONAL
michael@0 9
michael@0 10 #include "gc/Barrier.h"
michael@0 11 #include "jsapi-tests/tests.h"
michael@0 12
michael@0 13 using namespace JS;
michael@0 14 using namespace js;
michael@0 15
michael@0 16 struct AutoIgnoreRootingHazards {
michael@0 17 // Force a nontrivial destructor so the compiler sees the whole RAII scope
michael@0 18 static volatile int depth;
michael@0 19 AutoIgnoreRootingHazards() { depth++; }
michael@0 20 ~AutoIgnoreRootingHazards() { depth--; }
michael@0 21 };
michael@0 22 volatile int AutoIgnoreRootingHazards::depth = 0;
michael@0 23
michael@0 24 BEGIN_TEST(testGCStoreBufferRemoval)
michael@0 25 {
michael@0 26 // Sanity check - objects start in the nursery and then become tenured.
michael@0 27 JS_GC(cx->runtime());
michael@0 28 JS::RootedObject obj(cx, NurseryObject());
michael@0 29 CHECK(js::gc::IsInsideNursery(rt, obj.get()));
michael@0 30 JS_GC(cx->runtime());
michael@0 31 CHECK(!js::gc::IsInsideNursery(rt, obj.get()));
michael@0 32 JS::RootedObject tenuredObject(cx, obj);
michael@0 33
michael@0 34 // Hide the horrors herein from the static rooting analysis.
michael@0 35 AutoIgnoreRootingHazards ignore;
michael@0 36
michael@0 37 // Test removal of store buffer entries added by RelocatablePtr<T>.
michael@0 38 {
michael@0 39 JSObject *badObject = reinterpret_cast<JSObject*>(1);
michael@0 40 JSObject *punnedPtr = nullptr;
michael@0 41 RelocatablePtrObject* relocPtr =
michael@0 42 reinterpret_cast<RelocatablePtrObject*>(&punnedPtr);
michael@0 43 new (relocPtr) RelocatablePtrObject;
michael@0 44 *relocPtr = NurseryObject();
michael@0 45 relocPtr->~RelocatablePtrObject();
michael@0 46 punnedPtr = badObject;
michael@0 47 JS_GC(cx->runtime());
michael@0 48
michael@0 49 new (relocPtr) RelocatablePtrObject;
michael@0 50 *relocPtr = NurseryObject();
michael@0 51 *relocPtr = tenuredObject;
michael@0 52 relocPtr->~RelocatablePtrObject();
michael@0 53 punnedPtr = badObject;
michael@0 54 JS_GC(cx->runtime());
michael@0 55
michael@0 56 new (relocPtr) RelocatablePtrObject;
michael@0 57 *relocPtr = NurseryObject();
michael@0 58 *relocPtr = nullptr;
michael@0 59 relocPtr->~RelocatablePtrObject();
michael@0 60 punnedPtr = badObject;
michael@0 61 JS_GC(cx->runtime());
michael@0 62 }
michael@0 63
michael@0 64 // Test removal of store buffer entries added by RelocatableValue.
michael@0 65 {
michael@0 66 Value punnedValue;
michael@0 67 RelocatableValue *relocValue = reinterpret_cast<RelocatableValue*>(&punnedValue);
michael@0 68 new (relocValue) RelocatableValue;
michael@0 69 *relocValue = ObjectValue(*NurseryObject());
michael@0 70 relocValue->~RelocatableValue();
michael@0 71 punnedValue = ObjectValueCrashOnTouch();
michael@0 72 JS_GC(cx->runtime());
michael@0 73
michael@0 74 new (relocValue) RelocatableValue;
michael@0 75 *relocValue = ObjectValue(*NurseryObject());
michael@0 76 *relocValue = ObjectValue(*tenuredObject);
michael@0 77 relocValue->~RelocatableValue();
michael@0 78 punnedValue = ObjectValueCrashOnTouch();
michael@0 79 JS_GC(cx->runtime());
michael@0 80
michael@0 81 new (relocValue) RelocatableValue;
michael@0 82 *relocValue = ObjectValue(*NurseryObject());
michael@0 83 *relocValue = NullValue();
michael@0 84 relocValue->~RelocatableValue();
michael@0 85 punnedValue = ObjectValueCrashOnTouch();
michael@0 86 JS_GC(cx->runtime());
michael@0 87 }
michael@0 88
michael@0 89 // Test removal of store buffer entries added by Heap<T>.
michael@0 90 {
michael@0 91 JSObject *badObject = reinterpret_cast<JSObject*>(1);
michael@0 92 JSObject *punnedPtr = nullptr;
michael@0 93 Heap<JSObject*>* heapPtr =
michael@0 94 reinterpret_cast<Heap<JSObject*>*>(&punnedPtr);
michael@0 95 new (heapPtr) Heap<JSObject*>;
michael@0 96 *heapPtr = NurseryObject();
michael@0 97 heapPtr->~Heap<JSObject*>();
michael@0 98 punnedPtr = badObject;
michael@0 99 JS_GC(cx->runtime());
michael@0 100
michael@0 101 new (heapPtr) Heap<JSObject*>;
michael@0 102 *heapPtr = NurseryObject();
michael@0 103 *heapPtr = tenuredObject;
michael@0 104 heapPtr->~Heap<JSObject*>();
michael@0 105 punnedPtr = badObject;
michael@0 106 JS_GC(cx->runtime());
michael@0 107
michael@0 108 new (heapPtr) Heap<JSObject*>;
michael@0 109 *heapPtr = NurseryObject();
michael@0 110 *heapPtr = nullptr;
michael@0 111 heapPtr->~Heap<JSObject*>();
michael@0 112 punnedPtr = badObject;
michael@0 113 JS_GC(cx->runtime());
michael@0 114 }
michael@0 115
michael@0 116 return true;
michael@0 117 }
michael@0 118
michael@0 119 JSObject *NurseryObject()
michael@0 120 {
michael@0 121 return JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr());
michael@0 122 }
michael@0 123 END_TEST(testGCStoreBufferRemoval)
michael@0 124
michael@0 125 #endif

mercurial