Update V8 to r4588

We're using WebKit r58033, as used by
http://src.chromium.org/svn/releases/5.0.387.0/DEPS
This requires http://v8.googlecode.com/svn/trunk@4465 but this version has a
crashing bug for ARM. Instead we use http://v8.googlecode.com/svn/trunk@4588,
which is used by http://src.chromium.org/svn/releases/6.0.399.0/DEPS

Note that a trivial bug fix was required in arm/codegen-arm.cc. This is guarded
with ANDROID. See http://code.google.com/p/v8/issues/detail?id=703

Change-Id: I459647a8286c4f8c7405f0c5581ecbf051a6f1e8
diff --git a/src/compilation-cache.cc b/src/compilation-cache.cc
index d049d26..cec10fd 100644
--- a/src/compilation-cache.cc
+++ b/src/compilation-cache.cc
@@ -33,7 +33,6 @@
 namespace v8 {
 namespace internal {
 
-
 // The number of sub caches covering the different types to cache.
 static const int kSubCacheCount = 4;
 
@@ -48,6 +47,9 @@
 // Initial size of each compilation cache table allocated.
 static const int kInitialCacheSize = 64;
 
+// Index for the first generation in the cache.
+static const int kFirstGeneration = 0;
+
 // The compilation cache consists of several generational sub-caches which uses
 // this class as a base class. A sub-cache contains a compilation cache tables
 // for each generation of the sub-cache. Since the same source code string has
@@ -64,6 +66,15 @@
   // Get the compilation cache tables for a specific generation.
   Handle<CompilationCacheTable> GetTable(int generation);
 
+  // Accessors for first generation.
+  Handle<CompilationCacheTable> GetFirstTable() {
+    return GetTable(kFirstGeneration);
+  }
+  void SetFirstTable(Handle<CompilationCacheTable> value) {
+    ASSERT(kFirstGeneration < generations_);
+    tables_[kFirstGeneration] = *value;
+  }
+
   // Age the sub-cache by evicting the oldest generation and creating a new
   // young generation.
   void Age();
@@ -91,14 +102,18 @@
   explicit CompilationCacheScript(int generations)
       : CompilationSubCache(generations) { }
 
-  Handle<JSFunction> Lookup(Handle<String> source,
-                            Handle<Object> name,
-                            int line_offset,
-                            int column_offset);
-  void Put(Handle<String> source, Handle<JSFunction> boilerplate);
+  Handle<SharedFunctionInfo> Lookup(Handle<String> source,
+                                    Handle<Object> name,
+                                    int line_offset,
+                                    int column_offset);
+  void Put(Handle<String> source, Handle<SharedFunctionInfo> function_info);
 
  private:
-  bool HasOrigin(Handle<JSFunction> boilerplate,
+  // Note: Returns a new hash table if operation results in expansion.
+  Handle<CompilationCacheTable> TablePut(
+      Handle<String> source, Handle<SharedFunctionInfo> function_info);
+
+  bool HasOrigin(Handle<SharedFunctionInfo> function_info,
                  Handle<Object> name,
                  int line_offset,
                  int column_offset);
@@ -113,11 +128,19 @@
   explicit CompilationCacheEval(int generations)
       : CompilationSubCache(generations) { }
 
-  Handle<JSFunction> Lookup(Handle<String> source, Handle<Context> context);
+  Handle<SharedFunctionInfo> Lookup(Handle<String> source,
+                                    Handle<Context> context);
 
   void Put(Handle<String> source,
            Handle<Context> context,
-           Handle<JSFunction> boilerplate);
+           Handle<SharedFunctionInfo> function_info);
+
+ private:
+  // Note: Returns a new hash table if operation results in expansion.
+  Handle<CompilationCacheTable> TablePut(
+      Handle<String> source,
+      Handle<Context> context,
+      Handle<SharedFunctionInfo> function_info);
 
   DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheEval);
 };
@@ -134,6 +157,11 @@
   void Put(Handle<String> source,
            JSRegExp::Flags flags,
            Handle<FixedArray> data);
+ private:
+  // Note: Returns a new hash table if operation results in expansion.
+  Handle<CompilationCacheTable> TablePut(Handle<String> source,
+                                         JSRegExp::Flags flags,
+                                         Handle<FixedArray> data);
 
   DISALLOW_IMPLICIT_CONSTRUCTORS(CompilationCacheRegExp);
 };
@@ -193,21 +221,20 @@
 
 
 void CompilationSubCache::Clear() {
-  for (int i = 0; i < generations_; i++) {
-    tables_[i] = Heap::undefined_value();
-  }
+  MemsetPointer(tables_, Heap::undefined_value(), generations_);
 }
 
 
 // We only re-use a cached function for some script source code if the
 // script originates from the same place. This is to avoid issues
 // when reporting errors, etc.
