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" |
(...skipping 30 matching lines...) Expand all Loading... |
41 v8::HandleScope scope; | 41 v8::HandleScope scope; |
42 env->Enter(); | 42 env->Enter(); |
43 } | 43 } |
44 | 44 |
45 | 45 |
46 static const int NUMBER_OF_BUILDING_BLOCKS = 128; | 46 static const int NUMBER_OF_BUILDING_BLOCKS = 128; |
47 static const int DEEP_DEPTH = 8 * 1024; | 47 static const int DEEP_DEPTH = 8 * 1024; |
48 static const int SUPER_DEEP_DEPTH = 80 * 1024; | 48 static const int SUPER_DEEP_DEPTH = 80 * 1024; |
49 | 49 |
50 | 50 |
| 51 class Resource: public v8::String::ExternalStringResource, |
| 52 public ZoneObject { |
| 53 public: |
| 54 explicit Resource(Vector<const uc16> string): data_(string.start()) { |
| 55 length_ = string.length(); |
| 56 } |
| 57 virtual const uint16_t* data() const { return data_; } |
| 58 virtual size_t length() const { return length_; } |
| 59 |
| 60 private: |
| 61 const uc16* data_; |
| 62 size_t length_; |
| 63 }; |
| 64 |
| 65 |
51 static void InitializeBuildingBlocks( | 66 static void InitializeBuildingBlocks( |
52 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) { | 67 Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) { |
53 // A list of pointers that we don't have any interest in cleaning up. | 68 // A list of pointers that we don't have any interest in cleaning up. |
54 // If they are reachable from a root then leak detection won't complain. | 69 // If they are reachable from a root then leak detection won't complain. |
55 for (int i = 0; i < NUMBER_OF_BUILDING_BLOCKS; i++) { | 70 for (int i = 0; i < NUMBER_OF_BUILDING_BLOCKS; i++) { |
56 int len = gen() % 16; | 71 int len = gen() % 16; |
57 if (len > 14) { | 72 if (len > 14) { |
58 len += 1234; | 73 len += 1234; |
59 } | 74 } |
60 switch (gen() % 4) { | 75 switch (gen() % 4) { |
(...skipping 15 matching lines...) Expand all Loading... |
76 buf[j] = gen() % 128; | 91 buf[j] = gen() % 128; |
77 } | 92 } |
78 building_blocks[i] = | 93 building_blocks[i] = |
79 Factory::NewStringFromAscii(Vector<const char>(buf, len)); | 94 Factory::NewStringFromAscii(Vector<const char>(buf, len)); |
80 for (int j = 0; j < len; j++) { | 95 for (int j = 0; j < len; j++) { |
81 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); | 96 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); |
82 } | 97 } |
83 break; | 98 break; |
84 } | 99 } |
85 case 2: { | 100 case 2: { |
86 class Resource: public v8::String::ExternalStringResource, | |
87 public ZoneObject { | |
88 public: | |
89 explicit Resource(Vector<const uc16> string): data_(string.start()) { | |
90 length_ = string.length(); | |
91 } | |
92 virtual const uint16_t* data() const { return data_; } | |
93 virtual size_t length() const { return length_; } | |
94 | |
95 private: | |
96 const uc16* data_; | |
97 size_t length_; | |
98 }; | |
99 uc16* buf = Zone::NewArray<uc16>(len); | 101 uc16* buf = Zone::NewArray<uc16>(len); |
100 for (int j = 0; j < len; j++) { | 102 for (int j = 0; j < len; j++) { |
101 buf[j] = gen() % 65536; | 103 buf[j] = gen() % 65536; |
102 } | 104 } |
103 Resource* resource = new Resource(Vector<const uc16>(buf, len)); | 105 Resource* resource = new Resource(Vector<const uc16>(buf, len)); |
104 building_blocks[i] = Factory::NewExternalStringFromTwoByte(resource); | 106 building_blocks[i] = Factory::NewExternalStringFromTwoByte(resource); |
105 for (int j = 0; j < len; j++) { | 107 for (int j = 0; j < len; j++) { |
106 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); | 108 CHECK_EQ(buf[j], building_blocks[i]->Get(j)); |
107 } | 109 } |
108 break; | 110 break; |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 CHECK(!Heap::LookupSymbolIfExists(*key_string, &out)); | 509 CHECK(!Heap::LookupSymbolIfExists(*key_string, &out)); |
508 | 510 |
509 // Forcing yet another garbage collection must allow us to finally | 511 // Forcing yet another garbage collection must allow us to finally |
510 // get rid of the external string. | 512 // get rid of the external string. |
511 Heap::CollectAllGarbage(false); | 513 Heap::CollectAllGarbage(false); |
512 CHECK(resource_destructed); | 514 CHECK(resource_destructed); |
513 | 515 |
514 delete[] source; | 516 delete[] source; |
515 delete[] key; | 517 delete[] key; |
516 } | 518 } |
OLD | NEW |