[vm] Reduce maximum new generation size and growth rate.

For example, by default 64-bit architectures now grow as 2, 4, 8, 16 instead of 2, 8, 32.

This change is to reduce memory usage and maximum minor GC time for Flutter and Fuchsia.
It would negatively impact batch applications, which prefer throughput,
so the new defaults are overriden by the command-line Dart VM in
runtime/bin/main.cc

Change-Id: Ie56a7599d4011a629c8c57bd88fec3ee8f277a9f
Reviewed-on: https://dart-review.googlesource.com/54305
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc
index 4bddd36a..bc95b54 100644
--- a/runtime/bin/gen_snapshot.cc
+++ b/runtime/bin/gen_snapshot.cc
@@ -1505,7 +1505,7 @@
 }
 
 int main(int argc, char** argv) {
-  const int EXTRA_VM_ARGUMENTS = 2;
+  const int EXTRA_VM_ARGUMENTS = 4;
   CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS);
 
   // Initialize the URL mapping array.
@@ -1516,6 +1516,16 @@
   CommandLineOptions entry_points_files_array(argc);
   entry_points_files = &entry_points_files_array;
 
+  // When running from the command line we assume that we are optimizing for
+  // throughput, and therefore use a larger new gen semi space size and a faster
+  // new gen growth factor unless others have been specified.
+  if (kWordSize <= 4) {
+    vm_options.AddArgument("--new_gen_semi_max_size=16");
+  } else {
+    vm_options.AddArgument("--new_gen_semi_max_size=32");
+  }
+  vm_options.AddArgument("--new_gen_growth_factor=4");
+
   // Parse command line arguments.
   if (ParseArguments(argc, argv, &vm_options, &app_script_name) < 0) {
     PrintUsage();
diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc
index b3c71de..1859422 100644
--- a/runtime/bin/main.cc
+++ b/runtime/bin/main.cc
@@ -1159,7 +1159,7 @@
 
 void main(int argc, char** argv) {
   char* script_name;
-  const int EXTRA_VM_ARGUMENTS = 8;
+  const int EXTRA_VM_ARGUMENTS = 10;
   CommandLineOptions vm_options(argc + EXTRA_VM_ARGUMENTS);
   CommandLineOptions dart_options(argc);
   bool print_flags_seen = false;
@@ -1183,6 +1183,16 @@
   Options::set_dfe(&dfe);
 #endif  // !defined(DART_PRECOMPILED_RUNTIME)
 
+  // When running from the command line we assume that we are optimizing for
+  // throughput, and therefore use a larger new gen semi space size and a faster
+  // new gen growth factor unless others have been specified.
+  if (kWordSize <= 4) {
+    vm_options.AddArgument("--new_gen_semi_max_size=16");
+  } else {
+    vm_options.AddArgument("--new_gen_semi_max_size=32");
+  }
+  vm_options.AddArgument("--new_gen_growth_factor=4");
+
   // Parse command line arguments.
   if (Options::ParseArguments(argc, argv, vm_run_app_snapshot, &vm_options,
                               &script_name, &dart_options, &print_flags_seen,
diff --git a/runtime/vm/flag_list.h b/runtime/vm/flag_list.h
index 7dd0cc2..50afd6e 100644
--- a/runtime/vm/flag_list.h
+++ b/runtime/vm/flag_list.h
@@ -118,8 +118,10 @@
     "Maximum number of polymorphic check, otherwise it is megamorphic.")       \
   P(max_equality_polymorphic_checks, int, 32,                                  \
     "Maximum number of polymorphic checks in equality operator,")              \
-  P(new_gen_semi_max_size, int, (kWordSize <= 4) ? 16 : 32,                    \
+  P(new_gen_semi_max_size, int, (kWordSize <= 4) ? 8 : 16,                     \
     "Max size of new gen semi space in MB")                                    \
+  P(new_gen_semi_initial_size, int, (kWordSize <= 4) ? 1 : 2,                  \
+    "Initial size of new gen semi space in MB")                                \
   P(optimization_counter_threshold, int, 30000,                                \
     "Function's usage-counter value before it is optimized, -1 means never")   \
   P(old_gen_heap_size, int, kDefaultMaxOldGenHeapSize,                         \
diff --git a/runtime/vm/scavenger.cc b/runtime/vm/scavenger.cc
index 9ca79a7..3121e86 100644
--- a/runtime/vm/scavenger.cc
+++ b/runtime/vm/scavenger.cc
@@ -6,6 +6,7 @@
 
 #include "vm/dart.h"
 #include "vm/dart_api_state.h"
+#include "vm/flag_list.h"
 #include "vm/isolate.h"
 #include "vm/lockers.h"
 #include "vm/object.h"
@@ -31,7 +32,7 @@
             new_gen_garbage_threshold,
             90,
             "Grow new gen when less than this percentage is garbage.");
-DEFINE_FLAG(int, new_gen_growth_factor, 4, "Grow new gen by this factor.");
+DEFINE_FLAG(int, new_gen_growth_factor, 2, "Grow new gen by this factor.");
 
 // Scavenger uses RawObject::kMarkBit to distinguish forwarded and non-forwarded
 // objects. The kMarkBit does not intersect with the target address because of
@@ -350,10 +351,9 @@
   // going to use for forwarding pointers.
   ASSERT(Object::tags_offset() == 0);
 
-  // Set initial size resulting in a total of three different levels.
-  const intptr_t initial_semi_capacity_in_words =
-      max_semi_capacity_in_words /
-      (FLAG_new_gen_growth_factor * FLAG_new_gen_growth_factor);
+  // Set initial semi space size in words.
+  const intptr_t initial_semi_capacity_in_words = Utils::Minimum(
+      max_semi_capacity_in_words, FLAG_new_gen_semi_initial_size * MBInWords);
 
   const intptr_t kVmNameSize = 128;
   char vm_name[kVmNameSize];