js/src/jit/IonLinker.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 2 * vim: set ts=8 sts=4 et sw=4 tw=99:
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef jit_IonLinker_h
michael@0 8 #define jit_IonLinker_h
michael@0 9
michael@0 10 #include "jscntxt.h"
michael@0 11 #include "jscompartment.h"
michael@0 12 #include "jsgc.h"
michael@0 13
michael@0 14 #include "assembler/jit/ExecutableAllocator.h"
michael@0 15 #include "jit/IonCode.h"
michael@0 16 #include "jit/IonMacroAssembler.h"
michael@0 17 #include "jit/JitCompartment.h"
michael@0 18
michael@0 19 namespace js {
michael@0 20 namespace jit {
michael@0 21
michael@0 22 class Linker
michael@0 23 {
michael@0 24 MacroAssembler &masm;
michael@0 25
michael@0 26 JitCode *fail(JSContext *cx) {
michael@0 27 js_ReportOutOfMemory(cx);
michael@0 28 return nullptr;
michael@0 29 }
michael@0 30
michael@0 31 template <AllowGC allowGC>
michael@0 32 JitCode *newCode(JSContext *cx, JSC::ExecutableAllocator *execAlloc, JSC::CodeKind kind) {
michael@0 33 JS_ASSERT(kind == JSC::ION_CODE ||
michael@0 34 kind == JSC::BASELINE_CODE ||
michael@0 35 kind == JSC::OTHER_CODE);
michael@0 36 JS_ASSERT(masm.numAsmJSAbsoluteLinks() == 0);
michael@0 37
michael@0 38 gc::AutoSuppressGC suppressGC(cx);
michael@0 39 if (masm.oom())
michael@0 40 return fail(cx);
michael@0 41
michael@0 42 JSC::ExecutablePool *pool;
michael@0 43 size_t bytesNeeded = masm.bytesNeeded() + sizeof(JitCode *) + CodeAlignment;
michael@0 44 if (bytesNeeded >= MAX_BUFFER_SIZE)
michael@0 45 return fail(cx);
michael@0 46
michael@0 47 // ExecutableAllocator requires bytesNeeded to be word-size aligned.
michael@0 48 bytesNeeded = AlignBytes(bytesNeeded, sizeof(void *));
michael@0 49
michael@0 50 uint8_t *result = (uint8_t *)execAlloc->alloc(bytesNeeded, &pool, kind);
michael@0 51 if (!result)
michael@0 52 return fail(cx);
michael@0 53
michael@0 54 // The JitCode pointer will be stored right before the code buffer.
michael@0 55 uint8_t *codeStart = result + sizeof(JitCode *);
michael@0 56
michael@0 57 // Bump the code up to a nice alignment.
michael@0 58 codeStart = (uint8_t *)AlignBytes((uintptr_t)codeStart, CodeAlignment);
michael@0 59 uint32_t headerSize = codeStart - result;
michael@0 60 JitCode *code = JitCode::New<allowGC>(cx, codeStart, bytesNeeded - headerSize,
michael@0 61 headerSize, pool, kind);
michael@0 62 if (!code)
michael@0 63 return nullptr;
michael@0 64 if (masm.oom())
michael@0 65 return fail(cx);
michael@0 66 code->copyFrom(masm);
michael@0 67 masm.link(code);
michael@0 68 #ifdef JSGC_GENERATIONAL
michael@0 69 if (masm.embedsNurseryPointers())
michael@0 70 cx->runtime()->gcStoreBuffer.putWholeCell(code);
michael@0 71 #endif
michael@0 72 return code;
michael@0 73 }
michael@0 74
michael@0 75 public:
michael@0 76 Linker(MacroAssembler &masm)
michael@0 77 : masm(masm)
michael@0 78 {
michael@0 79 masm.finish();
michael@0 80 }
michael@0 81
michael@0 82 template <AllowGC allowGC>
michael@0 83 JitCode *newCode(JSContext *cx, JSC::CodeKind kind) {
michael@0 84 return newCode<allowGC>(cx, cx->runtime()->jitRuntime()->execAlloc(), kind);
michael@0 85 }
michael@0 86
michael@0 87 JitCode *newCodeForIonScript(JSContext *cx) {
michael@0 88 #ifdef JS_CODEGEN_ARM
michael@0 89 // ARM does not yet use implicit interrupt checks, see bug 864220.
michael@0 90 return newCode<CanGC>(cx, JSC::ION_CODE);
michael@0 91 #else
michael@0 92 // The caller must lock the runtime against interrupt requests, as the
michael@0 93 // thread requesting an interrupt may use the executable allocator below.
michael@0 94 JS_ASSERT(cx->runtime()->currentThreadOwnsInterruptLock());
michael@0 95
michael@0 96 JSC::ExecutableAllocator *alloc = cx->runtime()->jitRuntime()->getIonAlloc(cx);
michael@0 97 if (!alloc)
michael@0 98 return nullptr;
michael@0 99
michael@0 100 return newCode<CanGC>(cx, alloc, JSC::ION_CODE);
michael@0 101 #endif
michael@0 102 }
michael@0 103 };
michael@0 104
michael@0 105 } // namespace jit
michael@0 106 } // namespace js
michael@0 107
michael@0 108 #endif /* jit_IonLinker_h */

mercurial