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/. */
6
7 #ifndef vm_Caches_inl_h
8 #define vm_Caches_inl_h
9
10 #include "vm/Caches.h"
11
12 #include "gc/Allocator.h"
13 #include "gc/GCTrace.h"
14 #include "vm/JSCompartment.h"
15 #include "vm/Probes.h"
16
17 #include "vm/JSObject-inl.h"
18
19 namespace js {
20
lookupProto(const Class * clasp,JSObject * proto,gc::AllocKind kind,EntryIndex * pentry)21 inline bool NewObjectCache::lookupProto(const Class* clasp, JSObject* proto,
22 gc::AllocKind kind,
23 EntryIndex* pentry) {
24 MOZ_ASSERT(!proto->is<GlobalObject>());
25 return lookup(clasp, proto, kind, pentry);
26 }
27
lookupGlobal(const Class * clasp,GlobalObject * global,gc::AllocKind kind,EntryIndex * pentry)28 inline bool NewObjectCache::lookupGlobal(const Class* clasp,
29 GlobalObject* global,
30 gc::AllocKind kind,
31 EntryIndex* pentry) {
32 return lookup(clasp, global, kind, pentry);
33 }
34
fillGlobal(EntryIndex entry,const Class * clasp,GlobalObject * global,gc::AllocKind kind,NativeObject * obj)35 inline void NewObjectCache::fillGlobal(EntryIndex entry, const Class* clasp,
36 GlobalObject* global, gc::AllocKind kind,
37 NativeObject* obj) {
38 // MOZ_ASSERT(global == obj->getGlobal());
39 return fill(entry, clasp, global, kind, obj);
40 }
41
newObjectFromHit(JSContext * cx,EntryIndex entryIndex,gc::InitialHeap heap)42 inline NativeObject* NewObjectCache::newObjectFromHit(JSContext* cx,
43 EntryIndex entryIndex,
44 gc::InitialHeap heap) {
45 MOZ_ASSERT(unsigned(entryIndex) < mozilla::ArrayLength(entries));
46 Entry* entry = &entries[entryIndex];
47
48 NativeObject* templateObj =
49 reinterpret_cast<NativeObject*>(&entry->templateObject);
50
51 // Do an end run around JSObject::group() to avoid doing AutoUnprotectCell
52 // on the templateObj, which is not a GC thing and can't use
53 // runtimeFromAnyThread.
54 ObjectGroup* group = templateObj->group_;
55
56 MOZ_ASSERT(!group->hasUnanalyzedPreliminaryObjects());
57
58 if (group->shouldPreTenure()) heap = gc::TenuredHeap;
59
60 if (cx->runtime()->gc.upcomingZealousGC()) return nullptr;
61
62 NativeObject* obj = static_cast<NativeObject*>(
63 Allocate<JSObject, NoGC>(cx, entry->kind,
64 /* nDynamicSlots = */ 0, heap, group->clasp()));
65 if (!obj) return nullptr;
66
67 copyCachedToObject(obj, templateObj, entry->kind);
68
69 if (group->clasp()->shouldDelayMetadataBuilder())
70 cx->compartment()->setObjectPendingMetadata(cx, obj);
71 else
72 obj = static_cast<NativeObject*>(SetNewObjectMetadata(cx, obj));
73
74 probes::CreateObject(cx, obj);
75 gc::TraceCreateObject(obj);
76 return obj;
77 }
78
79 } /* namespace js */
80
81 #endif /* vm_Caches_inl_h */
82