Delete pin table

The pin table was brought over from dalvik but not really needed
since ART doesn't support pinning in movable spaces. The only
thing it did was hold objects live for JNI functions.
This shouldn't be necessary since people keep jni references to
these objects or else they could never release the elements.

Bug: 17456946

(cherry picked from commit a967c62e4e6675d3553445aa8e95a09e7a3381b0)
Change-Id: Ibed0d029157ffb9e75ecd80d4d544d690986c090
diff --git a/runtime/java_vm_ext.cc b/runtime/java_vm_ext.cc
index 0ac5b88..1444d97 100644
--- a/runtime/java_vm_ext.cc
+++ b/runtime/java_vm_ext.cc
@@ -36,9 +36,6 @@
 
 namespace art {
 
-static const size_t kPinTableInitial = 16;  // Arbitrary.
-static const size_t kPinTableMax = 1024;  // Arbitrary sanity check.
-
 static size_t gGlobalsInitial = 512;  // Arbitrary.
 static size_t gGlobalsMax = 51200;  // Arbitrary sanity check. (Must fit in 16 bits.)
 
@@ -365,8 +362,6 @@
       force_copy_(options->force_copy_),
       tracing_enabled_(!options->jni_trace_.empty() || VLOG_IS_ON(third_party_jni)),
       trace_(options->jni_trace_),
-      pins_lock_("JNI pin table lock", kPinTableLock),
-      pin_table_("pin table", kPinTableInitial, kPinTableMax),
       globals_lock_("JNI global reference table lock"),
       globals_(gGlobalsInitial, gGlobalsMax, kGlobal),
       libraries_(new Libraries),
@@ -523,10 +518,6 @@
   }
   Thread* self = Thread::Current();
   {
-    MutexLock mu(self, pins_lock_);
-    os << "; pins=" << pin_table_.Size();
-  }
-  {
     ReaderMutexLock mu(self, globals_lock_);
     os << "; globals=" << globals_.Capacity();
   }
@@ -568,16 +559,6 @@
   return weak_globals_.Get(ref);
 }
 
-void JavaVMExt::PinPrimitiveArray(Thread* self, mirror::Array* array) {
-  MutexLock mu(self, pins_lock_);
-  pin_table_.Add(array);
-}
-
-void JavaVMExt::UnpinPrimitiveArray(Thread* self, mirror::Array* array) {
-  MutexLock mu(self, pins_lock_);
-  pin_table_.Remove(array);
-}
-
 void JavaVMExt::DumpReferenceTables(std::ostream& os) {
   Thread* self = Thread::Current();
   {
@@ -588,10 +569,6 @@
     MutexLock mu(self, weak_globals_lock_);
     weak_globals_.Dump(os);
   }
-  {
-    MutexLock mu(self, pins_lock_);
-    pin_table_.Dump(os);
-  }
 }
 
 bool JavaVMExt::LoadNativeLibrary(JNIEnv* env, const std::string& path, jobject class_loader,
@@ -779,10 +756,6 @@
     ReaderMutexLock mu(self, globals_lock_);
     globals_.VisitRoots(callback, arg, 0, kRootJNIGlobal);
   }
-  {
-    MutexLock mu(self, pins_lock_);
-    pin_table_.VisitRoots(callback, arg, 0, kRootVMInternal);
-  }
   // The weak_globals table is visited by the GC itself (because it mutates the table).
 }
 
diff --git a/runtime/java_vm_ext.h b/runtime/java_vm_ext.h
index da0b8e3..2957ba3 100644
--- a/runtime/java_vm_ext.h
+++ b/runtime/java_vm_ext.h
@@ -95,7 +95,7 @@
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
   void DumpForSigQuit(std::ostream& os)
-      LOCKS_EXCLUDED(Locks::jni_libraries_lock_, globals_lock_, weak_globals_lock_, pins_lock_);
+      LOCKS_EXCLUDED(Locks::jni_libraries_lock_, globals_lock_, weak_globals_lock_);
 
   void DumpReferenceTables(std::ostream& os)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -127,14 +127,6 @@
   mirror::Object* DecodeWeakGlobal(Thread* self, IndirectRef ref)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
