2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
27 #include "PutByIdStatus.h"
29 #include "CodeBlock.h"
30 #include "LowLevelInterpreter.h"
31 #include "Structure.h"
32 #include "StructureChain.h"
36 PutByIdStatus
PutByIdStatus::computeFromLLInt(CodeBlock
* profiledBlock
, unsigned bytecodeIndex
, Identifier
& ident
)
38 UNUSED_PARAM(profiledBlock
);
39 UNUSED_PARAM(bytecodeIndex
);
42 Instruction
* instruction
= profiledBlock
->instructions().begin() + bytecodeIndex
;
44 Structure
* structure
= instruction
[4].u
.structure
.get();
46 return PutByIdStatus(NoInformation
, 0, 0, 0, notFound
);
48 if (instruction
[0].u
.opcode
== llint_op_put_by_id
) {
49 size_t offset
= structure
->get(*profiledBlock
->globalData(), ident
);
50 if (offset
== notFound
)
51 return PutByIdStatus(NoInformation
, 0, 0, 0, notFound
);
53 return PutByIdStatus(SimpleReplace
, structure
, 0, 0, offset
);
56 ASSERT(instruction
[0].u
.opcode
== llint_op_put_by_id_transition_direct
57 || instruction
[0].u
.opcode
== llint_op_put_by_id_transition_normal
);
59 Structure
* newStructure
= instruction
[6].u
.structure
.get();
60 StructureChain
* chain
= instruction
[7].u
.structureChain
.get();
64 size_t offset
= newStructure
->get(*profiledBlock
->globalData(), ident
);
65 if (offset
== notFound
)
66 return PutByIdStatus(NoInformation
, 0, 0, 0, notFound
);
68 return PutByIdStatus(SimpleTransition
, structure
, newStructure
, chain
, offset
);
70 return PutByIdStatus(NoInformation
, 0, 0, 0, notFound
);
74 PutByIdStatus
PutByIdStatus::computeFor(CodeBlock
* profiledBlock
, unsigned bytecodeIndex
, Identifier
& ident
)
76 UNUSED_PARAM(profiledBlock
);
77 UNUSED_PARAM(bytecodeIndex
);
79 #if ENABLE(JIT) && ENABLE(VALUE_PROFILER)
80 if (!profiledBlock
->numberOfStructureStubInfos())
81 return computeFromLLInt(profiledBlock
, bytecodeIndex
, ident
);
83 if (profiledBlock
->likelyToTakeSlowCase(bytecodeIndex
))
84 return PutByIdStatus(TakesSlowPath
, 0, 0, 0, notFound
);
86 StructureStubInfo
& stubInfo
= profiledBlock
->getStubInfo(bytecodeIndex
);
88 return computeFromLLInt(profiledBlock
, bytecodeIndex
, ident
);
90 switch (stubInfo
.accessType
) {
92 return computeFromLLInt(profiledBlock
, bytecodeIndex
, ident
);
94 case access_put_by_id_replace
: {
95 size_t offset
= stubInfo
.u
.putByIdReplace
.baseObjectStructure
->get(
96 *profiledBlock
->globalData(), ident
);
97 if (offset
!= notFound
) {
100 stubInfo
.u
.putByIdReplace
.baseObjectStructure
.get(),
104 return PutByIdStatus(TakesSlowPath
, 0, 0, 0, notFound
);
107 case access_put_by_id_transition_normal
:
108 case access_put_by_id_transition_direct
: {
109 size_t offset
= stubInfo
.u
.putByIdTransition
.structure
->get(
110 *profiledBlock
->globalData(), ident
);
111 if (offset
!= notFound
) {
112 return PutByIdStatus(
114 stubInfo
.u
.putByIdTransition
.previousStructure
.get(),
115 stubInfo
.u
.putByIdTransition
.structure
.get(),
116 stubInfo
.u
.putByIdTransition
.chain
.get(),
119 return PutByIdStatus(TakesSlowPath
, 0, 0, 0, notFound
);
123 return PutByIdStatus(TakesSlowPath
, 0, 0, 0, notFound
);
126 return PutByIdStatus(NoInformation
, 0, 0, 0, notFound
);
127 #endif // ENABLE(JIT)