From aa5f53101f59340e719477f8a52c8eb3751f5023 Mon Sep 17 00:00:00 2001 From: "whesse@chromium.org" Date: Mon, 4 May 2009 13:29:29 +0000 Subject: [PATCH] Include 64-bit pointer and constant types in include/v8.h. Make some definitions in globals.h 64-bit safe Review URL: http://codereview.chromium.org/100336 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1844 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- include/v8.h | 9 ++++++-- src/globals.h | 66 +++++++++++++++++++++++++++++++---------------------------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/include/v8.h b/include/v8.h index ee4951d..068a1cd 100644 --- a/include/v8.h +++ b/include/v8.h @@ -41,10 +41,15 @@ #include #ifdef _WIN32 +typedef signed char int8_t; +typedef unsigned char uint8_t; +typedef short int16_t; // NOLINT +typedef unsigned short uint16_t; // NOLINT typedef int int32_t; typedef unsigned int uint32_t; -typedef unsigned short uint16_t; // NOLINT -typedef long long int64_t; // NOLINT +typedef __int64 int64_t; +typedef unsigned __int64 uint64_t; +// intptr_t is defined in crtdefs.h through stdio.h. // Setup for Windows DLL export/import. When building the V8 DLL the // BUILDING_V8_SHARED needs to be defined. When building a program which uses diff --git a/src/globals.h b/src/globals.h index 5d2ac04..35208c4 100644 --- a/src/globals.h +++ b/src/globals.h @@ -28,25 +28,6 @@ #ifndef V8_GLOBALS_H_ #define V8_GLOBALS_H_ -// ----------------------------------------------------------------------------- -// Types -// Visual Studio C++ is missing the stdint.h header file. Instead we define -// standard integer types for Windows here. - -#ifdef _MSC_VER -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef short int16_t; // NOLINT -typedef unsigned short uint16_t; // NOLINT -typedef int int32_t; -typedef unsigned int uint32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -#else // _MSC_VER -#include // for intptr_t -#endif // _MSC_VER - - namespace v8 { namespace internal { // Support for alternative bool type. This is only enabled if the code is @@ -69,9 +50,18 @@ typedef unsigned int __my_bool__; typedef uint8_t byte; typedef byte* Address; +// Define macros for writing 64-bit constants and pointer-size constants. +#ifdef _MSC_VER +#define UINT64_C(x) (x ## UI64) +#define INT64_C(x) (x ## I64) +#else +#define UINT64_C(x) (x ## ULL) +#define INT64_C(x) (x ## LL) +#endif + // Code-point values in Unicode 4.0 are 21 bits wide. typedef uint16_t uc16; -typedef signed int uc32; +typedef int32_t uc32; #if defined(V8_ARCH_IA32) || defined(V8_ARCH_X64) #define CAN_READ_UNALIGNED 1 @@ -94,29 +84,33 @@ const int kIntSize = sizeof(int); // NOLINT const int kDoubleSize = sizeof(double); // NOLINT const int kPointerSize = sizeof(void*); // NOLINT +#ifdef V8_ARCH_X64 +const int kPointerSizeLog2 = 3; +#else const int kPointerSizeLog2 = 2; +#endif -const int kObjectAlignmentBits = 2; -const int kObjectAlignmentMask = (1 << kObjectAlignmentBits) - 1; -const int kObjectAlignment = 1 << kObjectAlignmentBits; +const int kObjectAlignmentBits = kPointerSizeLog2; +const intptr_t kObjectAlignmentMask = (1 << kObjectAlignmentBits) - 1; +const intptr_t kObjectAlignment = 1 << kObjectAlignmentBits; // Tag information for HeapObject. const int kHeapObjectTag = 1; const int kHeapObjectTagSize = 2; -const int kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; +const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; // Tag information for Smi. const int kSmiTag = 0; const int kSmiTagSize = 1; -const int kSmiTagMask = (1 << kSmiTagSize) - 1; +const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; // Tag information for Failure. const int kFailureTag = 3; const int kFailureTagSize = 2; -const int kFailureTagMask = (1 << kFailureTagSize) - 1; +const intptr_t kFailureTagMask = (1 << kFailureTagSize) - 1; const int kBitsPerByte = 8; @@ -125,11 +119,21 @@ const int kBitsPerPointer = kPointerSize * kBitsPerByte; const int kBitsPerInt = kIntSize * kBitsPerByte; -// Zap-value: The value used for zapping dead objects. Should be a recognizable -// illegal heap object pointer. +// Zap-value: The value used for zapping dead objects. +// Should be a recognizable hex value tagged as a heap object pointer. +#ifdef V8_ARCH_X64 +const Address kZapValue = + reinterpret_cast
(UINT64_C(0xdeadbeedbeadbeed)); +const Address kHandleZapValue = + reinterpret_cast
(UINT64_C(0x1baddead0baddead)); +const Address kFromSpaceZapValue = + reinterpret_cast
(UINT64_C(0x1beefdad0beefdad)); +#else const Address kZapValue = reinterpret_cast
(0xdeadbeed); const Address kHandleZapValue = reinterpret_cast
(0xbaddead); const Address kFromSpaceZapValue = reinterpret_cast
(0xbeefdad); +#endif + // ----------------------------------------------------------------------------- // Forward declarations for frequently used classes @@ -372,13 +376,13 @@ enum StateTag { // Testers for test. #define HAS_SMI_TAG(value) \ - ((reinterpret_cast(value) & kSmiTagMask) == kSmiTag) + ((reinterpret_cast(value) & kSmiTagMask) == kSmiTag) #define HAS_FAILURE_TAG(value) \ - ((reinterpret_cast(value) & kFailureTagMask) == kFailureTag) + ((reinterpret_cast(value) & kFailureTagMask) == kFailureTag) #define HAS_HEAP_OBJECT_TAG(value) \ - ((reinterpret_cast(value) & kHeapObjectTagMask) == kHeapObjectTag) + ((reinterpret_cast(value) & kHeapObjectTagMask) == kHeapObjectTag) // OBJECT_SIZE_ALIGN returns the value aligned HeapObject size #define OBJECT_SIZE_ALIGN(value) \ -- 2.7.4