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 8424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8435 } | 8435 } |
8436 | 8436 |
8437 | 8437 |
8438 static int GetGlobalObjectsCount() { | 8438 static int GetGlobalObjectsCount() { |
8439 int count = 0; | 8439 int count = 0; |
8440 v8::internal::HeapIterator it; | 8440 v8::internal::HeapIterator it; |
8441 while (it.has_next()) { | 8441 while (it.has_next()) { |
8442 v8::internal::HeapObject* object = it.next(); | 8442 v8::internal::HeapObject* object = it.next(); |
8443 if (object->IsJSGlobalObject()) { | 8443 if (object->IsJSGlobalObject()) { |
8444 count++; | 8444 count++; |
| 8445 //object->PrintLn(); |
8445 } | 8446 } |
8446 } | 8447 } |
8447 #ifdef DEBUG | |
8448 if (count > 0) v8::internal::Heap::TracePathToGlobal(); | |
8449 #endif | |
8450 return count; | 8448 return count; |
8451 } | 8449 } |
8452 | 8450 |
8453 | 8451 |
8454 TEST(Bug528) { | 8452 TEST(Bug528) { |
8455 v8::V8::Initialize(); | 8453 v8::V8::Initialize(); |
8456 | 8454 |
8457 v8::HandleScope scope; | 8455 v8::HandleScope scope; |
8458 v8::Persistent<Context> context; | 8456 v8::Persistent<Context> context; |
| 8457 v8::Persistent<Context> other_context; |
8459 int gc_count; | 8458 int gc_count; |
8460 | 8459 |
| 8460 // Create a context used to keep the code from aging in the compilation |
| 8461 // cache. |
| 8462 other_context = Context::New(); |
| 8463 |
8461 // Context-dependent context data creates reference from the compilation | 8464 // Context-dependent context data creates reference from the compilation |
8462 // cache to the global object. | 8465 // cache to the global object. |
| 8466 const char* source_simple = "1"; |
8463 context = Context::New(); | 8467 context = Context::New(); |
8464 { | 8468 { |
8465 v8::HandleScope scope; | 8469 v8::HandleScope scope; |
8466 | 8470 |
8467 context->Enter(); | 8471 context->Enter(); |
8468 Local<v8::String> obj = v8::String::New(""); | 8472 Local<v8::String> obj = v8::String::New(""); |
8469 context->SetData(obj); | 8473 context->SetData(obj); |
8470 CompileRun("1"); | 8474 CompileRun(source_simple); |
8471 context->Exit(); | 8475 context->Exit(); |
8472 } | 8476 } |
8473 context.Dispose(); | 8477 context.Dispose(); |
8474 for (gc_count = 1; gc_count < 10; gc_count++) { | 8478 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 8479 other_context->Enter(); |
| 8480 CompileRun(source_simple); |
| 8481 other_context->Exit(); |
8475 v8::internal::Heap::CollectAllGarbage(false); | 8482 v8::internal::Heap::CollectAllGarbage(false); |
8476 if (GetGlobalObjectsCount() == 0) break; | 8483 if (GetGlobalObjectsCount() == 1) break; |
8477 } | 8484 } |
8478 CHECK_EQ(0, GetGlobalObjectsCount()); | 8485 CHECK(gc_count <= 2); |
8479 CHECK_EQ(2, gc_count); | 8486 CHECK_EQ(1, GetGlobalObjectsCount()); |
8480 | 8487 |
8481 // Eval in a function creates reference from the compilation cache to the | 8488 // Eval in a function creates reference from the compilation cache to the |
8482 // global object. | 8489 // global object. |
| 8490 const char* source_eval = "function f(){eval('1')}; f()"; |
8483 context = Context::New(); | 8491 context = Context::New(); |
8484 { | 8492 { |
8485 v8::HandleScope scope; | 8493 v8::HandleScope scope; |
8486 | 8494 |
8487 context->Enter(); | 8495 context->Enter(); |
8488 CompileRun("function f(){eval('1')}; f()"); | 8496 CompileRun(source_eval); |
8489 context->Exit(); | 8497 context->Exit(); |
8490 } | 8498 } |
8491 context.Dispose(); | 8499 context.Dispose(); |
8492 for (gc_count = 1; gc_count < 10; gc_count++) { | 8500 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 8501 other_context->Enter(); |
| 8502 CompileRun(source_eval); |
| 8503 other_context->Exit(); |
8493 v8::internal::Heap::CollectAllGarbage(false); | 8504 v8::internal::Heap::CollectAllGarbage(false); |
8494 if (GetGlobalObjectsCount() == 0) break; | 8505 if (GetGlobalObjectsCount() == 1) break; |
8495 } | 8506 } |
8496 CHECK_EQ(0, GetGlobalObjectsCount()); | 8507 CHECK_EQ(10, gc_count); // Should be 1 or 2 when the bug is resolved. |
8497 CHECK_EQ(2, gc_count); | 8508 CHECK_EQ(2, GetGlobalObjectsCount()); // Should be 1 when resolved. |
8498 | 8509 |
8499 // Looking up the line number for an exception creates reference from the | 8510 // Looking up the line number for an exception creates reference from the |
8500 // compilation cache to the global object. | 8511 // compilation cache to the global object. |
| 8512 const char* source_exception = "function f(){throw 1;} f()"; |
8501 context = Context::New(); | 8513 context = Context::New(); |
8502 { | 8514 { |
8503 v8::HandleScope scope; | 8515 v8::HandleScope scope; |
8504 | 8516 |
8505 context->Enter(); | 8517 context->Enter(); |
8506 v8::TryCatch try_catch; | 8518 v8::TryCatch try_catch; |
8507 CompileRun("function f(){throw 1;}; f()"); | 8519 CompileRun(source_exception); |
8508 CHECK(try_catch.HasCaught()); | 8520 CHECK(try_catch.HasCaught()); |
8509 v8::Handle<v8::Message> message = try_catch.Message(); | 8521 v8::Handle<v8::Message> message = try_catch.Message(); |
8510 CHECK(!message.IsEmpty()); | 8522 CHECK(!message.IsEmpty()); |
8511 CHECK_EQ(1, message->GetLineNumber()); | 8523 CHECK_EQ(1, message->GetLineNumber()); |
8512 context->Exit(); | 8524 context->Exit(); |
8513 } | 8525 } |
8514 context.Dispose(); | 8526 context.Dispose(); |
8515 for (gc_count = 1; gc_count < 10; gc_count++) { | 8527 for (gc_count = 1; gc_count < 10; gc_count++) { |
| 8528 other_context->Enter(); |
| 8529 CompileRun(source_exception); |
| 8530 other_context->Exit(); |
8516 v8::internal::Heap::CollectAllGarbage(false); | 8531 v8::internal::Heap::CollectAllGarbage(false); |
8517 if (GetGlobalObjectsCount() == 0) break; | 8532 if (GetGlobalObjectsCount() == 1) break; |
8518 } | 8533 } |
8519 CHECK_EQ(0, GetGlobalObjectsCount()); | 8534 CHECK(gc_count <= 2); |
8520 CHECK_EQ(2, gc_count); | 8535 CHECK_EQ(1, GetGlobalObjectsCount()); |
| 8536 |
| 8537 other_context.Dispose(); |
8521 } | 8538 } |
OLD | NEW |