Upgrade V8 to 5.1.281.57  DO NOT MERGE

FPIIM-449

Change-Id: Id981b686b4d587ac31697662eb98bb34be42ad90
(cherry picked from commit 3b9bc31999c9787eb726ecdbfd5796bfdec32a18)
diff --git a/src/base/accounting-allocator.cc b/src/base/accounting-allocator.cc
new file mode 100644
index 0000000..2269c60
--- /dev/null
+++ b/src/base/accounting-allocator.cc
@@ -0,0 +1,33 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "src/base/accounting-allocator.h"
+
+#include <cstdlib>
+
+#if V8_LIBC_BIONIC
+#include <malloc.h>  // NOLINT
+#endif
+
+namespace v8 {
+namespace base {
+
+void* AccountingAllocator::Allocate(size_t bytes) {
+  void* memory = malloc(bytes);
+  if (memory) NoBarrier_AtomicIncrement(&current_memory_usage_, bytes);
+  return memory;
+}
+
+void AccountingAllocator::Free(void* memory, size_t bytes) {
+  free(memory);
+  NoBarrier_AtomicIncrement(&current_memory_usage_,
+                            -static_cast<AtomicWord>(bytes));
+}
+
+size_t AccountingAllocator::GetCurrentMemoryUsage() const {
+  return NoBarrier_Load(&current_memory_usage_);
+}
+
+}  // namespace base
+}  // namespace v8
diff --git a/src/base/accounting-allocator.h b/src/base/accounting-allocator.h
new file mode 100644
index 0000000..ce67f37
--- /dev/null
+++ b/src/base/accounting-allocator.h
@@ -0,0 +1,34 @@
+// Copyright 2016 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_BASE_ACCOUNTING_ALLOCATOR_H_
+#define V8_BASE_ACCOUNTING_ALLOCATOR_H_
+
+#include "src/base/atomicops.h"
+#include "src/base/macros.h"
+
+namespace v8 {
+namespace base {
+
+class AccountingAllocator final {
+ public:
+  AccountingAllocator() = default;
+  ~AccountingAllocator() = default;
+
+  // Returns nullptr on failed allocation.
+  void* Allocate(size_t bytes);
+  void Free(void* memory, size_t bytes);
+
+  size_t GetCurrentMemoryUsage() const;
+
+ private:
+  AtomicWord current_memory_usage_ = 0;
+
+  DISALLOW_COPY_AND_ASSIGN(AccountingAllocator);
+};
+
+}  // namespace base
+}  // namespace v8
+
+#endif  // V8_BASE_ACCOUNTING_ALLOCATOR_H_
diff --git a/src/base/atomicops_internals_arm_gcc.h b/src/base/atomicops_internals_arm_gcc.h
index 6c8b27e..8d049e0 100644
--- a/src/base/atomicops_internals_arm_gcc.h
+++ b/src/base/atomicops_internals_arm_gcc.h
@@ -44,14 +44,15 @@
 //
 
 inline void MemoryBarrier() {
-#if defined(__linux__) || defined(__ANDROID__)
+#if defined(__ANDROID__)
   // Note: This is a function call, which is also an implicit compiler barrier.
   typedef void (*KernelMemoryBarrierFunc)();
   ((KernelMemoryBarrierFunc)0xffff0fa0)();
 #elif defined(__QNXNTO__)
   __cpu_membarrier();
 #else
-#error MemoryBarrier() is not implemented on this platform.
+  // Fallback to GCC built-in function
+  __sync_synchronize();
 #endif
 }
 
diff --git a/src/base/cpu.cc b/src/base/cpu.cc
index 777f379..12a3881 100644
--- a/src/base/cpu.cc
+++ b/src/base/cpu.cc
@@ -468,7 +468,12 @@
     char* end;
     architecture_ = strtol(architecture, &end, 10);
     if (end == architecture) {
-      architecture_ = 0;
+      // Kernels older than 3.18 report "CPU architecture: AArch64" on ARMv8.
+      if (strcmp(architecture, "AArch64") == 0) {
+        architecture_ = 8;
+      } else {
+        architecture_ = 0;
+      }
     }
     delete[] architecture;
 
