Revision: 22048
Author:   [email protected]
Date:     Fri Jun 27 08:38:56 2014 UTC
Log:      Remove dependency from platform files on v8.h

Pass flag values in through a central initialize call.

We still depend on utils.h for RoundUp and IsAligned.

BUG=none
[email protected]
LOG=n

Review URL: https://codereview.chromium.org/353113003
http://code.google.com/p/v8/source/detail?r=22048

Modified:
 /branches/bleeding_edge/src/base/macros.h
 /branches/bleeding_edge/src/globals.h
 /branches/bleeding_edge/src/platform-cygwin.cc
 /branches/bleeding_edge/src/platform-freebsd.cc
 /branches/bleeding_edge/src/platform-linux.cc
 /branches/bleeding_edge/src/platform-macos.cc
 /branches/bleeding_edge/src/platform-openbsd.cc
 /branches/bleeding_edge/src/platform-posix.cc
 /branches/bleeding_edge/src/platform-qnx.cc
 /branches/bleeding_edge/src/platform-solaris.cc
 /branches/bleeding_edge/src/platform-win32.cc
 /branches/bleeding_edge/src/platform.h
 /branches/bleeding_edge/src/v8.cc

=======================================
--- /branches/bleeding_edge/src/base/macros.h   Tue Jun 17 16:27:19 2014 UTC
+++ /branches/bleeding_edge/src/base/macros.h   Fri Jun 27 08:38:56 2014 UTC
@@ -6,6 +6,7 @@
 #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
@@ -112,6 +113,52 @@

 #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);
=======================================
--- /branches/bleeding_edge/src/globals.h       Tue Jun 24 09:31:30 2014 UTC
+++ /branches/bleeding_edge/src/globals.h       Fri Jun 27 08:38:56 2014 UTC
@@ -66,51 +66,6 @@
 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

=======================================
--- /branches/bleeding_edge/src/platform-cygwin.cc Fri Jun 20 08:40:11 2014 UTC +++ /branches/bleeding_edge/src/platform-cygwin.cc Fri Jun 27 08:38:56 2014 UTC
@@ -14,12 +14,13 @@
 #include <sys/time.h>
 #include <unistd.h>     // sysconf

+#include <cmath>
+
 #undef MAP_TYPE

-#include "src/v8.h"
-
 #include "src/base/win32-headers.h"
 #include "src/platform.h"
+#include "src/utils.h"

 namespace v8 {
 namespace internal {
@@ -237,7 +238,7 @@
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);
@@ -245,7 +246,7 @@
   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);
=======================================
--- /branches/bleeding_edge/src/platform-freebsd.cc Fri Jun 20 08:40:11 2014 UTC +++ /branches/bleeding_edge/src/platform-freebsd.cc Fri Jun 27 08:38:56 2014 UTC
@@ -25,11 +25,12 @@
 #include <stdarg.h>
 #include <strings.h>    // index

+#include <cmath>
+
 #undef MAP_TYPE

-#include "src/v8.h"
-
 #include "src/platform.h"
