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

Unified Diff: test/cctest/test-api.cc

Issue 1695007: Moving more code to lookup an item from the native cache into code generator. (Closed)
Patch Set: Next round of Lasse's comments Created 10 years, 7 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 | « src/x64/codegen-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 2e601af965d9a5cdd5c9880b3b4723f7d9d2d38f..14bdf5d0cbd67793acb5cffabb09ca806966d87b 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -10264,3 +10264,120 @@ TEST(GCCallbacks) {
CHECK_EQ(2, prologue_call_count_second);
CHECK_EQ(2, epilogue_call_count_second);
}
+
+
+THREADED_TEST(AddToJSFunctionResultCache) {
+ i::FLAG_allow_natives_syntax = true;
+ v8::HandleScope scope;
+
+ LocalContext context;
+
+ const char* code =
+ "(function() {"
+ " var key0 = 'a';"
+ " var key1 = 'b';"
+ " var r0 = %_GetFromCache(0, key0);"
+ " var r1 = %_GetFromCache(0, key1);"
+ " var r0_ = %_GetFromCache(0, key0);"
+ " if (r0 !== r0_)"
+ " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;"
+ " var r1_ = %_GetFromCache(0, key1);"
+ " if (r1 !== r1_)"
+ " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;"
+ " return 'PASSED';"
+ "})()";
+ v8::internal::Heap::ClearJSFunctionResultCaches();
+ ExpectString(code, "PASSED");
+}
+
+
+static const int k0CacheSize = 16;
+
+THREADED_TEST(FillJSFunctionResultCache) {
+ i::FLAG_allow_natives_syntax = true;
+ v8::HandleScope scope;
+
+ LocalContext context;
+
+ const char* code =
+ "(function() {"
+ " var k = 'a';"
+ " var r = %_GetFromCache(0, k);"
+ " for (var i = 0; i < 16; i++) {"
+ " %_GetFromCache(0, 'a' + i);"
+ " };"
+ " if (r === %_GetFromCache(0, k))"
+ " return 'FAILED: k0CacheSize is too small';"
+ " return 'PASSED';"
+ "})()";
+ v8::internal::Heap::ClearJSFunctionResultCaches();
+ ExpectString(code, "PASSED");
+}
+
+
+THREADED_TEST(RoundRobinGetFromCache) {
+ i::FLAG_allow_natives_syntax = true;
+ v8::HandleScope scope;
+
+ LocalContext context;
+
+ const char* code =
+ "(function() {"
+ " var keys = [];"
+ " for (var i = 0; i < 16; i++) keys.push(i);"
+ " var values = [];"
+ " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
+ " for (var i = 0; i < 16; i++) {"
+ " var v = %_GetFromCache(0, keys[i]);"
+ " if (v !== values[i])"
+ " return 'Wrong value for ' + "
+ " keys[i] + ': ' + v + ' vs. ' + values[i];"
+ " };"
+ " return 'PASSED';"
+ "})()";
+ v8::internal::Heap::ClearJSFunctionResultCaches();
+ ExpectString(code, "PASSED");
+}
+
+
+THREADED_TEST(ReverseGetFromCache) {
+ i::FLAG_allow_natives_syntax = true;
+ v8::HandleScope scope;
+
+ LocalContext context;
+
+ const char* code =
+ "(function() {"
+ " var keys = [];"
+ " for (var i = 0; i < 16; i++) keys.push(i);"
+ " var values = [];"
+ " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);"
+ " for (var i = 15; i >= 16; i--) {"
+ " var v = %_GetFromCache(0, keys[i]);"
+ " if (v !== values[i])"
+ " return 'Wrong value for ' + "
+ " keys[i] + ': ' + v + ' vs. ' + values[i];"
+ " };"
+ " return 'PASSED';"
+ "})()";
+ v8::internal::Heap::ClearJSFunctionResultCaches();
+ ExpectString(code, "PASSED");
+}
+
+
+THREADED_TEST(TestEviction) {
+ i::FLAG_allow_natives_syntax = true;
+ v8::HandleScope scope;
+
+ LocalContext context;
+
+ const char* code =
+ "(function() {"
+ " for (var i = 0; i < 2*16; i++) {"
+ " %_GetFromCache(0, 'a' + i);"
+ " };"
+ " return 'PASSED';"
+ "})()";
+ v8::internal::Heap::ClearJSFunctionResultCaches();
+ ExpectString(code, "PASSED");
+}
« no previous file with comments | « src/x64/codegen-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698