ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1 | // Copyright 2009 the V8 project authors. All rights reserved. |
| 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 | |
| 61 | case kExternalStringTag: |
| 62 | return GetVisitorIdForSize(kVisitDataObject, |
| 63 | kVisitDataObjectGeneric, |
| 64 | ExternalString::kSize); |
| 65 | } |
| 66 | UNREACHABLE(); |
| 67 | } |
| 68 | |
| 69 | switch (instance_type) { |
| 70 | case BYTE_ARRAY_TYPE: |
| 71 | return kVisitByteArray; |
| 72 | |
| 73 | case FIXED_ARRAY_TYPE: |
| 74 | return kVisitFixedArray; |
| 75 | |
| 76 | case ODDBALL_TYPE: |
| 77 | return kVisitOddball; |
| 78 | |
| 79 | case MAP_TYPE: |
| 80 | return kVisitMap; |
| 81 | |
| 82 | case CODE_TYPE: |
| 83 | return kVisitCode; |
| 84 | |
| 85 | case JS_GLOBAL_PROPERTY_CELL_TYPE: |
| 86 | return kVisitPropertyCell; |
| 87 | |
| 88 | case SHARED_FUNCTION_INFO_TYPE: |
| 89 | return kVisitSharedFunctionInfo; |
| 90 | |
| 91 | case PROXY_TYPE: |
| 92 | return GetVisitorIdForSize(kVisitDataObject, |
| 93 | kVisitDataObjectGeneric, |
| 94 | Proxy::kSize); |
| 95 | |
| 96 | case FILLER_TYPE: |
| 97 | return kVisitDataObjectGeneric; |
| 98 | |
| 99 | case JS_OBJECT_TYPE: |
| 100 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
| 101 | case JS_VALUE_TYPE: |
| 102 | case JS_ARRAY_TYPE: |
| 103 | case JS_REGEXP_TYPE: |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 104 | case JS_GLOBAL_PROXY_TYPE: |
| 105 | case JS_GLOBAL_OBJECT_TYPE: |
| 106 | case JS_BUILTINS_OBJECT_TYPE: |
| 107 | return GetVisitorIdForSize(kVisitJSObject, |
| 108 | kVisitJSObjectGeneric, |
| 109 | instance_size); |
| 110 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 111 | case JS_FUNCTION_TYPE: |
| 112 | return kVisitJSFunction; |
| 113 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 114 | case HEAP_NUMBER_TYPE: |
| 115 | case PIXEL_ARRAY_TYPE: |
| 116 | case EXTERNAL_BYTE_ARRAY_TYPE: |
| 117 | case EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE: |
| 118 | case EXTERNAL_SHORT_ARRAY_TYPE: |
| 119 | case EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE: |
| 120 | case EXTERNAL_INT_ARRAY_TYPE: |
| 121 | case EXTERNAL_UNSIGNED_INT_ARRAY_TYPE: |
| 122 | case EXTERNAL_FLOAT_ARRAY_TYPE: |
| 123 | return GetVisitorIdForSize(kVisitDataObject, |
| 124 | kVisitDataObjectGeneric, |
| 125 | instance_size); |
| 126 | |
| 127 | #define MAKE_STRUCT_CASE(NAME, Name, name) \ |
| 128 | case NAME##_TYPE: |
| 129 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 130 | #undef MAKE_STRUCT_CASE |
| 131 | return GetVisitorIdForSize(kVisitStruct, |
| 132 | kVisitStructGeneric, |
| 133 | instance_size); |
| 134 | |
| 135 | default: |
| 136 | UNREACHABLE(); |
| 137 | return kVisitorIdCount; |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | } } // namespace v8::internal |