+#include "src/utils.h"


 namespace v8 {
@@ -192,8 +193,8 @@
                            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.
=======================================
--- /branches/bleeding_edge/src/platform-linux.cc Fri Jun 20 08:40:11 2014 UTC +++ /branches/bleeding_edge/src/platform-linux.cc Fri Jun 27 08:38:56 2014 UTC
@@ -39,11 +39,12 @@
 #include <sanitizer/lsan_interface.h>
 #endif

+#include <cmath>
+
 #undef MAP_TYPE

-#include "src/v8.h"
-
 #include "src/platform.h"
+#include "src/utils.h"


 namespace v8 {
@@ -254,9 +255,9 @@
   // 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(),
@@ -302,8 +303,8 @@
                            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.
=======================================
--- /branches/bleeding_edge/src/platform-macos.cc Fri Jun 20 08:40:11 2014 UTC +++ /branches/bleeding_edge/src/platform-macos.cc Fri Jun 27 08:38:56 2014 UTC
@@ -31,11 +31,12 @@
 #include <sys/time.h>
 #include <sys/types.h>

+#include <cmath>
+
 #undef MAP_TYPE

-#include "src/v8.h"
-
 #include "src/platform.h"
+#include "src/utils.h"


 namespace v8 {
@@ -194,8 +195,8 @@
                            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.
=======================================
--- /branches/bleeding_edge/src/platform-openbsd.cc Fri Jun 20 08:40:11 2014 UTC +++ /branches/bleeding_edge/src/platform-openbsd.cc Fri Jun 27 08:38:56 2014 UTC
@@ -23,11 +23,12 @@
 #include <sys/types.h>  // mmap & munmap
 #include <unistd.h>     // sysconf

+#include <cmath>
+
 #undef MAP_TYPE

-#include "src/v8.h"
-
 #include "src/platform.h"
+#include "src/utils.h"


 namespace v8 {
@@ -184,9 +185,9 @@
   // 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,
@@ -223,8 +224,8 @@
                            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.
=======================================
--- /branches/bleeding_edge/src/platform-posix.cc Wed Jun 25 08:20:42 2014 UTC +++ /branches/bleeding_edge/src/platform-posix.cc Fri Jun 27 08:38:56 2014 UTC
@@ -8,6 +8,7 @@

 #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
@@ -41,10 +42,13 @@
 #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
@@ -54,9 +58,17 @@
 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() {
   return static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
@@ -191,8 +203,18 @@
     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;
 }


@@ -253,7 +275,7 @@


 void OS::Abort() {
-  if (FLAG_hard_abort) {
+  if (g_hard_abort) {
     V8_IMMEDIATE_CRASH();
   }
   // Redirect to std abort to signal abnormal program termination.
=======================================
--- /branches/bleeding_edge/src/platform-qnx.cc Fri Jun 20 08:40:11 2014 UTC
+++ /branches/bleeding_edge/src/platform-qnx.cc Fri Jun 27 08:38:56 2014 UTC
@@ -27,11 +27,12 @@
 #include <sys/types.h>  // mmap & munmap
 #include <unistd.h>     // sysconf

+#include <cmath>
+
 #undef MAP_TYPE

-#include "src/v8.h"
-
 #include "src/platform.h"
+#include "src/utils.h"


 namespace v8 {
@@ -259,8 +260,8 @@
                            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.
=======================================
--- /branches/bleeding_edge/src/platform-solaris.cc Fri Jun 20 08:40:11 2014 UTC +++ /branches/bleeding_edge/src/platform-solaris.cc Fri Jun 27 08:38:56 2014 UTC
@@ -23,12 +23,12 @@
 #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
@@ -165,8 +165,8 @@
                            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.
=======================================
--- /branches/bleeding_edge/src/platform-win32.cc Wed Jun 25 08:20:42 2014 UTC +++ /branches/bleeding_edge/src/platform-win32.cc Fri Jun 27 08:38:56 2014 UTC
@@ -17,10 +17,10 @@

 #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
@@ -103,6 +103,12 @@
 namespace v8 {
 namespace internal {

+namespace {
+
+bool g_hard_abort = false;
+
+}  // namespace
+
 intptr_t OS::MaxVirtualMemory() {
   return 0;
 }
@@ -713,8 +719,12 @@
     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;
 }


@@ -808,7 +818,7 @@


 void OS::Abort() {
-  if (FLAG_hard_abort) {
+  if (g_hard_abort) {
     V8_IMMEDIATE_CRASH();
   }
   // Make the MSVCRT do a silent abort.
@@ -1217,7 +1227,7 @@
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);
@@ -1225,7 +1235,7 @@
   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);
=======================================
--- /branches/bleeding_edge/src/platform.h      Wed Jun 25 08:20:42 2014 UTC
+++ /branches/bleeding_edge/src/platform.h      Fri Jun 27 08:38:56 2014 UTC
@@ -141,6 +141,14 @@

 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
@@ -212,10 +220,6 @@
   // 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();

@@ -306,6 +310,10 @@
  private:
   static const int msPerSecond = 1000;

+#if V8_OS_POSIX
+  static const char* GetGCFakeMMapFile();
+#endif
+
   DISALLOW_IMPLICIT_CONSTRUCTORS(OS);
 };

=======================================
--- /branches/bleeding_edge/src/v8.cc   Wed Jun 25 08:20:42 2014 UTC
+++ /branches/bleeding_edge/src/v8.cc   Fri Jun 27 08:38:56 2014 UTC
@@ -90,7 +90,7 @@
     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;

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to