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