/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- * vim: set ts=8 sts=2 et sw=2 tw=80: * * ***** BEGIN LICENSE BLOCK ***** * Copyright (C) 2008 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* ***** END LICENSE BLOCK ***** */
// AllocPolicy for AssemblerBuffer. OOMs when trying to allocate more than // MaxCodeBytesPerProcess bytes. Use private inheritance to make sure we // explicitly have to expose SystemAllocPolicy methods. class AssemblerBufferAllocPolicy : private SystemAllocPolicy { public: using SystemAllocPolicy::checkSimulatedOOM; using SystemAllocPolicy::free_; using SystemAllocPolicy::reportAllocOverflow;
template <typename T>
T* pod_realloc(T* p, size_t oldSize, size_t newSize) {
static_assert( sizeof(T) == 1, "AssemblerBufferAllocPolicy should only be used with byte vectors");
MOZ_ASSERT(oldSize <= MaxCodeBytesPerProcess); if (MOZ_UNLIKELY(newSize > MaxCodeBytesPerProcess)) { return nullptr;
} return SystemAllocPolicy::pod_realloc<T>(p, oldSize, newSize);
} template <typename T>
T* pod_malloc(size_t numElems) {
static_assert( sizeof(T) == 1, "AssemblerBufferAllocPolicy should only be used with byte vectors"); if (MOZ_UNLIKELY(numElems > MaxCodeBytesPerProcess)) { return nullptr;
} return SystemAllocPolicy::pod_malloc<T>(numElems);
}
};
void ensureSpace(size_t space) { // This should only be called with small |space| values to ensure // we don't overflow below.
MOZ_ASSERT(space <= 16); if (MOZ_UNLIKELY(!m_buffer.reserve(m_buffer.length() + space))) {
oomDetected();
}
}
protected: /* * OOM handling: This class can OOM in the ensureSpace() method trying * to allocate a new buffer. In response to an OOM, we need to avoid * crashing and report the error. We also want to make it so that * users of this class need to check for OOM only at certain points * and not after every operation. * * Our strategy for handling an OOM is to set m_oom, and then clear (but * not free) m_buffer, preserving the current buffer. This way, the user * can continue assembling into the buffer, deferring OOM checking * until the user wants to read code out of the buffer. * * See also the |buffer| method.
*/ void oomDetected() {
m_oom = true;
m_buffer.clear(); #ifdef DEBUG
JitContext* context = MaybeGetJitContext(); if (context) {
context->setOOM();
} #endif
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.