diff options
author | dsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-13 23:57:37 +0000 |
---|---|---|
committer | dsinclair@chromium.org <dsinclair@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-13 23:57:37 +0000 |
commit | 8838f9837e1cf6dd75dced18c2204f322fd84356 (patch) | |
tree | 33924e049b18a691d4000d1b2c07318cdd55212b /net | |
parent | 095f067e6632f08901b2f59f74ec8b6bcd9fc73e (diff) | |
download | chromium_src-8838f9837e1cf6dd75dced18c2204f322fd84356.zip chromium_src-8838f9837e1cf6dd75dced18c2204f322fd84356.tar.gz chromium_src-8838f9837e1cf6dd75dced18c2204f322fd84356.tar.bz2 |
Create a new disk_cache type, SHADER_CACHE.
Create a new type of disk_cache to be used by the GL Shader
cache. This cache acts similar to the regular DISK_CACHE
except the rank of the entry is not updated if the entry
is not modified. This means we can read entries as we
iterate and the iterators do not get shuffled around.
BUG=166763
Review URL: https://chromiumcodereview.appspot.com/12224017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182343 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/base/cache_type.h | 3 | ||||
-rw-r--r-- | net/disk_cache/backend_impl.cc | 10 | ||||
-rw-r--r-- | net/disk_cache/backend_unittest.cc | 115 | ||||
-rw-r--r-- | net/disk_cache/entry_unittest.cc | 9 | ||||
-rw-r--r-- | net/disk_cache/histogram_macros.h | 3 |
5 files changed, 135 insertions, 5 deletions
diff --git a/net/base/cache_type.h b/net/base/cache_type.h index 0823389..a7a21df 100644 --- a/net/base/cache_type.h +++ b/net/base/cache_type.h @@ -12,7 +12,8 @@ enum CacheType { DISK_CACHE, // Disk is used as the backing storage. MEMORY_CACHE, // Data is stored only in memory. MEDIA_CACHE, // Optimized to handle media files. - APP_CACHE // Backing store for an AppCache. + APP_CACHE, // Backing store for an AppCache. + SHADER_CACHE // Backing store for the GL shader cache. }; } // namespace disk_cache diff --git a/net/disk_cache/backend_impl.cc b/net/disk_cache/backend_impl.cc index 232b3f8..c92c9ee 100644 --- a/net/disk_cache/backend_impl.cc +++ b/net/disk_cache/backend_impl.cc @@ -478,6 +478,8 @@ int BackendImpl::SyncInit() { if (cache_type() == net::APP_CACHE) { DCHECK(!new_eviction_); read_only_ = true; + } else if (cache_type() == net::SHADER_CACHE) { + DCHECK(!new_eviction_); } eviction_.Init(this); @@ -670,7 +672,7 @@ void BackendImpl::SyncOnExternalCacheHit(const std::string& key) { EntryImpl* cache_entry = MatchEntry(key, hash, false, Addr(), &error); if (cache_entry) { if (ENTRY_NORMAL == cache_entry->entry()->Data()->state) { - UpdateRank(cache_entry, false); + UpdateRank(cache_entry, cache_type() == net::SHADER_CACHE); } cache_entry->Release(); } @@ -922,9 +924,9 @@ LruData* BackendImpl::GetLruData() { } void BackendImpl::UpdateRank(EntryImpl* entry, bool modified) { - if (!read_only_) { - eviction_.UpdateRank(entry, modified); - } + if (read_only_ || (!modified && cache_type() == net::SHADER_CACHE)) + return; + eviction_.UpdateRank(entry, modified); } void BackendImpl::RecoveredEntry(CacheRankingsBlock* rankings) { diff --git a/net/disk_cache/backend_unittest.cc b/net/disk_cache/backend_unittest.cc index 65cd3837..db33c8e 100644 --- a/net/disk_cache/backend_unittest.cc +++ b/net/disk_cache/backend_unittest.cc @@ -138,6 +138,11 @@ TEST_F(DiskCacheBackendTest, AppCacheBasics) { BackendBasics(); } +TEST_F(DiskCacheBackendTest, ShaderCacheBasics) { + SetCacheType(net::SHADER_CACHE); + BackendBasics(); +} + void DiskCacheBackendTest::BackendKeying() { InitCache(); const char* kName1 = "the first key"; @@ -198,6 +203,11 @@ TEST_F(DiskCacheBackendTest, AppCacheKeying) { BackendKeying(); } +TEST_F(DiskCacheBackendTest, ShaderCacheKeying) { + SetCacheType(net::SHADER_CACHE); + BackendKeying(); +} + TEST_F(DiskCacheTest, CreateBackend) { net::TestCompletionCallback cb; @@ -592,6 +602,14 @@ TEST_F(DiskCacheBackendTest, AppCacheLoad) { BackendLoad(); } +TEST_F(DiskCacheBackendTest, ShaderCacheLoad) { + SetCacheType(net::SHADER_CACHE); + // Work with a tiny index table (16 entries) + SetMask(0xf); + SetMaxSize(0x100000); + BackendLoad(); +} + // Tests the chaining of an entry to the current head. void DiskCacheBackendTest::BackendChain() { SetMask(0x1); // 2-entry table. @@ -619,6 +637,11 @@ TEST_F(DiskCacheBackendTest, AppCacheChain) { BackendChain(); } +TEST_F(DiskCacheBackendTest, ShaderCacheChain) { + SetCacheType(net::SHADER_CACHE); + BackendChain(); +} + TEST_F(DiskCacheBackendTest, NewEvictionTrim) { SetNewEviction(); SetDirectMode(); @@ -729,6 +752,12 @@ TEST_F(DiskCacheBackendTest, AppCacheInvalidEntry) { BackendInvalidEntry(); } +// We'll be leaking memory from this test. +TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntry) { + SetCacheType(net::SHADER_CACHE); + BackendInvalidEntry(); +} + // Almost the same test, but this time crash the cache after reading an entry. // We'll be leaking memory from this test. void DiskCacheBackendTest::BackendInvalidEntryRead() { @@ -780,6 +809,12 @@ TEST_F(DiskCacheBackendTest, AppCacheInvalidEntryRead) { } // We'll be leaking memory from this test. +TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntryRead) { + SetCacheType(net::SHADER_CACHE); + BackendInvalidEntryRead(); +} + +// We'll be leaking memory from this test. void DiskCacheBackendTest::BackendInvalidEntryWithLoad() { // Work with a tiny index table (16 entries) SetMask(0xf); @@ -846,6 +881,12 @@ TEST_F(DiskCacheBackendTest, AppCacheInvalidEntryWithLoad) { } // We'll be leaking memory from this test. +TEST_F(DiskCacheBackendTest, ShaderCacheInvalidEntryWithLoad) { + SetCacheType(net::SHADER_CACHE); + BackendInvalidEntryWithLoad(); +} + +// We'll be leaking memory from this test. void DiskCacheBackendTest::BackendTrimInvalidEntry() { // Use the implementation directly... we need to simulate a crash. SetDirectMode(); @@ -1028,6 +1069,11 @@ TEST_F(DiskCacheBackendTest, MemoryOnlyEnumerations) { BackendEnumerations(); } +TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations) { + SetCacheType(net::SHADER_CACHE); + BackendEnumerations(); +} + TEST_F(DiskCacheBackendTest, AppCacheEnumerations) { SetCacheType(net::APP_CACHE); BackendEnumerations(); @@ -1097,6 +1143,46 @@ TEST_F(DiskCacheBackendTest, AppCacheEnumerations2) { BackendEnumerations2(); } +TEST_F(DiskCacheBackendTest, ShaderCacheEnumerations2) { + SetCacheType(net::SHADER_CACHE); + BackendEnumerations2(); +} + +// Verify that ReadData calls do not update the LRU cache +// when using the SHADER_CACHE type. +TEST_F(DiskCacheBackendTest, ShaderCacheEnumerationReadData) { + SetCacheType(net::SHADER_CACHE); + InitCache(); + const std::string first("first"); + const std::string second("second"); + disk_cache::Entry *entry1, *entry2; + const int kSize = 50; + scoped_refptr<net::IOBuffer> buffer1(new net::IOBuffer(kSize)); + + ASSERT_EQ(net::OK, CreateEntry(first, &entry1)); + memset(buffer1->data(), 0, kSize); + base::strlcpy(buffer1->data(), "And the data to save", kSize); + EXPECT_EQ(kSize, WriteData(entry1, 0, 0, buffer1, kSize, false)); + + ASSERT_EQ(net::OK, CreateEntry(second, &entry2)); + entry2->Close(); + + FlushQueueForTest(); + + // Make sure that the timestamp is not the same. + AddDelay(); + + // Read from the last item in the LRU. + EXPECT_EQ(kSize, ReadData(entry1, 0, 0, buffer1, kSize)); + entry1->Close(); + + void* iter = NULL; + ASSERT_EQ(net::OK, OpenNextEntry(&iter, &entry2)); + EXPECT_EQ(entry2->GetKey(), second); + entry2->Close(); + cache_->EndEnumeration(&iter); +} + // Verify handling of invalid entries while doing enumerations. // We'll be leaking memory from this test. void DiskCacheBackendTest::BackendInvalidEntryEnumeration() { @@ -2325,6 +2411,11 @@ TEST_F(DiskCacheBackendTest, AppCacheOnlyDoomAll) { BackendDoomAll(); } +TEST_F(DiskCacheBackendTest, ShaderCacheOnlyDoomAll) { + SetCacheType(net::SHADER_CACHE); + BackendDoomAll(); +} + // If the index size changes when we doom the cache, we should not crash. void DiskCacheBackendTest::BackendDoomAll2() { EXPECT_EQ(2, cache_->GetEntryCount()); @@ -2576,3 +2667,27 @@ TEST_F(DiskCacheBackendTest, UpdateRankForExternalCacheHit) { ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); entry->Close(); } + +TEST_F(DiskCacheBackendTest, ShaderCacheUpdateRankForExternalCacheHit) { + SetCacheType(net::SHADER_CACHE); + SetDirectMode(); + InitCache(); + + disk_cache::Entry* entry; + + for (int i = 0; i < 2; ++i) { + std::string key = StringPrintf("key%d", i); + ASSERT_EQ(net::OK, CreateEntry(key, &entry)); + entry->Close(); + } + + // Ping the oldest entry. + cache_->OnExternalCacheHit("key0"); + + TrimForTest(false); + + // Make sure the older key remains. + EXPECT_EQ(1, cache_->GetEntryCount()); + ASSERT_EQ(net::OK, OpenEntry("key0", &entry)); + entry->Close(); +} diff --git a/net/disk_cache/entry_unittest.cc b/net/disk_cache/entry_unittest.cc index 6e68034..4b7e2bc 100644 --- a/net/disk_cache/entry_unittest.cc +++ b/net/disk_cache/entry_unittest.cc @@ -656,6 +656,9 @@ void DiskCacheEntryTest::GetTimes() { if (type_ == net::APP_CACHE) { EXPECT_TRUE(entry->GetLastUsed() < t2); EXPECT_TRUE(entry->GetLastModified() < t2); + } else if (type_ == net::SHADER_CACHE) { + EXPECT_TRUE(entry->GetLastUsed() < t3); + EXPECT_TRUE(entry->GetLastModified() < t3); } else { EXPECT_TRUE(entry->GetLastUsed() >= t3); EXPECT_TRUE(entry->GetLastModified() < t3); @@ -680,6 +683,12 @@ TEST_F(DiskCacheEntryTest, AppCacheGetTimes) { GetTimes(); } +TEST_F(DiskCacheEntryTest, ShaderCacheGetTimes) { + SetCacheType(net::SHADER_CACHE); + InitCache(); + GetTimes(); +} + void DiskCacheEntryTest::GrowData() { std::string key1("the first key"); disk_cache::Entry* entry; diff --git a/net/disk_cache/histogram_macros.h b/net/disk_cache/histogram_macros.h index 4416acb..3d8011c 100644 --- a/net/disk_cache/histogram_macros.h +++ b/net/disk_cache/histogram_macros.h @@ -112,6 +112,9 @@ case net::APP_CACHE:\ CACHE_HISTOGRAM_##type(my_name.data(), sample);\ break;\ + case net::SHADER_CACHE:\ + CACHE_HISTOGRAM_##type(my_name.data(), sample);\ + break;\ default:\ NOTREACHED();\ break;\ |