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

Side by Side Diff: test/cctest/test-strings.cc

Issue 11565031: Make string test resilient against GC stress. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 2
3 // Check that we can traverse very deep stacks of ConsStrings using 3 // Check that we can traverse very deep stacks of ConsStrings using
4 // StringInputBuffer. Check that Get(int) works on very deep stacks 4 // StringInputBuffer. Check that Get(int) works on very deep stacks
5 // of ConsStrings. These operations may not be very fast, but they 5 // of ConsStrings. These operations may not be very fast, but they
6 // should be possible without getting errors due to too deep recursion. 6 // should be possible without getting errors due to too deep recursion.
7 7
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "v8.h" 10 #include "v8.h"
(...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 } 664 }
665 665
666 666
667 template<typename BuildString> 667 template<typename BuildString>
668 void TestStringCharacterStream(BuildString build, int test_cases) { 668 void TestStringCharacterStream(BuildString build, int test_cases) {
669 InitializeVM(); 669 InitializeVM();
670 Isolate* isolate = Isolate::Current(); 670 Isolate* isolate = Isolate::Current();
671 HandleScope outer_scope(isolate); 671 HandleScope outer_scope(isolate);
672 ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); 672 ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT);
673 ConsStringGenerationData data(true); 673 ConsStringGenerationData data(true);
674 bool last_test_did_gc = false;
675 for (int i = 0; i < test_cases; i++) { 674 for (int i = 0; i < test_cases; i++) {
676 printf("%d\n", i); 675 printf("%d\n", i);
677 HandleScope inner_scope(isolate); 676 HandleScope inner_scope(isolate);
677 AlwaysAllocateScope always_allocate;
678 // Build flat version of cons string. 678 // Build flat version of cons string.
679 Handle<String> flat_string = build(i, &data); 679 Handle<String> flat_string = build(i, &data);
680 ConsStringStats flat_string_stats; 680 ConsStringStats flat_string_stats;
681 AccumulateStats(flat_string, &flat_string_stats); 681 AccumulateStats(flat_string, &flat_string_stats);
682 // Flatten string. 682 // Flatten string.
683 FlattenString(flat_string); 683 FlattenString(flat_string);
684 // Build unflattened version of cons string to test. 684 // Build unflattened version of cons string to test.
685 Handle<String> cons_string = build(i, &data); 685 Handle<String> cons_string = build(i, &data);
686 ConsStringStats cons_string_stats; 686 ConsStringStats cons_string_stats;
687 AccumulateStats(cons_string, &cons_string_stats); 687 AccumulateStats(cons_string, &cons_string_stats);
688 // Check if gc changed our data structure.
689 bool broken_by_gc =
690 cons_string_stats.leaves_ != data.stats_.leaves_ ||
691 cons_string_stats.leaves_ != flat_string_stats.leaves_;
692 // If gc altered the data structure, do a full collection and retry test.
693 if (broken_by_gc) {
694 // Bail if test runs twice.
695 if (last_test_did_gc) CHECK(false);
696 printf("forcing gc\n");
697 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, "retry test");
698 // Retry test.
699 last_test_did_gc = true;
700 i--;
701 continue;
702 }
703 last_test_did_gc = false;
704 AssertNoAllocation no_alloc; 688 AssertNoAllocation no_alloc;
705 PrintStats(data); 689 PrintStats(data);
706 // Full verify of cons string. 690 // Full verify of cons string.
707 cons_string_stats.VerifyEqual(flat_string_stats); 691 cons_string_stats.VerifyEqual(flat_string_stats);
708 cons_string_stats.VerifyEqual(data.stats_); 692 cons_string_stats.VerifyEqual(data.stats_);
709 VerifyConsString(cons_string, &data); 693 VerifyConsString(cons_string, &data);
710 String* flat_string_ptr = 694 String* flat_string_ptr =
711 flat_string->IsConsString() ? 695 flat_string->IsConsString() ?
712 ConsString::cast(*flat_string)->first() : 696 ConsString::cast(*flat_string)->first() :
713 *flat_string; 697 *flat_string;
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 1294
1311 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); 1295 v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80");
1312 CHECK(expected->Equals(result)); 1296 CHECK(expected->Equals(result));
1313 } 1297 }
1314 1298
1315 1299
1316 TEST(IsAscii) { 1300 TEST(IsAscii) {
1317 CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); 1301 CHECK(String::IsAscii(static_cast<char*>(NULL), 0));
1318 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); 1302 CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0));
1319 } 1303 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698