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"); |
+} |