DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (27a812186ff4)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=8 sts=4 et sw=4 tw=99:
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef vm_Runtime_inl_h
#define vm_Runtime_inl_h

#include "vm/Runtime.h"

#include "jscompartment.h"

#include "vm/Probes.h"

#include "jsgcinlines.h"

namespace js {

inline bool
NewObjectCache::lookupProto(const Class* clasp, JSObject* proto, gc::AllocKind kind, EntryIndex* pentry)
{
    JS_ASSERT(!proto->is<GlobalObject>());
    return lookup(clasp, proto, kind, pentry);
}

inline bool
NewObjectCache::lookupGlobal(const Class* clasp, js::GlobalObject* global, gc::AllocKind kind, EntryIndex* pentry)
{
    return lookup(clasp, global, kind, pentry);
}

inline void
NewObjectCache::fillGlobal(EntryIndex entry, const Class* clasp, js::GlobalObject* global, gc::AllocKind kind, JSObject* obj)
{
    //JS_ASSERT(global == obj->getGlobal());
    return fill(entry, clasp, global, kind, obj);
}

template <AllowGC allowGC>
inline JSObject*
NewObjectCache::newObjectFromHit(JSContext* cx, EntryIndex entry_, js::gc::InitialHeap heap)
{
    // The new object cache does not account for metadata attached via callbacks.
    JS_ASSERT(!cx->compartment()->hasObjectMetadataCallback());

    JS_ASSERT(unsigned(entry_) < mozilla::ArrayLength(entries));
    Entry* entry = &entries[entry_];

    JSObject* templateObj = reinterpret_cast<JSObject*>(&entry->templateObject);

    // Do an end run around JSObject::type() to avoid doing AutoUnprotectCell
    // on the templateObj, which is not a GC thing and can't use runtimeFromAnyThread.
    types::TypeObject* type = templateObj->type_;

    if (type->shouldPreTenure())
        heap = gc::TenuredHeap;

    if (cx->runtime()->upcomingZealousGC())
        return nullptr;

    // Trigger an identical allocation to the one that notified us of OOM
    // so that we trigger the right kind of GC automatically.
    if (allowGC) {
        mozilla::DebugOnly<JSObject*> obj =
            js::gc::AllocateObjectForCacheHit<allowGC>(cx, entry->kind, heap);
        JS_ASSERT(!obj);
        return nullptr;
    }

    JS_ASSERT(allowGC == NoGC);
    JSObject* obj = js::gc::AllocateObjectForCacheHit<NoGC>(cx, entry->kind, heap);
    if (obj) {
        copyCachedToObject(obj, templateObj, entry->kind);
        probes::CreateObject(cx, obj);
        return obj;
    }

    return nullptr;
}

}  /* namespace js */

#endif /* vm_Runtime_inl_h */