|
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_Runtime_inl_h |
|
8 #define vm_Runtime_inl_h |
|
9 |
|
10 #include "vm/Runtime.h" |
|
11 |
|
12 #include "jscompartment.h" |
|
13 |
|
14 #include "vm/Probes.h" |
|
15 |
|
16 #include "jsgcinlines.h" |
|
17 |
|
18 namespace js { |
|
19 |
|
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 } |
|
26 |
|
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 } |
|
32 |
|
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 } |
|
39 |
|
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()); |
|
46 |
|
47 JS_ASSERT(unsigned(entry_) < mozilla::ArrayLength(entries)); |
|
48 Entry *entry = &entries[entry_]; |
|
49 |
|
50 JSObject *templateObj = reinterpret_cast<JSObject *>(&entry->templateObject); |
|
51 |
|
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_; |
|
55 |
|
56 if (type->shouldPreTenure()) |
|
57 heap = gc::TenuredHeap; |
|
58 |
|
59 if (cx->runtime()->upcomingZealousGC()) |
|
60 return nullptr; |
|
61 |
|
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 } |
|
70 |
|
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 } |
|
78 |
|
79 return nullptr; |
|
80 } |
|
81 |
|
82 } /* namespace js */ |
|
83 |
|
84 #endif /* vm_Runtime_inl_h */ |