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 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 } | 387 } |
388 | 388 |
389 | 389 |
390 THREADED_TEST(ScriptMakingExternalString) { | 390 THREADED_TEST(ScriptMakingExternalString) { |
391 TestResource::dispose_count = 0; | 391 TestResource::dispose_count = 0; |
392 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); | 392 uint16_t* two_byte_source = AsciiToTwoByteString("1 + 2 * 3"); |
393 { | 393 { |
394 v8::HandleScope scope; | 394 v8::HandleScope scope; |
395 LocalContext env; | 395 LocalContext env; |
396 Local<String> source = String::New(two_byte_source); | 396 Local<String> source = String::New(two_byte_source); |
397 // Trigger GCs so that the newly allocated string moves to old gen. | |
398 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | |
399 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | |
397 bool success = source->MakeExternal(new TestResource(two_byte_source)); | 400 bool success = source->MakeExternal(new TestResource(two_byte_source)); |
398 CHECK(success); | 401 CHECK(success); |
399 Local<Script> script = Script::Compile(source); | 402 Local<Script> script = Script::Compile(source); |
400 Local<Value> value = script->Run(); | 403 Local<Value> value = script->Run(); |
401 CHECK(value->IsNumber()); | 404 CHECK(value->IsNumber()); |
402 CHECK_EQ(7, value->Int32Value()); | 405 CHECK_EQ(7, value->Int32Value()); |
403 v8::internal::Heap::CollectAllGarbage(false); | 406 v8::internal::Heap::CollectAllGarbage(false); |
404 CHECK_EQ(0, TestResource::dispose_count); | 407 CHECK_EQ(0, TestResource::dispose_count); |
405 } | 408 } |
406 v8::internal::CompilationCache::Clear(); | 409 v8::internal::CompilationCache::Clear(); |
407 v8::internal::Heap::CollectAllGarbage(false); | 410 v8::internal::Heap::CollectAllGarbage(false); |
408 CHECK_EQ(1, TestResource::dispose_count); | 411 CHECK_EQ(1, TestResource::dispose_count); |
409 } | 412 } |
410 | 413 |
411 | 414 |
412 THREADED_TEST(ScriptMakingExternalAsciiString) { | 415 THREADED_TEST(ScriptMakingExternalAsciiString) { |
413 TestAsciiResource::dispose_count = 0; | 416 TestAsciiResource::dispose_count = 0; |
414 const char* c_source = "1 + 2 * 3"; | 417 const char* c_source = "1 + 2 * 3"; |
415 { | 418 { |
416 v8::HandleScope scope; | 419 v8::HandleScope scope; |
417 LocalContext env; | 420 LocalContext env; |
418 Local<String> source = v8_str(c_source); | 421 Local<String> source = v8_str(c_source); |
422 // Trigger GCs so that the newly allocated string moves to old gen. | |
423 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | |
424 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | |
419 bool success = source->MakeExternal( | 425 bool success = source->MakeExternal( |
420 new TestAsciiResource(i::StrDup(c_source))); | 426 new TestAsciiResource(i::StrDup(c_source))); |
421 CHECK(success); | 427 CHECK(success); |
422 Local<Script> script = Script::Compile(source); | 428 Local<Script> script = Script::Compile(source); |
423 Local<Value> value = script->Run(); | 429 Local<Value> value = script->Run(); |
424 CHECK(value->IsNumber()); | 430 CHECK(value->IsNumber()); |
425 CHECK_EQ(7, value->Int32Value()); | 431 CHECK_EQ(7, value->Int32Value()); |
426 v8::internal::Heap::CollectAllGarbage(false); | 432 v8::internal::Heap::CollectAllGarbage(false); |
427 CHECK_EQ(0, TestAsciiResource::dispose_count); | 433 CHECK_EQ(0, TestAsciiResource::dispose_count); |
428 } | 434 } |
429 v8::internal::CompilationCache::Clear(); | 435 v8::internal::CompilationCache::Clear(); |
430 v8::internal::Heap::CollectAllGarbage(false); | 436 v8::internal::Heap::CollectAllGarbage(false); |
431 CHECK_EQ(1, TestAsciiResource::dispose_count); | 437 CHECK_EQ(1, TestAsciiResource::dispose_count); |
432 } | 438 } |
433 | 439 |
434 | 440 |
441 TEST(MakingExternalStringConditions) { | |
442 v8::HandleScope scope; | |
443 LocalContext env; | |
444 | |
445 // Free some space in the new space so that we can check freshness. | |
446 i::Heap::CollectGarbage(0, i::NEW_SPACE); | |
447 i::Heap::CollectGarbage(0, i::NEW_SPACE); | |
448 | |
449 Local<String> small_string = String::New(AsciiToTwoByteString("small")); | |
450 // We should refuse to externalize newly created small string. | |
451 CHECK(!small_string->CanMakeExternal()); | |
452 // Trigger GCs so that the newly allocated string moves to old gen. | |
453 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | |
454 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | |
455 // Old space strings should be accepted. | |
456 CHECK(small_string->CanMakeExternal()); | |
457 | |
458 small_string = String::New(AsciiToTwoByteString("small 2")); | |
459 // We should refuse externalizing newly created small string. | |
460 CHECK(!small_string->CanMakeExternal()); | |
461 for (int i = 0; i < 100; i++) { | |
462 String::Value value(small_string); | |
463 } | |
464 // Frequently used strings should be accepted. | |
465 CHECK(small_string->CanMakeExternal()); | |
466 | |
467 const int buf_size = 10 * 1024; | |
468 char* buf = i::NewArray<char>(buf_size); | |
469 memset(buf, 'a', buf_size); | |
470 buf[buf_size - 1] = '\0'; | |
471 Local<String> large_string = String::New(AsciiToTwoByteString(buf)); | |
472 i::DeleteArray(buf); | |
473 // Large strings should be immediately accepted. | |
474 CHECK(small_string->CanMakeExternal()); | |
Mads Ager (chromium)
2010/02/16 08:16:19
small_ -> large_
Vitaly Repeshko
2010/02/16 18:56:42
Oops. Done.
| |
475 } | |
476 | |
477 | |
478 TEST(MakingExternalAsciiStringConditions) { | |
479 v8::HandleScope scope; | |
480 LocalContext env; | |
481 | |
482 // Free some space in the new space so that we can check freshness. | |
483 i::Heap::CollectGarbage(0, i::NEW_SPACE); | |
484 i::Heap::CollectGarbage(0, i::NEW_SPACE); | |
485 | |
486 Local<String> small_string = String::New("small"); | |
487 // We should refuse to externalize newly created small string. | |
488 CHECK(!small_string->CanMakeExternal()); | |
489 // Trigger GCs so that the newly allocated string moves to old gen. | |
490 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | |
491 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | |
492 // Old space strings should be accepted. | |
493 CHECK(small_string->CanMakeExternal()); | |
494 | |
495 small_string = String::New("small 2"); | |
496 // We should refuse externalizing newly created small string. | |
497 CHECK(!small_string->CanMakeExternal()); | |
498 for (int i = 0; i < 100; i++) { | |
499 String::Value value(small_string); | |
500 } | |
501 // Frequently used strings should be accepted. | |
502 CHECK(small_string->CanMakeExternal()); | |
503 | |
504 const int buf_size = 10 * 1024; | |
505 char* buf = i::NewArray<char>(buf_size); | |
506 memset(buf, 'a', buf_size); | |
507 buf[buf_size - 1] = '\0'; | |
508 Local<String> large_string = String::New(buf); | |
509 i::DeleteArray(buf); | |
510 // Large strings should be immediately accepted. | |
511 CHECK(small_string->CanMakeExternal()); | |
Mads Ager (chromium)
2010/02/16 08:16:19
small_ -> large_
Vitaly Repeshko
2010/02/16 18:56:42
Ditto.
| |
512 } | |
513 | |
514 | |
435 THREADED_TEST(UsingExternalString) { | 515 THREADED_TEST(UsingExternalString) { |
436 { | 516 { |
437 v8::HandleScope scope; | 517 v8::HandleScope scope; |
438 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); | 518 uint16_t* two_byte_string = AsciiToTwoByteString("test string"); |
439 Local<String> string = | 519 Local<String> string = |
440 String::NewExternal(new TestResource(two_byte_string)); | 520 String::NewExternal(new TestResource(two_byte_string)); |
441 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); | 521 i::Handle<i::String> istring = v8::Utils::OpenHandle(*string); |
442 // Trigger GCs so that the newly allocated string moves to old gen. | 522 // Trigger GCs so that the newly allocated string moves to old gen. |
443 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now | 523 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in survivor space now |
444 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now | 524 i::Heap::CollectGarbage(0, i::NEW_SPACE); // in old gen now |
(...skipping 9029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
9474 CompileRun(source_exception); | 9554 CompileRun(source_exception); |
9475 other_context->Exit(); | 9555 other_context->Exit(); |
9476 v8::internal::Heap::CollectAllGarbage(false); | 9556 v8::internal::Heap::CollectAllGarbage(false); |
9477 if (GetGlobalObjectsCount() == 1) break; | 9557 if (GetGlobalObjectsCount() == 1) break; |
9478 } | 9558 } |
9479 CHECK_GE(2, gc_count); | 9559 CHECK_GE(2, gc_count); |
9480 CHECK_EQ(1, GetGlobalObjectsCount()); | 9560 CHECK_EQ(1, GetGlobalObjectsCount()); |
9481 | 9561 |
9482 other_context.Dispose(); | 9562 other_context.Dispose(); |
9483 } | 9563 } |
OLD | NEW |