Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "object_registry.h" |
| 18 | |
Sebastien Hertz | e2d628b | 2014-10-23 15:39:33 +0200 | [diff] [blame] | 19 | #include "handle_scope-inl.h" |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 20 | #include "jni_internal.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 21 | #include "mirror/class.h" |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 22 | #include "obj_ptr-inl.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 23 | #include "scoped_thread_state_change-inl.h" |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 24 | |
| 25 | namespace art { |
| 26 | |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 27 | std::ostream& operator<<(std::ostream& os, const ObjectRegistryEntry& rhs) { |
| 28 | os << "ObjectRegistryEntry[" << rhs.jni_reference_type |
| 29 | << ",reference=" << rhs.jni_reference |
| 30 | << ",count=" << rhs.reference_count |
| 31 | << ",id=" << rhs.id << "]"; |
| 32 | return os; |
| 33 | } |
| 34 | |
Elliott Hughes | 0f82716 | 2013-02-26 12:12:58 -0800 | [diff] [blame] | 35 | ObjectRegistry::ObjectRegistry() |
Hiroshi Yamauchi | b5a9e3d | 2014-06-09 12:11:20 -0700 | [diff] [blame] | 36 | : lock_("ObjectRegistry lock", kJdwpObjectRegistryLock), next_id_(1) { |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 37 | } |
| 38 | |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 39 | JDWP::RefTypeId ObjectRegistry::AddRefType(ObjPtr<mirror::Class> c) { |
Sebastien Hertz | 261bc04 | 2015-04-08 09:36:07 +0200 | [diff] [blame] | 40 | return Add(c); |
| 41 | } |
| 42 | |
| 43 | JDWP::RefTypeId ObjectRegistry::AddRefType(Handle<mirror::Class> c_h) { |
| 44 | return Add(c_h); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 47 | JDWP::ObjectId ObjectRegistry::Add(ObjPtr<mirror::Object> o) { |
Hiroshi Yamauchi | b5a9e3d | 2014-06-09 12:11:20 -0700 | [diff] [blame] | 48 | if (o == nullptr) { |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 49 | return 0; |
| 50 | } |
Sebastien Hertz | 261bc04 | 2015-04-08 09:36:07 +0200 | [diff] [blame] | 51 | Thread* const self = Thread::Current(); |
| 52 | StackHandleScope<1> hs(self); |
| 53 | return InternalAdd(hs.NewHandle(o)); |
| 54 | } |
| 55 | |
| 56 | // Template instantiations must be declared below. |
| 57 | template<class T> |
| 58 | JDWP::ObjectId ObjectRegistry::Add(Handle<T> obj_h) { |
| 59 | if (obj_h.Get() == nullptr) { |
| 60 | return 0; |
| 61 | } |
| 62 | return InternalAdd(obj_h); |
| 63 | } |
| 64 | |
| 65 | // Explicit template instantiation. |
| 66 | template |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 67 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 68 | REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_) |
Sebastien Hertz | 261bc04 | 2015-04-08 09:36:07 +0200 | [diff] [blame] | 69 | JDWP::ObjectId ObjectRegistry::Add(Handle<mirror::Object> obj_h); |
| 70 | |
| 71 | template |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 72 | REQUIRES_SHARED(Locks::mutator_lock_) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 73 | REQUIRES(!Locks::thread_list_lock_, !Locks::thread_suspend_count_lock_) |
Sebastien Hertz | 261bc04 | 2015-04-08 09:36:07 +0200 | [diff] [blame] | 74 | JDWP::ObjectId ObjectRegistry::Add(Handle<mirror::Throwable> obj_h); |
| 75 | |
| 76 | template<class T> |
| 77 | JDWP::ObjectId ObjectRegistry::InternalAdd(Handle<T> obj_h) { |
| 78 | CHECK(obj_h.Get() != nullptr); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 79 | |
Sebastien Hertz | e2d628b | 2014-10-23 15:39:33 +0200 | [diff] [blame] | 80 | Thread* const self = Thread::Current(); |
Sebastien Hertz | e4266c5 | 2014-10-29 12:06:51 +0100 | [diff] [blame] | 81 | self->AssertNoPendingException(); |
Sebastien Hertz | 6920639 | 2015-04-07 15:54:25 +0200 | [diff] [blame] | 82 | // Object::IdentityHashCode may cause these locks to be held so check we do not already |
| 83 | // hold them. |
| 84 | Locks::thread_list_lock_->AssertNotHeld(self); |
| 85 | Locks::thread_suspend_count_lock_->AssertNotHeld(self); |
Sebastien Hertz | e4266c5 | 2014-10-29 12:06:51 +0100 | [diff] [blame] | 86 | |
Hiroshi Yamauchi | b5a9e3d | 2014-06-09 12:11:20 -0700 | [diff] [blame] | 87 | // Call IdentityHashCode here to avoid a lock level violation between lock_ and monitor_lock. |
Sebastien Hertz | e2d628b | 2014-10-23 15:39:33 +0200 | [diff] [blame] | 88 | int32_t identity_hash_code = obj_h->IdentityHashCode(); |
| 89 | |
| 90 | ScopedObjectAccessUnchecked soa(self); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 91 | MutexLock mu(soa.Self(), lock_); |
Hiroshi Yamauchi | b5a9e3d | 2014-06-09 12:11:20 -0700 | [diff] [blame] | 92 | ObjectRegistryEntry* entry = nullptr; |
Sebastien Hertz | e2d628b | 2014-10-23 15:39:33 +0200 | [diff] [blame] | 93 | if (ContainsLocked(soa.Self(), obj_h.Get(), identity_hash_code, &entry)) { |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 94 | // This object was already in our map. |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 95 | ++entry->reference_count; |
| 96 | } else { |
| 97 | entry = new ObjectRegistryEntry; |
| 98 | entry->jni_reference_type = JNIWeakGlobalRefType; |
| 99 | entry->jni_reference = nullptr; |
| 100 | entry->reference_count = 0; |
| 101 | entry->id = 0; |
Hiroshi Yamauchi | b5a9e3d | 2014-06-09 12:11:20 -0700 | [diff] [blame] | 102 | entry->identity_hash_code = identity_hash_code; |
| 103 | object_to_entry_.insert(std::make_pair(identity_hash_code, entry)); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 104 | |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 105 | // This object isn't in the registry yet, so add it. |
| 106 | JNIEnv* env = soa.Env(); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 107 | |
Sebastien Hertz | e2d628b | 2014-10-23 15:39:33 +0200 | [diff] [blame] | 108 | jobject local_reference = soa.AddLocalReference<jobject>(obj_h.Get()); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 109 | |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 110 | entry->jni_reference_type = JNIWeakGlobalRefType; |
| 111 | entry->jni_reference = env->NewWeakGlobalRef(local_reference); |
| 112 | entry->reference_count = 1; |
| 113 | entry->id = next_id_++; |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 114 | |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 115 | id_to_entry_.Put(entry->id, entry); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 116 | |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 117 | env->DeleteLocalRef(local_reference); |
| 118 | } |
| 119 | return entry->id; |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 120 | } |
| 121 | |
Mathieu Chartier | 3398c78 | 2016-09-30 10:27:43 -0700 | [diff] [blame] | 122 | bool ObjectRegistry::ContainsLocked(Thread* self, |
| 123 | ObjPtr<mirror::Object> o, |
| 124 | int32_t identity_hash_code, |
Hiroshi Yamauchi | b5a9e3d | 2014-06-09 12:11:20 -0700 | [diff] [blame] | 125 | ObjectRegistryEntry** out_entry) { |
| 126 | DCHECK(o != nullptr); |
| 127 | for (auto it = object_to_entry_.lower_bound(identity_hash_code), end = object_to_entry_.end(); |
| 128 | it != end && it->first == identity_hash_code; ++it) { |
| 129 | ObjectRegistryEntry* entry = it->second; |
| 130 | if (o == self->DecodeJObject(entry->jni_reference)) { |
| 131 | if (out_entry != nullptr) { |
| 132 | *out_entry = entry; |
| 133 | } |
| 134 | return true; |
| 135 | } |
| 136 | } |
| 137 | return false; |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | void ObjectRegistry::Clear() { |
Sebastien Hertz | 55f6534 | 2015-01-13 22:48:34 +0100 | [diff] [blame] | 141 | Thread* const self = Thread::Current(); |
| 142 | |
| 143 | // We must not hold the mutator lock exclusively if we want to delete weak global |
| 144 | // references. Otherwise this can lead to a deadlock with a running GC: |
| 145 | // 1. GC thread disables access to weak global references, then releases |
| 146 | // mutator lock. |
| 147 | // 2. JDWP thread takes mutator lock exclusively after suspending all |
| 148 | // threads. |
| 149 | // 3. GC thread waits for shared mutator lock which is held by JDWP |
| 150 | // thread. |
| 151 | // 4. JDWP thread clears weak global references but need to wait for GC |
| 152 | // thread to re-enable access to them. |
| 153 | Locks::mutator_lock_->AssertNotExclusiveHeld(self); |
| 154 | |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 155 | MutexLock mu(self, lock_); |
| 156 | VLOG(jdwp) << "Object registry contained " << object_to_entry_.size() << " entries"; |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 157 | // Delete all the JNI references. |
| 158 | JNIEnv* env = self->GetJniEnv(); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 159 | for (const auto& pair : object_to_entry_) { |
Sebastien Hertz | a032870 | 2014-06-25 22:06:12 +0200 | [diff] [blame] | 160 | const ObjectRegistryEntry* entry = pair.second; |
| 161 | if (entry->jni_reference_type == JNIWeakGlobalRefType) { |
| 162 | env->DeleteWeakGlobalRef(entry->jni_reference); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 163 | } else { |
Sebastien Hertz | a032870 | 2014-06-25 22:06:12 +0200 | [diff] [blame] | 164 | env->DeleteGlobalRef(entry->jni_reference); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 165 | } |
Sebastien Hertz | a032870 | 2014-06-25 22:06:12 +0200 | [diff] [blame] | 166 | delete entry; |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 167 | } |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 168 | // Clear the maps. |
| 169 | object_to_entry_.clear(); |
| 170 | id_to_entry_.clear(); |
| 171 | } |
| 172 | |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 173 | mirror::Object* ObjectRegistry::InternalGet(JDWP::ObjectId id, JDWP::JdwpError* error) { |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 174 | Thread* self = Thread::Current(); |
| 175 | MutexLock mu(self, lock_); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 176 | auto it = id_to_entry_.find(id); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 177 | if (it == id_to_entry_.end()) { |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 178 | *error = JDWP::ERR_INVALID_OBJECT; |
| 179 | return nullptr; |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 180 | } |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 181 | ObjectRegistryEntry& entry = *it->second; |
Ian Rogers | c0542af | 2014-09-03 16:16:56 -0700 | [diff] [blame] | 182 | *error = JDWP::ERR_NONE; |
Mathieu Chartier | c4f3925 | 2016-10-05 18:32:08 -0700 | [diff] [blame] | 183 | return self->DecodeJObject(entry.jni_reference).Ptr(); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Jeff Hao | 449db33 | 2013-04-12 18:30:52 -0700 | [diff] [blame] | 186 | jobject ObjectRegistry::GetJObject(JDWP::ObjectId id) { |
Sebastien Hertz | 0630ab5 | 2013-11-28 18:53:35 +0100 | [diff] [blame] | 187 | if (id == 0) { |
Sebastien Hertz | 7d95565 | 2014-10-22 10:57:10 +0200 | [diff] [blame] | 188 | return nullptr; |
Sebastien Hertz | 0630ab5 | 2013-11-28 18:53:35 +0100 | [diff] [blame] | 189 | } |
Jeff Hao | 449db33 | 2013-04-12 18:30:52 -0700 | [diff] [blame] | 190 | Thread* self = Thread::Current(); |
| 191 | MutexLock mu(self, lock_); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 192 | auto it = id_to_entry_.find(id); |
Jeff Hao | 449db33 | 2013-04-12 18:30:52 -0700 | [diff] [blame] | 193 | CHECK(it != id_to_entry_.end()) << id; |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 194 | ObjectRegistryEntry& entry = *it->second; |
Jeff Hao | 449db33 | 2013-04-12 18:30:52 -0700 | [diff] [blame] | 195 | return entry.jni_reference; |
| 196 | } |
| 197 | |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 198 | void ObjectRegistry::DisableCollection(JDWP::ObjectId id) { |
| 199 | Thread* self = Thread::Current(); |
| 200 | MutexLock mu(self, lock_); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 201 | auto it = id_to_entry_.find(id); |
Sebastien Hertz | e96060a | 2013-12-11 12:06:28 +0100 | [diff] [blame] | 202 | CHECK(it != id_to_entry_.end()); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 203 | Promote(*it->second); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | void ObjectRegistry::EnableCollection(JDWP::ObjectId id) { |
| 207 | Thread* self = Thread::Current(); |
| 208 | MutexLock mu(self, lock_); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 209 | auto it = id_to_entry_.find(id); |
Sebastien Hertz | e96060a | 2013-12-11 12:06:28 +0100 | [diff] [blame] | 210 | CHECK(it != id_to_entry_.end()); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 211 | Demote(*it->second); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void ObjectRegistry::Demote(ObjectRegistryEntry& entry) { |
| 215 | if (entry.jni_reference_type == JNIGlobalRefType) { |
| 216 | Thread* self = Thread::Current(); |
| 217 | JNIEnv* env = self->GetJniEnv(); |
| 218 | jobject global = entry.jni_reference; |
| 219 | entry.jni_reference = env->NewWeakGlobalRef(entry.jni_reference); |
| 220 | entry.jni_reference_type = JNIWeakGlobalRefType; |
| 221 | env->DeleteGlobalRef(global); |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | void ObjectRegistry::Promote(ObjectRegistryEntry& entry) { |
| 226 | if (entry.jni_reference_type == JNIWeakGlobalRefType) { |
| 227 | Thread* self = Thread::Current(); |
| 228 | JNIEnv* env = self->GetJniEnv(); |
| 229 | jobject weak = entry.jni_reference; |
| 230 | entry.jni_reference = env->NewGlobalRef(entry.jni_reference); |
| 231 | entry.jni_reference_type = JNIGlobalRefType; |
| 232 | env->DeleteWeakGlobalRef(weak); |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | bool ObjectRegistry::IsCollected(JDWP::ObjectId id) { |
| 237 | Thread* self = Thread::Current(); |
| 238 | MutexLock mu(self, lock_); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 239 | auto it = id_to_entry_.find(id); |
Sebastien Hertz | e96060a | 2013-12-11 12:06:28 +0100 | [diff] [blame] | 240 | CHECK(it != id_to_entry_.end()); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 241 | ObjectRegistryEntry& entry = *it->second; |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 242 | if (entry.jni_reference_type == JNIWeakGlobalRefType) { |
| 243 | JNIEnv* env = self->GetJniEnv(); |
Sebastien Hertz | 7d95565 | 2014-10-22 10:57:10 +0200 | [diff] [blame] | 244 | return env->IsSameObject(entry.jni_reference, nullptr); // Has the jweak been collected? |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 245 | } else { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 246 | return false; // We hold a strong reference, so we know this is live. |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | |
| 250 | void ObjectRegistry::DisposeObject(JDWP::ObjectId id, uint32_t reference_count) { |
| 251 | Thread* self = Thread::Current(); |
| 252 | MutexLock mu(self, lock_); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 253 | auto it = id_to_entry_.find(id); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 254 | if (it == id_to_entry_.end()) { |
| 255 | return; |
| 256 | } |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 257 | ObjectRegistryEntry* entry = it->second; |
| 258 | entry->reference_count -= reference_count; |
| 259 | if (entry->reference_count <= 0) { |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 260 | JNIEnv* env = self->GetJniEnv(); |
Hiroshi Yamauchi | b5a9e3d | 2014-06-09 12:11:20 -0700 | [diff] [blame] | 261 | // Erase the object from the maps. Note object may be null if it's |
| 262 | // a weak ref and the GC has cleared it. |
| 263 | int32_t hash_code = entry->identity_hash_code; |
Andreas Gampe | 277ccbd | 2014-11-03 21:36:10 -0800 | [diff] [blame] | 264 | for (auto inner_it = object_to_entry_.lower_bound(hash_code), end = object_to_entry_.end(); |
| 265 | inner_it != end && inner_it->first == hash_code; ++inner_it) { |
| 266 | if (entry == inner_it->second) { |
| 267 | object_to_entry_.erase(inner_it); |
Hiroshi Yamauchi | b5a9e3d | 2014-06-09 12:11:20 -0700 | [diff] [blame] | 268 | break; |
| 269 | } |
| 270 | } |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 271 | if (entry->jni_reference_type == JNIWeakGlobalRefType) { |
| 272 | env->DeleteWeakGlobalRef(entry->jni_reference); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 273 | } else { |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 274 | env->DeleteGlobalRef(entry->jni_reference); |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 275 | } |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 276 | id_to_entry_.erase(id); |
Mathieu Chartier | 412c7fc | 2014-02-07 12:18:39 -0800 | [diff] [blame] | 277 | delete entry; |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 278 | } |
| 279 | } |
| 280 | |
Elliott Hughes | 64f574f | 2013-02-20 14:57:12 -0800 | [diff] [blame] | 281 | } // namespace art |