Chromium Code Reviews| 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 3349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3360 static const int kSmiShiftSize = 0; | 3360 static const int kSmiShiftSize = 0; |
| 3361 static const int kSmiValueSize = 31; | 3361 static const int kSmiValueSize = 31; |
| 3362 static inline int SmiToInt(internal::Object* value) { | 3362 static inline int SmiToInt(internal::Object* value) { |
| 3363 int shift_bits = kSmiTagSize + kSmiShiftSize; | 3363 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3364 // Throw away top 32 bits and shift down (requires >> to be sign extending). | 3364 // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 3365 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | 3365 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 3366 } | 3366 } |
| 3367 | 3367 |
| 3368 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi | 3368 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi |
| 3369 // with a plain reinterpret_cast. | 3369 // with a plain reinterpret_cast. |
| 3370 static const intptr_t kEncodablePointerMask = 0x1; | 3370 static const uintptr_t kEncodablePointerMask = 0x1; |
| 3371 static const int kPointerToSmiShift = 0; | 3371 static const int kPointerToSmiShift = 0; |
| 3372 }; | 3372 }; |
| 3373 | 3373 |
| 3374 // Smi constants for 64-bit systems. | 3374 // Smi constants for 64-bit systems. |
| 3375 template <> struct SmiTagging<8> { | 3375 template <> struct SmiTagging<8> { |
| 3376 static const int kSmiShiftSize = 31; | 3376 static const int kSmiShiftSize = 31; |
| 3377 static const int kSmiValueSize = 32; | 3377 static const int kSmiValueSize = 32; |
| 3378 static inline int SmiToInt(internal::Object* value) { | 3378 static inline int SmiToInt(internal::Object* value) { |
| 3379 int shift_bits = kSmiTagSize + kSmiShiftSize; | 3379 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3380 // Shift down and throw away top 32 bits. | 3380 // Shift down and throw away top 32 bits. |
| 3381 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 3381 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 3382 } | 3382 } |
| 3383 | 3383 |
| 3384 // To maximize the range of pointers that can be encoded | 3384 // To maximize the range of pointers that can be encoded |
| 3385 // in the available 32 bits, we require them to be 8 bytes aligned. | 3385 // in the available 32 bits, we require them to be 8 bytes aligned. |
| 3386 // This gives 2 ^ (32 + 3) = 32G address space covered. | 3386 // This gives 2 ^ (32 + 3) = 32G address space covered. |
| 3387 // It might be not enough to cover stack allocated objects on some platforms. | 3387 // It might be not enough to cover stack allocated objects on some platforms. |
| 3388 static const int kPointerAlignment = 3; | 3388 static const int kPointerAlignment = 3; |
| 3389 | 3389 |
| 3390 static const intptr_t kEncodablePointerMask = | 3390 static const uintptr_t kEncodablePointerMask = |
| 3391 ~(intptr_t(0xffffffff) << kPointerAlignment); | 3391 ~(intptr_t(0xffffffff) << kPointerAlignment); |
|
Vyacheslav Egorov (Chromium)
2011/01/19 10:19:43
intptr_t => uintptr_t
antonm
2011/01/19 11:16:00
Done.
| |
| 3392 | 3392 |
| 3393 static const int kPointerToSmiShift = | 3393 static const int kPointerToSmiShift = |
| 3394 kSmiTagSize + kSmiShiftSize - kPointerAlignment; | 3394 kSmiTagSize + kSmiShiftSize - kPointerAlignment; |
| 3395 }; | 3395 }; |
| 3396 | 3396 |
| 3397 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; | 3397 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 3398 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; | 3398 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 3399 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; | 3399 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
| 3400 const intptr_t kEncodablePointerMask = | 3400 const uintptr_t kEncodablePointerMask = |
| 3401 PlatformSmiTagging::kEncodablePointerMask; | 3401 PlatformSmiTagging::kEncodablePointerMask; |
| 3402 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; | 3402 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; |
| 3403 | 3403 |
| 3404 template <size_t ptr_size> struct InternalConstants; | 3404 template <size_t ptr_size> struct InternalConstants; |
| 3405 | 3405 |
| 3406 // Internal constants for 32-bit systems. | 3406 // Internal constants for 32-bit systems. |
| 3407 template <> struct InternalConstants<4> { | 3407 template <> struct InternalConstants<4> { |
| 3408 static const int kStringResourceOffset = 3 * kApiPointerSize; | 3408 static const int kStringResourceOffset = 3 * kApiPointerSize; |
| 3409 }; | 3409 }; |
| 3410 | 3410 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3450 return PlatformSmiTagging::SmiToInt(value); | 3450 return PlatformSmiTagging::SmiToInt(value); |
| 3451 } | 3451 } |
| 3452 | 3452 |
| 3453 static inline int GetInstanceType(internal::Object* obj) { | 3453 static inline int GetInstanceType(internal::Object* obj) { |
| 3454 typedef internal::Object O; | 3454 typedef internal::Object O; |
| 3455 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 3455 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 3456 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 3456 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 3457 } | 3457 } |
| 3458 | 3458 |
| 3459 static inline void* GetExternalPointerFromSmi(internal::Object* value) { | 3459 static inline void* GetExternalPointerFromSmi(internal::Object* value) { |
| 3460 const intptr_t address = reinterpret_cast<intptr_t>(value); | 3460 const uintptr_t address = reinterpret_cast<intptr_t>(value); |
|
Vyacheslav Egorov (Chromium)
2011/01/19 10:19:43
<intptr_t> => <uintptr_t>
antonm
2011/01/19 11:16:00
Done.
| |
| 3461 return reinterpret_cast<void*>(address >> kPointerToSmiShift); | 3461 return reinterpret_cast<void*>(address >> kPointerToSmiShift); |
| 3462 } | 3462 } |
| 3463 | 3463 |
| 3464 static inline void* GetExternalPointer(internal::Object* obj) { | 3464 static inline void* GetExternalPointer(internal::Object* obj) { |
| 3465 if (HasSmiTag(obj)) { | 3465 if (HasSmiTag(obj)) { |
| 3466 return GetExternalPointerFromSmi(obj); | 3466 return GetExternalPointerFromSmi(obj); |
| 3467 } else if (GetInstanceType(obj) == kProxyType) { | 3467 } else if (GetInstanceType(obj) == kProxyType) { |
| 3468 return ReadField<void*>(obj, kProxyProxyOffset); | 3468 return ReadField<void*>(obj, kProxyProxyOffset); |
| 3469 } else { | 3469 } else { |
| 3470 return NULL; | 3470 return NULL; |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3823 | 3823 |
| 3824 | 3824 |
| 3825 } // namespace v8 | 3825 } // namespace v8 |
| 3826 | 3826 |
| 3827 | 3827 |
| 3828 #undef V8EXPORT | 3828 #undef V8EXPORT |
| 3829 #undef TYPE_CHECK | 3829 #undef TYPE_CHECK |
| 3830 | 3830 |
| 3831 | 3831 |
| 3832 #endif // V8_H_ | 3832 #endif // V8_H_ |
| OLD | NEW |