Merge V8 5.3.332.45.  DO NOT MERGE

Test: Manual

FPIIM-449

Change-Id: Id3254828b068abdea3cb10442e0172a8c9a98e03
(cherry picked from commit 13e2dadd00298019ed862f2b2fc5068bba730bcf)
diff --git a/src/snapshot/startup-serializer.h b/src/snapshot/startup-serializer.h
index 71b8475..cc66f71 100644
--- a/src/snapshot/startup-serializer.h
+++ b/src/snapshot/startup-serializer.h
@@ -6,6 +6,7 @@
 #define V8_SNAPSHOT_STARTUP_SERIALIZER_H_
 
 #include <bitset>
+#include "include/v8.h"
 #include "src/snapshot/serializer.h"
 
 namespace v8 {
@@ -13,11 +14,9 @@
 
 class StartupSerializer : public Serializer {
  public:
-  enum FunctionCodeHandling { CLEAR_FUNCTION_CODE, KEEP_FUNCTION_CODE };
-
   StartupSerializer(
-      Isolate* isolate, SnapshotByteSink* sink,
-      FunctionCodeHandling function_code_handling = CLEAR_FUNCTION_CODE);
+      Isolate* isolate,
+      v8::SnapshotCreator::FunctionCodeHandling function_code_handling);
   ~StartupSerializer() override;
 
   // Serialize the current state of the heap.  The order is:
@@ -28,7 +27,34 @@
   void SerializeStrongReferences();
   void SerializeWeakReferencesAndDeferred();
 
+  int PartialSnapshotCacheIndex(HeapObject* o);
+
  private:
+  class PartialCacheIndexMap : public AddressMapBase {
+   public:
+    PartialCacheIndexMap()
+        : map_(base::HashMap::PointersMatch), next_index_(0) {}
+
+    // Lookup object in the map. Return its index if found, or create
+    // a new entry with new_index as value, and return kInvalidIndex.
+    bool LookupOrInsert(HeapObject* obj, int* index_out) {
+      base::HashMap::Entry* entry = LookupEntry(&map_, obj, false);
+      if (entry != NULL) {
+        *index_out = GetValue(entry);
+        return true;
+      }
+      *index_out = next_index_;
+      SetValue(LookupEntry(&map_, obj, true), next_index_++);
+      return false;
+    }
+
+   private:
+    base::HashMap map_;
+    int next_index_;
+
+    DISALLOW_COPY_AND_ASSIGN(PartialCacheIndexMap);
+  };
+
   // The StartupSerializer has to serialize the root array, which is slightly
   // different.
   void VisitPointers(Object** start, Object** end) override;
@@ -42,10 +68,11 @@
   // roots. In the second pass, we serialize the rest.
   bool RootShouldBeSkipped(int root_index);
 
-  FunctionCodeHandling function_code_handling_;
+  bool clear_function_code_;
   bool serializing_builtins_;
   bool serializing_immortal_immovables_roots_;
   std::bitset<Heap::kStrongRootListLength> root_has_been_serialized_;
+  PartialCacheIndexMap partial_cache_index_map_;
   DISALLOW_COPY_AND_ASSIGN(StartupSerializer);
 };