| 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 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 | 458 |
| 459 | 459 |
| 460 TEST(MakingExternalStringConditions) { | 460 TEST(MakingExternalStringConditions) { |
| 461 v8::HandleScope scope; | 461 v8::HandleScope scope; |
| 462 LocalContext env; | 462 LocalContext env; |
| 463 | 463 |
| 464 // Free some space in the new space so that we can check freshness. | 464 // Free some space in the new space so that we can check freshness. |
| 465 i::Heap::CollectGarbage(0, i::NEW_SPACE); | 465 i::Heap::CollectGarbage(0, i::NEW_SPACE); |
| 466 i::Heap::CollectGarbage(0, i::NEW_SPACE); | 466 i::Heap::CollectGarbage(0, i::NEW_SPACE); |
| 467 | 467 |
| 468 Local<String> small_string = String::New(AsciiToTwoByteString("small")); | 468 uint16_t* two_byte_string = AsciiToTwoByteString("small"); |
| 469 Local<String> small_string = String::New(two_byte_string); |
| 470 i::DeleteArray(two_byte_string); |
| 471 |
| 469 // We should refuse to externalize newly created small string. | 472 // We should refuse to externalize newly created small string. |
| 470 CHECK(!small_string->CanMakeExternal()); | 473 CHECK(!small_string->CanMakeExternal()); |
| 471 // Trigger GCs so that the newly allocated string moves to old gen. | 474 // Trigger GCs so that the newly allocated string moves to old gen. |
| 472 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | 475 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now |
| 473 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | 476 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now |
| 474 // Old space strings should be accepted. | 477 // Old space strings should be accepted. |
| 475 CHECK(small_string->CanMakeExternal()); | 478 CHECK(small_string->CanMakeExternal()); |
| 476 | 479 |
| 477 small_string = String::New(AsciiToTwoByteString("small 2")); | 480 two_byte_string = AsciiToTwoByteString("small 2"); |
| 481 small_string = String::New(two_byte_string); |
| 482 i::DeleteArray(two_byte_string); |
| 483 |
| 478 // We should refuse externalizing newly created small string. | 484 // We should refuse externalizing newly created small string. |
| 479 CHECK(!small_string->CanMakeExternal()); | 485 CHECK(!small_string->CanMakeExternal()); |
| 480 for (int i = 0; i < 100; i++) { | 486 for (int i = 0; i < 100; i++) { |
| 481 String::Value value(small_string); | 487 String::Value value(small_string); |
| 482 } | 488 } |
| 483 // Frequently used strings should be accepted. | 489 // Frequently used strings should be accepted. |
| 484 CHECK(small_string->CanMakeExternal()); | 490 CHECK(small_string->CanMakeExternal()); |
| 485 | 491 |
| 486 const int buf_size = 10 * 1024; | 492 const int buf_size = 10 * 1024; |
| 487 char* buf = i::NewArray<char>(buf_size); | 493 char* buf = i::NewArray<char>(buf_size); |
| 488 memset(buf, 'a', buf_size); | 494 memset(buf, 'a', buf_size); |
| 489 buf[buf_size - 1] = '\0'; | 495 buf[buf_size - 1] = '\0'; |
| 490 Local<String> large_string = String::New(AsciiToTwoByteString(buf)); | 496 |
| 497 two_byte_string = AsciiToTwoByteString(buf); |
| 498 Local<String> large_string = String::New(two_byte_string); |
| 491 i::DeleteArray(buf); | 499 i::DeleteArray(buf); |
| 500 i::DeleteArray(two_byte_string); |
| 492 // Large strings should be immediately accepted. | 501 // Large strings should be immediately accepted. |
| 493 CHECK(large_string->CanMakeExternal()); | 502 CHECK(large_string->CanMakeExternal()); |
| 494 } | 503 } |
| 495 | 504 |
| 496 | 505 |
| 497 TEST(MakingExternalAsciiStringConditions) { | 506 TEST(MakingExternalAsciiStringConditions) { |
| 498 v8::HandleScope scope; | 507 v8::HandleScope scope; |
| 499 LocalContext env; | 508 LocalContext env; |
| 500 | 509 |
| 501 // Free some space in the new space so that we can check freshness. | 510 // Free some space in the new space so that we can check freshness. |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 v8::HandleScope scope; | 619 v8::HandleScope scope; |
| 611 LocalContext env; | 620 LocalContext env; |
| 612 const char* one_byte_string_1 = "function a_times_t"; | 621 const char* one_byte_string_1 = "function a_times_t"; |
| 613 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; | 622 const char* two_byte_string_1 = "wo_plus_b(a, b) {return "; |
| 614 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; | 623 const char* one_byte_extern_1 = "a * 2 + b;} a_times_two_plus_b(4, 8) + "; |
| 615 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; | 624 const char* two_byte_extern_1 = "a_times_two_plus_b(4, 8) + "; |
| 616 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; | 625 const char* one_byte_string_2 = "a_times_two_plus_b(4, 8) + "; |
| 617 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; | 626 const char* two_byte_string_2 = "a_times_two_plus_b(4, 8) + "; |
| 618 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);"; | 627 const char* two_byte_extern_2 = "a_times_two_plus_b(1, 2);"; |
| 619 Local<String> left = v8_str(one_byte_string_1); | 628 Local<String> left = v8_str(one_byte_string_1); |
| 620 Local<String> right = String::New(AsciiToTwoByteString(two_byte_string_1)); | 629 |
| 630 uint16_t* two_byte_source = AsciiToTwoByteString(two_byte_string_1); |
| 631 Local<String> right = String::New(two_byte_source); |
| 632 i::DeleteArray(two_byte_source); |
| 633 |
| 621 Local<String> source = String::Concat(left, right); | 634 Local<String> source = String::Concat(left, right); |
| 622 right = String::NewExternal( | 635 right = String::NewExternal( |
| 623 new TestAsciiResource(i::StrDup(one_byte_extern_1))); | 636 new TestAsciiResource(i::StrDup(one_byte_extern_1))); |
| 624 source = String::Concat(source, right); | 637 source = String::Concat(source, right); |
| 625 right = String::NewExternal( | 638 right = String::NewExternal( |
| 626 new TestResource(AsciiToTwoByteString(two_byte_extern_1))); | 639 new TestResource(AsciiToTwoByteString(two_byte_extern_1))); |
| 627 source = String::Concat(source, right); | 640 source = String::Concat(source, right); |
| 628 right = v8_str(one_byte_string_2); | 641 right = v8_str(one_byte_string_2); |
| 629 source = String::Concat(source, right); | 642 source = String::Concat(source, right); |
| 630 right = String::New(AsciiToTwoByteString(two_byte_string_2)); | 643 |
| 644 two_byte_source = AsciiToTwoByteString(two_byte_string_2); |
| 645 right = String::New(two_byte_source); |
| 646 i::DeleteArray(two_byte_source); |
| 647 |
| 631 source = String::Concat(source, right); | 648 source = String::Concat(source, right); |
| 632 right = String::NewExternal( | 649 right = String::NewExternal( |
| 633 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); | 650 new TestResource(AsciiToTwoByteString(two_byte_extern_2))); |
| 634 source = String::Concat(source, right); | 651 source = String::Concat(source, right); |
| 635 Local<Script> script = Script::Compile(source); | 652 Local<Script> script = Script::Compile(source); |
| 636 Local<Value> value = script->Run(); | 653 Local<Value> value = script->Run(); |
| 637 CHECK(value->IsNumber()); | 654 CHECK(value->IsNumber()); |
| 638 CHECK_EQ(68, value->Int32Value()); | 655 CHECK_EQ(68, value->Int32Value()); |
| 639 } | 656 } |
| 640 v8::internal::CompilationCache::Clear(); | 657 v8::internal::CompilationCache::Clear(); |
| (...skipping 2907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3548 whammy->objects_[whammy->cursor_].Clear(); | 3565 whammy->objects_[whammy->cursor_].Clear(); |
| 3549 } | 3566 } |
| 3550 whammy->objects_[whammy->cursor_] = global; | 3567 whammy->objects_[whammy->cursor_] = global; |
| 3551 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; | 3568 whammy->cursor_ = (whammy->cursor_ + 1) % Whammy::kObjectCount; |
| 3552 return whammy->getScript()->Run(); | 3569 return whammy->getScript()->Run(); |
| 3553 } | 3570 } |
| 3554 | 3571 |
| 3555 THREADED_TEST(WeakReference) { | 3572 THREADED_TEST(WeakReference) { |
| 3556 v8::HandleScope handle_scope; | 3573 v8::HandleScope handle_scope; |
| 3557 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); | 3574 v8::Handle<v8::ObjectTemplate> templ= v8::ObjectTemplate::New(); |
| 3575 Whammy* whammy = new Whammy(); |
| 3558 templ->SetNamedPropertyHandler(WhammyPropertyGetter, | 3576 templ->SetNamedPropertyHandler(WhammyPropertyGetter, |
| 3559 0, 0, 0, 0, | 3577 0, 0, 0, 0, |
| 3560 v8::External::New(new Whammy())); | 3578 v8::External::New(whammy)); |
| 3561 const char* extension_list[] = { "v8/gc" }; | 3579 const char* extension_list[] = { "v8/gc" }; |
| 3562 v8::ExtensionConfiguration extensions(1, extension_list); | 3580 v8::ExtensionConfiguration extensions(1, extension_list); |
| 3563 v8::Persistent<Context> context = Context::New(&extensions); | 3581 v8::Persistent<Context> context = Context::New(&extensions); |
| 3564 Context::Scope context_scope(context); | 3582 Context::Scope context_scope(context); |
| 3565 | 3583 |
| 3566 v8::Handle<v8::Object> interceptor = templ->NewInstance(); | 3584 v8::Handle<v8::Object> interceptor = templ->NewInstance(); |
| 3567 context->Global()->Set(v8_str("whammy"), interceptor); | 3585 context->Global()->Set(v8_str("whammy"), interceptor); |
| 3568 const char* code = | 3586 const char* code = |
| 3569 "var last;" | 3587 "var last;" |
| 3570 "for (var i = 0; i < 10000; i++) {" | 3588 "for (var i = 0; i < 10000; i++) {" |
| 3571 " var obj = whammy.length;" | 3589 " var obj = whammy.length;" |
| 3572 " if (last) last.next = obj;" | 3590 " if (last) last.next = obj;" |
| 3573 " last = obj;" | 3591 " last = obj;" |
| 3574 "}" | 3592 "}" |
| 3575 "gc();" | 3593 "gc();" |
| 3576 "4"; | 3594 "4"; |
| 3577 v8::Handle<Value> result = CompileRun(code); | 3595 v8::Handle<Value> result = CompileRun(code); |
| 3578 CHECK_EQ(4.0, result->NumberValue()); | 3596 CHECK_EQ(4.0, result->NumberValue()); |
| 3579 | 3597 delete whammy; |
| 3580 context.Dispose(); | 3598 context.Dispose(); |
| 3581 } | 3599 } |
| 3582 | 3600 |
| 3583 | 3601 |
| 3584 static bool in_scavenge = false; | 3602 static bool in_scavenge = false; |
| 3585 static int last = -1; | 3603 static int last = -1; |
| 3586 | 3604 |
| 3587 static void ForceScavenge(v8::Persistent<v8::Value> obj, void* data) { | 3605 static void ForceScavenge(v8::Persistent<v8::Value> obj, void* data) { |
| 3588 CHECK_EQ(-1, last); | 3606 CHECK_EQ(-1, last); |
| 3589 last = 0; | 3607 last = 0; |
| (...skipping 4856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8446 const char* expected_slice_on_cons = | 8464 const char* expected_slice_on_cons = |
| 8447 "ow is the time for all good men to come to the aid of the party" | 8465 "ow is the time for all good men to come to the aid of the party" |
| 8448 "Now is the time for all good men to come to the aid of the part"; | 8466 "Now is the time for all good men to come to the aid of the part"; |
| 8449 CHECK_EQ(String::New(expected_cons), | 8467 CHECK_EQ(String::New(expected_cons), |
| 8450 env->Global()->Get(v8_str("cons"))); | 8468 env->Global()->Get(v8_str("cons"))); |
| 8451 CHECK_EQ(String::New(expected_slice), | 8469 CHECK_EQ(String::New(expected_slice), |
| 8452 env->Global()->Get(v8_str("slice"))); | 8470 env->Global()->Get(v8_str("slice"))); |
| 8453 CHECK_EQ(String::New(expected_slice_on_cons), | 8471 CHECK_EQ(String::New(expected_slice_on_cons), |
| 8454 env->Global()->Get(v8_str("slice_on_cons"))); | 8472 env->Global()->Get(v8_str("slice_on_cons"))); |
| 8455 } | 8473 } |
| 8474 i::DeleteArray(two_byte_string); |
| 8456 } | 8475 } |
| 8457 | 8476 |
| 8458 | 8477 |
| 8459 TEST(CompileExternalTwoByteSource) { | 8478 TEST(CompileExternalTwoByteSource) { |
| 8460 v8::HandleScope scope; | 8479 v8::HandleScope scope; |
| 8461 LocalContext context; | 8480 LocalContext context; |
| 8462 | 8481 |
| 8463 // This is a very short list of sources, which currently is to check for a | 8482 // This is a very short list of sources, which currently is to check for a |
| 8464 // regression caused by r2703. | 8483 // regression caused by r2703. |
| 8465 const char* ascii_sources[] = { | 8484 const char* ascii_sources[] = { |
| 8466 "0.5", | 8485 "0.5", |
| 8467 "-0.5", // This mainly testes PushBack in the Scanner. | 8486 "-0.5", // This mainly testes PushBack in the Scanner. |
| 8468 "--0.5", // This mainly testes PushBack in the Scanner. | 8487 "--0.5", // This mainly testes PushBack in the Scanner. |
| 8469 NULL | 8488 NULL |
| 8470 }; | 8489 }; |
| 8471 | 8490 |
| 8472 // Compile the sources as external two byte strings. | 8491 // Compile the sources as external two byte strings. |
| 8473 for (int i = 0; ascii_sources[i] != NULL; i++) { | 8492 for (int i = 0; ascii_sources[i] != NULL; i++) { |
| 8474 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]); | 8493 uint16_t* two_byte_string = AsciiToTwoByteString(ascii_sources[i]); |
| 8475 UC16VectorResource uc16_resource( | 8494 UC16VectorResource uc16_resource( |
| 8476 i::Vector<const uint16_t>(two_byte_string, | 8495 i::Vector<const uint16_t>(two_byte_string, |
| 8477 i::StrLength(ascii_sources[i]))); | 8496 i::StrLength(ascii_sources[i]))); |
| 8478 v8::Local<v8::String> source = v8::String::NewExternal(&uc16_resource); | 8497 v8::Local<v8::String> source = v8::String::NewExternal(&uc16_resource); |
| 8479 v8::Script::Compile(source); | 8498 v8::Script::Compile(source); |
| 8499 i::DeleteArray(two_byte_string); |
| 8480 } | 8500 } |
| 8481 } | 8501 } |
| 8482 | 8502 |
| 8483 | 8503 |
| 8484 class RegExpStringModificationTest { | 8504 class RegExpStringModificationTest { |
| 8485 public: | 8505 public: |
| 8486 RegExpStringModificationTest() | 8506 RegExpStringModificationTest() |
| 8487 : block_(i::OS::CreateSemaphore(0)), | 8507 : block_(i::OS::CreateSemaphore(0)), |
| 8488 morphs_(0), | 8508 morphs_(0), |
| 8489 morphs_during_regexp_(0), | 8509 morphs_during_regexp_(0), |
| (...skipping 1767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10257 CHECK_EQ(2, prologue_call_count_second); | 10277 CHECK_EQ(2, prologue_call_count_second); |
| 10258 CHECK_EQ(2, epilogue_call_count_second); | 10278 CHECK_EQ(2, epilogue_call_count_second); |
| 10259 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); | 10279 v8::V8::RemoveGCPrologueCallback(PrologueCallbackSecond); |
| 10260 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); | 10280 v8::V8::RemoveGCEpilogueCallback(EpilogueCallbackSecond); |
| 10261 i::Heap::CollectAllGarbage(false); | 10281 i::Heap::CollectAllGarbage(false); |
| 10262 CHECK_EQ(2, prologue_call_count); | 10282 CHECK_EQ(2, prologue_call_count); |
| 10263 CHECK_EQ(2, epilogue_call_count); | 10283 CHECK_EQ(2, epilogue_call_count); |
| 10264 CHECK_EQ(2, prologue_call_count_second); | 10284 CHECK_EQ(2, prologue_call_count_second); |
| 10265 CHECK_EQ(2, epilogue_call_count_second); | 10285 CHECK_EQ(2, epilogue_call_count_second); |
| 10266 } | 10286 } |
| OLD | NEW |