diff --git a/client/dom/generated/src/interface/TextMetrics.dart b/client/dom/generated/src/interface/TextMetrics.dart index 555c76b3714..4f9220e272b 100644 --- a/client/dom/generated/src/interface/TextMetrics.dart +++ b/client/dom/generated/src/interface/TextMetrics.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file + // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. diff --git a/runtime/platform/assert.cc b/runtime/platform/assert.cc index 2f3e145e47b..39ec602f18d 100644 --- a/runtime/platform/assert.cc +++ b/runtime/platform/assert.cc @@ -7,7 +7,7 @@ #include #include "platform/assert.h" -#include "vm/globals.h" +#include "platform/globals.h" namespace dart { diff --git a/runtime/platform/globals.h b/runtime/platform/globals.h index 24212cba20e..7f8beed655a 100644 --- a/runtime/platform/globals.h +++ b/runtime/platform/globals.h @@ -61,6 +61,116 @@ #error Automatic target os detection failed. #endif +// Processor architecture detection. For more info on what's defined, see: +// http://msdn.microsoft.com/en-us/library/b0084kay.aspx +// http://www.agner.org/optimize/calling_conventions.pdf +// or with gcc, run: "echo | gcc -E -dM -" +#if defined(_M_X64) || defined(__x86_64__) +#define HOST_ARCH_X64 1 +#define ARCH_IS_64_BIT 1 +#elif defined(_M_IX86) || defined(__i386__) +#define HOST_ARCH_IA32 1 +#define ARCH_IS_32_BIT 1 +#elif defined(__ARMEL__) +#define HOST_ARCH_ARM 1 +#define ARCH_IS_32_BIT 1 +#else +#error Architecture was not detected as supported by Dart. +#endif + +#if !defined(TARGET_ARCH_ARM) +#if !defined(TARGET_ARCH_X64) +#if !defined(TARGET_ARCH_IA32) +// No target architecture specified pick the one matching the host architecture. +#if defined(HOST_ARCH_ARM) +#define TARGET_ARCH_ARM 1 +#elif defined(HOST_ARCH_X64) +#define TARGET_ARCH_X64 1 +#elif defined(HOST_ARCH_IA32) +#define TARGET_ARCH_IA32 1 +#else +#error Automatic target architecture detection failed. +#endif +#endif +#endif +#endif + +// Verify that host and target architectures match, we cannot +// have a 64 bit Dart VM generating 32 bit code or vice-versa. +#if defined(TARGET_ARCH_X64) +#if !defined(ARCH_IS_64_BIT) +#error Mismatched Host/Target architectures. +#endif +#elif defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM) +#if !defined(ARCH_IS_32_BIT) +#error Mismatched Host/Target architectures. +#endif +#endif + + +// Printf format for intptr_t on Windows. +#if !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) +#if defined(ARCH_IS_32_BIT) +#define PRIxPTR "x" +#else +#define PRIxPTR "llx" +#endif // defined(ARCH_IS_32_BIT) +#endif // !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) + + +// Suffixes for 64-bit integer literals. +#ifdef _MSC_VER +#define DART_INT64_C(x) x##I64 +#define DART_UINT64_C(x) x##UI64 +#else +#define DART_INT64_C(x) x##LL +#define DART_UINT64_C(x) x##ULL +#endif + + +// The following macro works on both 32 and 64-bit platforms. +// Usage: instead of writing 0x1234567890123456 +// write DART_2PART_UINT64_C(0x12345678,90123456); +#define DART_2PART_UINT64_C(a, b) \ + (((static_cast(a) << 32) + 0x##b##u)) + + +// Types for native machine words. Guaranteed to be able to hold pointers and +// integers. +typedef intptr_t word; +typedef uintptr_t uword; + +// Byte sizes. +const int kWordSize = sizeof(word); +#ifdef ARCH_IS_32_BIT +const int kWordSizeLog2 = 2; +#else +const int kWordSizeLog2 = 3; +#endif + +// Bit sizes. +const int kBitsPerByte = 8; +const int kBitsPerByteLog2 = 3; +const int kBitsPerWord = kWordSize * kBitsPerByte; + +// System-wide named constants. +const int KB = 1024; +const int MB = KB * KB; +const int GB = KB * KB * KB; +const intptr_t kIntptrOne = 1; +const intptr_t kIntptrMin = (kIntptrOne << (kBitsPerWord - 1)); +const intptr_t kIntptrMax = ~kIntptrMin; + +// Time constants. +const int kMillisecondsPerSecond = 1000; +const int kMicrosecondsPerMillisecond = 1000; +const int kMicrosecondsPerSecond = (kMicrosecondsPerMillisecond * + kMillisecondsPerSecond); +const int kNanosecondsPerMicrosecond = 1000; +const int kNanosecondsPerMillisecond = (kNanosecondsPerMicrosecond * + kMicrosecondsPerMillisecond); +const int kNanosecondsPerSecond = (kNanosecondsPerMicrosecond * + kMicrosecondsPerSecond); // A macro to disallow the copy constructor and operator= functions. // This should be used in the private: declarations for a class. @@ -96,6 +206,111 @@ template static inline void USE(T) { } +// Use implicit_cast as a safe version of static_cast or const_cast +// for upcasting in the type hierarchy (i.e. casting a pointer to Foo +// to a pointer to SuperclassOfFoo or casting a pointer to Foo to +// a const pointer to Foo). +// When you use implicit_cast, the compiler checks that the cast is safe. +// Such explicit implicit_casts are necessary in surprisingly many +// situations where C++ demands an exact type match instead of an +// argument type convertable to a target type. +// +// The From type can be inferred, so the preferred syntax for using +// implicit_cast is the same as for static_cast etc.: +// +// implicit_cast(expr) +// +// implicit_cast would have been part of the C++ standard library, +// but the proposal was submitted too late. It will probably make +// its way into the language in the future. +template +inline To implicit_cast(From const &f) { + return f; +} + + +// Use like this: down_cast(foo); +template // use like this: down_cast(foo); +inline To down_cast(From* f) { // so we only accept pointers + // Ensures that To is a sub-type of From *. This test is here only + // for compile-time type checking, and has no overhead in an + // optimized build at run-time, as it will be optimized away completely. + if (false) { + implicit_cast(0); + } + return static_cast(f); +} + + +// The type-based aliasing rule allows the compiler to assume that +// pointers of different types (for some definition of different) +// never alias each other. Thus the following code does not work: +// +// float f = foo(); +// int fbits = *(int*)(&f); +// +// The compiler 'knows' that the int pointer can't refer to f since +// the types don't match, so the compiler may cache f in a register, +// leaving random data in fbits. Using C++ style casts makes no +// difference, however a pointer to char data is assumed to alias any +// other pointer. This is the 'memcpy exception'. +// +// The bit_cast function uses the memcpy exception to move the bits +// from a variable of one type to a variable of another type. Of +// course the end result is likely to be implementation dependent. +// Most compilers (gcc-4.2 and MSVC 2005) will completely optimize +// bit_cast away. +// +// There is an additional use for bit_cast. Recent gccs will warn when +// they see casts that may result in breakage due to the type-based +// aliasing rule. If you have checked that there is no breakage you +// can use bit_cast to cast one pointer type to another. This confuses +// gcc enough that it can no longer see that you have cast one pointer +// type to another thus avoiding the warning. +template +inline D bit_cast(const S& source) { + // Compile time assertion: sizeof(D) == sizeof(S). A compile error + // here means your D and S have different sizes. + typedef char VerifySizesAreEqual[sizeof(D) == sizeof(S) ? 1 : -1]; + + D destination; + // This use of memcpy is safe: source and destination cannot overlap. + memcpy(&destination, &source, sizeof(destination)); + return destination; +} + + +// Similar to bit_cast, but allows copying from types of unrelated +// sizes. This method was introduced to enable the strict aliasing +// optimizations of GCC 4.4. Basically, GCC mindlessly relies on +// obscure details in the C++ standard that make reinterpret_cast +// virtually useless. +template +inline D bit_copy(const S& source) { + D destination; + // This use of memcpy is safe: source and destination cannot overlap. + memcpy(&destination, + reinterpret_cast(&source), + sizeof(destination)); + return destination; +} + + +// A macro to ensure that memcpy cannot be called. memcpy does not handle +// overlapping memory regions. Even though this is well documented it seems +// to be used in error quite often. To avoid problems we disallow the direct +// use of memcpy here. +// +// On Windows the basic libraries use memcpy and therefore compilation will +// fail if memcpy is overwritten even if user code does not use memcpy. +#if defined(memcpy) +#undef memcpy +#endif +#if !defined(TARGET_OS_WINDOWS) +#define memcpy "Please use memmove instead of memcpy." +#endif + + // On Windows the reentrent version of strtok is called // strtok_s. Unify on the posix name strtok_r. #if defined(TARGET_OS_WINDOWS) diff --git a/runtime/platform/platform_headers.gypi b/runtime/platform/platform_headers.gypi index c64023efb65..310c8705812 100644 --- a/runtime/platform/platform_headers.gypi +++ b/runtime/platform/platform_headers.gypi @@ -6,8 +6,9 @@ { 'sources': [ 'assert.h', - 'globals.h', 'c99_support_win.h', + 'globals.h', 'inttypes_support_win.h', + 'utils.h', ], } diff --git a/runtime/platform/platform_sources.gypi b/runtime/platform/platform_sources.gypi index 58ee91bf2f7..b5281ad083f 100644 --- a/runtime/platform/platform_sources.gypi +++ b/runtime/platform/platform_sources.gypi @@ -6,5 +6,6 @@ { 'sources': [ 'assert.cc', + 'utils.cc', ], } diff --git a/runtime/vm/utils.cc b/runtime/platform/utils.cc similarity index 96% rename from runtime/vm/utils.cc rename to runtime/platform/utils.cc index 86b9c6a5baa..09b9260473a 100644 --- a/runtime/vm/utils.cc +++ b/runtime/platform/utils.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#include "vm/utils.h" +#include "platform/utils.h" namespace dart { diff --git a/runtime/vm/utils.h b/runtime/platform/utils.h similarity index 97% rename from runtime/vm/utils.h rename to runtime/platform/utils.h index 855e1f18d88..38d87bd6020 100644 --- a/runtime/vm/utils.h +++ b/runtime/platform/utils.h @@ -2,11 +2,11 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -#ifndef VM_UTILS_H_ -#define VM_UTILS_H_ +#ifndef PLATFORM_UTILS_H_ +#define PLATFORM_UTILS_H_ #include "platform/assert.h" -#include "vm/globals.h" +#include "platform/globals.h" namespace dart { @@ -152,4 +152,4 @@ class Utils { } // namespace dart -#endif // VM_UTILS_H_ +#endif // PLATFORM_UTILS_H_ diff --git a/runtime/vm/assembler.cc b/runtime/vm/assembler.cc index 8319db41f9e..446c78a630f 100644 --- a/runtime/vm/assembler.cc +++ b/runtime/vm/assembler.cc @@ -1,13 +1,14 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. #include "vm/assembler.h" + +#include "platform/utils.h" #include "vm/cpu.h" #include "vm/heap.h" #include "vm/memory_region.h" #include "vm/os.h" -#include "vm/utils.h" #include "vm/zone.h" namespace dart { diff --git a/runtime/vm/assembler_ia32.h b/runtime/vm/assembler_ia32.h index 9de739f7ccd..a18ffb5377f 100644 --- a/runtime/vm/assembler_ia32.h +++ b/runtime/vm/assembler_ia32.h @@ -10,8 +10,8 @@ #endif #include "platform/assert.h" +#include "platform/utils.h" #include "vm/constants_ia32.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/assembler_x64.h b/runtime/vm/assembler_x64.h index 06d0500341f..96376519e50 100644 --- a/runtime/vm/assembler_x64.h +++ b/runtime/vm/assembler_x64.h @@ -10,8 +10,8 @@ #endif #include "platform/assert.h" +#include "platform/utils.h" #include "vm/constants_x64.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/bigint_operations.cc b/runtime/vm/bigint_operations.cc index 094fd934bd7..afd4b9935f9 100644 --- a/runtime/vm/bigint_operations.cc +++ b/runtime/vm/bigint_operations.cc @@ -6,10 +6,10 @@ #include +#include "platform/utils.h" #include "vm/bigint_store.h" #include "vm/double_internals.h" #include "vm/exceptions.h" -#include "vm/utils.h" #include "vm/zone.h" namespace dart { diff --git a/runtime/vm/bigint_store.h b/runtime/vm/bigint_store.h index 4c8ebc940fc..f6cb71f89be 100644 --- a/runtime/vm/bigint_store.h +++ b/runtime/vm/bigint_store.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -6,6 +6,7 @@ #define VM_BIGINT_STORE_H_ #include "vm/globals.h" +#include "vm/isolate.h" namespace dart { diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index 529f4d06fb1..a5480a1f89b 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -4,11 +4,11 @@ #include "include/dart_api.h" #include "platform/assert.h" +#include "platform/utils.h" #include "vm/dart_api_impl.h" #include "vm/dart_api_state.h" #include "vm/thread.h" #include "vm/unit_test.h" -#include "vm/utils.h" #include "vm/verifier.h" namespace dart { diff --git a/runtime/vm/debuginfo.h b/runtime/vm/debuginfo.h index 778446da6e3..fd942680fd8 100644 --- a/runtime/vm/debuginfo.h +++ b/runtime/vm/debuginfo.h @@ -6,8 +6,8 @@ #define VM_DEBUGINFO_H_ #include "platform/assert.h" +#include "platform/utils.h" #include "vm/globals.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/debuginfo_linux.cc b/runtime/vm/debuginfo_linux.cc index b11df1bce8a..35a7824e2e0 100644 --- a/runtime/vm/debuginfo_linux.cc +++ b/runtime/vm/debuginfo_linux.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. #include "vm/debuginfo.h" +#include "platform/utils.h" #include "vm/gdbjit_linux.h" #include "vm/os.h" -#include "vm/utils.h" #include "vm/thread.h" namespace dart { diff --git a/runtime/vm/disassembler_arm.cc b/runtime/vm/disassembler_arm.cc index bea7a3af943..e74333dc82c 100644 --- a/runtime/vm/disassembler_arm.cc +++ b/runtime/vm/disassembler_arm.cc @@ -4,10 +4,9 @@ #include "vm/disassembler.h" -#include "platform/assert.h" #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. #if defined(TARGET_ARCH_ARM) - +#include "platform/assert.h" namespace dart { diff --git a/runtime/vm/disassembler_ia32.cc b/runtime/vm/disassembler_ia32.cc index 75b6a8b201d..82118e0d63f 100644 --- a/runtime/vm/disassembler_ia32.cc +++ b/runtime/vm/disassembler_ia32.cc @@ -6,13 +6,12 @@ #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. #if defined(TARGET_ARCH_IA32) - +#include "platform/utils.h" #include "vm/allocation.h" #include "vm/code_index_table.h" #include "vm/heap.h" #include "vm/os.h" #include "vm/stub_code.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/disassembler_x64.cc b/runtime/vm/disassembler_x64.cc index 8787ae1763b..3e0e5a2a8be 100644 --- a/runtime/vm/disassembler_x64.cc +++ b/runtime/vm/disassembler_x64.cc @@ -11,9 +11,9 @@ #include #endif -#include "platform/assert.h" #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. #if defined(TARGET_ARCH_X64) +#include "platform/assert.h" namespace dart { diff --git a/runtime/vm/double_internals.h b/runtime/vm/double_internals.h index 2465ffb6107..4e54475c6e5 100644 --- a/runtime/vm/double_internals.h +++ b/runtime/vm/double_internals.h @@ -1,11 +1,11 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. #ifndef VM_DOUBLE_INTERNALS_H_ #define VM_DOUBLE_INTERNALS_H_ -#include "vm/utils.h" +#include "platform/utils.h" namespace dart { diff --git a/runtime/vm/globals.h b/runtime/vm/globals.h index ffb6d3ff036..be3981885c6 100644 --- a/runtime/vm/globals.h +++ b/runtime/vm/globals.h @@ -22,121 +22,6 @@ namespace dart { -// Processor architecture detection. For more info on what's defined, see: -// http://msdn.microsoft.com/en-us/library/b0084kay.aspx -// http://www.agner.org/optimize/calling_conventions.pdf -// or with gcc, run: "echo | gcc -E -dM -" -#if defined(_M_X64) || defined(__x86_64__) -#define HOST_ARCH_X64 1 -#define ARCH_IS_64_BIT 1 -#elif defined(_M_IX86) || defined(__i386__) -#define HOST_ARCH_IA32 1 -#define ARCH_IS_32_BIT 1 -#elif defined(__ARMEL__) -#define HOST_ARCH_ARM 1 -#define ARCH_IS_32_BIT 1 -#else -#error Architecture was not detected as supported by Dart. -#endif - -#if !defined(TARGET_ARCH_ARM) -#if !defined(TARGET_ARCH_X64) -#if !defined(TARGET_ARCH_IA32) -// No target architecture specified pick the one matching the host architecture. -#if defined(HOST_ARCH_ARM) -#define TARGET_ARCH_ARM 1 -#elif defined(HOST_ARCH_X64) -#define TARGET_ARCH_X64 1 -#elif defined(HOST_ARCH_IA32) -#define TARGET_ARCH_IA32 1 -#else -#error Automatic target architecture detection failed. -#endif -#endif -#endif -#endif - -// Verify that host and target architectures match, we cannot -// have a 64 bit Dart VM generating 32 bit code or vice-versa. -#if defined(TARGET_ARCH_X64) -#if !defined(ARCH_IS_64_BIT) -#error Mismatched Host/Target architectures. -#endif -#elif defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_ARM) -#if !defined(ARCH_IS_32_BIT) -#error Mismatched Host/Target architectures. -#endif -#endif - - -// Printf format for intptr_t on Windows. -#if !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) -#if defined(ARCH_IS_32_BIT) -#define PRIxPTR "x" -#else -#define PRIxPTR "llx" -#endif // defined(ARCH_IS_32_BIT) -#endif // !defined(PRIxPTR) && defined(TARGET_OS_WINDOWS) - - -// Suffixes for 64-bit integer literals. -#ifdef _MSC_VER -#define DART_INT64_C(x) x##I64 -#define DART_UINT64_C(x) x##UI64 -#else -#define DART_INT64_C(x) x##LL -#define DART_UINT64_C(x) x##ULL -#endif - - -// The following macro works on both 32 and 64-bit platforms. -// Usage: instead of writing 0x1234567890123456 -// write DART_2PART_UINT64_C(0x12345678,90123456); -#define DART_2PART_UINT64_C(a, b) \ - (((static_cast(a) << 32) + 0x##b##u)) - - -// Types for native machine words. Guaranteed to be able to hold pointers and -// integers. -typedef intptr_t word; -typedef uintptr_t uword; - -// A type large enough to contain the value of the C++ vtable. This is needed -// to support the handle operations. -typedef uword cpp_vtable; - -// Byte sizes. -const int kWordSize = sizeof(word); -#ifdef ARCH_IS_32_BIT -const int kWordSizeLog2 = 2; -#else -const int kWordSizeLog2 = 3; -#endif - -// Bit sizes. -const int kBitsPerByte = 8; -const int kBitsPerByteLog2 = 3; -const int kBitsPerWord = kWordSize * kBitsPerByte; - -// System-wide named constants. -const int KB = 1024; -const int MB = KB * KB; -const int GB = KB * KB * KB; -const intptr_t kIntptrOne = 1; -const intptr_t kIntptrMin = (kIntptrOne << (kBitsPerWord - 1)); -const intptr_t kIntptrMax = ~kIntptrMin; - -// Time constants. -const int kMillisecondsPerSecond = 1000; -const int kMicrosecondsPerMillisecond = 1000; -const int kMicrosecondsPerSecond = (kMicrosecondsPerMillisecond * - kMillisecondsPerSecond); -const int kNanosecondsPerMicrosecond = 1000; -const int kNanosecondsPerMillisecond = (kNanosecondsPerMicrosecond * - kMicrosecondsPerMillisecond); -const int kNanosecondsPerSecond = (kNanosecondsPerMicrosecond * - kMicrosecondsPerSecond); - // The expression ARRAY_SIZE(array) is a compile-time constant of type // size_t which represents the number of elements of the given // array. You should only use ARRAY_SIZE on statically allocated @@ -166,108 +51,9 @@ const intptr_t kOffsetOfPtr = 32; (reinterpret_cast(kOffsetOfPtr)->accessor())) - kOffsetOfPtr) -// Use implicit_cast as a safe version of static_cast or const_cast -// for upcasting in the type hierarchy (i.e. casting a pointer to Foo -// to a pointer to SuperclassOfFoo or casting a pointer to Foo to -// a const pointer to Foo). -// When you use implicit_cast, the compiler checks that the cast is safe. -// Such explicit implicit_casts are necessary in surprisingly many -// situations where C++ demands an exact type match instead of an -// argument type convertable to a target type. -// -// The From type can be inferred, so the preferred syntax for using -// implicit_cast is the same as for static_cast etc.: -// -// implicit_cast(expr) -// -// implicit_cast would have been part of the C++ standard library, -// but the proposal was submitted too late. It will probably make -// its way into the language in the future. -template -inline To implicit_cast(From const &f) { - return f; -} - - -// Use like this: down_cast(foo); -template // use like this: down_cast(foo); -inline To down_cast(From* f) { // so we only accept pointers - // Ensures that To is a sub-type of From *. This test is here only - // for compile-time type checking, and has no overhead in an - // optimized build at run-time, as it will be optimized away completely. - if (false) { - implicit_cast(0); - } - return static_cast(f); -} - - -// The type-based aliasing rule allows the compiler to assume that -// pointers of different types (for some definition of different) -// never alias each other. Thus the following code does not work: -// -// float f = foo(); -// int fbits = *(int*)(&f); -// -// The compiler 'knows' that the int pointer can't refer to f since -// the types don't match, so the compiler may cache f in a register, -// leaving random data in fbits. Using C++ style casts makes no -// difference, however a pointer to char data is assumed to alias any -// other pointer. This is the 'memcpy exception'. -// -// The bit_cast function uses the memcpy exception to move the bits -// from a variable of one type to a variable of another type. Of -// course the end result is likely to be implementation dependent. -// Most compilers (gcc-4.2 and MSVC 2005) will completely optimize -// bit_cast away. -// -// There is an additional use for bit_cast. Recent gccs will warn when -// they see casts that may result in breakage due to the type-based -// aliasing rule. If you have checked that there is no breakage you -// can use bit_cast to cast one pointer type to another. This confuses -// gcc enough that it can no longer see that you have cast one pointer -// type to another thus avoiding the warning. -template -inline D bit_cast(const S& source) { - // Compile time assertion: sizeof(D) == sizeof(S). A compile error - // here means your D and S have different sizes. - typedef char VerifySizesAreEqual[sizeof(D) == sizeof(S) ? 1 : -1]; - - D destination; - // This use of memcpy is safe: source and destination cannot overlap. - memcpy(&destination, &source, sizeof(destination)); - return destination; -} - - -// Similar to bit_cast, but allows copying from types of unrelated -// sizes. This method was introduced to enable the strict aliasing -// optimizations of GCC 4.4. Basically, GCC mindlessly relies on -// obscure details in the C++ standard that make reinterpret_cast -// virtually useless. -template -inline D bit_copy(const S& source) { - D destination; - // This use of memcpy is safe: source and destination cannot overlap. - memcpy(&destination, - reinterpret_cast(&source), - sizeof(destination)); - return destination; -} - -// A macro to ensure that memcpy cannot be called. memcpy does not handle -// overlapping memory regions. Even though this is well documented it seems -// to be used in error quite often. To avoid problems we disallow the direct -// use of memcpy here. -// -// On Windows the basic libraries use memcpy and therefore compilation will -// fail if memcpy is overwritten even if user code does not use memcpy. -#if defined(memcpy) -#undef memcpy -#endif -#if !defined(TARGET_OS_WINDOWS) -#define memcpy "Please use memmove instead of memcpy." -#endif +// A type large enough to contain the value of the C++ vtable. This is needed +// to support the handle operations. +typedef uword cpp_vtable; // When using GCC we can use GCC attributes to ensure that certain diff --git a/runtime/vm/growable_array.h b/runtime/vm/growable_array.h index 1175b868a41..692da64a670 100644 --- a/runtime/vm/growable_array.h +++ b/runtime/vm/growable_array.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // Defines growable array classes, that differ where they are allocated: @@ -8,9 +8,9 @@ #ifndef VM_GROWABLE_ARRAY_H_ #define VM_GROWABLE_ARRAY_H_ +#include "platform/utils.h" #include "vm/allocation.h" #include "vm/isolate.h" -#include "vm/utils.h" #include "vm/zone.h" namespace dart { diff --git a/runtime/vm/handles.cc b/runtime/vm/handles.cc index fd4e1d32bab..40956576936 100644 --- a/runtime/vm/handles.cc +++ b/runtime/vm/handles.cc @@ -5,11 +5,11 @@ #include "vm/handles.h" #include "platform/assert.h" +#include "platform/utils.h" #include "vm/flags.h" #include "vm/isolate.h" #include "vm/os.h" #include "vm/raw_object.h" -#include "vm/utils.h" #include "vm/visitor.h" #include "vm/zone.h" diff --git a/runtime/vm/heap.cc b/runtime/vm/heap.cc index 76b343928d4..98cd59d5d35 100644 --- a/runtime/vm/heap.cc +++ b/runtime/vm/heap.cc @@ -5,13 +5,13 @@ #include "vm/heap.h" #include "platform/assert.h" +#include "platform/utils.h" #include "vm/compiler_stats.h" #include "vm/flags.h" #include "vm/isolate.h" #include "vm/os.h" #include "vm/pages.h" #include "vm/scavenger.h" -#include "vm/utils.h" #include "vm/verifier.h" #include "vm/virtual_memory.h" diff --git a/runtime/vm/object.h b/runtime/vm/object.h index 5e220fbc5d0..6e653a4fa36 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -6,6 +6,7 @@ #define VM_OBJECT_H_ #include "platform/assert.h" +#include "platform/utils.h" #include "vm/dart.h" #include "vm/globals.h" #include "vm/handles.h" @@ -14,7 +15,6 @@ #include "vm/os.h" #include "vm/raw_object.h" #include "vm/scanner.h" -#include "vm/utils.h" #include "include/dart_api.h" diff --git a/runtime/vm/os_linux.cc b/runtime/vm/os_linux.cc index b2233970892..52bdaf7b538 100644 --- a/runtime/vm/os_linux.cc +++ b/runtime/vm/os_linux.cc @@ -12,8 +12,8 @@ #include #include +#include "platform/utils.h" #include "vm/isolate.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/os_macos.cc b/runtime/vm/os_macos.cc index 8f4be1b19f0..e6107650d00 100644 --- a/runtime/vm/os_macos.cc +++ b/runtime/vm/os_macos.cc @@ -13,8 +13,8 @@ #include #include +#include "platform/utils.h" #include "vm/isolate.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/os_test.cc b/runtime/vm/os_test.cc index 25d36e76d61..b3da024866e 100644 --- a/runtime/vm/os_test.cc +++ b/runtime/vm/os_test.cc @@ -3,10 +3,10 @@ // BSD-style license that can be found in the LICENSE file. #include "platform/assert.h" +#include "platform/utils.h" #include "vm/globals.h" #include "vm/os.h" #include "vm/unit_test.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/port.cc b/runtime/vm/port.cc index 3f5f9a384d6..37413bba29e 100644 --- a/runtime/vm/port.cc +++ b/runtime/vm/port.cc @@ -1,13 +1,13 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. #include "vm/port.h" +#include "platform/utils.h" #include "vm/dart_api_impl.h" #include "vm/isolate.h" #include "vm/thread.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/scavenger.h b/runtime/vm/scavenger.h index f03a70b6e6e..fc9b6e64d82 100644 --- a/runtime/vm/scavenger.h +++ b/runtime/vm/scavenger.h @@ -6,10 +6,10 @@ #define VM_SCAVENGER_H_ #include "platform/assert.h" +#include "platform/utils.h" #include "vm/flags.h" #include "vm/globals.h" #include "vm/raw_object.h" -#include "vm/utils.h" #include "vm/virtual_memory.h" #include "vm/visitor.h" diff --git a/runtime/vm/utils_test.cc b/runtime/vm/utils_test.cc index 90a1e22f2bf..f547e4d1dad 100644 --- a/runtime/vm/utils_test.cc +++ b/runtime/vm/utils_test.cc @@ -3,8 +3,8 @@ // BSD-style license that can be found in the LICENSE file. #include "platform/assert.h" +#include "platform/utils.h" #include "vm/unit_test.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/virtual_memory.cc b/runtime/vm/virtual_memory.cc index 67a67e26481..7c683d9ed28 100644 --- a/runtime/vm/virtual_memory.cc +++ b/runtime/vm/virtual_memory.cc @@ -5,7 +5,7 @@ #include "vm/virtual_memory.h" #include "platform/assert.h" -#include "vm/utils.h" +#include "platform/utils.h" namespace dart { diff --git a/runtime/vm/virtual_memory.h b/runtime/vm/virtual_memory.h index 2defcdb063a..87070a3e7fd 100644 --- a/runtime/vm/virtual_memory.h +++ b/runtime/vm/virtual_memory.h @@ -1,13 +1,13 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. #ifndef VM_VIRTUAL_MEMORY_H_ #define VM_VIRTUAL_MEMORY_H_ +#include "platform/utils.h" #include "vm/globals.h" #include "vm/memory_region.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/virtual_memory_linux.cc b/runtime/vm/virtual_memory_linux.cc index f7a898ab8a6..a6df453d958 100644 --- a/runtime/vm/virtual_memory_linux.cc +++ b/runtime/vm/virtual_memory_linux.cc @@ -9,7 +9,7 @@ #include #include "platform/assert.h" -#include "vm/utils.h" +#include "platform/utils.h" namespace dart { diff --git a/runtime/vm/virtual_memory_macos.cc b/runtime/vm/virtual_memory_macos.cc index 0d3f876f3d5..c2274798ff5 100644 --- a/runtime/vm/virtual_memory_macos.cc +++ b/runtime/vm/virtual_memory_macos.cc @@ -8,7 +8,7 @@ #include #include "platform/assert.h" -#include "vm/utils.h" +#include "platform/utils.h" namespace dart { diff --git a/runtime/vm/vm_sources.gypi b/runtime/vm/vm_sources.gypi index 5998c86c9c4..6b0fcd7fb0b 100644 --- a/runtime/vm/vm_sources.gypi +++ b/runtime/vm/vm_sources.gypi @@ -251,8 +251,6 @@ 'unicode_test.cc', 'unit_test.cc', 'unit_test.h', - 'utils.cc', - 'utils.h', 'utils_test.cc', 'virtual_memory.cc', 'virtual_memory.h', diff --git a/runtime/vm/zone.cc b/runtime/vm/zone.cc index e223d01143e..9afc8c12ffc 100644 --- a/runtime/vm/zone.cc +++ b/runtime/vm/zone.cc @@ -5,10 +5,10 @@ #include "vm/zone.h" #include "platform/assert.h" +#include "platform/utils.h" #include "vm/flags.h" #include "vm/isolate.h" #include "vm/os.h" -#include "vm/utils.h" namespace dart { diff --git a/runtime/vm/zone.h b/runtime/vm/zone.h index 61ff545b771..76cfeef765f 100644 --- a/runtime/vm/zone.h +++ b/runtime/vm/zone.h @@ -1,14 +1,14 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. #ifndef VM_ZONE_H_ #define VM_ZONE_H_ +#include "platform/utils.h" #include "vm/allocation.h" #include "vm/handles.h" #include "vm/memory_region.h" -#include "vm/utils.h" namespace dart {