| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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" |
| 11 | 11 |
| 12 #include "factory.h" | 12 #include "factory.h" |
| 13 #include "cctest.h" | 13 #include "cctest.h" |
| 14 #include "zone-inl.h" |
| 14 | 15 |
| 15 unsigned int seed = 123; | 16 unsigned int seed = 123; |
| 16 | 17 |
| 17 static uint32_t gen() { | 18 static uint32_t gen() { |
| 18 uint64_t z; | 19 uint64_t z; |
| 19 z = seed; | 20 z = seed; |
| 20 z *= 279470273; | 21 z *= 279470273; |
| 21 z %= 4294967291U; | 22 z %= 4294967291U; |
| 22 seed = static_cast<unsigned int>(z); | 23 seed = static_cast<unsigned int>(z); |
| 23 return static_cast<uint32_t>(seed >> 16); | 24 return static_cast<uint32_t>(seed >> 16); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 41 } | 42 } |
| 42 | 43 |
| 43 | 44 |
| 44 static const int NUMBER_OF_BUILDING_BLOCKS = 128; | 45 static const int NUMBER_OF_BUILDING_BLOCKS = 128; |
| 45 static const int DEEP_DEPTH = 8 * 1024; | 46 static const int DEEP_DEPTH = 8 * 1024; |
| 46 static const int SUPER_DEEP_DEPTH = 80 * 1024; | 47 static const int SUPER_DEEP_DEPTH = 80 * 1024; |
| 47 | 48 |
| 48 | 49 |
| 49 static void InitializeBuildingBlocks( | 50 static void InitializeBuildingBlocks( |
| 50 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) { | 51 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) { |
| 52 // A list of pointers that we don't have any interest in cleaning up. |
| 53 // If they are reachable from a root then leak detection won't complain. |
| 51 for (int i = 0; i < NUMBER_OF_BUILDING_BLOCKS; i++) { | 54 for (int i = 0; i < NUMBER_OF_BUILDING_BLOCKS; i++) { |
| 52 int len = gen() % 16; | 55 int len = gen() % 16; |
| 53 if (len > 14) { | 56 if (len > 14) { |
| 54 len += 1234; | 57 len += 1234; |
| 55 } | 58 } |
| 56 switch (gen() % 4) { | 59 switch (gen() % 4) { |
| 57 case 0: { | 60 case 0: { |
| 58 uc16 buf[2000]; | 61 uc16 buf[2000]; |
| 59 for (int j = 0; j < len; j++) { | 62 for (int j = 0; j < len; j++) { |
| 60 buf[j] = gen() % 65536; | 63 buf[j] = gen() % 65536; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 73 } | 76 } |
| 74 building_blocks[i] = | 77 building_blocks[i] = |
| 75 Factory::NewStringFromAscii(Vector<const char>(buf, len)); | 78 Factory::NewStringFromAscii(Vector<const char>(buf, len)); |
| 76 for (int j = 0; j < len; j++) { | 79 for (int j = 0; j < len; j++) { |
| 77 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); | 80 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); |
| 78 } | 81 } |
| 79 break; | 82 break; |
| 80 } | 83 } |
| 81 case 2: { | 84 case 2: { |
| 82 class Resource: public v8::String::ExternalStringResource, | 85 class Resource: public v8::String::ExternalStringResource, |
| 83 public Malloced { | 86 public ZoneObject { |
| 84 public: | 87 public: |
| 85 explicit Resource(Vector<const uc16> string): data_(string.start()) { | 88 explicit Resource(Vector<const uc16> string): data_(string.start()) { |
| 86 length_ = string.length(); | 89 length_ = string.length(); |
| 87 } | 90 } |
| 88 virtual const uint16_t* data() const { return data_; } | 91 virtual const uint16_t* data() const { return data_; } |
| 89 virtual size_t length() const { return length_; } | 92 virtual size_t length() const { return length_; } |
| 90 | 93 |
| 91 private: | 94 private: |
| 92 const uc16* data_; | 95 const uc16* data_; |
| 93 size_t length_; | 96 size_t length_; |
| 94 }; | 97 }; |
| 95 uc16* buf = NewArray<uc16>(len); | 98 uc16* buf = Zone::NewArray<uc16>(len); |
| 96 for (int j = 0; j < len; j++) { | 99 for (int j = 0; j < len; j++) { |
| 97 buf[j] = gen() % 65536; | 100 buf[j] = gen() % 65536; |
| 98 } | 101 } |
| 99 Resource* resource = new Resource(Vector<const uc16>(buf, len)); | 102 Resource* resource = new Resource(Vector<const uc16>(buf, len)); |
| 100 building_blocks[i] = Factory::NewExternalStringFromTwoByte(resource); | 103 building_blocks[i] = Factory::NewExternalStringFromTwoByte(resource); |
| 101 for (int j = 0; j < len; j++) { | 104 for (int j = 0; j < len; j++) { |
| 102 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); | 105 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); |
| 103 } | 106 } |
| 104 break; | 107 break; |
| 105 } | 108 } |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 s1->Get(s1->length() - 1); | 208 s1->Get(s1->length() - 1); |
| 206 s2->Get(s2->length() - 1); | 209 s2->Get(s2->length() - 1); |
| 207 } | 210 } |
| 208 | 211 |
| 209 | 212 |
| 210 TEST(Traverse) { | 213 TEST(Traverse) { |
| 211 printf("TestTraverse\n"); | 214 printf("TestTraverse\n"); |
| 212 InitializeVM(); | 215 InitializeVM(); |
| 213 v8::HandleScope scope; | 216 v8::HandleScope scope; |
| 214 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]; | 217 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]; |
| 218 ZoneScope zone(DELETE_ON_EXIT); |
| 215 InitializeBuildingBlocks(building_blocks); | 219 InitializeBuildingBlocks(building_blocks); |
| 216 Handle<String> flat = ConstructBalanced(building_blocks); | 220 Handle<String> flat = ConstructBalanced(building_blocks); |
| 217 FlattenString(flat); | 221 FlattenString(flat); |
| 218 Handle<String> left_asymmetric = ConstructLeft(building_blocks, DEEP_DEPTH); | 222 Handle<String> left_asymmetric = ConstructLeft(building_blocks, DEEP_DEPTH); |
| 219 Handle<String> right_asymmetric = ConstructRight(building_blocks, DEEP_DEPTH); | 223 Handle<String> right_asymmetric = ConstructRight(building_blocks, DEEP_DEPTH); |
| 220 Handle<String> symmetric = ConstructBalanced(building_blocks); | 224 Handle<String> symmetric = ConstructBalanced(building_blocks); |
| 221 printf("1\n"); | 225 printf("1\n"); |
| 222 Traverse(flat, symmetric); | 226 Traverse(flat, symmetric); |
| 223 printf("2\n"); | 227 printf("2\n"); |
| 224 Traverse(flat, left_asymmetric); | 228 Traverse(flat, left_asymmetric); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 return branch; | 300 return branch; |
| 297 return(SliceOf(branch)); | 301 return(SliceOf(branch)); |
| 298 } | 302 } |
| 299 | 303 |
| 300 | 304 |
| 301 TEST(Slice) { | 305 TEST(Slice) { |
| 302 printf("TestSlice\n"); | 306 printf("TestSlice\n"); |
| 303 InitializeVM(); | 307 InitializeVM(); |
| 304 v8::HandleScope scope; | 308 v8::HandleScope scope; |
| 305 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]; | 309 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]; |
| 310 ZoneScope zone(DELETE_ON_EXIT); |
| 306 InitializeBuildingBlocks(building_blocks); | 311 InitializeBuildingBlocks(building_blocks); |
| 307 | 312 |
| 308 seed = 42; | 313 seed = 42; |
| 309 Handle<String> slice_tree = | 314 Handle<String> slice_tree = |
| 310 ConstructSliceTree(building_blocks, 0, DEEP_DEPTH); | 315 ConstructSliceTree(building_blocks, 0, DEEP_DEPTH); |
| 311 seed = 42; | 316 seed = 42; |
| 312 Handle<String> flat_slice_tree = | 317 Handle<String> flat_slice_tree = |
| 313 ConstructSliceTree(building_blocks, 0, DEEP_DEPTH); | 318 ConstructSliceTree(building_blocks, 0, DEEP_DEPTH); |
| 314 FlattenString(flat_slice_tree); | 319 FlattenString(flat_slice_tree); |
| 315 Traverse(flat_slice_tree, slice_tree); | 320 Traverse(flat_slice_tree, slice_tree); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 int written = mixed->WriteUtf8(buffer, i); | 380 int written = mixed->WriteUtf8(buffer, i); |
| 376 CHECK_EQ(lengths[i], written); | 381 CHECK_EQ(lengths[i], written); |
| 377 // Check that the contents are correct | 382 // Check that the contents are correct |
| 378 for (int j = 0; j < lengths[i]; j++) | 383 for (int j = 0; j < lengths[i]; j++) |
| 379 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); | 384 CHECK_EQ(as_utf8[j], static_cast<unsigned char>(buffer[j])); |
| 380 // Check that the rest of the buffer hasn't been touched | 385 // Check that the rest of the buffer hasn't been touched |
| 381 for (int j = lengths[i]; j < 11; j++) | 386 for (int j = lengths[i]; j < 11; j++) |
| 382 CHECK_EQ(kNoChar, buffer[j]); | 387 CHECK_EQ(kNoChar, buffer[j]); |
| 383 } | 388 } |
| 384 } | 389 } |
| OLD | NEW |