Line data Source code
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 "jscompartment.h"
13 :
14 : #include "gc/Allocator.h"
15 : #include "gc/GCTrace.h"
16 : #include "vm/Probes.h"
17 :
18 : #include "jsobjinlines.h"
19 :
20 : namespace js {
21 :
22 : inline bool
23 20976 : NewObjectCache::lookupProto(const Class* clasp, JSObject* proto, gc::AllocKind kind, EntryIndex* pentry)
24 : {
25 20976 : MOZ_ASSERT(!proto->is<GlobalObject>());
26 20976 : return lookup(clasp, proto, kind, pentry);
27 : }
28 :
29 : inline bool
30 17667 : NewObjectCache::lookupGlobal(const Class* clasp, GlobalObject* global, gc::AllocKind kind, EntryIndex* pentry)
31 : {
32 17667 : return lookup(clasp, global, kind, pentry);
33 : }
34 :
35 : inline void
36 1900 : NewObjectCache::fillGlobal(EntryIndex entry, const Class* clasp, GlobalObject* global,
37 : gc::AllocKind kind, NativeObject* obj)
38 : {
39 : //MOZ_ASSERT(global == obj->getGlobal());
40 1900 : return fill(entry, clasp, global, kind, obj);
41 : }
42 :
43 : inline NativeObject*
44 24321 : NewObjectCache::newObjectFromHit(JSContext* cx, EntryIndex entryIndex, gc::InitialHeap heap)
45 : {
46 24321 : MOZ_ASSERT(unsigned(entryIndex) < mozilla::ArrayLength(entries));
47 24321 : Entry* entry = &entries[entryIndex];
48 :
49 24321 : NativeObject* templateObj = 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 runtimeFromAnyThread.
53 24321 : ObjectGroup* group = templateObj->group_;
54 :
55 24321 : MOZ_ASSERT(!group->hasUnanalyzedPreliminaryObjects());
56 :
57 24321 : if (group->shouldPreTenure())
58 0 : heap = gc::TenuredHeap;
59 :
60 24321 : if (cx->runtime()->gc.upcomingZealousGC())
61 0 : return nullptr;
62 :
63 24321 : NativeObject* obj = static_cast<NativeObject*>(Allocate<JSObject, NoGC>(cx, entry->kind, 0,
64 24321 : heap, group->clasp()));
65 24321 : if (!obj)
66 0 : return nullptr;
67 :
68 24321 : copyCachedToObject(obj, templateObj, entry->kind);
69 :
70 24321 : if (group->clasp()->shouldDelayMetadataBuilder())
71 3277 : cx->compartment()->setObjectPendingMetadata(cx, obj);
72 : else
73 21044 : obj = static_cast<NativeObject*>(SetNewObjectMetadata(cx, obj));
74 :
75 24321 : probes::CreateObject(cx, obj);
76 24321 : gc::TraceCreateObject(obj);
77 24321 : return obj;
78 : }
79 :
80 : } /* namespace js */
81 :
82 : #endif /* vm_Caches_inl_h */
|