| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_GLOBALS_H_ | 28 #ifndef V8_GLOBALS_H_ |
| 29 #define V8_GLOBALS_H_ | 29 #define V8_GLOBALS_H_ |
| 30 | 30 |
| 31 namespace v8 { namespace internal { | 31 namespace v8 { namespace internal { |
| 32 | 32 |
| 33 // Processor architecture detection. For more info on what's defined, see: |
| 34 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx |
| 35 // http://www.agner.org/optimize/calling_conventions.pdf |
| 36 // or with gcc, run: "echo | gcc -E -dM -" |
| 37 #if defined(_M_X64) || defined(__x86_64__) |
| 38 #define V8_HOST_ARCH_X64 1 |
| 39 #define V8_HOST_ARCH_64_BIT 1 |
| 40 #define V8_HOST_CAN_READ_UNALIGNED 1 |
| 41 #elif defined(_M_IX86) || defined(__i386__) |
| 42 #define V8_HOST_ARCH_IA32 1 |
| 43 #define V8_HOST_ARCH_32_BIT 1 |
| 44 #define V8_HOST_CAN_READ_UNALIGNED 1 |
| 45 #elif defined(__ARMEL__) |
| 46 #define V8_HOST_ARCH_ARM 1 |
| 47 #define V8_HOST_ARCH_32_BIT 1 |
| 48 #else |
| 49 #error Your architecture was not detected as supported by v8 |
| 50 #endif |
| 51 |
| 33 // Support for alternative bool type. This is only enabled if the code is | 52 // Support for alternative bool type. This is only enabled if the code is |
| 34 // compiled with USE_MYBOOL defined. This catches some nasty type bugs. | 53 // compiled with USE_MYBOOL defined. This catches some nasty type bugs. |
| 35 // For instance, 'bool b = "false";' results in b == true! This is a hidden | 54 // For instance, 'bool b = "false";' results in b == true! This is a hidden |
| 36 // source of bugs. | 55 // source of bugs. |
| 37 // However, redefining the bool type does have some negative impact on some | 56 // However, redefining the bool type does have some negative impact on some |
| 38 // platforms. It gives rise to compiler warnings (i.e. with | 57 // platforms. It gives rise to compiler warnings (i.e. with |
| 39 // MSVC) in the API header files when mixing code that uses the standard | 58 // MSVC) in the API header files when mixing code that uses the standard |
| 40 // bool with code that uses the redefined version. | 59 // bool with code that uses the redefined version. |
| 41 // This does not actually belong in the platform code, but needs to be | 60 // This does not actually belong in the platform code, but needs to be |
| 42 // defined here because the platform code uses bool, and platform.h is | 61 // defined here because the platform code uses bool, and platform.h is |
| 43 // include very early in the main include file. | 62 // include very early in the main include file. |
| 44 | 63 |
| 45 #ifdef USE_MYBOOL | 64 #ifdef USE_MYBOOL |
| 46 typedef unsigned int __my_bool__; | 65 typedef unsigned int __my_bool__; |
| 47 #define bool __my_bool__ // use 'indirection' to avoid name clashes | 66 #define bool __my_bool__ // use 'indirection' to avoid name clashes |
| 48 #endif | 67 #endif |
| 49 | 68 |
| 50 typedef uint8_t byte; | 69 typedef uint8_t byte; |
| 51 typedef byte* Address; | 70 typedef byte* Address; |
| 52 | 71 |
| 53 // Define our own macros for writing 64-bit constants. This is less fragile | 72 // Define our own macros for writing 64-bit constants. This is less fragile |
| 54 // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it | 73 // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it |
| 55 // works on compilers that don't have it (like MSVC). | 74 // works on compilers that don't have it (like MSVC). |
| 75 #if V8_HOST_ARCH_64_BIT |
| 56 #ifdef _MSC_VER | 76 #ifdef _MSC_VER |
| 57 #define V8_UINT64_C(x) (x ## UI64) | 77 #define V8_UINT64_C(x) (x ## UI64) |
| 58 #define V8_INT64_C(x) (x ## I64) | 78 #define V8_INT64_C(x) (x ## I64) |
| 59 #else | 79 #else |
| 60 #define V8_UINT64_C(x) (x ## ULL) | 80 #define V8_UINT64_C(x) (x ## UL) |
| 61 #define V8_INT64_C(x) (x ## LL) | 81 #define V8_INT64_C(x) (x ## L) |
| 62 #endif | 82 #endif |
| 83 #endif // V8_HOST_ARCH_64_BIT |
| 63 | 84 |
| 64 // Code-point values in Unicode 4.0 are 21 bits wide. | 85 // Code-point values in Unicode 4.0 are 21 bits wide. |
| 65 typedef uint16_t uc16; | 86 typedef uint16_t uc16; |
| 66 typedef int32_t uc32; | 87 typedef int32_t uc32; |
| 67 | 88 |
| 68 #if defined(V8_ARCH_IA32) || defined(V8_ARCH_X64) | |
| 69 #define CAN_READ_UNALIGNED 1 | |
| 70 #endif | |
| 71 | |
| 72 // ----------------------------------------------------------------------------- | 89 // ----------------------------------------------------------------------------- |
| 73 // Constants | 90 // Constants |
| 74 | 91 |
| 75 const int KB = 1024; | 92 const int KB = 1024; |
| 76 const int MB = KB * KB; | 93 const int MB = KB * KB; |
| 77 const int GB = KB * KB * KB; | 94 const int GB = KB * KB * KB; |
| 78 const int kMaxInt = 0x7FFFFFFF; | 95 const int kMaxInt = 0x7FFFFFFF; |
| 79 const int kMinInt = -kMaxInt - 1; | 96 const int kMinInt = -kMaxInt - 1; |
| 80 | 97 |
| 81 const uint32_t kMaxUInt32 = 0xFFFFFFFFu; | 98 const uint32_t kMaxUInt32 = 0xFFFFFFFFu; |
| 82 | 99 |
| 83 const int kCharSize = sizeof(char); // NOLINT | 100 const int kCharSize = sizeof(char); // NOLINT |
| 84 const int kShortSize = sizeof(short); // NOLINT | 101 const int kShortSize = sizeof(short); // NOLINT |
| 85 const int kIntSize = sizeof(int); // NOLINT | 102 const int kIntSize = sizeof(int); // NOLINT |
| 86 const int kDoubleSize = sizeof(double); // NOLINT | 103 const int kDoubleSize = sizeof(double); // NOLINT |
| 87 const int kPointerSize = sizeof(void*); // NOLINT | 104 const int kPointerSize = sizeof(void*); // NOLINT |
| 88 | 105 |
| 89 #ifdef V8_ARCH_X64 | 106 #if V8_HOST_ARCH_64_BIT |
| 90 const int kPointerSizeLog2 = 3; | 107 const int kPointerSizeLog2 = 3; |
| 91 #else | 108 #else |
| 92 const int kPointerSizeLog2 = 2; | 109 const int kPointerSizeLog2 = 2; |
| 93 #endif | 110 #endif |
| 94 | 111 |
| 95 const int kObjectAlignmentBits = kPointerSizeLog2; | 112 const int kObjectAlignmentBits = kPointerSizeLog2; |
| 96 const intptr_t kObjectAlignmentMask = (1 << kObjectAlignmentBits) - 1; | 113 const intptr_t kObjectAlignmentMask = (1 << kObjectAlignmentBits) - 1; |
| 97 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits; | 114 const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits; |
| 98 | 115 |
| 99 | 116 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 116 | 133 |
| 117 | 134 |
| 118 const int kBitsPerByte = 8; | 135 const int kBitsPerByte = 8; |
| 119 const int kBitsPerByteLog2 = 3; | 136 const int kBitsPerByteLog2 = 3; |
| 120 const int kBitsPerPointer = kPointerSize * kBitsPerByte; | 137 const int kBitsPerPointer = kPointerSize * kBitsPerByte; |
| 121 const int kBitsPerInt = kIntSize * kBitsPerByte; | 138 const int kBitsPerInt = kIntSize * kBitsPerByte; |
| 122 | 139 |
| 123 | 140 |
| 124 // Zap-value: The value used for zapping dead objects. | 141 // Zap-value: The value used for zapping dead objects. |
| 125 // Should be a recognizable hex value tagged as a heap object pointer. | 142 // Should be a recognizable hex value tagged as a heap object pointer. |
| 126 #ifdef V8_ARCH_X64 | 143 #ifdef V8_HOST_ARCH_64_BIT |
| 127 const Address kZapValue = | 144 const Address kZapValue = |
| 128 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeed)); | 145 reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeed)); |
| 129 const Address kHandleZapValue = | 146 const Address kHandleZapValue = |
| 130 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddead)); | 147 reinterpret_cast<Address>(V8_UINT64_C(0x1baddead0baddead)); |
| 131 const Address kFromSpaceZapValue = | 148 const Address kFromSpaceZapValue = |
| 132 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdad)); | 149 reinterpret_cast<Address>(V8_UINT64_C(0x1beefdad0beefdad)); |
| 133 #else | 150 #else |
| 134 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeed); | 151 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeed); |
| 135 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddead); | 152 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddead); |
| 136 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdad); | 153 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdad); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 // float f = foo(); | 503 // float f = foo(); |
| 487 // int fbits = *(int*)(&f); | 504 // int fbits = *(int*)(&f); |
| 488 // | 505 // |
| 489 // The compiler 'knows' that the int pointer can't refer to f since the types | 506 // The compiler 'knows' that the int pointer can't refer to f since the types |
| 490 // don't match, so the compiler may cache f in a register, leaving random data | 507 // don't match, so the compiler may cache f in a register, leaving random data |
| 491 // in fbits. Using C++ style casts makes no difference, however a pointer to | 508 // in fbits. Using C++ style casts makes no difference, however a pointer to |
| 492 // char data is assumed to alias any other pointer. This is the 'memcpy | 509 // char data is assumed to alias any other pointer. This is the 'memcpy |
| 493 // exception'. | 510 // exception'. |
| 494 // | 511 // |
| 495 // Bit_cast uses the memcpy exception to move the bits from a variable of one | 512 // Bit_cast uses the memcpy exception to move the bits from a variable of one |
| 496 // type o a variable of another type. Of course the end result is likely to | 513 // type of a variable of another type. Of course the end result is likely to |
| 497 // be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005) | 514 // be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005) |
| 498 // will completely optimize bit_cast away. | 515 // will completely optimize bit_cast away. |
| 499 // | 516 // |
| 500 // There is an additional use for bit_cast. | 517 // There is an additional use for bit_cast. |
| 501 // Recent gccs will warn when they see casts that may result in breakage due to | 518 // Recent gccs will warn when they see casts that may result in breakage due to |
| 502 // the type-based aliasing rule. If you have checked that there is no breakage | 519 // the type-based aliasing rule. If you have checked that there is no breakage |
| 503 // you can use bit_cast to cast one pointer type to another. This confuses gcc | 520 // you can use bit_cast to cast one pointer type to another. This confuses gcc |
| 504 // enough that it can no longer see that you have cast one pointer type to | 521 // enough that it can no longer see that you have cast one pointer type to |
| 505 // another thus avoiding the warning. | 522 // another thus avoiding the warning. |
| 506 template <class Dest, class Source> | 523 template <class Dest, class Source> |
| 507 inline Dest bit_cast(const Source& source) { | 524 inline Dest bit_cast(const Source& source) { |
| 508 // Compile time assertion: sizeof(Dest) == sizeof(Source) | 525 // Compile time assertion: sizeof(Dest) == sizeof(Source) |
| 509 // A compile error here means your Dest and Source have different sizes. | 526 // A compile error here means your Dest and Source have different sizes. |
| 510 typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1]; | 527 typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1]; |
| 511 | 528 |
| 512 Dest dest; | 529 Dest dest; |
| 513 memcpy(&dest, &source, sizeof(dest)); | 530 memcpy(&dest, &source, sizeof(dest)); |
| 514 return dest; | 531 return dest; |
| 515 } | 532 } |
| 516 | 533 |
| 517 | 534 |
| 518 } } // namespace v8::internal | 535 } } // namespace v8::internal |
| 519 | 536 |
| 520 #endif // V8_GLOBALS_H_ | 537 #endif // V8_GLOBALS_H_ |
| OLD | NEW |