-  void PinPrimitiveArray(Thread* self, mirror::Array* array)
-      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
-      LOCKS_EXCLUDED(pins_lock_);
-
-  void UnpinPrimitiveArray(Thread* self, mirror::Array* array)
-      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
-      LOCKS_EXCLUDED(pins_lock_);
-
   const JNIInvokeInterface* GetUncheckedFunctions() const {
     return unchecked_functions_;
   }
@@ -154,10 +146,6 @@
   // Extra diagnostics.
   const std::string trace_;
 
-  // Used to hold references to pinned primitive arrays.
-  Mutex pins_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
-  ReferenceTable pin_table_ GUARDED_BY(pins_lock_);
-
   // JNI global references.
   ReaderWriterMutex globals_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
   // Not guarded by globals_lock since we sometimes use SynchronizedGet in Thread::DecodeJObject.
diff --git a/runtime/jni_internal.cc b/runtime/jni_internal.cc
index 3e9ae09..36f01db 100644
--- a/runtime/jni_internal.cc
+++ b/runtime/jni_internal.cc
@@ -1695,7 +1695,6 @@
     ScopedObjectAccess soa(env);
     mirror::String* s = soa.Decode<mirror::String*>(java_string);
     mirror::CharArray* chars = s->GetCharArray();
-    soa.Vm()->PinPrimitiveArray(soa.Self(), chars);
     gc::Heap* heap = Runtime::Current()->GetHeap();
     if (heap->IsMovableObject(chars)) {
       if (is_copy != nullptr) {
@@ -1724,7 +1723,6 @@
     if (chars != (s_chars->GetData() + s->GetOffset())) {
       delete[] chars;
     }
-    soa.Vm()->UnpinPrimitiveArray(soa.Self(), s->GetCharArray());
   }
 
   static const jchar* GetStringCritical(JNIEnv* env, jstring java_string, jboolean* is_copy) {
@@ -1733,7 +1731,6 @@
     mirror::String* s = soa.Decode<mirror::String*>(java_string);
     mirror::CharArray* chars = s->GetCharArray();
     int32_t offset = s->GetOffset();
-    soa.Vm()->PinPrimitiveArray(soa.Self(), chars);
     gc::Heap* heap = Runtime::Current()->GetHeap();
     if (heap->IsMovableObject(chars)) {
       StackHandleScope<1> hs(soa.Self());
@@ -1749,8 +1746,6 @@
   static void ReleaseStringCritical(JNIEnv* env, jstring java_string, const jchar* chars) {
     CHECK_NON_NULL_ARGUMENT_RETURN_VOID(java_string);
     ScopedObjectAccess soa(env);
-    soa.Vm()->UnpinPrimitiveArray(soa.Self(),
-                                  soa.Decode<mirror::String*>(java_string)->GetCharArray());
     gc::Heap* heap = Runtime::Current()->GetHeap();
     mirror::String* s = soa.Decode<mirror::String*>(java_string);
     mirror::CharArray* s_chars = s->GetCharArray();
@@ -1906,7 +1901,6 @@
       // Re-decode in case the object moved since IncrementDisableGC waits for GC to complete.
       array = soa.Decode<mirror::Array*>(java_array);
     }
-    soa.Vm()->PinPrimitiveArray(soa.Self(), array);
     if (is_copy != nullptr) {
       *is_copy = JNI_FALSE;
     }
@@ -2331,7 +2325,6 @@
     if (UNLIKELY(array == nullptr)) {
       return nullptr;
     }
-    soa.Vm()->PinPrimitiveArray(soa.Self(), array);
     // Only make a copy if necessary.
     if (Runtime::Current()->GetHeap()->IsMovableObject(array)) {
       if (is_copy != nullptr) {
@@ -2394,7 +2387,6 @@
         // Non copy to a movable object must means that we had disabled the moving GC.
         heap->DecrementDisableMovingGC(soa.Self());
       }
-      soa.Vm()->UnpinPrimitiveArray(soa.Self(), array);
     }
   }