| OLD | NEW |
| 1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 5076 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5087 " unlock_for_a_moment();" | 5087 " unlock_for_a_moment();" |
| 5088 " return 42;" | 5088 " return 42;" |
| 5089 "})();"); | 5089 "})();"); |
| 5090 CHECK_EQ(42, script->Run()->Int32Value()); | 5090 CHECK_EQ(42, script->Run()->Int32Value()); |
| 5091 } | 5091 } |
| 5092 } | 5092 } |
| 5093 | 5093 |
| 5094 | 5094 |
| 5095 static int GetSurvivingGlobalObjectsCount() { | 5095 static int GetSurvivingGlobalObjectsCount() { |
| 5096 int count = 0; | 5096 int count = 0; |
| 5097 // We need to collect all garbage twice to be sure that everything |
| 5098 // has been collected. This is because inline caches are cleared in |
| 5099 // the first garbage collection but some of the maps have already |
| 5100 // been marked at that point. Therefore some of the maps are not |
| 5101 // collected until the second garbage collection. |
| 5102 v8::internal::Heap::CollectAllGarbage(); |
| 5097 v8::internal::Heap::CollectAllGarbage(); | 5103 v8::internal::Heap::CollectAllGarbage(); |
| 5098 v8::internal::HeapIterator it; | 5104 v8::internal::HeapIterator it; |
| 5099 while (it.has_next()) { | 5105 while (it.has_next()) { |
| 5100 v8::internal::HeapObject* object = it.next(); | 5106 v8::internal::HeapObject* object = it.next(); |
| 5101 if (object->IsJSGlobalObject()) { | 5107 if (object->IsJSGlobalObject()) { |
| 5102 count++; | 5108 count++; |
| 5103 } | 5109 } |
| 5104 } | 5110 } |
| 5105 #ifdef DEBUG | 5111 #ifdef DEBUG |
| 5106 if (count > 0) v8::internal::Heap::TracePathToGlobal(); | 5112 if (count > 0) v8::internal::Heap::TracePathToGlobal(); |
| 5107 #endif | 5113 #endif |
| 5108 return count; | 5114 return count; |
| 5109 } | 5115 } |
| 5110 | 5116 |
| 5111 | 5117 |
| 5112 TEST(DontLeakGlobalObjects) { | 5118 TEST(DontLeakGlobalObjects) { |
| 5113 // Regression test for issues 1139850 and 1174891. | 5119 // Regression test for issues 1139850 and 1174891. |
| 5114 | 5120 |
| 5115 v8::V8::Initialize(); | 5121 v8::V8::Initialize(); |
| 5116 | 5122 |
| 5117 // TODO(121): when running "cctest test-api", the initial count is 2, | |
| 5118 // after second GC, the counter drops to 1. Needs to figure out why | |
| 5119 // one GC is not enough to collect all garbage. | |
| 5120 GetSurvivingGlobalObjectsCount(); | |
| 5121 int count = GetSurvivingGlobalObjectsCount(); | 5123 int count = GetSurvivingGlobalObjectsCount(); |
| 5122 | 5124 |
| 5123 for (int i = 0; i < 5; i++) { | 5125 for (int i = 0; i < 5; i++) { |
| 5124 { v8::HandleScope scope; | 5126 { v8::HandleScope scope; |
| 5125 LocalContext context; | 5127 LocalContext context; |
| 5126 } | 5128 } |
| 5127 CHECK_EQ(count, GetSurvivingGlobalObjectsCount()); | 5129 CHECK_EQ(count, GetSurvivingGlobalObjectsCount()); |
| 5128 | 5130 |
| 5129 { v8::HandleScope scope; | 5131 { v8::HandleScope scope; |
| 5130 LocalContext context; | 5132 LocalContext context; |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5546 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); | 5548 CompileRun("for (var j = 0; j < 10; j++) new RegExp('');"); |
| 5547 } | 5549 } |
| 5548 // Test CallIC. | 5550 // Test CallIC. |
| 5549 for (int i = 0; i < 2; i++) { | 5551 for (int i = 0; i < 2; i++) { |
| 5550 LocalContext context; | 5552 LocalContext context; |
| 5551 context->Global()->Set(v8_str("tmp"), v8::True()); | 5553 context->Global()->Set(v8_str("tmp"), v8::True()); |
| 5552 context->Global()->Delete(v8_str("tmp")); | 5554 context->Global()->Delete(v8_str("tmp")); |
| 5553 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); | 5555 CompileRun("for (var j = 0; j < 10; j++) RegExp('')"); |
| 5554 } | 5556 } |
| 5555 } | 5557 } |
| OLD | NEW |