michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef vm_Runtime_inl_h michael@0: #define vm_Runtime_inl_h michael@0: michael@0: #include "vm/Runtime.h" michael@0: michael@0: #include "jscompartment.h" michael@0: michael@0: #include "vm/Probes.h" michael@0: michael@0: #include "jsgcinlines.h" michael@0: michael@0: namespace js { michael@0: michael@0: inline bool michael@0: NewObjectCache::lookupProto(const Class *clasp, JSObject *proto, gc::AllocKind kind, EntryIndex *pentry) michael@0: { michael@0: JS_ASSERT(!proto->is()); michael@0: return lookup(clasp, proto, kind, pentry); michael@0: } michael@0: michael@0: inline bool michael@0: NewObjectCache::lookupGlobal(const Class *clasp, js::GlobalObject *global, gc::AllocKind kind, EntryIndex *pentry) michael@0: { michael@0: return lookup(clasp, global, kind, pentry); michael@0: } michael@0: michael@0: inline void michael@0: NewObjectCache::fillGlobal(EntryIndex entry, const Class *clasp, js::GlobalObject *global, gc::AllocKind kind, JSObject *obj) michael@0: { michael@0: //JS_ASSERT(global == obj->getGlobal()); michael@0: return fill(entry, clasp, global, kind, obj); michael@0: } michael@0: michael@0: template michael@0: inline JSObject * michael@0: NewObjectCache::newObjectFromHit(JSContext *cx, EntryIndex entry_, js::gc::InitialHeap heap) michael@0: { michael@0: // The new object cache does not account for metadata attached via callbacks. michael@0: JS_ASSERT(!cx->compartment()->hasObjectMetadataCallback()); michael@0: michael@0: JS_ASSERT(unsigned(entry_) < mozilla::ArrayLength(entries)); michael@0: Entry *entry = &entries[entry_]; michael@0: michael@0: JSObject *templateObj = reinterpret_cast(&entry->templateObject); michael@0: michael@0: // Do an end run around JSObject::type() to avoid doing AutoUnprotectCell michael@0: // on the templateObj, which is not a GC thing and can't use runtimeFromAnyThread. michael@0: types::TypeObject *type = templateObj->type_; michael@0: michael@0: if (type->shouldPreTenure()) michael@0: heap = gc::TenuredHeap; michael@0: michael@0: if (cx->runtime()->upcomingZealousGC()) michael@0: return nullptr; michael@0: michael@0: // Trigger an identical allocation to the one that notified us of OOM michael@0: // so that we trigger the right kind of GC automatically. michael@0: if (allowGC) { michael@0: mozilla::DebugOnly obj = michael@0: js::gc::AllocateObjectForCacheHit(cx, entry->kind, heap); michael@0: JS_ASSERT(!obj); michael@0: return nullptr; michael@0: } michael@0: michael@0: JS_ASSERT(allowGC == NoGC); michael@0: JSObject *obj = js::gc::AllocateObjectForCacheHit(cx, entry->kind, heap); michael@0: if (obj) { michael@0: copyCachedToObject(obj, templateObj, entry->kind); michael@0: probes::CreateObject(cx, obj); michael@0: return obj; michael@0: } michael@0: michael@0: return nullptr; michael@0: } michael@0: michael@0: } /* namespace js */ michael@0: michael@0: #endif /* vm_Runtime_inl_h */