]> git.saurik.com Git - apple/javascriptcore.git/blame - bytecode/PutByIdStatus.cpp
JavaScriptCore-1097.3.3.tar.gz
[apple/javascriptcore.git] / bytecode / PutByIdStatus.cpp
CommitLineData
6fe7ccc8
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#include "config.h"
27#include "PutByIdStatus.h"
28
29#include "CodeBlock.h"
30#include "LowLevelInterpreter.h"
31#include "Structure.h"
32#include "StructureChain.h"
33
34namespace JSC {
35
36PutByIdStatus PutByIdStatus::computeFromLLInt(CodeBlock* profiledBlock, unsigned bytecodeIndex, Identifier& ident)
37{
38 UNUSED_PARAM(profiledBlock);
39 UNUSED_PARAM(bytecodeIndex);
40 UNUSED_PARAM(ident);
41#if ENABLE(LLINT)
42 Instruction* instruction = profiledBlock->instructions().begin() + bytecodeIndex;
43
44 Structure* structure = instruction[4].u.structure.get();
45 if (!structure)
46 return PutByIdStatus(NoInformation, 0, 0, 0, notFound);
47
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);
52
53 return PutByIdStatus(SimpleReplace, structure, 0, 0, offset);
54 }
55
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);
58
59 Structure* newStructure = instruction[6].u.structure.get();
60 StructureChain* chain = instruction[7].u.structureChain.get();
61 ASSERT(newStructure);
62 ASSERT(chain);
63
64 size_t offset = newStructure->get(*profiledBlock->globalData(), ident);
65 if (offset == notFound)
66 return PutByIdStatus(NoInformation, 0, 0, 0, notFound);
67
68 return PutByIdStatus(SimpleTransition, structure, newStructure, chain, offset);
69#else
70 return PutByIdStatus(NoInformation, 0, 0, 0, notFound);
71#endif
72}
73
74PutByIdStatus PutByIdStatus::computeFor(CodeBlock* profiledBlock, unsigned bytecodeIndex, Identifier& ident)
75{
76 UNUSED_PARAM(profiledBlock);
77 UNUSED_PARAM(bytecodeIndex);
78 UNUSED_PARAM(ident);
79#if ENABLE(JIT) && ENABLE(VALUE_PROFILER)
80 if (!profiledBlock->numberOfStructureStubInfos())
81 return computeFromLLInt(profiledBlock, bytecodeIndex, ident);
82
83 if (profiledBlock->likelyToTakeSlowCase(bytecodeIndex))
84 return PutByIdStatus(TakesSlowPath, 0, 0, 0, notFound);
85
86 StructureStubInfo& stubInfo = profiledBlock->getStubInfo(bytecodeIndex);
87 if (!stubInfo.seen)
88 return computeFromLLInt(profiledBlock, bytecodeIndex, ident);
89
90 switch (stubInfo.accessType) {
91 case access_unset:
92 return computeFromLLInt(profiledBlock, bytecodeIndex, ident);
93
94 case access_put_by_id_replace: {
95 size_t offset = stubInfo.u.putByIdReplace.baseObjectStructure->get(
96 *profiledBlock->globalData(), ident);
97 if (offset != notFound) {
98 return PutByIdStatus(
99 SimpleReplace,
100 stubInfo.u.putByIdReplace.baseObjectStructure.get(),
101 0, 0,
102 offset);
103 }
104 return PutByIdStatus(TakesSlowPath, 0, 0, 0, notFound);
105 }
106
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(
113 SimpleTransition,
114 stubInfo.u.putByIdTransition.previousStructure.get(),
115 stubInfo.u.putByIdTransition.structure.get(),
116 stubInfo.u.putByIdTransition.chain.get(),
117 offset);
118 }
119 return PutByIdStatus(TakesSlowPath, 0, 0, 0, notFound);
120 }
121
122 default:
123 return PutByIdStatus(TakesSlowPath, 0, 0, 0, notFound);
124 }
125#else // ENABLE(JIT)
126 return PutByIdStatus(NoInformation, 0, 0, 0, notFound);
127#endif // ENABLE(JIT)
128}
129
130} // namespace JSC
131