js/src/vm/Runtime-inl.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/vm/Runtime-inl.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef vm_Runtime_inl_h
    1.11 +#define vm_Runtime_inl_h
    1.12 +
    1.13 +#include "vm/Runtime.h"
    1.14 +
    1.15 +#include "jscompartment.h"
    1.16 +
    1.17 +#include "vm/Probes.h"
    1.18 +
    1.19 +#include "jsgcinlines.h"
    1.20 +
    1.21 +namespace js {
    1.22 +
    1.23 +inline bool
    1.24 +NewObjectCache::lookupProto(const Class *clasp, JSObject *proto, gc::AllocKind kind, EntryIndex *pentry)
    1.25 +{
    1.26 +    JS_ASSERT(!proto->is<GlobalObject>());
    1.27 +    return lookup(clasp, proto, kind, pentry);
    1.28 +}
    1.29 +
    1.30 +inline bool
    1.31 +NewObjectCache::lookupGlobal(const Class *clasp, js::GlobalObject *global, gc::AllocKind kind, EntryIndex *pentry)
    1.32 +{
    1.33 +    return lookup(clasp, global, kind, pentry);
    1.34 +}
    1.35 +
    1.36 +inline void
    1.37 +NewObjectCache::fillGlobal(EntryIndex entry, const Class *clasp, js::GlobalObject *global, gc::AllocKind kind, JSObject *obj)
    1.38 +{
    1.39 +    //JS_ASSERT(global == obj->getGlobal());
    1.40 +    return fill(entry, clasp, global, kind, obj);
    1.41 +}
    1.42 +
    1.43 +template <AllowGC allowGC>
    1.44 +inline JSObject *
    1.45 +NewObjectCache::newObjectFromHit(JSContext *cx, EntryIndex entry_, js::gc::InitialHeap heap)
    1.46 +{
    1.47 +    // The new object cache does not account for metadata attached via callbacks.
    1.48 +    JS_ASSERT(!cx->compartment()->hasObjectMetadataCallback());
    1.49 +
    1.50 +    JS_ASSERT(unsigned(entry_) < mozilla::ArrayLength(entries));
    1.51 +    Entry *entry = &entries[entry_];
    1.52 +
    1.53 +    JSObject *templateObj = reinterpret_cast<JSObject *>(&entry->templateObject);
    1.54 +
    1.55 +    // Do an end run around JSObject::type() to avoid doing AutoUnprotectCell
    1.56 +    // on the templateObj, which is not a GC thing and can't use runtimeFromAnyThread.
    1.57 +    types::TypeObject *type = templateObj->type_;
    1.58 +
    1.59 +    if (type->shouldPreTenure())
    1.60 +        heap = gc::TenuredHeap;
    1.61 +
    1.62 +    if (cx->runtime()->upcomingZealousGC())
    1.63 +        return nullptr;
    1.64 +
    1.65 +    // Trigger an identical allocation to the one that notified us of OOM
    1.66 +    // so that we trigger the right kind of GC automatically.
    1.67 +    if (allowGC) {
    1.68 +        mozilla::DebugOnly<JSObject *> obj =
    1.69 +            js::gc::AllocateObjectForCacheHit<allowGC>(cx, entry->kind, heap);
    1.70 +        JS_ASSERT(!obj);
    1.71 +        return nullptr;
    1.72 +    }
    1.73 +
    1.74 +    JS_ASSERT(allowGC == NoGC);
    1.75 +    JSObject *obj = js::gc::AllocateObjectForCacheHit<NoGC>(cx, entry->kind, heap);
    1.76 +    if (obj) {
    1.77 +        copyCachedToObject(obj, templateObj, entry->kind);
    1.78 +        probes::CreateObject(cx, obj);
    1.79 +        return obj;
    1.80 +    }
    1.81 +
    1.82 +    return nullptr;
    1.83 +}
    1.84 +
    1.85 +}  /* namespace js */
    1.86 +
    1.87 +#endif /* vm_Runtime_inl_h */

mercurial