diff --git a/src/base/logging.cc b/src/base/logging.cc
index a2688c9..ebab129 100644
--- a/src/base/logging.cc
+++ b/src/base/logging.cc
@@ -115,3 +115,14 @@
   fflush(stderr);
   v8::base::OS::Abort();
 }
+
+extern "C" void V8_RuntimeError(const char* file, int line,
+                                const char* message) {
+  fflush(stdout);
+  fflush(stderr);
+  v8::base::OS::PrintError("\n\n#\n# Runtime error in %s, line %d\n# ", file,
+                           line);
+  v8::base::OS::PrintError("\n# %s\n", message);
+  v8::base::DumpBacktrace();
+  fflush(stderr);
+}
diff --git a/src/base/logging.h b/src/base/logging.h
index e4e3f49..15322f6 100644
--- a/src/base/logging.h
+++ b/src/base/logging.h
@@ -14,6 +14,8 @@
 extern "C" V8_NORETURN void V8_Fatal(const char* file, int line,
                                      const char* format, ...);
 
+extern "C" void V8_RuntimeError(const char* file, int line,
+                                const char* message);
 
 // The FATAL, UNREACHABLE and UNIMPLEMENTED macros are useful during
 // development, but they should not be relied on in the final product.
diff --git a/src/base/macros.h b/src/base/macros.h
index 10cab4b..3f09b2b 100644
--- a/src/base/macros.h
+++ b/src/base/macros.h
@@ -278,6 +278,17 @@
 #if V8_OS_MACOSX
 #undef V8PRIxPTR
 #define V8PRIxPTR "lx"
+#undef V8PRIuPTR
+#define V8PRIuPTR "lxu"
+#endif
+
+// GCC on S390 31-bit expands 'size_t' to 'long unsigned int'
+// instead of 'int', resulting in compilation errors with %d.
+// The printf format specifier needs to be %zd instead.
+#if V8_HOST_ARCH_S390 && !V8_HOST_ARCH_64_BIT
+#define V8_SIZET_PREFIX "z"
+#else
+#define V8_SIZET_PREFIX ""
 #endif
 
 // The following macro works on both 32 and 64-bit platforms.
diff --git a/src/base/platform/platform-linux.cc b/src/base/platform/platform-linux.cc
index a4b742a..1323a0d 100644
--- a/src/base/platform/platform-linux.cc
+++ b/src/base/platform/platform-linux.cc
@@ -72,14 +72,14 @@
 #define GCC_VERSION (__GNUC__ * 10000                                          \
                      + __GNUC_MINOR__ * 100                                    \
                      + __GNUC_PATCHLEVEL__)
-#if GCC_VERSION >= 40600
+#if GCC_VERSION >= 40600 && !defined(__clang__)
 #if defined(__ARM_PCS_VFP)
   return true;
 #else
   return false;
 #endif
 
-#elif GCC_VERSION < 40500
+#elif GCC_VERSION < 40500 && !defined(__clang__)
   return false;
 
 #else
@@ -89,7 +89,7 @@
       !defined(__VFP_FP__)
   return false;
 #else
-#error "Your version of GCC does not report the FP ABI compiled for."          \
+#error "Your version of compiler does not report the FP ABI compiled for."     \
        "Please report it on this issue"                                        \
        "http://code.google.com/p/v8/issues/detail?id=2140"
 
diff --git a/src/base/platform/platform-posix.cc b/src/base/platform/platform-posix.cc
index 046dbb6..bb340ab 100644
--- a/src/base/platform/platform-posix.cc
+++ b/src/base/platform/platform-posix.cc
@@ -81,6 +81,8 @@
   return 8;
 #elif V8_TARGET_ARCH_MIPS
   return 8;
