| 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 3292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 3310 |
| 3311 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi | 3311 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi |
| 3312 // with a plain reinterpret_cast. | 3312 // with a plain reinterpret_cast. |
| 3313 static const intptr_t kEncodablePointerMask = 0x1; | 3313 static const uintptr_t kEncodablePointerMask = 0x1; |
| 3314 static const int kPointerToSmiShift = 0; | 3314 static const int kPointerToSmiShift = 0; |
| 3315 }; | 3315 }; |
| 3316 | 3316 |
| 3317 // Smi constants for 64-bit systems. | 3317 // Smi constants for 64-bit systems. |
| 3318 template <> struct SmiTagging<8> { | 3318 template <> struct SmiTagging<8> { |
| 3319 static const int kSmiShiftSize = 31; | 3319 static const int kSmiShiftSize = 31; |
| 3320 static const int kSmiValueSize = 32; | 3320 static const int kSmiValueSize = 32; |
| 3321 static inline int SmiToInt(internal::Object* value) { | 3321 static inline int SmiToInt(internal::Object* value) { |
| 3322 int shift_bits = kSmiTagSize + kSmiShiftSize; | 3322 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3323 // Shift down and throw away top 32 bits. | 3323 // Shift down and throw away top 32 bits. |
| 3324 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 3324 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 3325 } | 3325 } |
| 3326 | 3326 |
| 3327 // To maximize the range of pointers that can be encoded | 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. | 3328 // in the available 32 bits, we require them to be 8 bytes aligned. |
| 3329 // This gives 2 ^ (32 + 3) = 32G address space covered. | 3329 // This gives 2 ^ (32 + 3) = 32G address space covered. |
| 3330 // It might be not enough to cover stack allocated objects on some platforms. | 3330 // It might be not enough to cover stack allocated objects on some platforms. |
| 3331 static const int kPointerAlignment = 3; | 3331 static const int kPointerAlignment = 3; |
| 3332 | 3332 |
| 3333 static const intptr_t kEncodablePointerMask = | 3333 static const uintptr_t kEncodablePointerMask = |
| 3334 ~(intptr_t(0xffffffff) << kPointerAlignment); | 3334 ~(uintptr_t(0xffffffff) << kPointerAlignment); |
| 3335 | 3335 |
| 3336 static const int kPointerToSmiShift = | 3336 static const int kPointerToSmiShift = |
| 3337 kSmiTagSize + kSmiShiftSize - kPointerAlignment; | 3337 kSmiTagSize + kSmiShiftSize - kPointerAlignment; |
| 3338 }; | 3338 }; |
| 3339 | 3339 |
| 3340 typedef SmiTagging<sizeof(void*)> PlatformSmiTagging; | 3340 typedef SmiTagging<sizeof(void*)> PlatformSmiTagging; |
| 3341 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; | 3341 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 3342 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; | 3342 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
| 3343 const intptr_t kEncodablePointerMask = | 3343 const uintptr_t kEncodablePointerMask = |
| 3344 PlatformSmiTagging::kEncodablePointerMask; | 3344 PlatformSmiTagging::kEncodablePointerMask; |
| 3345 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; | 3345 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; |
| 3346 | 3346 |
| 3347 template <size_t ptr_size> struct InternalConstants; | 3347 template <size_t ptr_size> struct InternalConstants; |
| 3348 | 3348 |
| 3349 // Internal constants for 32-bit systems. | 3349 // Internal constants for 32-bit systems. |
| 3350 template <> struct InternalConstants<4> { | 3350 template <> struct InternalConstants<4> { |
| 3351 static const int kStringResourceOffset = 3 * sizeof(void*); | 3351 static const int kStringResourceOffset = 3 * sizeof(void*); |
| 3352 }; | 3352 }; |
| 3353 | 3353 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3393 return PlatformSmiTagging::SmiToInt(value); | 3393 return PlatformSmiTagging::SmiToInt(value); |
| 3394 } | 3394 } |
| 3395 | 3395 |
| 3396 static inline int GetInstanceType(internal::Object* obj) { | 3396 static inline int GetInstanceType(internal::Object* obj) { |
| 3397 typedef internal::Object O; | 3397 typedef internal::Object O; |
| 3398 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 3398 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 3399 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 3399 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 3400 } | 3400 } |
| 3401 | 3401 |
| 3402 static inline void* GetExternalPointerFromSmi(internal::Object* value) { | 3402 static inline void* GetExternalPointerFromSmi(internal::Object* value) { |
| 3403 const intptr_t address = reinterpret_cast<intptr_t>(value); | 3403 const uintptr_t address = reinterpret_cast<uintptr_t>(value); |
| 3404 return reinterpret_cast<void*>(address >> kPointerToSmiShift); | 3404 return reinterpret_cast<void*>(address >> kPointerToSmiShift); |
| 3405 } | 3405 } |
| 3406 | 3406 |
| 3407 static inline void* GetExternalPointer(internal::Object* obj) { | 3407 static inline void* GetExternalPointer(internal::Object* obj) { |
| 3408 if (HasSmiTag(obj)) { | 3408 if (HasSmiTag(obj)) { |
| 3409 return GetExternalPointerFromSmi(obj); | 3409 return GetExternalPointerFromSmi(obj); |
| 3410 } else if (GetInstanceType(obj) == kProxyType) { | 3410 } else if (GetInstanceType(obj) == kProxyType) { |
| 3411 return ReadField<void*>(obj, kProxyProxyOffset); | 3411 return ReadField<void*>(obj, kProxyProxyOffset); |
| 3412 } else { | 3412 } else { |
| 3413 return NULL; | 3413 return NULL; |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3766 | 3766 |
| 3767 | 3767 |
| 3768 } // namespace v8 | 3768 } // namespace v8 |
| 3769 | 3769 |
| 3770 | 3770 |
| 3771 #undef V8EXPORT | 3771 #undef V8EXPORT |
| 3772 #undef TYPE_CHECK | 3772 #undef TYPE_CHECK |
| 3773 | 3773 |
| 3774 | 3774 |
| 3775 #endif // V8_H_ | 3775 #endif // V8_H_ |
| OLD | NEW |