Add option for changing number of GC threads.

The number of threads was previously set to 1 by an accidential
checkin. This hurts on all devices which aren't dual core. We now
properly use sysconf to determine how many threads we should create.

Also added a -XX:HeapGCThreads heap option which lets us change
how many GC threads we create. The default value is equal to the
number of processors on the device minus one.

Change-Id: If65065ef09174a3813b8741efdd5ea7bbe82a4e2
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index dd76f3e..ae843cb 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -66,10 +66,11 @@
 
 Heap::Heap(size_t initial_size, size_t growth_limit, size_t min_free, size_t max_free,
            double target_utilization, size_t capacity,
-           const std::string& original_image_file_name, bool concurrent_gc)
+           const std::string& original_image_file_name, bool concurrent_gc, size_t num_gc_threads)
     : alloc_space_(NULL),
       card_table_(NULL),
       concurrent_gc_(concurrent_gc),
+      num_gc_threads_(num_gc_threads),
       have_zygote_space_(false),
       reference_queue_lock_(NULL),
       is_gc_running_(false),
@@ -196,7 +197,7 @@
   gc_complete_cond_.reset(new ConditionVariable("GC complete condition variable",
                                                 *gc_complete_lock_));
 
-  // Create the reference queue lock, this is required so for parrallel object scanning in the GC.
+  // Create the reference queue lock, this is required so for parallel object scanning in the GC.
   reference_queue_lock_ = new Mutex("reference queue lock");
 
   last_gc_time_ns_ = NanoTime();
@@ -217,10 +218,7 @@
 }
 
 void Heap::CreateThreadPool() {
-  // TODO: Make sysconf(_SC_NPROCESSORS_CONF) be a helper function?
-  // Use the number of processors - 1 since the thread doing the GC does work while its waiting for
-  // workers to complete.
-  thread_pool_.reset(new ThreadPool(1)); // new ThreadPool(sysconf(_SC_NPROCESSORS_CONF) - 1));
+  thread_pool_.reset(new ThreadPool(num_gc_threads_));
 }
 
 void Heap::DeleteThreadPool() {
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 33b7601..b64fdc0 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -136,7 +136,8 @@
   // ImageWriter output.
   explicit Heap(size_t initial_size, size_t growth_limit, size_t min_free,
                 size_t max_free, double target_utilization, size_t capacity,
-                const std::string& original_image_file_name, bool concurrent_gc);
+                const std::string& original_image_file_name, bool concurrent_gc,
+                size_t num_gc_threads);
 
   ~Heap();
 
@@ -489,6 +490,9 @@
   // false for stop-the-world mark sweep.
   const bool concurrent_gc_;
 
+  // How many GC threads we may use for garbage collection.
+  const bool num_gc_threads_;
+
   // If we have a zygote space.
   bool have_zygote_space_;