| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 #define V8_PTR_PREFIX "ll" | 91 #define V8_PTR_PREFIX "ll" |
| 92 #else // _MSC_VER | 92 #else // _MSC_VER |
| 93 #define V8_UINT64_C(x) (x ## UL) | 93 #define V8_UINT64_C(x) (x ## UL) |
| 94 #define V8_INT64_C(x) (x ## L) | 94 #define V8_INT64_C(x) (x ## L) |
| 95 #define V8_PTR_PREFIX "l" | 95 #define V8_PTR_PREFIX "l" |
| 96 #endif // _MSC_VER | 96 #endif // _MSC_VER |
| 97 #else // V8_HOST_ARCH_64_BIT | 97 #else // V8_HOST_ARCH_64_BIT |
| 98 #define V8_PTR_PREFIX "" | 98 #define V8_PTR_PREFIX "" |
| 99 #endif // V8_HOST_ARCH_64_BIT | 99 #endif // V8_HOST_ARCH_64_BIT |
| 100 | 100 |
| 101 // The following macro works on both 32 and 64-bit platforms. |
| 102 // Usage: instead of writing 0x1234567890123456 |
| 103 // write V8_2PART_UINT64_C(0x12345678,90123456); |
| 104 #define V8_2PART_UINT64_C(a, b) (((static_cast<uint64_t>(a) << 32) + 0x##b##u)) |
| 105 |
| 101 #define V8PRIxPTR V8_PTR_PREFIX "x" | 106 #define V8PRIxPTR V8_PTR_PREFIX "x" |
| 102 #define V8PRIdPTR V8_PTR_PREFIX "d" | 107 #define V8PRIdPTR V8_PTR_PREFIX "d" |
| 103 | 108 |
| 104 // Fix for Mac OS X defining uintptr_t as "unsigned long": | 109 // Fix for Mac OS X defining uintptr_t as "unsigned long": |
| 105 #if defined(__APPLE__) && defined(__MACH__) | 110 #if defined(__APPLE__) && defined(__MACH__) |
| 106 #undef V8PRIxPTR | 111 #undef V8PRIxPTR |
| 107 #define V8PRIxPTR "lx" | 112 #define V8PRIxPTR "lx" |
| 108 #endif | 113 #endif |
| 109 | 114 |
| 110 #if defined(__APPLE__) && defined(__MACH__) | 115 #if defined(__APPLE__) && defined(__MACH__) |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // (allocated in the young generation if the object size and type | 314 // (allocated in the young generation if the object size and type |
| 310 // allows). | 315 // allows). |
| 311 enum PretenureFlag { NOT_TENURED, TENURED }; | 316 enum PretenureFlag { NOT_TENURED, TENURED }; |
| 312 | 317 |
| 313 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR }; | 318 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR }; |
| 314 | 319 |
| 315 enum Executability { NOT_EXECUTABLE, EXECUTABLE }; | 320 enum Executability { NOT_EXECUTABLE, EXECUTABLE }; |
| 316 | 321 |
| 317 enum VisitMode { VISIT_ALL, VISIT_ALL_IN_SCAVENGE, VISIT_ONLY_STRONG }; | 322 enum VisitMode { VISIT_ALL, VISIT_ALL_IN_SCAVENGE, VISIT_ONLY_STRONG }; |
| 318 | 323 |
| 319 // Flag indicating whether code is built in to the VM (one of the natives | 324 // Flag indicating whether code is built into the VM (one of the natives files). |
| 320 // files). | |
| 321 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE }; | 325 enum NativesFlag { NOT_NATIVES_CODE, NATIVES_CODE }; |
| 322 | 326 |
| 323 | 327 |
| 324 // A CodeDesc describes a buffer holding instructions and relocation | 328 // A CodeDesc describes a buffer holding instructions and relocation |
| 325 // information. The instructions start at the beginning of the buffer | 329 // information. The instructions start at the beginning of the buffer |
| 326 // and grow forward, the relocation information starts at the end of | 330 // and grow forward, the relocation information starts at the end of |
| 327 // the buffer and grows backward. | 331 // the buffer and grows backward. |
| 328 // | 332 // |
| 329 // |<--------------- buffer_size ---------------->| | 333 // |<--------------- buffer_size ---------------->| |
| 330 // |<-- instr_size -->| |<-- reloc_size -->| | 334 // |<-- instr_size -->| |<-- reloc_size -->| |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 #if defined(__GNUC__) && !defined(DEBUG) | 570 #if defined(__GNUC__) && !defined(DEBUG) |
| 567 #if (__GNUC__ >= 4) | 571 #if (__GNUC__ >= 4) |
| 568 #define INLINE(header) inline header __attribute__((always_inline)) | 572 #define INLINE(header) inline header __attribute__((always_inline)) |
| 569 #else | 573 #else |
| 570 #define INLINE(header) inline __attribute__((always_inline)) header | 574 #define INLINE(header) inline __attribute__((always_inline)) header |
| 571 #endif | 575 #endif |
| 572 #else | 576 #else |
| 573 #define INLINE(header) inline header | 577 #define INLINE(header) inline header |
| 574 #endif | 578 #endif |
| 575 | 579 |
| 576 // The type-based aliasing rule allows the compiler to assume that pointers of | |
| 577 // different types (for some definition of different) never alias each other. | |
| 578 // Thus the following code does not work: | |
| 579 // | |
| 580 // float f = foo(); | |
| 581 // int fbits = *(int*)(&f); | |
| 582 // | |
| 583 // The compiler 'knows' that the int pointer can't refer to f since the types | |
| 584 // don't match, so the compiler may cache f in a register, leaving random data | |
| 585 // in fbits. Using C++ style casts makes no difference, however a pointer to | |
| 586 // char data is assumed to alias any other pointer. This is the 'memcpy | |
| 587 // exception'. | |
| 588 // | |
| 589 // Bit_cast uses the memcpy exception to move the bits from a variable of one | |
| 590 // type of a variable of another type. Of course the end result is likely to | |
| 591 // be implementation dependent. Most compilers (gcc-4.2 and MSVC 2005) | |
| 592 // will completely optimize bit_cast away. | |
| 593 // | |
| 594 // There is an additional use for bit_cast. | |
| 595 // Recent gccs will warn when they see casts that may result in breakage due to | |
| 596 // the type-based aliasing rule. If you have checked that there is no breakage | |
| 597 // you can use bit_cast to cast one pointer type to another. This confuses gcc | |
| 598 // enough that it can no longer see that you have cast one pointer type to | |
| 599 // another thus avoiding the warning. | |
| 600 template <class Dest, class Source> | |
| 601 inline Dest bit_cast(const Source& source) { | |
| 602 // Compile time assertion: sizeof(Dest) == sizeof(Source) | |
| 603 // A compile error here means your Dest and Source have different sizes. | |
| 604 typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1]; | |
| 605 | |
| 606 Dest dest; | |
| 607 memcpy(&dest, &source, sizeof(dest)); | |
| 608 return dest; | |
| 609 } | |
| 610 | |
| 611 | |
| 612 // Feature flags bit positions. They are mostly based on the CPUID spec. | 580 // Feature flags bit positions. They are mostly based on the CPUID spec. |
| 613 // (We assign CPUID itself to one of the currently reserved bits -- | 581 // (We assign CPUID itself to one of the currently reserved bits -- |
| 614 // feel free to change this if needed.) | 582 // feel free to change this if needed.) |
| 615 enum CpuFeature { SSE3 = 32, // x86 | 583 enum CpuFeature { SSE3 = 32, // x86 |
| 616 SSE2 = 26, // x86 | 584 SSE2 = 26, // x86 |
| 617 CMOV = 15, // x86 | 585 CMOV = 15, // x86 |
| 618 RDTSC = 4, // x86 | 586 RDTSC = 4, // x86 |
| 619 CPUID = 10, // x86 | 587 CPUID = 10, // x86 |
| 620 VFP3 = 1, // ARM | 588 VFP3 = 1, // ARM |
| 621 ARMv7 = 2, // ARM | 589 ARMv7 = 2, // ARM |
| 622 SAHF = 0}; // x86 | 590 SAHF = 0}; // x86 |
| 623 | 591 |
| 624 } } // namespace v8::internal | 592 } } // namespace v8::internal |
| 625 | 593 |
| 626 #endif // V8_GLOBALS_H_ | 594 #endif // V8_GLOBALS_H_ |
| OLD | NEW |