Avoid race on Thread::tlsPtr_::top_handle_scope.

Require mutator lock for that field and update tests to hold
the mutator lock when needed. This prevents GC thread that
executes a thread roots flip on behalf of suspended threads
from racing against construction or destruction of handle
scopes by those threads and possibly seeing invalid values.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 189439174
Change-Id: I268a0ef6e5aa838347956febca0d3b6e02fe3ae5
diff --git a/compiler/optimizing/instruction_simplifier_test.cc b/compiler/optimizing/instruction_simplifier_test.cc
index ac0bdb9..2063eed 100644
--- a/compiler/optimizing/instruction_simplifier_test.cc
+++ b/compiler/optimizing/instruction_simplifier_test.cc
@@ -127,7 +127,8 @@
 // target_phi = PHI[param2, param3, obj2]
 // return PredFieldGet[val_phi, target_phi] => PredFieldGet[val_phi, target_phi]
 TEST_F(InstructionSimplifierTest, SimplifyPredicatedFieldGetNoMerge) {
-  VariableSizedHandleScope vshs(Thread::Current());
+  ScopedObjectAccess soa(Thread::Current());
+  VariableSizedHandleScope vshs(soa.Self());
   CreateGraph(&vshs);
   AdjacencyListGraph blks(SetupFromAdjacencyList("entry",
                                                  "exit",
@@ -219,7 +220,8 @@
 // target_phi = PHI[param2, param3, obj2]
 // return PredFieldGet[val_phi, target_phi] => PredFieldGet[3, target_phi]
 TEST_F(InstructionSimplifierTest, SimplifyPredicatedFieldGetMerge) {
-  VariableSizedHandleScope vshs(Thread::Current());
+  ScopedObjectAccess soa(Thread::Current());
+  VariableSizedHandleScope vshs(soa.Self());
   CreateGraph(&vshs);
   AdjacencyListGraph blks(SetupFromAdjacencyList("entry",
                                                  "exit",
@@ -308,7 +310,8 @@
 // target_phi = PHI[obj1, obj2]
 // return PredFieldGet[val_phi, target_phi] => FieldGet[target_phi]
 TEST_F(InstructionSimplifierTest, SimplifyPredicatedFieldGetNoNull) {
-  VariableSizedHandleScope vshs(Thread::Current());
+  ScopedObjectAccess soa(Thread::Current());
+  VariableSizedHandleScope vshs(soa.Self());
   CreateGraph(&vshs);
   AdjacencyListGraph blks(SetupFromAdjacencyList("entry",
                                                  "exit",
@@ -394,7 +397,8 @@
 // EXIT
 // return obj.field
 TEST_P(InstanceOfInstructionSimplifierTestGroup, ExactClassInstanceOfOther) {
-  VariableSizedHandleScope vshs(Thread::Current());
+  ScopedObjectAccess soa(Thread::Current());
+  VariableSizedHandleScope vshs(soa.Self());
   InitGraph(/*handles=*/&vshs);
 
   AdjacencyListGraph blks(SetupFromAdjacencyList("entry",
@@ -483,7 +487,8 @@
 // EXIT
 // return obj
 TEST_P(InstanceOfInstructionSimplifierTestGroup, ExactClassCheckCastOther) {
-  VariableSizedHandleScope vshs(Thread::Current());
+  ScopedObjectAccess soa(Thread::Current());
+  VariableSizedHandleScope vshs(soa.Self());
   InitGraph(/*handles=*/&vshs);
 
   AdjacencyListGraph blks(SetupFromAdjacencyList("entry", "exit", {{"entry", "exit"}}));