Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 vm_Runtime_inl_h |
michael@0 | 8 | #define vm_Runtime_inl_h |
michael@0 | 9 | |
michael@0 | 10 | #include "vm/Runtime.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "jscompartment.h" |
michael@0 | 13 | |
michael@0 | 14 | #include "vm/Probes.h" |
michael@0 | 15 | |
michael@0 | 16 | #include "jsgcinlines.h" |
michael@0 | 17 | |
michael@0 | 18 | namespace js { |
michael@0 | 19 | |
michael@0 | 20 | inline bool |
michael@0 | 21 | NewObjectCache::lookupProto(const Class *clasp, JSObject *proto, gc::AllocKind kind, EntryIndex *pentry) |
michael@0 | 22 | { |
michael@0 | 23 | JS_ASSERT(!proto->is<GlobalObject>()); |
michael@0 | 24 | return lookup(clasp, proto, kind, pentry); |
michael@0 | 25 | } |
michael@0 | 26 | |
michael@0 | 27 | inline bool |
michael@0 | 28 | NewObjectCache::lookupGlobal(const Class *clasp, js::GlobalObject *global, gc::AllocKind kind, EntryIndex *pentry) |
michael@0 | 29 | { |
michael@0 | 30 | return lookup(clasp, global, kind, pentry); |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | inline void |
michael@0 | 34 | NewObjectCache::fillGlobal(EntryIndex entry, const Class *clasp, js::GlobalObject *global, gc::AllocKind kind, JSObject *obj) |
michael@0 | 35 | { |
michael@0 | 36 | //JS_ASSERT(global == obj->getGlobal()); |
michael@0 | 37 | return fill(entry, clasp, global, kind, obj); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | template <AllowGC allowGC> |
michael@0 | 41 | inline JSObject * |
michael@0 | 42 | NewObjectCache::newObjectFromHit(JSContext *cx, EntryIndex entry_, js::gc::InitialHeap heap) |
michael@0 | 43 | { |
michael@0 | 44 | // The new object cache does not account for metadata attached via callbacks. |
michael@0 | 45 | JS_ASSERT(!cx->compartment()->hasObjectMetadataCallback()); |
michael@0 | 46 | |
michael@0 | 47 | JS_ASSERT(unsigned(entry_) < mozilla::ArrayLength(entries)); |
michael@0 | 48 | Entry *entry = &entries[entry_]; |
michael@0 | 49 | |
michael@0 | 50 | JSObject *templateObj = reinterpret_cast<JSObject *>(&entry->templateObject); |
michael@0 | 51 | |
michael@0 | 52 | // Do an end run around JSObject::type() to avoid doing AutoUnprotectCell |
michael@0 | 53 | // on the templateObj, which is not a GC thing and can't use runtimeFromAnyThread. |
michael@0 | 54 | types::TypeObject *type = templateObj->type_; |
michael@0 | 55 | |
michael@0 | 56 | if (type->shouldPreTenure()) |
michael@0 | 57 | heap = gc::TenuredHeap; |
michael@0 | 58 | |
michael@0 | 59 | if (cx->runtime()->upcomingZealousGC()) |
michael@0 | 60 | return nullptr; |
michael@0 | 61 | |
michael@0 | 62 | // Trigger an identical allocation to the one that notified us of OOM |
michael@0 | 63 | // so that we trigger the right kind of GC automatically. |
michael@0 | 64 | if (allowGC) { |
michael@0 | 65 | mozilla::DebugOnly<JSObject *> obj = |
michael@0 | 66 | js::gc::AllocateObjectForCacheHit<allowGC>(cx, entry->kind, heap); |
michael@0 | 67 | JS_ASSERT(!obj); |
michael@0 | 68 | return nullptr; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | JS_ASSERT(allowGC == NoGC); |
michael@0 | 72 | JSObject *obj = js::gc::AllocateObjectForCacheHit<NoGC>(cx, entry->kind, heap); |
michael@0 | 73 | if (obj) { |
michael@0 | 74 | copyCachedToObject(obj, templateObj, entry->kind); |
michael@0 | 75 | probes::CreateObject(cx, obj); |
michael@0 | 76 | return obj; |
michael@0 | 77 | } |
michael@0 | 78 | |
michael@0 | 79 | return nullptr; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | } /* namespace js */ |
michael@0 | 83 | |
michael@0 | 84 | #endif /* vm_Runtime_inl_h */ |