]> git.saurik.com Git - apple/javascriptcore.git/blame - dfg/DFGCallArrayAllocatorSlowPathGenerator.h
JavaScriptCore-1218.33.tar.gz
[apple/javascriptcore.git] / dfg / DFGCallArrayAllocatorSlowPathGenerator.h
CommitLineData
93a37866
A
1/*
2 * Copyright (C) 2012 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#ifndef DFGCallArrayAllocatorSlowPathGenerator_h
27#define DFGCallArrayAllocatorSlowPathGenerator_h
28
29#include <wtf/Platform.h>
30
31#if ENABLE(DFG_JIT)
32
33#include "DFGCommon.h"
34#include "DFGSlowPathGenerator.h"
35#include "DFGSpeculativeJIT.h"
36#include <wtf/Vector.h>
37
38namespace JSC { namespace DFG {
39
40class CallArrayAllocatorSlowPathGenerator : public JumpingSlowPathGenerator<MacroAssembler::JumpList> {
41public:
42 CallArrayAllocatorSlowPathGenerator(
43 MacroAssembler::JumpList from, SpeculativeJIT* jit, P_DFGOperation_EStZ function,
44 GPRReg resultGPR, GPRReg storageGPR, Structure* structure, size_t size)
45 : JumpingSlowPathGenerator<MacroAssembler::JumpList>(from, jit)
46 , m_function(function)
47 , m_resultGPR(resultGPR)
48 , m_storageGPR(storageGPR)
49 , m_structure(structure)
50 , m_size(size)
51 {
52 ASSERT(size < static_cast<size_t>(std::numeric_limits<int32_t>::max()));
53 jit->silentSpillAllRegistersImpl(false, m_plans, resultGPR);
54 }
55
56protected:
57 void generateInternal(SpeculativeJIT* jit)
58 {
59 linkFrom(jit);
60 for (unsigned i = 0; i < m_plans.size(); ++i)
61 jit->silentSpill(m_plans[i]);
62 jit->callOperation(m_function, m_resultGPR, m_structure, m_size);
63 GPRReg canTrample = SpeculativeJIT::pickCanTrample(m_resultGPR);
64 for (unsigned i = m_plans.size(); i--;)
65 jit->silentFill(m_plans[i], canTrample);
66 jit->m_jit.loadPtr(MacroAssembler::Address(m_resultGPR, JSObject::butterflyOffset()), m_storageGPR);
67 jumpTo(jit);
68 }
69
70private:
71 P_DFGOperation_EStZ m_function;
72 GPRReg m_resultGPR;
73 GPRReg m_storageGPR;
74 Structure* m_structure;
75 size_t m_size;
76 Vector<SilentRegisterSavePlan, 2> m_plans;
77};
78
79class CallArrayAllocatorWithVariableSizeSlowPathGenerator : public JumpingSlowPathGenerator<MacroAssembler::JumpList> {
80public:
81 CallArrayAllocatorWithVariableSizeSlowPathGenerator(
82 MacroAssembler::JumpList from, SpeculativeJIT* jit, P_DFGOperation_EStZ function,
83 GPRReg resultGPR, Structure* contiguousStructure, Structure* arrayStorageStructure, GPRReg sizeGPR)
84 : JumpingSlowPathGenerator<MacroAssembler::JumpList>(from, jit)
85 , m_function(function)
86 , m_resultGPR(resultGPR)
87 , m_contiguousStructure(contiguousStructure)
88 , m_arrayStorageStructure(arrayStorageStructure)
89 , m_sizeGPR(sizeGPR)
90 {
91 jit->silentSpillAllRegistersImpl(false, m_plans, resultGPR);
92 }
93
94protected:
95 void generateInternal(SpeculativeJIT* jit)
96 {
97 linkFrom(jit);
98 for (unsigned i = 0; i < m_plans.size(); ++i)
99 jit->silentSpill(m_plans[i]);
100 GPRReg scratchGPR = AssemblyHelpers::selectScratchGPR(m_sizeGPR);
101 MacroAssembler::Jump bigLength = jit->m_jit.branch32(MacroAssembler::AboveOrEqual, m_sizeGPR, MacroAssembler::TrustedImm32(MIN_SPARSE_ARRAY_INDEX));
102 jit->m_jit.move(MacroAssembler::TrustedImmPtr(m_contiguousStructure), scratchGPR);
103 MacroAssembler::Jump done = jit->m_jit.jump();
104 bigLength.link(&jit->m_jit);
105 jit->m_jit.move(MacroAssembler::TrustedImmPtr(m_arrayStorageStructure), scratchGPR);
106 done.link(&jit->m_jit);
107 jit->callOperation(m_function, m_resultGPR, scratchGPR, m_sizeGPR);
108 GPRReg canTrample = SpeculativeJIT::pickCanTrample(m_resultGPR);
109 for (unsigned i = m_plans.size(); i--;)
110 jit->silentFill(m_plans[i], canTrample);
111 jumpTo(jit);
112 }
113
114private:
115 P_DFGOperation_EStZ m_function;
116 GPRReg m_resultGPR;
117 Structure* m_contiguousStructure;
118 Structure* m_arrayStorageStructure;
119 GPRReg m_sizeGPR;
120 Vector<SilentRegisterSavePlan, 2> m_plans;
121};
122
123} } // namespace JSC::DFG
124
125#endif // ENABLE(DFG_JIT)
126
127#endif // DFGCallArrayAllocatorSlowPathGenerator_h
128