Revert "Revert "Prevent races with GC when transferring objects between threads""

This reverts commit e5179ce0ca8becf34ba6e7b2f3988874fe647c26.

Reason for revert: Fixed issues with:
  Checkpoint flag set without pending checkpoint in parent CL.

Bug: 67838964
Test: ./test.py --host -j50

Change-Id: I7622f9c18866b58ee3cbd9f4fe38a29b2cf84a88
diff --git a/openjdkjvmti/ti_thread.h b/openjdkjvmti/ti_thread.h
index 09b4cab..341bffe 100644
--- a/openjdkjvmti/ti_thread.h
+++ b/openjdkjvmti/ti_thread.h
@@ -42,6 +42,7 @@
 class ArtField;
 class ScopedObjectAccessAlreadyRunnable;
 class Thread;
+class Closure;
 }  // namespace art
 
 namespace openjdkjvmti {
@@ -133,6 +134,16 @@
     REQUIRES(!art::Locks::user_code_suspension_lock_,
              !art::Locks::thread_suspend_count_lock_);
 
+  // This will request a synchronous checkpoint in such a way as to prevent gc races if a local
+  // variable is taken from one thread's stack and placed in the stack of another thread.
+  // RequestSynchronousCheckpoint releases the thread_list_lock_ as a part of its execution. This is
+  // due to the fact that Thread::Current() needs to go to sleep to allow the targeted thread to
+  // execute the checkpoint for us if it is Runnable.
+  static bool RequestGCSafeSynchronousCheckpoint(art::Thread* thr, art::Closure* function)
+      REQUIRES_SHARED(art::Locks::mutator_lock_)
+      RELEASE(art::Locks::thread_list_lock_)
+      REQUIRES(!art::Locks::thread_suspend_count_lock_);
+
  private:
   // We need to make sure only one thread tries to suspend threads at a time so we can get the
   // 'suspend-only-once' behavior the spec requires. Internally, ART considers suspension to be a