#define V8_BASE_MACROS_H_
#include "include/v8stdint.h"
+#include "src/base/build_config.h"
// The expression OFFSET_OF(type, field) computes the byte-offset
#define IS_POWER_OF_TWO(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
+
+// Define our own macros for writing 64-bit constants. This is less fragile
+// than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
+// works on compilers that don't have it (like MSVC).
+#if V8_CC_MSVC
+# define V8_UINT64_C(x) (x ## UI64)
+# define V8_INT64_C(x) (x ## I64)
+# if V8_HOST_ARCH_64_BIT
+# define V8_INTPTR_C(x) (x ## I64)
+# define V8_PTR_PREFIX "ll"
+# else
+# define V8_INTPTR_C(x) (x)
+# define V8_PTR_PREFIX ""
+# endif // V8_HOST_ARCH_64_BIT
+#elif V8_CC_MINGW64
+# define V8_UINT64_C(x) (x ## ULL)
+# define V8_INT64_C(x) (x ## LL)
+# define V8_INTPTR_C(x) (x ## LL)
+# define V8_PTR_PREFIX "I64"
+#elif V8_HOST_ARCH_64_BIT
+# if V8_OS_MACOSX
+# define V8_UINT64_C(x) (x ## ULL)
+# define V8_INT64_C(x) (x ## LL)
+# else
+# define V8_UINT64_C(x) (x ## UL)
+# define V8_INT64_C(x) (x ## L)
+# endif
+# define V8_INTPTR_C(x) (x ## L)
+# define V8_PTR_PREFIX "l"
+#else
+# define V8_UINT64_C(x) (x ## ULL)
+# define V8_INT64_C(x) (x ## LL)
+# define V8_INTPTR_C(x) (x)
+# define V8_PTR_PREFIX ""
+#endif
+
+#define V8PRIxPTR V8_PTR_PREFIX "x"
+#define V8PRIdPTR V8_PTR_PREFIX "d"
+#define V8PRIuPTR V8_PTR_PREFIX "u"
+
+// Fix for Mac OS X defining uintptr_t as "unsigned long":
+#if V8_OS_MACOSX
+#undef V8PRIxPTR
+#define V8PRIxPTR "lx"
+#endif
+
// The following macro works on both 32 and 64-bit platforms.
// Usage: instead of writing 0x1234567890123456
// write V8_2PART_UINT64_C(0x12345678,90123456);
typedef uint8_t byte;
typedef byte* Address;
-// Define our own macros for writing 64-bit constants. This is less fragile
-// than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
-// works on compilers that don't have it (like MSVC).
-#if V8_CC_MSVC
-# define V8_UINT64_C(x) (x ## UI64)
-# define V8_INT64_C(x) (x ## I64)
-# if V8_HOST_ARCH_64_BIT
-# define V8_INTPTR_C(x) (x ## I64)
-# define V8_PTR_PREFIX "ll"
-# else
-# define V8_INTPTR_C(x) (x)
-# define V8_PTR_PREFIX ""
-# endif // V8_HOST_ARCH_64_BIT
-#elif V8_CC_MINGW64
-# define V8_UINT64_C(x) (x ## ULL)
-# define V8_INT64_C(x) (x ## LL)
-# define V8_INTPTR_C(x) (x ## LL)
-# define V8_PTR_PREFIX "I64"
-#elif V8_HOST_ARCH_64_BIT
-# if V8_OS_MACOSX
-# define V8_UINT64_C(x) (x ## ULL)
-# define V8_INT64_C(x) (x ## LL)
-# else
-# define V8_UINT64_C(x) (x ## UL)
-# define V8_INT64_C(x) (x ## L)
-# endif
-# define V8_INTPTR_C(x) (x ## L)
-# define V8_PTR_PREFIX "l"
-#else
-# define V8_UINT64_C(x) (x ## ULL)
-# define V8_INT64_C(x) (x ## LL)
-# define V8_INTPTR_C(x) (x)
-# define V8_PTR_PREFIX ""
-#endif
-
-#define V8PRIxPTR V8_PTR_PREFIX "x"
-#define V8PRIdPTR V8_PTR_PREFIX "d"
-#define V8PRIuPTR V8_PTR_PREFIX "u"
-
-// Fix for Mac OS X defining uintptr_t as "unsigned long":
-#if V8_OS_MACOSX
-#undef V8PRIxPTR
-#define V8PRIxPTR "lx"
-#endif
-
// -----------------------------------------------------------------------------
// Constants
#include <sys/time.h>
#include <unistd.h> // sysconf
-#undef MAP_TYPE
+#include <cmath>
-#include "src/v8.h"
+#undef MAP_TYPE
#include "src/base/win32-headers.h"
#include "src/platform.h"
+#include "src/utils.h"
namespace v8 {
namespace internal {
static_cast<intptr_t>(OS::AllocateAlignment()));
void* address = ReserveRegion(request_size);
if (address == NULL) return;
- Address base = RoundUp(static_cast<Address>(address), alignment);
+ uint8_t* base = RoundUp(static_cast<uint8_t*>(address), alignment);
// Try reducing the size by freeing and then reallocating a specific area.
bool result = ReleaseRegion(address, request_size);
USE(result);
address = VirtualAlloc(base, size, MEM_RESERVE, PAGE_NOACCESS);
if (address != NULL) {
request_size = size;
- ASSERT(base == static_cast<Address>(address));
+ ASSERT(base == static_cast<uint8_t*>(address));
} else {
// Resizing failed, just go with a bigger area.
address = ReserveRegion(request_size);
#include <stdarg.h>
#include <strings.h> // index
-#undef MAP_TYPE
+#include <cmath>
-#include "src/v8.h"
+#undef MAP_TYPE
#include "src/platform.h"
+#include "src/utils.h"
namespace v8 {
kMmapFdOffset);
if (reservation == MAP_FAILED) return;
- Address base = static_cast<Address>(reservation);
- Address aligned_base = RoundUp(base, alignment);
+ uint8_t* base = static_cast<uint8_t*>(reservation);
+ uint8_t* aligned_base = RoundUp(base, alignment);
ASSERT_LE(base, aligned_base);
// Unmap extra memory reserved before and after the desired block.
#include <sanitizer/lsan_interface.h>
#endif
-#undef MAP_TYPE
+#include <cmath>
-#include "src/v8.h"
+#undef MAP_TYPE
#include "src/platform.h"
+#include "src/utils.h"
namespace v8 {
// by the kernel and allows us to synchronize V8 code log and the
// kernel log.
int size = sysconf(_SC_PAGESIZE);
- FILE* f = fopen(FLAG_gc_fake_mmap, "w+");
+ FILE* f = fopen(OS::GetGCFakeMMapFile(), "w+");
if (f == NULL) {
- OS::PrintError("Failed to open %s\n", FLAG_gc_fake_mmap);
+ OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile());
OS::Abort();
}
void* addr = mmap(OS::GetRandomMmapAddr(),
kMmapFdOffset);
if (reservation == MAP_FAILED) return;
- Address base = static_cast<Address>(reservation);
- Address aligned_base = RoundUp(base, alignment);
+ uint8_t* base = static_cast<uint8_t*>(reservation);
+ uint8_t* aligned_base = RoundUp(base, alignment);
ASSERT_LE(base, aligned_base);
// Unmap extra memory reserved before and after the desired block.
#include <sys/time.h>
#include <sys/types.h>
-#undef MAP_TYPE
+#include <cmath>
-#include "src/v8.h"
+#undef MAP_TYPE
#include "src/platform.h"
+#include "src/utils.h"
namespace v8 {
kMmapFdOffset);
if (reservation == MAP_FAILED) return;
- Address base = static_cast<Address>(reservation);
- Address aligned_base = RoundUp(base, alignment);
+ uint8_t* base = static_cast<uint8_t*>(reservation);
+ uint8_t* aligned_base = RoundUp(base, alignment);
ASSERT_LE(base, aligned_base);
// Unmap extra memory reserved before and after the desired block.
#include <sys/types.h> // mmap & munmap
#include <unistd.h> // sysconf
-#undef MAP_TYPE
+#include <cmath>
-#include "src/v8.h"
+#undef MAP_TYPE
#include "src/platform.h"
+#include "src/utils.h"
namespace v8 {
// by the kernel and allows us to synchronize V8 code log and the
// kernel log.
int size = sysconf(_SC_PAGESIZE);
- FILE* f = fopen(FLAG_gc_fake_mmap, "w+");
+ FILE* f = fopen(OS::GetGCFakeMMapFile(), "w+");
if (f == NULL) {
- OS::PrintError("Failed to open %s\n", FLAG_gc_fake_mmap);
+ OS::PrintError("Failed to open %s\n", OS::GetGCFakeMMapFile());
OS::Abort();
}
void* addr = mmap(NULL, size, PROT_READ | PROT_EXEC, MAP_PRIVATE,
kMmapFdOffset);
if (reservation == MAP_FAILED) return;
- Address base = static_cast<Address>(reservation);
- Address aligned_base = RoundUp(base, alignment);
+ uint8_t* base = static_cast<uint8_t*>(reservation);
+ uint8_t* aligned_base = RoundUp(base, alignment);
ASSERT_LE(base, aligned_base);
// Unmap extra memory reserved before and after the desired block.
#include <dlfcn.h>
#include <errno.h>
+#include <limits.h>
#include <pthread.h>
#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <pthread_np.h> // for pthread_set_name_np
#include <android/log.h> // NOLINT
#endif
-#include "src/v8.h"
+#include <cmath>
+#include <cstdlib>
#include "src/base/lazy-instance.h"
+#include "src/base/macros.h"
#include "src/platform.h"
+#include "src/platform/time.h"
#include "src/utils/random-number-generator.h"
#ifdef V8_FAST_TLS_SUPPORTED
namespace v8 {
namespace internal {
+namespace {
+
// 0 is never a valid thread id.
-static const pthread_t kNoThread = (pthread_t) 0;
+const pthread_t kNoThread = (pthread_t) 0;
+
+bool g_hard_abort = false;
+
+const char* g_gc_fake_mmap = NULL;
+
+} // namespace
int OS::NumberOfProcessorsOnline() {
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
-void OS::SetRandomSeed(int64_t seed) {
- platform_random_number_generator.Pointer()->SetSeed(seed);
+void OS::Initialize(int64_t random_seed, bool hard_abort,
+ const char* const gc_fake_mmap) {
+ if (random_seed) {
+ platform_random_number_generator.Pointer()->SetSeed(random_seed);
+ }
+ g_hard_abort = hard_abort;
+ g_gc_fake_mmap = gc_fake_mmap;
+}
+
+
+const char* OS::GetGCFakeMMapFile() {
+ return g_gc_fake_mmap;
}
void OS::Abort() {
- if (FLAG_hard_abort) {
+ if (g_hard_abort) {
V8_IMMEDIATE_CRASH();
}
// Redirect to std abort to signal abnormal program termination.
#include <sys/types.h> // mmap & munmap
#include <unistd.h> // sysconf
-#undef MAP_TYPE
+#include <cmath>
-#include "src/v8.h"
+#undef MAP_TYPE
#include "src/platform.h"
+#include "src/utils.h"
namespace v8 {
kMmapFdOffset);
if (reservation == MAP_FAILED) return;
- Address base = static_cast<Address>(reservation);
- Address aligned_base = RoundUp(base, alignment);
+ uint8_t* base = static_cast<uint8_t*>(reservation);
+ uint8_t* aligned_base = RoundUp(base, alignment);
ASSERT_LE(base, aligned_base);
// Unmap extra memory reserved before and after the desired block.
#include <ucontext.h> // walkstack(), getcontext()
#include <unistd.h> // getpagesize(), usleep()
+#include <cmath>
#undef MAP_TYPE
-#include "src/v8.h"
-
#include "src/platform.h"
+#include "src/utils.h"
// It seems there is a bug in some Solaris distributions (experienced in
kMmapFdOffset);
if (reservation == MAP_FAILED) return;
- Address base = static_cast<Address>(reservation);
- Address aligned_base = RoundUp(base, alignment);
+ uint8_t* base = static_cast<uint8_t*>(reservation);
+ uint8_t* aligned_base = RoundUp(base, alignment);
ASSERT_LE(base, aligned_base);
// Unmap extra memory reserved before and after the desired block.
#include "src/base/win32-headers.h"
-#include "src/v8.h"
-
#include "src/base/lazy-instance.h"
#include "src/platform.h"
+#include "src/platform/time.h"
+#include "src/utils.h"
#include "src/utils/random-number-generator.h"
#ifdef _MSC_VER
namespace v8 {
namespace internal {
+namespace {
+
+bool g_hard_abort = false;
+
+} // namespace
+
intptr_t OS::MaxVirtualMemory() {
return 0;
}
platform_random_number_generator = LAZY_INSTANCE_INITIALIZER;
-void OS::SetRandomSeed(int64_t seed) {
- platform_random_number_generator.Pointer()->SetSeed(seed);
+void OS::Initialize(int64_t random_seed, bool hard_abort,
+ const char* const gc_fake_mmap) {
+ if (random_seed) {
+ platform_random_number_generator.Pointer()->SetSeed(random_seed);
+ }
+ g_hard_abort = hard_abort;
}
void OS::Abort() {
- if (FLAG_hard_abort) {
+ if (g_hard_abort) {
V8_IMMEDIATE_CRASH();
}
// Make the MSVCRT do a silent abort.
static_cast<intptr_t>(OS::AllocateAlignment()));
void* address = ReserveRegion(request_size);
if (address == NULL) return;
- Address base = RoundUp(static_cast<Address>(address), alignment);
+ uint8_t* base = RoundUp(static_cast<uint8_t*>(address), alignment);
// Try reducing the size by freeing and then reallocating a specific area.
bool result = ReleaseRegion(address, request_size);
USE(result);
address = VirtualAlloc(base, size, MEM_RESERVE, PAGE_NOACCESS);
if (address != NULL) {
request_size = size;
- ASSERT(base == static_cast<Address>(address));
+ ASSERT(base == static_cast<uint8_t*>(address));
} else {
// Resizing failed, just go with a bigger area.
address = ReserveRegion(request_size);
class OS {
public:
+ // Initialize the OS class.
+ // - random_seed: Used for the GetRandomMmapAddress() if non-zero.
+ // - hard_abort: If true, OS::Abort() will crash instead of aborting.
+ // - gc_fake_mmap: Name of the file for fake gc mmap used in ll_prof.
+ static void Initialize(int64_t random_seed,
+ bool hard_abort,
+ const char* const gc_fake_mmap);
+
// Returns the accumulated user time for thread. This routine
// can be used for profiling. The implementation should
// strive for high-precision timer resolution, preferable
// Assign memory as a guard page so that access will cause an exception.
static void Guard(void* address, const size_t size);
- // Set a fixed random seed for the random number generator used for
- // GetRandomMmapAddr.
- static void SetRandomSeed(int64_t seed);
-
// Generate a random address to be used for hinting mmap().
static void* GetRandomMmapAddr();
private:
static const int msPerSecond = 1000;
+#if V8_OS_POSIX
+ static const char* GetGCFakeMMapFile();
+#endif
+
DISALLOW_IMPLICIT_CONSTRUCTORS(OS);
};
FLAG_max_semi_space_size = 1;
}
- if (FLAG_random_seed != 0) OS::SetRandomSeed(FLAG_random_seed);
+ OS::Initialize(FLAG_random_seed, FLAG_hard_abort, FLAG_gc_fake_mmap);
#ifdef V8_USE_DEFAULT_PLATFORM
platform_ = new DefaultPlatform;