| 1 | /* |
| 2 | * Copyright (C) 2009-2019 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | |
| 28 | #include "BatchedTransitionOptimizer.h" |
| 29 | #include "CodeBlock.h" |
| 30 | #include "Debugger.h" |
| 31 | #include "JIT.h" |
| 32 | #include "JSCInlines.h" |
| 33 | #include "LLIntEntrypoint.h" |
| 34 | #include "Parser.h" |
| 35 | #include "TypeProfiler.h" |
| 36 | #include "VMInlines.h" |
| 37 | #include <wtf/CommaPrinter.h> |
| 38 | |
| 39 | namespace JSC { |
| 40 | |
| 41 | const ClassInfo NativeExecutable::s_info = { "NativeExecutable" , &ExecutableBase::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(NativeExecutable) }; |
| 42 | |
| 43 | NativeExecutable* NativeExecutable::create(VM& vm, Ref<JITCode>&& callThunk, TaggedNativeFunction function, Ref<JITCode>&& constructThunk, TaggedNativeFunction constructor, const String& name) |
| 44 | { |
| 45 | NativeExecutable* executable; |
| 46 | executable = new (NotNull, allocateCell<NativeExecutable>(vm.heap)) NativeExecutable(vm, function, constructor); |
| 47 | executable->finishCreation(vm, WTFMove(callThunk), WTFMove(constructThunk), name); |
| 48 | return executable; |
| 49 | } |
| 50 | |
| 51 | void NativeExecutable::destroy(JSCell* cell) |
| 52 | { |
| 53 | static_cast<NativeExecutable*>(cell)->NativeExecutable::~NativeExecutable(); |
| 54 | } |
| 55 | |
| 56 | Structure* NativeExecutable::createStructure(VM& vm, JSGlobalObject* globalObject, JSValue proto) |
| 57 | { |
| 58 | return Structure::create(vm, globalObject, proto, TypeInfo(NativeExecutableType, StructureFlags), info()); |
| 59 | } |
| 60 | |
| 61 | void NativeExecutable::finishCreation(VM& vm, Ref<JITCode>&& callThunk, Ref<JITCode>&& constructThunk, const String& name) |
| 62 | { |
| 63 | Base::finishCreation(vm); |
| 64 | m_jitCodeForCall = WTFMove(callThunk); |
| 65 | m_jitCodeForConstruct = WTFMove(constructThunk); |
| 66 | m_jitCodeForCallWithArityCheck = m_jitCodeForCall->addressForCall(MustCheckArity); |
| 67 | m_jitCodeForConstructWithArityCheck = m_jitCodeForConstruct->addressForCall(MustCheckArity); |
| 68 | m_name = name; |
| 69 | |
| 70 | assertIsTaggedWith(m_jitCodeForCall->addressForCall(ArityCheckNotRequired).executableAddress(), JSEntryPtrTag); |
| 71 | assertIsTaggedWith(m_jitCodeForConstruct->addressForCall(ArityCheckNotRequired).executableAddress(), JSEntryPtrTag); |
| 72 | assertIsTaggedWith(m_jitCodeForCallWithArityCheck.executableAddress(), JSEntryPtrTag); |
| 73 | assertIsTaggedWith(m_jitCodeForConstructWithArityCheck.executableAddress(), JSEntryPtrTag); |
| 74 | } |
| 75 | |
| 76 | NativeExecutable::NativeExecutable(VM& vm, TaggedNativeFunction function, TaggedNativeFunction constructor) |
| 77 | : ExecutableBase(vm, vm.nativeExecutableStructure.get()) |
| 78 | , m_function(function) |
| 79 | , m_constructor(constructor) |
| 80 | { |
| 81 | } |
| 82 | |
| 83 | const DOMJIT::Signature* NativeExecutable::signatureFor(CodeSpecializationKind kind) const |
| 84 | { |
| 85 | ASSERT(hasJITCodeFor(kind)); |
| 86 | return generatedJITCodeFor(kind)->signature(); |
| 87 | } |
| 88 | |
| 89 | Intrinsic NativeExecutable::intrinsic() const |
| 90 | { |
| 91 | return generatedJITCodeFor(CodeForCall)->intrinsic(); |
| 92 | } |
| 93 | |
| 94 | CodeBlockHash NativeExecutable::hashFor(CodeSpecializationKind kind) const |
| 95 | { |
| 96 | if (kind == CodeForCall) |
| 97 | return CodeBlockHash(bitwise_cast<uintptr_t>(m_function)); |
| 98 | |
| 99 | RELEASE_ASSERT(kind == CodeForConstruct); |
| 100 | return CodeBlockHash(bitwise_cast<uintptr_t>(m_constructor)); |
| 101 | } |
| 102 | |
| 103 | } // namespace JSC |
| 104 | |