OLD | NEW |
1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 10246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10257 CHECK_EQ(2, prologue_call_count_second); | 10257 CHECK_EQ(2, prologue_call_count_second); |
10258 CHECK_EQ(2, epilogue_call_count_second); | 10258 CHECK_EQ(2, epilogue_call_count_second); |
10259 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); | 10259 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); |
10260 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); | 10260 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); |
10261 i::Heap::CollectAllGarbage(false); | 10261 i::Heap::CollectAllGarbage(false); |
10262 CHECK_EQ(2, prologue_call_count); | 10262 CHECK_EQ(2, prologue_call_count); |
10263 CHECK_EQ(2, epilogue_call_count); | 10263 CHECK_EQ(2, epilogue_call_count); |
10264 CHECK_EQ(2, prologue_call_count_second); | 10264 CHECK_EQ(2, prologue_call_count_second); |
10265 CHECK_EQ(2, epilogue_call_count_second); | 10265 CHECK_EQ(2, epilogue_call_count_second); |
10266 } | 10266 } |
| 10267 |
| 10268 |
| 10269 THREADED_TEST(AddToJSFunctionResultCache) { |
| 10270 i::FLAG_allow_natives_syntax = true; |
| 10271 v8::HandleScope scope; |
| 10272 |
| 10273 LocalContext context; |
| 10274 |
| 10275 const char* code = |
| 10276 "(function() {" |
| 10277 " var key0 = 'a';" |
| 10278 " var key1 = 'b';" |
| 10279 " var r0 = %_GetFromCache(0, key0);" |
| 10280 " var r1 = %_GetFromCache(0, key1);" |
| 10281 " var r0_ = %_GetFromCache(0, key0);" |
| 10282 " if (r0 !== r0_)" |
| 10283 " return 'Different results for ' + key0 + ': ' + r0 + ' vs. ' + r0_;" |
| 10284 " var r1_ = %_GetFromCache(0, key1);" |
| 10285 " if (r1 !== r1_)" |
| 10286 " return 'Different results for ' + key1 + ': ' + r1 + ' vs. ' + r1_;" |
| 10287 " return 'PASSED';" |
| 10288 "})()"; |
| 10289 v8::internal::Heap::ClearJSFunctionResultCaches(); |
| 10290 ExpectString(code, "PASSED"); |
| 10291 } |
| 10292 |
| 10293 |
| 10294 static const int k0CacheSize = 16; |
| 10295 |
| 10296 THREADED_TEST(FillJSFunctionResultCache) { |
| 10297 i::FLAG_allow_natives_syntax = true; |
| 10298 v8::HandleScope scope; |
| 10299 |
| 10300 LocalContext context; |
| 10301 |
| 10302 const char* code = |
| 10303 "(function() {" |
| 10304 " var k = 'a';" |
| 10305 " var r = %_GetFromCache(0, k);" |
| 10306 " for (var i = 0; i < 16; i++) {" |
| 10307 " %_GetFromCache(0, 'a' + i);" |
| 10308 " };" |
| 10309 " if (r === %_GetFromCache(0, k))" |
| 10310 " return 'FAILED: k0CacheSize is too small';" |
| 10311 " return 'PASSED';" |
| 10312 "})()"; |
| 10313 v8::internal::Heap::ClearJSFunctionResultCaches(); |
| 10314 ExpectString(code, "PASSED"); |
| 10315 } |
| 10316 |
| 10317 |
| 10318 THREADED_TEST(RoundRobinGetFromCache) { |
| 10319 i::FLAG_allow_natives_syntax = true; |
| 10320 v8::HandleScope scope; |
| 10321 |
| 10322 LocalContext context; |
| 10323 |
| 10324 const char* code = |
| 10325 "(function() {" |
| 10326 " var keys = [];" |
| 10327 " for (var i = 0; i < 16; i++) keys.push(i);" |
| 10328 " var values = [];" |
| 10329 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);" |
| 10330 " for (var i = 0; i < 16; i++) {" |
| 10331 " var v = %_GetFromCache(0, keys[i]);" |
| 10332 " if (v !== values[i])" |
| 10333 " return 'Wrong value for ' + " |
| 10334 " keys[i] + ': ' + v + ' vs. ' + values[i];" |
| 10335 " };" |
| 10336 " return 'PASSED';" |
| 10337 "})()"; |
| 10338 v8::internal::Heap::ClearJSFunctionResultCaches(); |
| 10339 ExpectString(code, "PASSED"); |
| 10340 } |
| 10341 |
| 10342 |
| 10343 THREADED_TEST(ReverseGetFromCache) { |
| 10344 i::FLAG_allow_natives_syntax = true; |
| 10345 v8::HandleScope scope; |
| 10346 |
| 10347 LocalContext context; |
| 10348 |
| 10349 const char* code = |
| 10350 "(function() {" |
| 10351 " var keys = [];" |
| 10352 " for (var i = 0; i < 16; i++) keys.push(i);" |
| 10353 " var values = [];" |
| 10354 " for (var i = 0; i < 16; i++) values[i] = %_GetFromCache(0, keys[i]);" |
| 10355 " for (var i = 15; i >= 16; i--) {" |
| 10356 " var v = %_GetFromCache(0, keys[i]);" |
| 10357 " if (v !== values[i])" |
| 10358 " return 'Wrong value for ' + " |
| 10359 " keys[i] + ': ' + v + ' vs. ' + values[i];" |
| 10360 " };" |
| 10361 " return 'PASSED';" |
| 10362 "})()"; |
| 10363 v8::internal::Heap::ClearJSFunctionResultCaches(); |
| 10364 ExpectString(code, "PASSED"); |
| 10365 } |
| 10366 |
| 10367 |
| 10368 THREADED_TEST(TestEviction) { |
| 10369 i::FLAG_allow_natives_syntax = true; |
| 10370 v8::HandleScope scope; |
| 10371 |
| 10372 LocalContext context; |
| 10373 |
| 10374 const char* code = |
| 10375 "(function() {" |
| 10376 " for (var i = 0; i < 2*16; i++) {" |
| 10377 " %_GetFromCache(0, 'a' + i);" |
| 10378 " };" |
| 10379 " return 'PASSED';" |
| 10380 "})()"; |
| 10381 v8::internal::Heap::ClearJSFunctionResultCaches(); |
| 10382 ExpectString(code, "PASSED"); |
| 10383 } |
OLD | NEW |