summaryrefslogtreecommitdiff
path: root/runtime/class_linker.h
diff options
context:
space:
mode:
author Ian Rogers <irogers@google.com> 2014-02-24 16:53:16 -0800
committer Ian Rogers <irogers@google.com> 2014-02-24 18:47:23 -0800
commit9837939678bb5dcba178e5fb00ed59b5d14c8d9b (patch)
tree00f0e6b54d7c4cac78a02752e268724157e50b6e /runtime/class_linker.h
parent3fcf18e25241253f23efbeebe77b2a4c4a7c54d3 (diff)
Avoid std::string allocations for finding an array class.
Introduce ClassLinker::FindArrayClass which performs an array class lookup given the element/component class. This has a 16 element cache of recently looked up arrays. Pass the current thread to ClassLinker Find .. Class routines to avoid calls to Thread::Current(). Avoid some uses of FindClass in the debugger where WellKnownClasses is a faster and more compacting GC friendly alternative. Change-Id: I60e231820b349543a7edb3ceb9cf1ce92db3c843
Diffstat (limited to 'runtime/class_linker.h')
-rw-r--r--runtime/class_linker.h26
1 files changed, 20 insertions, 6 deletions
diff --git a/runtime/class_linker.h b/runtime/class_linker.h
index 0745ee2b09..f346102f97 100644
--- a/runtime/class_linker.h
+++ b/runtime/class_linker.h
@@ -72,10 +72,17 @@ class ClassLinker {
// Finds a class by its descriptor, loading it if necessary.
// If class_loader is null, searches boot_class_path_.
- mirror::Class* FindClass(const char* descriptor, const SirtRef<mirror::ClassLoader>& class_loader)
+ mirror::Class* FindClass(Thread* self, const char* descriptor,
+ const SirtRef<mirror::ClassLoader>& class_loader)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- mirror::Class* FindSystemClass(const char* descriptor)
+ // Finds a class by its descriptor using the "system" class loader, ie by searching the
+ // boot_class_path_.
+ mirror::Class* FindSystemClass(Thread* self, const char* descriptor)
+ SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
+ // Finds the array class given for the element class.
+ mirror::Class* FindArrayClass(Thread* self, mirror::Class* element_class)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
// Reutrns true if the class linker is initialized.
@@ -378,7 +385,7 @@ class ClassLinker {
LOCKS_EXCLUDED(dex_lock_)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- void FinishInit() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+ void FinishInit(Thread* self) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
// For early bootstrapping by Init
mirror::Class* AllocClass(Thread* self, mirror::Class* java_lang_Class, size_t class_size)
@@ -399,7 +406,7 @@ class ClassLinker {
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- mirror::Class* CreateArrayClass(const char* descriptor,
+ mirror::Class* CreateArrayClass(Thread* self, const char* descriptor,
const SirtRef<mirror::ClassLoader>& class_loader)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -449,12 +456,12 @@ class ClassLinker {
bool ValidateSuperClassDescriptors(const SirtRef<mirror::Class>& klass)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- bool IsSameDescriptorInDifferentClassContexts(const char* descriptor,
+ bool IsSameDescriptorInDifferentClassContexts(Thread* self, const char* descriptor,
SirtRef<mirror::ClassLoader>& class_loader1,
SirtRef<mirror::ClassLoader>& class_loader2)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
- bool IsSameMethodSignatureInDifferentClassContexts(mirror::ArtMethod* method,
+ bool IsSameMethodSignatureInDifferentClassContexts(Thread* self, mirror::ArtMethod* method,
mirror::Class* klass1,
mirror::Class* klass2)
SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
@@ -617,8 +624,15 @@ class ClassLinker {
return descriptor;
}
+ // The interface table used by all arrays.
mirror::IfTable* array_iftable_;
+ // A cache of the last FindArrayClass results. The cache serves to avoid creating array class
+ // descriptors for the sake of performing FindClass.
+ static constexpr size_t kFindArrayCacheSize = 16;
+ mirror::Class* find_array_class_cache_[kFindArrayCacheSize];
+ size_t find_array_class_cache_next_victim_;
+
bool init_done_;
bool dex_caches_dirty_ GUARDED_BY(dex_lock_);
bool class_table_dirty_ GUARDED_BY(Locks::classlinker_classes_lock_);