Include 64-bit pointer and constant types in include/v8.h.
authorwhesse@chromium.org <whesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 4 May 2009 13:29:29 +0000 (13:29 +0000)
committerwhesse@chromium.org <whesse@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Mon, 4 May 2009 13:29:29 +0000 (13:29 +0000)
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
src/globals.h

index ee4951d221c10961bde9ccacd28848c9baccbea8..068a1cdef58ee29d7dfdb0b52f1884f9ae6e757b 100644 (file)
 #include <stdio.h>
 
 #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
index 5d2ac048cf222ff257dc149b2a6dd385d65bf689..35208c4399d25b9d58bfd0f86b4cdc0c03a0c49b 100644 (file)
 #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 <stdint.h>  // 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<Address>(UINT64_C(0xdeadbeedbeadbeed));
+const Address kHandleZapValue =
+    reinterpret_cast<Address>(UINT64_C(0x1baddead0baddead));
+const Address kFromSpaceZapValue =
+    reinterpret_cast<Address>(UINT64_C(0x1beefdad0beefdad));
+#else
 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeed);
 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddead);
 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdad);
+#endif
+
 
 // -----------------------------------------------------------------------------
 // Forward declarations for frequently used classes
@@ -372,13 +376,13 @@ enum StateTag {
 // Testers for test.
 
 #define HAS_SMI_TAG(value) \
-  ((reinterpret_cast<int>(value) & kSmiTagMask) == kSmiTag)
+  ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag)
 
 #define HAS_FAILURE_TAG(value) \
-  ((reinterpret_cast<int>(value) & kFailureTagMask) == kFailureTag)
+  ((reinterpret_cast<intptr_t>(value) & kFailureTagMask) == kFailureTag)
 
 #define HAS_HEAP_OBJECT_TAG(value) \
-  ((reinterpret_cast<int>(value) & kHeapObjectTagMask) == kHeapObjectTag)
+  ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == kHeapObjectTag)
 
 // OBJECT_SIZE_ALIGN returns the value aligned HeapObject size
 #define OBJECT_SIZE_ALIGN(value)                                \