diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/class_linker.cc | 4 | ||||
-rw-r--r-- | runtime/intern_table.cc | 5 | ||||
-rw-r--r-- | runtime/intern_table.h | 4 |
3 files changed, 12 insertions, 1 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 0c8d53927e..2d19bfc207 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -2538,7 +2538,9 @@ ObjPtr<mirror::DexCache> ClassLinker::AllocDexCache(/*out*/ ObjPtr<mirror::Strin self->AssertPendingOOMException(); return nullptr; } - ObjPtr<mirror::String> location = intern_table_->InternStrong(dex_file.GetLocation().c_str()); + // Use InternWeak() so that the location String can be collected when the ClassLoader + // with this DexCache is collected. + ObjPtr<mirror::String> location = intern_table_->InternWeak(dex_file.GetLocation().c_str()); if (location == nullptr) { self->AssertPendingOOMException(); return nullptr; diff --git a/runtime/intern_table.cc b/runtime/intern_table.cc index 3f728cbbfe..96f70d1b80 100644 --- a/runtime/intern_table.cc +++ b/runtime/intern_table.cc @@ -289,6 +289,11 @@ ObjPtr<mirror::String> InternTable::InternStrong(ObjPtr<mirror::String> s) { return Insert(s, true, false); } +ObjPtr<mirror::String> InternTable::InternWeak(const char* utf8_data) { + DCHECK(utf8_data != nullptr); + return InternWeak(mirror::String::AllocFromModifiedUtf8(Thread::Current(), utf8_data)); +} + ObjPtr<mirror::String> InternTable::InternWeak(ObjPtr<mirror::String> s) { return Insert(s, false, false); } diff --git a/runtime/intern_table.h b/runtime/intern_table.h index 745821d0ca..a5301a5908 100644 --- a/runtime/intern_table.h +++ b/runtime/intern_table.h @@ -132,6 +132,10 @@ class InternTable { REQUIRES(!Roles::uninterruptible_); // Interns a potentially new string in the 'weak' table. May cause thread suspension. + ObjPtr<mirror::String> InternWeak(const char* utf8_data) REQUIRES_SHARED(Locks::mutator_lock_) + REQUIRES(!Roles::uninterruptible_); + + // Interns a potentially new string in the 'weak' table. May cause thread suspension. ObjPtr<mirror::String> InternWeak(ObjPtr<mirror::String> s) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_); |