danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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 | // Review notes: |
| 29 | // |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 30 | // - The use of macros in these inline functions may seem superfluous |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 31 | // but it is absolutely needed to make sure gcc generates optimal |
| 32 | // code. gcc is not happy when attempting to inline too deep. |
| 33 | // |
| 34 | |
| 35 | #ifndef V8_OBJECTS_INL_H_ |
| 36 | #define V8_OBJECTS_INL_H_ |
| 37 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 38 | #include "elements.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 39 | #include "objects.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 40 | #include "contexts.h" |
| 41 | #include "conversions-inl.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 42 | #include "heap.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 43 | #include "isolate.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 44 | #include "property.h" |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 45 | #include "spaces.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 46 | #include "store-buffer.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 47 | #include "v8memory.h" |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 48 | #include "factory.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 49 | #include "incremental-marking.h" |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 50 | #include "transitions-inl.h" |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 51 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 52 | namespace v8 { |
| 53 | namespace internal { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 54 | |
| 55 | PropertyDetails::PropertyDetails(Smi* smi) { |
| 56 | value_ = smi->value(); |
| 57 | } |
| 58 | |
| 59 | |
| 60 | Smi* PropertyDetails::AsSmi() { |
| 61 | return Smi::FromInt(value_); |
| 62 | } |
| 63 | |
| 64 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 65 | PropertyDetails PropertyDetails::AsDeleted() { |
ager@chromium.org | 378b34e | 2011-01-28 08:04:38 +0000 | [diff] [blame] | 66 | Smi* smi = Smi::FromInt(value_ | DeletedField::encode(1)); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 67 | return PropertyDetails(smi); |
| 68 | } |
| 69 | |
| 70 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 71 | #define TYPE_CHECKER(type, instancetype) \ |
| 72 | bool Object::Is##type() { \ |
| 73 | return Object::IsHeapObject() && \ |
| 74 | HeapObject::cast(this)->map()->instance_type() == instancetype; \ |
| 75 | } |
| 76 | |
| 77 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 78 | #define CAST_ACCESSOR(type) \ |
| 79 | type* type::cast(Object* object) { \ |
| 80 | ASSERT(object->Is##type()); \ |
| 81 | return reinterpret_cast<type*>(object); \ |
| 82 | } |
| 83 | |
| 84 | |
| 85 | #define INT_ACCESSORS(holder, name, offset) \ |
| 86 | int holder::name() { return READ_INT_FIELD(this, offset); } \ |
| 87 | void holder::set_##name(int value) { WRITE_INT_FIELD(this, offset, value); } |
| 88 | |
| 89 | |
| 90 | #define ACCESSORS(holder, name, type, offset) \ |
| 91 | type* holder::name() { return type::cast(READ_FIELD(this, offset)); } \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 92 | void holder::set_##name(type* value, WriteBarrierMode mode) { \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 93 | WRITE_FIELD(this, offset, value); \ |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 94 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 98 | // Getter that returns a tagged Smi and setter that writes a tagged Smi. |
| 99 | #define ACCESSORS_TO_SMI(holder, name, offset) \ |
| 100 | Smi* holder::name() { return Smi::cast(READ_FIELD(this, offset)); } \ |
| 101 | void holder::set_##name(Smi* value, WriteBarrierMode mode) { \ |
| 102 | WRITE_FIELD(this, offset, value); \ |
| 103 | } |
| 104 | |
| 105 | |
| 106 | // Getter that returns a Smi as an int and writes an int as a Smi. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 107 | #define SMI_ACCESSORS(holder, name, offset) \ |
| 108 | int holder::name() { \ |
| 109 | Object* value = READ_FIELD(this, offset); \ |
| 110 | return Smi::cast(value)->value(); \ |
| 111 | } \ |
| 112 | void holder::set_##name(int value) { \ |
| 113 | WRITE_FIELD(this, offset, Smi::FromInt(value)); \ |
| 114 | } |
| 115 | |
| 116 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 117 | #define BOOL_GETTER(holder, field, name, offset) \ |
| 118 | bool holder::name() { \ |
| 119 | return BooleanBit::get(field(), offset); \ |
| 120 | } \ |
| 121 | |
| 122 | |
| 123 | #define BOOL_ACCESSORS(holder, field, name, offset) \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 124 | bool holder::name() { \ |
| 125 | return BooleanBit::get(field(), offset); \ |
| 126 | } \ |
| 127 | void holder::set_##name(bool value) { \ |
| 128 | set_##field(BooleanBit::set(field(), offset, value)); \ |
| 129 | } |
| 130 | |
| 131 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 132 | bool Object::IsFixedArrayBase() { |
| 133 | return IsFixedArray() || IsFixedDoubleArray(); |
| 134 | } |
| 135 | |
| 136 | |
sgjesse@chromium.org | 900d3b7 | 2009-08-07 11:24:25 +0000 | [diff] [blame] | 137 | bool Object::IsInstanceOf(FunctionTemplateInfo* expected) { |
| 138 | // There is a constraint on the object; check. |
| 139 | if (!this->IsJSObject()) return false; |
| 140 | // Fetch the constructor function of the object. |
| 141 | Object* cons_obj = JSObject::cast(this)->map()->constructor(); |
| 142 | if (!cons_obj->IsJSFunction()) return false; |
| 143 | JSFunction* fun = JSFunction::cast(cons_obj); |
| 144 | // Iterate through the chain of inheriting function templates to |
| 145 | // see if the required one occurs. |
| 146 | for (Object* type = fun->shared()->function_data(); |
| 147 | type->IsFunctionTemplateInfo(); |
| 148 | type = FunctionTemplateInfo::cast(type)->parent_template()) { |
| 149 | if (type == expected) return true; |
| 150 | } |
| 151 | // Didn't find the required type in the inheritance chain. |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 156 | bool Object::IsSmi() { |
| 157 | return HAS_SMI_TAG(this); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | bool Object::IsHeapObject() { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 162 | return Internals::HasHeapObjectTag(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 166 | bool Object::NonFailureIsHeapObject() { |
| 167 | ASSERT(!this->IsFailure()); |
| 168 | return (reinterpret_cast<intptr_t>(this) & kSmiTagMask) != 0; |
| 169 | } |
| 170 | |
| 171 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 172 | TYPE_CHECKER(HeapNumber, HEAP_NUMBER_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 173 | |
| 174 | |
| 175 | bool Object::IsString() { |
| 176 | return Object::IsHeapObject() |
| 177 | && HeapObject::cast(this)->map()->instance_type() < FIRST_NONSTRING_TYPE; |
| 178 | } |
| 179 | |
| 180 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 181 | bool Object::IsSpecObject() { |
| 182 | return Object::IsHeapObject() |
| 183 | && HeapObject::cast(this)->map()->instance_type() >= FIRST_SPEC_OBJECT_TYPE; |
| 184 | } |
| 185 | |
| 186 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 187 | bool Object::IsSpecFunction() { |
| 188 | if (!Object::IsHeapObject()) return false; |
| 189 | InstanceType type = HeapObject::cast(this)->map()->instance_type(); |
| 190 | return type == JS_FUNCTION_TYPE || type == JS_FUNCTION_PROXY_TYPE; |
| 191 | } |
| 192 | |
| 193 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 194 | bool Object::IsSymbol() { |
| 195 | if (!this->IsHeapObject()) return false; |
| 196 | uint32_t type = HeapObject::cast(this)->map()->instance_type(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 197 | // Because the symbol tag is non-zero and no non-string types have the |
| 198 | // symbol bit set we can test for symbols with a very simple test |
| 199 | // operation. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 200 | STATIC_ASSERT(kSymbolTag != 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 201 | ASSERT(kNotStringTag + kIsSymbolMask > LAST_TYPE); |
| 202 | return (type & kIsSymbolMask) != 0; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | |
| 206 | bool Object::IsConsString() { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 207 | if (!IsString()) return false; |
| 208 | return StringShape(String::cast(this)).IsCons(); |
| 209 | } |
| 210 | |
| 211 | |
| 212 | bool Object::IsSlicedString() { |
| 213 | if (!IsString()) return false; |
| 214 | return StringShape(String::cast(this)).IsSliced(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 218 | bool Object::IsSeqString() { |
| 219 | if (!IsString()) return false; |
| 220 | return StringShape(String::cast(this)).IsSequential(); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | bool Object::IsSeqAsciiString() { |
| 225 | if (!IsString()) return false; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 226 | return StringShape(String::cast(this)).IsSequential() && |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 227 | String::cast(this)->IsAsciiRepresentation(); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
| 231 | bool Object::IsSeqTwoByteString() { |
| 232 | if (!IsString()) return false; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 233 | return StringShape(String::cast(this)).IsSequential() && |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 234 | String::cast(this)->IsTwoByteRepresentation(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
| 238 | bool Object::IsExternalString() { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 239 | if (!IsString()) return false; |
| 240 | return StringShape(String::cast(this)).IsExternal(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | |
| 244 | bool Object::IsExternalAsciiString() { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 245 | if (!IsString()) return false; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 246 | return StringShape(String::cast(this)).IsExternal() && |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 247 | String::cast(this)->IsAsciiRepresentation(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | |
| 251 | bool Object::IsExternalTwoByteString() { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 252 | if (!IsString()) return false; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 253 | return StringShape(String::cast(this)).IsExternal() && |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 254 | String::cast(this)->IsTwoByteRepresentation(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 255 | } |
| 256 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 257 | bool Object::HasValidElements() { |
| 258 | // Dictionary is covered under FixedArray. |
| 259 | return IsFixedArray() || IsFixedDoubleArray() || IsExternalArray(); |
| 260 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 261 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 262 | StringShape::StringShape(String* str) |
| 263 | : type_(str->map()->instance_type()) { |
| 264 | set_valid(); |
| 265 | ASSERT((type_ & kIsNotStringMask) == kStringTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 269 | StringShape::StringShape(Map* map) |
| 270 | : type_(map->instance_type()) { |
| 271 | set_valid(); |
| 272 | ASSERT((type_ & kIsNotStringMask) == kStringTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 276 | StringShape::StringShape(InstanceType t) |
| 277 | : type_(static_cast<uint32_t>(t)) { |
| 278 | set_valid(); |
| 279 | ASSERT((type_ & kIsNotStringMask) == kStringTag); |
| 280 | } |
| 281 | |
| 282 | |
| 283 | bool StringShape::IsSymbol() { |
| 284 | ASSERT(valid()); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 285 | STATIC_ASSERT(kSymbolTag != 0); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 286 | return (type_ & kIsSymbolMask) != 0; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 290 | bool String::IsAsciiRepresentation() { |
| 291 | uint32_t type = map()->instance_type(); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 292 | return (type & kStringEncodingMask) == kAsciiStringTag; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 296 | bool String::IsTwoByteRepresentation() { |
| 297 | uint32_t type = map()->instance_type(); |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 298 | return (type & kStringEncodingMask) == kTwoByteStringTag; |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 302 | bool String::IsAsciiRepresentationUnderneath() { |
| 303 | uint32_t type = map()->instance_type(); |
| 304 | STATIC_ASSERT(kIsIndirectStringTag != 0); |
| 305 | STATIC_ASSERT((kIsIndirectStringMask & kStringEncodingMask) == 0); |
| 306 | ASSERT(IsFlat()); |
| 307 | switch (type & (kIsIndirectStringMask | kStringEncodingMask)) { |
| 308 | case kAsciiStringTag: |
| 309 | return true; |
| 310 | case kTwoByteStringTag: |
| 311 | return false; |
| 312 | default: // Cons or sliced string. Need to go deeper. |
| 313 | return GetUnderlying()->IsAsciiRepresentation(); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | |
| 318 | bool String::IsTwoByteRepresentationUnderneath() { |
| 319 | uint32_t type = map()->instance_type(); |
| 320 | STATIC_ASSERT(kIsIndirectStringTag != 0); |
| 321 | STATIC_ASSERT((kIsIndirectStringMask & kStringEncodingMask) == 0); |
| 322 | ASSERT(IsFlat()); |
| 323 | switch (type & (kIsIndirectStringMask | kStringEncodingMask)) { |
| 324 | case kAsciiStringTag: |
| 325 | return false; |
| 326 | case kTwoByteStringTag: |
| 327 | return true; |
| 328 | default: // Cons or sliced string. Need to go deeper. |
| 329 | return GetUnderlying()->IsTwoByteRepresentation(); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | |
ricow@chromium.org | 5ad5ace | 2010-06-23 09:06:43 +0000 | [diff] [blame] | 334 | bool String::HasOnlyAsciiChars() { |
| 335 | uint32_t type = map()->instance_type(); |
| 336 | return (type & kStringEncodingMask) == kAsciiStringTag || |
| 337 | (type & kAsciiDataHintMask) == kAsciiDataHintTag; |
ricow@chromium.org | aa1b616 | 2010-03-29 07:44:58 +0000 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 341 | bool StringShape::IsCons() { |
| 342 | return (type_ & kStringRepresentationMask) == kConsStringTag; |
| 343 | } |
| 344 | |
| 345 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 346 | bool StringShape::IsSliced() { |
| 347 | return (type_ & kStringRepresentationMask) == kSlicedStringTag; |
| 348 | } |
| 349 | |
| 350 | |
| 351 | bool StringShape::IsIndirect() { |
| 352 | return (type_ & kIsIndirectStringMask) == kIsIndirectStringTag; |
| 353 | } |
| 354 | |
| 355 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 356 | bool StringShape::IsExternal() { |
| 357 | return (type_ & kStringRepresentationMask) == kExternalStringTag; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | bool StringShape::IsSequential() { |
| 362 | return (type_ & kStringRepresentationMask) == kSeqStringTag; |
| 363 | } |
| 364 | |
| 365 | |
| 366 | StringRepresentationTag StringShape::representation_tag() { |
| 367 | uint32_t tag = (type_ & kStringRepresentationMask); |
| 368 | return static_cast<StringRepresentationTag>(tag); |
| 369 | } |
| 370 | |
| 371 | |
ricow@chromium.org | ddd545c | 2011-08-24 12:02:41 +0000 | [diff] [blame] | 372 | uint32_t StringShape::encoding_tag() { |
| 373 | return type_ & kStringEncodingMask; |
| 374 | } |
| 375 | |
| 376 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 377 | uint32_t StringShape::full_representation_tag() { |
| 378 | return (type_ & (kStringRepresentationMask | kStringEncodingMask)); |
| 379 | } |
| 380 | |
| 381 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 382 | STATIC_CHECK((kStringRepresentationMask | kStringEncodingMask) == |
| 383 | Internals::kFullStringRepresentationMask); |
| 384 | |
| 385 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 386 | bool StringShape::IsSequentialAscii() { |
| 387 | return full_representation_tag() == (kSeqStringTag | kAsciiStringTag); |
| 388 | } |
| 389 | |
| 390 | |
| 391 | bool StringShape::IsSequentialTwoByte() { |
ager@chromium.org | 80787b7 | 2009-04-17 10:24:24 +0000 | [diff] [blame] | 392 | return full_representation_tag() == (kSeqStringTag | kTwoByteStringTag); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
| 396 | bool StringShape::IsExternalAscii() { |
| 397 | return full_representation_tag() == (kExternalStringTag | kAsciiStringTag); |
| 398 | } |
| 399 | |
| 400 | |
| 401 | bool StringShape::IsExternalTwoByte() { |
ager@chromium.org | 80787b7 | 2009-04-17 10:24:24 +0000 | [diff] [blame] | 402 | return full_representation_tag() == (kExternalStringTag | kTwoByteStringTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 406 | STATIC_CHECK((kExternalStringTag | kTwoByteStringTag) == |
| 407 | Internals::kExternalTwoByteRepresentationTag); |
| 408 | |
| 409 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 410 | uc32 FlatStringReader::Get(int index) { |
| 411 | ASSERT(0 <= index && index <= length_); |
| 412 | if (is_ascii_) { |
| 413 | return static_cast<const byte*>(start_)[index]; |
| 414 | } else { |
| 415 | return static_cast<const uc16*>(start_)[index]; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 420 | bool Object::IsNumber() { |
| 421 | return IsSmi() || IsHeapNumber(); |
| 422 | } |
| 423 | |
| 424 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 425 | TYPE_CHECKER(ByteArray, BYTE_ARRAY_TYPE) |
| 426 | TYPE_CHECKER(FreeSpace, FREE_SPACE_TYPE) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 427 | |
| 428 | |
| 429 | bool Object::IsFiller() { |
| 430 | if (!Object::IsHeapObject()) return false; |
| 431 | InstanceType instance_type = HeapObject::cast(this)->map()->instance_type(); |
| 432 | return instance_type == FREE_SPACE_TYPE || instance_type == FILLER_TYPE; |
| 433 | } |
| 434 | |
| 435 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 436 | TYPE_CHECKER(ExternalPixelArray, EXTERNAL_PIXEL_ARRAY_TYPE) |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 437 | |
| 438 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 439 | bool Object::IsExternalArray() { |
| 440 | if (!Object::IsHeapObject()) |
| 441 | return false; |
| 442 | InstanceType instance_type = |
| 443 | HeapObject::cast(this)->map()->instance_type(); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 444 | return (instance_type >= FIRST_EXTERNAL_ARRAY_TYPE && |
| 445 | instance_type <= LAST_EXTERNAL_ARRAY_TYPE); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 449 | TYPE_CHECKER(ExternalByteArray, EXTERNAL_BYTE_ARRAY_TYPE) |
| 450 | TYPE_CHECKER(ExternalUnsignedByteArray, EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) |
| 451 | TYPE_CHECKER(ExternalShortArray, EXTERNAL_SHORT_ARRAY_TYPE) |
| 452 | TYPE_CHECKER(ExternalUnsignedShortArray, EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) |
| 453 | TYPE_CHECKER(ExternalIntArray, EXTERNAL_INT_ARRAY_TYPE) |
| 454 | TYPE_CHECKER(ExternalUnsignedIntArray, EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) |
| 455 | TYPE_CHECKER(ExternalFloatArray, EXTERNAL_FLOAT_ARRAY_TYPE) |
| 456 | TYPE_CHECKER(ExternalDoubleArray, EXTERNAL_DOUBLE_ARRAY_TYPE) |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 457 | |
| 458 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 459 | bool MaybeObject::IsFailure() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 460 | return HAS_FAILURE_TAG(this); |
| 461 | } |
| 462 | |
| 463 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 464 | bool MaybeObject::IsRetryAfterGC() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 465 | return HAS_FAILURE_TAG(this) |
| 466 | && Failure::cast(this)->type() == Failure::RETRY_AFTER_GC; |
| 467 | } |
| 468 | |
| 469 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 470 | bool MaybeObject::IsOutOfMemory() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 471 | return HAS_FAILURE_TAG(this) |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 472 | && Failure::cast(this)->IsOutOfMemoryException(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 476 | bool MaybeObject::IsException() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 477 | return this == Failure::Exception(); |
| 478 | } |
| 479 | |
| 480 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 481 | bool MaybeObject::IsTheHole() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 482 | return !IsFailure() && ToObjectUnchecked()->IsTheHole(); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | |
| 486 | Failure* Failure::cast(MaybeObject* obj) { |
| 487 | ASSERT(HAS_FAILURE_TAG(obj)); |
| 488 | return reinterpret_cast<Failure*>(obj); |
| 489 | } |
| 490 | |
| 491 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 492 | bool Object::IsJSReceiver() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 493 | STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 494 | return IsHeapObject() && |
| 495 | HeapObject::cast(this)->map()->instance_type() >= FIRST_JS_RECEIVER_TYPE; |
| 496 | } |
| 497 | |
| 498 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 499 | bool Object::IsJSObject() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 500 | STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE); |
| 501 | return IsHeapObject() && |
| 502 | HeapObject::cast(this)->map()->instance_type() >= FIRST_JS_OBJECT_TYPE; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | |
| 506 | bool Object::IsJSProxy() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 507 | if (!Object::IsHeapObject()) return false; |
| 508 | InstanceType type = HeapObject::cast(this)->map()->instance_type(); |
| 509 | return FIRST_JS_PROXY_TYPE <= type && type <= LAST_JS_PROXY_TYPE; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 513 | TYPE_CHECKER(JSFunctionProxy, JS_FUNCTION_PROXY_TYPE) |
| 514 | TYPE_CHECKER(JSSet, JS_SET_TYPE) |
| 515 | TYPE_CHECKER(JSMap, JS_MAP_TYPE) |
| 516 | TYPE_CHECKER(JSWeakMap, JS_WEAK_MAP_TYPE) |
| 517 | TYPE_CHECKER(JSContextExtensionObject, JS_CONTEXT_EXTENSION_OBJECT_TYPE) |
| 518 | TYPE_CHECKER(Map, MAP_TYPE) |
| 519 | TYPE_CHECKER(FixedArray, FIXED_ARRAY_TYPE) |
| 520 | TYPE_CHECKER(FixedDoubleArray, FIXED_DOUBLE_ARRAY_TYPE) |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 521 | |
| 522 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 523 | bool Object::IsDescriptorArray() { |
| 524 | return IsFixedArray(); |
| 525 | } |
| 526 | |
| 527 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 528 | bool Object::IsTransitionArray() { |
| 529 | return IsFixedArray(); |
| 530 | } |
| 531 | |
| 532 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 533 | bool Object::IsDeoptimizationInputData() { |
| 534 | // Must be a fixed array. |
| 535 | if (!IsFixedArray()) return false; |
| 536 | |
| 537 | // There's no sure way to detect the difference between a fixed array and |
| 538 | // a deoptimization data array. Since this is used for asserts we can |
| 539 | // check that the length is zero or else the fixed size plus a multiple of |
| 540 | // the entry size. |
| 541 | int length = FixedArray::cast(this)->length(); |
| 542 | if (length == 0) return true; |
| 543 | |
| 544 | length -= DeoptimizationInputData::kFirstDeoptEntryIndex; |
| 545 | return length >= 0 && |
| 546 | length % DeoptimizationInputData::kDeoptEntrySize == 0; |
| 547 | } |
| 548 | |
| 549 | |
| 550 | bool Object::IsDeoptimizationOutputData() { |
| 551 | if (!IsFixedArray()) return false; |
| 552 | // There's actually no way to see the difference between a fixed array and |
| 553 | // a deoptimization data array. Since this is used for asserts we can check |
| 554 | // that the length is plausible though. |
| 555 | if (FixedArray::cast(this)->length() % 2 != 0) return false; |
| 556 | return true; |
| 557 | } |
| 558 | |
| 559 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 560 | bool Object::IsTypeFeedbackCells() { |
| 561 | if (!IsFixedArray()) return false; |
| 562 | // There's actually no way to see the difference between a fixed array and |
| 563 | // a cache cells array. Since this is used for asserts we can check that |
| 564 | // the length is plausible though. |
| 565 | if (FixedArray::cast(this)->length() % 2 != 0) return false; |
| 566 | return true; |
| 567 | } |
| 568 | |
| 569 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 570 | bool Object::IsContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 571 | if (Object::IsHeapObject()) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 572 | Map* map = HeapObject::cast(this)->map(); |
| 573 | Heap* heap = map->GetHeap(); |
| 574 | return (map == heap->function_context_map() || |
| 575 | map == heap->catch_context_map() || |
| 576 | map == heap->with_context_map() || |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 577 | map == heap->global_context_map() || |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 578 | map == heap->block_context_map() || |
| 579 | map == heap->module_context_map()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 580 | } |
| 581 | return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | |
| 585 | bool Object::IsGlobalContext() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 586 | return Object::IsHeapObject() && |
| 587 | HeapObject::cast(this)->map() == |
| 588 | HeapObject::cast(this)->GetHeap()->global_context_map(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 592 | bool Object::IsModuleContext() { |
| 593 | return Object::IsHeapObject() && |
| 594 | HeapObject::cast(this)->map() == |
| 595 | HeapObject::cast(this)->GetHeap()->module_context_map(); |
| 596 | } |
| 597 | |
| 598 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 599 | bool Object::IsScopeInfo() { |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 600 | return Object::IsHeapObject() && |
| 601 | HeapObject::cast(this)->map() == |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 602 | HeapObject::cast(this)->GetHeap()->scope_info_map(); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 606 | TYPE_CHECKER(JSFunction, JS_FUNCTION_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 607 | |
| 608 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 609 | template <> inline bool Is<JSFunction>(Object* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 610 | return obj->IsJSFunction(); |
| 611 | } |
| 612 | |
| 613 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 614 | TYPE_CHECKER(Code, CODE_TYPE) |
| 615 | TYPE_CHECKER(Oddball, ODDBALL_TYPE) |
| 616 | TYPE_CHECKER(JSGlobalPropertyCell, JS_GLOBAL_PROPERTY_CELL_TYPE) |
| 617 | TYPE_CHECKER(SharedFunctionInfo, SHARED_FUNCTION_INFO_TYPE) |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 618 | TYPE_CHECKER(JSModule, JS_MODULE_TYPE) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 619 | TYPE_CHECKER(JSValue, JS_VALUE_TYPE) |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 620 | TYPE_CHECKER(JSDate, JS_DATE_TYPE) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 621 | TYPE_CHECKER(JSMessageObject, JS_MESSAGE_OBJECT_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 622 | |
| 623 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 624 | bool Object::IsStringWrapper() { |
| 625 | return IsJSValue() && JSValue::cast(this)->value()->IsString(); |
| 626 | } |
| 627 | |
| 628 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 629 | TYPE_CHECKER(Foreign, FOREIGN_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 630 | |
| 631 | |
| 632 | bool Object::IsBoolean() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 633 | return IsOddball() && |
| 634 | ((Oddball::cast(this)->kind() & Oddball::kNotBooleanMask) == 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 638 | TYPE_CHECKER(JSArray, JS_ARRAY_TYPE) |
| 639 | TYPE_CHECKER(JSRegExp, JS_REGEXP_TYPE) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 640 | |
| 641 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 642 | template <> inline bool Is<JSArray>(Object* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 643 | return obj->IsJSArray(); |
| 644 | } |
| 645 | |
| 646 | |
| 647 | bool Object::IsHashTable() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 648 | return Object::IsHeapObject() && |
| 649 | HeapObject::cast(this)->map() == |
| 650 | HeapObject::cast(this)->GetHeap()->hash_table_map(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | |
| 654 | bool Object::IsDictionary() { |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 655 | return IsHashTable() && |
| 656 | this != HeapObject::cast(this)->GetHeap()->symbol_table(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | |
| 660 | bool Object::IsSymbolTable() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 661 | return IsHashTable() && this == |
| 662 | HeapObject::cast(this)->GetHeap()->raw_unchecked_symbol_table(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 666 | bool Object::IsJSFunctionResultCache() { |
| 667 | if (!IsFixedArray()) return false; |
| 668 | FixedArray* self = FixedArray::cast(this); |
| 669 | int length = self->length(); |
| 670 | if (length < JSFunctionResultCache::kEntriesIndex) return false; |
| 671 | if ((length - JSFunctionResultCache::kEntriesIndex) |
| 672 | % JSFunctionResultCache::kEntrySize != 0) { |
| 673 | return false; |
| 674 | } |
| 675 | #ifdef DEBUG |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 676 | if (FLAG_verify_heap) { |
| 677 | reinterpret_cast<JSFunctionResultCache*>(this)-> |
| 678 | JSFunctionResultCacheVerify(); |
| 679 | } |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 680 | #endif |
| 681 | return true; |
| 682 | } |
| 683 | |
| 684 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 685 | bool Object::IsNormalizedMapCache() { |
| 686 | if (!IsFixedArray()) return false; |
| 687 | if (FixedArray::cast(this)->length() != NormalizedMapCache::kEntries) { |
| 688 | return false; |
| 689 | } |
| 690 | #ifdef DEBUG |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 691 | if (FLAG_verify_heap) { |
| 692 | reinterpret_cast<NormalizedMapCache*>(this)->NormalizedMapCacheVerify(); |
| 693 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 694 | #endif |
| 695 | return true; |
| 696 | } |
| 697 | |
| 698 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 699 | bool Object::IsCompilationCacheTable() { |
| 700 | return IsHashTable(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 704 | bool Object::IsCodeCacheHashTable() { |
| 705 | return IsHashTable(); |
| 706 | } |
| 707 | |
| 708 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 709 | bool Object::IsPolymorphicCodeCacheHashTable() { |
| 710 | return IsHashTable(); |
| 711 | } |
| 712 | |
| 713 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 714 | bool Object::IsMapCache() { |
| 715 | return IsHashTable(); |
| 716 | } |
| 717 | |
| 718 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 719 | bool Object::IsPrimitive() { |
| 720 | return IsOddball() || IsNumber() || IsString(); |
| 721 | } |
| 722 | |
| 723 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 724 | bool Object::IsJSGlobalProxy() { |
| 725 | bool result = IsHeapObject() && |
| 726 | (HeapObject::cast(this)->map()->instance_type() == |
| 727 | JS_GLOBAL_PROXY_TYPE); |
| 728 | ASSERT(!result || IsAccessCheckNeeded()); |
| 729 | return result; |
| 730 | } |
| 731 | |
| 732 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 733 | bool Object::IsGlobalObject() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 734 | if (!IsHeapObject()) return false; |
| 735 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 736 | InstanceType type = HeapObject::cast(this)->map()->instance_type(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 737 | return type == JS_GLOBAL_OBJECT_TYPE || |
| 738 | type == JS_BUILTINS_OBJECT_TYPE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 739 | } |
| 740 | |
| 741 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 742 | TYPE_CHECKER(JSGlobalObject, JS_GLOBAL_OBJECT_TYPE) |
| 743 | TYPE_CHECKER(JSBuiltinsObject, JS_BUILTINS_OBJECT_TYPE) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 744 | |
| 745 | |
| 746 | bool Object::IsUndetectableObject() { |
| 747 | return IsHeapObject() |
| 748 | && HeapObject::cast(this)->map()->is_undetectable(); |
| 749 | } |
| 750 | |
| 751 | |
| 752 | bool Object::IsAccessCheckNeeded() { |
| 753 | return IsHeapObject() |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 754 | && HeapObject::cast(this)->map()->is_access_check_needed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 755 | } |
| 756 | |
| 757 | |
| 758 | bool Object::IsStruct() { |
| 759 | if (!IsHeapObject()) return false; |
| 760 | switch (HeapObject::cast(this)->map()->instance_type()) { |
| 761 | #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return true; |
| 762 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 763 | #undef MAKE_STRUCT_CASE |
| 764 | default: return false; |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | |
| 769 | #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 770 | bool Object::Is##Name() { \ |
| 771 | return Object::IsHeapObject() \ |
| 772 | && HeapObject::cast(this)->map()->instance_type() == NAME##_TYPE; \ |
| 773 | } |
| 774 | STRUCT_LIST(MAKE_STRUCT_PREDICATE) |
| 775 | #undef MAKE_STRUCT_PREDICATE |
| 776 | |
| 777 | |
| 778 | bool Object::IsUndefined() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 779 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kUndefined; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 783 | bool Object::IsNull() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 784 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kNull; |
| 785 | } |
| 786 | |
| 787 | |
| 788 | bool Object::IsTheHole() { |
| 789 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kTheHole; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 790 | } |
| 791 | |
| 792 | |
| 793 | bool Object::IsTrue() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 794 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kTrue; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | |
| 798 | bool Object::IsFalse() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 799 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kFalse; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 803 | bool Object::IsArgumentsMarker() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 804 | return IsOddball() && Oddball::cast(this)->kind() == Oddball::kArgumentMarker; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 808 | double Object::Number() { |
| 809 | ASSERT(IsNumber()); |
| 810 | return IsSmi() |
| 811 | ? static_cast<double>(reinterpret_cast<Smi*>(this)->value()) |
| 812 | : reinterpret_cast<HeapNumber*>(this)->value(); |
| 813 | } |
| 814 | |
| 815 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 816 | bool Object::IsNaN() { |
| 817 | return this->IsHeapNumber() && isnan(HeapNumber::cast(this)->value()); |
| 818 | } |
| 819 | |
| 820 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 821 | MaybeObject* Object::ToSmi() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 822 | if (IsSmi()) return this; |
| 823 | if (IsHeapNumber()) { |
| 824 | double value = HeapNumber::cast(this)->value(); |
| 825 | int int_value = FastD2I(value); |
| 826 | if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { |
| 827 | return Smi::FromInt(int_value); |
| 828 | } |
| 829 | } |
| 830 | return Failure::Exception(); |
| 831 | } |
| 832 | |
| 833 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 834 | bool Object::HasSpecificClassOf(String* name) { |
| 835 | return this->IsJSObject() && (JSObject::cast(this)->class_name() == name); |
| 836 | } |
| 837 | |
| 838 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 839 | MaybeObject* Object::GetElement(uint32_t index) { |
vegorov@chromium.org | 5d6c1f5 | 2011-02-28 13:13:38 +0000 | [diff] [blame] | 840 | // GetElement can trigger a getter which can cause allocation. |
| 841 | // This was not always the case. This ASSERT is here to catch |
| 842 | // leftover incorrect uses. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 843 | ASSERT(HEAP->IsAllocationAllowed()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 844 | return GetElementWithReceiver(this, index); |
| 845 | } |
| 846 | |
| 847 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 848 | Object* Object::GetElementNoExceptionThrown(uint32_t index) { |
| 849 | MaybeObject* maybe = GetElementWithReceiver(this, index); |
| 850 | ASSERT(!maybe->IsFailure()); |
| 851 | Object* result = NULL; // Initialization to please compiler. |
| 852 | maybe->ToObject(&result); |
| 853 | return result; |
| 854 | } |
| 855 | |
| 856 | |
| 857 | MaybeObject* Object::GetProperty(String* key) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 858 | PropertyAttributes attributes; |
| 859 | return GetPropertyWithReceiver(this, key, &attributes); |
| 860 | } |
| 861 | |
| 862 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 863 | MaybeObject* Object::GetProperty(String* key, PropertyAttributes* attributes) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 864 | return GetPropertyWithReceiver(this, key, attributes); |
| 865 | } |
| 866 | |
| 867 | |
| 868 | #define FIELD_ADDR(p, offset) \ |
| 869 | (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) |
| 870 | |
| 871 | #define READ_FIELD(p, offset) \ |
| 872 | (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset))) |
| 873 | |
| 874 | #define WRITE_FIELD(p, offset, value) \ |
| 875 | (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) |
| 876 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 877 | #define WRITE_BARRIER(heap, object, offset, value) \ |
| 878 | heap->incremental_marking()->RecordWrite( \ |
| 879 | object, HeapObject::RawField(object, offset), value); \ |
| 880 | if (heap->InNewSpace(value)) { \ |
| 881 | heap->RecordWrite(object->address(), offset); \ |
| 882 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 883 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 884 | #define CONDITIONAL_WRITE_BARRIER(heap, object, offset, value, mode) \ |
| 885 | if (mode == UPDATE_WRITE_BARRIER) { \ |
| 886 | heap->incremental_marking()->RecordWrite( \ |
| 887 | object, HeapObject::RawField(object, offset), value); \ |
| 888 | if (heap->InNewSpace(value)) { \ |
| 889 | heap->RecordWrite(object->address(), offset); \ |
| 890 | } \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 891 | } |
| 892 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 893 | #ifndef V8_TARGET_ARCH_MIPS |
| 894 | #define READ_DOUBLE_FIELD(p, offset) \ |
| 895 | (*reinterpret_cast<double*>(FIELD_ADDR(p, offset))) |
| 896 | #else // V8_TARGET_ARCH_MIPS |
| 897 | // Prevent gcc from using load-double (mips ldc1) on (possibly) |
| 898 | // non-64-bit aligned HeapNumber::value. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 899 | static inline double read_double_field(void* p, int offset) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 900 | union conversion { |
| 901 | double d; |
| 902 | uint32_t u[2]; |
| 903 | } c; |
| 904 | c.u[0] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset))); |
| 905 | c.u[1] = (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset + 4))); |
| 906 | return c.d; |
| 907 | } |
| 908 | #define READ_DOUBLE_FIELD(p, offset) read_double_field(p, offset) |
| 909 | #endif // V8_TARGET_ARCH_MIPS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 910 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 911 | #ifndef V8_TARGET_ARCH_MIPS |
| 912 | #define WRITE_DOUBLE_FIELD(p, offset, value) \ |
| 913 | (*reinterpret_cast<double*>(FIELD_ADDR(p, offset)) = value) |
| 914 | #else // V8_TARGET_ARCH_MIPS |
| 915 | // Prevent gcc from using store-double (mips sdc1) on (possibly) |
| 916 | // non-64-bit aligned HeapNumber::value. |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 917 | static inline void write_double_field(void* p, int offset, |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 918 | double value) { |
| 919 | union conversion { |
| 920 | double d; |
| 921 | uint32_t u[2]; |
| 922 | } c; |
| 923 | c.d = value; |
| 924 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset))) = c.u[0]; |
| 925 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset + 4))) = c.u[1]; |
| 926 | } |
| 927 | #define WRITE_DOUBLE_FIELD(p, offset, value) \ |
| 928 | write_double_field(p, offset, value) |
| 929 | #endif // V8_TARGET_ARCH_MIPS |
| 930 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 931 | |
| 932 | #define READ_INT_FIELD(p, offset) \ |
| 933 | (*reinterpret_cast<int*>(FIELD_ADDR(p, offset))) |
| 934 | |
| 935 | #define WRITE_INT_FIELD(p, offset, value) \ |
| 936 | (*reinterpret_cast<int*>(FIELD_ADDR(p, offset)) = value) |
| 937 | |
ager@chromium.org | 3e87580 | 2009-06-29 08:26:34 +0000 | [diff] [blame] | 938 | #define READ_INTPTR_FIELD(p, offset) \ |
| 939 | (*reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset))) |
| 940 | |
| 941 | #define WRITE_INTPTR_FIELD(p, offset, value) \ |
| 942 | (*reinterpret_cast<intptr_t*>(FIELD_ADDR(p, offset)) = value) |
| 943 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 944 | #define READ_UINT32_FIELD(p, offset) \ |
| 945 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset))) |
| 946 | |
| 947 | #define WRITE_UINT32_FIELD(p, offset, value) \ |
| 948 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)) = value) |
| 949 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 950 | #define READ_INT64_FIELD(p, offset) \ |
| 951 | (*reinterpret_cast<int64_t*>(FIELD_ADDR(p, offset))) |
| 952 | |
| 953 | #define WRITE_INT64_FIELD(p, offset, value) \ |
| 954 | (*reinterpret_cast<int64_t*>(FIELD_ADDR(p, offset)) = value) |
| 955 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 956 | #define READ_SHORT_FIELD(p, offset) \ |
| 957 | (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset))) |
| 958 | |
| 959 | #define WRITE_SHORT_FIELD(p, offset, value) \ |
| 960 | (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value) |
| 961 | |
| 962 | #define READ_BYTE_FIELD(p, offset) \ |
| 963 | (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset))) |
| 964 | |
| 965 | #define WRITE_BYTE_FIELD(p, offset, value) \ |
| 966 | (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value) |
| 967 | |
| 968 | |
kasperl@chromium.org | 9bbf968 | 2008-10-30 11:53:07 +0000 | [diff] [blame] | 969 | Object** HeapObject::RawField(HeapObject* obj, int byte_offset) { |
| 970 | return &READ_FIELD(obj, byte_offset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | |
| 974 | int Smi::value() { |
ager@chromium.org | 18ad94b | 2009-09-02 08:22:29 +0000 | [diff] [blame] | 975 | return Internals::SmiValue(this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 976 | } |
| 977 | |
| 978 | |
| 979 | Smi* Smi::FromInt(int value) { |
| 980 | ASSERT(Smi::IsValid(value)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 981 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 982 | intptr_t tagged_value = |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 983 | (static_cast<intptr_t>(value) << smi_shift_bits) | kSmiTag; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 984 | return reinterpret_cast<Smi*>(tagged_value); |
| 985 | } |
| 986 | |
| 987 | |
| 988 | Smi* Smi::FromIntptr(intptr_t value) { |
| 989 | ASSERT(Smi::IsValid(value)); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 990 | int smi_shift_bits = kSmiTagSize + kSmiShiftSize; |
| 991 | return reinterpret_cast<Smi*>((value << smi_shift_bits) | kSmiTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | |
| 995 | Failure::Type Failure::type() const { |
| 996 | return static_cast<Type>(value() & kFailureTypeTagMask); |
| 997 | } |
| 998 | |
| 999 | |
| 1000 | bool Failure::IsInternalError() const { |
| 1001 | return type() == INTERNAL_ERROR; |
| 1002 | } |
| 1003 | |
| 1004 | |
| 1005 | bool Failure::IsOutOfMemoryException() const { |
| 1006 | return type() == OUT_OF_MEMORY_EXCEPTION; |
| 1007 | } |
| 1008 | |
| 1009 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1010 | AllocationSpace Failure::allocation_space() const { |
| 1011 | ASSERT_EQ(RETRY_AFTER_GC, type()); |
| 1012 | return static_cast<AllocationSpace>((value() >> kFailureTypeTagSize) |
| 1013 | & kSpaceTagMask); |
| 1014 | } |
| 1015 | |
| 1016 | |
| 1017 | Failure* Failure::InternalError() { |
| 1018 | return Construct(INTERNAL_ERROR); |
| 1019 | } |
| 1020 | |
| 1021 | |
| 1022 | Failure* Failure::Exception() { |
| 1023 | return Construct(EXCEPTION); |
| 1024 | } |
| 1025 | |
sgjesse@chromium.org | c81c894 | 2009-08-21 10:54:26 +0000 | [diff] [blame] | 1026 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1027 | Failure* Failure::OutOfMemoryException() { |
| 1028 | return Construct(OUT_OF_MEMORY_EXCEPTION); |
| 1029 | } |
| 1030 | |
| 1031 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1032 | intptr_t Failure::value() const { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1033 | return static_cast<intptr_t>( |
| 1034 | reinterpret_cast<uintptr_t>(this) >> kFailureTagSize); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1038 | Failure* Failure::RetryAfterGC() { |
| 1039 | return RetryAfterGC(NEW_SPACE); |
| 1040 | } |
| 1041 | |
| 1042 | |
| 1043 | Failure* Failure::RetryAfterGC(AllocationSpace space) { |
| 1044 | ASSERT((space & ~kSpaceTagMask) == 0); |
| 1045 | return Construct(RETRY_AFTER_GC, space); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1049 | Failure* Failure::Construct(Type type, intptr_t value) { |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1050 | uintptr_t info = |
| 1051 | (static_cast<uintptr_t>(value) << kFailureTypeTagSize) | type; |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1052 | ASSERT(((info << kFailureTagSize) >> kFailureTagSize) == info); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1053 | return reinterpret_cast<Failure*>((info << kFailureTagSize) | kFailureTag); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
| 1056 | |
ager@chromium.org | ab99eea | 2009-08-25 07:05:41 +0000 | [diff] [blame] | 1057 | bool Smi::IsValid(intptr_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1058 | #ifdef DEBUG |
| 1059 | bool in_range = (value >= kMinValue) && (value <= kMaxValue); |
| 1060 | #endif |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1061 | |
| 1062 | #ifdef V8_TARGET_ARCH_X64 |
| 1063 | // To be representable as a long smi, the value must be a 32-bit integer. |
| 1064 | bool result = (value == static_cast<int32_t>(value)); |
| 1065 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1066 | // To be representable as an tagged small integer, the two |
| 1067 | // most-significant bits of 'value' must be either 00 or 11 due to |
| 1068 | // sign-extension. To check this we add 01 to the two |
| 1069 | // most-significant bits, and check if the most-significant bit is 0 |
| 1070 | // |
| 1071 | // CAUTION: The original code below: |
| 1072 | // bool result = ((value + 0x40000000) & 0x80000000) == 0; |
| 1073 | // may lead to incorrect results according to the C language spec, and |
| 1074 | // in fact doesn't work correctly with gcc4.1.1 in some cases: The |
| 1075 | // compiler may produce undefined results in case of signed integer |
| 1076 | // overflow. The computation must be done w/ unsigned ints. |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 1077 | bool result = (static_cast<uintptr_t>(value + 0x40000000U) < 0x80000000U); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1078 | #endif |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 1079 | ASSERT(result == in_range); |
| 1080 | return result; |
| 1081 | } |
| 1082 | |
| 1083 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1084 | MapWord MapWord::FromMap(Map* map) { |
| 1085 | return MapWord(reinterpret_cast<uintptr_t>(map)); |
| 1086 | } |
| 1087 | |
| 1088 | |
| 1089 | Map* MapWord::ToMap() { |
| 1090 | return reinterpret_cast<Map*>(value_); |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | bool MapWord::IsForwardingAddress() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1095 | return HAS_SMI_TAG(reinterpret_cast<Object*>(value_)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | |
| 1099 | MapWord MapWord::FromForwardingAddress(HeapObject* object) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1100 | Address raw = reinterpret_cast<Address>(object) - kHeapObjectTag; |
| 1101 | return MapWord(reinterpret_cast<uintptr_t>(raw)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | |
| 1105 | HeapObject* MapWord::ToForwardingAddress() { |
| 1106 | ASSERT(IsForwardingAddress()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1107 | return HeapObject::FromAddress(reinterpret_cast<Address>(value_)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1111 | #ifdef DEBUG |
| 1112 | void HeapObject::VerifyObjectField(int offset) { |
| 1113 | VerifyPointer(READ_FIELD(this, offset)); |
| 1114 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1115 | |
| 1116 | void HeapObject::VerifySmiField(int offset) { |
| 1117 | ASSERT(READ_FIELD(this, offset)->IsSmi()); |
| 1118 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1119 | #endif |
| 1120 | |
| 1121 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1122 | Heap* HeapObject::GetHeap() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1123 | Heap* heap = |
| 1124 | MemoryChunk::FromAddress(reinterpret_cast<Address>(this))->heap(); |
| 1125 | ASSERT(heap != NULL); |
| 1126 | ASSERT(heap->isolate() == Isolate::Current()); |
| 1127 | return heap; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | |
| 1131 | Isolate* HeapObject::GetIsolate() { |
| 1132 | return GetHeap()->isolate(); |
| 1133 | } |
| 1134 | |
| 1135 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1136 | Map* HeapObject::map() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1137 | return map_word().ToMap(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | |
| 1141 | void HeapObject::set_map(Map* value) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1142 | set_map_word(MapWord::FromMap(value)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1143 | if (value != NULL) { |
| 1144 | // TODO(1600) We are passing NULL as a slot because maps can never be on |
| 1145 | // evacuation candidate. |
| 1146 | value->GetHeap()->incremental_marking()->RecordWrite(this, NULL, value); |
| 1147 | } |
| 1148 | } |
| 1149 | |
| 1150 | |
| 1151 | // Unsafe accessor omitting write barrier. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1152 | void HeapObject::set_map_no_write_barrier(Map* value) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1153 | set_map_word(MapWord::FromMap(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1157 | MapWord HeapObject::map_word() { |
| 1158 | return MapWord(reinterpret_cast<uintptr_t>(READ_FIELD(this, kMapOffset))); |
| 1159 | } |
| 1160 | |
| 1161 | |
| 1162 | void HeapObject::set_map_word(MapWord map_word) { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1163 | // WRITE_FIELD does not invoke write barrier, but there is no need |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1164 | // here. |
| 1165 | WRITE_FIELD(this, kMapOffset, reinterpret_cast<Object*>(map_word.value_)); |
| 1166 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1167 | |
| 1168 | |
| 1169 | HeapObject* HeapObject::FromAddress(Address address) { |
| 1170 | ASSERT_TAG_ALIGNED(address); |
| 1171 | return reinterpret_cast<HeapObject*>(address + kHeapObjectTag); |
| 1172 | } |
| 1173 | |
| 1174 | |
| 1175 | Address HeapObject::address() { |
| 1176 | return reinterpret_cast<Address>(this) - kHeapObjectTag; |
| 1177 | } |
| 1178 | |
| 1179 | |
| 1180 | int HeapObject::Size() { |
| 1181 | return SizeFromMap(map()); |
| 1182 | } |
| 1183 | |
| 1184 | |
| 1185 | void HeapObject::IteratePointers(ObjectVisitor* v, int start, int end) { |
| 1186 | v->VisitPointers(reinterpret_cast<Object**>(FIELD_ADDR(this, start)), |
| 1187 | reinterpret_cast<Object**>(FIELD_ADDR(this, end))); |
| 1188 | } |
| 1189 | |
| 1190 | |
| 1191 | void HeapObject::IteratePointer(ObjectVisitor* v, int offset) { |
| 1192 | v->VisitPointer(reinterpret_cast<Object**>(FIELD_ADDR(this, offset))); |
| 1193 | } |
| 1194 | |
| 1195 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1196 | double HeapNumber::value() { |
| 1197 | return READ_DOUBLE_FIELD(this, kValueOffset); |
| 1198 | } |
| 1199 | |
| 1200 | |
| 1201 | void HeapNumber::set_value(double value) { |
| 1202 | WRITE_DOUBLE_FIELD(this, kValueOffset, value); |
| 1203 | } |
| 1204 | |
| 1205 | |
whesse@chromium.org | cec079d | 2010-03-22 14:44:04 +0000 | [diff] [blame] | 1206 | int HeapNumber::get_exponent() { |
| 1207 | return ((READ_INT_FIELD(this, kExponentOffset) & kExponentMask) >> |
| 1208 | kExponentShift) - kExponentBias; |
| 1209 | } |
| 1210 | |
| 1211 | |
| 1212 | int HeapNumber::get_sign() { |
| 1213 | return READ_INT_FIELD(this, kExponentOffset) & kSignMask; |
| 1214 | } |
| 1215 | |
| 1216 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1217 | ACCESSORS(JSObject, properties, FixedArray, kPropertiesOffset) |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1218 | |
| 1219 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1220 | Object** FixedArray::GetFirstElementAddress() { |
| 1221 | return reinterpret_cast<Object**>(FIELD_ADDR(this, OffsetOfElementAt(0))); |
| 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | bool FixedArray::ContainsOnlySmisOrHoles() { |
| 1226 | Object* the_hole = GetHeap()->the_hole_value(); |
| 1227 | Object** current = GetFirstElementAddress(); |
| 1228 | for (int i = 0; i < length(); ++i) { |
| 1229 | Object* candidate = *current++; |
| 1230 | if (!candidate->IsSmi() && candidate != the_hole) return false; |
| 1231 | } |
| 1232 | return true; |
| 1233 | } |
| 1234 | |
| 1235 | |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1236 | FixedArrayBase* JSObject::elements() { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1237 | Object* array = READ_FIELD(this, kElementsOffset); |
whesse@chromium.org | 4acdc2c | 2011-08-15 13:01:23 +0000 | [diff] [blame] | 1238 | return static_cast<FixedArrayBase*>(array); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1241 | |
| 1242 | void JSObject::ValidateElements() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1243 | #if DEBUG |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1244 | if (FLAG_enable_slow_asserts) { |
| 1245 | ElementsAccessor* accessor = GetElementsAccessor(); |
| 1246 | accessor->Validate(this); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1247 | } |
| 1248 | #endif |
| 1249 | } |
| 1250 | |
| 1251 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1252 | MaybeObject* JSObject::EnsureCanContainHeapObjectElements() { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1253 | ValidateElements(); |
| 1254 | ElementsKind elements_kind = map()->elements_kind(); |
| 1255 | if (!IsFastObjectElementsKind(elements_kind)) { |
| 1256 | if (IsFastHoleyElementsKind(elements_kind)) { |
| 1257 | return TransitionElementsKind(FAST_HOLEY_ELEMENTS); |
| 1258 | } else { |
| 1259 | return TransitionElementsKind(FAST_ELEMENTS); |
| 1260 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1261 | } |
| 1262 | return this; |
| 1263 | } |
| 1264 | |
| 1265 | |
| 1266 | MaybeObject* JSObject::EnsureCanContainElements(Object** objects, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1267 | uint32_t count, |
| 1268 | EnsureElementsMode mode) { |
| 1269 | ElementsKind current_kind = map()->elements_kind(); |
| 1270 | ElementsKind target_kind = current_kind; |
| 1271 | ASSERT(mode != ALLOW_COPIED_DOUBLE_ELEMENTS); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1272 | bool is_holey = IsFastHoleyElementsKind(current_kind); |
| 1273 | if (current_kind == FAST_HOLEY_ELEMENTS) return this; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1274 | Heap* heap = GetHeap(); |
| 1275 | Object* the_hole = heap->the_hole_value(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1276 | for (uint32_t i = 0; i < count; ++i) { |
| 1277 | Object* current = *objects++; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1278 | if (current == the_hole) { |
| 1279 | is_holey = true; |
| 1280 | target_kind = GetHoleyElementsKind(target_kind); |
| 1281 | } else if (!current->IsSmi()) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1282 | if (mode == ALLOW_CONVERTED_DOUBLE_ELEMENTS && current->IsNumber()) { |
| 1283 | if (IsFastSmiElementsKind(target_kind)) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1284 | if (is_holey) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1285 | target_kind = FAST_HOLEY_DOUBLE_ELEMENTS; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1286 | } else { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1287 | target_kind = FAST_DOUBLE_ELEMENTS; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1288 | } |
| 1289 | } |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1290 | } else if (is_holey) { |
| 1291 | target_kind = FAST_HOLEY_ELEMENTS; |
| 1292 | break; |
| 1293 | } else { |
| 1294 | target_kind = FAST_ELEMENTS; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1295 | } |
| 1296 | } |
| 1297 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1298 | |
| 1299 | if (target_kind != current_kind) { |
| 1300 | return TransitionElementsKind(target_kind); |
| 1301 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1302 | return this; |
| 1303 | } |
| 1304 | |
| 1305 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1306 | MaybeObject* JSObject::EnsureCanContainElements(FixedArrayBase* elements, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1307 | uint32_t length, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1308 | EnsureElementsMode mode) { |
| 1309 | if (elements->map() != GetHeap()->fixed_double_array_map()) { |
| 1310 | ASSERT(elements->map() == GetHeap()->fixed_array_map() || |
| 1311 | elements->map() == GetHeap()->fixed_cow_array_map()); |
| 1312 | if (mode == ALLOW_COPIED_DOUBLE_ELEMENTS) { |
| 1313 | mode = DONT_ALLOW_DOUBLE_ELEMENTS; |
| 1314 | } |
| 1315 | Object** objects = FixedArray::cast(elements)->GetFirstElementAddress(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1316 | return EnsureCanContainElements(objects, length, mode); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | ASSERT(mode == ALLOW_COPIED_DOUBLE_ELEMENTS); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1320 | if (GetElementsKind() == FAST_HOLEY_SMI_ELEMENTS) { |
| 1321 | return TransitionElementsKind(FAST_HOLEY_DOUBLE_ELEMENTS); |
| 1322 | } else if (GetElementsKind() == FAST_SMI_ELEMENTS) { |
| 1323 | FixedDoubleArray* double_array = FixedDoubleArray::cast(elements); |
| 1324 | for (uint32_t i = 0; i < length; ++i) { |
| 1325 | if (double_array->is_the_hole(i)) { |
| 1326 | return TransitionElementsKind(FAST_HOLEY_DOUBLE_ELEMENTS); |
| 1327 | } |
| 1328 | } |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1329 | return TransitionElementsKind(FAST_DOUBLE_ELEMENTS); |
| 1330 | } |
| 1331 | |
| 1332 | return this; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1333 | } |
| 1334 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1335 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1336 | MaybeObject* JSObject::GetElementsTransitionMap(Isolate* isolate, |
| 1337 | ElementsKind to_kind) { |
| 1338 | Map* current_map = map(); |
| 1339 | ElementsKind from_kind = current_map->elements_kind(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1340 | if (from_kind == to_kind) return current_map; |
| 1341 | |
| 1342 | Context* global_context = isolate->context()->global_context(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1343 | Object* maybe_array_maps = global_context->js_array_maps(); |
| 1344 | if (maybe_array_maps->IsFixedArray()) { |
| 1345 | FixedArray* array_maps = FixedArray::cast(maybe_array_maps); |
| 1346 | if (array_maps->get(from_kind) == current_map) { |
| 1347 | Object* maybe_transitioned_map = array_maps->get(to_kind); |
| 1348 | if (maybe_transitioned_map->IsMap()) { |
| 1349 | return Map::cast(maybe_transitioned_map); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1350 | } |
| 1351 | } |
| 1352 | } |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1353 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1354 | return GetElementsTransitionMapSlow(to_kind); |
| 1355 | } |
| 1356 | |
| 1357 | |
svenpanne@chromium.org | 3c93e77 | 2012-01-02 09:26:59 +0000 | [diff] [blame] | 1358 | void JSObject::set_map_and_elements(Map* new_map, |
| 1359 | FixedArrayBase* value, |
| 1360 | WriteBarrierMode mode) { |
| 1361 | ASSERT(value->HasValidElements()); |
svenpanne@chromium.org | 3c93e77 | 2012-01-02 09:26:59 +0000 | [diff] [blame] | 1362 | if (new_map != NULL) { |
| 1363 | if (mode == UPDATE_WRITE_BARRIER) { |
| 1364 | set_map(new_map); |
| 1365 | } else { |
| 1366 | ASSERT(mode == SKIP_WRITE_BARRIER); |
| 1367 | set_map_no_write_barrier(new_map); |
| 1368 | } |
| 1369 | } |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1370 | ASSERT((map()->has_fast_smi_or_object_elements() || |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1371 | (value == GetHeap()->empty_fixed_array())) == |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1372 | (value->map() == GetHeap()->fixed_array_map() || |
| 1373 | value->map() == GetHeap()->fixed_cow_array_map())); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1374 | ASSERT((value == GetHeap()->empty_fixed_array()) || |
| 1375 | (map()->has_fast_double_elements() == value->IsFixedDoubleArray())); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1376 | WRITE_FIELD(this, kElementsOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1377 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kElementsOffset, value, mode); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 1378 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1379 | |
| 1380 | |
svenpanne@chromium.org | 3c93e77 | 2012-01-02 09:26:59 +0000 | [diff] [blame] | 1381 | void JSObject::set_elements(FixedArrayBase* value, WriteBarrierMode mode) { |
| 1382 | set_map_and_elements(NULL, value, mode); |
| 1383 | } |
| 1384 | |
| 1385 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1386 | void JSObject::initialize_properties() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1387 | ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
| 1388 | WRITE_FIELD(this, kPropertiesOffset, GetHeap()->empty_fixed_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | |
| 1392 | void JSObject::initialize_elements() { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1393 | ASSERT(map()->has_fast_smi_or_object_elements() || |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 1394 | map()->has_fast_double_elements()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1395 | ASSERT(!GetHeap()->InNewSpace(GetHeap()->empty_fixed_array())); |
| 1396 | WRITE_FIELD(this, kElementsOffset, GetHeap()->empty_fixed_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 1400 | MaybeObject* JSObject::ResetElements() { |
| 1401 | Object* obj; |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1402 | ElementsKind elements_kind = GetInitialFastElementsKind(); |
| 1403 | if (!FLAG_smi_only_arrays) { |
| 1404 | elements_kind = FastSmiToObjectElementsKind(elements_kind); |
| 1405 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 1406 | MaybeObject* maybe_obj = GetElementsTransitionMap(GetIsolate(), |
| 1407 | elements_kind); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1408 | if (!maybe_obj->ToObject(&obj)) return maybe_obj; |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 1409 | set_map(Map::cast(obj)); |
| 1410 | initialize_elements(); |
| 1411 | return this; |
| 1412 | } |
| 1413 | |
| 1414 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1415 | ACCESSORS(Oddball, to_string, String, kToStringOffset) |
| 1416 | ACCESSORS(Oddball, to_number, Object, kToNumberOffset) |
| 1417 | |
| 1418 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1419 | byte Oddball::kind() { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1420 | return Smi::cast(READ_FIELD(this, kKindOffset))->value(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1421 | } |
| 1422 | |
| 1423 | |
| 1424 | void Oddball::set_kind(byte value) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1425 | WRITE_FIELD(this, kKindOffset, Smi::FromInt(value)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 1429 | Object* JSGlobalPropertyCell::value() { |
| 1430 | return READ_FIELD(this, kValueOffset); |
| 1431 | } |
| 1432 | |
| 1433 | |
| 1434 | void JSGlobalPropertyCell::set_value(Object* val, WriteBarrierMode ignored) { |
| 1435 | // The write barrier is not used for global property cells. |
| 1436 | ASSERT(!val->IsJSGlobalPropertyCell()); |
| 1437 | WRITE_FIELD(this, kValueOffset, val); |
| 1438 | } |
| 1439 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 1440 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1441 | int JSObject::GetHeaderSize() { |
kasperl@chromium.org | e959c18 | 2009-07-27 08:59:04 +0000 | [diff] [blame] | 1442 | InstanceType type = map()->instance_type(); |
| 1443 | // Check for the most common kind of JavaScript object before |
| 1444 | // falling into the generic switch. This speeds up the internal |
| 1445 | // field operations considerably on average. |
| 1446 | if (type == JS_OBJECT_TYPE) return JSObject::kHeaderSize; |
| 1447 | switch (type) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 1448 | case JS_MODULE_TYPE: |
| 1449 | return JSModule::kSize; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1450 | case JS_GLOBAL_PROXY_TYPE: |
| 1451 | return JSGlobalProxy::kSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1452 | case JS_GLOBAL_OBJECT_TYPE: |
| 1453 | return JSGlobalObject::kSize; |
| 1454 | case JS_BUILTINS_OBJECT_TYPE: |
| 1455 | return JSBuiltinsObject::kSize; |
| 1456 | case JS_FUNCTION_TYPE: |
| 1457 | return JSFunction::kSize; |
| 1458 | case JS_VALUE_TYPE: |
| 1459 | return JSValue::kSize; |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 1460 | case JS_DATE_TYPE: |
| 1461 | return JSDate::kSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1462 | case JS_ARRAY_TYPE: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1463 | return JSArray::kSize; |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1464 | case JS_WEAK_MAP_TYPE: |
| 1465 | return JSWeakMap::kSize; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1466 | case JS_REGEXP_TYPE: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1467 | return JSRegExp::kSize; |
ager@chromium.org | 3291210 | 2009-01-16 10:38:43 +0000 | [diff] [blame] | 1468 | case JS_CONTEXT_EXTENSION_OBJECT_TYPE: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1469 | return JSObject::kHeaderSize; |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 1470 | case JS_MESSAGE_OBJECT_TYPE: |
| 1471 | return JSMessageObject::kSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1472 | default: |
| 1473 | UNREACHABLE(); |
| 1474 | return 0; |
| 1475 | } |
| 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | int JSObject::GetInternalFieldCount() { |
| 1480 | ASSERT(1 << kPointerSizeLog2 == kPointerSize); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1481 | // Make sure to adjust for the number of in-object properties. These |
| 1482 | // properties do contribute to the size, but are not internal fields. |
| 1483 | return ((Size() - GetHeaderSize()) >> kPointerSizeLog2) - |
| 1484 | map()->inobject_properties(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
| 1487 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1488 | int JSObject::GetInternalFieldOffset(int index) { |
| 1489 | ASSERT(index < GetInternalFieldCount() && index >= 0); |
| 1490 | return GetHeaderSize() + (kPointerSize * index); |
| 1491 | } |
| 1492 | |
| 1493 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1494 | Object* JSObject::GetInternalField(int index) { |
| 1495 | ASSERT(index < GetInternalFieldCount() && index >= 0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1496 | // Internal objects do follow immediately after the header, whereas in-object |
| 1497 | // properties are at the end of the object. Therefore there is no need |
| 1498 | // to adjust the index here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1499 | return READ_FIELD(this, GetHeaderSize() + (kPointerSize * index)); |
| 1500 | } |
| 1501 | |
| 1502 | |
| 1503 | void JSObject::SetInternalField(int index, Object* value) { |
| 1504 | ASSERT(index < GetInternalFieldCount() && index >= 0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1505 | // Internal objects do follow immediately after the header, whereas in-object |
| 1506 | // properties are at the end of the object. Therefore there is no need |
| 1507 | // to adjust the index here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1508 | int offset = GetHeaderSize() + (kPointerSize * index); |
| 1509 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1510 | WRITE_BARRIER(GetHeap(), this, offset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | |
ricow@chromium.org | 27bf288 | 2011-11-17 08:34:43 +0000 | [diff] [blame] | 1514 | void JSObject::SetInternalField(int index, Smi* value) { |
| 1515 | ASSERT(index < GetInternalFieldCount() && index >= 0); |
| 1516 | // Internal objects do follow immediately after the header, whereas in-object |
| 1517 | // properties are at the end of the object. Therefore there is no need |
| 1518 | // to adjust the index here. |
| 1519 | int offset = GetHeaderSize() + (kPointerSize * index); |
| 1520 | WRITE_FIELD(this, offset, value); |
| 1521 | } |
| 1522 | |
| 1523 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1524 | // Access fast-case object properties at index. The use of these routines |
| 1525 | // is needed to correctly distinguish between properties stored in-object and |
| 1526 | // properties stored in the properties array. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1527 | Object* JSObject::FastPropertyAt(int index) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1528 | // Adjust for the number of properties stored in the object. |
| 1529 | index -= map()->inobject_properties(); |
| 1530 | if (index < 0) { |
| 1531 | int offset = map()->instance_size() + (index * kPointerSize); |
| 1532 | return READ_FIELD(this, offset); |
| 1533 | } else { |
| 1534 | ASSERT(index < properties()->length()); |
| 1535 | return properties()->get(index); |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1540 | Object* JSObject::FastPropertyAtPut(int index, Object* value) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1541 | // Adjust for the number of properties stored in the object. |
| 1542 | index -= map()->inobject_properties(); |
| 1543 | if (index < 0) { |
| 1544 | int offset = map()->instance_size() + (index * kPointerSize); |
| 1545 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1546 | WRITE_BARRIER(GetHeap(), this, offset, value); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1547 | } else { |
| 1548 | ASSERT(index < properties()->length()); |
| 1549 | properties()->set(index, value); |
| 1550 | } |
| 1551 | return value; |
| 1552 | } |
| 1553 | |
| 1554 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1555 | int JSObject::GetInObjectPropertyOffset(int index) { |
| 1556 | // Adjust for the number of properties stored in the object. |
| 1557 | index -= map()->inobject_properties(); |
| 1558 | ASSERT(index < 0); |
| 1559 | return map()->instance_size() + (index * kPointerSize); |
| 1560 | } |
| 1561 | |
| 1562 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1563 | Object* JSObject::InObjectPropertyAt(int index) { |
| 1564 | // Adjust for the number of properties stored in the object. |
| 1565 | index -= map()->inobject_properties(); |
| 1566 | ASSERT(index < 0); |
| 1567 | int offset = map()->instance_size() + (index * kPointerSize); |
| 1568 | return READ_FIELD(this, offset); |
| 1569 | } |
| 1570 | |
| 1571 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1572 | Object* JSObject::InObjectPropertyAtPut(int index, |
| 1573 | Object* value, |
| 1574 | WriteBarrierMode mode) { |
| 1575 | // Adjust for the number of properties stored in the object. |
| 1576 | index -= map()->inobject_properties(); |
| 1577 | ASSERT(index < 0); |
| 1578 | int offset = map()->instance_size() + (index * kPointerSize); |
| 1579 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1580 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1581 | return value; |
| 1582 | } |
| 1583 | |
| 1584 | |
| 1585 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1586 | void JSObject::InitializeBody(Map* map, |
| 1587 | Object* pre_allocated_value, |
| 1588 | Object* filler_value) { |
| 1589 | ASSERT(!filler_value->IsHeapObject() || |
| 1590 | !GetHeap()->InNewSpace(filler_value)); |
| 1591 | ASSERT(!pre_allocated_value->IsHeapObject() || |
| 1592 | !GetHeap()->InNewSpace(pre_allocated_value)); |
| 1593 | int size = map->instance_size(); |
| 1594 | int offset = kHeaderSize; |
| 1595 | if (filler_value != pre_allocated_value) { |
| 1596 | int pre_allocated = map->pre_allocated_property_fields(); |
| 1597 | ASSERT(pre_allocated * kPointerSize + kHeaderSize <= size); |
| 1598 | for (int i = 0; i < pre_allocated; i++) { |
| 1599 | WRITE_FIELD(this, offset, pre_allocated_value); |
| 1600 | offset += kPointerSize; |
| 1601 | } |
| 1602 | } |
| 1603 | while (offset < size) { |
| 1604 | WRITE_FIELD(this, offset, filler_value); |
| 1605 | offset += kPointerSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1610 | bool JSObject::HasFastProperties() { |
| 1611 | return !properties()->IsDictionary(); |
| 1612 | } |
| 1613 | |
| 1614 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1615 | bool JSObject::TooManyFastProperties(int properties, |
| 1616 | JSObject::StoreFromKeyed store_mode) { |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1617 | // Allow extra fast properties if the object has more than |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1618 | // kFastPropertiesSoftLimit in-object properties. When this is the case, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1619 | // it is very unlikely that the object is being used as a dictionary |
| 1620 | // and there is a good chance that allowing more map transitions |
| 1621 | // will be worth it. |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1622 | int inobject = map()->inobject_properties(); |
| 1623 | |
| 1624 | int limit; |
ulan@chromium.org | f6a0c41 | 2012-06-15 12:31:06 +0000 | [diff] [blame] | 1625 | if (store_mode == CERTAINLY_NOT_STORE_FROM_KEYED) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1626 | limit = Max(inobject, kMaxFastProperties); |
| 1627 | } else { |
| 1628 | limit = Max(inobject, kFastPropertiesSoftLimit); |
| 1629 | } |
| 1630 | return properties > limit; |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1634 | void Struct::InitializeBody(int object_size) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1635 | Object* value = GetHeap()->undefined_value(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1636 | for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1637 | WRITE_FIELD(this, offset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1642 | bool Object::ToArrayIndex(uint32_t* index) { |
| 1643 | if (IsSmi()) { |
| 1644 | int value = Smi::cast(this)->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1645 | if (value < 0) return false; |
| 1646 | *index = value; |
| 1647 | return true; |
| 1648 | } |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 1649 | if (IsHeapNumber()) { |
| 1650 | double value = HeapNumber::cast(this)->value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1651 | uint32_t uint_value = static_cast<uint32_t>(value); |
| 1652 | if (value == static_cast<double>(uint_value)) { |
| 1653 | *index = uint_value; |
| 1654 | return true; |
| 1655 | } |
| 1656 | } |
| 1657 | return false; |
| 1658 | } |
| 1659 | |
| 1660 | |
| 1661 | bool Object::IsStringObjectWithCharacterAt(uint32_t index) { |
| 1662 | if (!this->IsJSValue()) return false; |
| 1663 | |
| 1664 | JSValue* js_value = JSValue::cast(this); |
| 1665 | if (!js_value->value()->IsString()) return false; |
| 1666 | |
| 1667 | String* str = String::cast(js_value->value()); |
| 1668 | if (index >= (uint32_t)str->length()) return false; |
| 1669 | |
| 1670 | return true; |
| 1671 | } |
| 1672 | |
| 1673 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1674 | FixedArrayBase* FixedArrayBase::cast(Object* object) { |
| 1675 | ASSERT(object->IsFixedArray() || object->IsFixedDoubleArray()); |
| 1676 | return reinterpret_cast<FixedArrayBase*>(object); |
| 1677 | } |
| 1678 | |
| 1679 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1680 | Object* FixedArray::get(int index) { |
| 1681 | ASSERT(index >= 0 && index < this->length()); |
| 1682 | return READ_FIELD(this, kHeaderSize + index * kPointerSize); |
| 1683 | } |
| 1684 | |
| 1685 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 1686 | bool FixedArray::is_the_hole(int index) { |
| 1687 | return get(index) == GetHeap()->the_hole_value(); |
| 1688 | } |
| 1689 | |
| 1690 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1691 | void FixedArray::set(int index, Smi* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1692 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1693 | ASSERT(index >= 0 && index < this->length()); |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 1694 | ASSERT(reinterpret_cast<Object*>(value)->IsSmi()); |
| 1695 | int offset = kHeaderSize + index * kPointerSize; |
| 1696 | WRITE_FIELD(this, offset, value); |
| 1697 | } |
| 1698 | |
| 1699 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1700 | void FixedArray::set(int index, Object* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1701 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1702 | ASSERT(index >= 0 && index < this->length()); |
| 1703 | int offset = kHeaderSize + index * kPointerSize; |
| 1704 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1705 | WRITE_BARRIER(GetHeap(), this, offset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | |
svenpanne@chromium.org | 84bcc55 | 2011-07-18 09:50:57 +0000 | [diff] [blame] | 1709 | inline bool FixedDoubleArray::is_the_hole_nan(double value) { |
| 1710 | return BitCast<uint64_t, double>(value) == kHoleNanInt64; |
| 1711 | } |
| 1712 | |
| 1713 | |
| 1714 | inline double FixedDoubleArray::hole_nan_as_double() { |
| 1715 | return BitCast<double, uint64_t>(kHoleNanInt64); |
| 1716 | } |
| 1717 | |
| 1718 | |
| 1719 | inline double FixedDoubleArray::canonical_not_the_hole_nan_as_double() { |
| 1720 | ASSERT(BitCast<uint64_t>(OS::nan_value()) != kHoleNanInt64); |
| 1721 | ASSERT((BitCast<uint64_t>(OS::nan_value()) >> 32) != kHoleNanUpper32); |
| 1722 | return OS::nan_value(); |
| 1723 | } |
| 1724 | |
| 1725 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1726 | double FixedDoubleArray::get_scalar(int index) { |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1727 | ASSERT(map() != HEAP->fixed_cow_array_map() && |
| 1728 | map() != HEAP->fixed_array_map()); |
| 1729 | ASSERT(index >= 0 && index < this->length()); |
| 1730 | double result = READ_DOUBLE_FIELD(this, kHeaderSize + index * kDoubleSize); |
| 1731 | ASSERT(!is_the_hole_nan(result)); |
| 1732 | return result; |
| 1733 | } |
| 1734 | |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 1735 | int64_t FixedDoubleArray::get_representation(int index) { |
| 1736 | ASSERT(map() != HEAP->fixed_cow_array_map() && |
| 1737 | map() != HEAP->fixed_array_map()); |
| 1738 | ASSERT(index >= 0 && index < this->length()); |
| 1739 | return READ_INT64_FIELD(this, kHeaderSize + index * kDoubleSize); |
| 1740 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1741 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 1742 | MaybeObject* FixedDoubleArray::get(int index) { |
| 1743 | if (is_the_hole(index)) { |
| 1744 | return GetHeap()->the_hole_value(); |
| 1745 | } else { |
| 1746 | return GetHeap()->NumberFromDouble(get_scalar(index)); |
| 1747 | } |
| 1748 | } |
| 1749 | |
| 1750 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 1751 | void FixedDoubleArray::set(int index, double value) { |
| 1752 | ASSERT(map() != HEAP->fixed_cow_array_map() && |
| 1753 | map() != HEAP->fixed_array_map()); |
| 1754 | int offset = kHeaderSize + index * kDoubleSize; |
| 1755 | if (isnan(value)) value = canonical_not_the_hole_nan_as_double(); |
| 1756 | WRITE_DOUBLE_FIELD(this, offset, value); |
| 1757 | } |
| 1758 | |
| 1759 | |
| 1760 | void FixedDoubleArray::set_the_hole(int index) { |
| 1761 | ASSERT(map() != HEAP->fixed_cow_array_map() && |
| 1762 | map() != HEAP->fixed_array_map()); |
| 1763 | int offset = kHeaderSize + index * kDoubleSize; |
| 1764 | WRITE_DOUBLE_FIELD(this, offset, hole_nan_as_double()); |
| 1765 | } |
| 1766 | |
| 1767 | |
| 1768 | bool FixedDoubleArray::is_the_hole(int index) { |
| 1769 | int offset = kHeaderSize + index * kDoubleSize; |
| 1770 | return is_the_hole_nan(READ_DOUBLE_FIELD(this, offset)); |
| 1771 | } |
| 1772 | |
| 1773 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1774 | WriteBarrierMode HeapObject::GetWriteBarrierMode(const AssertNoAllocation&) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1775 | Heap* heap = GetHeap(); |
| 1776 | if (heap->incremental_marking()->IsMarking()) return UPDATE_WRITE_BARRIER; |
| 1777 | if (heap->InNewSpace(this)) return SKIP_WRITE_BARRIER; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1778 | return UPDATE_WRITE_BARRIER; |
| 1779 | } |
| 1780 | |
| 1781 | |
| 1782 | void FixedArray::set(int index, |
| 1783 | Object* value, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1784 | WriteBarrierMode mode) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1785 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1786 | ASSERT(index >= 0 && index < this->length()); |
| 1787 | int offset = kHeaderSize + index * kPointerSize; |
| 1788 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1789 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, offset, value, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1790 | } |
| 1791 | |
| 1792 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1793 | void FixedArray::NoIncrementalWriteBarrierSet(FixedArray* array, |
| 1794 | int index, |
| 1795 | Object* value) { |
| 1796 | ASSERT(array->map() != HEAP->raw_unchecked_fixed_cow_array_map()); |
| 1797 | ASSERT(index >= 0 && index < array->length()); |
| 1798 | int offset = kHeaderSize + index * kPointerSize; |
| 1799 | WRITE_FIELD(array, offset, value); |
| 1800 | Heap* heap = array->GetHeap(); |
| 1801 | if (heap->InNewSpace(value)) { |
| 1802 | heap->RecordWrite(array->address(), offset); |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 1807 | void FixedArray::NoWriteBarrierSet(FixedArray* array, |
| 1808 | int index, |
| 1809 | Object* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1810 | ASSERT(array->map() != HEAP->raw_unchecked_fixed_cow_array_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1811 | ASSERT(index >= 0 && index < array->length()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1812 | ASSERT(!HEAP->InNewSpace(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1813 | WRITE_FIELD(array, kHeaderSize + index * kPointerSize, value); |
| 1814 | } |
| 1815 | |
| 1816 | |
| 1817 | void FixedArray::set_undefined(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1818 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
| 1819 | set_undefined(GetHeap(), index); |
| 1820 | } |
| 1821 | |
| 1822 | |
| 1823 | void FixedArray::set_undefined(Heap* heap, int index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1824 | ASSERT(index >= 0 && index < this->length()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1825 | ASSERT(!heap->InNewSpace(heap->undefined_value())); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1826 | WRITE_FIELD(this, kHeaderSize + index * kPointerSize, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1827 | heap->undefined_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1831 | void FixedArray::set_null(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1832 | set_null(GetHeap(), index); |
| 1833 | } |
| 1834 | |
| 1835 | |
| 1836 | void FixedArray::set_null(Heap* heap, int index) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1837 | ASSERT(index >= 0 && index < this->length()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1838 | ASSERT(!heap->InNewSpace(heap->null_value())); |
| 1839 | WRITE_FIELD(this, kHeaderSize + index * kPointerSize, heap->null_value()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1843 | void FixedArray::set_the_hole(int index) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1844 | ASSERT(map() != HEAP->fixed_cow_array_map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1845 | ASSERT(index >= 0 && index < this->length()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1846 | ASSERT(!HEAP->InNewSpace(HEAP->the_hole_value())); |
| 1847 | WRITE_FIELD(this, |
| 1848 | kHeaderSize + index * kPointerSize, |
| 1849 | GetHeap()->the_hole_value()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1853 | void FixedArray::set_unchecked(int index, Smi* value) { |
| 1854 | ASSERT(reinterpret_cast<Object*>(value)->IsSmi()); |
| 1855 | int offset = kHeaderSize + index * kPointerSize; |
| 1856 | WRITE_FIELD(this, offset, value); |
| 1857 | } |
| 1858 | |
| 1859 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1860 | void FixedArray::set_unchecked(Heap* heap, |
| 1861 | int index, |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1862 | Object* value, |
| 1863 | WriteBarrierMode mode) { |
| 1864 | int offset = kHeaderSize + index * kPointerSize; |
| 1865 | WRITE_FIELD(this, offset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1866 | CONDITIONAL_WRITE_BARRIER(heap, this, offset, value, mode); |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1870 | void FixedArray::set_null_unchecked(Heap* heap, int index) { |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1871 | ASSERT(index >= 0 && index < this->length()); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 1872 | ASSERT(!heap->InNewSpace(heap->null_value())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1873 | WRITE_FIELD(this, kHeaderSize + index * kPointerSize, heap->null_value()); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 1877 | Object** FixedArray::data_start() { |
| 1878 | return HeapObject::RawField(this, kHeaderSize); |
| 1879 | } |
| 1880 | |
| 1881 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1882 | bool DescriptorArray::IsEmpty() { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1883 | ASSERT(length() >= kFirstIndex || |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1884 | this == HEAP->empty_descriptor_array()); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1885 | return length() < kFirstIndex; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 1886 | } |
| 1887 | |
| 1888 | |
| 1889 | bool DescriptorArray::MayContainTransitions() { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 1890 | return !IsEmpty(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1894 | bool DescriptorArray::HasTransitionArray() { |
| 1895 | return MayContainTransitions() && !get(kTransitionsIndex)->IsSmi(); |
| 1896 | } |
| 1897 | |
| 1898 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 1899 | Object* DescriptorArray::back_pointer_storage() { |
| 1900 | return READ_FIELD(this, kBackPointerStorageOffset); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 1903 | |
| 1904 | void DescriptorArray::set_back_pointer_storage(Object* value, |
| 1905 | WriteBarrierMode mode) { |
| 1906 | ASSERT(length() > kBackPointerStorageIndex); |
| 1907 | Heap* heap = GetHeap(); |
| 1908 | WRITE_FIELD(this, kBackPointerStorageOffset, value); |
| 1909 | CONDITIONAL_WRITE_BARRIER(heap, this, kBackPointerStorageOffset, value, mode); |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1913 | void DescriptorArray::NoIncrementalWriteBarrierSwap(FixedArray* array, |
| 1914 | int first, |
| 1915 | int second) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1916 | Object* tmp = array->get(first); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1917 | NoIncrementalWriteBarrierSet(array, first, array->get(second)); |
| 1918 | NoIncrementalWriteBarrierSet(array, second, tmp); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1922 | // Perform a binary search in a fixed array. Low and high are entry indices. If |
| 1923 | // there are three entries in this array it should be called with low=0 and |
| 1924 | // high=2. |
| 1925 | template<typename T> |
| 1926 | int BinarySearch(T* array, String* name, int low, int high) { |
| 1927 | uint32_t hash = name->Hash(); |
| 1928 | int limit = high; |
| 1929 | |
| 1930 | ASSERT(low <= high); |
| 1931 | |
| 1932 | while (low != high) { |
| 1933 | int mid = (low + high) / 2; |
| 1934 | String* mid_name = array->GetKey(mid); |
| 1935 | uint32_t mid_hash = mid_name->Hash(); |
| 1936 | |
| 1937 | if (mid_hash >= hash) { |
| 1938 | high = mid; |
| 1939 | } else { |
| 1940 | low = mid + 1; |
| 1941 | } |
| 1942 | } |
| 1943 | |
| 1944 | for (; low <= limit && array->GetKey(low)->Hash() == hash; ++low) { |
| 1945 | if (array->GetKey(low)->Equals(name)) return low; |
| 1946 | } |
| 1947 | |
| 1948 | return T::kNotFound; |
| 1949 | } |
| 1950 | |
| 1951 | |
| 1952 | // Perform a linear search in this fixed array. len is the number of entry |
| 1953 | // indices that are valid. |
| 1954 | template<typename T> |
| 1955 | int LinearSearch(T* array, SearchMode mode, String* name, int len) { |
| 1956 | uint32_t hash = name->Hash(); |
| 1957 | for (int number = 0; number < len; number++) { |
| 1958 | String* entry = array->GetKey(number); |
| 1959 | uint32_t current_hash = entry->Hash(); |
| 1960 | if (mode == EXPECT_SORTED && current_hash > hash) break; |
| 1961 | if (current_hash == hash && name->Equals(entry)) return number; |
| 1962 | } |
| 1963 | return T::kNotFound; |
| 1964 | } |
| 1965 | |
| 1966 | |
| 1967 | template<typename T> |
| 1968 | int Search(T* array, String* name) { |
| 1969 | SLOW_ASSERT(array->IsSortedNoDuplicates()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1970 | |
| 1971 | // Check for empty descriptor array. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1972 | int nof = array->number_of_entries(); |
| 1973 | if (nof == 0) return T::kNotFound; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1974 | |
| 1975 | // Fast case: do linear search for small arrays. |
| 1976 | const int kMaxElementsForLinearSearch = 8; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 1977 | if (StringShape(name).IsSymbol() && nof < kMaxElementsForLinearSearch) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1978 | return LinearSearch(array, EXPECT_SORTED, name, nof); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1979 | } |
| 1980 | |
| 1981 | // Slow case: perform binary search. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1982 | return BinarySearch(array, name, 0, nof - 1); |
| 1983 | } |
| 1984 | |
| 1985 | |
| 1986 | int DescriptorArray::Search(String* name) { |
| 1987 | return internal::Search(this, name); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
| 1990 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1991 | int DescriptorArray::SearchWithCache(String* name) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1992 | DescriptorLookupCache* cache = GetIsolate()->descriptor_lookup_cache(); |
| 1993 | int number = cache->Lookup(this, name); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1994 | if (number == DescriptorLookupCache::kAbsent) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 1995 | number = internal::Search(this, name); |
| 1996 | cache->Update(this, name, number); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 1997 | } |
| 1998 | return number; |
| 1999 | } |
| 2000 | |
| 2001 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2002 | TransitionArray* DescriptorArray::transitions() { |
| 2003 | ASSERT(MayContainTransitions()); |
| 2004 | Object* array = get(kTransitionsIndex); |
| 2005 | return TransitionArray::cast(array); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
| 2008 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2009 | void DescriptorArray::ClearTransitions() { |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 2010 | WRITE_FIELD(this, kTransitionsOffset, Smi::FromInt(0)); |
| 2011 | } |
| 2012 | |
| 2013 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2014 | void DescriptorArray::set_transitions(TransitionArray* transitions_array, |
| 2015 | WriteBarrierMode mode) { |
| 2016 | Heap* heap = GetHeap(); |
| 2017 | WRITE_FIELD(this, kTransitionsOffset, transitions_array); |
| 2018 | CONDITIONAL_WRITE_BARRIER( |
| 2019 | heap, this, kTransitionsOffset, transitions_array, mode); |
| 2020 | } |
| 2021 | |
| 2022 | |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2023 | Object** DescriptorArray::GetKeySlot(int descriptor_number) { |
| 2024 | ASSERT(descriptor_number < number_of_descriptors()); |
| 2025 | return HeapObject::RawField( |
| 2026 | reinterpret_cast<HeapObject*>(this), |
| 2027 | OffsetOfElementAt(ToKeyIndex(descriptor_number))); |
| 2028 | } |
| 2029 | |
| 2030 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2031 | String* DescriptorArray::GetKey(int descriptor_number) { |
| 2032 | ASSERT(descriptor_number < number_of_descriptors()); |
| 2033 | return String::cast(get(ToKeyIndex(descriptor_number))); |
| 2034 | } |
| 2035 | |
| 2036 | |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2037 | Object** DescriptorArray::GetValueSlot(int descriptor_number) { |
| 2038 | ASSERT(descriptor_number < number_of_descriptors()); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2039 | return HeapObject::RawField( |
| 2040 | reinterpret_cast<HeapObject*>(this), |
| 2041 | OffsetOfElementAt(ToValueIndex(descriptor_number))); |
verwaest@chromium.org | 3714139 | 2012-05-31 13:27:02 +0000 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2045 | Object* DescriptorArray::GetValue(int descriptor_number) { |
| 2046 | ASSERT(descriptor_number < number_of_descriptors()); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2047 | return get(ToValueIndex(descriptor_number)); |
| 2048 | } |
| 2049 | |
| 2050 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2051 | PropertyDetails DescriptorArray::GetDetails(int descriptor_number) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2052 | ASSERT(descriptor_number < number_of_descriptors()); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2053 | Object* details = get(ToDetailsIndex(descriptor_number)); |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2054 | return PropertyDetails(Smi::cast(details)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2058 | PropertyType DescriptorArray::GetType(int descriptor_number) { |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2059 | return GetDetails(descriptor_number).type(); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | |
| 2063 | int DescriptorArray::GetFieldIndex(int descriptor_number) { |
| 2064 | return Descriptor::IndexFromValue(GetValue(descriptor_number)); |
| 2065 | } |
| 2066 | |
| 2067 | |
| 2068 | JSFunction* DescriptorArray::GetConstantFunction(int descriptor_number) { |
| 2069 | return JSFunction::cast(GetValue(descriptor_number)); |
| 2070 | } |
| 2071 | |
| 2072 | |
| 2073 | Object* DescriptorArray::GetCallbacksObject(int descriptor_number) { |
| 2074 | ASSERT(GetType(descriptor_number) == CALLBACKS); |
| 2075 | return GetValue(descriptor_number); |
| 2076 | } |
| 2077 | |
| 2078 | |
| 2079 | AccessorDescriptor* DescriptorArray::GetCallbacks(int descriptor_number) { |
| 2080 | ASSERT(GetType(descriptor_number) == CALLBACKS); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2081 | Foreign* p = Foreign::cast(GetCallbacksObject(descriptor_number)); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2082 | return reinterpret_cast<AccessorDescriptor*>(p->foreign_address()); |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 2083 | } |
| 2084 | |
| 2085 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2086 | void DescriptorArray::Get(int descriptor_number, Descriptor* desc) { |
| 2087 | desc->Init(GetKey(descriptor_number), |
| 2088 | GetValue(descriptor_number), |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 2089 | GetDetails(descriptor_number)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2093 | void DescriptorArray::Set(int descriptor_number, |
| 2094 | Descriptor* desc, |
| 2095 | const WhitenessWitness&) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2096 | // Range check. |
| 2097 | ASSERT(descriptor_number < number_of_descriptors()); |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame^] | 2098 | ASSERT(desc->GetDetails().index() <= number_of_descriptors()); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 2099 | ASSERT(desc->GetDetails().index() > 0); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2100 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2101 | NoIncrementalWriteBarrierSet(this, |
| 2102 | ToKeyIndex(descriptor_number), |
| 2103 | desc->GetKey()); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2104 | NoIncrementalWriteBarrierSet(this, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2105 | ToValueIndex(descriptor_number), |
| 2106 | desc->GetValue()); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2107 | NoIncrementalWriteBarrierSet(this, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2108 | ToDetailsIndex(descriptor_number), |
| 2109 | desc->GetDetails().AsSmi()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame^] | 2113 | void DescriptorArray::Append(Descriptor* desc, |
| 2114 | const WhitenessWitness& witness) { |
| 2115 | int descriptor_number = NumberOfSetDescriptors(); |
| 2116 | int enumeration_index = descriptor_number + 1; |
| 2117 | desc->SetEnumerationIndex(enumeration_index); |
| 2118 | Set(descriptor_number, desc, witness); |
| 2119 | SetLastAdded(descriptor_number); |
| 2120 | } |
| 2121 | |
| 2122 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2123 | void DescriptorArray::NoIncrementalWriteBarrierSwapDescriptors( |
| 2124 | int first, int second) { |
| 2125 | NoIncrementalWriteBarrierSwap(this, ToKeyIndex(first), ToKeyIndex(second)); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2126 | NoIncrementalWriteBarrierSwap(this, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2127 | ToValueIndex(first), |
| 2128 | ToValueIndex(second)); |
rossberg@chromium.org | 400388e | 2012-06-06 09:29:22 +0000 | [diff] [blame] | 2129 | NoIncrementalWriteBarrierSwap(this, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2130 | ToDetailsIndex(first), |
| 2131 | ToDetailsIndex(second)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2135 | FixedArray::WhitenessWitness::WhitenessWitness(FixedArray* array) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2136 | : marking_(array->GetHeap()->incremental_marking()) { |
| 2137 | marking_->EnterNoMarkingScope(); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2138 | ASSERT(Marking::Color(array) == Marking::WHITE_OBJECT); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 2142 | FixedArray::WhitenessWitness::~WhitenessWitness() { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2143 | marking_->LeaveNoMarkingScope(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2147 | template<typename Shape, typename Key> |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 2148 | int HashTable<Shape, Key>::ComputeCapacity(int at_least_space_for) { |
| 2149 | const int kMinCapacity = 32; |
| 2150 | int capacity = RoundUpToPowerOf2(at_least_space_for * 2); |
| 2151 | if (capacity < kMinCapacity) { |
| 2152 | capacity = kMinCapacity; // Guarantee min capacity. |
| 2153 | } |
| 2154 | return capacity; |
| 2155 | } |
| 2156 | |
| 2157 | |
| 2158 | template<typename Shape, typename Key> |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2159 | int HashTable<Shape, Key>::FindEntry(Key key) { |
| 2160 | return FindEntry(GetIsolate(), key); |
| 2161 | } |
| 2162 | |
| 2163 | |
| 2164 | // Find entry for key otherwise return kNotFound. |
| 2165 | template<typename Shape, typename Key> |
| 2166 | int HashTable<Shape, Key>::FindEntry(Isolate* isolate, Key key) { |
| 2167 | uint32_t capacity = Capacity(); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2168 | uint32_t entry = FirstProbe(HashTable<Shape, Key>::Hash(key), capacity); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2169 | uint32_t count = 1; |
| 2170 | // EnsureCapacity will guarantee the hash table is never full. |
| 2171 | while (true) { |
| 2172 | Object* element = KeyAt(entry); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 2173 | // Empty entry. |
| 2174 | if (element == isolate->heap()->raw_unchecked_undefined_value()) break; |
| 2175 | if (element != isolate->heap()->raw_unchecked_the_hole_value() && |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2176 | Shape::IsMatch(key, element)) return entry; |
| 2177 | entry = NextProbe(entry, count++, capacity); |
| 2178 | } |
| 2179 | return kNotFound; |
| 2180 | } |
| 2181 | |
| 2182 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2183 | bool SeededNumberDictionary::requires_slow_elements() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2184 | Object* max_index_object = get(kMaxNumberKeyIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2185 | if (!max_index_object->IsSmi()) return false; |
| 2186 | return 0 != |
| 2187 | (Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask); |
| 2188 | } |
| 2189 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2190 | uint32_t SeededNumberDictionary::max_number_key() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2191 | ASSERT(!requires_slow_elements()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2192 | Object* max_index_object = get(kMaxNumberKeyIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2193 | if (!max_index_object->IsSmi()) return 0; |
| 2194 | uint32_t value = static_cast<uint32_t>(Smi::cast(max_index_object)->value()); |
| 2195 | return value >> kRequiresSlowElementsTagSize; |
| 2196 | } |
| 2197 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2198 | void SeededNumberDictionary::set_requires_slow_elements() { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 2199 | set(kMaxNumberKeyIndex, Smi::FromInt(kRequiresSlowElementsMask)); |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2203 | // ------------------------------------ |
| 2204 | // Cast operations |
| 2205 | |
| 2206 | |
| 2207 | CAST_ACCESSOR(FixedArray) |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2208 | CAST_ACCESSOR(FixedDoubleArray) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2209 | CAST_ACCESSOR(DescriptorArray) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2210 | CAST_ACCESSOR(DeoptimizationInputData) |
| 2211 | CAST_ACCESSOR(DeoptimizationOutputData) |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2212 | CAST_ACCESSOR(TypeFeedbackCells) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2213 | CAST_ACCESSOR(SymbolTable) |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2214 | CAST_ACCESSOR(JSFunctionResultCache) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2215 | CAST_ACCESSOR(NormalizedMapCache) |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 2216 | CAST_ACCESSOR(ScopeInfo) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 2217 | CAST_ACCESSOR(CompilationCacheTable) |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2218 | CAST_ACCESSOR(CodeCacheHashTable) |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 2219 | CAST_ACCESSOR(PolymorphicCodeCacheHashTable) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2220 | CAST_ACCESSOR(MapCache) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2221 | CAST_ACCESSOR(String) |
| 2222 | CAST_ACCESSOR(SeqString) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2223 | CAST_ACCESSOR(SeqAsciiString) |
| 2224 | CAST_ACCESSOR(SeqTwoByteString) |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2225 | CAST_ACCESSOR(SlicedString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2226 | CAST_ACCESSOR(ConsString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2227 | CAST_ACCESSOR(ExternalString) |
| 2228 | CAST_ACCESSOR(ExternalAsciiString) |
| 2229 | CAST_ACCESSOR(ExternalTwoByteString) |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2230 | CAST_ACCESSOR(JSReceiver) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2231 | CAST_ACCESSOR(JSObject) |
| 2232 | CAST_ACCESSOR(Smi) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2233 | CAST_ACCESSOR(HeapObject) |
| 2234 | CAST_ACCESSOR(HeapNumber) |
| 2235 | CAST_ACCESSOR(Oddball) |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 2236 | CAST_ACCESSOR(JSGlobalPropertyCell) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2237 | CAST_ACCESSOR(SharedFunctionInfo) |
| 2238 | CAST_ACCESSOR(Map) |
| 2239 | CAST_ACCESSOR(JSFunction) |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2240 | CAST_ACCESSOR(GlobalObject) |
| 2241 | CAST_ACCESSOR(JSGlobalProxy) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2242 | CAST_ACCESSOR(JSGlobalObject) |
| 2243 | CAST_ACCESSOR(JSBuiltinsObject) |
| 2244 | CAST_ACCESSOR(Code) |
| 2245 | CAST_ACCESSOR(JSArray) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2246 | CAST_ACCESSOR(JSRegExp) |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2247 | CAST_ACCESSOR(JSProxy) |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2248 | CAST_ACCESSOR(JSFunctionProxy) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 2249 | CAST_ACCESSOR(JSSet) |
| 2250 | CAST_ACCESSOR(JSMap) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2251 | CAST_ACCESSOR(JSWeakMap) |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 2252 | CAST_ACCESSOR(Foreign) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2253 | CAST_ACCESSOR(ByteArray) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2254 | CAST_ACCESSOR(FreeSpace) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2255 | CAST_ACCESSOR(ExternalArray) |
| 2256 | CAST_ACCESSOR(ExternalByteArray) |
| 2257 | CAST_ACCESSOR(ExternalUnsignedByteArray) |
| 2258 | CAST_ACCESSOR(ExternalShortArray) |
| 2259 | CAST_ACCESSOR(ExternalUnsignedShortArray) |
| 2260 | CAST_ACCESSOR(ExternalIntArray) |
| 2261 | CAST_ACCESSOR(ExternalUnsignedIntArray) |
| 2262 | CAST_ACCESSOR(ExternalFloatArray) |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2263 | CAST_ACCESSOR(ExternalDoubleArray) |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2264 | CAST_ACCESSOR(ExternalPixelArray) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2265 | CAST_ACCESSOR(Struct) |
| 2266 | |
| 2267 | |
| 2268 | #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name) |
| 2269 | STRUCT_LIST(MAKE_STRUCT_CAST) |
| 2270 | #undef MAKE_STRUCT_CAST |
| 2271 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 2272 | |
| 2273 | template <typename Shape, typename Key> |
| 2274 | HashTable<Shape, Key>* HashTable<Shape, Key>::cast(Object* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2275 | ASSERT(obj->IsHashTable()); |
| 2276 | return reinterpret_cast<HashTable*>(obj); |
| 2277 | } |
| 2278 | |
| 2279 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2280 | SMI_ACCESSORS(FixedArrayBase, length, kLengthOffset) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2281 | SMI_ACCESSORS(FreeSpace, size, kSizeOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2282 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2283 | SMI_ACCESSORS(String, length, kLengthOffset) |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2284 | |
| 2285 | |
| 2286 | uint32_t String::hash_field() { |
| 2287 | return READ_UINT32_FIELD(this, kHashFieldOffset); |
| 2288 | } |
| 2289 | |
| 2290 | |
| 2291 | void String::set_hash_field(uint32_t value) { |
| 2292 | WRITE_UINT32_FIELD(this, kHashFieldOffset, value); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 2293 | #if V8_HOST_ARCH_64_BIT |
| 2294 | WRITE_UINT32_FIELD(this, kHashFieldOffset + kIntSize, 0); |
| 2295 | #endif |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2299 | bool String::Equals(String* other) { |
| 2300 | if (other == this) return true; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2301 | if (StringShape(this).IsSymbol() && StringShape(other).IsSymbol()) { |
| 2302 | return false; |
| 2303 | } |
| 2304 | return SlowEquals(other); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2308 | MaybeObject* String::TryFlatten(PretenureFlag pretenure) { |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2309 | if (!StringShape(this).IsCons()) return this; |
| 2310 | ConsString* cons = ConsString::cast(this); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2311 | if (cons->IsFlat()) return cons->first(); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 2312 | return SlowTryFlatten(pretenure); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2316 | String* String::TryFlattenGetString(PretenureFlag pretenure) { |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 2317 | MaybeObject* flat = TryFlatten(pretenure); |
| 2318 | Object* successfully_flattened; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2319 | if (!flat->ToObject(&successfully_flattened)) return this; |
| 2320 | return String::cast(successfully_flattened); |
erik.corry@gmail.com | 9dfbea4 | 2010-05-21 12:58:28 +0000 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2324 | uint16_t String::Get(int index) { |
| 2325 | ASSERT(index >= 0 && index < length()); |
| 2326 | switch (StringShape(this).full_representation_tag()) { |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2327 | case kSeqStringTag | kAsciiStringTag: |
| 2328 | return SeqAsciiString::cast(this)->SeqAsciiStringGet(index); |
| 2329 | case kSeqStringTag | kTwoByteStringTag: |
| 2330 | return SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); |
| 2331 | case kConsStringTag | kAsciiStringTag: |
| 2332 | case kConsStringTag | kTwoByteStringTag: |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2333 | return ConsString::cast(this)->ConsStringGet(index); |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2334 | case kExternalStringTag | kAsciiStringTag: |
| 2335 | return ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index); |
| 2336 | case kExternalStringTag | kTwoByteStringTag: |
| 2337 | return ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2338 | case kSlicedStringTag | kAsciiStringTag: |
| 2339 | case kSlicedStringTag | kTwoByteStringTag: |
| 2340 | return SlicedString::cast(this)->SlicedStringGet(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2341 | default: |
| 2342 | break; |
| 2343 | } |
| 2344 | |
| 2345 | UNREACHABLE(); |
| 2346 | return 0; |
| 2347 | } |
| 2348 | |
| 2349 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2350 | void String::Set(int index, uint16_t value) { |
| 2351 | ASSERT(index >= 0 && index < length()); |
| 2352 | ASSERT(StringShape(this).IsSequential()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2353 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 2354 | return this->IsAsciiRepresentation() |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2355 | ? SeqAsciiString::cast(this)->SeqAsciiStringSet(index, value) |
| 2356 | : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2360 | bool String::IsFlat() { |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2361 | if (!StringShape(this).IsCons()) return true; |
| 2362 | return ConsString::cast(this)->second()->length() == 0; |
| 2363 | } |
| 2364 | |
| 2365 | |
| 2366 | String* String::GetUnderlying() { |
| 2367 | // Giving direct access to underlying string only makes sense if the |
| 2368 | // wrapping string is already flattened. |
| 2369 | ASSERT(this->IsFlat()); |
| 2370 | ASSERT(StringShape(this).IsIndirect()); |
| 2371 | STATIC_ASSERT(ConsString::kFirstOffset == SlicedString::kParentOffset); |
| 2372 | const int kUnderlyingOffset = SlicedString::kParentOffset; |
| 2373 | return String::cast(READ_FIELD(this, kUnderlyingOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2377 | uint16_t SeqAsciiString::SeqAsciiStringGet(int index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2378 | ASSERT(index >= 0 && index < length()); |
| 2379 | return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
| 2380 | } |
| 2381 | |
| 2382 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2383 | void SeqAsciiString::SeqAsciiStringSet(int index, uint16_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2384 | ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode); |
| 2385 | WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, |
| 2386 | static_cast<byte>(value)); |
| 2387 | } |
| 2388 | |
| 2389 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2390 | Address SeqAsciiString::GetCharsAddress() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2391 | return FIELD_ADDR(this, kHeaderSize); |
| 2392 | } |
| 2393 | |
| 2394 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2395 | char* SeqAsciiString::GetChars() { |
| 2396 | return reinterpret_cast<char*>(GetCharsAddress()); |
| 2397 | } |
| 2398 | |
| 2399 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2400 | Address SeqTwoByteString::GetCharsAddress() { |
| 2401 | return FIELD_ADDR(this, kHeaderSize); |
| 2402 | } |
| 2403 | |
| 2404 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2405 | uc16* SeqTwoByteString::GetChars() { |
| 2406 | return reinterpret_cast<uc16*>(FIELD_ADDR(this, kHeaderSize)); |
| 2407 | } |
| 2408 | |
| 2409 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2410 | uint16_t SeqTwoByteString::SeqTwoByteStringGet(int index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2411 | ASSERT(index >= 0 && index < length()); |
| 2412 | return READ_SHORT_FIELD(this, kHeaderSize + index * kShortSize); |
| 2413 | } |
| 2414 | |
| 2415 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2416 | void SeqTwoByteString::SeqTwoByteStringSet(int index, uint16_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2417 | ASSERT(index >= 0 && index < length()); |
| 2418 | WRITE_SHORT_FIELD(this, kHeaderSize + index * kShortSize, value); |
| 2419 | } |
| 2420 | |
| 2421 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2422 | int SeqTwoByteString::SeqTwoByteStringSize(InstanceType instance_type) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2423 | return SizeFor(length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2424 | } |
| 2425 | |
| 2426 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 2427 | int SeqAsciiString::SeqAsciiStringSize(InstanceType instance_type) { |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2428 | return SizeFor(length()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2429 | } |
| 2430 | |
| 2431 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2432 | String* SlicedString::parent() { |
| 2433 | return String::cast(READ_FIELD(this, kParentOffset)); |
| 2434 | } |
| 2435 | |
| 2436 | |
| 2437 | void SlicedString::set_parent(String* parent) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2438 | ASSERT(parent->IsSeqString() || parent->IsExternalString()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2439 | WRITE_FIELD(this, kParentOffset, parent); |
| 2440 | } |
| 2441 | |
| 2442 | |
| 2443 | SMI_ACCESSORS(SlicedString, offset, kOffsetOffset) |
| 2444 | |
| 2445 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2446 | String* ConsString::first() { |
| 2447 | return String::cast(READ_FIELD(this, kFirstOffset)); |
| 2448 | } |
| 2449 | |
| 2450 | |
| 2451 | Object* ConsString::unchecked_first() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2452 | return READ_FIELD(this, kFirstOffset); |
| 2453 | } |
| 2454 | |
| 2455 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2456 | void ConsString::set_first(String* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2457 | WRITE_FIELD(this, kFirstOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2458 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kFirstOffset, value, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2462 | String* ConsString::second() { |
| 2463 | return String::cast(READ_FIELD(this, kSecondOffset)); |
| 2464 | } |
| 2465 | |
| 2466 | |
| 2467 | Object* ConsString::unchecked_second() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2468 | return READ_FIELD(this, kSecondOffset); |
| 2469 | } |
| 2470 | |
| 2471 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2472 | void ConsString::set_second(String* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2473 | WRITE_FIELD(this, kSecondOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2474 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kSecondOffset, value, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2475 | } |
| 2476 | |
| 2477 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2478 | bool ExternalString::is_short() { |
| 2479 | InstanceType type = map()->instance_type(); |
| 2480 | return (type & kShortExternalStringMask) == kShortExternalStringTag; |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2484 | const ExternalAsciiString::Resource* ExternalAsciiString::resource() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2485 | return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); |
| 2486 | } |
| 2487 | |
| 2488 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2489 | void ExternalAsciiString::update_data_cache() { |
| 2490 | if (is_short()) return; |
| 2491 | const char** data_field = |
| 2492 | reinterpret_cast<const char**>(FIELD_ADDR(this, kResourceDataOffset)); |
| 2493 | *data_field = resource()->data(); |
| 2494 | } |
| 2495 | |
| 2496 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2497 | void ExternalAsciiString::set_resource( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2498 | const ExternalAsciiString::Resource* resource) { |
| 2499 | *reinterpret_cast<const Resource**>( |
| 2500 | FIELD_ADDR(this, kResourceOffset)) = resource; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2501 | if (resource != NULL) update_data_cache(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | |
| 2505 | const char* ExternalAsciiString::GetChars() { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2506 | return resource()->data(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | |
| 2510 | uint16_t ExternalAsciiString::ExternalAsciiStringGet(int index) { |
| 2511 | ASSERT(index >= 0 && index < length()); |
| 2512 | return GetChars()[index]; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2513 | } |
| 2514 | |
| 2515 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2516 | const ExternalTwoByteString::Resource* ExternalTwoByteString::resource() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2517 | return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); |
| 2518 | } |
| 2519 | |
| 2520 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2521 | void ExternalTwoByteString::update_data_cache() { |
| 2522 | if (is_short()) return; |
| 2523 | const uint16_t** data_field = |
| 2524 | reinterpret_cast<const uint16_t**>(FIELD_ADDR(this, kResourceDataOffset)); |
| 2525 | *data_field = resource()->data(); |
| 2526 | } |
| 2527 | |
| 2528 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2529 | void ExternalTwoByteString::set_resource( |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2530 | const ExternalTwoByteString::Resource* resource) { |
| 2531 | *reinterpret_cast<const Resource**>( |
| 2532 | FIELD_ADDR(this, kResourceOffset)) = resource; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2533 | if (resource != NULL) update_data_cache(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | |
| 2537 | const uint16_t* ExternalTwoByteString::GetChars() { |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2538 | return resource()->data(); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | |
| 2542 | uint16_t ExternalTwoByteString::ExternalTwoByteStringGet(int index) { |
| 2543 | ASSERT(index >= 0 && index < length()); |
| 2544 | return GetChars()[index]; |
| 2545 | } |
| 2546 | |
| 2547 | |
| 2548 | const uint16_t* ExternalTwoByteString::ExternalTwoByteStringGetData( |
| 2549 | unsigned start) { |
| 2550 | return GetChars() + start; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2554 | void JSFunctionResultCache::MakeZeroSize() { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2555 | set_finger_index(kEntriesIndex); |
| 2556 | set_size(kEntriesIndex); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | |
| 2560 | void JSFunctionResultCache::Clear() { |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2561 | int cache_size = size(); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2562 | Object** entries_start = RawField(this, OffsetOfElementAt(kEntriesIndex)); |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2563 | MemsetPointer(entries_start, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2564 | GetHeap()->the_hole_value(), |
fschneider@chromium.org | e03fb64 | 2010-11-01 12:34:09 +0000 | [diff] [blame] | 2565 | cache_size - kEntriesIndex); |
ager@chromium.org | ac091b7 | 2010-05-05 07:34:42 +0000 | [diff] [blame] | 2566 | MakeZeroSize(); |
| 2567 | } |
| 2568 | |
| 2569 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 2570 | int JSFunctionResultCache::size() { |
| 2571 | return Smi::cast(get(kCacheSizeIndex))->value(); |
| 2572 | } |
| 2573 | |
| 2574 | |
| 2575 | void JSFunctionResultCache::set_size(int size) { |
| 2576 | set(kCacheSizeIndex, Smi::FromInt(size)); |
| 2577 | } |
| 2578 | |
| 2579 | |
| 2580 | int JSFunctionResultCache::finger_index() { |
| 2581 | return Smi::cast(get(kFingerIndex))->value(); |
| 2582 | } |
| 2583 | |
| 2584 | |
| 2585 | void JSFunctionResultCache::set_finger_index(int finger_index) { |
| 2586 | set(kFingerIndex, Smi::FromInt(finger_index)); |
| 2587 | } |
| 2588 | |
| 2589 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2590 | byte ByteArray::get(int index) { |
| 2591 | ASSERT(index >= 0 && index < this->length()); |
| 2592 | return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
| 2593 | } |
| 2594 | |
| 2595 | |
| 2596 | void ByteArray::set(int index, byte value) { |
| 2597 | ASSERT(index >= 0 && index < this->length()); |
| 2598 | WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value); |
| 2599 | } |
| 2600 | |
| 2601 | |
| 2602 | int ByteArray::get_int(int index) { |
| 2603 | ASSERT(index >= 0 && (index * kIntSize) < this->length()); |
| 2604 | return READ_INT_FIELD(this, kHeaderSize + index * kIntSize); |
| 2605 | } |
| 2606 | |
| 2607 | |
| 2608 | ByteArray* ByteArray::FromDataStartAddress(Address address) { |
| 2609 | ASSERT_TAG_ALIGNED(address); |
| 2610 | return reinterpret_cast<ByteArray*>(address - kHeaderSize + kHeapObjectTag); |
| 2611 | } |
| 2612 | |
| 2613 | |
| 2614 | Address ByteArray::GetDataStartAddress() { |
| 2615 | return reinterpret_cast<Address>(this) - kHeapObjectTag + kHeaderSize; |
| 2616 | } |
| 2617 | |
| 2618 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2619 | uint8_t* ExternalPixelArray::external_pixel_pointer() { |
| 2620 | return reinterpret_cast<uint8_t*>(external_pointer()); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2624 | uint8_t ExternalPixelArray::get_scalar(int index) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2625 | ASSERT((index >= 0) && (index < this->length())); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2626 | uint8_t* ptr = external_pixel_pointer(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2627 | return ptr[index]; |
| 2628 | } |
| 2629 | |
| 2630 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2631 | MaybeObject* ExternalPixelArray::get(int index) { |
| 2632 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2633 | } |
| 2634 | |
| 2635 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2636 | void ExternalPixelArray::set(int index, uint8_t value) { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2637 | ASSERT((index >= 0) && (index < this->length())); |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2638 | uint8_t* ptr = external_pixel_pointer(); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 2639 | ptr[index] = value; |
| 2640 | } |
| 2641 | |
| 2642 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2643 | void* ExternalArray::external_pointer() { |
| 2644 | intptr_t ptr = READ_INTPTR_FIELD(this, kExternalPointerOffset); |
| 2645 | return reinterpret_cast<void*>(ptr); |
| 2646 | } |
| 2647 | |
| 2648 | |
| 2649 | void ExternalArray::set_external_pointer(void* value, WriteBarrierMode mode) { |
| 2650 | intptr_t ptr = reinterpret_cast<intptr_t>(value); |
| 2651 | WRITE_INTPTR_FIELD(this, kExternalPointerOffset, ptr); |
| 2652 | } |
| 2653 | |
| 2654 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2655 | int8_t ExternalByteArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2656 | ASSERT((index >= 0) && (index < this->length())); |
| 2657 | int8_t* ptr = static_cast<int8_t*>(external_pointer()); |
| 2658 | return ptr[index]; |
| 2659 | } |
| 2660 | |
| 2661 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2662 | MaybeObject* ExternalByteArray::get(int index) { |
| 2663 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2664 | } |
| 2665 | |
| 2666 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2667 | void ExternalByteArray::set(int index, int8_t value) { |
| 2668 | ASSERT((index >= 0) && (index < this->length())); |
| 2669 | int8_t* ptr = static_cast<int8_t*>(external_pointer()); |
| 2670 | ptr[index] = value; |
| 2671 | } |
| 2672 | |
| 2673 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2674 | uint8_t ExternalUnsignedByteArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2675 | ASSERT((index >= 0) && (index < this->length())); |
| 2676 | uint8_t* ptr = static_cast<uint8_t*>(external_pointer()); |
| 2677 | return ptr[index]; |
| 2678 | } |
| 2679 | |
| 2680 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2681 | MaybeObject* ExternalUnsignedByteArray::get(int index) { |
| 2682 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2683 | } |
| 2684 | |
| 2685 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2686 | void ExternalUnsignedByteArray::set(int index, uint8_t value) { |
| 2687 | ASSERT((index >= 0) && (index < this->length())); |
| 2688 | uint8_t* ptr = static_cast<uint8_t*>(external_pointer()); |
| 2689 | ptr[index] = value; |
| 2690 | } |
| 2691 | |
| 2692 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2693 | int16_t ExternalShortArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2694 | ASSERT((index >= 0) && (index < this->length())); |
| 2695 | int16_t* ptr = static_cast<int16_t*>(external_pointer()); |
| 2696 | return ptr[index]; |
| 2697 | } |
| 2698 | |
| 2699 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2700 | MaybeObject* ExternalShortArray::get(int index) { |
| 2701 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2702 | } |
| 2703 | |
| 2704 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2705 | void ExternalShortArray::set(int index, int16_t value) { |
| 2706 | ASSERT((index >= 0) && (index < this->length())); |
| 2707 | int16_t* ptr = static_cast<int16_t*>(external_pointer()); |
| 2708 | ptr[index] = value; |
| 2709 | } |
| 2710 | |
| 2711 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2712 | uint16_t ExternalUnsignedShortArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2713 | ASSERT((index >= 0) && (index < this->length())); |
| 2714 | uint16_t* ptr = static_cast<uint16_t*>(external_pointer()); |
| 2715 | return ptr[index]; |
| 2716 | } |
| 2717 | |
| 2718 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2719 | MaybeObject* ExternalUnsignedShortArray::get(int index) { |
| 2720 | return Smi::FromInt(static_cast<int>(get_scalar(index))); |
| 2721 | } |
| 2722 | |
| 2723 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2724 | void ExternalUnsignedShortArray::set(int index, uint16_t value) { |
| 2725 | ASSERT((index >= 0) && (index < this->length())); |
| 2726 | uint16_t* ptr = static_cast<uint16_t*>(external_pointer()); |
| 2727 | ptr[index] = value; |
| 2728 | } |
| 2729 | |
| 2730 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2731 | int32_t ExternalIntArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2732 | ASSERT((index >= 0) && (index < this->length())); |
| 2733 | int32_t* ptr = static_cast<int32_t*>(external_pointer()); |
| 2734 | return ptr[index]; |
| 2735 | } |
| 2736 | |
| 2737 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2738 | MaybeObject* ExternalIntArray::get(int index) { |
| 2739 | return GetHeap()->NumberFromInt32(get_scalar(index)); |
| 2740 | } |
| 2741 | |
| 2742 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2743 | void ExternalIntArray::set(int index, int32_t value) { |
| 2744 | ASSERT((index >= 0) && (index < this->length())); |
| 2745 | int32_t* ptr = static_cast<int32_t*>(external_pointer()); |
| 2746 | ptr[index] = value; |
| 2747 | } |
| 2748 | |
| 2749 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2750 | uint32_t ExternalUnsignedIntArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2751 | ASSERT((index >= 0) && (index < this->length())); |
| 2752 | uint32_t* ptr = static_cast<uint32_t*>(external_pointer()); |
| 2753 | return ptr[index]; |
| 2754 | } |
| 2755 | |
| 2756 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2757 | MaybeObject* ExternalUnsignedIntArray::get(int index) { |
| 2758 | return GetHeap()->NumberFromUint32(get_scalar(index)); |
| 2759 | } |
| 2760 | |
| 2761 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2762 | void ExternalUnsignedIntArray::set(int index, uint32_t value) { |
| 2763 | ASSERT((index >= 0) && (index < this->length())); |
| 2764 | uint32_t* ptr = static_cast<uint32_t*>(external_pointer()); |
| 2765 | ptr[index] = value; |
| 2766 | } |
| 2767 | |
| 2768 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2769 | float ExternalFloatArray::get_scalar(int index) { |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2770 | ASSERT((index >= 0) && (index < this->length())); |
| 2771 | float* ptr = static_cast<float*>(external_pointer()); |
| 2772 | return ptr[index]; |
| 2773 | } |
| 2774 | |
| 2775 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2776 | MaybeObject* ExternalFloatArray::get(int index) { |
| 2777 | return GetHeap()->NumberFromDouble(get_scalar(index)); |
| 2778 | } |
| 2779 | |
| 2780 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2781 | void ExternalFloatArray::set(int index, float value) { |
| 2782 | ASSERT((index >= 0) && (index < this->length())); |
| 2783 | float* ptr = static_cast<float*>(external_pointer()); |
| 2784 | ptr[index] = value; |
| 2785 | } |
| 2786 | |
ager@chromium.org | 6a2b0aa | 2010-07-13 20:58:03 +0000 | [diff] [blame] | 2787 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2788 | double ExternalDoubleArray::get_scalar(int index) { |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2789 | ASSERT((index >= 0) && (index < this->length())); |
| 2790 | double* ptr = static_cast<double*>(external_pointer()); |
| 2791 | return ptr[index]; |
| 2792 | } |
| 2793 | |
| 2794 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 2795 | MaybeObject* ExternalDoubleArray::get(int index) { |
| 2796 | return GetHeap()->NumberFromDouble(get_scalar(index)); |
| 2797 | } |
| 2798 | |
| 2799 | |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 2800 | void ExternalDoubleArray::set(int index, double value) { |
| 2801 | ASSERT((index >= 0) && (index < this->length())); |
| 2802 | double* ptr = static_cast<double*>(external_pointer()); |
| 2803 | ptr[index] = value; |
| 2804 | } |
| 2805 | |
| 2806 | |
ager@chromium.org | 5b2fbee | 2010-09-08 06:38:15 +0000 | [diff] [blame] | 2807 | int Map::visitor_id() { |
| 2808 | return READ_BYTE_FIELD(this, kVisitorIdOffset); |
| 2809 | } |
| 2810 | |
| 2811 | |
| 2812 | void Map::set_visitor_id(int id) { |
| 2813 | ASSERT(0 <= id && id < 256); |
| 2814 | WRITE_BYTE_FIELD(this, kVisitorIdOffset, static_cast<byte>(id)); |
| 2815 | } |
| 2816 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 2817 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2818 | int Map::instance_size() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2819 | return READ_BYTE_FIELD(this, kInstanceSizeOffset) << kPointerSizeLog2; |
| 2820 | } |
| 2821 | |
| 2822 | |
| 2823 | int Map::inobject_properties() { |
| 2824 | return READ_BYTE_FIELD(this, kInObjectPropertiesOffset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2828 | int Map::pre_allocated_property_fields() { |
| 2829 | return READ_BYTE_FIELD(this, kPreAllocatedPropertyFieldsOffset); |
| 2830 | } |
| 2831 | |
| 2832 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2833 | int HeapObject::SizeFromMap(Map* map) { |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2834 | int instance_size = map->instance_size(); |
| 2835 | if (instance_size != kVariableSizeSentinel) return instance_size; |
| 2836 | // We can ignore the "symbol" bit becase it is only set for symbols |
| 2837 | // and implies a string type. |
| 2838 | int instance_type = static_cast<int>(map->instance_type()) & ~kIsSymbolMask; |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2839 | // Only inline the most frequent cases. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2840 | if (instance_type == FIXED_ARRAY_TYPE) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 2841 | return FixedArray::BodyDescriptor::SizeOf(map, this); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2842 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2843 | if (instance_type == ASCII_STRING_TYPE) { |
| 2844 | return SeqAsciiString::SizeFor( |
| 2845 | reinterpret_cast<SeqAsciiString*>(this)->length()); |
| 2846 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 2847 | if (instance_type == BYTE_ARRAY_TYPE) { |
| 2848 | return reinterpret_cast<ByteArray*>(this)->ByteArraySize(); |
| 2849 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2850 | if (instance_type == FREE_SPACE_TYPE) { |
| 2851 | return reinterpret_cast<FreeSpace*>(this)->size(); |
| 2852 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2853 | if (instance_type == STRING_TYPE) { |
| 2854 | return SeqTwoByteString::SizeFor( |
| 2855 | reinterpret_cast<SeqTwoByteString*>(this)->length()); |
| 2856 | } |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 2857 | if (instance_type == FIXED_DOUBLE_ARRAY_TYPE) { |
| 2858 | return FixedDoubleArray::SizeFor( |
| 2859 | reinterpret_cast<FixedDoubleArray*>(this)->length()); |
| 2860 | } |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 2861 | ASSERT(instance_type == CODE_TYPE); |
| 2862 | return reinterpret_cast<Code*>(this)->CodeSize(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2863 | } |
| 2864 | |
| 2865 | |
| 2866 | void Map::set_instance_size(int value) { |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 2867 | ASSERT_EQ(0, value & (kPointerSize - 1)); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2868 | value >>= kPointerSizeLog2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2869 | ASSERT(0 <= value && value < 256); |
| 2870 | WRITE_BYTE_FIELD(this, kInstanceSizeOffset, static_cast<byte>(value)); |
| 2871 | } |
| 2872 | |
| 2873 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2874 | void Map::set_inobject_properties(int value) { |
| 2875 | ASSERT(0 <= value && value < 256); |
| 2876 | WRITE_BYTE_FIELD(this, kInObjectPropertiesOffset, static_cast<byte>(value)); |
| 2877 | } |
| 2878 | |
| 2879 | |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 2880 | void Map::set_pre_allocated_property_fields(int value) { |
| 2881 | ASSERT(0 <= value && value < 256); |
| 2882 | WRITE_BYTE_FIELD(this, |
| 2883 | kPreAllocatedPropertyFieldsOffset, |
| 2884 | static_cast<byte>(value)); |
| 2885 | } |
| 2886 | |
| 2887 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2888 | InstanceType Map::instance_type() { |
| 2889 | return static_cast<InstanceType>(READ_BYTE_FIELD(this, kInstanceTypeOffset)); |
| 2890 | } |
| 2891 | |
| 2892 | |
| 2893 | void Map::set_instance_type(InstanceType value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2894 | WRITE_BYTE_FIELD(this, kInstanceTypeOffset, value); |
| 2895 | } |
| 2896 | |
| 2897 | |
| 2898 | int Map::unused_property_fields() { |
| 2899 | return READ_BYTE_FIELD(this, kUnusedPropertyFieldsOffset); |
| 2900 | } |
| 2901 | |
| 2902 | |
| 2903 | void Map::set_unused_property_fields(int value) { |
| 2904 | WRITE_BYTE_FIELD(this, kUnusedPropertyFieldsOffset, Min(value, 255)); |
| 2905 | } |
| 2906 | |
| 2907 | |
| 2908 | byte Map::bit_field() { |
| 2909 | return READ_BYTE_FIELD(this, kBitFieldOffset); |
| 2910 | } |
| 2911 | |
| 2912 | |
| 2913 | void Map::set_bit_field(byte value) { |
| 2914 | WRITE_BYTE_FIELD(this, kBitFieldOffset, value); |
| 2915 | } |
| 2916 | |
| 2917 | |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 2918 | byte Map::bit_field2() { |
| 2919 | return READ_BYTE_FIELD(this, kBitField2Offset); |
| 2920 | } |
| 2921 | |
| 2922 | |
| 2923 | void Map::set_bit_field2(byte value) { |
| 2924 | WRITE_BYTE_FIELD(this, kBitField2Offset, value); |
| 2925 | } |
| 2926 | |
| 2927 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2928 | void Map::set_non_instance_prototype(bool value) { |
| 2929 | if (value) { |
| 2930 | set_bit_field(bit_field() | (1 << kHasNonInstancePrototype)); |
| 2931 | } else { |
| 2932 | set_bit_field(bit_field() & ~(1 << kHasNonInstancePrototype)); |
| 2933 | } |
| 2934 | } |
| 2935 | |
| 2936 | |
| 2937 | bool Map::has_non_instance_prototype() { |
| 2938 | return ((1 << kHasNonInstancePrototype) & bit_field()) != 0; |
| 2939 | } |
| 2940 | |
| 2941 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2942 | void Map::set_function_with_prototype(bool value) { |
| 2943 | if (value) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2944 | set_bit_field3(bit_field3() | (1 << kFunctionWithPrototype)); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2945 | } else { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2946 | set_bit_field3(bit_field3() & ~(1 << kFunctionWithPrototype)); |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2947 | } |
| 2948 | } |
| 2949 | |
| 2950 | |
| 2951 | bool Map::function_with_prototype() { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 2952 | return ((1 << kFunctionWithPrototype) & bit_field3()) != 0; |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 2953 | } |
| 2954 | |
| 2955 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 2956 | void Map::set_is_access_check_needed(bool access_check_needed) { |
| 2957 | if (access_check_needed) { |
| 2958 | set_bit_field(bit_field() | (1 << kIsAccessCheckNeeded)); |
| 2959 | } else { |
| 2960 | set_bit_field(bit_field() & ~(1 << kIsAccessCheckNeeded)); |
| 2961 | } |
| 2962 | } |
| 2963 | |
| 2964 | |
| 2965 | bool Map::is_access_check_needed() { |
| 2966 | return ((1 << kIsAccessCheckNeeded) & bit_field()) != 0; |
| 2967 | } |
| 2968 | |
| 2969 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 2970 | void Map::set_is_extensible(bool value) { |
| 2971 | if (value) { |
| 2972 | set_bit_field2(bit_field2() | (1 << kIsExtensible)); |
| 2973 | } else { |
| 2974 | set_bit_field2(bit_field2() & ~(1 << kIsExtensible)); |
| 2975 | } |
| 2976 | } |
| 2977 | |
| 2978 | bool Map::is_extensible() { |
| 2979 | return ((1 << kIsExtensible) & bit_field2()) != 0; |
| 2980 | } |
| 2981 | |
| 2982 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2983 | void Map::set_attached_to_shared_function_info(bool value) { |
| 2984 | if (value) { |
| 2985 | set_bit_field2(bit_field2() | (1 << kAttachedToSharedFunctionInfo)); |
| 2986 | } else { |
| 2987 | set_bit_field2(bit_field2() & ~(1 << kAttachedToSharedFunctionInfo)); |
| 2988 | } |
| 2989 | } |
| 2990 | |
| 2991 | bool Map::attached_to_shared_function_info() { |
| 2992 | return ((1 << kAttachedToSharedFunctionInfo) & bit_field2()) != 0; |
| 2993 | } |
| 2994 | |
| 2995 | |
| 2996 | void Map::set_is_shared(bool value) { |
| 2997 | if (value) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2998 | set_bit_field3(bit_field3() | (1 << kIsShared)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 2999 | } else { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3000 | set_bit_field3(bit_field3() & ~(1 << kIsShared)); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3001 | } |
| 3002 | } |
| 3003 | |
| 3004 | bool Map::is_shared() { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3005 | return ((1 << kIsShared) & bit_field3()) != 0; |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | |
| 3009 | JSFunction* Map::unchecked_constructor() { |
| 3010 | return reinterpret_cast<JSFunction*>(READ_FIELD(this, kConstructorOffset)); |
| 3011 | } |
| 3012 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3013 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3014 | Code::Flags Code::flags() { |
| 3015 | return static_cast<Flags>(READ_INT_FIELD(this, kFlagsOffset)); |
| 3016 | } |
| 3017 | |
| 3018 | |
| 3019 | void Code::set_flags(Code::Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3020 | STATIC_ASSERT(Code::NUMBER_OF_KINDS <= KindField::kMax + 1); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3021 | // Make sure that all call stubs have an arguments count. |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3022 | ASSERT((ExtractKindFromFlags(flags) != CALL_IC && |
| 3023 | ExtractKindFromFlags(flags) != KEYED_CALL_IC) || |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3024 | ExtractArgumentsCountFromFlags(flags) >= 0); |
| 3025 | WRITE_INT_FIELD(this, kFlagsOffset, flags); |
| 3026 | } |
| 3027 | |
| 3028 | |
| 3029 | Code::Kind Code::kind() { |
| 3030 | return ExtractKindFromFlags(flags()); |
| 3031 | } |
| 3032 | |
| 3033 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3034 | InlineCacheState Code::ic_state() { |
| 3035 | InlineCacheState result = ExtractICStateFromFlags(flags()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3036 | // Only allow uninitialized or debugger states for non-IC code |
| 3037 | // objects. This is used in the debugger to determine whether or not |
| 3038 | // a call to code object has been replaced with a debug break call. |
| 3039 | ASSERT(is_inline_cache_stub() || |
| 3040 | result == UNINITIALIZED || |
| 3041 | result == DEBUG_BREAK || |
| 3042 | result == DEBUG_PREPARE_STEP_IN); |
| 3043 | return result; |
| 3044 | } |
| 3045 | |
| 3046 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3047 | Code::ExtraICState Code::extra_ic_state() { |
| 3048 | ASSERT(is_inline_cache_stub()); |
| 3049 | return ExtractExtraICStateFromFlags(flags()); |
| 3050 | } |
| 3051 | |
| 3052 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3053 | Code::StubType Code::type() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3054 | return ExtractTypeFromFlags(flags()); |
| 3055 | } |
| 3056 | |
| 3057 | |
| 3058 | int Code::arguments_count() { |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 3059 | ASSERT(is_call_stub() || is_keyed_call_stub() || kind() == STUB); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3060 | return ExtractArgumentsCountFromFlags(flags()); |
| 3061 | } |
| 3062 | |
| 3063 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3064 | int Code::major_key() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3065 | ASSERT(kind() == STUB || |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3066 | kind() == UNARY_OP_IC || |
| 3067 | kind() == BINARY_OP_IC || |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3068 | kind() == COMPARE_IC || |
| 3069 | kind() == TO_BOOLEAN_IC); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3070 | return StubMajorKeyField::decode( |
| 3071 | READ_UINT32_FIELD(this, kKindSpecificFlags2Offset)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3072 | } |
| 3073 | |
| 3074 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 3075 | void Code::set_major_key(int major) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3076 | ASSERT(kind() == STUB || |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3077 | kind() == UNARY_OP_IC || |
| 3078 | kind() == BINARY_OP_IC || |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3079 | kind() == COMPARE_IC || |
| 3080 | kind() == TO_BOOLEAN_IC); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3081 | ASSERT(0 <= major && major < 256); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3082 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags2Offset); |
| 3083 | int updated = StubMajorKeyField::update(previous, major); |
| 3084 | WRITE_UINT32_FIELD(this, kKindSpecificFlags2Offset, updated); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3085 | } |
| 3086 | |
| 3087 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3088 | bool Code::is_pregenerated() { |
| 3089 | return kind() == STUB && IsPregeneratedField::decode(flags()); |
| 3090 | } |
| 3091 | |
| 3092 | |
| 3093 | void Code::set_is_pregenerated(bool value) { |
| 3094 | ASSERT(kind() == STUB); |
| 3095 | Flags f = flags(); |
| 3096 | f = static_cast<Flags>(IsPregeneratedField::update(f, value)); |
| 3097 | set_flags(f); |
| 3098 | } |
| 3099 | |
| 3100 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3101 | bool Code::optimizable() { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3102 | ASSERT_EQ(FUNCTION, kind()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3103 | return READ_BYTE_FIELD(this, kOptimizableOffset) == 1; |
| 3104 | } |
| 3105 | |
| 3106 | |
| 3107 | void Code::set_optimizable(bool value) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3108 | ASSERT_EQ(FUNCTION, kind()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3109 | WRITE_BYTE_FIELD(this, kOptimizableOffset, value ? 1 : 0); |
| 3110 | } |
| 3111 | |
| 3112 | |
| 3113 | bool Code::has_deoptimization_support() { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3114 | ASSERT_EQ(FUNCTION, kind()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3115 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 3116 | return FullCodeFlagsHasDeoptimizationSupportField::decode(flags); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | |
| 3120 | void Code::set_has_deoptimization_support(bool value) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3121 | ASSERT_EQ(FUNCTION, kind()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3122 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 3123 | flags = FullCodeFlagsHasDeoptimizationSupportField::update(flags, value); |
| 3124 | WRITE_BYTE_FIELD(this, kFullCodeFlags, flags); |
| 3125 | } |
| 3126 | |
| 3127 | |
| 3128 | bool Code::has_debug_break_slots() { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3129 | ASSERT_EQ(FUNCTION, kind()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3130 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 3131 | return FullCodeFlagsHasDebugBreakSlotsField::decode(flags); |
| 3132 | } |
| 3133 | |
| 3134 | |
| 3135 | void Code::set_has_debug_break_slots(bool value) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3136 | ASSERT_EQ(FUNCTION, kind()); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3137 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 3138 | flags = FullCodeFlagsHasDebugBreakSlotsField::update(flags, value); |
| 3139 | WRITE_BYTE_FIELD(this, kFullCodeFlags, flags); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3140 | } |
| 3141 | |
| 3142 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3143 | bool Code::is_compiled_optimizable() { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3144 | ASSERT_EQ(FUNCTION, kind()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3145 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 3146 | return FullCodeFlagsIsCompiledOptimizable::decode(flags); |
| 3147 | } |
| 3148 | |
| 3149 | |
| 3150 | void Code::set_compiled_optimizable(bool value) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3151 | ASSERT_EQ(FUNCTION, kind()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3152 | byte flags = READ_BYTE_FIELD(this, kFullCodeFlags); |
| 3153 | flags = FullCodeFlagsIsCompiledOptimizable::update(flags, value); |
| 3154 | WRITE_BYTE_FIELD(this, kFullCodeFlags, flags); |
| 3155 | } |
| 3156 | |
| 3157 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3158 | int Code::allow_osr_at_loop_nesting_level() { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3159 | ASSERT_EQ(FUNCTION, kind()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3160 | return READ_BYTE_FIELD(this, kAllowOSRAtLoopNestingLevelOffset); |
| 3161 | } |
| 3162 | |
| 3163 | |
| 3164 | void Code::set_allow_osr_at_loop_nesting_level(int level) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3165 | ASSERT_EQ(FUNCTION, kind()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3166 | ASSERT(level >= 0 && level <= kMaxLoopNestingMarker); |
| 3167 | WRITE_BYTE_FIELD(this, kAllowOSRAtLoopNestingLevelOffset, level); |
| 3168 | } |
| 3169 | |
| 3170 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 3171 | int Code::profiler_ticks() { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3172 | ASSERT_EQ(FUNCTION, kind()); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 3173 | return READ_BYTE_FIELD(this, kProfilerTicksOffset); |
| 3174 | } |
| 3175 | |
| 3176 | |
| 3177 | void Code::set_profiler_ticks(int ticks) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3178 | ASSERT_EQ(FUNCTION, kind()); |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 3179 | ASSERT(ticks < 256); |
| 3180 | WRITE_BYTE_FIELD(this, kProfilerTicksOffset, ticks); |
| 3181 | } |
| 3182 | |
| 3183 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3184 | unsigned Code::stack_slots() { |
| 3185 | ASSERT(kind() == OPTIMIZED_FUNCTION); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3186 | return StackSlotsField::decode( |
| 3187 | READ_UINT32_FIELD(this, kKindSpecificFlags1Offset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3188 | } |
| 3189 | |
| 3190 | |
| 3191 | void Code::set_stack_slots(unsigned slots) { |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3192 | CHECK(slots <= (1 << kStackSlotsBitCount)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3193 | ASSERT(kind() == OPTIMIZED_FUNCTION); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3194 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags1Offset); |
| 3195 | int updated = StackSlotsField::update(previous, slots); |
| 3196 | WRITE_UINT32_FIELD(this, kKindSpecificFlags1Offset, updated); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3200 | unsigned Code::safepoint_table_offset() { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3201 | ASSERT(kind() == OPTIMIZED_FUNCTION); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3202 | return SafepointTableOffsetField::decode( |
| 3203 | READ_UINT32_FIELD(this, kKindSpecificFlags2Offset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3207 | void Code::set_safepoint_table_offset(unsigned offset) { |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3208 | CHECK(offset <= (1 << kSafepointTableOffsetBitCount)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3209 | ASSERT(kind() == OPTIMIZED_FUNCTION); |
| 3210 | ASSERT(IsAligned(offset, static_cast<unsigned>(kIntSize))); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3211 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags2Offset); |
| 3212 | int updated = SafepointTableOffsetField::update(previous, offset); |
| 3213 | WRITE_UINT32_FIELD(this, kKindSpecificFlags2Offset, updated); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3217 | unsigned Code::stack_check_table_offset() { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3218 | ASSERT_EQ(FUNCTION, kind()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3219 | return StackCheckTableOffsetField::decode( |
| 3220 | READ_UINT32_FIELD(this, kKindSpecificFlags2Offset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | |
ricow@chromium.org | 83aa549 | 2011-02-07 12:42:56 +0000 | [diff] [blame] | 3224 | void Code::set_stack_check_table_offset(unsigned offset) { |
fschneider@chromium.org | 7d10be5 | 2012-04-10 12:30:14 +0000 | [diff] [blame] | 3225 | ASSERT_EQ(FUNCTION, kind()); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3226 | ASSERT(IsAligned(offset, static_cast<unsigned>(kIntSize))); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3227 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags2Offset); |
| 3228 | int updated = StackCheckTableOffsetField::update(previous, offset); |
| 3229 | WRITE_UINT32_FIELD(this, kKindSpecificFlags2Offset, updated); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3230 | } |
| 3231 | |
| 3232 | |
| 3233 | CheckType Code::check_type() { |
| 3234 | ASSERT(is_call_stub() || is_keyed_call_stub()); |
| 3235 | byte type = READ_BYTE_FIELD(this, kCheckTypeOffset); |
| 3236 | return static_cast<CheckType>(type); |
| 3237 | } |
| 3238 | |
| 3239 | |
| 3240 | void Code::set_check_type(CheckType value) { |
| 3241 | ASSERT(is_call_stub() || is_keyed_call_stub()); |
| 3242 | WRITE_BYTE_FIELD(this, kCheckTypeOffset, value); |
| 3243 | } |
| 3244 | |
| 3245 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3246 | byte Code::unary_op_type() { |
| 3247 | ASSERT(is_unary_op_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3248 | return UnaryOpTypeField::decode( |
| 3249 | READ_UINT32_FIELD(this, kKindSpecificFlags1Offset)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3250 | } |
| 3251 | |
| 3252 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3253 | void Code::set_unary_op_type(byte value) { |
| 3254 | ASSERT(is_unary_op_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3255 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags1Offset); |
| 3256 | int updated = UnaryOpTypeField::update(previous, value); |
| 3257 | WRITE_UINT32_FIELD(this, kKindSpecificFlags1Offset, updated); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 3258 | } |
| 3259 | |
| 3260 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3261 | byte Code::binary_op_type() { |
| 3262 | ASSERT(is_binary_op_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3263 | return BinaryOpTypeField::decode( |
| 3264 | READ_UINT32_FIELD(this, kKindSpecificFlags1Offset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3268 | void Code::set_binary_op_type(byte value) { |
| 3269 | ASSERT(is_binary_op_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3270 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags1Offset); |
| 3271 | int updated = BinaryOpTypeField::update(previous, value); |
| 3272 | WRITE_UINT32_FIELD(this, kKindSpecificFlags1Offset, updated); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3273 | } |
| 3274 | |
| 3275 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3276 | byte Code::binary_op_result_type() { |
| 3277 | ASSERT(is_binary_op_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3278 | return BinaryOpResultTypeField::decode( |
| 3279 | READ_UINT32_FIELD(this, kKindSpecificFlags1Offset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3280 | } |
| 3281 | |
| 3282 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3283 | void Code::set_binary_op_result_type(byte value) { |
| 3284 | ASSERT(is_binary_op_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3285 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags1Offset); |
| 3286 | int updated = BinaryOpResultTypeField::update(previous, value); |
| 3287 | WRITE_UINT32_FIELD(this, kKindSpecificFlags1Offset, updated); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3288 | } |
| 3289 | |
| 3290 | |
| 3291 | byte Code::compare_state() { |
| 3292 | ASSERT(is_compare_ic_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3293 | return CompareStateField::decode( |
| 3294 | READ_UINT32_FIELD(this, kKindSpecificFlags1Offset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3295 | } |
| 3296 | |
| 3297 | |
| 3298 | void Code::set_compare_state(byte value) { |
| 3299 | ASSERT(is_compare_ic_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3300 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags1Offset); |
| 3301 | int updated = CompareStateField::update(previous, value); |
| 3302 | WRITE_UINT32_FIELD(this, kKindSpecificFlags1Offset, updated); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3303 | } |
| 3304 | |
| 3305 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3306 | byte Code::compare_operation() { |
| 3307 | ASSERT(is_compare_ic_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3308 | return CompareOperationField::decode( |
| 3309 | READ_UINT32_FIELD(this, kKindSpecificFlags1Offset)); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | |
| 3313 | void Code::set_compare_operation(byte value) { |
| 3314 | ASSERT(is_compare_ic_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3315 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags1Offset); |
| 3316 | int updated = CompareOperationField::update(previous, value); |
| 3317 | WRITE_UINT32_FIELD(this, kKindSpecificFlags1Offset, updated); |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3318 | } |
| 3319 | |
| 3320 | |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3321 | byte Code::to_boolean_state() { |
| 3322 | ASSERT(is_to_boolean_ic_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3323 | return ToBooleanStateField::decode( |
| 3324 | READ_UINT32_FIELD(this, kKindSpecificFlags1Offset)); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3325 | } |
| 3326 | |
| 3327 | |
| 3328 | void Code::set_to_boolean_state(byte value) { |
| 3329 | ASSERT(is_to_boolean_ic_stub()); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3330 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags1Offset); |
| 3331 | int updated = ToBooleanStateField::update(previous, value); |
| 3332 | WRITE_UINT32_FIELD(this, kKindSpecificFlags1Offset, updated); |
ricow@chromium.org | 9fa0967 | 2011-07-25 11:05:35 +0000 | [diff] [blame] | 3333 | } |
| 3334 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3335 | |
| 3336 | bool Code::has_function_cache() { |
| 3337 | ASSERT(kind() == STUB); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3338 | return HasFunctionCacheField::decode( |
| 3339 | READ_UINT32_FIELD(this, kKindSpecificFlags1Offset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3340 | } |
| 3341 | |
| 3342 | |
| 3343 | void Code::set_has_function_cache(bool flag) { |
| 3344 | ASSERT(kind() == STUB); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3345 | int previous = READ_UINT32_FIELD(this, kKindSpecificFlags1Offset); |
| 3346 | int updated = HasFunctionCacheField::update(previous, flag); |
| 3347 | WRITE_UINT32_FIELD(this, kKindSpecificFlags1Offset, updated); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3348 | } |
| 3349 | |
| 3350 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3351 | bool Code::is_inline_cache_stub() { |
| 3352 | Kind kind = this->kind(); |
| 3353 | return kind >= FIRST_IC_KIND && kind <= LAST_IC_KIND; |
| 3354 | } |
| 3355 | |
| 3356 | |
| 3357 | Code::Flags Code::ComputeFlags(Kind kind, |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3358 | InlineCacheState ic_state, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3359 | ExtraICState extra_ic_state, |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3360 | StubType type, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3361 | int argc, |
| 3362 | InlineCacheHolderFlag holder) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3363 | // Extra IC state is only allowed for call IC stubs or for store IC |
| 3364 | // stubs. |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3365 | ASSERT(extra_ic_state == kNoExtraICState || |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3366 | kind == CALL_IC || |
| 3367 | kind == STORE_IC || |
| 3368 | kind == KEYED_STORE_IC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3369 | // Compute the bit mask. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3370 | int bits = KindField::encode(kind) |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3371 | | ICStateField::encode(ic_state) |
| 3372 | | TypeField::encode(type) |
| 3373 | | ExtraICStateField::encode(extra_ic_state) |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3374 | | (argc << kArgumentsCountShift) |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3375 | | CacheHolderField::encode(holder); |
| 3376 | return static_cast<Flags>(bits); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | |
| 3380 | Code::Flags Code::ComputeMonomorphicFlags(Kind kind, |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3381 | StubType type, |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3382 | ExtraICState extra_ic_state, |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3383 | InlineCacheHolderFlag holder, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3384 | int argc) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3385 | return ComputeFlags(kind, MONOMORPHIC, extra_ic_state, type, argc, holder); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | |
| 3389 | Code::Kind Code::ExtractKindFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3390 | return KindField::decode(flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 3394 | InlineCacheState Code::ExtractICStateFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3395 | return ICStateField::decode(flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3396 | } |
| 3397 | |
| 3398 | |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3399 | Code::ExtraICState Code::ExtractExtraICStateFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3400 | return ExtraICStateField::decode(flags); |
erik.corry@gmail.com | 0511e24 | 2011-01-19 11:11:08 +0000 | [diff] [blame] | 3401 | } |
| 3402 | |
| 3403 | |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3404 | Code::StubType Code::ExtractTypeFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3405 | return TypeField::decode(flags); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | |
| 3409 | int Code::ExtractArgumentsCountFromFlags(Flags flags) { |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 3410 | return (flags & kArgumentsCountMask) >> kArgumentsCountShift; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3411 | } |
| 3412 | |
| 3413 | |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3414 | InlineCacheHolderFlag Code::ExtractCacheHolderFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3415 | return CacheHolderField::decode(flags); |
kmillikin@chromium.org | 69ea396 | 2010-07-05 11:01:40 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
| 3418 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3419 | Code::Flags Code::RemoveTypeFromFlags(Flags flags) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3420 | int bits = flags & ~TypeField::kMask; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3421 | return static_cast<Flags>(bits); |
| 3422 | } |
| 3423 | |
| 3424 | |
ager@chromium.org | 8bb6058 | 2008-12-11 12:02:20 +0000 | [diff] [blame] | 3425 | Code* Code::GetCodeFromTargetAddress(Address address) { |
| 3426 | HeapObject* code = HeapObject::FromAddress(address - Code::kHeaderSize); |
| 3427 | // GetCodeFromTargetAddress might be called when marking objects during mark |
| 3428 | // sweep. reinterpret_cast is therefore used instead of the more appropriate |
| 3429 | // Code::cast. Code::cast does not work when the object's map is |
| 3430 | // marked. |
| 3431 | Code* result = reinterpret_cast<Code*>(code); |
| 3432 | return result; |
| 3433 | } |
| 3434 | |
| 3435 | |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 3436 | Object* Code::GetObjectFromEntryAddress(Address location_of_address) { |
| 3437 | return HeapObject:: |
| 3438 | FromAddress(Memory::Address_at(location_of_address) - Code::kHeaderSize); |
| 3439 | } |
| 3440 | |
| 3441 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3442 | Object* Map::prototype() { |
| 3443 | return READ_FIELD(this, kPrototypeOffset); |
| 3444 | } |
| 3445 | |
| 3446 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3447 | void Map::set_prototype(Object* value, WriteBarrierMode mode) { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 3448 | ASSERT(value->IsNull() || value->IsJSReceiver()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3449 | WRITE_FIELD(this, kPrototypeOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3450 | CONDITIONAL_WRITE_BARRIER(GetHeap(), this, kPrototypeOffset, value, mode); |
fschneider@chromium.org | 40b9da3 | 2010-06-28 11:29:21 +0000 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3454 | DescriptorArray* Map::instance_descriptors() { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3455 | Object* object = READ_FIELD(this, kInstanceDescriptorsOrBackPointerOffset); |
| 3456 | if (!object->IsDescriptorArray()) { |
| 3457 | ASSERT(object->IsMap() || object->IsUndefined()); |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 3458 | return GetHeap()->empty_descriptor_array(); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3459 | } else { |
| 3460 | return DescriptorArray::cast(object); |
| 3461 | } |
| 3462 | } |
| 3463 | |
| 3464 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3465 | void Map::set_instance_descriptors(DescriptorArray* value, |
| 3466 | WriteBarrierMode mode) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3467 | Heap* heap = GetHeap(); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3468 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3469 | if (value == heap->empty_descriptor_array()) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3470 | ClearDescriptorArray(heap, mode); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3471 | return; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3472 | } |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3473 | |
| 3474 | Object* object = READ_FIELD(this, kInstanceDescriptorsOrBackPointerOffset); |
| 3475 | |
| 3476 | if (object->IsDescriptorArray()) { |
| 3477 | value->set_back_pointer_storage( |
| 3478 | DescriptorArray::cast(object)->back_pointer_storage()); |
| 3479 | } else { |
| 3480 | ASSERT(object->IsMap() || object->IsUndefined()); |
| 3481 | value->set_back_pointer_storage(object); |
| 3482 | } |
| 3483 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3484 | ASSERT(!is_shared()); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3485 | WRITE_FIELD(this, kInstanceDescriptorsOrBackPointerOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3486 | CONDITIONAL_WRITE_BARRIER( |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3487 | heap, this, kInstanceDescriptorsOrBackPointerOffset, value, mode); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3488 | } |
| 3489 | |
| 3490 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3491 | SMI_ACCESSORS(Map, bit_field3, kBitField3Offset) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3492 | |
| 3493 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3494 | void Map::ClearDescriptorArray(Heap* heap, WriteBarrierMode mode) { |
| 3495 | Object* back_pointer = GetBackPointer(); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3496 | #ifdef DEBUG |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3497 | Object* object = READ_FIELD(this, kInstanceDescriptorsOrBackPointerOffset); |
| 3498 | if (object->IsDescriptorArray()) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3499 | ZapTransitions(); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3500 | } else { |
| 3501 | ASSERT(object->IsMap() || object->IsUndefined()); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3502 | } |
| 3503 | #endif |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3504 | WRITE_FIELD(this, kInstanceDescriptorsOrBackPointerOffset, back_pointer); |
| 3505 | CONDITIONAL_WRITE_BARRIER( |
| 3506 | heap, this, kInstanceDescriptorsOrBackPointerOffset, back_pointer, mode); |
jkummerow@chromium.org | 7a6fc81 | 2012-06-27 11:12:38 +0000 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 3510 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3511 | Object* Map::GetBackPointer() { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3512 | Object* object = READ_FIELD(this, kInstanceDescriptorsOrBackPointerOffset); |
| 3513 | if (object->IsDescriptorArray()) { |
| 3514 | return DescriptorArray::cast(object)->back_pointer_storage(); |
| 3515 | } else { |
| 3516 | ASSERT(object->IsMap() || object->IsUndefined()); |
| 3517 | return object; |
| 3518 | } |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3522 | bool Map::HasElementsTransition() { |
| 3523 | return HasTransitionArray() && transitions()->HasElementsTransition(); |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3527 | bool Map::HasTransitionArray() { |
| 3528 | return instance_descriptors()->HasTransitionArray(); |
| 3529 | } |
| 3530 | |
| 3531 | |
| 3532 | Map* Map::elements_transition_map() { |
| 3533 | return transitions()->elements_transition(); |
| 3534 | } |
| 3535 | |
| 3536 | |
| 3537 | MaybeObject* Map::AddTransition(String* key, Object* value) { |
| 3538 | if (HasTransitionArray()) return transitions()->CopyInsert(key, value); |
| 3539 | return TransitionArray::NewWith(key, value); |
| 3540 | } |
| 3541 | |
jkummerow@chromium.org | 28583c9 | 2012-07-16 11:31:55 +0000 | [diff] [blame^] | 3542 | void Map::SetTransition(int transition_index, Object* value) { |
| 3543 | transitions()->SetValue(transition_index, value); |
| 3544 | } |
| 3545 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3546 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3547 | // If the map is using the empty descriptor array, install a new empty |
| 3548 | // descriptor array that will contain an elements transition. |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3549 | static MaybeObject* AllowTransitions(Map* map) { |
| 3550 | if (map->instance_descriptors()->MayContainTransitions()) return map; |
| 3551 | DescriptorArray* descriptors; |
| 3552 | MaybeObject* maybe_descriptors = |
| 3553 | DescriptorArray::Allocate(0, DescriptorArray::CANNOT_BE_SHARED); |
| 3554 | if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors; |
| 3555 | map->set_instance_descriptors(descriptors); |
| 3556 | return descriptors; |
| 3557 | } |
| 3558 | |
| 3559 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3560 | // If the descriptor is using the empty transition array, install a new empty |
| 3561 | // transition array that will have place for an element transition. |
| 3562 | static MaybeObject* EnsureHasTransitionArray(Map* map) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3563 | if (map->HasTransitionArray()) return map; |
| 3564 | |
| 3565 | AllowTransitions(map); |
| 3566 | |
| 3567 | TransitionArray* transitions; |
| 3568 | MaybeObject* maybe_transitions = TransitionArray::Allocate(0); |
| 3569 | if (!maybe_transitions->To(&transitions)) return maybe_transitions; |
| 3570 | MaybeObject* added_transitions = map->set_transitions(transitions); |
| 3571 | if (added_transitions->IsFailure()) return added_transitions; |
| 3572 | return transitions; |
| 3573 | } |
| 3574 | |
| 3575 | |
| 3576 | MaybeObject* Map::set_elements_transition_map(Map* transitioned_map) { |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3577 | MaybeObject* allow_elements = EnsureHasTransitionArray(this); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3578 | if (allow_elements->IsFailure()) return allow_elements; |
| 3579 | transitions()->set_elements_transition(transitioned_map); |
| 3580 | return this; |
| 3581 | } |
| 3582 | |
| 3583 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3584 | FixedArray* Map::GetPrototypeTransitions() { |
| 3585 | if (!HasTransitionArray()) return GetHeap()->empty_fixed_array(); |
| 3586 | if (!transitions()->HasPrototypeTransitions()) { |
| 3587 | return GetHeap()->empty_fixed_array(); |
| 3588 | } |
| 3589 | return transitions()->GetPrototypeTransitions(); |
| 3590 | } |
| 3591 | |
| 3592 | |
| 3593 | MaybeObject* Map::SetPrototypeTransitions(FixedArray* proto_transitions) { |
| 3594 | MaybeObject* allow_prototype = EnsureHasTransitionArray(this); |
| 3595 | if (allow_prototype->IsFailure()) return allow_prototype; |
| 3596 | #ifdef DEBUG |
| 3597 | if (HasPrototypeTransitions()) { |
| 3598 | ASSERT(GetPrototypeTransitions() != proto_transitions); |
| 3599 | ZapPrototypeTransitions(); |
| 3600 | } |
| 3601 | #endif |
| 3602 | transitions()->SetPrototypeTransitions(proto_transitions); |
| 3603 | return this; |
| 3604 | } |
| 3605 | |
| 3606 | |
| 3607 | bool Map::HasPrototypeTransitions() { |
| 3608 | return HasTransitionArray() && transitions()->HasPrototypeTransitions(); |
| 3609 | } |
| 3610 | |
| 3611 | |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3612 | TransitionArray* Map::transitions() { |
| 3613 | return instance_descriptors()->transitions(); |
| 3614 | } |
| 3615 | |
| 3616 | |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3617 | void Map::ClearTransitions(Heap* heap, WriteBarrierMode mode) { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3618 | #ifdef DEBUG |
| 3619 | ZapTransitions(); |
| 3620 | #endif |
| 3621 | DescriptorArray* descriptors = instance_descriptors(); |
| 3622 | if (descriptors->number_of_descriptors() == 0) { |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3623 | ClearDescriptorArray(heap, mode); |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 3624 | } else { |
| 3625 | descriptors->ClearTransitions(); |
| 3626 | } |
| 3627 | } |
| 3628 | |
| 3629 | |
| 3630 | MaybeObject* Map::set_transitions(TransitionArray* transitions_array) { |
| 3631 | MaybeObject* allow_transitions = AllowTransitions(this); |
| 3632 | if (allow_transitions->IsFailure()) return allow_transitions; |
| 3633 | #ifdef DEBUG |
| 3634 | if (HasTransitionArray()) { |
| 3635 | ASSERT(transitions() != transitions_array); |
| 3636 | ZapTransitions(); |
| 3637 | } |
| 3638 | #endif |
| 3639 | instance_descriptors()->set_transitions(transitions_array); |
| 3640 | return this; |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3644 | void Map::init_back_pointer(Object* undefined) { |
| 3645 | ASSERT(undefined->IsUndefined()); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3646 | WRITE_FIELD(this, kInstanceDescriptorsOrBackPointerOffset, undefined); |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3650 | void Map::SetBackPointer(Object* value, WriteBarrierMode mode) { |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3651 | ASSERT(instance_type() >= FIRST_JS_RECEIVER_TYPE); |
| 3652 | ASSERT((value->IsUndefined() && GetBackPointer()->IsMap()) || |
| 3653 | (value->IsMap() && GetBackPointer()->IsUndefined())); |
rossberg@chromium.org | 657d53b | 2012-07-12 11:06:03 +0000 | [diff] [blame] | 3654 | Object* object = READ_FIELD(this, kInstanceDescriptorsOrBackPointerOffset); |
| 3655 | if (object->IsMap()) { |
| 3656 | WRITE_FIELD(this, kInstanceDescriptorsOrBackPointerOffset, value); |
| 3657 | CONDITIONAL_WRITE_BARRIER( |
| 3658 | GetHeap(), this, kInstanceDescriptorsOrBackPointerOffset, value, mode); |
| 3659 | } else { |
| 3660 | DescriptorArray::cast(object)->set_back_pointer_storage(value); |
| 3661 | } |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3665 | // Can either be Smi (no transitions), normal transition array, or a transition |
| 3666 | // array with the header overwritten as a Smi (thus iterating). |
| 3667 | TransitionArray* Map::unchecked_transition_array() { |
| 3668 | ASSERT(HasTransitionArray()); |
| 3669 | Object* object = *HeapObject::RawField(instance_descriptors(), |
| 3670 | DescriptorArray::kTransitionsOffset); |
| 3671 | ASSERT(!object->IsSmi()); |
| 3672 | TransitionArray* transition_array = static_cast<TransitionArray*>(object); |
| 3673 | return transition_array; |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3674 | } |
| 3675 | |
| 3676 | |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 3677 | HeapObject* Map::UncheckedPrototypeTransitions() { |
| 3678 | ASSERT(HasTransitionArray()); |
| 3679 | ASSERT(unchecked_transition_array()->HasPrototypeTransitions()); |
| 3680 | return unchecked_transition_array()->UncheckedPrototypeTransitions(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 3684 | ACCESSORS(Map, code_cache, Object, kCodeCacheOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3685 | ACCESSORS(Map, constructor, Object, kConstructorOffset) |
| 3686 | |
| 3687 | ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3688 | ACCESSORS(JSFunction, literals_or_bindings, FixedArray, kLiteralsOffset) |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3689 | ACCESSORS(JSFunction, next_function_link, Object, kNextFunctionLinkOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3690 | |
| 3691 | ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset) |
| 3692 | ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset) |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3693 | ACCESSORS(GlobalObject, global_receiver, JSObject, kGlobalReceiverOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3694 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 3695 | ACCESSORS(JSGlobalProxy, context, Object, kContextOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3696 | |
| 3697 | ACCESSORS(AccessorInfo, getter, Object, kGetterOffset) |
| 3698 | ACCESSORS(AccessorInfo, setter, Object, kSetterOffset) |
| 3699 | ACCESSORS(AccessorInfo, data, Object, kDataOffset) |
| 3700 | ACCESSORS(AccessorInfo, name, Object, kNameOffset) |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3701 | ACCESSORS_TO_SMI(AccessorInfo, flag, kFlagOffset) |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3702 | ACCESSORS(AccessorInfo, expected_receiver_type, Object, |
| 3703 | kExpectedReceiverTypeOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3704 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3705 | ACCESSORS(AccessorPair, getter, Object, kGetterOffset) |
| 3706 | ACCESSORS(AccessorPair, setter, Object, kSetterOffset) |
| 3707 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3708 | ACCESSORS(AccessCheckInfo, named_callback, Object, kNamedCallbackOffset) |
| 3709 | ACCESSORS(AccessCheckInfo, indexed_callback, Object, kIndexedCallbackOffset) |
| 3710 | ACCESSORS(AccessCheckInfo, data, Object, kDataOffset) |
| 3711 | |
| 3712 | ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset) |
| 3713 | ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset) |
| 3714 | ACCESSORS(InterceptorInfo, query, Object, kQueryOffset) |
| 3715 | ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset) |
| 3716 | ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset) |
| 3717 | ACCESSORS(InterceptorInfo, data, Object, kDataOffset) |
| 3718 | |
| 3719 | ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset) |
| 3720 | ACCESSORS(CallHandlerInfo, data, Object, kDataOffset) |
| 3721 | |
| 3722 | ACCESSORS(TemplateInfo, tag, Object, kTagOffset) |
| 3723 | ACCESSORS(TemplateInfo, property_list, Object, kPropertyListOffset) |
| 3724 | |
| 3725 | ACCESSORS(FunctionTemplateInfo, serial_number, Object, kSerialNumberOffset) |
| 3726 | ACCESSORS(FunctionTemplateInfo, call_code, Object, kCallCodeOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3727 | ACCESSORS(FunctionTemplateInfo, property_accessors, Object, |
| 3728 | kPropertyAccessorsOffset) |
| 3729 | ACCESSORS(FunctionTemplateInfo, prototype_template, Object, |
| 3730 | kPrototypeTemplateOffset) |
| 3731 | ACCESSORS(FunctionTemplateInfo, parent_template, Object, kParentTemplateOffset) |
| 3732 | ACCESSORS(FunctionTemplateInfo, named_property_handler, Object, |
| 3733 | kNamedPropertyHandlerOffset) |
| 3734 | ACCESSORS(FunctionTemplateInfo, indexed_property_handler, Object, |
| 3735 | kIndexedPropertyHandlerOffset) |
| 3736 | ACCESSORS(FunctionTemplateInfo, instance_template, Object, |
| 3737 | kInstanceTemplateOffset) |
| 3738 | ACCESSORS(FunctionTemplateInfo, class_name, Object, kClassNameOffset) |
| 3739 | ACCESSORS(FunctionTemplateInfo, signature, Object, kSignatureOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3740 | ACCESSORS(FunctionTemplateInfo, instance_call_handler, Object, |
| 3741 | kInstanceCallHandlerOffset) |
| 3742 | ACCESSORS(FunctionTemplateInfo, access_check_info, Object, |
| 3743 | kAccessCheckInfoOffset) |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3744 | ACCESSORS_TO_SMI(FunctionTemplateInfo, flag, kFlagOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3745 | |
| 3746 | ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset) |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 3747 | ACCESSORS(ObjectTemplateInfo, internal_field_count, Object, |
| 3748 | kInternalFieldCountOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3749 | |
| 3750 | ACCESSORS(SignatureInfo, receiver, Object, kReceiverOffset) |
| 3751 | ACCESSORS(SignatureInfo, args, Object, kArgsOffset) |
| 3752 | |
| 3753 | ACCESSORS(TypeSwitchInfo, types, Object, kTypesOffset) |
| 3754 | |
| 3755 | ACCESSORS(Script, source, Object, kSourceOffset) |
| 3756 | ACCESSORS(Script, name, Object, kNameOffset) |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 3757 | ACCESSORS(Script, id, Object, kIdOffset) |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3758 | ACCESSORS_TO_SMI(Script, line_offset, kLineOffsetOffset) |
| 3759 | ACCESSORS_TO_SMI(Script, column_offset, kColumnOffsetOffset) |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3760 | ACCESSORS(Script, data, Object, kDataOffset) |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 3761 | ACCESSORS(Script, context_data, Object, kContextOffset) |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 3762 | ACCESSORS(Script, wrapper, Foreign, kWrapperOffset) |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3763 | ACCESSORS_TO_SMI(Script, type, kTypeOffset) |
| 3764 | ACCESSORS_TO_SMI(Script, compilation_type, kCompilationTypeOffset) |
| 3765 | ACCESSORS_TO_SMI(Script, compilation_state, kCompilationStateOffset) |
sgjesse@chromium.org | 499aaa5 | 2009-11-30 08:07:20 +0000 | [diff] [blame] | 3766 | ACCESSORS(Script, line_ends, Object, kLineEndsOffset) |
sgjesse@chromium.org | 9818059 | 2009-12-02 08:17:28 +0000 | [diff] [blame] | 3767 | ACCESSORS(Script, eval_from_shared, Object, kEvalFromSharedOffset) |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3768 | ACCESSORS_TO_SMI(Script, eval_from_instructions_offset, |
| 3769 | kEvalFrominstructionsOffsetOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3770 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3771 | #ifdef ENABLE_DEBUGGER_SUPPORT |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3772 | ACCESSORS(DebugInfo, shared, SharedFunctionInfo, kSharedFunctionInfoIndex) |
| 3773 | ACCESSORS(DebugInfo, original_code, Code, kOriginalCodeIndex) |
| 3774 | ACCESSORS(DebugInfo, code, Code, kPatchedCodeIndex) |
| 3775 | ACCESSORS(DebugInfo, break_points, FixedArray, kBreakPointsStateIndex) |
| 3776 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 3777 | ACCESSORS_TO_SMI(BreakPointInfo, code_position, kCodePositionIndex) |
| 3778 | ACCESSORS_TO_SMI(BreakPointInfo, source_position, kSourcePositionIndex) |
| 3779 | ACCESSORS_TO_SMI(BreakPointInfo, statement_position, kStatementPositionIndex) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3780 | ACCESSORS(BreakPointInfo, break_point_objects, Object, kBreakPointObjectsIndex) |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 3781 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3782 | |
| 3783 | ACCESSORS(SharedFunctionInfo, name, Object, kNameOffset) |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 3784 | ACCESSORS(SharedFunctionInfo, optimized_code_map, Object, |
| 3785 | kOptimizedCodeMapOffset) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3786 | ACCESSORS(SharedFunctionInfo, construct_stub, Code, kConstructStubOffset) |
| 3787 | ACCESSORS(SharedFunctionInfo, initial_map, Object, kInitialMapOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3788 | ACCESSORS(SharedFunctionInfo, instance_class_name, Object, |
| 3789 | kInstanceClassNameOffset) |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 3790 | ACCESSORS(SharedFunctionInfo, function_data, Object, kFunctionDataOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3791 | ACCESSORS(SharedFunctionInfo, script, Object, kScriptOffset) |
| 3792 | ACCESSORS(SharedFunctionInfo, debug_info, Object, kDebugInfoOffset) |
kasperl@chromium.org | d1e3e72 | 2009-04-14 13:38:25 +0000 | [diff] [blame] | 3793 | ACCESSORS(SharedFunctionInfo, inferred_name, String, kInferredNameOffset) |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3794 | ACCESSORS(SharedFunctionInfo, this_property_assignments, Object, |
| 3795 | kThisPropertyAssignmentsOffset) |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3796 | SMI_ACCESSORS(SharedFunctionInfo, ast_node_count, kAstNodeCountOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3797 | |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 3798 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3799 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, hidden_prototype, |
| 3800 | kHiddenPrototypeBit) |
| 3801 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit) |
| 3802 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check, |
| 3803 | kNeedsAccessCheckBit) |
ricow@chromium.org | 2c99e28 | 2011-07-28 09:15:17 +0000 | [diff] [blame] | 3804 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, read_only_prototype, |
| 3805 | kReadOnlyPrototypeBit) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3806 | BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_expression, |
| 3807 | kIsExpressionBit) |
| 3808 | BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel, |
| 3809 | kIsTopLevelBit) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3810 | BOOL_GETTER(SharedFunctionInfo, |
| 3811 | compiler_hints, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3812 | has_only_simple_this_property_assignments, |
| 3813 | kHasOnlySimpleThisPropertyAssignments) |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 3814 | BOOL_ACCESSORS(SharedFunctionInfo, |
| 3815 | compiler_hints, |
vegorov@chromium.org | 2356e6f | 2010-06-09 09:38:56 +0000 | [diff] [blame] | 3816 | allows_lazy_compilation, |
| 3817 | kAllowLazyCompilation) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3818 | BOOL_ACCESSORS(SharedFunctionInfo, |
| 3819 | compiler_hints, |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 3820 | allows_lazy_compilation_without_context, |
| 3821 | kAllowLazyCompilationWithoutContext) |
| 3822 | BOOL_ACCESSORS(SharedFunctionInfo, |
| 3823 | compiler_hints, |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3824 | uses_arguments, |
| 3825 | kUsesArguments) |
| 3826 | BOOL_ACCESSORS(SharedFunctionInfo, |
| 3827 | compiler_hints, |
| 3828 | has_duplicate_parameters, |
| 3829 | kHasDuplicateParameters) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3830 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 3831 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3832 | #if V8_HOST_ARCH_32_BIT |
| 3833 | SMI_ACCESSORS(SharedFunctionInfo, length, kLengthOffset) |
| 3834 | SMI_ACCESSORS(SharedFunctionInfo, formal_parameter_count, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3835 | kFormalParameterCountOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3836 | SMI_ACCESSORS(SharedFunctionInfo, expected_nof_properties, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3837 | kExpectedNofPropertiesOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3838 | SMI_ACCESSORS(SharedFunctionInfo, num_literals, kNumLiteralsOffset) |
| 3839 | SMI_ACCESSORS(SharedFunctionInfo, start_position_and_type, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3840 | kStartPositionAndTypeOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3841 | SMI_ACCESSORS(SharedFunctionInfo, end_position, kEndPositionOffset) |
| 3842 | SMI_ACCESSORS(SharedFunctionInfo, function_token_position, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3843 | kFunctionTokenPositionOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3844 | SMI_ACCESSORS(SharedFunctionInfo, compiler_hints, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3845 | kCompilerHintsOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3846 | SMI_ACCESSORS(SharedFunctionInfo, this_property_assignments_count, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 3847 | kThisPropertyAssignmentsCountOffset) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3848 | SMI_ACCESSORS(SharedFunctionInfo, opt_count, kOptCountOffset) |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3849 | SMI_ACCESSORS(SharedFunctionInfo, counters, kCountersOffset) |
| 3850 | SMI_ACCESSORS(SharedFunctionInfo, |
| 3851 | stress_deopt_counter, |
| 3852 | kStressDeoptCounterOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3853 | #else |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3854 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3855 | #define PSEUDO_SMI_ACCESSORS_LO(holder, name, offset) \ |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3856 | STATIC_ASSERT(holder::offset % kPointerSize == 0); \ |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3857 | int holder::name() { \ |
| 3858 | int value = READ_INT_FIELD(this, offset); \ |
| 3859 | ASSERT(kHeapObjectTag == 1); \ |
| 3860 | ASSERT((value & kHeapObjectTag) == 0); \ |
| 3861 | return value >> 1; \ |
| 3862 | } \ |
| 3863 | void holder::set_##name(int value) { \ |
| 3864 | ASSERT(kHeapObjectTag == 1); \ |
| 3865 | ASSERT((value & 0xC0000000) == 0xC0000000 || \ |
| 3866 | (value & 0xC0000000) == 0x000000000); \ |
| 3867 | WRITE_INT_FIELD(this, \ |
| 3868 | offset, \ |
| 3869 | (value << 1) & ~kHeapObjectTag); \ |
| 3870 | } |
| 3871 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3872 | #define PSEUDO_SMI_ACCESSORS_HI(holder, name, offset) \ |
| 3873 | STATIC_ASSERT(holder::offset % kPointerSize == kIntSize); \ |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3874 | INT_ACCESSORS(holder, name, offset) |
| 3875 | |
| 3876 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3877 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, length, kLengthOffset) |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3878 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, |
| 3879 | formal_parameter_count, |
| 3880 | kFormalParameterCountOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3881 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3882 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, |
| 3883 | expected_nof_properties, |
| 3884 | kExpectedNofPropertiesOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3885 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, num_literals, kNumLiteralsOffset) |
| 3886 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3887 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, end_position, kEndPositionOffset) |
| 3888 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, |
| 3889 | start_position_and_type, |
| 3890 | kStartPositionAndTypeOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3891 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3892 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, |
| 3893 | function_token_position, |
| 3894 | kFunctionTokenPositionOffset) |
| 3895 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, |
| 3896 | compiler_hints, |
| 3897 | kCompilerHintsOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3898 | |
whesse@chromium.org | f0ac72d | 2010-11-08 12:47:26 +0000 | [diff] [blame] | 3899 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, |
| 3900 | this_property_assignments_count, |
| 3901 | kThisPropertyAssignmentsCountOffset) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3902 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, opt_count, kOptCountOffset) |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 3903 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 3904 | PSEUDO_SMI_ACCESSORS_LO(SharedFunctionInfo, counters, kCountersOffset) |
| 3905 | PSEUDO_SMI_ACCESSORS_HI(SharedFunctionInfo, |
| 3906 | stress_deopt_counter, |
| 3907 | kStressDeoptCounterOffset) |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 3908 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 3909 | |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3910 | |
| 3911 | int SharedFunctionInfo::construction_count() { |
| 3912 | return READ_BYTE_FIELD(this, kConstructionCountOffset); |
| 3913 | } |
| 3914 | |
| 3915 | |
| 3916 | void SharedFunctionInfo::set_construction_count(int value) { |
| 3917 | ASSERT(0 <= value && value < 256); |
| 3918 | WRITE_BYTE_FIELD(this, kConstructionCountOffset, static_cast<byte>(value)); |
| 3919 | } |
| 3920 | |
| 3921 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3922 | BOOL_ACCESSORS(SharedFunctionInfo, |
| 3923 | compiler_hints, |
| 3924 | live_objects_may_exist, |
| 3925 | kLiveObjectsMayExist) |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3926 | |
| 3927 | |
| 3928 | bool SharedFunctionInfo::IsInobjectSlackTrackingInProgress() { |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 3929 | return initial_map() != GetHeap()->undefined_value(); |
whesse@chromium.org | 4a1fe7d | 2010-09-27 12:32:04 +0000 | [diff] [blame] | 3930 | } |
| 3931 | |
| 3932 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3933 | BOOL_GETTER(SharedFunctionInfo, |
| 3934 | compiler_hints, |
| 3935 | optimization_disabled, |
| 3936 | kOptimizationDisabled) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3937 | |
| 3938 | |
| 3939 | void SharedFunctionInfo::set_optimization_disabled(bool disable) { |
| 3940 | set_compiler_hints(BooleanBit::set(compiler_hints(), |
| 3941 | kOptimizationDisabled, |
| 3942 | disable)); |
| 3943 | // If disabling optimizations we reflect that in the code object so |
| 3944 | // it will not be counted as optimizable code. |
| 3945 | if ((code()->kind() == Code::FUNCTION) && disable) { |
| 3946 | code()->set_optimizable(false); |
| 3947 | } |
| 3948 | } |
| 3949 | |
| 3950 | |
jkummerow@chromium.org | 212d964 | 2012-05-11 15:02:09 +0000 | [diff] [blame] | 3951 | int SharedFunctionInfo::profiler_ticks() { |
| 3952 | if (code()->kind() != Code::FUNCTION) return 0; |
| 3953 | return code()->profiler_ticks(); |
| 3954 | } |
| 3955 | |
| 3956 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3957 | LanguageMode SharedFunctionInfo::language_mode() { |
| 3958 | int hints = compiler_hints(); |
| 3959 | if (BooleanBit::get(hints, kExtendedModeFunction)) { |
| 3960 | ASSERT(BooleanBit::get(hints, kStrictModeFunction)); |
| 3961 | return EXTENDED_MODE; |
| 3962 | } |
| 3963 | return BooleanBit::get(hints, kStrictModeFunction) |
| 3964 | ? STRICT_MODE : CLASSIC_MODE; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3965 | } |
| 3966 | |
| 3967 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3968 | void SharedFunctionInfo::set_language_mode(LanguageMode language_mode) { |
| 3969 | // We only allow language mode transitions that go set the same language mode |
| 3970 | // again or go up in the chain: |
| 3971 | // CLASSIC_MODE -> STRICT_MODE -> EXTENDED_MODE. |
| 3972 | ASSERT(this->language_mode() == CLASSIC_MODE || |
| 3973 | this->language_mode() == language_mode || |
| 3974 | language_mode == EXTENDED_MODE); |
| 3975 | int hints = compiler_hints(); |
| 3976 | hints = BooleanBit::set( |
| 3977 | hints, kStrictModeFunction, language_mode != CLASSIC_MODE); |
| 3978 | hints = BooleanBit::set( |
| 3979 | hints, kExtendedModeFunction, language_mode == EXTENDED_MODE); |
| 3980 | set_compiler_hints(hints); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3981 | } |
| 3982 | |
| 3983 | |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3984 | bool SharedFunctionInfo::is_classic_mode() { |
| 3985 | return !BooleanBit::get(compiler_hints(), kStrictModeFunction); |
| 3986 | } |
| 3987 | |
| 3988 | BOOL_GETTER(SharedFunctionInfo, compiler_hints, is_extended_mode, |
| 3989 | kExtendedModeFunction) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 3990 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, native, kNative) |
| 3991 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, |
| 3992 | name_should_print_as_anonymous, |
| 3993 | kNameShouldPrintAsAnonymous) |
| 3994 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, bound, kBoundFunction) |
| 3995 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_anonymous, kIsAnonymous) |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 3996 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, is_function, kIsFunction) |
| 3997 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, dont_optimize, |
| 3998 | kDontOptimize) |
svenpanne@chromium.org | b1df11d | 2012-02-08 10:26:21 +0000 | [diff] [blame] | 3999 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, dont_inline, kDontInline) |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4000 | BOOL_ACCESSORS(SharedFunctionInfo, compiler_hints, dont_cache, kDontCache) |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4001 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 4002 | void SharedFunctionInfo::BeforeVisitingPointers() { |
| 4003 | if (IsInobjectSlackTrackingInProgress()) DetachInitialMap(); |
| 4004 | |
| 4005 | // Flush optimized code map on major GC. |
| 4006 | // Note: we may experiment with rebuilding it or retaining entries |
| 4007 | // which should survive as we iterate through optimized functions |
| 4008 | // anyway. |
| 4009 | set_optimized_code_map(Smi::FromInt(0)); |
| 4010 | } |
| 4011 | |
| 4012 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 4013 | ACCESSORS(CodeCache, default_cache, FixedArray, kDefaultCacheOffset) |
| 4014 | ACCESSORS(CodeCache, normal_type_cache, Object, kNormalTypeCacheOffset) |
| 4015 | |
jkummerow@chromium.org | e297f59 | 2011-06-08 10:05:15 +0000 | [diff] [blame] | 4016 | ACCESSORS(PolymorphicCodeCache, cache, Object, kCacheOffset) |
| 4017 | |
sgjesse@chromium.org | 152a0b0 | 2009-10-07 13:50:16 +0000 | [diff] [blame] | 4018 | bool Script::HasValidSource() { |
| 4019 | Object* src = this->source(); |
| 4020 | if (!src->IsString()) return true; |
| 4021 | String* src_str = String::cast(src); |
| 4022 | if (!StringShape(src_str).IsExternal()) return true; |
| 4023 | if (src_str->IsAsciiRepresentation()) { |
| 4024 | return ExternalAsciiString::cast(src)->resource() != NULL; |
| 4025 | } else if (src_str->IsTwoByteRepresentation()) { |
| 4026 | return ExternalTwoByteString::cast(src)->resource() != NULL; |
| 4027 | } |
| 4028 | return true; |
| 4029 | } |
| 4030 | |
| 4031 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 4032 | void SharedFunctionInfo::DontAdaptArguments() { |
| 4033 | ASSERT(code()->kind() == Code::BUILTIN); |
| 4034 | set_formal_parameter_count(kDontAdaptArgumentsSentinel); |
| 4035 | } |
| 4036 | |
| 4037 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4038 | int SharedFunctionInfo::start_position() { |
| 4039 | return start_position_and_type() >> kStartPositionShift; |
| 4040 | } |
| 4041 | |
| 4042 | |
| 4043 | void SharedFunctionInfo::set_start_position(int start_position) { |
| 4044 | set_start_position_and_type((start_position << kStartPositionShift) |
| 4045 | | (start_position_and_type() & ~kStartPositionMask)); |
| 4046 | } |
| 4047 | |
| 4048 | |
| 4049 | Code* SharedFunctionInfo::code() { |
| 4050 | return Code::cast(READ_FIELD(this, kCodeOffset)); |
| 4051 | } |
| 4052 | |
| 4053 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4054 | Code* SharedFunctionInfo::unchecked_code() { |
| 4055 | return reinterpret_cast<Code*>(READ_FIELD(this, kCodeOffset)); |
| 4056 | } |
| 4057 | |
| 4058 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4059 | void SharedFunctionInfo::set_code(Code* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4060 | WRITE_FIELD(this, kCodeOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4061 | CONDITIONAL_WRITE_BARRIER(value->GetHeap(), this, kCodeOffset, value, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
| 4064 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4065 | ScopeInfo* SharedFunctionInfo::scope_info() { |
| 4066 | return reinterpret_cast<ScopeInfo*>(READ_FIELD(this, kScopeInfoOffset)); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 4067 | } |
| 4068 | |
| 4069 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4070 | void SharedFunctionInfo::set_scope_info(ScopeInfo* value, |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 4071 | WriteBarrierMode mode) { |
| 4072 | WRITE_FIELD(this, kScopeInfoOffset, reinterpret_cast<Object*>(value)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4073 | CONDITIONAL_WRITE_BARRIER(GetHeap(), |
| 4074 | this, |
| 4075 | kScopeInfoOffset, |
| 4076 | reinterpret_cast<Object*>(value), |
| 4077 | mode); |
ager@chromium.org | b573749 | 2010-07-15 09:29:43 +0000 | [diff] [blame] | 4078 | } |
| 4079 | |
| 4080 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4081 | bool SharedFunctionInfo::is_compiled() { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4082 | return code() != |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4083 | Isolate::Current()->builtins()->builtin(Builtins::kLazyCompile); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4087 | bool SharedFunctionInfo::IsApiFunction() { |
| 4088 | return function_data()->IsFunctionTemplateInfo(); |
| 4089 | } |
| 4090 | |
| 4091 | |
| 4092 | FunctionTemplateInfo* SharedFunctionInfo::get_api_func_data() { |
| 4093 | ASSERT(IsApiFunction()); |
| 4094 | return FunctionTemplateInfo::cast(function_data()); |
| 4095 | } |
| 4096 | |
| 4097 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4098 | bool SharedFunctionInfo::HasBuiltinFunctionId() { |
sgjesse@chromium.org | 720dc0b | 2010-05-10 09:25:39 +0000 | [diff] [blame] | 4099 | return function_data()->IsSmi(); |
| 4100 | } |
| 4101 | |
| 4102 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4103 | BuiltinFunctionId SharedFunctionInfo::builtin_function_id() { |
| 4104 | ASSERT(HasBuiltinFunctionId()); |
| 4105 | return static_cast<BuiltinFunctionId>(Smi::cast(function_data())->value()); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4109 | int SharedFunctionInfo::code_age() { |
| 4110 | return (compiler_hints() >> kCodeAgeShift) & kCodeAgeMask; |
| 4111 | } |
| 4112 | |
| 4113 | |
| 4114 | void SharedFunctionInfo::set_code_age(int code_age) { |
mstarzinger@chromium.org | f8c6bd5 | 2011-11-23 12:13:52 +0000 | [diff] [blame] | 4115 | int hints = compiler_hints() & ~(kCodeAgeMask << kCodeAgeShift); |
| 4116 | set_compiler_hints(hints | ((code_age & kCodeAgeMask) << kCodeAgeShift)); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4120 | int SharedFunctionInfo::ic_age() { |
| 4121 | return ICAgeBits::decode(counters()); |
| 4122 | } |
| 4123 | |
| 4124 | |
| 4125 | void SharedFunctionInfo::set_ic_age(int ic_age) { |
| 4126 | set_counters(ICAgeBits::update(counters(), ic_age)); |
| 4127 | } |
| 4128 | |
| 4129 | |
| 4130 | int SharedFunctionInfo::deopt_count() { |
| 4131 | return DeoptCountBits::decode(counters()); |
| 4132 | } |
| 4133 | |
| 4134 | |
| 4135 | void SharedFunctionInfo::set_deopt_count(int deopt_count) { |
| 4136 | set_counters(DeoptCountBits::update(counters(), deopt_count)); |
| 4137 | } |
| 4138 | |
| 4139 | |
| 4140 | void SharedFunctionInfo::increment_deopt_count() { |
| 4141 | int value = counters(); |
| 4142 | int deopt_count = DeoptCountBits::decode(value); |
| 4143 | deopt_count = (deopt_count + 1) & DeoptCountBits::kMax; |
| 4144 | set_counters(DeoptCountBits::update(value, deopt_count)); |
| 4145 | } |
| 4146 | |
| 4147 | |
| 4148 | int SharedFunctionInfo::opt_reenable_tries() { |
| 4149 | return OptReenableTriesBits::decode(counters()); |
| 4150 | } |
| 4151 | |
| 4152 | |
| 4153 | void SharedFunctionInfo::set_opt_reenable_tries(int tries) { |
| 4154 | set_counters(OptReenableTriesBits::update(counters(), tries)); |
| 4155 | } |
| 4156 | |
| 4157 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4158 | bool SharedFunctionInfo::has_deoptimization_support() { |
| 4159 | Code* code = this->code(); |
| 4160 | return code->kind() == Code::FUNCTION && code->has_deoptimization_support(); |
| 4161 | } |
| 4162 | |
| 4163 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4164 | void SharedFunctionInfo::TryReenableOptimization() { |
| 4165 | int tries = opt_reenable_tries(); |
| 4166 | set_opt_reenable_tries((tries + 1) & OptReenableTriesBits::kMax); |
| 4167 | // We reenable optimization whenever the number of tries is a large |
| 4168 | // enough power of 2. |
| 4169 | if (tries >= 16 && (((tries - 1) & tries) == 0)) { |
| 4170 | set_optimization_disabled(false); |
| 4171 | set_opt_count(0); |
| 4172 | set_deopt_count(0); |
| 4173 | code()->set_optimizable(true); |
| 4174 | } |
| 4175 | } |
| 4176 | |
| 4177 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4178 | bool JSFunction::IsBuiltin() { |
| 4179 | return context()->global()->IsJSBuiltinsObject(); |
| 4180 | } |
| 4181 | |
| 4182 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4183 | bool JSFunction::NeedsArgumentsAdaption() { |
| 4184 | return shared()->formal_parameter_count() != |
| 4185 | SharedFunctionInfo::kDontAdaptArgumentsSentinel; |
| 4186 | } |
| 4187 | |
| 4188 | |
| 4189 | bool JSFunction::IsOptimized() { |
| 4190 | return code()->kind() == Code::OPTIMIZED_FUNCTION; |
| 4191 | } |
| 4192 | |
| 4193 | |
ager@chromium.org | a9aa5fa | 2011-04-13 08:46:07 +0000 | [diff] [blame] | 4194 | bool JSFunction::IsOptimizable() { |
| 4195 | return code()->kind() == Code::FUNCTION && code()->optimizable(); |
| 4196 | } |
| 4197 | |
| 4198 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4199 | bool JSFunction::IsMarkedForLazyRecompilation() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4200 | return code() == GetIsolate()->builtins()->builtin(Builtins::kLazyRecompile); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4204 | Code* JSFunction::code() { |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4205 | return Code::cast(unchecked_code()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4206 | } |
| 4207 | |
| 4208 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4209 | Code* JSFunction::unchecked_code() { |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4210 | return reinterpret_cast<Code*>( |
| 4211 | Code::GetObjectFromEntryAddress(FIELD_ADDR(this, kCodeEntryOffset))); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4215 | void JSFunction::set_code(Code* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4216 | ASSERT(!HEAP->InNewSpace(value)); |
erik.corry@gmail.com | 145eff5 | 2010-08-23 11:36:18 +0000 | [diff] [blame] | 4217 | Address entry = value->entry(); |
| 4218 | WRITE_INTPTR_FIELD(this, kCodeEntryOffset, reinterpret_cast<intptr_t>(entry)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4219 | GetHeap()->incremental_marking()->RecordWriteOfCodeEntry( |
| 4220 | this, |
| 4221 | HeapObject::RawField(this, kCodeEntryOffset), |
| 4222 | value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
| 4225 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4226 | void JSFunction::ReplaceCode(Code* code) { |
| 4227 | bool was_optimized = IsOptimized(); |
| 4228 | bool is_optimized = code->kind() == Code::OPTIMIZED_FUNCTION; |
| 4229 | |
| 4230 | set_code(code); |
| 4231 | |
| 4232 | // Add/remove the function from the list of optimized functions for this |
| 4233 | // context based on the state change. |
| 4234 | if (!was_optimized && is_optimized) { |
| 4235 | context()->global_context()->AddOptimizedFunction(this); |
| 4236 | } |
| 4237 | if (was_optimized && !is_optimized) { |
| 4238 | context()->global_context()->RemoveOptimizedFunction(this); |
| 4239 | } |
| 4240 | } |
| 4241 | |
| 4242 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4243 | Context* JSFunction::context() { |
| 4244 | return Context::cast(READ_FIELD(this, kContextOffset)); |
| 4245 | } |
| 4246 | |
| 4247 | |
| 4248 | Object* JSFunction::unchecked_context() { |
| 4249 | return READ_FIELD(this, kContextOffset); |
| 4250 | } |
| 4251 | |
| 4252 | |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4253 | SharedFunctionInfo* JSFunction::unchecked_shared() { |
| 4254 | return reinterpret_cast<SharedFunctionInfo*>( |
| 4255 | READ_FIELD(this, kSharedFunctionInfoOffset)); |
| 4256 | } |
| 4257 | |
| 4258 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4259 | void JSFunction::set_context(Object* value) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4260 | ASSERT(value->IsUndefined() || value->IsContext()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4261 | WRITE_FIELD(this, kContextOffset, value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4262 | WRITE_BARRIER(GetHeap(), this, kContextOffset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | ACCESSORS(JSFunction, prototype_or_initial_map, Object, |
| 4266 | kPrototypeOrInitialMapOffset) |
| 4267 | |
| 4268 | |
| 4269 | Map* JSFunction::initial_map() { |
| 4270 | return Map::cast(prototype_or_initial_map()); |
| 4271 | } |
| 4272 | |
| 4273 | |
| 4274 | void JSFunction::set_initial_map(Map* value) { |
| 4275 | set_prototype_or_initial_map(value); |
| 4276 | } |
| 4277 | |
| 4278 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4279 | MaybeObject* JSFunction::set_initial_map_and_cache_transitions( |
| 4280 | Map* initial_map) { |
| 4281 | Context* global_context = context()->global_context(); |
| 4282 | Object* array_function = |
| 4283 | global_context->get(Context::ARRAY_FUNCTION_INDEX); |
| 4284 | if (array_function->IsJSFunction() && |
| 4285 | this == JSFunction::cast(array_function)) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4286 | // Replace all of the cached initial array maps in the global context with |
| 4287 | // the appropriate transitioned elements kind maps. |
| 4288 | Heap* heap = GetHeap(); |
| 4289 | MaybeObject* maybe_maps = |
| 4290 | heap->AllocateFixedArrayWithHoles(kElementsKindCount); |
| 4291 | FixedArray* maps; |
| 4292 | if (!maybe_maps->To(&maps)) return maybe_maps; |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4293 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4294 | Map* current_map = initial_map; |
| 4295 | ElementsKind kind = current_map->elements_kind(); |
| 4296 | ASSERT(kind == GetInitialFastElementsKind()); |
| 4297 | maps->set(kind, current_map); |
| 4298 | for (int i = GetSequenceIndexFromFastElementsKind(kind) + 1; |
| 4299 | i < kFastElementsKindCount; ++i) { |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4300 | Map* new_map; |
| 4301 | ElementsKind next_kind = GetFastElementsKindFromSequenceIndex(i); |
| 4302 | MaybeObject* maybe_new_map = |
| 4303 | current_map->CreateNextElementsTransition(next_kind); |
| 4304 | if (!maybe_new_map->To(&new_map)) return maybe_new_map; |
| 4305 | maps->set(next_kind, new_map); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4306 | current_map = new_map; |
| 4307 | } |
| 4308 | global_context->set_js_array_maps(maps); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4309 | } |
| 4310 | set_initial_map(initial_map); |
| 4311 | return this; |
| 4312 | } |
| 4313 | |
| 4314 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4315 | bool JSFunction::has_initial_map() { |
| 4316 | return prototype_or_initial_map()->IsMap(); |
| 4317 | } |
| 4318 | |
| 4319 | |
| 4320 | bool JSFunction::has_instance_prototype() { |
| 4321 | return has_initial_map() || !prototype_or_initial_map()->IsTheHole(); |
| 4322 | } |
| 4323 | |
| 4324 | |
| 4325 | bool JSFunction::has_prototype() { |
| 4326 | return map()->has_non_instance_prototype() || has_instance_prototype(); |
| 4327 | } |
| 4328 | |
| 4329 | |
| 4330 | Object* JSFunction::instance_prototype() { |
| 4331 | ASSERT(has_instance_prototype()); |
| 4332 | if (has_initial_map()) return initial_map()->prototype(); |
| 4333 | // When there is no initial map and the prototype is a JSObject, the |
| 4334 | // initial map field is used for the prototype field. |
| 4335 | return prototype_or_initial_map(); |
| 4336 | } |
| 4337 | |
| 4338 | |
| 4339 | Object* JSFunction::prototype() { |
| 4340 | ASSERT(has_prototype()); |
| 4341 | // If the function's prototype property has been set to a non-JSObject |
| 4342 | // value, that value is stored in the constructor field of the map. |
| 4343 | if (map()->has_non_instance_prototype()) return map()->constructor(); |
| 4344 | return instance_prototype(); |
| 4345 | } |
| 4346 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4347 | |
kmillikin@chromium.org | 4111b80 | 2010-05-03 10:34:42 +0000 | [diff] [blame] | 4348 | bool JSFunction::should_have_prototype() { |
| 4349 | return map()->function_with_prototype(); |
| 4350 | } |
| 4351 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4352 | |
| 4353 | bool JSFunction::is_compiled() { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4354 | return code() != GetIsolate()->builtins()->builtin(Builtins::kLazyCompile); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4358 | FixedArray* JSFunction::literals() { |
| 4359 | ASSERT(!shared()->bound()); |
| 4360 | return literals_or_bindings(); |
| 4361 | } |
| 4362 | |
| 4363 | |
| 4364 | void JSFunction::set_literals(FixedArray* literals) { |
| 4365 | ASSERT(!shared()->bound()); |
| 4366 | set_literals_or_bindings(literals); |
| 4367 | } |
| 4368 | |
| 4369 | |
| 4370 | FixedArray* JSFunction::function_bindings() { |
| 4371 | ASSERT(shared()->bound()); |
| 4372 | return literals_or_bindings(); |
| 4373 | } |
| 4374 | |
| 4375 | |
| 4376 | void JSFunction::set_function_bindings(FixedArray* bindings) { |
| 4377 | ASSERT(shared()->bound()); |
| 4378 | // Bound function literal may be initialized to the empty fixed array |
| 4379 | // before the bindings are set. |
| 4380 | ASSERT(bindings == GetHeap()->empty_fixed_array() || |
| 4381 | bindings->map() == GetHeap()->fixed_cow_array_map()); |
| 4382 | set_literals_or_bindings(bindings); |
| 4383 | } |
| 4384 | |
| 4385 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4386 | int JSFunction::NumberOfLiterals() { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4387 | ASSERT(!shared()->bound()); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4388 | return literals()->length(); |
| 4389 | } |
| 4390 | |
| 4391 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4392 | Object* JSBuiltinsObject::javascript_builtin(Builtins::JavaScript id) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4393 | ASSERT(id < kJSBuiltinsCount); // id is unsigned. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4394 | return READ_FIELD(this, OffsetOfFunctionWithId(id)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4395 | } |
| 4396 | |
| 4397 | |
| 4398 | void JSBuiltinsObject::set_javascript_builtin(Builtins::JavaScript id, |
| 4399 | Object* value) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4400 | ASSERT(id < kJSBuiltinsCount); // id is unsigned. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4401 | WRITE_FIELD(this, OffsetOfFunctionWithId(id), value); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4402 | WRITE_BARRIER(GetHeap(), this, OffsetOfFunctionWithId(id), value); |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4403 | } |
| 4404 | |
| 4405 | |
| 4406 | Code* JSBuiltinsObject::javascript_builtin_code(Builtins::JavaScript id) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4407 | ASSERT(id < kJSBuiltinsCount); // id is unsigned. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4408 | return Code::cast(READ_FIELD(this, OffsetOfCodeWithId(id))); |
| 4409 | } |
| 4410 | |
| 4411 | |
| 4412 | void JSBuiltinsObject::set_javascript_builtin_code(Builtins::JavaScript id, |
| 4413 | Code* value) { |
sgjesse@chromium.org | c6c5718 | 2011-01-17 12:24:25 +0000 | [diff] [blame] | 4414 | ASSERT(id < kJSBuiltinsCount); // id is unsigned. |
ricow@chromium.org | c9c8082 | 2010-04-21 08:22:37 +0000 | [diff] [blame] | 4415 | WRITE_FIELD(this, OffsetOfCodeWithId(id), value); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4416 | ASSERT(!HEAP->InNewSpace(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4417 | } |
| 4418 | |
| 4419 | |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4420 | ACCESSORS(JSProxy, handler, Object, kHandlerOffset) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4421 | ACCESSORS(JSProxy, hash, Object, kHashOffset) |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4422 | ACCESSORS(JSFunctionProxy, call_trap, Object, kCallTrapOffset) |
| 4423 | ACCESSORS(JSFunctionProxy, construct_trap, Object, kConstructTrapOffset) |
| 4424 | |
| 4425 | |
| 4426 | void JSProxy::InitializeBody(int object_size, Object* value) { |
| 4427 | ASSERT(!value->IsHeapObject() || !GetHeap()->InNewSpace(value)); |
| 4428 | for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { |
| 4429 | WRITE_FIELD(this, offset, value); |
| 4430 | } |
| 4431 | } |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4432 | |
| 4433 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4434 | ACCESSORS(JSSet, table, Object, kTableOffset) |
| 4435 | ACCESSORS(JSMap, table, Object, kTableOffset) |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4436 | ACCESSORS(JSWeakMap, table, Object, kTableOffset) |
| 4437 | ACCESSORS(JSWeakMap, next, Object, kNextOffset) |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4438 | |
| 4439 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4440 | Address Foreign::foreign_address() { |
| 4441 | return AddressFrom<Address>(READ_INTPTR_FIELD(this, kForeignAddressOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4442 | } |
| 4443 | |
| 4444 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4445 | void Foreign::set_foreign_address(Address value) { |
| 4446 | WRITE_INTPTR_FIELD(this, kForeignAddressOffset, OffsetFrom(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4450 | ACCESSORS(JSModule, context, Object, kContextOffset) |
danno@chromium.org | 81cac2b | 2012-07-10 11:28:27 +0000 | [diff] [blame] | 4451 | ACCESSORS(JSModule, scope_info, ScopeInfo, kScopeInfoOffset) |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4452 | |
| 4453 | |
| 4454 | JSModule* JSModule::cast(Object* obj) { |
| 4455 | ASSERT(obj->IsJSModule()); |
| 4456 | ASSERT(HeapObject::cast(obj)->Size() == JSModule::kSize); |
| 4457 | return reinterpret_cast<JSModule*>(obj); |
| 4458 | } |
| 4459 | |
| 4460 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4461 | ACCESSORS(JSValue, value, Object, kValueOffset) |
| 4462 | |
| 4463 | |
| 4464 | JSValue* JSValue::cast(Object* obj) { |
| 4465 | ASSERT(obj->IsJSValue()); |
| 4466 | ASSERT(HeapObject::cast(obj)->Size() == JSValue::kSize); |
| 4467 | return reinterpret_cast<JSValue*>(obj); |
| 4468 | } |
| 4469 | |
| 4470 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4471 | ACCESSORS(JSDate, value, Object, kValueOffset) |
| 4472 | ACCESSORS(JSDate, cache_stamp, Object, kCacheStampOffset) |
| 4473 | ACCESSORS(JSDate, year, Object, kYearOffset) |
| 4474 | ACCESSORS(JSDate, month, Object, kMonthOffset) |
| 4475 | ACCESSORS(JSDate, day, Object, kDayOffset) |
| 4476 | ACCESSORS(JSDate, weekday, Object, kWeekdayOffset) |
| 4477 | ACCESSORS(JSDate, hour, Object, kHourOffset) |
| 4478 | ACCESSORS(JSDate, min, Object, kMinOffset) |
| 4479 | ACCESSORS(JSDate, sec, Object, kSecOffset) |
| 4480 | |
| 4481 | |
| 4482 | JSDate* JSDate::cast(Object* obj) { |
| 4483 | ASSERT(obj->IsJSDate()); |
| 4484 | ASSERT(HeapObject::cast(obj)->Size() == JSDate::kSize); |
| 4485 | return reinterpret_cast<JSDate*>(obj); |
| 4486 | } |
| 4487 | |
| 4488 | |
kmillikin@chromium.org | 31b1277 | 2011-02-02 16:08:26 +0000 | [diff] [blame] | 4489 | ACCESSORS(JSMessageObject, type, String, kTypeOffset) |
| 4490 | ACCESSORS(JSMessageObject, arguments, JSArray, kArgumentsOffset) |
| 4491 | ACCESSORS(JSMessageObject, script, Object, kScriptOffset) |
| 4492 | ACCESSORS(JSMessageObject, stack_trace, Object, kStackTraceOffset) |
| 4493 | ACCESSORS(JSMessageObject, stack_frames, Object, kStackFramesOffset) |
| 4494 | SMI_ACCESSORS(JSMessageObject, start_position, kStartPositionOffset) |
| 4495 | SMI_ACCESSORS(JSMessageObject, end_position, kEndPositionOffset) |
| 4496 | |
| 4497 | |
| 4498 | JSMessageObject* JSMessageObject::cast(Object* obj) { |
| 4499 | ASSERT(obj->IsJSMessageObject()); |
| 4500 | ASSERT(HeapObject::cast(obj)->Size() == JSMessageObject::kSize); |
| 4501 | return reinterpret_cast<JSMessageObject*>(obj); |
| 4502 | } |
| 4503 | |
| 4504 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4505 | INT_ACCESSORS(Code, instruction_size, kInstructionSizeOffset) |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4506 | ACCESSORS(Code, relocation_info, ByteArray, kRelocationInfoOffset) |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4507 | ACCESSORS(Code, handler_table, FixedArray, kHandlerTableOffset) |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4508 | ACCESSORS(Code, deoptimization_data, FixedArray, kDeoptimizationDataOffset) |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 4509 | ACCESSORS(Code, type_feedback_info, Object, kTypeFeedbackInfoOffset) |
yangguo@chromium.org | 659ceec | 2012-01-26 07:37:54 +0000 | [diff] [blame] | 4510 | ACCESSORS(Code, gc_metadata, Object, kGCMetadataOffset) |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 4511 | INT_ACCESSORS(Code, ic_age, kICAgeOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4512 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4513 | byte* Code::instruction_start() { |
| 4514 | return FIELD_ADDR(this, kHeaderSize); |
| 4515 | } |
| 4516 | |
| 4517 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4518 | byte* Code::instruction_end() { |
| 4519 | return instruction_start() + instruction_size(); |
| 4520 | } |
| 4521 | |
| 4522 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4523 | int Code::body_size() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4524 | return RoundUp(instruction_size(), kObjectAlignment); |
| 4525 | } |
| 4526 | |
| 4527 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4528 | FixedArray* Code::unchecked_deoptimization_data() { |
| 4529 | return reinterpret_cast<FixedArray*>( |
| 4530 | READ_FIELD(this, kDeoptimizationDataOffset)); |
| 4531 | } |
| 4532 | |
| 4533 | |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4534 | ByteArray* Code::unchecked_relocation_info() { |
| 4535 | return reinterpret_cast<ByteArray*>(READ_FIELD(this, kRelocationInfoOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4536 | } |
| 4537 | |
| 4538 | |
| 4539 | byte* Code::relocation_start() { |
erik.corry@gmail.com | 4a2e25e | 2010-07-07 12:22:46 +0000 | [diff] [blame] | 4540 | return unchecked_relocation_info()->GetDataStartAddress(); |
| 4541 | } |
| 4542 | |
| 4543 | |
| 4544 | int Code::relocation_size() { |
| 4545 | return unchecked_relocation_info()->length(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4546 | } |
| 4547 | |
| 4548 | |
| 4549 | byte* Code::entry() { |
| 4550 | return instruction_start(); |
| 4551 | } |
| 4552 | |
| 4553 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4554 | bool Code::contains(byte* inner_pointer) { |
| 4555 | return (address() <= inner_pointer) && (inner_pointer <= address() + Size()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4556 | } |
| 4557 | |
| 4558 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4559 | ACCESSORS(JSArray, length, Object, kLengthOffset) |
| 4560 | |
| 4561 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4562 | ACCESSORS(JSRegExp, data, Object, kDataOffset) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4563 | |
| 4564 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4565 | JSRegExp::Type JSRegExp::TypeTag() { |
| 4566 | Object* data = this->data(); |
| 4567 | if (data->IsUndefined()) return JSRegExp::NOT_COMPILED; |
| 4568 | Smi* smi = Smi::cast(FixedArray::cast(data)->get(kTagIndex)); |
| 4569 | return static_cast<JSRegExp::Type>(smi->value()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4570 | } |
| 4571 | |
| 4572 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4573 | JSRegExp::Type JSRegExp::TypeTagUnchecked() { |
| 4574 | Smi* smi = Smi::cast(DataAtUnchecked(kTagIndex)); |
| 4575 | return static_cast<JSRegExp::Type>(smi->value()); |
| 4576 | } |
| 4577 | |
| 4578 | |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 4579 | int JSRegExp::CaptureCount() { |
| 4580 | switch (TypeTag()) { |
| 4581 | case ATOM: |
| 4582 | return 0; |
| 4583 | case IRREGEXP: |
| 4584 | return Smi::cast(DataAt(kIrregexpCaptureCountIndex))->value(); |
| 4585 | default: |
| 4586 | UNREACHABLE(); |
| 4587 | return -1; |
| 4588 | } |
| 4589 | } |
| 4590 | |
| 4591 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 4592 | JSRegExp::Flags JSRegExp::GetFlags() { |
| 4593 | ASSERT(this->data()->IsFixedArray()); |
| 4594 | Object* data = this->data(); |
| 4595 | Smi* smi = Smi::cast(FixedArray::cast(data)->get(kFlagsIndex)); |
| 4596 | return Flags(smi->value()); |
| 4597 | } |
| 4598 | |
| 4599 | |
| 4600 | String* JSRegExp::Pattern() { |
| 4601 | ASSERT(this->data()->IsFixedArray()); |
| 4602 | Object* data = this->data(); |
| 4603 | String* pattern= String::cast(FixedArray::cast(data)->get(kSourceIndex)); |
| 4604 | return pattern; |
| 4605 | } |
| 4606 | |
| 4607 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame] | 4608 | Object* JSRegExp::DataAt(int index) { |
| 4609 | ASSERT(TypeTag() != NOT_COMPILED); |
| 4610 | return FixedArray::cast(data())->get(index); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4614 | Object* JSRegExp::DataAtUnchecked(int index) { |
| 4615 | FixedArray* fa = reinterpret_cast<FixedArray*>(data()); |
| 4616 | int offset = FixedArray::kHeaderSize + index * kPointerSize; |
| 4617 | return READ_FIELD(fa, offset); |
| 4618 | } |
| 4619 | |
| 4620 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 4621 | void JSRegExp::SetDataAt(int index, Object* value) { |
| 4622 | ASSERT(TypeTag() != NOT_COMPILED); |
| 4623 | ASSERT(index >= kDataIndex); // Only implementation data can be set this way. |
| 4624 | FixedArray::cast(data())->set(index, value); |
| 4625 | } |
| 4626 | |
| 4627 | |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4628 | void JSRegExp::SetDataAtUnchecked(int index, Object* value, Heap* heap) { |
| 4629 | ASSERT(index >= kDataIndex); // Only implementation data can be set this way. |
| 4630 | FixedArray* fa = reinterpret_cast<FixedArray*>(data()); |
| 4631 | if (value->IsSmi()) { |
| 4632 | fa->set_unchecked(index, Smi::cast(value)); |
| 4633 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4634 | // We only do this during GC, so we don't need to notify the write barrier. |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 4635 | fa->set_unchecked(heap, index, value, SKIP_WRITE_BARRIER); |
| 4636 | } |
| 4637 | } |
| 4638 | |
| 4639 | |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4640 | ElementsKind JSObject::GetElementsKind() { |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4641 | ElementsKind kind = map()->elements_kind(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4642 | #if DEBUG |
| 4643 | FixedArrayBase* fixed_array = |
| 4644 | reinterpret_cast<FixedArrayBase*>(READ_FIELD(this, kElementsOffset)); |
| 4645 | Map* map = fixed_array->map(); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4646 | ASSERT((IsFastSmiOrObjectElementsKind(kind) && |
| 4647 | (map == GetHeap()->fixed_array_map() || |
| 4648 | map == GetHeap()->fixed_cow_array_map())) || |
| 4649 | (IsFastDoubleElementsKind(kind) && |
| 4650 | (fixed_array->IsFixedDoubleArray() || |
| 4651 | fixed_array == GetHeap()->empty_fixed_array())) || |
| 4652 | (kind == DICTIONARY_ELEMENTS && |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4653 | fixed_array->IsFixedArray() && |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4654 | fixed_array->IsDictionary()) || |
| 4655 | (kind > DICTIONARY_ELEMENTS)); |
| 4656 | ASSERT((kind != NON_STRICT_ARGUMENTS_ELEMENTS) || |
| 4657 | (elements()->IsFixedArray() && elements()->length() >= 2)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4658 | #endif |
erik.corry@gmail.com | d6076d9 | 2011-06-06 09:39:18 +0000 | [diff] [blame] | 4659 | return kind; |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4660 | } |
| 4661 | |
| 4662 | |
kmillikin@chromium.org | 7c2628c | 2011-08-10 11:27:35 +0000 | [diff] [blame] | 4663 | ElementsAccessor* JSObject::GetElementsAccessor() { |
| 4664 | return ElementsAccessor::ForKind(GetElementsKind()); |
| 4665 | } |
| 4666 | |
| 4667 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4668 | bool JSObject::HasFastObjectElements() { |
| 4669 | return IsFastObjectElementsKind(GetElementsKind()); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4670 | } |
| 4671 | |
| 4672 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4673 | bool JSObject::HasFastSmiElements() { |
| 4674 | return IsFastSmiElementsKind(GetElementsKind()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4675 | } |
| 4676 | |
| 4677 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4678 | bool JSObject::HasFastSmiOrObjectElements() { |
| 4679 | return IsFastSmiOrObjectElementsKind(GetElementsKind()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4680 | } |
| 4681 | |
| 4682 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4683 | bool JSObject::HasFastDoubleElements() { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4684 | return IsFastDoubleElementsKind(GetElementsKind()); |
| 4685 | } |
| 4686 | |
| 4687 | |
| 4688 | bool JSObject::HasFastHoleyElements() { |
| 4689 | return IsFastHoleyElementsKind(GetElementsKind()); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 4690 | } |
| 4691 | |
| 4692 | |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4693 | bool JSObject::HasDictionaryElements() { |
| 4694 | return GetElementsKind() == DICTIONARY_ELEMENTS; |
| 4695 | } |
| 4696 | |
| 4697 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4698 | bool JSObject::HasNonStrictArgumentsElements() { |
| 4699 | return GetElementsKind() == NON_STRICT_ARGUMENTS_ELEMENTS; |
| 4700 | } |
| 4701 | |
| 4702 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4703 | bool JSObject::HasExternalArrayElements() { |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4704 | HeapObject* array = elements(); |
| 4705 | ASSERT(array != NULL); |
| 4706 | return array->IsExternalArray(); |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4707 | } |
| 4708 | |
| 4709 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4710 | #define EXTERNAL_ELEMENTS_CHECK(name, type) \ |
| 4711 | bool JSObject::HasExternal##name##Elements() { \ |
| 4712 | HeapObject* array = elements(); \ |
| 4713 | ASSERT(array != NULL); \ |
| 4714 | if (!array->IsHeapObject()) \ |
| 4715 | return false; \ |
| 4716 | return array->map()->instance_type() == type; \ |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4717 | } |
| 4718 | |
| 4719 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4720 | EXTERNAL_ELEMENTS_CHECK(Byte, EXTERNAL_BYTE_ARRAY_TYPE) |
| 4721 | EXTERNAL_ELEMENTS_CHECK(UnsignedByte, EXTERNAL_UNSIGNED_BYTE_ARRAY_TYPE) |
| 4722 | EXTERNAL_ELEMENTS_CHECK(Short, EXTERNAL_SHORT_ARRAY_TYPE) |
| 4723 | EXTERNAL_ELEMENTS_CHECK(UnsignedShort, |
| 4724 | EXTERNAL_UNSIGNED_SHORT_ARRAY_TYPE) |
| 4725 | EXTERNAL_ELEMENTS_CHECK(Int, EXTERNAL_INT_ARRAY_TYPE) |
| 4726 | EXTERNAL_ELEMENTS_CHECK(UnsignedInt, |
| 4727 | EXTERNAL_UNSIGNED_INT_ARRAY_TYPE) |
| 4728 | EXTERNAL_ELEMENTS_CHECK(Float, |
| 4729 | EXTERNAL_FLOAT_ARRAY_TYPE) |
erik.corry@gmail.com | 3847bd5 | 2011-04-27 10:38:56 +0000 | [diff] [blame] | 4730 | EXTERNAL_ELEMENTS_CHECK(Double, |
| 4731 | EXTERNAL_DOUBLE_ARRAY_TYPE) |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4732 | EXTERNAL_ELEMENTS_CHECK(Pixel, EXTERNAL_PIXEL_ARRAY_TYPE) |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 4733 | |
| 4734 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4735 | bool JSObject::HasNamedInterceptor() { |
| 4736 | return map()->has_named_interceptor(); |
| 4737 | } |
| 4738 | |
| 4739 | |
| 4740 | bool JSObject::HasIndexedInterceptor() { |
| 4741 | return map()->has_indexed_interceptor(); |
| 4742 | } |
| 4743 | |
| 4744 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4745 | MaybeObject* JSObject::EnsureWritableFastElements() { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4746 | ASSERT(HasFastSmiOrObjectElements()); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4747 | FixedArray* elems = FixedArray::cast(elements()); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4748 | Isolate* isolate = GetIsolate(); |
| 4749 | if (elems->map() != isolate->heap()->fixed_cow_array_map()) return elems; |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4750 | Object* writable_elems; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4751 | { MaybeObject* maybe_writable_elems = isolate->heap()->CopyFixedArrayWithMap( |
| 4752 | elems, isolate->heap()->fixed_array_map()); |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 4753 | if (!maybe_writable_elems->ToObject(&writable_elems)) { |
| 4754 | return maybe_writable_elems; |
| 4755 | } |
| 4756 | } |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4757 | set_elements(FixedArray::cast(writable_elems)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4758 | isolate->counters()->cow_arrays_converted()->Increment(); |
ricow@chromium.org | 0b9f850 | 2010-08-18 07:45:01 +0000 | [diff] [blame] | 4759 | return writable_elems; |
| 4760 | } |
| 4761 | |
| 4762 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4763 | StringDictionary* JSObject::property_dictionary() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4764 | ASSERT(!HasFastProperties()); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 4765 | return StringDictionary::cast(properties()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4766 | } |
| 4767 | |
| 4768 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4769 | SeededNumberDictionary* JSObject::element_dictionary() { |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 4770 | ASSERT(HasDictionaryElements()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4771 | return SeededNumberDictionary::cast(elements()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4772 | } |
| 4773 | |
| 4774 | |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4775 | bool String::IsHashFieldComputed(uint32_t field) { |
| 4776 | return (field & kHashNotComputedMask) == 0; |
| 4777 | } |
| 4778 | |
| 4779 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4780 | bool String::HasHashCode() { |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4781 | return IsHashFieldComputed(hash_field()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4782 | } |
| 4783 | |
| 4784 | |
| 4785 | uint32_t String::Hash() { |
| 4786 | // Fast case: has hash code already been computed? |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4787 | uint32_t field = hash_field(); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 4788 | if (IsHashFieldComputed(field)) return field >> kHashShift; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4789 | // Slow case: compute hash code and set it. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4790 | return ComputeAndSetHash(); |
| 4791 | } |
| 4792 | |
| 4793 | |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4794 | StringHasher::StringHasher(int length, uint32_t seed) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4795 | : length_(length), |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4796 | raw_running_hash_(seed), |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4797 | array_index_(0), |
| 4798 | is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), |
| 4799 | is_first_char_(true), |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4800 | is_valid_(true) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4801 | ASSERT(FLAG_randomize_hashes || raw_running_hash_ == 0); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4802 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4803 | |
| 4804 | |
| 4805 | bool StringHasher::has_trivial_hash() { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4806 | return length_ > String::kMaxHashCalcLength; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4807 | } |
| 4808 | |
| 4809 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 4810 | void StringHasher::AddCharacter(uint32_t c) { |
| 4811 | if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 4812 | AddSurrogatePair(c); // Not inlined. |
| 4813 | return; |
| 4814 | } |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4815 | // Use the Jenkins one-at-a-time hash function to update the hash |
| 4816 | // for the given character. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4817 | raw_running_hash_ += c; |
| 4818 | raw_running_hash_ += (raw_running_hash_ << 10); |
| 4819 | raw_running_hash_ ^= (raw_running_hash_ >> 6); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 4820 | // Incremental array index computation. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4821 | if (is_array_index_) { |
| 4822 | if (c < '0' || c > '9') { |
| 4823 | is_array_index_ = false; |
| 4824 | } else { |
| 4825 | int d = c - '0'; |
| 4826 | if (is_first_char_) { |
| 4827 | is_first_char_ = false; |
| 4828 | if (c == '0' && length_ > 1) { |
| 4829 | is_array_index_ = false; |
| 4830 | return; |
| 4831 | } |
| 4832 | } |
| 4833 | if (array_index_ > 429496729U - ((d + 2) >> 3)) { |
| 4834 | is_array_index_ = false; |
| 4835 | } else { |
| 4836 | array_index_ = array_index_ * 10 + d; |
| 4837 | } |
| 4838 | } |
| 4839 | } |
| 4840 | } |
| 4841 | |
| 4842 | |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 4843 | void StringHasher::AddCharacterNoIndex(uint32_t c) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4844 | ASSERT(!is_array_index()); |
yangguo@chromium.org | 154ff99 | 2012-03-13 08:09:54 +0000 | [diff] [blame] | 4845 | if (c > unibrow::Utf16::kMaxNonSurrogateCharCode) { |
| 4846 | AddSurrogatePairNoIndex(c); // Not inlined. |
| 4847 | return; |
| 4848 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4849 | raw_running_hash_ += c; |
| 4850 | raw_running_hash_ += (raw_running_hash_ << 10); |
| 4851 | raw_running_hash_ ^= (raw_running_hash_ >> 6); |
| 4852 | } |
| 4853 | |
| 4854 | |
| 4855 | uint32_t StringHasher::GetHash() { |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 4856 | // Get the calculated raw hash value and do some more bit ops to distribute |
| 4857 | // the hash further. Ensure that we never return zero as the hash value. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4858 | uint32_t result = raw_running_hash_; |
| 4859 | result += (result << 3); |
| 4860 | result ^= (result >> 11); |
| 4861 | result += (result << 15); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4862 | if ((result & String::kHashBitMask) == 0) { |
ager@chromium.org | 3b45ab5 | 2009-03-19 22:21:34 +0000 | [diff] [blame] | 4863 | result = 27; |
| 4864 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 4865 | return result; |
| 4866 | } |
| 4867 | |
| 4868 | |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4869 | template <typename schar> |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 4870 | uint32_t HashSequentialString(const schar* chars, int length, uint32_t seed) { |
| 4871 | StringHasher hasher(length, seed); |
whesse@chromium.org | b08986c | 2011-03-14 16:13:42 +0000 | [diff] [blame] | 4872 | if (!hasher.has_trivial_hash()) { |
| 4873 | int i; |
| 4874 | for (i = 0; hasher.is_array_index() && (i < length); i++) { |
| 4875 | hasher.AddCharacter(chars[i]); |
| 4876 | } |
| 4877 | for (; i < length; i++) { |
| 4878 | hasher.AddCharacterNoIndex(chars[i]); |
| 4879 | } |
| 4880 | } |
| 4881 | return hasher.GetHashField(); |
| 4882 | } |
| 4883 | |
| 4884 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4885 | bool String::AsArrayIndex(uint32_t* index) { |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 4886 | uint32_t field = hash_field(); |
lrn@chromium.org | 1af7e1b | 2010-06-07 11:12:01 +0000 | [diff] [blame] | 4887 | if (IsHashFieldComputed(field) && (field & kIsNotArrayIndexMask)) { |
| 4888 | return false; |
| 4889 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4890 | return SlowAsArrayIndex(index); |
| 4891 | } |
| 4892 | |
| 4893 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4894 | Object* JSReceiver::GetPrototype() { |
yangguo@chromium.org | 99aa490 | 2012-07-06 16:21:55 +0000 | [diff] [blame] | 4895 | return map()->prototype(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4896 | } |
| 4897 | |
| 4898 | |
yangguo@chromium.org | c74d674 | 2012-06-29 15:15:45 +0000 | [diff] [blame] | 4899 | Object* JSReceiver::GetConstructor() { |
| 4900 | return map()->constructor(); |
| 4901 | } |
| 4902 | |
| 4903 | |
rossberg@chromium.org | 717967f | 2011-07-20 13:44:42 +0000 | [diff] [blame] | 4904 | bool JSReceiver::HasProperty(String* name) { |
| 4905 | if (IsJSProxy()) { |
| 4906 | return JSProxy::cast(this)->HasPropertyWithHandler(name); |
| 4907 | } |
| 4908 | return GetPropertyAttribute(name) != ABSENT; |
| 4909 | } |
| 4910 | |
| 4911 | |
| 4912 | bool JSReceiver::HasLocalProperty(String* name) { |
| 4913 | if (IsJSProxy()) { |
| 4914 | return JSProxy::cast(this)->HasPropertyWithHandler(name); |
| 4915 | } |
| 4916 | return GetLocalPropertyAttribute(name) != ABSENT; |
| 4917 | } |
| 4918 | |
| 4919 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4920 | PropertyAttributes JSReceiver::GetPropertyAttribute(String* key) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4921 | return GetPropertyAttributeWithReceiver(this, key); |
| 4922 | } |
| 4923 | |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4924 | // TODO(504): this may be useful in other places too where JSGlobalProxy |
| 4925 | // is used. |
| 4926 | Object* JSObject::BypassGlobalProxy() { |
| 4927 | if (IsJSGlobalProxy()) { |
| 4928 | Object* proto = GetPrototype(); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4929 | if (proto->IsNull()) return GetHeap()->undefined_value(); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4930 | ASSERT(proto->IsJSGlobalObject()); |
| 4931 | return proto; |
| 4932 | } |
| 4933 | return this; |
| 4934 | } |
| 4935 | |
| 4936 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4937 | MaybeObject* JSReceiver::GetIdentityHash(CreationFlag flag) { |
| 4938 | return IsJSProxy() |
| 4939 | ? JSProxy::cast(this)->GetIdentityHash(flag) |
| 4940 | : JSObject::cast(this)->GetIdentityHash(flag); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 4941 | } |
| 4942 | |
| 4943 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4944 | bool JSReceiver::HasElement(uint32_t index) { |
| 4945 | if (IsJSProxy()) { |
| 4946 | return JSProxy::cast(this)->HasElementWithHandler(index); |
| 4947 | } |
| 4948 | return JSObject::cast(this)->HasElementWithReceiver(this, index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4949 | } |
| 4950 | |
| 4951 | |
| 4952 | bool AccessorInfo::all_can_read() { |
| 4953 | return BooleanBit::get(flag(), kAllCanReadBit); |
| 4954 | } |
| 4955 | |
| 4956 | |
| 4957 | void AccessorInfo::set_all_can_read(bool value) { |
| 4958 | set_flag(BooleanBit::set(flag(), kAllCanReadBit, value)); |
| 4959 | } |
| 4960 | |
| 4961 | |
| 4962 | bool AccessorInfo::all_can_write() { |
| 4963 | return BooleanBit::get(flag(), kAllCanWriteBit); |
| 4964 | } |
| 4965 | |
| 4966 | |
| 4967 | void AccessorInfo::set_all_can_write(bool value) { |
| 4968 | set_flag(BooleanBit::set(flag(), kAllCanWriteBit, value)); |
| 4969 | } |
| 4970 | |
| 4971 | |
ager@chromium.org | 870a0b6 | 2008-11-04 11:43:05 +0000 | [diff] [blame] | 4972 | bool AccessorInfo::prohibits_overwriting() { |
| 4973 | return BooleanBit::get(flag(), kProhibitsOverwritingBit); |
| 4974 | } |
| 4975 | |
| 4976 | |
| 4977 | void AccessorInfo::set_prohibits_overwriting(bool value) { |
| 4978 | set_flag(BooleanBit::set(flag(), kProhibitsOverwritingBit, value)); |
| 4979 | } |
| 4980 | |
| 4981 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4982 | PropertyAttributes AccessorInfo::property_attributes() { |
| 4983 | return AttributesField::decode(static_cast<uint32_t>(flag()->value())); |
| 4984 | } |
| 4985 | |
| 4986 | |
| 4987 | void AccessorInfo::set_property_attributes(PropertyAttributes attributes) { |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4988 | set_flag(Smi::FromInt(AttributesField::update(flag()->value(), attributes))); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 4989 | } |
| 4990 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4991 | |
mmassi@chromium.org | 7028c05 | 2012-06-13 11:51:58 +0000 | [diff] [blame] | 4992 | bool AccessorInfo::IsCompatibleReceiver(Object* receiver) { |
| 4993 | Object* function_template = expected_receiver_type(); |
| 4994 | if (!function_template->IsFunctionTemplateInfo()) return true; |
| 4995 | return receiver->IsInstanceOf(FunctionTemplateInfo::cast(function_template)); |
| 4996 | } |
| 4997 | |
| 4998 | |
karlklose@chromium.org | 44bc708 | 2011-04-11 12:33:05 +0000 | [diff] [blame] | 4999 | template<typename Shape, typename Key> |
| 5000 | void Dictionary<Shape, Key>::SetEntry(int entry, |
| 5001 | Object* key, |
| 5002 | Object* value) { |
| 5003 | SetEntry(entry, key, value, PropertyDetails(Smi::FromInt(0))); |
| 5004 | } |
| 5005 | |
| 5006 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5007 | template<typename Shape, typename Key> |
| 5008 | void Dictionary<Shape, Key>::SetEntry(int entry, |
| 5009 | Object* key, |
| 5010 | Object* value, |
| 5011 | PropertyDetails details) { |
kasperl@chromium.org | defbd10 | 2009-07-13 14:04:26 +0000 | [diff] [blame] | 5012 | ASSERT(!key->IsString() || details.IsDeleted() || details.index() > 0); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5013 | int index = HashTable<Shape, Key>::EntryToIndex(entry); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5014 | AssertNoAllocation no_gc; |
| 5015 | WriteBarrierMode mode = FixedArray::GetWriteBarrierMode(no_gc); |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 5016 | FixedArray::set(index, key, mode); |
| 5017 | FixedArray::set(index+1, value, mode); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5018 | FixedArray::set(index+2, details.AsSmi()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5019 | } |
| 5020 | |
| 5021 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5022 | bool NumberDictionaryShape::IsMatch(uint32_t key, Object* other) { |
| 5023 | ASSERT(other->IsNumber()); |
| 5024 | return key == static_cast<uint32_t>(other->Number()); |
| 5025 | } |
| 5026 | |
| 5027 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5028 | uint32_t UnseededNumberDictionaryShape::Hash(uint32_t key) { |
| 5029 | return ComputeIntegerHash(key, 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5030 | } |
| 5031 | |
| 5032 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5033 | uint32_t UnseededNumberDictionaryShape::HashForObject(uint32_t key, |
| 5034 | Object* other) { |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5035 | ASSERT(other->IsNumber()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5036 | return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), 0); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5037 | } |
| 5038 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5039 | uint32_t SeededNumberDictionaryShape::SeededHash(uint32_t key, uint32_t seed) { |
| 5040 | return ComputeIntegerHash(key, seed); |
| 5041 | } |
| 5042 | |
| 5043 | uint32_t SeededNumberDictionaryShape::SeededHashForObject(uint32_t key, |
| 5044 | uint32_t seed, |
| 5045 | Object* other) { |
| 5046 | ASSERT(other->IsNumber()); |
| 5047 | return ComputeIntegerHash(static_cast<uint32_t>(other->Number()), seed); |
| 5048 | } |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5049 | |
| 5050 | MaybeObject* NumberDictionaryShape::AsObject(uint32_t key) { |
| 5051 | return Isolate::Current()->heap()->NumberFromUint32(key); |
| 5052 | } |
| 5053 | |
| 5054 | |
| 5055 | bool StringDictionaryShape::IsMatch(String* key, Object* other) { |
| 5056 | // We know that all entries in a hash table had their hash keys created. |
| 5057 | // Use that knowledge to have fast failure. |
| 5058 | if (key->Hash() != String::cast(other)->Hash()) return false; |
| 5059 | return key->Equals(String::cast(other)); |
| 5060 | } |
| 5061 | |
| 5062 | |
| 5063 | uint32_t StringDictionaryShape::Hash(String* key) { |
| 5064 | return key->Hash(); |
| 5065 | } |
| 5066 | |
| 5067 | |
| 5068 | uint32_t StringDictionaryShape::HashForObject(String* key, Object* other) { |
| 5069 | return String::cast(other)->Hash(); |
| 5070 | } |
| 5071 | |
| 5072 | |
| 5073 | MaybeObject* StringDictionaryShape::AsObject(String* key) { |
| 5074 | return key; |
| 5075 | } |
| 5076 | |
| 5077 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5078 | template <int entrysize> |
| 5079 | bool ObjectHashTableShape<entrysize>::IsMatch(Object* key, Object* other) { |
| 5080 | return key->SameValue(other); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 5081 | } |
| 5082 | |
| 5083 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5084 | template <int entrysize> |
| 5085 | uint32_t ObjectHashTableShape<entrysize>::Hash(Object* key) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5086 | MaybeObject* maybe_hash = key->GetHash(OMIT_CREATION); |
| 5087 | return Smi::cast(maybe_hash->ToObjectChecked())->value(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 5088 | } |
| 5089 | |
| 5090 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5091 | template <int entrysize> |
| 5092 | uint32_t ObjectHashTableShape<entrysize>::HashForObject(Object* key, |
| 5093 | Object* other) { |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5094 | MaybeObject* maybe_hash = other->GetHash(OMIT_CREATION); |
| 5095 | return Smi::cast(maybe_hash->ToObjectChecked())->value(); |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 5096 | } |
| 5097 | |
| 5098 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5099 | template <int entrysize> |
| 5100 | MaybeObject* ObjectHashTableShape<entrysize>::AsObject(Object* key) { |
vegorov@chromium.org | 7943d46 | 2011-08-01 11:41:52 +0000 | [diff] [blame] | 5101 | return key; |
| 5102 | } |
| 5103 | |
| 5104 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5105 | void Map::ClearCodeCache(Heap* heap) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5106 | // No write barrier is needed since empty_fixed_array is not in new space. |
| 5107 | // Please note this function is used during marking: |
| 5108 | // - MarkCompactCollector::MarkUnmarkedObject |
danno@chromium.org | 88aa058 | 2012-03-23 15:11:57 +0000 | [diff] [blame] | 5109 | // - IncrementalMarking::Step |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5110 | ASSERT(!heap->InNewSpace(heap->raw_unchecked_empty_fixed_array())); |
| 5111 | WRITE_FIELD(this, kCodeCacheOffset, heap->raw_unchecked_empty_fixed_array()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 5115 | void JSArray::EnsureSize(int required_size) { |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5116 | ASSERT(HasFastSmiOrObjectElements()); |
ricow@chromium.org | 30ce411 | 2010-05-31 10:38:25 +0000 | [diff] [blame] | 5117 | FixedArray* elts = FixedArray::cast(elements()); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5118 | const int kArraySizeThatFitsComfortablyInNewSpace = 128; |
| 5119 | if (elts->length() < required_size) { |
| 5120 | // Doubling in size would be overkill, but leave some slack to avoid |
| 5121 | // constantly growing. |
| 5122 | Expand(required_size + (required_size >> 3)); |
| 5123 | // It's a performance benefit to keep a frequently used array in new-space. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5124 | } else if (!GetHeap()->new_space()->Contains(elts) && |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 5125 | required_size < kArraySizeThatFitsComfortablyInNewSpace) { |
| 5126 | // Expand will allocate a new backing store in new space even if the size |
| 5127 | // we asked for isn't larger than what we had before. |
| 5128 | Expand(required_size); |
| 5129 | } |
ager@chromium.org | 5aa501c | 2009-06-23 07:57:28 +0000 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5133 | void JSArray::set_length(Smi* length) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5134 | // Don't need a write barrier for a Smi. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 5135 | set_length(static_cast<Object*>(length), SKIP_WRITE_BARRIER); |
| 5136 | } |
| 5137 | |
| 5138 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5139 | bool JSArray::AllowsSetElementsLength() { |
| 5140 | bool result = elements()->IsFixedArray() || elements()->IsFixedDoubleArray(); |
| 5141 | ASSERT(result == !HasExternalArrayElements()); |
| 5142 | return result; |
| 5143 | } |
| 5144 | |
| 5145 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5146 | MaybeObject* JSArray::SetContent(FixedArrayBase* storage) { |
| 5147 | MaybeObject* maybe_result = EnsureCanContainElements( |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5148 | storage, storage->length(), ALLOW_COPIED_DOUBLE_ELEMENTS); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5149 | if (maybe_result->IsFailure()) return maybe_result; |
| 5150 | ASSERT((storage->map() == GetHeap()->fixed_double_array_map() && |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5151 | IsFastDoubleElementsKind(GetElementsKind())) || |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5152 | ((storage->map() != GetHeap()->fixed_double_array_map()) && |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5153 | (IsFastObjectElementsKind(GetElementsKind()) || |
| 5154 | (IsFastSmiElementsKind(GetElementsKind()) && |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5155 | FixedArray::cast(storage)->ContainsOnlySmisOrHoles())))); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5156 | set_elements(storage); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5157 | set_length(Smi::FromInt(storage->length())); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5158 | return this; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | |
lrn@chromium.org | 303ada7 | 2010-10-27 09:33:13 +0000 | [diff] [blame] | 5162 | MaybeObject* FixedArray::Copy() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5163 | if (length() == 0) return this; |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5164 | return GetHeap()->CopyFixedArray(this); |
| 5165 | } |
| 5166 | |
| 5167 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5168 | MaybeObject* FixedDoubleArray::Copy() { |
| 5169 | if (length() == 0) return this; |
| 5170 | return GetHeap()->CopyFixedDoubleArray(this); |
| 5171 | } |
| 5172 | |
| 5173 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 5174 | void TypeFeedbackCells::SetAstId(int index, Smi* id) { |
| 5175 | set(1 + index * 2, id); |
| 5176 | } |
| 5177 | |
| 5178 | |
| 5179 | Smi* TypeFeedbackCells::AstId(int index) { |
| 5180 | return Smi::cast(get(1 + index * 2)); |
| 5181 | } |
| 5182 | |
| 5183 | |
| 5184 | void TypeFeedbackCells::SetCell(int index, JSGlobalPropertyCell* cell) { |
| 5185 | set(index * 2, cell); |
| 5186 | } |
| 5187 | |
| 5188 | |
| 5189 | JSGlobalPropertyCell* TypeFeedbackCells::Cell(int index) { |
| 5190 | return JSGlobalPropertyCell::cast(get(index * 2)); |
| 5191 | } |
| 5192 | |
| 5193 | |
| 5194 | Handle<Object> TypeFeedbackCells::UninitializedSentinel(Isolate* isolate) { |
| 5195 | return isolate->factory()->the_hole_value(); |
| 5196 | } |
| 5197 | |
| 5198 | |
| 5199 | Handle<Object> TypeFeedbackCells::MegamorphicSentinel(Isolate* isolate) { |
| 5200 | return isolate->factory()->undefined_value(); |
| 5201 | } |
| 5202 | |
| 5203 | |
| 5204 | Object* TypeFeedbackCells::RawUninitializedSentinel(Heap* heap) { |
| 5205 | return heap->raw_unchecked_the_hole_value(); |
| 5206 | } |
| 5207 | |
| 5208 | |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 5209 | SMI_ACCESSORS(TypeFeedbackInfo, ic_total_count, kIcTotalCountOffset) |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 5210 | SMI_ACCESSORS(TypeFeedbackInfo, ic_with_type_info_count, |
jkummerow@chromium.org | f7a5884 | 2012-02-21 10:08:21 +0000 | [diff] [blame] | 5211 | kIcWithTypeinfoCountOffset) |
| 5212 | ACCESSORS(TypeFeedbackInfo, type_feedback_cells, TypeFeedbackCells, |
| 5213 | kTypeFeedbackCellsOffset) |
| 5214 | |
| 5215 | |
yangguo@chromium.org | ab30bb8 | 2012-02-24 14:41:46 +0000 | [diff] [blame] | 5216 | SMI_ACCESSORS(AliasedArgumentsEntry, aliased_context_slot, kAliasedContextSlot) |
| 5217 | |
| 5218 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5219 | Relocatable::Relocatable(Isolate* isolate) { |
| 5220 | ASSERT(isolate == Isolate::Current()); |
| 5221 | isolate_ = isolate; |
| 5222 | prev_ = isolate->relocatable_top(); |
| 5223 | isolate->set_relocatable_top(this); |
| 5224 | } |
| 5225 | |
| 5226 | |
| 5227 | Relocatable::~Relocatable() { |
| 5228 | ASSERT(isolate_ == Isolate::Current()); |
| 5229 | ASSERT_EQ(isolate_->relocatable_top(), this); |
| 5230 | isolate_->set_relocatable_top(prev_); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5231 | } |
| 5232 | |
| 5233 | |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5234 | int JSObject::BodyDescriptor::SizeOf(Map* map, HeapObject* object) { |
| 5235 | return map->instance_size(); |
| 5236 | } |
| 5237 | |
| 5238 | |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5239 | void Foreign::ForeignIterateBody(ObjectVisitor* v) { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5240 | v->VisitExternalReference( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5241 | reinterpret_cast<Address*>(FIELD_ADDR(this, kForeignAddressOffset))); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5242 | } |
| 5243 | |
| 5244 | |
| 5245 | template<typename StaticVisitor> |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 5246 | void Foreign::ForeignIterateBody() { |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5247 | StaticVisitor::VisitExternalReference( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5248 | reinterpret_cast<Address*>(FIELD_ADDR(this, kForeignAddressOffset))); |
ager@chromium.org | ea4f62e | 2010-08-16 16:28:43 +0000 | [diff] [blame] | 5249 | } |
| 5250 | |
| 5251 | |
| 5252 | void ExternalAsciiString::ExternalAsciiStringIterateBody(ObjectVisitor* v) { |
| 5253 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 5254 | v->VisitExternalAsciiString( |
| 5255 | reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
| 5256 | } |
| 5257 | |
| 5258 | |
| 5259 | template<typename StaticVisitor> |
| 5260 | void ExternalAsciiString::ExternalAsciiStringIterateBody() { |
| 5261 | typedef v8::String::ExternalAsciiStringResource Resource; |
| 5262 | StaticVisitor::VisitExternalAsciiString( |
| 5263 | reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
| 5264 | } |
| 5265 | |
| 5266 | |
| 5267 | void ExternalTwoByteString::ExternalTwoByteStringIterateBody(ObjectVisitor* v) { |
| 5268 | typedef v8::String::ExternalStringResource Resource; |
| 5269 | v->VisitExternalTwoByteString( |
| 5270 | reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
| 5271 | } |
| 5272 | |
| 5273 | |
| 5274 | template<typename StaticVisitor> |
| 5275 | void ExternalTwoByteString::ExternalTwoByteStringIterateBody() { |
| 5276 | typedef v8::String::ExternalStringResource Resource; |
| 5277 | StaticVisitor::VisitExternalTwoByteString( |
| 5278 | reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset))); |
| 5279 | } |
| 5280 | |
| 5281 | #define SLOT_ADDR(obj, offset) \ |
| 5282 | reinterpret_cast<Object**>((obj)->address() + offset) |
| 5283 | |
| 5284 | template<int start_offset, int end_offset, int size> |
| 5285 | void FixedBodyDescriptor<start_offset, end_offset, size>::IterateBody( |
| 5286 | HeapObject* obj, |
| 5287 | ObjectVisitor* v) { |
| 5288 | v->VisitPointers(SLOT_ADDR(obj, start_offset), SLOT_ADDR(obj, end_offset)); |
| 5289 | } |
| 5290 | |
| 5291 | |
| 5292 | template<int start_offset> |
| 5293 | void FlexibleBodyDescriptor<start_offset>::IterateBody(HeapObject* obj, |
| 5294 | int object_size, |
| 5295 | ObjectVisitor* v) { |
| 5296 | v->VisitPointers(SLOT_ADDR(obj, start_offset), SLOT_ADDR(obj, object_size)); |
| 5297 | } |
| 5298 | |
| 5299 | #undef SLOT_ADDR |
| 5300 | |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 5301 | #undef TYPE_CHECKER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5302 | #undef CAST_ACCESSOR |
| 5303 | #undef INT_ACCESSORS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5304 | #undef ACCESSORS |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 5305 | #undef ACCESSORS_TO_SMI |
| 5306 | #undef SMI_ACCESSORS |
| 5307 | #undef BOOL_GETTER |
| 5308 | #undef BOOL_ACCESSORS |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5309 | #undef FIELD_ADDR |
| 5310 | #undef READ_FIELD |
| 5311 | #undef WRITE_FIELD |
| 5312 | #undef WRITE_BARRIER |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 5313 | #undef CONDITIONAL_WRITE_BARRIER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5314 | #undef READ_DOUBLE_FIELD |
| 5315 | #undef WRITE_DOUBLE_FIELD |
| 5316 | #undef READ_INT_FIELD |
| 5317 | #undef WRITE_INT_FIELD |
rossberg@chromium.org | 2c067b1 | 2012-03-19 11:01:52 +0000 | [diff] [blame] | 5318 | #undef READ_INTPTR_FIELD |
| 5319 | #undef WRITE_INTPTR_FIELD |
| 5320 | #undef READ_UINT32_FIELD |
| 5321 | #undef WRITE_UINT32_FIELD |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 5322 | #undef READ_SHORT_FIELD |
| 5323 | #undef WRITE_SHORT_FIELD |
| 5324 | #undef READ_BYTE_FIELD |
| 5325 | #undef WRITE_BYTE_FIELD |
| 5326 | |
| 5327 | |
| 5328 | } } // namespace v8::internal |
| 5329 | |
| 5330 | #endif // V8_OBJECTS_INL_H_ |