1/*
2 * Copyright (C) 2016-2018 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(JIT)
29
30#include "CodeLocation.h"
31#include "PropertyOffset.h"
32
33namespace JSC {
34
35class JSArray;
36class Structure;
37class StructureStubInfo;
38class VM;
39
40class InlineAccess {
41public:
42
43 // This is the maximum between inline and out of line self access cases.
44 static constexpr size_t sizeForPropertyAccess()
45 {
46#if CPU(X86_64)
47 return 26;
48#elif CPU(X86)
49 return 27;
50#elif CPU(ARM64)
51 return 40;
52#elif CPU(ARM_THUMB2)
53 return 48;
54#elif CPU(MIPS)
55 return 72;
56#else
57#error "unsupported platform"
58#endif
59 }
60
61 // This is the maximum between inline and out of line property replace cases.
62 static constexpr size_t sizeForPropertyReplace()
63 {
64#if CPU(X86_64)
65 return 26;
66#elif CPU(X86)
67 return 27;
68#elif CPU(ARM64)
69 return 40;
70#elif CPU(ARM_THUMB2)
71 return 48;
72#elif CPU(MIPS)
73 return 72;
74#else
75#error "unsupported platform"
76#endif
77 }
78
79 // FIXME: Make this constexpr when GCC is able to compile std::max() inside a constexpr function.
80 // https://bugs.webkit.org/show_bug.cgi?id=159436
81 //
82 // This is the maximum between array length, string length, and regular self access sizes.
83 ALWAYS_INLINE static size_t sizeForLengthAccess()
84 {
85#if CPU(X86_64)
86 size_t size = 43;
87#elif CPU(X86)
88 size_t size = 27;
89#elif CPU(ARM64)
90 size_t size = 44;
91#elif CPU(ARM_THUMB2)
92 size_t size = 30;
93#elif CPU(MIPS)
94 size_t size = 56;
95#else
96#error "unsupported platform"
97#endif
98 return std::max(size, sizeForPropertyAccess());
99 }
100
101 static bool generateSelfPropertyAccess(StructureStubInfo&, Structure*, PropertyOffset);
102 static bool canGenerateSelfPropertyReplace(StructureStubInfo&, PropertyOffset);
103 static bool generateSelfPropertyReplace(StructureStubInfo&, Structure*, PropertyOffset);
104 static bool isCacheableArrayLength(StructureStubInfo&, JSArray*);
105 static bool isCacheableStringLength(StructureStubInfo&);
106 static bool generateArrayLength(StructureStubInfo&, JSArray*);
107 static void rewireStubAsJump(StructureStubInfo&, CodeLocationLabel<JITStubRoutinePtrTag>);
108 static bool generateSelfInAccess(StructureStubInfo&, Structure*);
109 static bool generateStringLength(StructureStubInfo&);
110
111 // This is helpful when determining the size of an IC on
112 // various platforms. When adding a new type of IC, implement
113 // its placeholder code here, and log the size. That way we
114 // can intelligently choose sizes on various platforms.
115 JS_EXPORT_PRIVATE NO_RETURN_DUE_TO_CRASH static void dumpCacheSizesAndCrash();
116};
117
118} // namespace JSC
119
120#endif // ENABLE(JIT)
121