ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 1 | // Copyright 2006-2008 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 | // |
| 30 | // - The use of macros in these inline fuctions may seem superfluous |
| 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 | |
| 38 | #include "objects.h" |
| 39 | #include "contexts.h" |
| 40 | #include "conversions-inl.h" |
| 41 | #include "property.h" |
| 42 | |
| 43 | namespace v8 { namespace internal { |
| 44 | |
| 45 | PropertyDetails::PropertyDetails(Smi* smi) { |
| 46 | value_ = smi->value(); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | Smi* PropertyDetails::AsSmi() { |
| 51 | return Smi::FromInt(value_); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | #define CAST_ACCESSOR(type) \ |
| 56 | type* type::cast(Object* object) { \ |
| 57 | ASSERT(object->Is##type()); \ |
| 58 | return reinterpret_cast<type*>(object); \ |
| 59 | } |
| 60 | |
| 61 | |
| 62 | #define INT_ACCESSORS(holder, name, offset) \ |
| 63 | int holder::name() { return READ_INT_FIELD(this, offset); } \ |
| 64 | void holder::set_##name(int value) { WRITE_INT_FIELD(this, offset, value); } |
| 65 | |
| 66 | |
| 67 | #define ACCESSORS(holder, name, type, offset) \ |
| 68 | type* holder::name() { return type::cast(READ_FIELD(this, offset)); } \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 69 | void holder::set_##name(type* value, WriteBarrierMode mode) { \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 70 | WRITE_FIELD(this, offset, value); \ |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 71 | CONDITIONAL_WRITE_BARRIER(this, offset, mode); \ |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 75 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | #define SMI_ACCESSORS(holder, name, offset) \ |
| 77 | int holder::name() { \ |
| 78 | Object* value = READ_FIELD(this, offset); \ |
| 79 | return Smi::cast(value)->value(); \ |
| 80 | } \ |
| 81 | void holder::set_##name(int value) { \ |
| 82 | WRITE_FIELD(this, offset, Smi::FromInt(value)); \ |
| 83 | } |
| 84 | |
| 85 | |
| 86 | #define BOOL_ACCESSORS(holder, field, name, offset) \ |
| 87 | bool holder::name() { \ |
| 88 | return BooleanBit::get(field(), offset); \ |
| 89 | } \ |
| 90 | void holder::set_##name(bool value) { \ |
| 91 | set_##field(BooleanBit::set(field(), offset, value)); \ |
| 92 | } |
| 93 | |
| 94 | |
| 95 | bool Object::IsSmi() { |
| 96 | return HAS_SMI_TAG(this); |
| 97 | } |
| 98 | |
| 99 | |
| 100 | bool Object::IsHeapObject() { |
| 101 | return HAS_HEAP_OBJECT_TAG(this); |
| 102 | } |
| 103 | |
| 104 | |
| 105 | bool Object::IsHeapNumber() { |
| 106 | return Object::IsHeapObject() |
| 107 | && HeapObject::cast(this)->map()->instance_type() == HEAP_NUMBER_TYPE; |
| 108 | } |
| 109 | |
| 110 | |
| 111 | bool Object::IsString() { |
| 112 | return Object::IsHeapObject() |
| 113 | && HeapObject::cast(this)->map()->instance_type() < FIRST_NONSTRING_TYPE; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | bool Object::IsSeqString() { |
| 118 | return IsString() |
| 119 | && (String::cast(this)->representation_tag() == kSeqStringTag); |
| 120 | } |
| 121 | |
| 122 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 123 | bool Object::IsSeqAsciiString() { |
| 124 | return IsSeqString() |
| 125 | && String::cast(this)->IsAsciiRepresentation(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 129 | bool String::IsSeqAsciiString() { |
| 130 | return (this->representation_tag() == kSeqStringTag) |
| 131 | && is_ascii_representation(); |
| 132 | } |
| 133 | |
| 134 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 135 | bool Object::IsSeqTwoByteString() { |
| 136 | return IsSeqString() |
| 137 | && !String::cast(this)->IsAsciiRepresentation(); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | bool Object::IsAsciiStringRepresentation() { |
| 142 | return IsString() && (String::cast(this)->is_ascii_representation()); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | bool Object::IsTwoByteStringRepresentation() { |
| 147 | return IsString() && (!String::cast(this)->is_ascii_representation()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | |
| 151 | bool Object::IsConsString() { |
| 152 | return IsString() |
| 153 | && (String::cast(this)->representation_tag() == kConsStringTag); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | bool Object::IsSlicedString() { |
| 158 | return IsString() |
| 159 | && (String::cast(this)->representation_tag() == kSlicedStringTag); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | bool Object::IsExternalString() { |
| 164 | return IsString() |
| 165 | && (String::cast(this)->representation_tag() == kExternalStringTag); |
| 166 | } |
| 167 | |
| 168 | |
| 169 | bool Object::IsExternalAsciiString() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 170 | return IsExternalString() && (String::cast(this)->is_ascii_representation()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | |
| 174 | bool Object::IsExternalTwoByteString() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 175 | return IsExternalString() && (!String::cast(this)->is_ascii_representation()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | |
| 179 | bool Object::IsShortString() { |
| 180 | return IsString() && (String::cast(this)->size_tag() == kShortStringTag); |
| 181 | } |
| 182 | |
| 183 | |
| 184 | bool Object::IsMediumString() { |
| 185 | return IsString() && (String::cast(this)->size_tag() == kMediumStringTag); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | bool Object::IsLongString() { |
| 190 | return IsString() && (String::cast(this)->size_tag() == kLongStringTag); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | bool Object::IsSymbol() { |
| 195 | return IsString() && (String::cast(this)->is_symbol()); |
| 196 | } |
| 197 | |
| 198 | |
| 199 | bool Object::IsNumber() { |
| 200 | return IsSmi() || IsHeapNumber(); |
| 201 | } |
| 202 | |
| 203 | |
| 204 | bool Object::IsByteArray() { |
| 205 | return Object::IsHeapObject() |
| 206 | && HeapObject::cast(this)->map()->instance_type() == BYTE_ARRAY_TYPE; |
| 207 | } |
| 208 | |
| 209 | |
| 210 | bool Object::IsFailure() { |
| 211 | return HAS_FAILURE_TAG(this); |
| 212 | } |
| 213 | |
| 214 | |
| 215 | bool Object::IsRetryAfterGC() { |
| 216 | return HAS_FAILURE_TAG(this) |
| 217 | && Failure::cast(this)->type() == Failure::RETRY_AFTER_GC; |
| 218 | } |
| 219 | |
| 220 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 221 | bool Object::IsOutOfMemoryFailure() { |
| 222 | return HAS_FAILURE_TAG(this) |
| 223 | && Failure::cast(this)->IsOutOfMemoryException(); |
| 224 | } |
| 225 | |
| 226 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 227 | bool Object::IsException() { |
| 228 | return this == Failure::Exception(); |
| 229 | } |
| 230 | |
| 231 | |
| 232 | bool Object::IsJSObject() { |
| 233 | return IsHeapObject() |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 234 | && HeapObject::cast(this)->map()->instance_type() >= FIRST_JS_OBJECT_TYPE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
| 238 | bool Object::IsMap() { |
| 239 | return Object::IsHeapObject() |
| 240 | && HeapObject::cast(this)->map()->instance_type() == MAP_TYPE; |
| 241 | } |
| 242 | |
| 243 | |
| 244 | bool Object::IsFixedArray() { |
| 245 | return Object::IsHeapObject() |
| 246 | && HeapObject::cast(this)->map()->instance_type() == FIXED_ARRAY_TYPE; |
| 247 | } |
| 248 | |
| 249 | |
| 250 | bool Object::IsDescriptorArray() { |
| 251 | return IsFixedArray(); |
| 252 | } |
| 253 | |
| 254 | |
| 255 | bool Object::IsContext() { |
| 256 | return Object::IsHeapObject() |
| 257 | && (HeapObject::cast(this)->map() == Heap::context_map() || |
| 258 | HeapObject::cast(this)->map() == Heap::global_context_map()); |
| 259 | } |
| 260 | |
| 261 | |
| 262 | bool Object::IsGlobalContext() { |
| 263 | return Object::IsHeapObject() |
| 264 | && HeapObject::cast(this)->map() == Heap::global_context_map(); |
| 265 | } |
| 266 | |
| 267 | |
| 268 | bool Object::IsJSFunction() { |
| 269 | return Object::IsHeapObject() |
| 270 | && HeapObject::cast(this)->map()->instance_type() == JS_FUNCTION_TYPE; |
| 271 | } |
| 272 | |
| 273 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 274 | template <> inline bool Is<JSFunction>(Object* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 275 | return obj->IsJSFunction(); |
| 276 | } |
| 277 | |
| 278 | |
| 279 | bool Object::IsCode() { |
| 280 | return Object::IsHeapObject() |
| 281 | && HeapObject::cast(this)->map()->instance_type() == CODE_TYPE; |
| 282 | } |
| 283 | |
| 284 | |
| 285 | bool Object::IsOddball() { |
| 286 | return Object::IsHeapObject() |
| 287 | && HeapObject::cast(this)->map()->instance_type() == ODDBALL_TYPE; |
| 288 | } |
| 289 | |
| 290 | |
| 291 | bool Object::IsSharedFunctionInfo() { |
| 292 | return Object::IsHeapObject() && |
| 293 | (HeapObject::cast(this)->map()->instance_type() == |
| 294 | SHARED_FUNCTION_INFO_TYPE); |
| 295 | } |
| 296 | |
| 297 | |
| 298 | bool Object::IsJSValue() { |
| 299 | return Object::IsHeapObject() |
| 300 | && HeapObject::cast(this)->map()->instance_type() == JS_VALUE_TYPE; |
| 301 | } |
| 302 | |
| 303 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 304 | bool Object::IsStringWrapper() { |
| 305 | return IsJSValue() && JSValue::cast(this)->value()->IsString(); |
| 306 | } |
| 307 | |
| 308 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 309 | bool Object::IsProxy() { |
| 310 | return Object::IsHeapObject() |
| 311 | && HeapObject::cast(this)->map()->instance_type() == PROXY_TYPE; |
| 312 | } |
| 313 | |
| 314 | |
| 315 | bool Object::IsBoolean() { |
| 316 | return IsTrue() || IsFalse(); |
| 317 | } |
| 318 | |
| 319 | |
| 320 | bool Object::IsJSArray() { |
| 321 | return Object::IsHeapObject() |
| 322 | && HeapObject::cast(this)->map()->instance_type() == JS_ARRAY_TYPE; |
| 323 | } |
| 324 | |
| 325 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 326 | bool Object::IsJSRegExp() { |
| 327 | return Object::IsHeapObject() |
| 328 | && HeapObject::cast(this)->map()->instance_type() == JS_REGEXP_TYPE; |
| 329 | } |
| 330 | |
| 331 | |
ager@chromium.org | c27e4e7 | 2008-09-04 13:52:27 +0000 | [diff] [blame] | 332 | template <> inline bool Is<JSArray>(Object* obj) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 333 | return obj->IsJSArray(); |
| 334 | } |
| 335 | |
| 336 | |
| 337 | bool Object::IsHashTable() { |
| 338 | return Object::IsHeapObject() |
| 339 | && HeapObject::cast(this)->map() == Heap::hash_table_map(); |
| 340 | } |
| 341 | |
| 342 | |
| 343 | bool Object::IsDictionary() { |
| 344 | return IsHashTable() && this != Heap::symbol_table(); |
| 345 | } |
| 346 | |
| 347 | |
| 348 | bool Object::IsSymbolTable() { |
| 349 | return IsHashTable() && this == Heap::symbol_table(); |
| 350 | } |
| 351 | |
| 352 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 353 | bool Object::IsCompilationCacheTable() { |
| 354 | return IsHashTable(); |
ager@chromium.org | 9258b6b | 2008-09-11 09:11:10 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 358 | bool Object::IsMapCache() { |
| 359 | return IsHashTable(); |
| 360 | } |
| 361 | |
| 362 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 363 | bool Object::IsLookupCache() { |
| 364 | return IsHashTable(); |
| 365 | } |
| 366 | |
| 367 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 368 | bool Object::IsPrimitive() { |
| 369 | return IsOddball() || IsNumber() || IsString(); |
| 370 | } |
| 371 | |
| 372 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 373 | bool Object::IsJSGlobalProxy() { |
| 374 | bool result = IsHeapObject() && |
| 375 | (HeapObject::cast(this)->map()->instance_type() == |
| 376 | JS_GLOBAL_PROXY_TYPE); |
| 377 | ASSERT(!result || IsAccessCheckNeeded()); |
| 378 | return result; |
| 379 | } |
| 380 | |
| 381 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 382 | bool Object::IsGlobalObject() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 383 | if (!IsHeapObject()) return false; |
| 384 | |
| 385 | InstanceType type = HeapObject::cast(this)->map()->instance_type(); |
| 386 | return type == JS_GLOBAL_OBJECT_TYPE || |
| 387 | type == JS_BUILTINS_OBJECT_TYPE; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | |
| 391 | bool Object::IsJSGlobalObject() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 392 | return IsHeapObject() && |
| 393 | (HeapObject::cast(this)->map()->instance_type() == |
| 394 | JS_GLOBAL_OBJECT_TYPE); |
| 395 | } |
| 396 | |
| 397 | |
| 398 | bool Object::IsJSBuiltinsObject() { |
| 399 | return IsHeapObject() && |
| 400 | (HeapObject::cast(this)->map()->instance_type() == |
| 401 | JS_BUILTINS_OBJECT_TYPE); |
| 402 | } |
| 403 | |
| 404 | |
| 405 | bool Object::IsUndetectableObject() { |
| 406 | return IsHeapObject() |
| 407 | && HeapObject::cast(this)->map()->is_undetectable(); |
| 408 | } |
| 409 | |
| 410 | |
| 411 | bool Object::IsAccessCheckNeeded() { |
| 412 | return IsHeapObject() |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 413 | && HeapObject::cast(this)->map()->is_access_check_needed(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | |
| 417 | bool Object::IsStruct() { |
| 418 | if (!IsHeapObject()) return false; |
| 419 | switch (HeapObject::cast(this)->map()->instance_type()) { |
| 420 | #define MAKE_STRUCT_CASE(NAME, Name, name) case NAME##_TYPE: return true; |
| 421 | STRUCT_LIST(MAKE_STRUCT_CASE) |
| 422 | #undef MAKE_STRUCT_CASE |
| 423 | default: return false; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | |
| 428 | #define MAKE_STRUCT_PREDICATE(NAME, Name, name) \ |
| 429 | bool Object::Is##Name() { \ |
| 430 | return Object::IsHeapObject() \ |
| 431 | && HeapObject::cast(this)->map()->instance_type() == NAME##_TYPE; \ |
| 432 | } |
| 433 | STRUCT_LIST(MAKE_STRUCT_PREDICATE) |
| 434 | #undef MAKE_STRUCT_PREDICATE |
| 435 | |
| 436 | |
| 437 | bool Object::IsUndefined() { |
| 438 | return this == Heap::undefined_value(); |
| 439 | } |
| 440 | |
| 441 | |
| 442 | bool Object::IsTheHole() { |
| 443 | return this == Heap::the_hole_value(); |
| 444 | } |
| 445 | |
| 446 | |
| 447 | bool Object::IsNull() { |
| 448 | return this == Heap::null_value(); |
| 449 | } |
| 450 | |
| 451 | |
| 452 | bool Object::IsTrue() { |
| 453 | return this == Heap::true_value(); |
| 454 | } |
| 455 | |
| 456 | |
| 457 | bool Object::IsFalse() { |
| 458 | return this == Heap::false_value(); |
| 459 | } |
| 460 | |
| 461 | |
| 462 | double Object::Number() { |
| 463 | ASSERT(IsNumber()); |
| 464 | return IsSmi() |
| 465 | ? static_cast<double>(reinterpret_cast<Smi*>(this)->value()) |
| 466 | : reinterpret_cast<HeapNumber*>(this)->value(); |
| 467 | } |
| 468 | |
| 469 | |
| 470 | |
| 471 | Object* Object::ToSmi() { |
| 472 | if (IsSmi()) return this; |
| 473 | if (IsHeapNumber()) { |
| 474 | double value = HeapNumber::cast(this)->value(); |
| 475 | int int_value = FastD2I(value); |
| 476 | if (value == FastI2D(int_value) && Smi::IsValid(int_value)) { |
| 477 | return Smi::FromInt(int_value); |
| 478 | } |
| 479 | } |
| 480 | return Failure::Exception(); |
| 481 | } |
| 482 | |
| 483 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 484 | bool Object::HasSpecificClassOf(String* name) { |
| 485 | return this->IsJSObject() && (JSObject::cast(this)->class_name() == name); |
| 486 | } |
| 487 | |
| 488 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 489 | Object* Object::GetElement(uint32_t index) { |
| 490 | return GetElementWithReceiver(this, index); |
| 491 | } |
| 492 | |
| 493 | |
| 494 | Object* Object::GetProperty(String* key) { |
| 495 | PropertyAttributes attributes; |
| 496 | return GetPropertyWithReceiver(this, key, &attributes); |
| 497 | } |
| 498 | |
| 499 | |
| 500 | Object* Object::GetProperty(String* key, PropertyAttributes* attributes) { |
| 501 | return GetPropertyWithReceiver(this, key, attributes); |
| 502 | } |
| 503 | |
| 504 | |
| 505 | #define FIELD_ADDR(p, offset) \ |
| 506 | (reinterpret_cast<byte*>(p) + offset - kHeapObjectTag) |
| 507 | |
| 508 | #define READ_FIELD(p, offset) \ |
| 509 | (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset))) |
| 510 | |
| 511 | #define WRITE_FIELD(p, offset, value) \ |
| 512 | (*reinterpret_cast<Object**>(FIELD_ADDR(p, offset)) = value) |
| 513 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 514 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 515 | #define WRITE_BARRIER(object, offset) \ |
| 516 | Heap::RecordWrite(object->address(), offset); |
| 517 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 518 | // CONDITIONAL_WRITE_BARRIER must be issued after the actual |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 519 | // write due to the assert validating the written value. |
| 520 | #define CONDITIONAL_WRITE_BARRIER(object, offset, mode) \ |
| 521 | if (mode == UPDATE_WRITE_BARRIER) { \ |
| 522 | Heap::RecordWrite(object->address(), offset); \ |
| 523 | } else { \ |
| 524 | ASSERT(mode == SKIP_WRITE_BARRIER); \ |
| 525 | ASSERT(Heap::InNewSpace(object) || \ |
| 526 | !Heap::InNewSpace(READ_FIELD(object, offset))); \ |
| 527 | } |
| 528 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 529 | #define READ_DOUBLE_FIELD(p, offset) \ |
| 530 | (*reinterpret_cast<double*>(FIELD_ADDR(p, offset))) |
| 531 | |
| 532 | #define WRITE_DOUBLE_FIELD(p, offset, value) \ |
| 533 | (*reinterpret_cast<double*>(FIELD_ADDR(p, offset)) = value) |
| 534 | |
| 535 | #define READ_INT_FIELD(p, offset) \ |
| 536 | (*reinterpret_cast<int*>(FIELD_ADDR(p, offset))) |
| 537 | |
| 538 | #define WRITE_INT_FIELD(p, offset, value) \ |
| 539 | (*reinterpret_cast<int*>(FIELD_ADDR(p, offset)) = value) |
| 540 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 541 | #define READ_UINT32_FIELD(p, offset) \ |
| 542 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset))) |
| 543 | |
| 544 | #define WRITE_UINT32_FIELD(p, offset, value) \ |
| 545 | (*reinterpret_cast<uint32_t*>(FIELD_ADDR(p, offset)) = value) |
| 546 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 547 | #define READ_SHORT_FIELD(p, offset) \ |
| 548 | (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset))) |
| 549 | |
| 550 | #define WRITE_SHORT_FIELD(p, offset, value) \ |
| 551 | (*reinterpret_cast<uint16_t*>(FIELD_ADDR(p, offset)) = value) |
| 552 | |
| 553 | #define READ_BYTE_FIELD(p, offset) \ |
| 554 | (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset))) |
| 555 | |
| 556 | #define WRITE_BYTE_FIELD(p, offset, value) \ |
| 557 | (*reinterpret_cast<byte*>(FIELD_ADDR(p, offset)) = value) |
| 558 | |
| 559 | |
| 560 | Object* HeapObject::GetHeapObjectField(HeapObject* obj, int index) { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 561 | return READ_FIELD(obj, HeapObject::kHeaderSize + kPointerSize * index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | |
| 565 | int Smi::value() { |
| 566 | return reinterpret_cast<int>(this) >> kSmiTagSize; |
| 567 | } |
| 568 | |
| 569 | |
| 570 | Smi* Smi::FromInt(int value) { |
| 571 | ASSERT(Smi::IsValid(value)); |
| 572 | return reinterpret_cast<Smi*>((value << kSmiTagSize) | kSmiTag); |
| 573 | } |
| 574 | |
| 575 | |
| 576 | Failure::Type Failure::type() const { |
| 577 | return static_cast<Type>(value() & kFailureTypeTagMask); |
| 578 | } |
| 579 | |
| 580 | |
| 581 | bool Failure::IsInternalError() const { |
| 582 | return type() == INTERNAL_ERROR; |
| 583 | } |
| 584 | |
| 585 | |
| 586 | bool Failure::IsOutOfMemoryException() const { |
| 587 | return type() == OUT_OF_MEMORY_EXCEPTION; |
| 588 | } |
| 589 | |
| 590 | |
| 591 | int Failure::requested() const { |
| 592 | const int kShiftBits = |
| 593 | kFailureTypeTagSize + kSpaceTagSize - kObjectAlignmentBits; |
| 594 | STATIC_ASSERT(kShiftBits >= 0); |
| 595 | ASSERT(type() == RETRY_AFTER_GC); |
| 596 | return value() >> kShiftBits; |
| 597 | } |
| 598 | |
| 599 | |
| 600 | AllocationSpace Failure::allocation_space() const { |
| 601 | ASSERT_EQ(RETRY_AFTER_GC, type()); |
| 602 | return static_cast<AllocationSpace>((value() >> kFailureTypeTagSize) |
| 603 | & kSpaceTagMask); |
| 604 | } |
| 605 | |
| 606 | |
| 607 | Failure* Failure::InternalError() { |
| 608 | return Construct(INTERNAL_ERROR); |
| 609 | } |
| 610 | |
| 611 | |
| 612 | Failure* Failure::Exception() { |
| 613 | return Construct(EXCEPTION); |
| 614 | } |
| 615 | |
| 616 | Failure* Failure::OutOfMemoryException() { |
| 617 | return Construct(OUT_OF_MEMORY_EXCEPTION); |
| 618 | } |
| 619 | |
| 620 | |
| 621 | int Failure::value() const { |
| 622 | return reinterpret_cast<int>(this) >> kFailureTagSize; |
| 623 | } |
| 624 | |
| 625 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 626 | Failure* Failure::RetryAfterGC(int requested_bytes) { |
| 627 | int requested = requested_bytes >> kObjectAlignmentBits; |
| 628 | int value = (requested << kSpaceTagSize) | NEW_SPACE; |
| 629 | ASSERT(value >> kSpaceTagSize == requested); |
| 630 | ASSERT(Smi::IsValid(value)); |
| 631 | ASSERT(value == ((value << kFailureTypeTagSize) >> kFailureTypeTagSize)); |
| 632 | ASSERT(Smi::IsValid(value << kFailureTypeTagSize)); |
| 633 | return Construct(RETRY_AFTER_GC, value); |
| 634 | } |
| 635 | |
| 636 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 637 | Failure* Failure::Construct(Type type, int value) { |
| 638 | int info = (value << kFailureTypeTagSize) | type; |
| 639 | ASSERT(Smi::IsValid(info)); // Same validation check as in Smi |
| 640 | return reinterpret_cast<Failure*>((info << kFailureTagSize) | kFailureTag); |
| 641 | } |
| 642 | |
| 643 | |
| 644 | bool Smi::IsValid(int value) { |
| 645 | #ifdef DEBUG |
| 646 | bool in_range = (value >= kMinValue) && (value <= kMaxValue); |
| 647 | #endif |
| 648 | // To be representable as an tagged small integer, the two |
| 649 | // most-significant bits of 'value' must be either 00 or 11 due to |
| 650 | // sign-extension. To check this we add 01 to the two |
| 651 | // most-significant bits, and check if the most-significant bit is 0 |
| 652 | // |
| 653 | // CAUTION: The original code below: |
| 654 | // bool result = ((value + 0x40000000) & 0x80000000) == 0; |
| 655 | // may lead to incorrect results according to the C language spec, and |
| 656 | // in fact doesn't work correctly with gcc4.1.1 in some cases: The |
| 657 | // compiler may produce undefined results in case of signed integer |
| 658 | // overflow. The computation must be done w/ unsigned ints. |
| 659 | bool result = |
| 660 | ((static_cast<unsigned int>(value) + 0x40000000U) & 0x80000000U) == 0; |
| 661 | ASSERT(result == in_range); |
| 662 | return result; |
| 663 | } |
| 664 | |
| 665 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 666 | MapWord MapWord::FromMap(Map* map) { |
| 667 | return MapWord(reinterpret_cast<uintptr_t>(map)); |
| 668 | } |
| 669 | |
| 670 | |
| 671 | Map* MapWord::ToMap() { |
| 672 | return reinterpret_cast<Map*>(value_); |
| 673 | } |
| 674 | |
| 675 | |
| 676 | bool MapWord::IsForwardingAddress() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 677 | return HAS_SMI_TAG(reinterpret_cast<Object*>(value_)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
| 681 | MapWord MapWord::FromForwardingAddress(HeapObject* object) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 682 | Address raw = reinterpret_cast<Address>(object) - kHeapObjectTag; |
| 683 | return MapWord(reinterpret_cast<uintptr_t>(raw)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | |
| 687 | HeapObject* MapWord::ToForwardingAddress() { |
| 688 | ASSERT(IsForwardingAddress()); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 689 | return HeapObject::FromAddress(reinterpret_cast<Address>(value_)); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | |
| 693 | bool MapWord::IsMarked() { |
| 694 | return (value_ & kMarkingMask) == 0; |
| 695 | } |
| 696 | |
| 697 | |
| 698 | void MapWord::SetMark() { |
| 699 | value_ &= ~kMarkingMask; |
| 700 | } |
| 701 | |
| 702 | |
| 703 | void MapWord::ClearMark() { |
| 704 | value_ |= kMarkingMask; |
| 705 | } |
| 706 | |
| 707 | |
| 708 | bool MapWord::IsOverflowed() { |
| 709 | return (value_ & kOverflowMask) != 0; |
| 710 | } |
| 711 | |
| 712 | |
| 713 | void MapWord::SetOverflow() { |
| 714 | value_ |= kOverflowMask; |
| 715 | } |
| 716 | |
| 717 | |
| 718 | void MapWord::ClearOverflow() { |
| 719 | value_ &= ~kOverflowMask; |
| 720 | } |
| 721 | |
| 722 | |
| 723 | MapWord MapWord::EncodeAddress(Address map_address, int offset) { |
| 724 | // Offset is the distance in live bytes from the first live object in the |
| 725 | // same page. The offset between two objects in the same page should not |
| 726 | // exceed the object area size of a page. |
| 727 | ASSERT(0 <= offset && offset < Page::kObjectAreaSize); |
| 728 | |
| 729 | int compact_offset = offset >> kObjectAlignmentBits; |
| 730 | ASSERT(compact_offset < (1 << kForwardingOffsetBits)); |
| 731 | |
| 732 | Page* map_page = Page::FromAddress(map_address); |
| 733 | ASSERT_MAP_PAGE_INDEX(map_page->mc_page_index); |
| 734 | |
| 735 | int map_page_offset = |
| 736 | map_page->Offset(map_address) >> kObjectAlignmentBits; |
| 737 | |
| 738 | uintptr_t encoding = |
| 739 | (compact_offset << kForwardingOffsetShift) | |
| 740 | (map_page_offset << kMapPageOffsetShift) | |
| 741 | (map_page->mc_page_index << kMapPageIndexShift); |
| 742 | return MapWord(encoding); |
| 743 | } |
| 744 | |
| 745 | |
| 746 | Address MapWord::DecodeMapAddress(MapSpace* map_space) { |
| 747 | int map_page_index = (value_ & kMapPageIndexMask) >> kMapPageIndexShift; |
| 748 | ASSERT_MAP_PAGE_INDEX(map_page_index); |
| 749 | |
| 750 | int map_page_offset = |
| 751 | ((value_ & kMapPageOffsetMask) >> kMapPageOffsetShift) |
| 752 | << kObjectAlignmentBits; |
| 753 | |
| 754 | return (map_space->PageAddress(map_page_index) + map_page_offset); |
| 755 | } |
| 756 | |
| 757 | |
| 758 | int MapWord::DecodeOffset() { |
| 759 | // The offset field is represented in the kForwardingOffsetBits |
| 760 | // most-significant bits. |
| 761 | int offset = (value_ >> kForwardingOffsetShift) << kObjectAlignmentBits; |
| 762 | ASSERT(0 <= offset && offset < Page::kObjectAreaSize); |
| 763 | return offset; |
| 764 | } |
| 765 | |
| 766 | |
| 767 | MapWord MapWord::FromEncodedAddress(Address address) { |
| 768 | return MapWord(reinterpret_cast<uintptr_t>(address)); |
| 769 | } |
| 770 | |
| 771 | |
| 772 | Address MapWord::ToEncodedAddress() { |
| 773 | return reinterpret_cast<Address>(value_); |
| 774 | } |
| 775 | |
| 776 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 777 | #ifdef DEBUG |
| 778 | void HeapObject::VerifyObjectField(int offset) { |
| 779 | VerifyPointer(READ_FIELD(this, offset)); |
| 780 | } |
| 781 | #endif |
| 782 | |
| 783 | |
| 784 | Map* HeapObject::map() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 785 | return map_word().ToMap(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | |
| 789 | void HeapObject::set_map(Map* value) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 790 | set_map_word(MapWord::FromMap(value)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 794 | MapWord HeapObject::map_word() { |
| 795 | return MapWord(reinterpret_cast<uintptr_t>(READ_FIELD(this, kMapOffset))); |
| 796 | } |
| 797 | |
| 798 | |
| 799 | void HeapObject::set_map_word(MapWord map_word) { |
| 800 | // WRITE_FIELD does not update the remembered set, but there is no need |
| 801 | // here. |
| 802 | WRITE_FIELD(this, kMapOffset, reinterpret_cast<Object*>(map_word.value_)); |
| 803 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 804 | |
| 805 | |
| 806 | HeapObject* HeapObject::FromAddress(Address address) { |
| 807 | ASSERT_TAG_ALIGNED(address); |
| 808 | return reinterpret_cast<HeapObject*>(address + kHeapObjectTag); |
| 809 | } |
| 810 | |
| 811 | |
| 812 | Address HeapObject::address() { |
| 813 | return reinterpret_cast<Address>(this) - kHeapObjectTag; |
| 814 | } |
| 815 | |
| 816 | |
| 817 | int HeapObject::Size() { |
| 818 | return SizeFromMap(map()); |
| 819 | } |
| 820 | |
| 821 | |
| 822 | void HeapObject::IteratePointers(ObjectVisitor* v, int start, int end) { |
| 823 | v->VisitPointers(reinterpret_cast<Object**>(FIELD_ADDR(this, start)), |
| 824 | reinterpret_cast<Object**>(FIELD_ADDR(this, end))); |
| 825 | } |
| 826 | |
| 827 | |
| 828 | void HeapObject::IteratePointer(ObjectVisitor* v, int offset) { |
| 829 | v->VisitPointer(reinterpret_cast<Object**>(FIELD_ADDR(this, offset))); |
| 830 | } |
| 831 | |
| 832 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 833 | bool HeapObject::IsMarked() { |
| 834 | return map_word().IsMarked(); |
| 835 | } |
| 836 | |
| 837 | |
| 838 | void HeapObject::SetMark() { |
| 839 | ASSERT(!IsMarked()); |
| 840 | MapWord first_word = map_word(); |
| 841 | first_word.SetMark(); |
| 842 | set_map_word(first_word); |
| 843 | } |
| 844 | |
| 845 | |
| 846 | void HeapObject::ClearMark() { |
| 847 | ASSERT(IsMarked()); |
| 848 | MapWord first_word = map_word(); |
| 849 | first_word.ClearMark(); |
| 850 | set_map_word(first_word); |
| 851 | } |
| 852 | |
| 853 | |
| 854 | bool HeapObject::IsOverflowed() { |
| 855 | return map_word().IsOverflowed(); |
| 856 | } |
| 857 | |
| 858 | |
| 859 | void HeapObject::SetOverflow() { |
| 860 | MapWord first_word = map_word(); |
| 861 | first_word.SetOverflow(); |
| 862 | set_map_word(first_word); |
| 863 | } |
| 864 | |
| 865 | |
| 866 | void HeapObject::ClearOverflow() { |
| 867 | ASSERT(IsOverflowed()); |
| 868 | MapWord first_word = map_word(); |
| 869 | first_word.ClearOverflow(); |
| 870 | set_map_word(first_word); |
| 871 | } |
| 872 | |
| 873 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 874 | double HeapNumber::value() { |
| 875 | return READ_DOUBLE_FIELD(this, kValueOffset); |
| 876 | } |
| 877 | |
| 878 | |
| 879 | void HeapNumber::set_value(double value) { |
| 880 | WRITE_DOUBLE_FIELD(this, kValueOffset, value); |
| 881 | } |
| 882 | |
| 883 | |
| 884 | ACCESSORS(JSObject, properties, FixedArray, kPropertiesOffset) |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 885 | ACCESSORS(JSObject, elements, FixedArray, kElementsOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 886 | |
| 887 | |
| 888 | void JSObject::initialize_properties() { |
| 889 | ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); |
| 890 | WRITE_FIELD(this, kPropertiesOffset, Heap::empty_fixed_array()); |
| 891 | } |
| 892 | |
| 893 | |
| 894 | void JSObject::initialize_elements() { |
| 895 | ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); |
| 896 | WRITE_FIELD(this, kElementsOffset, Heap::empty_fixed_array()); |
| 897 | } |
| 898 | |
| 899 | |
| 900 | ACCESSORS(Oddball, to_string, String, kToStringOffset) |
| 901 | ACCESSORS(Oddball, to_number, Object, kToNumberOffset) |
| 902 | |
| 903 | |
| 904 | int JSObject::GetHeaderSize() { |
| 905 | switch (map()->instance_type()) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 906 | case JS_GLOBAL_PROXY_TYPE: |
| 907 | return JSGlobalProxy::kSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 908 | case JS_GLOBAL_OBJECT_TYPE: |
| 909 | return JSGlobalObject::kSize; |
| 910 | case JS_BUILTINS_OBJECT_TYPE: |
| 911 | return JSBuiltinsObject::kSize; |
| 912 | case JS_FUNCTION_TYPE: |
| 913 | return JSFunction::kSize; |
| 914 | case JS_VALUE_TYPE: |
| 915 | return JSValue::kSize; |
| 916 | case JS_ARRAY_TYPE: |
| 917 | return JSValue::kSize; |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 918 | case JS_REGEXP_TYPE: |
| 919 | return JSValue::kSize; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 920 | case JS_OBJECT_TYPE: |
| 921 | return JSObject::kHeaderSize; |
| 922 | default: |
| 923 | UNREACHABLE(); |
| 924 | return 0; |
| 925 | } |
| 926 | } |
| 927 | |
| 928 | |
| 929 | int JSObject::GetInternalFieldCount() { |
| 930 | ASSERT(1 << kPointerSizeLog2 == kPointerSize); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 931 | // Make sure to adjust for the number of in-object properties. These |
| 932 | // properties do contribute to the size, but are not internal fields. |
| 933 | return ((Size() - GetHeaderSize()) >> kPointerSizeLog2) - |
| 934 | map()->inobject_properties(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | |
| 938 | Object* JSObject::GetInternalField(int index) { |
| 939 | ASSERT(index < GetInternalFieldCount() && index >= 0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 940 | // Internal objects do follow immediately after the header, whereas in-object |
| 941 | // properties are at the end of the object. Therefore there is no need |
| 942 | // to adjust the index here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 943 | return READ_FIELD(this, GetHeaderSize() + (kPointerSize * index)); |
| 944 | } |
| 945 | |
| 946 | |
| 947 | void JSObject::SetInternalField(int index, Object* value) { |
| 948 | ASSERT(index < GetInternalFieldCount() && index >= 0); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 949 | // Internal objects do follow immediately after the header, whereas in-object |
| 950 | // properties are at the end of the object. Therefore there is no need |
| 951 | // to adjust the index here. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 952 | int offset = GetHeaderSize() + (kPointerSize * index); |
| 953 | WRITE_FIELD(this, offset, value); |
| 954 | WRITE_BARRIER(this, offset); |
| 955 | } |
| 956 | |
| 957 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 958 | // Access fast-case object properties at index. The use of these routines |
| 959 | // is needed to correctly distinguish between properties stored in-object and |
| 960 | // properties stored in the properties array. |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 961 | Object* JSObject::FastPropertyAt(int index) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 962 | // Adjust for the number of properties stored in the object. |
| 963 | index -= map()->inobject_properties(); |
| 964 | if (index < 0) { |
| 965 | int offset = map()->instance_size() + (index * kPointerSize); |
| 966 | return READ_FIELD(this, offset); |
| 967 | } else { |
| 968 | ASSERT(index < properties()->length()); |
| 969 | return properties()->get(index); |
| 970 | } |
| 971 | } |
| 972 | |
| 973 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 974 | Object* JSObject::FastPropertyAtPut(int index, Object* value) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 975 | // Adjust for the number of properties stored in the object. |
| 976 | index -= map()->inobject_properties(); |
| 977 | if (index < 0) { |
| 978 | int offset = map()->instance_size() + (index * kPointerSize); |
| 979 | WRITE_FIELD(this, offset, value); |
| 980 | WRITE_BARRIER(this, offset); |
| 981 | } else { |
| 982 | ASSERT(index < properties()->length()); |
| 983 | properties()->set(index, value); |
| 984 | } |
| 985 | return value; |
| 986 | } |
| 987 | |
| 988 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 989 | Object* JSObject::InObjectPropertyAtPut(int index, |
| 990 | Object* value, |
| 991 | WriteBarrierMode mode) { |
| 992 | // Adjust for the number of properties stored in the object. |
| 993 | index -= map()->inobject_properties(); |
| 994 | ASSERT(index < 0); |
| 995 | int offset = map()->instance_size() + (index * kPointerSize); |
| 996 | WRITE_FIELD(this, offset, value); |
| 997 | CONDITIONAL_WRITE_BARRIER(this, offset, mode); |
| 998 | return value; |
| 999 | } |
| 1000 | |
| 1001 | |
| 1002 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1003 | void JSObject::InitializeBody(int object_size) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1004 | Object* value = Heap::undefined_value(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1005 | for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1006 | WRITE_FIELD(this, offset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | |
| 1011 | void Struct::InitializeBody(int object_size) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1012 | Object* value = Heap::undefined_value(); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1013 | for (int offset = kHeaderSize; offset < object_size; offset += kPointerSize) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1014 | WRITE_FIELD(this, offset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1015 | } |
| 1016 | } |
| 1017 | |
| 1018 | |
| 1019 | bool JSObject::HasFastProperties() { |
| 1020 | return !properties()->IsDictionary(); |
| 1021 | } |
| 1022 | |
| 1023 | |
| 1024 | bool Array::IndexFromObject(Object* object, uint32_t* index) { |
| 1025 | if (object->IsSmi()) { |
| 1026 | int value = Smi::cast(object)->value(); |
| 1027 | if (value < 0) return false; |
| 1028 | *index = value; |
| 1029 | return true; |
| 1030 | } |
| 1031 | if (object->IsHeapNumber()) { |
| 1032 | double value = HeapNumber::cast(object)->value(); |
| 1033 | uint32_t uint_value = static_cast<uint32_t>(value); |
| 1034 | if (value == static_cast<double>(uint_value)) { |
| 1035 | *index = uint_value; |
| 1036 | return true; |
| 1037 | } |
| 1038 | } |
| 1039 | return false; |
| 1040 | } |
| 1041 | |
| 1042 | |
| 1043 | bool Object::IsStringObjectWithCharacterAt(uint32_t index) { |
| 1044 | if (!this->IsJSValue()) return false; |
| 1045 | |
| 1046 | JSValue* js_value = JSValue::cast(this); |
| 1047 | if (!js_value->value()->IsString()) return false; |
| 1048 | |
| 1049 | String* str = String::cast(js_value->value()); |
| 1050 | if (index >= (uint32_t)str->length()) return false; |
| 1051 | |
| 1052 | return true; |
| 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | Object* FixedArray::get(int index) { |
| 1057 | ASSERT(index >= 0 && index < this->length()); |
| 1058 | return READ_FIELD(this, kHeaderSize + index * kPointerSize); |
| 1059 | } |
| 1060 | |
| 1061 | |
| 1062 | void FixedArray::set(int index, Object* value) { |
| 1063 | ASSERT(index >= 0 && index < this->length()); |
| 1064 | int offset = kHeaderSize + index * kPointerSize; |
| 1065 | WRITE_FIELD(this, offset, value); |
| 1066 | WRITE_BARRIER(this, offset); |
| 1067 | } |
| 1068 | |
| 1069 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1070 | WriteBarrierMode HeapObject::GetWriteBarrierMode() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1071 | if (Heap::InNewSpace(this)) return SKIP_WRITE_BARRIER; |
| 1072 | return UPDATE_WRITE_BARRIER; |
| 1073 | } |
| 1074 | |
| 1075 | |
| 1076 | void FixedArray::set(int index, |
| 1077 | Object* value, |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1078 | WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1079 | ASSERT(index >= 0 && index < this->length()); |
| 1080 | int offset = kHeaderSize + index * kPointerSize; |
| 1081 | WRITE_FIELD(this, offset, value); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1082 | CONDITIONAL_WRITE_BARRIER(this, offset, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | |
| 1086 | void FixedArray::fast_set(FixedArray* array, int index, Object* value) { |
| 1087 | ASSERT(index >= 0 && index < array->length()); |
| 1088 | WRITE_FIELD(array, kHeaderSize + index * kPointerSize, value); |
| 1089 | } |
| 1090 | |
| 1091 | |
| 1092 | void FixedArray::set_undefined(int index) { |
| 1093 | ASSERT(index >= 0 && index < this->length()); |
| 1094 | ASSERT(!Heap::InNewSpace(Heap::undefined_value())); |
| 1095 | WRITE_FIELD(this, kHeaderSize + index * kPointerSize, |
| 1096 | Heap::undefined_value()); |
| 1097 | } |
| 1098 | |
| 1099 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1100 | void FixedArray::set_null(int index) { |
| 1101 | ASSERT(index >= 0 && index < this->length()); |
| 1102 | ASSERT(!Heap::InNewSpace(Heap::null_value())); |
| 1103 | WRITE_FIELD(this, kHeaderSize + index * kPointerSize, Heap::null_value()); |
| 1104 | } |
| 1105 | |
| 1106 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1107 | void FixedArray::set_the_hole(int index) { |
| 1108 | ASSERT(index >= 0 && index < this->length()); |
| 1109 | ASSERT(!Heap::InNewSpace(Heap::the_hole_value())); |
| 1110 | WRITE_FIELD(this, kHeaderSize + index * kPointerSize, Heap::the_hole_value()); |
| 1111 | } |
| 1112 | |
| 1113 | |
mads.s.ager@gmail.com | 9a4089a | 2008-09-01 08:55:01 +0000 | [diff] [blame] | 1114 | bool DescriptorArray::IsEmpty() { |
| 1115 | ASSERT(this == Heap::empty_descriptor_array() || |
| 1116 | this->length() > 2); |
| 1117 | return this == Heap::empty_descriptor_array(); |
| 1118 | } |
| 1119 | |
| 1120 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1121 | void DescriptorArray::fast_swap(FixedArray* array, int first, int second) { |
| 1122 | Object* tmp = array->get(first); |
| 1123 | fast_set(array, first, array->get(second)); |
| 1124 | fast_set(array, second, tmp); |
| 1125 | } |
| 1126 | |
| 1127 | |
| 1128 | int DescriptorArray::Search(String* name) { |
| 1129 | SLOW_ASSERT(IsSortedNoDuplicates()); |
| 1130 | |
| 1131 | // Check for empty descriptor array. |
| 1132 | int nof = number_of_descriptors(); |
| 1133 | if (nof == 0) return kNotFound; |
| 1134 | |
| 1135 | // Fast case: do linear search for small arrays. |
| 1136 | const int kMaxElementsForLinearSearch = 8; |
| 1137 | if (name->IsSymbol() && nof < kMaxElementsForLinearSearch) { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1138 | return LinearSearch(name, nof); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | // Slow case: perform binary search. |
| 1142 | return BinarySearch(name, 0, nof - 1); |
| 1143 | } |
| 1144 | |
| 1145 | |
| 1146 | |
| 1147 | String* DescriptorArray::GetKey(int descriptor_number) { |
| 1148 | ASSERT(descriptor_number < number_of_descriptors()); |
| 1149 | return String::cast(get(ToKeyIndex(descriptor_number))); |
| 1150 | } |
| 1151 | |
| 1152 | |
| 1153 | Object* DescriptorArray::GetValue(int descriptor_number) { |
| 1154 | ASSERT(descriptor_number < number_of_descriptors()); |
| 1155 | return GetContentArray()->get(ToValueIndex(descriptor_number)); |
| 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | Smi* DescriptorArray::GetDetails(int descriptor_number) { |
| 1160 | ASSERT(descriptor_number < number_of_descriptors()); |
| 1161 | return Smi::cast(GetContentArray()->get(ToDetailsIndex(descriptor_number))); |
| 1162 | } |
| 1163 | |
| 1164 | |
| 1165 | void DescriptorArray::Get(int descriptor_number, Descriptor* desc) { |
| 1166 | desc->Init(GetKey(descriptor_number), |
| 1167 | GetValue(descriptor_number), |
| 1168 | GetDetails(descriptor_number)); |
| 1169 | } |
| 1170 | |
| 1171 | |
| 1172 | void DescriptorArray::Set(int descriptor_number, Descriptor* desc) { |
| 1173 | // Range check. |
| 1174 | ASSERT(descriptor_number < number_of_descriptors()); |
| 1175 | |
| 1176 | // Make sure non of the elements in desc are in new space. |
| 1177 | ASSERT(!Heap::InNewSpace(desc->GetKey())); |
| 1178 | ASSERT(!Heap::InNewSpace(desc->GetValue())); |
| 1179 | |
| 1180 | fast_set(this, ToKeyIndex(descriptor_number), desc->GetKey()); |
| 1181 | FixedArray* content_array = GetContentArray(); |
| 1182 | fast_set(content_array, ToValueIndex(descriptor_number), desc->GetValue()); |
| 1183 | fast_set(content_array, ToDetailsIndex(descriptor_number), |
| 1184 | desc->GetDetails().AsSmi()); |
| 1185 | } |
| 1186 | |
| 1187 | |
| 1188 | void DescriptorArray::Swap(int first, int second) { |
| 1189 | fast_swap(this, ToKeyIndex(first), ToKeyIndex(second)); |
| 1190 | FixedArray* content_array = GetContentArray(); |
| 1191 | fast_swap(content_array, ToValueIndex(first), ToValueIndex(second)); |
| 1192 | fast_swap(content_array, ToDetailsIndex(first), ToDetailsIndex(second)); |
| 1193 | } |
| 1194 | |
| 1195 | |
| 1196 | bool Dictionary::requires_slow_elements() { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1197 | Object* max_index_object = get(kMaxNumberKeyIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1198 | if (!max_index_object->IsSmi()) return false; |
| 1199 | return 0 != |
| 1200 | (Smi::cast(max_index_object)->value() & kRequiresSlowElementsMask); |
| 1201 | } |
| 1202 | |
| 1203 | |
| 1204 | uint32_t Dictionary::max_number_key() { |
| 1205 | ASSERT(!requires_slow_elements()); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1206 | Object* max_index_object = get(kMaxNumberKeyIndex); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1207 | if (!max_index_object->IsSmi()) return 0; |
| 1208 | uint32_t value = static_cast<uint32_t>(Smi::cast(max_index_object)->value()); |
| 1209 | return value >> kRequiresSlowElementsTagSize; |
| 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | // ------------------------------------ |
| 1214 | // Cast operations |
| 1215 | |
| 1216 | |
| 1217 | CAST_ACCESSOR(FixedArray) |
| 1218 | CAST_ACCESSOR(DescriptorArray) |
| 1219 | CAST_ACCESSOR(Dictionary) |
| 1220 | CAST_ACCESSOR(SymbolTable) |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1221 | CAST_ACCESSOR(CompilationCacheTable) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1222 | CAST_ACCESSOR(MapCache) |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1223 | CAST_ACCESSOR(LookupCache) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1224 | CAST_ACCESSOR(String) |
| 1225 | CAST_ACCESSOR(SeqString) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1226 | CAST_ACCESSOR(SeqAsciiString) |
| 1227 | CAST_ACCESSOR(SeqTwoByteString) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1228 | CAST_ACCESSOR(ConsString) |
| 1229 | CAST_ACCESSOR(SlicedString) |
| 1230 | CAST_ACCESSOR(ExternalString) |
| 1231 | CAST_ACCESSOR(ExternalAsciiString) |
| 1232 | CAST_ACCESSOR(ExternalTwoByteString) |
| 1233 | CAST_ACCESSOR(JSObject) |
| 1234 | CAST_ACCESSOR(Smi) |
| 1235 | CAST_ACCESSOR(Failure) |
| 1236 | CAST_ACCESSOR(HeapObject) |
| 1237 | CAST_ACCESSOR(HeapNumber) |
| 1238 | CAST_ACCESSOR(Oddball) |
| 1239 | CAST_ACCESSOR(SharedFunctionInfo) |
| 1240 | CAST_ACCESSOR(Map) |
| 1241 | CAST_ACCESSOR(JSFunction) |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1242 | CAST_ACCESSOR(GlobalObject) |
| 1243 | CAST_ACCESSOR(JSGlobalProxy) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1244 | CAST_ACCESSOR(JSGlobalObject) |
| 1245 | CAST_ACCESSOR(JSBuiltinsObject) |
| 1246 | CAST_ACCESSOR(Code) |
| 1247 | CAST_ACCESSOR(JSArray) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1248 | CAST_ACCESSOR(JSRegExp) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1249 | CAST_ACCESSOR(Proxy) |
| 1250 | CAST_ACCESSOR(ByteArray) |
| 1251 | CAST_ACCESSOR(Struct) |
| 1252 | |
| 1253 | |
| 1254 | #define MAKE_STRUCT_CAST(NAME, Name, name) CAST_ACCESSOR(Name) |
| 1255 | STRUCT_LIST(MAKE_STRUCT_CAST) |
| 1256 | #undef MAKE_STRUCT_CAST |
| 1257 | |
| 1258 | template <int prefix_size, int elem_size> |
| 1259 | HashTable<prefix_size, elem_size>* HashTable<prefix_size, elem_size>::cast( |
| 1260 | Object* obj) { |
| 1261 | ASSERT(obj->IsHashTable()); |
| 1262 | return reinterpret_cast<HashTable*>(obj); |
| 1263 | } |
| 1264 | |
| 1265 | |
| 1266 | INT_ACCESSORS(Array, length, kLengthOffset) |
| 1267 | |
| 1268 | |
| 1269 | bool String::Equals(String* other) { |
| 1270 | if (other == this) return true; |
| 1271 | if (IsSymbol() && other->IsSymbol()) return false; |
| 1272 | return SlowEquals(other); |
| 1273 | } |
| 1274 | |
| 1275 | |
| 1276 | int String::length() { |
| 1277 | uint32_t len = READ_INT_FIELD(this, kLengthOffset); |
| 1278 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1279 | ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift); |
| 1280 | ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift); |
| 1281 | ASSERT(kLongStringTag == 0); |
| 1282 | |
| 1283 | return len >> (size_tag() + kLongLengthShift); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | |
| 1287 | void String::set_length(int value) { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1288 | ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift); |
| 1289 | ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift); |
| 1290 | ASSERT(kLongStringTag == 0); |
| 1291 | |
| 1292 | WRITE_INT_FIELD(this, |
| 1293 | kLengthOffset, |
| 1294 | value << (size_tag() + kLongLengthShift)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1298 | uint32_t String::length_field() { |
| 1299 | return READ_UINT32_FIELD(this, kLengthOffset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
| 1302 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1303 | void String::set_length_field(uint32_t value) { |
| 1304 | WRITE_UINT32_FIELD(this, kLengthOffset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
| 1307 | |
| 1308 | void String::TryFlatten() { |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 1309 | // We don't need to flatten strings that are already flat. Since this code |
| 1310 | // is inlined, it can be helpful in the flat case to not call out to Flatten. |
| 1311 | StringRepresentationTag str_type = representation_tag(); |
| 1312 | if (str_type != kSeqStringTag && str_type != kExternalStringTag) { |
| 1313 | Flatten(); |
| 1314 | } |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | |
| 1318 | uint16_t String::Get(int index) { |
| 1319 | ASSERT(index >= 0 && index < length()); |
| 1320 | switch (representation_tag()) { |
| 1321 | case kSeqStringTag: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1322 | return is_ascii_representation() |
| 1323 | ? SeqAsciiString::cast(this)->SeqAsciiStringGet(index) |
| 1324 | : SeqTwoByteString::cast(this)->SeqTwoByteStringGet(index); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1325 | case kConsStringTag: |
| 1326 | return ConsString::cast(this)->ConsStringGet(index); |
| 1327 | case kSlicedStringTag: |
| 1328 | return SlicedString::cast(this)->SlicedStringGet(index); |
| 1329 | case kExternalStringTag: |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1330 | return is_ascii_representation() |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1331 | ? ExternalAsciiString::cast(this)->ExternalAsciiStringGet(index) |
| 1332 | : ExternalTwoByteString::cast(this)->ExternalTwoByteStringGet(index); |
| 1333 | default: |
| 1334 | break; |
| 1335 | } |
| 1336 | |
| 1337 | UNREACHABLE(); |
| 1338 | return 0; |
| 1339 | } |
| 1340 | |
| 1341 | |
| 1342 | void String::Set(int index, uint16_t value) { |
| 1343 | ASSERT(index >= 0 && index < length()); |
| 1344 | ASSERT(IsSeqString()); |
| 1345 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1346 | return is_ascii_representation() |
| 1347 | ? SeqAsciiString::cast(this)->SeqAsciiStringSet(index, value) |
| 1348 | : SeqTwoByteString::cast(this)->SeqTwoByteStringSet(index, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1352 | bool String::IsAsciiRepresentation() { |
| 1353 | return is_ascii_representation(); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | |
| 1357 | bool String::StringIsConsString() { |
| 1358 | return representation_tag() == kConsStringTag; |
| 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | bool String::StringIsSlicedString() { |
| 1363 | return representation_tag() == kSlicedStringTag; |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | uint32_t String::size_tag() { |
| 1368 | return map_size_tag(map()); |
| 1369 | } |
| 1370 | |
| 1371 | |
| 1372 | uint32_t String::map_size_tag(Map* map) { |
| 1373 | return map->instance_type() & kStringSizeMask; |
| 1374 | } |
| 1375 | |
| 1376 | |
| 1377 | bool String::is_symbol() { |
| 1378 | return is_symbol_map(map()); |
| 1379 | } |
| 1380 | |
| 1381 | |
| 1382 | bool String::is_symbol_map(Map* map) { |
| 1383 | return (map->instance_type() & kIsSymbolMask) != 0; |
| 1384 | } |
| 1385 | |
| 1386 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1387 | bool String::is_ascii_representation() { |
| 1388 | return is_ascii_representation_map(map()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1392 | bool String::is_ascii_representation_map(Map* map) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1393 | return (map->instance_type() & kStringEncodingMask) != 0; |
| 1394 | } |
| 1395 | |
| 1396 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1397 | int String::full_representation_tag() { |
| 1398 | return map()->instance_type() & |
| 1399 | (kStringRepresentationMask | kStringEncodingMask); |
| 1400 | } |
| 1401 | |
| 1402 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1403 | StringRepresentationTag String::representation_tag() { |
| 1404 | return map_representation_tag(map()); |
| 1405 | } |
| 1406 | |
| 1407 | |
| 1408 | StringRepresentationTag String::map_representation_tag(Map* map) { |
| 1409 | uint32_t tag = map->instance_type() & kStringRepresentationMask; |
| 1410 | return static_cast<StringRepresentationTag>(tag); |
| 1411 | } |
| 1412 | |
| 1413 | |
| 1414 | bool String::IsFlat() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1415 | switch (this->representation_tag()) { |
| 1416 | case kConsStringTag: |
| 1417 | // Only flattened strings have second part empty. |
| 1418 | return String::cast(ConsString::cast(this)->second())->length() == 0; |
| 1419 | case kSlicedStringTag: { |
| 1420 | String* slice = String::cast(SlicedString::cast(this)->buffer()); |
| 1421 | StringRepresentationTag tag = slice->representation_tag(); |
| 1422 | return tag == kSeqStringTag || tag == kExternalStringTag; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1423 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1424 | default: |
| 1425 | return true; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1426 | } |
| 1427 | } |
| 1428 | |
| 1429 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1430 | uint16_t SeqAsciiString::SeqAsciiStringGet(int index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1431 | ASSERT(index >= 0 && index < length()); |
| 1432 | return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
| 1433 | } |
| 1434 | |
| 1435 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1436 | void SeqAsciiString::SeqAsciiStringSet(int index, uint16_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1437 | ASSERT(index >= 0 && index < length() && value <= kMaxAsciiCharCode); |
| 1438 | WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, |
| 1439 | static_cast<byte>(value)); |
| 1440 | } |
| 1441 | |
| 1442 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1443 | Address SeqAsciiString::GetCharsAddress() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1444 | return FIELD_ADDR(this, kHeaderSize); |
| 1445 | } |
| 1446 | |
| 1447 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1448 | char* SeqAsciiString::GetChars() { |
| 1449 | return reinterpret_cast<char*>(GetCharsAddress()); |
| 1450 | } |
| 1451 | |
| 1452 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1453 | Address SeqTwoByteString::GetCharsAddress() { |
| 1454 | return FIELD_ADDR(this, kHeaderSize); |
| 1455 | } |
| 1456 | |
| 1457 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1458 | uc16* SeqTwoByteString::GetChars() { |
| 1459 | return reinterpret_cast<uc16*>(FIELD_ADDR(this, kHeaderSize)); |
| 1460 | } |
| 1461 | |
| 1462 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1463 | uint16_t SeqTwoByteString::SeqTwoByteStringGet(int index) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1464 | ASSERT(index >= 0 && index < length()); |
| 1465 | return READ_SHORT_FIELD(this, kHeaderSize + index * kShortSize); |
| 1466 | } |
| 1467 | |
| 1468 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1469 | void SeqTwoByteString::SeqTwoByteStringSet(int index, uint16_t value) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1470 | ASSERT(index >= 0 && index < length()); |
| 1471 | WRITE_SHORT_FIELD(this, kHeaderSize + index * kShortSize, value); |
| 1472 | } |
| 1473 | |
| 1474 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1475 | int SeqTwoByteString::SeqTwoByteStringSize(Map* map) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1476 | uint32_t length = READ_INT_FIELD(this, kLengthOffset); |
| 1477 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1478 | ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift); |
| 1479 | ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift); |
| 1480 | ASSERT(kLongStringTag == 0); |
| 1481 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1482 | // Use the map (and not 'this') to compute the size tag, since |
| 1483 | // TwoByteStringSize is called during GC when maps are encoded. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1484 | length >>= map_size_tag(map) + kLongLengthShift; |
| 1485 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1486 | return SizeFor(length); |
| 1487 | } |
| 1488 | |
| 1489 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1490 | int SeqAsciiString::SeqAsciiStringSize(Map* map) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1491 | uint32_t length = READ_INT_FIELD(this, kLengthOffset); |
| 1492 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1493 | ASSERT(kShortStringTag + kLongLengthShift == kShortLengthShift); |
| 1494 | ASSERT(kMediumStringTag + kLongLengthShift == kMediumLengthShift); |
| 1495 | ASSERT(kLongStringTag == 0); |
| 1496 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1497 | // Use the map (and not 'this') to compute the size tag, since |
| 1498 | // AsciiStringSize is called during GC when maps are encoded. |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1499 | length >>= map_size_tag(map) + kLongLengthShift; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1500 | |
| 1501 | return SizeFor(length); |
| 1502 | } |
| 1503 | |
| 1504 | |
| 1505 | Object* ConsString::first() { |
| 1506 | return READ_FIELD(this, kFirstOffset); |
| 1507 | } |
| 1508 | |
| 1509 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1510 | void ConsString::set_first(Object* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1511 | WRITE_FIELD(this, kFirstOffset, value); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1512 | CONDITIONAL_WRITE_BARRIER(this, kFirstOffset, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | |
| 1516 | Object* ConsString::second() { |
| 1517 | return READ_FIELD(this, kSecondOffset); |
| 1518 | } |
| 1519 | |
| 1520 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1521 | void ConsString::set_second(Object* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1522 | WRITE_FIELD(this, kSecondOffset, value); |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 1523 | CONDITIONAL_WRITE_BARRIER(this, kSecondOffset, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
| 1526 | |
| 1527 | Object* SlicedString::buffer() { |
| 1528 | return READ_FIELD(this, kBufferOffset); |
| 1529 | } |
| 1530 | |
| 1531 | |
| 1532 | void SlicedString::set_buffer(Object* buffer) { |
| 1533 | WRITE_FIELD(this, kBufferOffset, buffer); |
| 1534 | WRITE_BARRIER(this, kBufferOffset); |
| 1535 | } |
| 1536 | |
| 1537 | |
| 1538 | int SlicedString::start() { |
| 1539 | return READ_INT_FIELD(this, kStartOffset); |
| 1540 | } |
| 1541 | |
| 1542 | |
| 1543 | void SlicedString::set_start(int start) { |
| 1544 | WRITE_INT_FIELD(this, kStartOffset, start); |
| 1545 | } |
| 1546 | |
| 1547 | |
| 1548 | ExternalAsciiString::Resource* ExternalAsciiString::resource() { |
| 1549 | return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); |
| 1550 | } |
| 1551 | |
| 1552 | |
| 1553 | void ExternalAsciiString::set_resource( |
| 1554 | ExternalAsciiString::Resource* resource) { |
| 1555 | *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)) = resource; |
| 1556 | } |
| 1557 | |
| 1558 | |
| 1559 | ExternalTwoByteString::Resource* ExternalTwoByteString::resource() { |
| 1560 | return *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)); |
| 1561 | } |
| 1562 | |
| 1563 | |
| 1564 | void ExternalTwoByteString::set_resource( |
| 1565 | ExternalTwoByteString::Resource* resource) { |
| 1566 | *reinterpret_cast<Resource**>(FIELD_ADDR(this, kResourceOffset)) = resource; |
| 1567 | } |
| 1568 | |
| 1569 | |
| 1570 | byte ByteArray::get(int index) { |
| 1571 | ASSERT(index >= 0 && index < this->length()); |
| 1572 | return READ_BYTE_FIELD(this, kHeaderSize + index * kCharSize); |
| 1573 | } |
| 1574 | |
| 1575 | |
| 1576 | void ByteArray::set(int index, byte value) { |
| 1577 | ASSERT(index >= 0 && index < this->length()); |
| 1578 | WRITE_BYTE_FIELD(this, kHeaderSize + index * kCharSize, value); |
| 1579 | } |
| 1580 | |
| 1581 | |
| 1582 | int ByteArray::get_int(int index) { |
| 1583 | ASSERT(index >= 0 && (index * kIntSize) < this->length()); |
| 1584 | return READ_INT_FIELD(this, kHeaderSize + index * kIntSize); |
| 1585 | } |
| 1586 | |
| 1587 | |
| 1588 | ByteArray* ByteArray::FromDataStartAddress(Address address) { |
| 1589 | ASSERT_TAG_ALIGNED(address); |
| 1590 | return reinterpret_cast<ByteArray*>(address - kHeaderSize + kHeapObjectTag); |
| 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | Address ByteArray::GetDataStartAddress() { |
| 1595 | return reinterpret_cast<Address>(this) - kHeapObjectTag + kHeaderSize; |
| 1596 | } |
| 1597 | |
| 1598 | |
| 1599 | int Map::instance_size() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1600 | return READ_BYTE_FIELD(this, kInstanceSizeOffset) << kPointerSizeLog2; |
| 1601 | } |
| 1602 | |
| 1603 | |
| 1604 | int Map::inobject_properties() { |
| 1605 | return READ_BYTE_FIELD(this, kInObjectPropertiesOffset); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | int HeapObject::SizeFromMap(Map* map) { |
| 1610 | InstanceType instance_type = map->instance_type(); |
| 1611 | // Only inline the two most frequent cases. |
| 1612 | if (instance_type == JS_OBJECT_TYPE) return map->instance_size(); |
| 1613 | if (instance_type == FIXED_ARRAY_TYPE) { |
| 1614 | return reinterpret_cast<FixedArray*>(this)->FixedArraySize(); |
| 1615 | } |
| 1616 | // Otherwise do the general size computation. |
| 1617 | return SlowSizeFromMap(map); |
| 1618 | } |
| 1619 | |
| 1620 | |
| 1621 | void Map::set_instance_size(int value) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1622 | ASSERT((value & ~(kPointerSize - 1)) == value); |
| 1623 | value >>= kPointerSizeLog2; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1624 | ASSERT(0 <= value && value < 256); |
| 1625 | WRITE_BYTE_FIELD(this, kInstanceSizeOffset, static_cast<byte>(value)); |
| 1626 | } |
| 1627 | |
| 1628 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 1629 | void Map::set_inobject_properties(int value) { |
| 1630 | ASSERT(0 <= value && value < 256); |
| 1631 | WRITE_BYTE_FIELD(this, kInObjectPropertiesOffset, static_cast<byte>(value)); |
| 1632 | } |
| 1633 | |
| 1634 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1635 | InstanceType Map::instance_type() { |
| 1636 | return static_cast<InstanceType>(READ_BYTE_FIELD(this, kInstanceTypeOffset)); |
| 1637 | } |
| 1638 | |
| 1639 | |
| 1640 | void Map::set_instance_type(InstanceType value) { |
| 1641 | ASSERT(0 <= value && value < 256); |
| 1642 | WRITE_BYTE_FIELD(this, kInstanceTypeOffset, value); |
| 1643 | } |
| 1644 | |
| 1645 | |
| 1646 | int Map::unused_property_fields() { |
| 1647 | return READ_BYTE_FIELD(this, kUnusedPropertyFieldsOffset); |
| 1648 | } |
| 1649 | |
| 1650 | |
| 1651 | void Map::set_unused_property_fields(int value) { |
| 1652 | WRITE_BYTE_FIELD(this, kUnusedPropertyFieldsOffset, Min(value, 255)); |
| 1653 | } |
| 1654 | |
| 1655 | |
| 1656 | byte Map::bit_field() { |
| 1657 | return READ_BYTE_FIELD(this, kBitFieldOffset); |
| 1658 | } |
| 1659 | |
| 1660 | |
| 1661 | void Map::set_bit_field(byte value) { |
| 1662 | WRITE_BYTE_FIELD(this, kBitFieldOffset, value); |
| 1663 | } |
| 1664 | |
| 1665 | |
| 1666 | void Map::set_non_instance_prototype(bool value) { |
| 1667 | if (value) { |
| 1668 | set_bit_field(bit_field() | (1 << kHasNonInstancePrototype)); |
| 1669 | } else { |
| 1670 | set_bit_field(bit_field() & ~(1 << kHasNonInstancePrototype)); |
| 1671 | } |
| 1672 | } |
| 1673 | |
| 1674 | |
| 1675 | bool Map::has_non_instance_prototype() { |
| 1676 | return ((1 << kHasNonInstancePrototype) & bit_field()) != 0; |
| 1677 | } |
| 1678 | |
| 1679 | |
| 1680 | Code::Flags Code::flags() { |
| 1681 | return static_cast<Flags>(READ_INT_FIELD(this, kFlagsOffset)); |
| 1682 | } |
| 1683 | |
| 1684 | |
| 1685 | void Code::set_flags(Code::Flags flags) { |
| 1686 | // Make sure that all call stubs have an arguments count. |
| 1687 | ASSERT(ExtractKindFromFlags(flags) != CALL_IC || |
| 1688 | ExtractArgumentsCountFromFlags(flags) >= 0); |
| 1689 | WRITE_INT_FIELD(this, kFlagsOffset, flags); |
| 1690 | } |
| 1691 | |
| 1692 | |
| 1693 | Code::Kind Code::kind() { |
| 1694 | return ExtractKindFromFlags(flags()); |
| 1695 | } |
| 1696 | |
| 1697 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1698 | InlineCacheState Code::ic_state() { |
| 1699 | InlineCacheState result = ExtractICStateFromFlags(flags()); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1700 | // Only allow uninitialized or debugger states for non-IC code |
| 1701 | // objects. This is used in the debugger to determine whether or not |
| 1702 | // a call to code object has been replaced with a debug break call. |
| 1703 | ASSERT(is_inline_cache_stub() || |
| 1704 | result == UNINITIALIZED || |
| 1705 | result == DEBUG_BREAK || |
| 1706 | result == DEBUG_PREPARE_STEP_IN); |
| 1707 | return result; |
| 1708 | } |
| 1709 | |
| 1710 | |
| 1711 | PropertyType Code::type() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1712 | ASSERT(ic_state() == MONOMORPHIC); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1713 | return ExtractTypeFromFlags(flags()); |
| 1714 | } |
| 1715 | |
| 1716 | |
| 1717 | int Code::arguments_count() { |
| 1718 | ASSERT(is_call_stub() || kind() == STUB); |
| 1719 | return ExtractArgumentsCountFromFlags(flags()); |
| 1720 | } |
| 1721 | |
| 1722 | |
| 1723 | CodeStub::Major Code::major_key() { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1724 | ASSERT(kind() == STUB); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1725 | return static_cast<CodeStub::Major>(READ_BYTE_FIELD(this, |
| 1726 | kStubMajorKeyOffset)); |
| 1727 | } |
| 1728 | |
| 1729 | |
| 1730 | void Code::set_major_key(CodeStub::Major major) { |
| 1731 | ASSERT(kind() == STUB); |
| 1732 | ASSERT(0 <= major && major < 256); |
| 1733 | WRITE_BYTE_FIELD(this, kStubMajorKeyOffset, major); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | |
| 1737 | bool Code::is_inline_cache_stub() { |
| 1738 | Kind kind = this->kind(); |
| 1739 | return kind >= FIRST_IC_KIND && kind <= LAST_IC_KIND; |
| 1740 | } |
| 1741 | |
| 1742 | |
| 1743 | Code::Flags Code::ComputeFlags(Kind kind, |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1744 | InlineCacheState ic_state, |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1745 | PropertyType type, |
| 1746 | int argc) { |
| 1747 | // Compute the bit mask. |
| 1748 | int bits = kind << kFlagsKindShift; |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1749 | bits |= ic_state << kFlagsICStateShift; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1750 | bits |= type << kFlagsTypeShift; |
| 1751 | bits |= argc << kFlagsArgumentsCountShift; |
| 1752 | // Cast to flags and validate result before returning it. |
| 1753 | Flags result = static_cast<Flags>(bits); |
| 1754 | ASSERT(ExtractKindFromFlags(result) == kind); |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1755 | ASSERT(ExtractICStateFromFlags(result) == ic_state); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1756 | ASSERT(ExtractTypeFromFlags(result) == type); |
| 1757 | ASSERT(ExtractArgumentsCountFromFlags(result) == argc); |
| 1758 | return result; |
| 1759 | } |
| 1760 | |
| 1761 | |
| 1762 | Code::Flags Code::ComputeMonomorphicFlags(Kind kind, |
| 1763 | PropertyType type, |
| 1764 | int argc) { |
| 1765 | return ComputeFlags(kind, MONOMORPHIC, type, argc); |
| 1766 | } |
| 1767 | |
| 1768 | |
| 1769 | Code::Kind Code::ExtractKindFromFlags(Flags flags) { |
| 1770 | int bits = (flags & kFlagsKindMask) >> kFlagsKindShift; |
| 1771 | return static_cast<Kind>(bits); |
| 1772 | } |
| 1773 | |
| 1774 | |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 1775 | InlineCacheState Code::ExtractICStateFromFlags(Flags flags) { |
| 1776 | int bits = (flags & kFlagsICStateMask) >> kFlagsICStateShift; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1777 | return static_cast<InlineCacheState>(bits); |
| 1778 | } |
| 1779 | |
| 1780 | |
| 1781 | PropertyType Code::ExtractTypeFromFlags(Flags flags) { |
| 1782 | int bits = (flags & kFlagsTypeMask) >> kFlagsTypeShift; |
| 1783 | return static_cast<PropertyType>(bits); |
| 1784 | } |
| 1785 | |
| 1786 | |
| 1787 | int Code::ExtractArgumentsCountFromFlags(Flags flags) { |
| 1788 | return (flags & kFlagsArgumentsCountMask) >> kFlagsArgumentsCountShift; |
| 1789 | } |
| 1790 | |
| 1791 | |
| 1792 | Code::Flags Code::RemoveTypeFromFlags(Flags flags) { |
| 1793 | int bits = flags & ~kFlagsTypeMask; |
| 1794 | return static_cast<Flags>(bits); |
| 1795 | } |
| 1796 | |
| 1797 | |
| 1798 | Object* Map::prototype() { |
| 1799 | return READ_FIELD(this, kPrototypeOffset); |
| 1800 | } |
| 1801 | |
| 1802 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1803 | void Map::set_prototype(Object* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1804 | ASSERT(value->IsNull() || value->IsJSObject()); |
| 1805 | WRITE_FIELD(this, kPrototypeOffset, value); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1806 | CONDITIONAL_WRITE_BARRIER(this, kPrototypeOffset, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | |
| 1810 | ACCESSORS(Map, instance_descriptors, DescriptorArray, |
| 1811 | kInstanceDescriptorsOffset) |
| 1812 | ACCESSORS(Map, code_cache, FixedArray, kCodeCacheOffset) |
| 1813 | ACCESSORS(Map, constructor, Object, kConstructorOffset) |
| 1814 | |
| 1815 | ACCESSORS(JSFunction, shared, SharedFunctionInfo, kSharedFunctionInfoOffset) |
| 1816 | ACCESSORS(JSFunction, literals, FixedArray, kLiteralsOffset) |
| 1817 | |
| 1818 | ACCESSORS(GlobalObject, builtins, JSBuiltinsObject, kBuiltinsOffset) |
| 1819 | ACCESSORS(GlobalObject, global_context, Context, kGlobalContextOffset) |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1820 | ACCESSORS(GlobalObject, global_receiver, JSObject, kGlobalReceiverOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1821 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1822 | ACCESSORS(JSGlobalProxy, context, Object, kContextOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1823 | |
| 1824 | ACCESSORS(AccessorInfo, getter, Object, kGetterOffset) |
| 1825 | ACCESSORS(AccessorInfo, setter, Object, kSetterOffset) |
| 1826 | ACCESSORS(AccessorInfo, data, Object, kDataOffset) |
| 1827 | ACCESSORS(AccessorInfo, name, Object, kNameOffset) |
| 1828 | ACCESSORS(AccessorInfo, flag, Smi, kFlagOffset) |
| 1829 | |
| 1830 | ACCESSORS(AccessCheckInfo, named_callback, Object, kNamedCallbackOffset) |
| 1831 | ACCESSORS(AccessCheckInfo, indexed_callback, Object, kIndexedCallbackOffset) |
| 1832 | ACCESSORS(AccessCheckInfo, data, Object, kDataOffset) |
| 1833 | |
| 1834 | ACCESSORS(InterceptorInfo, getter, Object, kGetterOffset) |
| 1835 | ACCESSORS(InterceptorInfo, setter, Object, kSetterOffset) |
| 1836 | ACCESSORS(InterceptorInfo, query, Object, kQueryOffset) |
| 1837 | ACCESSORS(InterceptorInfo, deleter, Object, kDeleterOffset) |
| 1838 | ACCESSORS(InterceptorInfo, enumerator, Object, kEnumeratorOffset) |
| 1839 | ACCESSORS(InterceptorInfo, data, Object, kDataOffset) |
| 1840 | |
| 1841 | ACCESSORS(CallHandlerInfo, callback, Object, kCallbackOffset) |
| 1842 | ACCESSORS(CallHandlerInfo, data, Object, kDataOffset) |
| 1843 | |
| 1844 | ACCESSORS(TemplateInfo, tag, Object, kTagOffset) |
| 1845 | ACCESSORS(TemplateInfo, property_list, Object, kPropertyListOffset) |
| 1846 | |
| 1847 | ACCESSORS(FunctionTemplateInfo, serial_number, Object, kSerialNumberOffset) |
| 1848 | ACCESSORS(FunctionTemplateInfo, call_code, Object, kCallCodeOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1849 | ACCESSORS(FunctionTemplateInfo, property_accessors, Object, |
| 1850 | kPropertyAccessorsOffset) |
| 1851 | ACCESSORS(FunctionTemplateInfo, prototype_template, Object, |
| 1852 | kPrototypeTemplateOffset) |
| 1853 | ACCESSORS(FunctionTemplateInfo, parent_template, Object, kParentTemplateOffset) |
| 1854 | ACCESSORS(FunctionTemplateInfo, named_property_handler, Object, |
| 1855 | kNamedPropertyHandlerOffset) |
| 1856 | ACCESSORS(FunctionTemplateInfo, indexed_property_handler, Object, |
| 1857 | kIndexedPropertyHandlerOffset) |
| 1858 | ACCESSORS(FunctionTemplateInfo, instance_template, Object, |
| 1859 | kInstanceTemplateOffset) |
| 1860 | ACCESSORS(FunctionTemplateInfo, class_name, Object, kClassNameOffset) |
| 1861 | ACCESSORS(FunctionTemplateInfo, signature, Object, kSignatureOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1862 | ACCESSORS(FunctionTemplateInfo, instance_call_handler, Object, |
| 1863 | kInstanceCallHandlerOffset) |
| 1864 | ACCESSORS(FunctionTemplateInfo, access_check_info, Object, |
| 1865 | kAccessCheckInfoOffset) |
| 1866 | ACCESSORS(FunctionTemplateInfo, flag, Smi, kFlagOffset) |
| 1867 | |
| 1868 | ACCESSORS(ObjectTemplateInfo, constructor, Object, kConstructorOffset) |
kasper.lund | 212ac23 | 2008-07-16 07:07:30 +0000 | [diff] [blame] | 1869 | ACCESSORS(ObjectTemplateInfo, internal_field_count, Object, |
| 1870 | kInternalFieldCountOffset) |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1871 | |
| 1872 | ACCESSORS(SignatureInfo, receiver, Object, kReceiverOffset) |
| 1873 | ACCESSORS(SignatureInfo, args, Object, kArgsOffset) |
| 1874 | |
| 1875 | ACCESSORS(TypeSwitchInfo, types, Object, kTypesOffset) |
| 1876 | |
| 1877 | ACCESSORS(Script, source, Object, kSourceOffset) |
| 1878 | ACCESSORS(Script, name, Object, kNameOffset) |
| 1879 | ACCESSORS(Script, line_offset, Smi, kLineOffsetOffset) |
| 1880 | ACCESSORS(Script, column_offset, Smi, kColumnOffsetOffset) |
| 1881 | ACCESSORS(Script, wrapper, Proxy, kWrapperOffset) |
| 1882 | ACCESSORS(Script, type, Smi, kTypeOffset) |
| 1883 | |
| 1884 | ACCESSORS(DebugInfo, shared, SharedFunctionInfo, kSharedFunctionInfoIndex) |
| 1885 | ACCESSORS(DebugInfo, original_code, Code, kOriginalCodeIndex) |
| 1886 | ACCESSORS(DebugInfo, code, Code, kPatchedCodeIndex) |
| 1887 | ACCESSORS(DebugInfo, break_points, FixedArray, kBreakPointsStateIndex) |
| 1888 | |
| 1889 | ACCESSORS(BreakPointInfo, code_position, Smi, kCodePositionIndex) |
| 1890 | ACCESSORS(BreakPointInfo, source_position, Smi, kSourcePositionIndex) |
| 1891 | ACCESSORS(BreakPointInfo, statement_position, Smi, kStatementPositionIndex) |
| 1892 | ACCESSORS(BreakPointInfo, break_point_objects, Object, kBreakPointObjectsIndex) |
| 1893 | |
| 1894 | ACCESSORS(SharedFunctionInfo, name, Object, kNameOffset) |
| 1895 | ACCESSORS(SharedFunctionInfo, instance_class_name, Object, |
| 1896 | kInstanceClassNameOffset) |
| 1897 | ACCESSORS(SharedFunctionInfo, function_data, Object, |
| 1898 | kExternalReferenceDataOffset) |
| 1899 | ACCESSORS(SharedFunctionInfo, lazy_load_data, Object, kLazyLoadDataOffset) |
| 1900 | ACCESSORS(SharedFunctionInfo, script, Object, kScriptOffset) |
| 1901 | ACCESSORS(SharedFunctionInfo, debug_info, Object, kDebugInfoOffset) |
| 1902 | |
| 1903 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, hidden_prototype, |
| 1904 | kHiddenPrototypeBit) |
| 1905 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit) |
| 1906 | BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check, |
| 1907 | kNeedsAccessCheckBit) |
| 1908 | BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_expression, |
| 1909 | kIsExpressionBit) |
| 1910 | BOOL_ACCESSORS(SharedFunctionInfo, start_position_and_type, is_toplevel, |
| 1911 | kIsTopLevelBit) |
| 1912 | |
| 1913 | INT_ACCESSORS(SharedFunctionInfo, length, kLengthOffset) |
| 1914 | INT_ACCESSORS(SharedFunctionInfo, formal_parameter_count, |
| 1915 | kFormalParameterCountOffset) |
| 1916 | INT_ACCESSORS(SharedFunctionInfo, expected_nof_properties, |
| 1917 | kExpectedNofPropertiesOffset) |
| 1918 | INT_ACCESSORS(SharedFunctionInfo, start_position_and_type, |
| 1919 | kStartPositionAndTypeOffset) |
| 1920 | INT_ACCESSORS(SharedFunctionInfo, end_position, kEndPositionOffset) |
| 1921 | INT_ACCESSORS(SharedFunctionInfo, function_token_position, |
| 1922 | kFunctionTokenPositionOffset) |
| 1923 | |
| 1924 | |
kasperl@chromium.org | b912362 | 2008-09-17 14:05:56 +0000 | [diff] [blame] | 1925 | void SharedFunctionInfo::DontAdaptArguments() { |
| 1926 | ASSERT(code()->kind() == Code::BUILTIN); |
| 1927 | set_formal_parameter_count(kDontAdaptArgumentsSentinel); |
| 1928 | } |
| 1929 | |
| 1930 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1931 | int SharedFunctionInfo::start_position() { |
| 1932 | return start_position_and_type() >> kStartPositionShift; |
| 1933 | } |
| 1934 | |
| 1935 | |
| 1936 | void SharedFunctionInfo::set_start_position(int start_position) { |
| 1937 | set_start_position_and_type((start_position << kStartPositionShift) |
| 1938 | | (start_position_and_type() & ~kStartPositionMask)); |
| 1939 | } |
| 1940 | |
| 1941 | |
| 1942 | Code* SharedFunctionInfo::code() { |
| 1943 | return Code::cast(READ_FIELD(this, kCodeOffset)); |
| 1944 | } |
| 1945 | |
| 1946 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1947 | void SharedFunctionInfo::set_code(Code* value, WriteBarrierMode mode) { |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1948 | WRITE_FIELD(this, kCodeOffset, value); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 1949 | CONDITIONAL_WRITE_BARRIER(this, kCodeOffset, mode); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 1950 | } |
| 1951 | |
| 1952 | |
| 1953 | bool SharedFunctionInfo::is_compiled() { |
| 1954 | // TODO(1242782): Create a code kind for uncompiled code. |
| 1955 | return code()->kind() != Code::STUB; |
| 1956 | } |
| 1957 | |
| 1958 | |
| 1959 | bool JSFunction::IsBoilerplate() { |
| 1960 | return map() == Heap::boilerplate_function_map(); |
| 1961 | } |
| 1962 | |
| 1963 | |
| 1964 | bool JSFunction::IsLoaded() { |
| 1965 | return shared()->lazy_load_data() == Heap::undefined_value(); |
| 1966 | } |
| 1967 | |
| 1968 | |
| 1969 | Code* JSFunction::code() { |
| 1970 | return shared()->code(); |
| 1971 | } |
| 1972 | |
| 1973 | |
| 1974 | void JSFunction::set_code(Code* value) { |
| 1975 | shared()->set_code(value); |
| 1976 | } |
| 1977 | |
| 1978 | |
| 1979 | Context* JSFunction::context() { |
| 1980 | return Context::cast(READ_FIELD(this, kContextOffset)); |
| 1981 | } |
| 1982 | |
| 1983 | |
| 1984 | Object* JSFunction::unchecked_context() { |
| 1985 | return READ_FIELD(this, kContextOffset); |
| 1986 | } |
| 1987 | |
| 1988 | |
| 1989 | void JSFunction::set_context(Object* value) { |
| 1990 | ASSERT(value == Heap::undefined_value() || value->IsContext()); |
| 1991 | WRITE_FIELD(this, kContextOffset, value); |
| 1992 | WRITE_BARRIER(this, kContextOffset); |
| 1993 | } |
| 1994 | |
| 1995 | ACCESSORS(JSFunction, prototype_or_initial_map, Object, |
| 1996 | kPrototypeOrInitialMapOffset) |
| 1997 | |
| 1998 | |
| 1999 | Map* JSFunction::initial_map() { |
| 2000 | return Map::cast(prototype_or_initial_map()); |
| 2001 | } |
| 2002 | |
| 2003 | |
| 2004 | void JSFunction::set_initial_map(Map* value) { |
| 2005 | set_prototype_or_initial_map(value); |
| 2006 | } |
| 2007 | |
| 2008 | |
| 2009 | bool JSFunction::has_initial_map() { |
| 2010 | return prototype_or_initial_map()->IsMap(); |
| 2011 | } |
| 2012 | |
| 2013 | |
| 2014 | bool JSFunction::has_instance_prototype() { |
| 2015 | return has_initial_map() || !prototype_or_initial_map()->IsTheHole(); |
| 2016 | } |
| 2017 | |
| 2018 | |
| 2019 | bool JSFunction::has_prototype() { |
| 2020 | return map()->has_non_instance_prototype() || has_instance_prototype(); |
| 2021 | } |
| 2022 | |
| 2023 | |
| 2024 | Object* JSFunction::instance_prototype() { |
| 2025 | ASSERT(has_instance_prototype()); |
| 2026 | if (has_initial_map()) return initial_map()->prototype(); |
| 2027 | // When there is no initial map and the prototype is a JSObject, the |
| 2028 | // initial map field is used for the prototype field. |
| 2029 | return prototype_or_initial_map(); |
| 2030 | } |
| 2031 | |
| 2032 | |
| 2033 | Object* JSFunction::prototype() { |
| 2034 | ASSERT(has_prototype()); |
| 2035 | // If the function's prototype property has been set to a non-JSObject |
| 2036 | // value, that value is stored in the constructor field of the map. |
| 2037 | if (map()->has_non_instance_prototype()) return map()->constructor(); |
| 2038 | return instance_prototype(); |
| 2039 | } |
| 2040 | |
| 2041 | |
| 2042 | bool JSFunction::is_compiled() { |
| 2043 | return shared()->is_compiled(); |
| 2044 | } |
| 2045 | |
| 2046 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 2047 | int JSFunction::NumberOfLiterals() { |
| 2048 | return literals()->length(); |
| 2049 | } |
| 2050 | |
| 2051 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2052 | Object* JSBuiltinsObject::javascript_builtin(Builtins::JavaScript id) { |
| 2053 | ASSERT(0 <= id && id < kJSBuiltinsCount); |
| 2054 | return READ_FIELD(this, kJSBuiltinsOffset + (id * kPointerSize)); |
| 2055 | } |
| 2056 | |
| 2057 | |
| 2058 | void JSBuiltinsObject::set_javascript_builtin(Builtins::JavaScript id, |
| 2059 | Object* value) { |
| 2060 | ASSERT(0 <= id && id < kJSBuiltinsCount); |
| 2061 | WRITE_FIELD(this, kJSBuiltinsOffset + (id * kPointerSize), value); |
| 2062 | WRITE_BARRIER(this, kJSBuiltinsOffset + (id * kPointerSize)); |
| 2063 | } |
| 2064 | |
| 2065 | |
| 2066 | Address Proxy::proxy() { |
| 2067 | return AddressFrom<Address>(READ_INT_FIELD(this, kProxyOffset)); |
| 2068 | } |
| 2069 | |
| 2070 | |
| 2071 | void Proxy::set_proxy(Address value) { |
| 2072 | WRITE_INT_FIELD(this, kProxyOffset, OffsetFrom(value)); |
| 2073 | } |
| 2074 | |
| 2075 | |
| 2076 | void Proxy::ProxyIterateBody(ObjectVisitor* visitor) { |
| 2077 | visitor->VisitExternalReference( |
| 2078 | reinterpret_cast<Address *>(FIELD_ADDR(this, kProxyOffset))); |
| 2079 | } |
| 2080 | |
| 2081 | |
| 2082 | ACCESSORS(JSValue, value, Object, kValueOffset) |
| 2083 | |
| 2084 | |
| 2085 | JSValue* JSValue::cast(Object* obj) { |
| 2086 | ASSERT(obj->IsJSValue()); |
| 2087 | ASSERT(HeapObject::cast(obj)->Size() == JSValue::kSize); |
| 2088 | return reinterpret_cast<JSValue*>(obj); |
| 2089 | } |
| 2090 | |
| 2091 | |
| 2092 | INT_ACCESSORS(Code, instruction_size, kInstructionSizeOffset) |
| 2093 | INT_ACCESSORS(Code, relocation_size, kRelocationSizeOffset) |
| 2094 | INT_ACCESSORS(Code, sinfo_size, kSInfoSizeOffset) |
| 2095 | |
| 2096 | |
| 2097 | Code::ICTargetState Code::ic_flag() { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2098 | return static_cast<ICTargetState>(READ_BYTE_FIELD(this, kICFlagOffset)); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | |
| 2102 | void Code::set_ic_flag(ICTargetState value) { |
kasper.lund | 7276f14 | 2008-07-30 08:49:36 +0000 | [diff] [blame] | 2103 | WRITE_BYTE_FIELD(this, kICFlagOffset, value); |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2104 | } |
| 2105 | |
| 2106 | |
| 2107 | byte* Code::instruction_start() { |
| 2108 | return FIELD_ADDR(this, kHeaderSize); |
| 2109 | } |
| 2110 | |
| 2111 | |
| 2112 | int Code::body_size() { |
| 2113 | return RoundUp(instruction_size() + relocation_size(), kObjectAlignment); |
| 2114 | } |
| 2115 | |
| 2116 | |
| 2117 | byte* Code::relocation_start() { |
| 2118 | return FIELD_ADDR(this, CodeSize() - sinfo_size() - relocation_size()); |
| 2119 | } |
| 2120 | |
| 2121 | |
| 2122 | byte* Code::entry() { |
| 2123 | return instruction_start(); |
| 2124 | } |
| 2125 | |
| 2126 | |
| 2127 | bool Code::contains(byte* pc) { |
| 2128 | return (instruction_start() <= pc) && |
| 2129 | (pc < instruction_start() + instruction_size()); |
| 2130 | } |
| 2131 | |
| 2132 | |
| 2133 | byte* Code::sinfo_start() { |
| 2134 | return FIELD_ADDR(this, CodeSize() - sinfo_size()); |
| 2135 | } |
| 2136 | |
| 2137 | |
| 2138 | ACCESSORS(JSArray, length, Object, kLengthOffset) |
| 2139 | |
| 2140 | |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2141 | ACCESSORS(JSRegExp, data, Object, kDataOffset) |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2142 | |
| 2143 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 2144 | JSRegExp::Type JSRegExp::TypeTag() { |
| 2145 | Object* data = this->data(); |
| 2146 | if (data->IsUndefined()) return JSRegExp::NOT_COMPILED; |
| 2147 | Smi* smi = Smi::cast(FixedArray::cast(data)->get(kTagIndex)); |
| 2148 | return static_cast<JSRegExp::Type>(smi->value()); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 2152 | Object* JSRegExp::DataAt(int index) { |
| 2153 | ASSERT(TypeTag() != NOT_COMPILED); |
| 2154 | return FixedArray::cast(data())->get(index); |
ager@chromium.org | 236ad96 | 2008-09-25 09:45:57 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
| 2157 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2158 | bool JSObject::HasFastElements() { |
| 2159 | return !elements()->IsDictionary(); |
| 2160 | } |
| 2161 | |
| 2162 | |
| 2163 | bool JSObject::HasNamedInterceptor() { |
| 2164 | return map()->has_named_interceptor(); |
| 2165 | } |
| 2166 | |
| 2167 | |
| 2168 | bool JSObject::HasIndexedInterceptor() { |
| 2169 | return map()->has_indexed_interceptor(); |
| 2170 | } |
| 2171 | |
| 2172 | |
| 2173 | Dictionary* JSObject::property_dictionary() { |
| 2174 | ASSERT(!HasFastProperties()); |
| 2175 | return Dictionary::cast(properties()); |
| 2176 | } |
| 2177 | |
| 2178 | |
| 2179 | Dictionary* JSObject::element_dictionary() { |
| 2180 | ASSERT(!HasFastElements()); |
| 2181 | return Dictionary::cast(elements()); |
| 2182 | } |
| 2183 | |
| 2184 | |
| 2185 | bool String::HasHashCode() { |
| 2186 | return (length_field() & kHashComputedMask) != 0; |
| 2187 | } |
| 2188 | |
| 2189 | |
| 2190 | uint32_t String::Hash() { |
| 2191 | // Fast case: has hash code already been computed? |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2192 | uint32_t field = length_field(); |
| 2193 | if (field & kHashComputedMask) return field >> kHashShift; |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2194 | // Slow case: compute hash code and set it. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2195 | return ComputeAndSetHash(); |
| 2196 | } |
| 2197 | |
| 2198 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2199 | StringHasher::StringHasher(int length) |
| 2200 | : length_(length), |
| 2201 | raw_running_hash_(0), |
| 2202 | array_index_(0), |
| 2203 | is_array_index_(0 < length_ && length_ <= String::kMaxArrayIndexSize), |
| 2204 | is_first_char_(true), |
| 2205 | is_valid_(true) { } |
| 2206 | |
| 2207 | |
| 2208 | bool StringHasher::has_trivial_hash() { |
| 2209 | return length_ > String::kMaxMediumStringSize; |
| 2210 | } |
| 2211 | |
| 2212 | |
| 2213 | void StringHasher::AddCharacter(uc32 c) { |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2214 | // Use the Jenkins one-at-a-time hash function to update the hash |
| 2215 | // for the given character. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2216 | raw_running_hash_ += c; |
| 2217 | raw_running_hash_ += (raw_running_hash_ << 10); |
| 2218 | raw_running_hash_ ^= (raw_running_hash_ >> 6); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2219 | // Incremental array index computation. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2220 | if (is_array_index_) { |
| 2221 | if (c < '0' || c > '9') { |
| 2222 | is_array_index_ = false; |
| 2223 | } else { |
| 2224 | int d = c - '0'; |
| 2225 | if (is_first_char_) { |
| 2226 | is_first_char_ = false; |
| 2227 | if (c == '0' && length_ > 1) { |
| 2228 | is_array_index_ = false; |
| 2229 | return; |
| 2230 | } |
| 2231 | } |
| 2232 | if (array_index_ > 429496729U - ((d + 2) >> 3)) { |
| 2233 | is_array_index_ = false; |
| 2234 | } else { |
| 2235 | array_index_ = array_index_ * 10 + d; |
| 2236 | } |
| 2237 | } |
| 2238 | } |
| 2239 | } |
| 2240 | |
| 2241 | |
| 2242 | void StringHasher::AddCharacterNoIndex(uc32 c) { |
| 2243 | ASSERT(!is_array_index()); |
| 2244 | raw_running_hash_ += c; |
| 2245 | raw_running_hash_ += (raw_running_hash_ << 10); |
| 2246 | raw_running_hash_ ^= (raw_running_hash_ >> 6); |
| 2247 | } |
| 2248 | |
| 2249 | |
| 2250 | uint32_t StringHasher::GetHash() { |
| 2251 | uint32_t result = raw_running_hash_; |
| 2252 | result += (result << 3); |
| 2253 | result ^= (result >> 11); |
| 2254 | result += (result << 15); |
| 2255 | return result; |
| 2256 | } |
| 2257 | |
| 2258 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2259 | bool String::AsArrayIndex(uint32_t* index) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2260 | uint32_t field = length_field(); |
| 2261 | if ((field & kHashComputedMask) && !(field & kIsArrayIndexMask)) return false; |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2262 | return SlowAsArrayIndex(index); |
| 2263 | } |
| 2264 | |
| 2265 | |
| 2266 | Object* JSObject::GetPrototype() { |
| 2267 | return JSObject::cast(this)->map()->prototype(); |
| 2268 | } |
| 2269 | |
| 2270 | |
| 2271 | PropertyAttributes JSObject::GetPropertyAttribute(String* key) { |
| 2272 | return GetPropertyAttributeWithReceiver(this, key); |
| 2273 | } |
| 2274 | |
| 2275 | |
| 2276 | bool JSObject::HasElement(uint32_t index) { |
| 2277 | return HasElementWithReceiver(this, index); |
| 2278 | } |
| 2279 | |
| 2280 | |
| 2281 | bool AccessorInfo::all_can_read() { |
| 2282 | return BooleanBit::get(flag(), kAllCanReadBit); |
| 2283 | } |
| 2284 | |
| 2285 | |
| 2286 | void AccessorInfo::set_all_can_read(bool value) { |
| 2287 | set_flag(BooleanBit::set(flag(), kAllCanReadBit, value)); |
| 2288 | } |
| 2289 | |
| 2290 | |
| 2291 | bool AccessorInfo::all_can_write() { |
| 2292 | return BooleanBit::get(flag(), kAllCanWriteBit); |
| 2293 | } |
| 2294 | |
| 2295 | |
| 2296 | void AccessorInfo::set_all_can_write(bool value) { |
| 2297 | set_flag(BooleanBit::set(flag(), kAllCanWriteBit, value)); |
| 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | PropertyAttributes AccessorInfo::property_attributes() { |
| 2302 | return AttributesField::decode(static_cast<uint32_t>(flag()->value())); |
| 2303 | } |
| 2304 | |
| 2305 | |
| 2306 | void AccessorInfo::set_property_attributes(PropertyAttributes attributes) { |
| 2307 | ASSERT(AttributesField::is_valid(attributes)); |
| 2308 | int rest_value = flag()->value() & ~AttributesField::mask(); |
| 2309 | set_flag(Smi::FromInt(rest_value | AttributesField::encode(attributes))); |
| 2310 | } |
| 2311 | |
| 2312 | void Dictionary::SetEntry(int entry, |
| 2313 | Object* key, |
| 2314 | Object* value, |
| 2315 | PropertyDetails details) { |
| 2316 | ASSERT(!key->IsString() || details.index() > 0); |
| 2317 | int index = EntryToIndex(entry); |
| 2318 | WriteBarrierMode mode = GetWriteBarrierMode(); |
| 2319 | set(index, key, mode); |
| 2320 | set(index+1, value, mode); |
| 2321 | fast_set(this, index+2, details.AsSmi()); |
| 2322 | } |
| 2323 | |
| 2324 | |
| 2325 | void Map::ClearCodeCache() { |
| 2326 | // No write barrier is needed since empty_fixed_array is not in new space. |
| 2327 | // Please note this function is used during marking: |
| 2328 | // - MarkCompactCollector::MarkUnmarkedObject |
| 2329 | ASSERT(!Heap::InNewSpace(Heap::empty_fixed_array())); |
| 2330 | WRITE_FIELD(this, kCodeCacheOffset, Heap::empty_fixed_array()); |
| 2331 | } |
| 2332 | |
| 2333 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2334 | void JSArray::SetContent(FixedArray* storage) { |
kasperl@chromium.org | 9fe21c6 | 2008-10-28 08:53:51 +0000 | [diff] [blame^] | 2335 | set_length(Smi::FromInt(storage->length()), SKIP_WRITE_BARRIER); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2336 | set_elements(storage); |
| 2337 | } |
| 2338 | |
| 2339 | |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2340 | Object* FixedArray::Copy() { |
| 2341 | if (length() == 0) return this; |
| 2342 | return Heap::CopyFixedArray(this); |
| 2343 | } |
| 2344 | |
| 2345 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2346 | #undef CAST_ACCESSOR |
| 2347 | #undef INT_ACCESSORS |
| 2348 | #undef SMI_ACCESSORS |
| 2349 | #undef ACCESSORS |
| 2350 | #undef FIELD_ADDR |
| 2351 | #undef READ_FIELD |
| 2352 | #undef WRITE_FIELD |
| 2353 | #undef WRITE_BARRIER |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 2354 | #undef CONDITIONAL_WRITE_BARRIER |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 2355 | #undef READ_MEMADDR_FIELD |
| 2356 | #undef WRITE_MEMADDR_FIELD |
| 2357 | #undef READ_DOUBLE_FIELD |
| 2358 | #undef WRITE_DOUBLE_FIELD |
| 2359 | #undef READ_INT_FIELD |
| 2360 | #undef WRITE_INT_FIELD |
| 2361 | #undef READ_SHORT_FIELD |
| 2362 | #undef WRITE_SHORT_FIELD |
| 2363 | #undef READ_BYTE_FIELD |
| 2364 | #undef WRITE_BYTE_FIELD |
| 2365 | |
| 2366 | |
| 2367 | } } // namespace v8::internal |
| 2368 | |
| 2369 | #endif // V8_OBJECTS_INL_H_ |