+#elif V8_TARGET_ARCH_S390
+  return 8;
 #else
   // Otherwise we just assume 16 byte alignment, i.e.:
   // - With gcc 4.4 the tree vectorization optimizer can generate code
@@ -185,6 +187,15 @@
   // Little-endian Linux: 48 bits of virtual addressing.
   raw_addr &= V8_UINT64_C(0x3ffffffff000);
 #endif
+#elif V8_TARGET_ARCH_S390X
+  // Linux on Z uses bits 22-32 for Region Indexing, which translates to 42 bits
+  // of virtual addressing.  Truncate to 40 bits to allow kernel chance to
+  // fulfill request.
+  raw_addr &= V8_UINT64_C(0xfffffff000);
+#elif V8_TARGET_ARCH_S390
+  // 31 bits of virtual addressing.  Truncate to 29 bits to allow kernel chance
+  // to fulfill request.
+  raw_addr &= 0x1ffff000;
 #else
   raw_addr &= 0x3ffff000;
 
@@ -252,6 +263,9 @@
 #endif  // V8_OS_NACL
 #elif V8_HOST_ARCH_X64
   asm("int $3");
+#elif V8_HOST_ARCH_S390
+  // Software breakpoint instruction is 0x0001
+  asm volatile(".word 0x0001");
 #else
 #error Unsupported host architecture.
 #endif
@@ -415,9 +429,10 @@
   return (remove(path) == 0);
 }
 
+char OS::DirectorySeparator() { return '/'; }
 
 bool OS::isDirectorySeparator(const char ch) {
-  return ch == '/';
+  return ch == DirectorySeparator();
 }
 
 
diff --git a/src/base/platform/platform-win32.cc b/src/base/platform/platform-win32.cc
index 6afa6f9..0076a35 100644
--- a/src/base/platform/platform-win32.cc
+++ b/src/base/platform/platform-win32.cc
@@ -574,6 +574,7 @@
   return (DeleteFileA(path) != 0);
 }
 
+char OS::DirectorySeparator() { return '\\'; }
 
 bool OS::isDirectorySeparator(const char ch) {
   return ch == '/' || ch == '\\';
diff --git a/src/base/platform/platform.h b/src/base/platform/platform.h
index 89d6225..5b2dbc9 100644
--- a/src/base/platform/platform.h
+++ b/src/base/platform/platform.h
@@ -142,6 +142,7 @@
   static FILE* FOpen(const char* path, const char* mode);
   static bool Remove(const char* path);
 
+  static char DirectorySeparator();
   static bool isDirectorySeparator(const char ch);
 
   // Opens a temporary file, the file is auto removed on close.
@@ -290,6 +291,10 @@
   // by address().
   VirtualMemory(size_t size, size_t alignment);
 
+  // Construct a virtual memory by assigning it some already mapped address
+  // and size.
+  VirtualMemory(void* address, size_t size) : address_(address), size_(size) {}
+
   // Releases the reserved memory, if any, controlled by this VirtualMemory
   // object.
   ~VirtualMemory();
diff --git a/src/base/platform/semaphore.cc b/src/base/platform/semaphore.cc
index 9e7b59a..284474e 100644
--- a/src/base/platform/semaphore.cc
+++ b/src/base/platform/semaphore.cc
@@ -94,8 +94,7 @@
 
 void Semaphore::Signal() {
   int result = sem_post(&native_handle_);
-  DCHECK_EQ(0, result);
-  USE(result);
+  CHECK_EQ(0, result);
 }
 
 
diff --git a/src/base/platform/time.cc b/src/base/platform/time.cc
index e847d54..6d5e538 100644
--- a/src/base/platform/time.cc
+++ b/src/base/platform/time.cc
@@ -520,14 +520,6 @@
   return high_res_tick_clock.Pointer()->IsHighResolution();
 }
 
