Move RoS allocator to use unordered_set.

Work-around existing stlport issues for the target. This will go away when the
target is using libc++.

Change-Id: I8f213ecd9dc7d93d17f4a0d7e84182c12af6ca1b
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 188ddb5..74f8d8d 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -253,6 +253,9 @@
 endif
 ART_TARGET_CFLAGS += $(ART_DEFAULT_GC_TYPE_CFLAGS)
 
+# TODO: remove when target no longer implies stlport.
+ART_TARGET_CFLAGS += -DART_WITH_STLPORT=1
+
 # DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES is set in ../build/core/dex_preopt.mk based on
 # the TARGET_CPU_VARIANT
 ifeq ($(DEX2OAT_TARGET_INSTRUCTION_SET_FEATURES),)
diff --git a/runtime/gc/allocator/rosalloc.cc b/runtime/gc/allocator/rosalloc.cc
index a693659..27c4c17 100644
--- a/runtime/gc/allocator/rosalloc.cc
+++ b/runtime/gc/allocator/rosalloc.cc
@@ -793,7 +793,7 @@
     // already in the non-full run set (i.e., it was full) insert it
     // into the non-full run set.
     if (run != current_runs_[idx]) {
-      hash_set<Run*, hash_run, eq_run>* full_runs =
+      unordered_set<Run*, hash_run, eq_run>* full_runs =
           kIsDebugBuild ? &full_runs_[idx] : NULL;
       std::set<Run*>::iterator pos = non_full_runs->find(run);
       if (pos == non_full_runs->end()) {
@@ -1156,11 +1156,11 @@
   WriterMutexLock wmu(self, bulk_free_lock_);
 
   // First mark slots to free in the bulk free bit map without locking the
-  // size bracket locks. On host, hash_set is faster than vector + flag.
+  // size bracket locks. On host, unordered_set is faster than vector + flag.
 #ifdef HAVE_ANDROID_OS
   std::vector<Run*> runs;
 #else
-  hash_set<Run*, hash_run, eq_run> runs;
+  unordered_set<Run*, hash_run, eq_run> runs;
 #endif
   for (size_t i = 0; i < num_ptrs; i++) {
     void* ptr = ptrs[i];
@@ -1267,7 +1267,7 @@
       // Check if the run should be moved to non_full_runs_ or
       // free_page_runs_.
       std::set<Run*>* non_full_runs = &non_full_runs_[idx];
-      hash_set<Run*, hash_run, eq_run>* full_runs =
+      unordered_set<Run*, hash_run, eq_run>* full_runs =
           kIsDebugBuild ? &full_runs_[idx] : NULL;
       if (run->IsAllFree()) {
         // It has just become completely free. Free the pages of the
@@ -1281,7 +1281,7 @@
           // If it was full, remove it from the full run set (debug
           // only.)
           if (kIsDebugBuild) {
-            hash_set<Run*, hash_run, eq_run>::iterator pos = full_runs->find(run);
+            unordered_set<Run*, hash_run, eq_run>::iterator pos = full_runs->find(run);
             DCHECK(pos != full_runs->end());
             full_runs->erase(pos);
             if (kTraceRosAlloc) {
@@ -2054,7 +2054,7 @@
       } else {
         // If it's full, it must in the full run set (debug build only.)
         if (kIsDebugBuild) {
-          hash_set<Run*, hash_run, eq_run>& full_runs = rosalloc->full_runs_[idx];
+          unordered_set<Run*, hash_run, eq_run>& full_runs = rosalloc->full_runs_[idx];
           CHECK(full_runs.find(this) != full_runs.end())
               << " A full run isn't in the full run set " << Dump();
         }
diff --git a/runtime/gc/allocator/rosalloc.h b/runtime/gc/allocator/rosalloc.h
index 21044f3..8557f1b 100644
--- a/runtime/gc/allocator/rosalloc.h
+++ b/runtime/gc/allocator/rosalloc.h
@@ -31,29 +31,18 @@
 #include "UniquePtr.h"
 #include "utils.h"
 
-// A boilerplate to use hash_map/hash_set both on host and device.
-#ifdef HAVE_ANDROID_OS
-#include <hash_map>
+// Ensure we have an unordered_set until we have worked out C++ library issues.
+#ifdef ART_WITH_STLPORT
 #include <hash_set>
-using std::hash_map;
-using std::hash_set;
-#else  // HAVE_ANDROID_OS
-#ifdef __DEPRECATED
-#define ROSALLOC_OLD__DEPRECATED __DEPRECATED
-#undef __DEPRECATED
-#endif
-#include <ext/hash_map>
-#include <ext/hash_set>
-#ifdef ROSALLOC_OLD__DEPRECATED
-#define __DEPRECATED ROSALLOC_OLD__DEPRECATED
-#undef ROSALLOC_OLD__DEPRECATED
-#endif
-using __gnu_cxx::hash_map;
-using __gnu_cxx::hash_set;
-#endif  // HAVE_ANDROID_OS
+template <class V, class H, class P>
+class unordered_set : public std::hash_set<V, H, P> {};
+#else  // ART_WITH_STLPORT
+// TODO: avoid the use of using in a header file.
+#include <unordered_set>
+using std::unordered_set;
+#endif  // ART_WITH_STLPORT
 
 namespace art {
-
 namespace gc {
 namespace allocator {
 
@@ -462,7 +451,7 @@
   std::set<Run*> non_full_runs_[kNumOfSizeBrackets];
   // The run sets that hold the runs whose slots are all full. This is
   // debug only. full_runs_[i] is guarded by size_bracket_locks_[i].
-  hash_set<Run*, hash_run, eq_run> full_runs_[kNumOfSizeBrackets];
+  unordered_set<Run*, hash_run, eq_run> full_runs_[kNumOfSizeBrackets];
   // The set of free pages.
   std::set<FreePageRun*> free_page_runs_ GUARDED_BY(lock_);
   // The dedicated full run, it is always full and shared by all threads when revoking happens.