svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #include "ic-inl.h" |
| 31 | #include "objects-visiting.h" |
| 32 | |
| 33 | namespace v8 { |
| 34 | namespace internal { |
| 35 | |
| 36 | |
| 37 | static inline bool IsShortcutCandidate(int type) { |
| 38 | return ((type & kShortcutTypeMask) == kShortcutTypeTag); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId( |
| 43 | int instance_type, |
| 44 | int instance_size) { |
| 45 | if (instance_type < FIRST_NONSTRING_TYPE) { |
| 46 | switch (instance_type & kStringRepresentationMask) { |
| 47 | case kSeqStringTag: |
| 48 | if ((instance_type & kStringEncodingMask) == kAsciiStringTag) { |
| 49 | return kVisitSeqAsciiString; |
| 50 | } else { |
| 51 | return kVisitSeqTwoByteString; |
| 52 | } |
| 53 | |
| 54 | case kConsStringTag: |
| 55 | if (IsShortcutCandidate(instance_type)) { |
| 56 | return kVisitShortcutCandidate; |
| 57 | } else { |
| 58 | return kVisitConsString; |
| 59 | } |
| 60 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 61 | case kSlicedStringTag: |
| 62 | return kVisitSlicedString; |
| 63 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 64 | case kExternalStringTag: |
| 65 | return GetVisitorIdForSize(kVisitDataObject, |
| 66 | kVisitDataObjectGeneric, |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 67 | instance_size); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 68 | } |
| 69 | UNREACHABLE(); |
| 70 | } |
| 71 | |
| 72 | switch (instance_type) { |
| 73 | case BYTE_ARRAY_TYPE: |
| 74 | return kVisitByteArray; |
| 75 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 76 | case FREE_SPACE_TYPE: |
| 77 | return kVisitFreeSpace; |
| 78 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 79 | case FIXED_ARRAY_TYPE: |
| 80 | return kVisitFixedArray; |
| 81 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 82 | case FIXED_DOUBLE_ARRAY_TYPE: |
| 83 | return kVisitFixedDoubleArray; |
| 84 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 85 | case ODDBALL_TYPE: |
| 86 | return kVisitOddball; |
| 87 | |
| 88 | case MAP_TYPE: |
| 89 | return kVisitMap; |
| 90 | |
| 91 | case CODE_TYPE: |
| 92 | return kVisitCode; |
| 93 | |
| 94 | case JS_GLOBAL_PROPERTY_CELL_TYPE: |
| 95 | return kVisitPropertyCell; |
| 96 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 97 | case JS_SET_TYPE: |
| 98 | return GetVisitorIdForSize(kVisitStruct, |
| 99 | kVisitStructGeneric, |
| 100 | JSSet::kSize); |
| 101 | |
| 102 | case JS_MAP_TYPE: |
| 103 | return GetVisitorIdForSize(kVisitStruct, |
| 104 | kVisitStructGeneric, |
| 105 | JSMap::kSize); |
| 106 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 107 | case JS_WEAK_MAP_TYPE: |
| 108 | return kVisitJSWeakMap; |
| 109 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 110 | case JS_REGEXP_TYPE: |
| 111 | return kVisitJSRegExp; |
| 112 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 113 | case SHARED_FUNCTION_INFO_TYPE: |
| 114 | return kVisitSharedFunctionInfo; |
| 115 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 116 | case JS_PROXY_TYPE: |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 117 | return GetVisitorIdForSize(kVisitStruct, |
| 118 | kVisitStructGeneric, |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 119 | JSProxy::kSize); |
| 120 | |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 121 | case JS_FUNCTION_PROXY_TYPE: |
| 122 | return GetVisitorIdForSize(kVisitStruct, |
| 123 | kVisitStructGeneric, |
| 124 | JSFunctionProxy::kSize); |
| 125 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 126 | case FOREIGN_TYPE: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 127 | return GetVisitorIdForSize(kVisitDataObject, |
| 128 | kVisitDataObjectGeneric, |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 129 | Foreign::kSize); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 130 | |
| 131 | case FILLER_TYPE: |
| 132 | return kVisitDataObjectGeneric; |
| 133 | |
| 134 | case JS_OBJECT_TYPE: |
| 135 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 136 | case JS_MODULE_TYPE: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 137 | case JS_VALUE_TYPE: |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 138 | case JS_DATE_TYPE: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 139 | case JS_ARRAY_TYPE: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 140 | case JS_GLOBAL_PROXY_TYPE: |
| 141 | case JS_GLOBAL_OBJECT_TYPE: |
| 142 | case JS_BUILTINS_OBJECT_TYPE: |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 143 | case JS_MESSAGE_OBJECT_TYPE: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 144 | return GetVisitorIdForSize(kVisitJSObject, |
| 145 | kVisitJSObjectGeneric, |
| 146 | instance_size); |
| 147 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 148 | case JS_FUNCTION_TYPE: |
| 149 | return kVisitJSFunction; |
| 150 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 151 | case HEAP_NUMBER_TYPE: |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 152 | case EXTERNAL_PIXEL_ARRAY_TYPE: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 153 | case EXTERNAL_BYTE_ARRAY_TYPE: |
| 154 | case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 155 | case EXTERNAL_SHORT_ARRAY_TYPE: |
| 156 | case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 157 | case EXTERNAL_INT_ARRAY_TYPE: |
| 158 | case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 159 | case EXTERNAL_FLOAT_ARRAY_TYPE: |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 160 | case EXTERNAL_DOUBLE_ARRAY_TYPE: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 161 | return GetVisitorIdForSize(kVisitDataObject, |
| 162 | kVisitDataObjectGeneric, |
| 163 | instance_size); |
| 164 | |
| 165 | #define MAKE_STRUCT_CASE(NAME, Name, name) \ |
| 166 | case NAME##_TYPE: |
| 167 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 168 | #undef MAKE_STRUCT_CASE |
| 169 | return GetVisitorIdForSize(kVisitStruct, |
| 170 | kVisitStructGeneric, |
| 171 | instance_size); |
| 172 | |
| 173 | default: |
| 174 | UNREACHABLE(); |
| 175 | return kVisitorIdCount; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | } } // namespace v8::internal |