| OLD | NEW |
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 3278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3289 // Tag information for HeapObject. | 3289 // Tag information for HeapObject. |
| 3290 const int kHeapObjectTag = 1; | 3290 const int kHeapObjectTag = 1; |
| 3291 const int kHeapObjectTagSize = 2; | 3291 const int kHeapObjectTagSize = 2; |
| 3292 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; | 3292 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 3293 | 3293 |
| 3294 // Tag information for Smi. | 3294 // Tag information for Smi. |
| 3295 const int kSmiTag = 0; | 3295 const int kSmiTag = 0; |
| 3296 const int kSmiTagSize = 1; | 3296 const int kSmiTagSize = 1; |
| 3297 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | 3297 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 3298 | 3298 |
| 3299 template <size_t ptr_size> struct SmiConstants; | 3299 template <size_t ptr_size> struct SmiTagging; |
| 3300 | 3300 |
| 3301 // Smi constants for 32-bit systems. | 3301 // Smi constants for 32-bit systems. |
| 3302 template <> struct SmiConstants<4> { | 3302 template <> struct SmiTagging<4> { |
| 3303 static const int kSmiShiftSize = 0; | 3303 static const int kSmiShiftSize = 0; |
| 3304 static const int kSmiValueSize = 31; | 3304 static const int kSmiValueSize = 31; |
| 3305 static inline int SmiToInt(internal::Object* value) { | 3305 static inline int SmiToInt(internal::Object* value) { |
| 3306 int shift_bits = kSmiTagSize + kSmiShiftSize; | 3306 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3307 // Throw away top 32 bits and shift down (requires >> to be sign extending). | 3307 // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 3308 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | 3308 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 3309 } | 3309 } |
| 3310 |
| 3311 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi |
| 3312 // with a plain reinterpret_cast. |
| 3313 static const intptr_t kEncodablePointerMask = 0x1; |
| 3314 static const int kPointerToSmiShift = 0; |
| 3310 }; | 3315 }; |
| 3311 | 3316 |
| 3312 // Smi constants for 64-bit systems. | 3317 // Smi constants for 64-bit systems. |
| 3313 template <> struct SmiConstants<8> { | 3318 template <> struct SmiTagging<8> { |
| 3314 static const int kSmiShiftSize = 31; | 3319 static const int kSmiShiftSize = 31; |
| 3315 static const int kSmiValueSize = 32; | 3320 static const int kSmiValueSize = 32; |
| 3316 static inline int SmiToInt(internal::Object* value) { | 3321 static inline int SmiToInt(internal::Object* value) { |
| 3317 int shift_bits = kSmiTagSize + kSmiShiftSize; | 3322 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3318 // Shift down and throw away top 32 bits. | 3323 // Shift down and throw away top 32 bits. |
| 3319 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 3324 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 3320 } | 3325 } |
| 3326 |
| 3327 // To maximize the range of pointers that can be encoded |
| 3328 // in the available 32 bits, we require them to be 8 bytes aligned. |
| 3329 // This gives 2 ^ (32 + 3) = 32G address space covered. |
| 3330 // It might be not enough to cover stack allocated objects on some platforms. |
| 3331 static const int kPointerAlignment = 3; |
| 3332 |
| 3333 static const intptr_t kEncodablePointerMask = |
| 3334 ~(intptr_t(0xffffffff) << kPointerAlignment); |
| 3335 |
| 3336 static const int kPointerToSmiShift = |
| 3337 kSmiTagSize + kSmiShiftSize - kPointerAlignment; |
| 3321 }; | 3338 }; |
| 3322 | 3339 |
| 3323 const int kSmiShiftSize = SmiConstants<sizeof(void*)>::kSmiShiftSize; | 3340 typedef SmiTagging<sizeof(void*)> PlatformSmiTagging; |
| 3324 const int kSmiValueSize = SmiConstants<sizeof(void*)>::kSmiValueSize; | 3341 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 3342 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
| 3343 const intptr_t kEncodablePointerMask = |
| 3344 PlatformSmiTagging::kEncodablePointerMask; |
| 3345 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; |
| 3325 | 3346 |
| 3326 template <size_t ptr_size> struct InternalConstants; | 3347 template <size_t ptr_size> struct InternalConstants; |
| 3327 | 3348 |
| 3328 // Internal constants for 32-bit systems. | 3349 // Internal constants for 32-bit systems. |
| 3329 template <> struct InternalConstants<4> { | 3350 template <> struct InternalConstants<4> { |
| 3330 static const int kStringResourceOffset = 3 * sizeof(void*); | 3351 static const int kStringResourceOffset = 3 * sizeof(void*); |
| 3331 }; | 3352 }; |
| 3332 | 3353 |
| 3333 // Internal constants for 64-bit systems. | 3354 // Internal constants for 64-bit systems. |
| 3334 template <> struct InternalConstants<8> { | 3355 template <> struct InternalConstants<8> { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 3362 static inline bool HasHeapObjectTag(internal::Object* value) { | 3383 static inline bool HasHeapObjectTag(internal::Object* value) { |
| 3363 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 3384 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 3364 kHeapObjectTag); | 3385 kHeapObjectTag); |
| 3365 } | 3386 } |
| 3366 | 3387 |
| 3367 static inline bool HasSmiTag(internal::Object* value) { | 3388 static inline bool HasSmiTag(internal::Object* value) { |
| 3368 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); | 3389 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
| 3369 } | 3390 } |
| 3370 | 3391 |
| 3371 static inline int SmiValue(internal::Object* value) { | 3392 static inline int SmiValue(internal::Object* value) { |
| 3372 return SmiConstants<sizeof(void*)>::SmiToInt(value); | 3393 return PlatformSmiTagging::SmiToInt(value); |
| 3373 } | 3394 } |
| 3374 | 3395 |
| 3375 static inline int GetInstanceType(internal::Object* obj) { | 3396 static inline int GetInstanceType(internal::Object* obj) { |
| 3376 typedef internal::Object O; | 3397 typedef internal::Object O; |
| 3377 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 3398 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 3378 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 3399 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 3379 } | 3400 } |
| 3380 | 3401 |
| 3402 static inline void* GetExternalPointerFromSmi(internal::Object* value) { |
| 3403 const intptr_t address = reinterpret_cast<intptr_t>(value); |
| 3404 return reinterpret_cast<void*>(address >> kPointerToSmiShift); |
| 3405 } |
| 3406 |
| 3381 static inline void* GetExternalPointer(internal::Object* obj) { | 3407 static inline void* GetExternalPointer(internal::Object* obj) { |
| 3382 if (HasSmiTag(obj)) { | 3408 if (HasSmiTag(obj)) { |
| 3383 return obj; | 3409 return GetExternalPointerFromSmi(obj); |
| 3384 } else if (GetInstanceType(obj) == kProxyType) { | 3410 } else if (GetInstanceType(obj) == kProxyType) { |
| 3385 return ReadField<void*>(obj, kProxyProxyOffset); | 3411 return ReadField<void*>(obj, kProxyProxyOffset); |
| 3386 } else { | 3412 } else { |
| 3387 return NULL; | 3413 return NULL; |
| 3388 } | 3414 } |
| 3389 } | 3415 } |
| 3390 | 3416 |
| 3391 static inline bool IsExternalTwoByteString(int instance_type) { | 3417 static inline bool IsExternalTwoByteString(int instance_type) { |
| 3392 int representation = (instance_type & kFullStringRepresentationMask); | 3418 int representation = (instance_type & kFullStringRepresentationMask); |
| 3393 return representation == kExternalTwoByteRepresentationTag; | 3419 return representation == kExternalTwoByteRepresentationTag; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3740 | 3766 |
| 3741 | 3767 |
| 3742 } // namespace v8 | 3768 } // namespace v8 |
| 3743 | 3769 |
| 3744 | 3770 |
| 3745 #undef V8EXPORT | 3771 #undef V8EXPORT |
| 3746 #undef TYPE_CHECK | 3772 #undef TYPE_CHECK |
| 3747 | 3773 |
| 3748 | 3774 |
| 3749 #endif // V8_H_ | 3775 #endif // V8_H_ |
| OLD | NEW |