| 1 | /* |
| 2 | * Copyright (C) 2012-2017 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 | #pragma once |
| 27 | |
| 28 | #if ENABLE(DFG_JIT) |
| 29 | |
| 30 | #include "DFGSlowPathGenerator.h" |
| 31 | #include "DFGSpeculativeJIT.h" |
| 32 | #include <wtf/Vector.h> |
| 33 | |
| 34 | namespace JSC { namespace DFG { |
| 35 | |
| 36 | class CallArrayAllocatorSlowPathGenerator : public JumpingSlowPathGenerator<MacroAssembler::JumpList> { |
| 37 | public: |
| 38 | CallArrayAllocatorSlowPathGenerator( |
| 39 | MacroAssembler::JumpList from, SpeculativeJIT* jit, P_JITOperation_EStZB function, |
| 40 | GPRReg resultGPR, GPRReg storageGPR, RegisteredStructure structure, size_t size) |
| 41 | : JumpingSlowPathGenerator<MacroAssembler::JumpList>(from, jit) |
| 42 | , m_function(function) |
| 43 | , m_resultGPR(resultGPR) |
| 44 | , m_storageGPR(storageGPR) |
| 45 | , m_size(size) |
| 46 | , m_structure(structure) |
| 47 | { |
| 48 | ASSERT(size < static_cast<size_t>(std::numeric_limits<int32_t>::max())); |
| 49 | jit->silentSpillAllRegistersImpl(false, m_plans, resultGPR); |
| 50 | } |
| 51 | |
| 52 | protected: |
| 53 | void generateInternal(SpeculativeJIT* jit) override |
| 54 | { |
| 55 | linkFrom(jit); |
| 56 | for (unsigned i = 0; i < m_plans.size(); ++i) |
| 57 | jit->silentSpill(m_plans[i]); |
| 58 | jit->callOperation(m_function, m_resultGPR, m_structure, m_size, m_storageGPR); |
| 59 | for (unsigned i = m_plans.size(); i--;) |
| 60 | jit->silentFill(m_plans[i]); |
| 61 | jit->m_jit.exceptionCheck(); |
| 62 | jit->m_jit.loadPtr(MacroAssembler::Address(m_resultGPR, JSObject::butterflyOffset()), m_storageGPR); |
| 63 | jumpTo(jit); |
| 64 | } |
| 65 | |
| 66 | private: |
| 67 | P_JITOperation_EStZB m_function; |
| 68 | GPRReg m_resultGPR; |
| 69 | GPRReg m_storageGPR; |
| 70 | int m_size; |
| 71 | RegisteredStructure m_structure; |
| 72 | Vector<SilentRegisterSavePlan, 2> m_plans; |
| 73 | }; |
| 74 | |
| 75 | class CallArrayAllocatorWithVariableSizeSlowPathGenerator : public JumpingSlowPathGenerator<MacroAssembler::JumpList> { |
| 76 | public: |
| 77 | CallArrayAllocatorWithVariableSizeSlowPathGenerator( |
| 78 | MacroAssembler::JumpList from, SpeculativeJIT* jit, P_JITOperation_EStZB function, |
| 79 | GPRReg resultGPR, RegisteredStructure contiguousStructure, RegisteredStructure arrayStorageStructure, GPRReg sizeGPR, GPRReg storageGPR) |
| 80 | : JumpingSlowPathGenerator<MacroAssembler::JumpList>(from, jit) |
| 81 | , m_function(function) |
| 82 | , m_contiguousStructure(contiguousStructure) |
| 83 | , m_arrayStorageOrContiguousStructure(arrayStorageStructure) |
| 84 | , m_resultGPR(resultGPR) |
| 85 | , m_sizeGPR(sizeGPR) |
| 86 | , m_storageGPR(storageGPR) |
| 87 | { |
| 88 | jit->silentSpillAllRegistersImpl(false, m_plans, resultGPR); |
| 89 | } |
| 90 | |
| 91 | protected: |
| 92 | void generateInternal(SpeculativeJIT* jit) override |
| 93 | { |
| 94 | linkFrom(jit); |
| 95 | for (unsigned i = 0; i < m_plans.size(); ++i) |
| 96 | jit->silentSpill(m_plans[i]); |
| 97 | GPRReg scratchGPR = AssemblyHelpers::selectScratchGPR(m_sizeGPR, m_storageGPR); |
| 98 | if (m_contiguousStructure.get() != m_arrayStorageOrContiguousStructure.get()) { |
| 99 | MacroAssembler::Jump bigLength = jit->m_jit.branch32(MacroAssembler::AboveOrEqual, m_sizeGPR, MacroAssembler::TrustedImm32(MIN_ARRAY_STORAGE_CONSTRUCTION_LENGTH)); |
| 100 | jit->m_jit.move(SpeculativeJIT::TrustedImmPtr(m_contiguousStructure), scratchGPR); |
| 101 | MacroAssembler::Jump done = jit->m_jit.jump(); |
| 102 | bigLength.link(&jit->m_jit); |
| 103 | jit->m_jit.move(SpeculativeJIT::TrustedImmPtr(m_arrayStorageOrContiguousStructure), scratchGPR); |
| 104 | done.link(&jit->m_jit); |
| 105 | } else |
| 106 | jit->m_jit.move(SpeculativeJIT::TrustedImmPtr(m_contiguousStructure), scratchGPR); |
| 107 | jit->callOperation(m_function, m_resultGPR, scratchGPR, m_sizeGPR, m_storageGPR); |
| 108 | for (unsigned i = m_plans.size(); i--;) |
| 109 | jit->silentFill(m_plans[i]); |
| 110 | jit->m_jit.exceptionCheck(); |
| 111 | jumpTo(jit); |
| 112 | } |
| 113 | |
| 114 | private: |
| 115 | P_JITOperation_EStZB m_function; |
| 116 | RegisteredStructure m_contiguousStructure; |
| 117 | RegisteredStructure m_arrayStorageOrContiguousStructure; |
| 118 | GPRReg m_resultGPR; |
| 119 | GPRReg m_sizeGPR; |
| 120 | GPRReg m_storageGPR; |
| 121 | Vector<SilentRegisterSavePlan, 2> m_plans; |
| 122 | }; |
| 123 | |
| 124 | class CallArrayAllocatorWithVariableStructureVariableSizeSlowPathGenerator : public JumpingSlowPathGenerator<MacroAssembler::JumpList> { |
| 125 | public: |
| 126 | CallArrayAllocatorWithVariableStructureVariableSizeSlowPathGenerator( |
| 127 | MacroAssembler::JumpList from, SpeculativeJIT* jit, P_JITOperation_EStZB function, |
| 128 | GPRReg resultGPR, GPRReg structureGPR, GPRReg sizeGPR, GPRReg storageGPR) |
| 129 | : JumpingSlowPathGenerator<MacroAssembler::JumpList>(from, jit) |
| 130 | , m_function(function) |
| 131 | , m_resultGPR(resultGPR) |
| 132 | , m_structureGPR(structureGPR) |
| 133 | , m_sizeGPR(sizeGPR) |
| 134 | , m_storageGPR(storageGPR) |
| 135 | { |
| 136 | jit->silentSpillAllRegistersImpl(false, m_plans, resultGPR); |
| 137 | } |
| 138 | |
| 139 | protected: |
| 140 | void generateInternal(SpeculativeJIT* jit) override |
| 141 | { |
| 142 | linkFrom(jit); |
| 143 | for (unsigned i = 0; i < m_plans.size(); ++i) |
| 144 | jit->silentSpill(m_plans[i]); |
| 145 | jit->callOperation(m_function, m_resultGPR, m_structureGPR, m_sizeGPR, m_storageGPR); |
| 146 | for (unsigned i = m_plans.size(); i--;) |
| 147 | jit->silentFill(m_plans[i]); |
| 148 | jit->m_jit.exceptionCheck(); |
| 149 | jumpTo(jit); |
| 150 | } |
| 151 | |
| 152 | private: |
| 153 | P_JITOperation_EStZB m_function; |
| 154 | GPRReg m_resultGPR; |
| 155 | GPRReg m_structureGPR; |
| 156 | GPRReg m_sizeGPR; |
| 157 | GPRReg m_storageGPR; |
| 158 | Vector<SilentRegisterSavePlan, 2> m_plans; |
| 159 | }; |
| 160 | |
| 161 | } } // namespace JSC::DFG |
| 162 | |
| 163 | #endif // ENABLE(DFG_JIT) |
| 164 | |