Sat, 03 Jan 2015 20:18:00 +0100
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.
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sts=4 et sw=4 tw=99:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef jit_PcScriptCache_h
8 #define jit_PcScriptCache_h
10 // Defines a fixed-size hash table solely for the purpose of caching jit::GetPcScript().
11 // One cache is attached to each JSRuntime; it functions as if cleared on GC.
13 struct JSRuntime;
15 namespace js {
16 namespace jit {
18 struct PcScriptCacheEntry
19 {
20 uint8_t *returnAddress; // Key into the hash table.
21 jsbytecode *pc; // Cached PC.
22 JSScript *script; // Cached script.
23 };
25 struct PcScriptCache
26 {
27 static const uint32_t Length = 73;
29 // GC number at the time the cache was filled or created.
30 // Storing and checking against this number allows us to not bother
31 // clearing this cache on every GC -- only when actually necessary.
32 uint64_t gcNumber;
34 // List of cache entries.
35 mozilla::Array<PcScriptCacheEntry, Length> entries;
37 void clear(uint64_t gcNumber) {
38 for (uint32_t i = 0; i < Length; i++)
39 entries[i].returnAddress = nullptr;
40 this->gcNumber = gcNumber;
41 }
43 // Get a value from the cache. May perform lazy allocation.
44 bool get(JSRuntime *rt, uint32_t hash, uint8_t *addr,
45 JSScript **scriptRes, jsbytecode **pcRes)
46 {
47 // If a GC occurred, lazily clear the cache now.
48 if (gcNumber != rt->gcNumber) {
49 clear(rt->gcNumber);
50 return false;
51 }
53 if (entries[hash].returnAddress != addr)
54 return false;
56 *scriptRes = entries[hash].script;
57 if (pcRes)
58 *pcRes = entries[hash].pc;
60 return true;
61 }
63 void add(uint32_t hash, uint8_t *addr, jsbytecode *pc, JSScript *script) {
64 entries[hash].returnAddress = addr;
65 entries[hash].pc = pc;
66 entries[hash].script = script;
67 }
69 static uint32_t Hash(uint8_t *addr) {
70 uint32_t key = (uint32_t)((uintptr_t)addr);
71 return ((key >> 3) * 2654435761u) % Length;
72 }
73 };
75 } // namespace jit
76 } // namespace js
78 #endif /* jit_PcScriptCache_h */