Update V8 to version 4.1.0.21

This is a cherry-pick of all commits up to and including the
4.1.0.21 cherry-pick in Chromium.

Original commit message:

Version 4.1.0.21 (cherry-pick)

Merged 206e9136bde0f2b5ae8cb77afbb1e7833e5bd412

Unlink pages from the space page list after evacuation.

BUG=430201
LOG=N
R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/953813002

Cr-Commit-Position: refs/branch-heads/4.1@{#22}
Cr-Branched-From: 2e08d2a7aa9d65d269d8c57aba82eb38a8cb0a18-refs/heads/candidates@{#25353}

---

FPIIM-449

Change-Id: I8c23c7bbb70772b4858fe8a47b64fa97ee0d1f8c
diff --git a/src/ostreams.h b/src/ostreams.h
index 508a88d..56787f7 100644
--- a/src/ostreams.h
+++ b/src/ostreams.h
@@ -5,9 +5,11 @@
 #ifndef V8_OSTREAMS_H_
 #define V8_OSTREAMS_H_
 
-#include <stddef.h>
-#include <stdio.h>
-#include <string.h>
+#include <cstddef>
+#include <cstdio>
+#include <cstring>
+#include <ostream>  // NOLINT
+#include <streambuf>
 
 #include "include/v8config.h"
 #include "src/base/macros.h"
@@ -15,104 +17,28 @@
 namespace v8 {
 namespace internal {
 
-// An abstract base class for output streams with a cut-down standard interface.
-class OStream {
- public:
-  OStream() : hex_(false) { }
-  virtual ~OStream() { }
+class OFStreamBase : public std::streambuf {
+ protected:
+  explicit OFStreamBase(FILE* f);
+  virtual ~OFStreamBase();
 
-  // For manipulators like 'os << endl' or 'os << flush', etc.
-  OStream& operator<<(OStream& (*manipulator)(OStream& os)) {
-    return manipulator(*this);
-  }
-
-  // Numeric conversions.
-  OStream& operator<<(short x);  // NOLINT(runtime/int)
-  OStream& operator<<(unsigned short x);  // NOLINT(runtime/int)
-  OStream& operator<<(int x);
-  OStream& operator<<(unsigned int x);
-  OStream& operator<<(long x);  // NOLINT(runtime/int)
-  OStream& operator<<(unsigned long x);  // NOLINT(runtime/int)
-  OStream& operator<<(long long x);  // NOLINT(runtime/int)
-  OStream& operator<<(unsigned long long x);  // NOLINT(runtime/int)
-  OStream& operator<<(double x);
-  OStream& operator<<(void* x);
-
-  // Character output.
-  OStream& operator<<(char x);
-  OStream& operator<<(signed char x);
-  OStream& operator<<(unsigned char x);
-  OStream& operator<<(const char* s) { return write(s, strlen(s)); }
-  OStream& put(char c) { return write(&c, 1); }
-
-  // Primitive format flag handling, can be extended if needed.
-  OStream& dec();
-  OStream& hex();
-
-  virtual OStream& write(const char* s, size_t n) = 0;
-  virtual OStream& flush() = 0;
-
- private:
-  template<class T> OStream& print(const char* format, T x);
-
-  bool hex_;
-
-  DISALLOW_COPY_AND_ASSIGN(OStream);
-};
-
-
-// Some manipulators.
-OStream& flush(OStream& os);  // NOLINT(runtime/references)
-OStream& endl(OStream& os);  // NOLINT(runtime/references)
-OStream& dec(OStream& os);  // NOLINT(runtime/references)
-OStream& hex(OStream& os);  // NOLINT(runtime/references)
-
-
-// An output stream writing to a character buffer.
-class OStringStream: public OStream {
- public:
-  OStringStream() : size_(0), capacity_(32), data_(allocate(capacity_)) {
-    data_[0] = '\0';
-  }
-  ~OStringStream() { deallocate(data_, capacity_); }
-
-  size_t size() const { return size_; }
-  size_t capacity() const { return capacity_; }
-  const char* data() const { return data_; }
-
-  // Internally, our character data is always 0-terminated.
-  const char* c_str() const { return data(); }
-
-  virtual OStringStream& write(const char* s, size_t n) OVERRIDE;
-  virtual OStringStream& flush() OVERRIDE;
-
- private:
-  // Primitive allocator interface, can be extracted if needed.
-  static char* allocate (size_t n) { return new char[n]; }
-  static void deallocate (char* s, size_t n) { delete[] s; }
-
-  void reserve(size_t requested_capacity);
-
-  size_t size_;
-  size_t capacity_;
-  char* data_;
-
-  DISALLOW_COPY_AND_ASSIGN(OStringStream);
-};
-
-
-// An output stream writing to a file.
-class OFStream: public OStream {
- public:
-  explicit OFStream(FILE* f) : f_(f) { }
-  virtual ~OFStream() { }
-
-  virtual OFStream& write(const char* s, size_t n) OVERRIDE;
-  virtual OFStream& flush() OVERRIDE;
+  int_type sync() FINAL;
+  int_type overflow(int_type c) FINAL;
 
  private:
   FILE* const f_;
 
+  DISALLOW_COPY_AND_ASSIGN(OFStreamBase);
+};
+
+
+// An output stream writing to a file.
+class OFStream FINAL : private virtual OFStreamBase, public std::ostream {
+ public:
+  explicit OFStream(FILE* f);
+  ~OFStream();
+
+ private:
   DISALLOW_COPY_AND_ASSIGN(OFStream);
 };
 
@@ -133,11 +59,13 @@
 // Writes the given character to the output escaping everything outside of
 // printable/space ASCII range. Additionally escapes '\' making escaping
 // reversible.
-OStream& operator<<(OStream& os, const AsReversiblyEscapedUC16& c);
+std::ostream& operator<<(std::ostream& os, const AsReversiblyEscapedUC16& c);
 
 // Writes the given character to the output escaping everything outside
 // of printable ASCII range.
-OStream& operator<<(OStream& os, const AsUC16& c);
-} }  // namespace v8::internal
+std::ostream& operator<<(std::ostream& os, const AsUC16& c);
+
+}  // namespace internal
+}  // namespace v8
 
 #endif  // V8_OSTREAMS_H_