-
-// static
-TimeTicks TimeTicks::KernelTimestampNow() { return TimeTicks(0); }
-
-
-// static
-bool TimeTicks::KernelTimestampAvailable() { return false; }
-
 #else  // V8_OS_WIN
 
 TimeTicks TimeTicks::Now() {
@@ -566,82 +558,6 @@
   return true;
 }
 
-
-#if V8_OS_LINUX
-
-class KernelTimestampClock {
- public:
-  KernelTimestampClock() : clock_fd_(-1), clock_id_(kClockInvalid) {
-    clock_fd_ = open(kTraceClockDevice, O_RDONLY);
-    if (clock_fd_ == -1) {
-      return;
-    }
-    clock_id_ = get_clockid(clock_fd_);
-  }
-
-  virtual ~KernelTimestampClock() {
-    if (clock_fd_ != -1) {
-      close(clock_fd_);
-    }
-  }
-
-  int64_t Now() {
-    if (clock_id_ == kClockInvalid) {
-      return 0;
-    }
-
-    struct timespec ts;
-
-    clock_gettime(clock_id_, &ts);
-    return ((int64_t)ts.tv_sec * kNsecPerSec) + ts.tv_nsec;
-  }
-
-  bool Available() { return clock_id_ != kClockInvalid; }
-
- private:
-  static const clockid_t kClockInvalid = -1;
-  static const char kTraceClockDevice[];
-  static const uint64_t kNsecPerSec = 1000000000;
-
-  int clock_fd_;
-  clockid_t clock_id_;
-
-  static int get_clockid(int fd) { return ((~(clockid_t)(fd) << 3) | 3); }
-};
-
-
-// Timestamp module name
-const char KernelTimestampClock::kTraceClockDevice[] = "/dev/trace_clock";
-
-#else
-
-class KernelTimestampClock {
- public:
-  KernelTimestampClock() {}
-
-  int64_t Now() { return 0; }
-  bool Available() { return false; }
-};
-
-#endif  // V8_OS_LINUX
-
-static LazyStaticInstance<KernelTimestampClock,
-                          DefaultConstructTrait<KernelTimestampClock>,
-                          ThreadSafeInitOnceTrait>::type kernel_tick_clock =
-    LAZY_STATIC_INSTANCE_INITIALIZER;
-
-
-// static
-TimeTicks TimeTicks::KernelTimestampNow() {
-  return TimeTicks(kernel_tick_clock.Pointer()->Now());
-}
-
-
-// static
-bool TimeTicks::KernelTimestampAvailable() {
-  return kernel_tick_clock.Pointer()->Available();
-}
-
 #endif  // V8_OS_WIN
 
 }  // namespace base
diff --git a/src/base/platform/time.h b/src/base/platform/time.h
index 29300e5..c8140ef 100644
--- a/src/base/platform/time.h
+++ b/src/base/platform/time.h
@@ -318,13 +318,6 @@
   // Returns true if the high-resolution clock is working on this system.
   static bool IsHighResolutionClockWorking();
 
-  // Returns Linux kernel timestamp for generating profiler events. This method
-  // returns null TimeTicks if the kernel cannot provide the timestamps (e.g.,
-  // on non-Linux OS or if the kernel module for timestamps is not loaded).
-
-  static TimeTicks KernelTimestampNow();
-  static bool KernelTimestampAvailable();
-
   // Returns true if this object has not been initialized.
   bool IsNull() const { return ticks_ == 0; }
 
diff --git a/src/base/win32-headers.h b/src/base/win32-headers.h
index 2d94abd..20ec8e0 100644
--- a/src/base/win32-headers.h
+++ b/src/base/win32-headers.h
@@ -76,6 +76,8 @@
 #undef CreateSemaphore
 #undef Yield
 #undef RotateRight32
+#undef RotateLeft32
 #undef RotateRight64
+#undef RotateLeft64
 
 #endif  // V8_BASE_WIN32_HEADERS_H_