-bool CompilationCacheScript::HasOrigin(Handle<JSFunction> boilerplate,
-                                       Handle<Object> name,
-                                       int line_offset,
-                                       int column_offset) {
+bool CompilationCacheScript::HasOrigin(
+    Handle<SharedFunctionInfo> function_info,
+    Handle<Object> name,
+    int line_offset,
+    int column_offset) {
   Handle<Script> script =
-      Handle<Script>(Script::cast(boilerplate->shared()->script()));
+      Handle<Script>(Script::cast(function_info->script()));
   // If the script name isn't set, the boilerplate script should have
   // an undefined name to have the same origin.
   if (name.is_null()) {
@@ -227,10 +254,10 @@
 // be cached in the same script generation. Currently the first use
 // will be cached, but subsequent code from different source / line
 // won't.
-Handle<JSFunction> CompilationCacheScript::Lookup(Handle<String> source,
-                                                  Handle<Object> name,
-                                                  int line_offset,
-                                                  int column_offset) {
+Handle<SharedFunctionInfo> CompilationCacheScript::Lookup(Handle<String> source,
+                                                          Handle<Object> name,
+                                                          int line_offset,
+                                                          int column_offset) {
   Object* result = NULL;
   int generation;
 
@@ -240,12 +267,13 @@
     for (generation = 0; generation < generations(); generation++) {
       Handle<CompilationCacheTable> table = GetTable(generation);
       Handle<Object> probe(table->Lookup(*source));
-      if (probe->IsJSFunction()) {
-        Handle<JSFunction> boilerplate = Handle<JSFunction>::cast(probe);
-        // Break when we've found a suitable boilerplate function that
+      if (probe->IsSharedFunctionInfo()) {
+        Handle<SharedFunctionInfo> function_info =
+            Handle<SharedFunctionInfo>::cast(probe);
+        // Break when we've found a suitable shared function info that
         // matches the origin.
-        if (HasOrigin(boilerplate, name, line_offset, column_offset)) {
-          result = *boilerplate;
+        if (HasOrigin(function_info, name, line_offset, column_offset)) {
+          result = *function_info;
           break;
         }
       }
@@ -267,31 +295,37 @@
   // to see if we actually found a cached script. If so, we return a
   // handle created in the caller's handle scope.
   if (result != NULL) {
-    Handle<JSFunction> boilerplate(JSFunction::cast(result));
-    ASSERT(HasOrigin(boilerplate, name, line_offset, column_offset));
+    Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(result));
+    ASSERT(HasOrigin(shared, name, line_offset, column_offset));
     // If the script was found in a later generation, we promote it to
     // the first generation to let it survive longer in the cache.
-    if (generation != 0) Put(source, boilerplate);
+    if (generation != 0) Put(source, shared);
     Counters::compilation_cache_hits.Increment();
-    return boilerplate;
+    return shared;
   } else {
     Counters::compilation_cache_misses.Increment();
-    return Handle<JSFunction>::null();
+    return Handle<SharedFunctionInfo>::null();
   }
 }
 
 
-void CompilationCacheScript::Put(Handle<String> source,
-                                 Handle<JSFunction> boilerplate) {
-  HandleScope scope;
-  ASSERT(boilerplate->IsBoilerplate());
-  Handle<CompilationCacheTable> table = GetTable(0);
-  CALL_HEAP_FUNCTION_VOID(table->Put(*source, *boilerplate));
+Handle<CompilationCacheTable> CompilationCacheScript::TablePut(
+    Handle<String> source,
+    Handle<SharedFunctionInfo> function_info) {
+  CALL_HEAP_FUNCTION(GetFirstTable()->Put(*source, *function_info),
+                     CompilationCacheTable);
 }
 
 
-Handle<JSFunction> CompilationCacheEval::Lookup(Handle<String> source,
-                                                Handle<Context> context) {
+void CompilationCacheScript::Put(Handle<String> source,
+                                 Handle<SharedFunctionInfo> function_info) {
+  HandleScope scope;
+  SetFirstTable(TablePut(source, function_info));
+}
+
+
+Handle<SharedFunctionInfo> CompilationCacheEval::Lookup(
+    Handle<String> source, Handle<Context> context) {
   // Make sure not to leak the table into the surrounding handle
   // scope. Otherwise, we risk keeping old tables around even after
   // having cleared the cache.
@@ -301,32 +335,42 @@
     for (generation = 0; generation < generations(); generation++) {
       Handle<CompilationCacheTable> table = GetTable(generation);
       result = table->LookupEval(*source, *context);
-      if (result->IsJSFunction()) {
+      if (result->IsSharedFunctionInfo()) {
         break;
       }
     }
   }
-  if (result->IsJSFunction()) {
-    Handle<JSFunction> boilerplate(JSFunction::cast(result));
+  if (result->IsSharedFunctionInfo()) {
+    Handle<SharedFunctionInfo>
+        function_info(SharedFunctionInfo::cast(result));
     if (generation != 0) {
-      Put(source, context, boilerplate);
+      Put(source, context, function_info);
     }
     Counters::compilation_cache_hits.Increment();
-    return boilerplate;
+    return function_info;
   } else {
     Counters::compilation_cache_misses.Increment();
-    return Handle<JSFunction>::null();
+    return Handle<SharedFunctionInfo>::null();
   }
 }
 
 
+Handle<CompilationCacheTable> CompilationCacheEval::TablePut(
+    Handle<String> source,
+    Handle<Context> context,
+    Handle<SharedFunctionInfo> function_info) {
+  CALL_HEAP_FUNCTION(GetFirstTable()->PutEval(*source,
+                                              *context,
+                                              *function_info),
+                     CompilationCacheTable);
+}
+
+
 void CompilationCacheEval::Put(Handle<String> source,
                                Handle<Context> context,
-                               Handle<JSFunction> boilerplate) {
+                               Handle<SharedFunctionInfo> function_info) {
   HandleScope scope;
-  ASSERT(boilerplate->IsBoilerplate());
-  Handle<CompilationCacheTable> table = GetTable(0);
-  CALL_HEAP_FUNCTION_VOID(table->PutEval(*source, *context, *boilerplate));
+  SetFirstTable(TablePut(source, context, function_info));
 }
 
 
@@ -360,35 +404,43 @@
 }
 
 
+Handle<CompilationCacheTable> CompilationCacheRegExp::TablePut(
+    Handle<String> source,
+    JSRegExp::Flags flags,
+    Handle<FixedArray> data) {
+  CALL_HEAP_FUNCTION(GetFirstTable()->PutRegExp(*source, flags, *data),
+                     CompilationCacheTable);
+}
+
+
 void CompilationCacheRegExp::Put(Handle<String> source,
                                  JSRegExp::Flags flags,
                                  Handle<FixedArray> data) {
   HandleScope scope;
-  Handle<CompilationCacheTable> table = GetTable(0);
-  CALL_HEAP_FUNCTION_VOID(table->PutRegExp(*source, flags, *data));
+  SetFirstTable(TablePut(source, flags, data));
 }
 
 
-Handle<JSFunction> CompilationCache::LookupScript(Handle<String> source,
-                                                  Handle<Object> name,
-                                                  int line_offset,
-                                                  int column_offset) {
+Handle<SharedFunctionInfo> CompilationCache::LookupScript(Handle<String> source,
+                                                          Handle<Object> name,
+                                                          int line_offset,
+                                                          int column_offset) {
   if (!IsEnabled()) {
-    return Handle<JSFunction>::null();
+    return Handle<SharedFunctionInfo>::null();
   }
 
   return script.Lookup(source, name, line_offset, column_offset);
 }
 
 
-Handle<JSFunction> CompilationCache::LookupEval(Handle<String> source,
-                                                Handle<Context> context,
-                                                bool is_global) {
+Handle<SharedFunctionInfo> CompilationCache::LookupEval(Handle<String> source,
+                                                        Handle<Context> context,
+                                                        bool is_global) {
   if (!IsEnabled()) {
-    return Handle<JSFunction>::null();
+    return Handle<SharedFunctionInfo>::null();
   }
 
-  Handle<JSFunction> result;
+  Handle<SharedFunctionInfo> result;
   if (is_global) {
     result = eval_global.Lookup(source, context);
   } else {
@@ -409,30 +461,28 @@
 
 
 void CompilationCache::PutScript(Handle<String> source,
-                                 Handle<JSFunction> boilerplate) {
+                                 Handle<SharedFunctionInfo> function_info) {
   if (!IsEnabled()) {
     return;
   }
 
-  ASSERT(boilerplate->IsBoilerplate());
-  script.Put(source, boilerplate);
+  script.Put(source, function_info);
 }
 
 
 void CompilationCache::PutEval(Handle<String> source,
                                Handle<Context> context,
                                bool is_global,
-                               Handle<JSFunction> boilerplate) {
+                               Handle<SharedFunctionInfo> function_info) {
   if (!IsEnabled()) {
     return;
   }
 
   HandleScope scope;
-  ASSERT(boilerplate->IsBoilerplate());
   if (is_global) {
-    eval_global.Put(source, context, boilerplate);
+    eval_global.Put(source, context, function_info);
   } else {
-    eval_contextual.Put(source, context, boilerplate);
+    eval_contextual.Put(source, context, function_info);
   }
 }