Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(806)

Unified Diff: runtime/vm/object.cc

Issue 2823633003: Allow the resolved names cache to be lazily created like the exported names cache. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object_snapshot.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/object.cc
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index b012e5a80fe6bba680491c37853f7619fb627382..080d0e5550aaf632507b3ee2a2b459bbdecd8a6d 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -10093,6 +10093,9 @@ typedef UnorderedHashMap<StringEqualsTraits> ResolvedNamesMap;
// obj is set to the cached entry. It may be null, indicating that the
// name does not resolve to anything in this library.
bool Library::LookupResolvedNamesCache(const String& name, Object* obj) const {
+ if (resolved_names() == Array::null()) {
+ return false;
+ }
ResolvedNamesMap cache(resolved_names());
bool present = false;
*obj = cache.GetOrNull(name, &present);
@@ -10119,6 +10122,9 @@ void Library::AddToResolvedNamesCache(const String& name,
if (!FLAG_use_lib_cache || Compiler::IsBackgroundCompilation()) {
return;
}
+ if (resolved_names() == Array::null()) {
+ InitResolvedNamesCache();
+ }
ResolvedNamesMap cache(resolved_names());
cache.UpdateOrInsert(name, obj);
StorePointer(&raw_ptr()->resolved_names_, cache.Release().raw());
@@ -10153,7 +10159,7 @@ void Library::AddToExportedNamesCache(const String& name,
return;
}
if (exported_names() == Array::null()) {
- AllocateExportedNamesCache();
+ InitExportedNamesCache();
}
ResolvedNamesMap cache(exported_names());
cache.UpdateOrInsert(name, obj);
@@ -10167,7 +10173,7 @@ void Library::InvalidateResolvedName(const String& name) const {
Object& entry = Object::Handle(zone);
if (LookupResolvedNamesCache(name, &entry)) {
// TODO(koda): Support deleted sentinel in snapshots and remove only 'name'.
- InvalidateResolvedNamesCache();
+ ClearResolvedNamesCache();
}
// When a new name is added to a library, we need to invalidate all
// caches that contain an entry for this name. If the name was previously
@@ -10179,18 +10185,12 @@ void Library::InvalidateResolvedName(const String& name) const {
for (intptr_t i = 0; i < num_libs; i++) {
lib ^= libs.At(i);
if (lib.LookupExportedNamesCache(name, &entry)) {
- lib.InitExportedNamesCache();
+ lib.ClearExportedNamesCache();
}
}
}
-void Library::InvalidateResolvedNamesCache() const {
- const intptr_t kInvalidatedCacheSize = 16;
- InitResolvedNamesCache(kInvalidatedCacheSize);
-}
-
-
// Invalidate all exported names caches in the isolate.
void Library::InvalidateExportedNamesCaches() {
GrowableObjectArray& libs = GrowableObjectArray::Handle(
@@ -10199,7 +10199,7 @@ void Library::InvalidateExportedNamesCaches() {
intptr_t num_libs = libs.Length();
for (intptr_t i = 0; i < num_libs; i++) {
lib ^= libs.At(i);
- lib.InitExportedNamesCache();
+ lib.ClearExportedNamesCache();
}
}
@@ -10398,7 +10398,7 @@ bool Library::RemoveObject(const Object& obj, const String& name) const {
intptr_t used_elements = Smi::Value(Smi::RawCast(dict.At(dict_size))) - 1;
dict.SetAt(dict_size, Smi::Handle(zone, Smi::New(used_elements)));
- InvalidateResolvedNamesCache();
+ ClearResolvedNamesCache();
InvalidateExportedNamesCaches();
return true;
@@ -10811,24 +10811,27 @@ static RawArray* NewDictionary(intptr_t initial_size) {
}
-void Library::InitResolvedNamesCache(intptr_t size) const {
+void Library::InitResolvedNamesCache() const {
ASSERT(Thread::Current()->IsMutatorThread());
StorePointer(&raw_ptr()->resolved_names_,
- HashTables::New<ResolvedNamesMap>(size));
+ HashTables::New<ResolvedNamesMap>(64));
+}
+
+
+void Library::ClearResolvedNamesCache() const {
+ ASSERT(Thread::Current()->IsMutatorThread());
+ StorePointer(&raw_ptr()->resolved_names_, Array::null());
}
-void Library::AllocateExportedNamesCache() const {
+void Library::InitExportedNamesCache() const {
StorePointer(&raw_ptr()->exported_names_,
HashTables::New<ResolvedNamesMap>(16));
}
-void Library::InitExportedNamesCache() const {
- if (exported_names() != Array::null()) {
- StorePointer(&raw_ptr()->exported_names_,
- HashTables::New<ResolvedNamesMap>(16));
- }
+void Library::ClearExportedNamesCache() const {
+ StorePointer(&raw_ptr()->exported_names_, Array::null());
}
@@ -10867,8 +10870,7 @@ RawLibrary* Library::NewLibraryHelper(const String& url, bool import_core_lib) {
const Library& result = Library::Handle(zone, Library::New());
result.StorePointer(&result.raw_ptr()->name_, Symbols::Empty().raw());
result.StorePointer(&result.raw_ptr()->url_, url.raw());
- result.StorePointer(&result.raw_ptr()->resolved_names_,
- Object::empty_array().raw());
+ result.StorePointer(&result.raw_ptr()->resolved_names_, Array::null());
result.StorePointer(&result.raw_ptr()->exported_names_, Array::null());
result.StorePointer(&result.raw_ptr()->dictionary_,
Object::empty_array().raw());
@@ -10901,8 +10903,6 @@ RawLibrary* Library::NewLibraryHelper(const String& url, bool import_core_lib) {
result.StoreNonPointer(&result.raw_ptr()->load_state_,
RawLibrary::kAllocated);
result.StoreNonPointer(&result.raw_ptr()->index_, -1);
- const intptr_t kInitialNameCacheSize = 64;
- result.InitResolvedNamesCache(kInitialNameCacheSize);
result.InitClassDictionary();
result.InitImportList();
result.AllocatePrivateKey();
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/raw_object_snapshot.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698