| 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 516 |
| 517 // Free some space in the new space so that we can check freshness. | 517 // Free some space in the new space so that we can check freshness. |
| 518 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 518 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 519 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 519 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 520 | 520 |
| 521 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); | 521 uint16_t* two_byte_string = AsciiToTwoByteString("s1"); |
| 522 Local<String> small_string = | 522 Local<String> small_string = |
| 523 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); | 523 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); |
| 524 i::DeleteArray(two_byte_string); | 524 i::DeleteArray(two_byte_string); |
| 525 | 525 |
| 526 // We should refuse to externalize newly created small string. | 526 // We should refuse to externalize small strings. |
| 527 CHECK(!small_string->CanMakeExternal()); | 527 CHECK(!small_string->CanMakeExternal()); |
| 528 // Trigger GCs so that the newly allocated string moves to old gen. | 528 // Trigger GCs so that the newly allocated string moves to old gen. |
| 529 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 529 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 530 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 530 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 531 // Old space strings should be accepted. | 531 // Old space strings should be accepted. |
| 532 CHECK(small_string->CanMakeExternal()); | 532 CHECK(small_string->CanMakeExternal()); |
| 533 | 533 |
| 534 two_byte_string = AsciiToTwoByteString("small string 2"); | 534 two_byte_string = AsciiToTwoByteString("small string 2"); |
| 535 small_string = String::NewFromTwoByte(env->GetIsolate(), two_byte_string); | 535 small_string = String::NewFromTwoByte(env->GetIsolate(), two_byte_string); |
| 536 i::DeleteArray(two_byte_string); | 536 i::DeleteArray(two_byte_string); |
| 537 | 537 |
| 538 // We should refuse externalizing newly created small string. | |
| 539 CHECK(!small_string->CanMakeExternal()); | |
| 540 for (int i = 0; i < 100; i++) { | |
| 541 String::Value value(small_string); | |
| 542 } | |
| 543 // Frequently used strings should be accepted. | |
| 544 CHECK(small_string->CanMakeExternal()); | |
| 545 | |
| 546 const int buf_size = 10 * 1024; | 538 const int buf_size = 10 * 1024; |
| 547 char* buf = i::NewArray<char>(buf_size); | 539 char* buf = i::NewArray<char>(buf_size); |
| 548 memset(buf, 'a', buf_size); | 540 memset(buf, 'a', buf_size); |
| 549 buf[buf_size - 1] = '\0'; | 541 buf[buf_size - 1] = '\0'; |
| 550 | 542 |
| 551 two_byte_string = AsciiToTwoByteString(buf); | 543 two_byte_string = AsciiToTwoByteString(buf); |
| 552 Local<String> large_string = | 544 Local<String> large_string = |
| 553 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); | 545 String::NewFromTwoByte(env->GetIsolate(), two_byte_string); |
| 554 i::DeleteArray(buf); | 546 i::DeleteArray(buf); |
| 555 i::DeleteArray(two_byte_string); | 547 i::DeleteArray(two_byte_string); |
| 556 // Large strings should be immediately accepted. | 548 // Large strings should be immediately accepted. |
| 557 CHECK(large_string->CanMakeExternal()); | 549 CHECK(large_string->CanMakeExternal()); |
| 558 } | 550 } |
| 559 | 551 |
| 560 | 552 |
| 561 TEST(MakingExternalOneByteStringConditions) { | 553 TEST(MakingExternalOneByteStringConditions) { |
| 562 LocalContext env; | 554 LocalContext env; |
| 563 v8::HandleScope scope(env->GetIsolate()); | 555 v8::HandleScope scope(env->GetIsolate()); |
| 564 | 556 |
| 565 // Free some space in the new space so that we can check freshness. | 557 // Free some space in the new space so that we can check freshness. |
| 566 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 558 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 567 CcTest::heap()->CollectGarbage(i::NEW_SPACE); | 559 CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
| 568 | 560 |
| 569 Local<String> small_string = String::NewFromUtf8(env->GetIsolate(), "s1"); | 561 Local<String> small_string = String::NewFromUtf8(env->GetIsolate(), "s1"); |
| 570 // We should refuse to externalize newly created small string. | 562 // We should refuse to externalize small strings. |
| 571 CHECK(!small_string->CanMakeExternal()); | 563 CHECK(!small_string->CanMakeExternal()); |
| 572 // Trigger GCs so that the newly allocated string moves to old gen. | 564 // Trigger GCs so that the newly allocated string moves to old gen. |
| 573 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now | 565 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now |
| 574 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now | 566 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now |
| 575 // Old space strings should be accepted. | 567 // Old space strings should be accepted. |
| 576 CHECK(small_string->CanMakeExternal()); | 568 CHECK(small_string->CanMakeExternal()); |
| 577 | 569 |
| 578 small_string = String::NewFromUtf8(env->GetIsolate(), "small string 2"); | |
| 579 // We should refuse externalizing newly created small string. | |
| 580 CHECK(!small_string->CanMakeExternal()); | |
| 581 for (int i = 0; i < 100; i++) { | |
| 582 String::Value value(small_string); | |
| 583 } | |
| 584 // Frequently used strings should be accepted. | |
| 585 CHECK(small_string->CanMakeExternal()); | |
| 586 | |
| 587 const int buf_size = 10 * 1024; | 570 const int buf_size = 10 * 1024; |
| 588 char* buf = i::NewArray<char>(buf_size); | 571 char* buf = i::NewArray<char>(buf_size); |
| 589 memset(buf, 'a', buf_size); | 572 memset(buf, 'a', buf_size); |
| 590 buf[buf_size - 1] = '\0'; | 573 buf[buf_size - 1] = '\0'; |
| 591 Local<String> large_string = String::NewFromUtf8(env->GetIsolate(), buf); | 574 Local<String> large_string = String::NewFromUtf8(env->GetIsolate(), buf); |
| 592 i::DeleteArray(buf); | 575 i::DeleteArray(buf); |
| 593 // Large strings should be immediately accepted. | 576 // Large strings should be immediately accepted. |
| 594 CHECK(large_string->CanMakeExternal()); | 577 CHECK(large_string->CanMakeExternal()); |
| 595 } | 578 } |
| 596 | 579 |
| (...skipping 21223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21820 | 21803 |
| 21821 v8::TryCatch try_catch(CcTest::isolate()); | 21804 v8::TryCatch try_catch(CcTest::isolate()); |
| 21822 timeout_thread.Start(); | 21805 timeout_thread.Start(); |
| 21823 | 21806 |
| 21824 CompileRun( | 21807 CompileRun( |
| 21825 "var ab = new SharedArrayBuffer(4);" | 21808 "var ab = new SharedArrayBuffer(4);" |
| 21826 "var i32a = new Int32Array(ab);" | 21809 "var i32a = new Int32Array(ab);" |
| 21827 "Atomics.futexWait(i32a, 0, 0);"); | 21810 "Atomics.futexWait(i32a, 0, 0);"); |
| 21828 CHECK(try_catch.HasTerminated()); | 21811 CHECK(try_catch.HasTerminated()); |
| 21829 } | 21812 } |
| OLD | NEW |