| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 } | 223 } |
| 224 | 224 |
| 225 | 225 |
| 226 class ConsStringStats { | 226 class ConsStringStats { |
| 227 public: | 227 public: |
| 228 ConsStringStats() { | 228 ConsStringStats() { |
| 229 Reset(); | 229 Reset(); |
| 230 } | 230 } |
| 231 void Reset(); | 231 void Reset(); |
| 232 void VerifyEqual(const ConsStringStats& that) const; | 232 void VerifyEqual(const ConsStringStats& that) const; |
| 233 unsigned leaves_; | 233 int leaves_; |
| 234 unsigned empty_leaves_; | 234 int empty_leaves_; |
| 235 unsigned chars_; | 235 int chars_; |
| 236 unsigned left_traversals_; | 236 int left_traversals_; |
| 237 unsigned right_traversals_; | 237 int right_traversals_; |
| 238 private: | 238 private: |
| 239 DISALLOW_COPY_AND_ASSIGN(ConsStringStats); | 239 DISALLOW_COPY_AND_ASSIGN(ConsStringStats); |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 | 242 |
| 243 void ConsStringStats::Reset() { | 243 void ConsStringStats::Reset() { |
| 244 leaves_ = 0; | 244 leaves_ = 0; |
| 245 empty_leaves_ = 0; | 245 empty_leaves_ = 0; |
| 246 chars_ = 0; | 246 chars_ = 0; |
| 247 left_traversals_ = 0; | 247 left_traversals_ = 0; |
| 248 right_traversals_ = 0; | 248 right_traversals_ = 0; |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 void ConsStringStats::VerifyEqual(const ConsStringStats& that) const { | 252 void ConsStringStats::VerifyEqual(const ConsStringStats& that) const { |
| 253 CHECK(this->leaves_ == that.leaves_); | 253 CHECK_EQ(this->leaves_, that.leaves_); |
| 254 CHECK(this->empty_leaves_ == that.empty_leaves_); | 254 CHECK_EQ(this->empty_leaves_, that.empty_leaves_); |
| 255 CHECK(this->chars_ == that.chars_); | 255 CHECK_EQ(this->chars_, that.chars_); |
| 256 CHECK(this->left_traversals_ == that.left_traversals_); | 256 CHECK_EQ(this->left_traversals_, that.left_traversals_); |
| 257 CHECK(this->right_traversals_ == that.right_traversals_); | 257 CHECK_EQ(this->right_traversals_, that.right_traversals_); |
| 258 } | 258 } |
| 259 | 259 |
| 260 | 260 |
| 261 class ConsStringGenerationData { | 261 class ConsStringGenerationData { |
| 262 public: | 262 public: |
| 263 static const int kNumberOfBuildingBlocks = 256; | 263 static const int kNumberOfBuildingBlocks = 256; |
| 264 explicit ConsStringGenerationData(bool long_blocks); | 264 explicit ConsStringGenerationData(bool long_blocks); |
| 265 void Reset(); | 265 void Reset(); |
| 266 inline Handle<String> block(int offset); | 266 inline Handle<String> block(int offset); |
| 267 inline Handle<String> block(uint32_t offset); | 267 inline Handle<String> block(uint32_t offset); |
| 268 // Input variables. | 268 // Input variables. |
| 269 double early_termination_threshold_; | 269 double early_termination_threshold_; |
| 270 double leftness_; | 270 double leftness_; |
| 271 double rightness_; | 271 double rightness_; |
| 272 double empty_leaf_threshold_; | 272 double empty_leaf_threshold_; |
| 273 unsigned max_leaves_; | 273 int max_leaves_; |
| 274 // Cached data. | 274 // Cached data. |
| 275 Handle<String> building_blocks_[kNumberOfBuildingBlocks]; | 275 Handle<String> building_blocks_[kNumberOfBuildingBlocks]; |
| 276 String* empty_string_; | 276 String* empty_string_; |
| 277 MyRandomNumberGenerator rng_; | 277 MyRandomNumberGenerator rng_; |
| 278 // Stats. | 278 // Stats. |
| 279 ConsStringStats stats_; | 279 ConsStringStats stats_; |
| 280 unsigned early_terminations_; | 280 int early_terminations_; |
| 281 private: | 281 private: |
| 282 DISALLOW_COPY_AND_ASSIGN(ConsStringGenerationData); | 282 DISALLOW_COPY_AND_ASSIGN(ConsStringGenerationData); |
| 283 }; | 283 }; |
| 284 | 284 |
| 285 | 285 |
| 286 ConsStringGenerationData::ConsStringGenerationData(bool long_blocks) { | 286 ConsStringGenerationData::ConsStringGenerationData(bool long_blocks) { |
| 287 rng_.init(); | 287 rng_.init(); |
| 288 InitializeBuildingBlocks( | 288 InitializeBuildingBlocks( |
| 289 building_blocks_, kNumberOfBuildingBlocks, long_blocks, &rng_); | 289 building_blocks_, kNumberOfBuildingBlocks, long_blocks, &rng_); |
| 290 empty_string_ = CcTest::heap()->empty_string(); | 290 empty_string_ = CcTest::heap()->empty_string(); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 if (cons_string->IsConsString()) { | 349 if (cons_string->IsConsString()) { |
| 350 return AccumulateStats(ConsString::cast(*cons_string), stats); | 350 return AccumulateStats(ConsString::cast(*cons_string), stats); |
| 351 } | 351 } |
| 352 // This string got flattened by gc. | 352 // This string got flattened by gc. |
| 353 stats->chars_ += cons_string->length(); | 353 stats->chars_ += cons_string->length(); |
| 354 } | 354 } |
| 355 | 355 |
| 356 | 356 |
| 357 void AccumulateStatsWithOperator( | 357 void AccumulateStatsWithOperator( |
| 358 ConsString* cons_string, ConsStringStats* stats) { | 358 ConsString* cons_string, ConsStringStats* stats) { |
| 359 unsigned offset = 0; | 359 ConsStringIteratorOp op(cons_string); |
| 360 int32_t type = cons_string->map()->instance_type(); | 360 String* string; |
| 361 unsigned length = static_cast<unsigned>(cons_string->length()); | 361 int offset; |
| 362 ConsStringIteratorOp op; | 362 while (NULL != (string = op.Next(&offset))) { |
| 363 String* string = op.Operate(cons_string, &offset, &type, &length); | |
| 364 CHECK(string != NULL); | |
| 365 while (true) { | |
| 366 ASSERT(!string->IsConsString()); | |
| 367 // Accumulate stats. | 363 // Accumulate stats. |
| 364 CHECK_EQ(0, offset); |
| 368 stats->leaves_++; | 365 stats->leaves_++; |
| 369 stats->chars_ += string->length(); | 366 stats->chars_ += string->length(); |
| 370 // Check for completion. | |
| 371 bool keep_going_fast_check = op.HasMore(); | |
| 372 string = op.ContinueOperation(&type, &length); | |
| 373 if (string == NULL) return; | |
| 374 // Verify no false positives for fast check. | |
| 375 CHECK(keep_going_fast_check); | |
| 376 } | 367 } |
| 377 } | 368 } |
| 378 | 369 |
| 379 | 370 |
| 380 void VerifyConsString(Handle<String> root, ConsStringGenerationData* data) { | 371 void VerifyConsString(Handle<String> root, ConsStringGenerationData* data) { |
| 381 // Verify basic data. | 372 // Verify basic data. |
| 382 CHECK(root->IsConsString()); | 373 CHECK(root->IsConsString()); |
| 383 CHECK(static_cast<unsigned>(root->length()) == data->stats_.chars_); | 374 CHECK_EQ(root->length(), data->stats_.chars_); |
| 384 // Recursive verify. | 375 // Recursive verify. |
| 385 ConsStringStats stats; | 376 ConsStringStats stats; |
| 386 AccumulateStats(ConsString::cast(*root), &stats); | 377 AccumulateStats(ConsString::cast(*root), &stats); |
| 387 stats.VerifyEqual(data->stats_); | 378 stats.VerifyEqual(data->stats_); |
| 388 // Iteratively verify. | 379 // Iteratively verify. |
| 389 stats.Reset(); | 380 stats.Reset(); |
| 390 AccumulateStatsWithOperator(ConsString::cast(*root), &stats); | 381 AccumulateStatsWithOperator(ConsString::cast(*root), &stats); |
| 391 // Don't see these. Must copy over. | 382 // Don't see these. Must copy over. |
| 392 stats.empty_leaves_ = data->stats_.empty_leaves_; | 383 stats.empty_leaves_ = data->stats_.empty_leaves_; |
| 393 stats.left_traversals_ = data->stats_.left_traversals_; | 384 stats.left_traversals_ = data->stats_.left_traversals_; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 // TODO(dcarney) Test stream reset as well. | 609 // TODO(dcarney) Test stream reset as well. |
| 619 int length = flat_string->length(); | 610 int length = flat_string->length(); |
| 620 // Iterate start search in multiple places in the string. | 611 // Iterate start search in multiple places in the string. |
| 621 int outer_iterations = length > 20 ? 20 : length; | 612 int outer_iterations = length > 20 ? 20 : length; |
| 622 for (int j = 0; j <= outer_iterations; j++) { | 613 for (int j = 0; j <= outer_iterations; j++) { |
| 623 int offset = length * j / outer_iterations; | 614 int offset = length * j / outer_iterations; |
| 624 if (offset < 0) offset = 0; | 615 if (offset < 0) offset = 0; |
| 625 // Want to test the offset == length case. | 616 // Want to test the offset == length case. |
| 626 if (offset > length) offset = length; | 617 if (offset > length) offset = length; |
| 627 StringCharacterStream flat_stream( | 618 StringCharacterStream flat_stream( |
| 628 flat_string, &cons_string_iterator_op_1, static_cast<unsigned>(offset)); | 619 flat_string, &cons_string_iterator_op_1, offset); |
| 629 StringCharacterStream cons_stream( | 620 StringCharacterStream cons_stream( |
| 630 cons_string, &cons_string_iterator_op_2, static_cast<unsigned>(offset)); | 621 cons_string, &cons_string_iterator_op_2, offset); |
| 631 for (int i = offset; i < length; i++) { | 622 for (int i = offset; i < length; i++) { |
| 632 uint16_t c = flat_string->Get(i); | 623 uint16_t c = flat_string->Get(i); |
| 633 CHECK(flat_stream.HasMore()); | 624 CHECK(flat_stream.HasMore()); |
| 634 CHECK(cons_stream.HasMore()); | 625 CHECK(cons_stream.HasMore()); |
| 635 CHECK_EQ(c, flat_stream.GetNext()); | 626 CHECK_EQ(c, flat_stream.GetNext()); |
| 636 CHECK_EQ(c, cons_stream.GetNext()); | 627 CHECK_EQ(c, cons_stream.GetNext()); |
| 637 } | 628 } |
| 638 CHECK(!flat_stream.HasMore()); | 629 CHECK(!flat_stream.HasMore()); |
| 639 CHECK(!cons_stream.HasMore()); | 630 CHECK(!cons_stream.HasMore()); |
| 640 } | 631 } |
| (...skipping 772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1413 CHECK(isolate->has_pending_exception()); \ | 1404 CHECK(isolate->has_pending_exception()); \ |
| 1414 isolate->clear_pending_exception(); \ | 1405 isolate->clear_pending_exception(); \ |
| 1415 dummy.Dispose(); \ | 1406 dummy.Dispose(); \ |
| 1416 } | 1407 } |
| 1417 | 1408 |
| 1418 INVALID_STRING_TEST(NewStringFromAscii, char) | 1409 INVALID_STRING_TEST(NewStringFromAscii, char) |
| 1419 INVALID_STRING_TEST(NewStringFromUtf8, char) | 1410 INVALID_STRING_TEST(NewStringFromUtf8, char) |
| 1420 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) | 1411 INVALID_STRING_TEST(NewStringFromOneByte, uint8_t) |
| 1421 | 1412 |
| 1422 #undef INVALID_STRING_TEST | 1413 #undef INVALID_STRING_TEST |
| OLD | NEW |