Remove unnecessary thread suspension

Removed unnecessary thread suspension since it's already done by
ScopedGCCriticalSection. This also fixes the access of handles
without holding the mutator lock.

Added scoped traces to RegisterDexFile to help detect any delays
caused by blocking on GC from the ScopedGCCriticalSection.

Bug: 109720594
Test: test-art-host

Change-Id: I0bc7402eca7c8bff92d3522ccd30ca802bca2863
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 0b955ca..be636d8 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -3360,6 +3360,7 @@
 
 void ClassLinker::RegisterExistingDexCache(ObjPtr<mirror::DexCache> dex_cache,
                                            ObjPtr<mirror::ClassLoader> class_loader) {
+  SCOPED_TRACE << __FUNCTION__ << " " << dex_cache->GetDexFile()->GetLocation();
   Thread* self = Thread::Current();
   StackHandleScope<2> hs(self);
   Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(dex_cache));
@@ -3384,7 +3385,6 @@
   // Avoid a deadlock between a garbage collecting thread running a checkpoint,
   // a thread holding the dex lock and blocking on a condition variable regarding
   // weak references access, and a thread blocking on the dex lock.
-  ScopedThreadStateChange tsc(self, kSuspended);
   gc::ScopedGCCriticalSection gcs(self, gc::kGcCauseClassLinker, gc::kCollectorTypeClassLinker);
   WriterMutexLock mu(self, *Locks::dex_lock_);
   RegisterDexFileLocked(*dex_file, h_dex_cache.Get(), h_class_loader.Get());
@@ -3408,6 +3408,7 @@
   if (old_dex_cache != nullptr) {
     return EnsureSameClassLoader(self, old_dex_cache, old_data, class_loader);
   }
+  SCOPED_TRACE << __FUNCTION__ << " " << dex_file.GetLocation();
   LinearAlloc* const linear_alloc = GetOrCreateAllocatorForClassLoader(class_loader);
   DCHECK(linear_alloc != nullptr);
   ClassTable* table;
@@ -3429,7 +3430,6 @@
     // Avoid a deadlock between a garbage collecting thread running a checkpoint,
     // a thread holding the dex lock and blocking on a condition variable regarding
     // weak references access, and a thread blocking on the dex lock.
-    ScopedThreadStateChange tsc(self, kSuspended);
     gc::ScopedGCCriticalSection gcs(self, gc::kGcCauseClassLinker, gc::kCollectorTypeClassLinker);
     WriterMutexLock mu(self, *Locks::dex_lock_);
     old_data = FindDexCacheDataLocked(dex_file);