summaryrefslogtreecommitdiff
path: root/runtime/class_linker.cc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r--runtime/class_linker.cc72
1 files changed, 29 insertions, 43 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 81622e14ed..da70456369 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -616,10 +616,7 @@ void ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> b
// initialized.
{
const DexFile& dex_file = java_lang_Object->GetDexFile();
- const DexFile::StringId* void_string_id = dex_file.FindStringId("V");
- CHECK(void_string_id != nullptr);
- uint32_t void_string_index = dex_file.GetIndexForStringId(*void_string_id);
- const DexFile::TypeId* void_type_id = dex_file.FindTypeId(void_string_index);
+ const DexFile::TypeId* void_type_id = dex_file.FindTypeId("V");
CHECK(void_type_id != nullptr);
uint16_t void_type_idx = dex_file.GetIndexForTypeId(*void_type_id);
// Now we resolve void type so the dex cache contains it. We use java.lang.Object class
@@ -1174,15 +1171,26 @@ ClassLinker::~ClassLinker() {
mirror::LongArray::ResetArrayClass();
mirror::ShortArray::ResetArrayClass();
Thread* const self = Thread::Current();
- JavaVMExt* const vm = Runtime::Current()->GetJavaVM();
for (const ClassLoaderData& data : class_loaders_) {
- vm->DeleteWeakGlobalRef(self, data.weak_root);
- delete data.allocator;
- delete data.class_table;
+ DeleteClassLoader(self, data);
}
class_loaders_.clear();
}
+void ClassLinker::DeleteClassLoader(Thread* self, const ClassLoaderData& data) {
+ Runtime* const runtime = Runtime::Current();
+ JavaVMExt* const vm = runtime->GetJavaVM();
+ vm->DeleteWeakGlobalRef(self, data.weak_root);
+ if (runtime->GetJit() != nullptr) {
+ jit::JitCodeCache* code_cache = runtime->GetJit()->GetCodeCache();
+ if (code_cache != nullptr) {
+ code_cache->RemoveMethodsIn(self, *data.allocator);
+ }
+ }
+ delete data.allocator;
+ delete data.class_table;
+}
+
mirror::PointerArray* ClassLinker::AllocPointerArray(Thread* self, size_t length) {
return down_cast<mirror::PointerArray*>(image_pointer_size_ == 8u ?
static_cast<mirror::Array*>(mirror::LongArray::Alloc(self, length)) :
@@ -1833,13 +1841,6 @@ const void* ClassLinker::GetQuickOatCodeFor(ArtMethod* method) {
return code;
}
}
- jit::Jit* const jit = Runtime::Current()->GetJit();
- if (jit != nullptr) {
- auto* code = jit->GetCodeCache()->GetCodeFor(method);
- if (code != nullptr) {
- return code;
- }
- }
if (method->IsNative()) {
// No code and native? Use generic trampoline.
return GetQuickGenericJniStub();
@@ -1856,13 +1857,6 @@ const void* ClassLinker::GetOatMethodQuickCodeFor(ArtMethod* method) {
if (found) {
return oat_method.GetQuickCode();
}
- jit::Jit* jit = Runtime::Current()->GetJit();
- if (jit != nullptr) {
- auto* code = jit->GetCodeCache()->GetCodeFor(method);
- if (code != nullptr) {
- return code;
- }
- }
return nullptr;
}
@@ -2743,17 +2737,13 @@ mirror::Class* ClassLinker::LookupClassFromImage(const char* descriptor) {
for (int32_t i = 0; i < dex_caches->GetLength(); ++i) {
mirror::DexCache* dex_cache = dex_caches->Get(i);
const DexFile* dex_file = dex_cache->GetDexFile();
- // Try binary searching the string/type index.
- const DexFile::StringId* string_id = dex_file->FindStringId(descriptor);
- if (string_id != nullptr) {
- const DexFile::TypeId* type_id =
- dex_file->FindTypeId(dex_file->GetIndexForStringId(*string_id));
- if (type_id != nullptr) {
- uint16_t type_idx = dex_file->GetIndexForTypeId(*type_id);
- mirror::Class* klass = dex_cache->GetResolvedType(type_idx);
- if (klass != nullptr) {
- return klass;
- }
+ // Try binary searching the type index by descriptor.
+ const DexFile::TypeId* type_id = dex_file->FindTypeId(descriptor);
+ if (type_id != nullptr) {
+ uint16_t type_idx = dex_file->GetIndexForTypeId(*type_id);
+ mirror::Class* klass = dex_cache->GetResolvedType(type_idx);
+ if (klass != nullptr) {
+ return klass;
}
}
}
@@ -5289,7 +5279,7 @@ bool ClassLinker::LinkInterfaceMethods(
miranda_method = reinterpret_cast<ArtMethod*>(allocator.Alloc(method_size));
CHECK(miranda_method != nullptr);
// Point the interface table at a phantom slot.
- new(miranda_method) ArtMethod(*interface_method, image_pointer_size_);
+ new(miranda_method) ArtMethod(interface_method, image_pointer_size_);
miranda_methods.push_back(miranda_method);
}
method_array->SetElementPtrSize(j, miranda_method, image_pointer_size_);
@@ -5325,7 +5315,7 @@ bool ClassLinker::LinkInterfaceMethods(
ScopedArenaUnorderedMap<ArtMethod*, ArtMethod*> move_table(allocator.Adapter());
if (virtuals != old_virtuals) {
// Maps from heap allocated miranda method to linear alloc miranda method.
- StrideIterator<ArtMethod> out = virtuals->Begin(method_size, method_alignment);
+ StrideIterator<ArtMethod> out = virtuals->begin(method_size, method_alignment);
// Copy over the old methods + miranda methods.
for (auto& m : klass->GetVirtualMethods(image_pointer_size_)) {
move_table.emplace(&m, &*out);
@@ -5335,7 +5325,7 @@ bool ClassLinker::LinkInterfaceMethods(
++out;
}
}
- StrideIterator<ArtMethod> out(virtuals->Begin(method_size, method_alignment)
+ StrideIterator<ArtMethod> out(virtuals->begin(method_size, method_alignment)
+ old_method_count);
// Copy over miranda methods before copying vtable since CopyOf may cause thread suspension and
// we want the roots of the miranda methods to get visited.
@@ -5367,7 +5357,7 @@ bool ClassLinker::LinkInterfaceMethods(
move_table.emplace(def_method, &new_method);
++out;
}
- virtuals->SetLength(new_method_count);
+ virtuals->SetSize(new_method_count);
UpdateClassVirtualMethods(klass.Get(), virtuals);
// Done copying methods, they are all roots in the class now, so we can end the no thread
// suspension assert.
@@ -5382,7 +5372,7 @@ bool ClassLinker::LinkInterfaceMethods(
self->AssertPendingOOMException();
return false;
}
- out = virtuals->Begin(method_size, method_alignment) + old_method_count;
+ out = virtuals->begin(method_size, method_alignment) + old_method_count;
size_t vtable_pos = old_vtable_count;
for (size_t i = old_method_count; i < new_method_count; ++i) {
// Leave the declaring class alone as type indices are relative to it
@@ -6387,7 +6377,6 @@ void ClassLinker::InsertDexFileInToClassLoader(mirror::Object* dex_file,
void ClassLinker::CleanupClassLoaders() {
Thread* const self = Thread::Current();
WriterMutexLock mu(self, *Locks::classlinker_classes_lock_);
- JavaVMExt* const vm = Runtime::Current()->GetJavaVM();
for (auto it = class_loaders_.begin(); it != class_loaders_.end(); ) {
const ClassLoaderData& data = *it;
// Need to use DecodeJObject so that we get null for cleared JNI weak globals.
@@ -6395,10 +6384,7 @@ void ClassLinker::CleanupClassLoaders() {
if (class_loader != nullptr) {
++it;
} else {
- // Weak reference was cleared, delete the data associated with this class loader.
- delete data.class_table;
- delete data.allocator;
- vm->DeleteWeakGlobalRef(self, data.weak_root);
+ DeleteClassLoader(self, data);
it = class_loaders_.erase(it);
}
}