js/src/jit/StackSlotAllocator.h

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 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef jit_StackSlotAllocator_h
michael@0 8 #define jit_StackSlotAllocator_h
michael@0 9
michael@0 10 #include "jit/Registers.h"
michael@0 11
michael@0 12 namespace js {
michael@0 13 namespace jit {
michael@0 14
michael@0 15 class StackSlotAllocator
michael@0 16 {
michael@0 17 js::Vector<uint32_t, 4, SystemAllocPolicy> normalSlots;
michael@0 18 js::Vector<uint32_t, 4, SystemAllocPolicy> doubleSlots;
michael@0 19 uint32_t height_;
michael@0 20
michael@0 21 void freeSlot(uint32_t index) {
michael@0 22 normalSlots.append(index);
michael@0 23 }
michael@0 24 void freeDoubleSlot(uint32_t index) {
michael@0 25 doubleSlots.append(index);
michael@0 26 }
michael@0 27
michael@0 28 uint32_t allocateDoubleSlot() {
michael@0 29 if (!doubleSlots.empty())
michael@0 30 return doubleSlots.popCopy();
michael@0 31 if (height_ % 8 != 0)
michael@0 32 normalSlots.append(height_ += 4);
michael@0 33 return height_ += 8;
michael@0 34 }
michael@0 35 uint32_t allocateSlot() {
michael@0 36 if (!normalSlots.empty())
michael@0 37 return normalSlots.popCopy();
michael@0 38 if (!doubleSlots.empty()) {
michael@0 39 uint32_t index = doubleSlots.popCopy();
michael@0 40 normalSlots.append(index - 4);
michael@0 41 return index;
michael@0 42 }
michael@0 43 return height_ += 4;
michael@0 44 }
michael@0 45
michael@0 46 public:
michael@0 47 StackSlotAllocator() : height_(0)
michael@0 48 { }
michael@0 49
michael@0 50 void freeSlot(LDefinition::Type type, uint32_t index) {
michael@0 51 switch (type) {
michael@0 52 #if JS_BITS_PER_WORD == 32
michael@0 53 case LDefinition::GENERAL:
michael@0 54 case LDefinition::OBJECT:
michael@0 55 case LDefinition::SLOTS:
michael@0 56 #endif
michael@0 57 case LDefinition::INT32:
michael@0 58 case LDefinition::FLOAT32: return freeSlot(index);
michael@0 59 #if JS_BITS_PER_WORD == 64
michael@0 60 case LDefinition::GENERAL:
michael@0 61 case LDefinition::OBJECT:
michael@0 62 case LDefinition::SLOTS:
michael@0 63 #endif
michael@0 64 #ifdef JS_PUNBOX64
michael@0 65 case LDefinition::BOX:
michael@0 66 #endif
michael@0 67 #ifdef JS_NUNBOX32
michael@0 68 case LDefinition::TYPE:
michael@0 69 case LDefinition::PAYLOAD:
michael@0 70 #endif
michael@0 71 case LDefinition::DOUBLE: return freeDoubleSlot(index);
michael@0 72 default: MOZ_ASSUME_UNREACHABLE("Unknown slot type");
michael@0 73 }
michael@0 74 }
michael@0 75
michael@0 76 uint32_t allocateSlot(LDefinition::Type type) {
michael@0 77 switch (type) {
michael@0 78 #if JS_BITS_PER_WORD == 32
michael@0 79 case LDefinition::GENERAL:
michael@0 80 case LDefinition::OBJECT:
michael@0 81 case LDefinition::SLOTS:
michael@0 82 #endif
michael@0 83 case LDefinition::INT32:
michael@0 84 case LDefinition::FLOAT32: return allocateSlot();
michael@0 85 #if JS_BITS_PER_WORD == 64
michael@0 86 case LDefinition::GENERAL:
michael@0 87 case LDefinition::OBJECT:
michael@0 88 case LDefinition::SLOTS:
michael@0 89 #endif
michael@0 90 #ifdef JS_PUNBOX64
michael@0 91 case LDefinition::BOX:
michael@0 92 #endif
michael@0 93 #ifdef JS_NUNBOX32
michael@0 94 case LDefinition::TYPE:
michael@0 95 case LDefinition::PAYLOAD:
michael@0 96 #endif
michael@0 97 case LDefinition::DOUBLE: return allocateDoubleSlot();
michael@0 98 default: MOZ_ASSUME_UNREACHABLE("Unknown slot type");
michael@0 99 }
michael@0 100 }
michael@0 101
michael@0 102 uint32_t stackHeight() const {
michael@0 103 return height_;
michael@0 104 }
michael@0 105 };
michael@0 106
michael@0 107 } // namespace jit
michael@0 108 } // namespace js
michael@0 109
michael@0 110 #endif /* jit_StackSlotAllocator_h */

mercurial