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