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 1625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1636 | 1636 |
1637 | 1637 |
1638 // Count the number of native contexts in the weak list of native contexts. | 1638 // Count the number of native contexts in the weak list of native contexts. |
1639 int CountNativeContexts() { | 1639 int CountNativeContexts() { |
1640 int count = 0; | 1640 int count = 0; |
1641 Object* object = CcTest::heap()->native_contexts_list(); | 1641 Object* object = CcTest::heap()->native_contexts_list(); |
1642 while (!object->IsUndefined()) { | 1642 while (!object->IsUndefined()) { |
1643 count++; | 1643 count++; |
1644 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK); | 1644 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK); |
1645 } | 1645 } |
1646 // Subtract one to compensate for the code stub context that is always present | 1646 return count; |
1647 return count - 1; | |
1648 } | 1647 } |
1649 | 1648 |
1650 | 1649 |
1651 // Count the number of user functions in the weak list of optimized | 1650 // Count the number of user functions in the weak list of optimized |
1652 // functions attached to a native context. | 1651 // functions attached to a native context. |
1653 static int CountOptimizedUserFunctions(v8::Local<v8::Context> context) { | 1652 static int CountOptimizedUserFunctions(v8::Local<v8::Context> context) { |
1654 int count = 0; | 1653 int count = 0; |
1655 Handle<Context> icontext = v8::Utils::OpenHandle(*context); | 1654 Handle<Context> icontext = v8::Utils::OpenHandle(*context); |
1656 Object* object = icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST); | 1655 Object* object = icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST); |
1657 while (object->IsJSFunction() && | 1656 while (object->IsJSFunction() && |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1776 Heap* heap = isolate->heap(); | 1775 Heap* heap = isolate->heap(); |
1777 int count = 0; | 1776 int count = 0; |
1778 Handle<Object> object(heap->native_contexts_list(), isolate); | 1777 Handle<Object> object(heap->native_contexts_list(), isolate); |
1779 while (!object->IsUndefined()) { | 1778 while (!object->IsUndefined()) { |
1780 count++; | 1779 count++; |
1781 if (count == n) heap->CollectAllGarbage(); | 1780 if (count == n) heap->CollectAllGarbage(); |
1782 object = | 1781 object = |
1783 Handle<Object>(Context::cast(*object)->get(Context::NEXT_CONTEXT_LINK), | 1782 Handle<Object>(Context::cast(*object)->get(Context::NEXT_CONTEXT_LINK), |
1784 isolate); | 1783 isolate); |
1785 } | 1784 } |
1786 // Subtract one to compensate for the code stub context that is always present | 1785 return count; |
1787 return count - 1; | |
1788 } | 1786 } |
1789 | 1787 |
1790 | 1788 |
1791 // Count the number of user functions in the weak list of optimized | 1789 // Count the number of user functions in the weak list of optimized |
1792 // functions attached to a native context causing a GC after the | 1790 // functions attached to a native context causing a GC after the |
1793 // specified number of elements. | 1791 // specified number of elements. |
1794 static int CountOptimizedUserFunctionsWithGC(v8::Local<v8::Context> context, | 1792 static int CountOptimizedUserFunctionsWithGC(v8::Local<v8::Context> context, |
1795 int n) { | 1793 int n) { |
1796 int count = 0; | 1794 int count = 0; |
1797 Handle<Context> icontext = v8::Utils::OpenHandle(*context); | 1795 Handle<Context> icontext = v8::Utils::OpenHandle(*context); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2354 CHECK(old_capacity == new_capacity); | 2352 CHECK(old_capacity == new_capacity); |
2355 } | 2353 } |
2356 | 2354 |
2357 | 2355 |
2358 static int NumberOfGlobalObjects() { | 2356 static int NumberOfGlobalObjects() { |
2359 int count = 0; | 2357 int count = 0; |
2360 HeapIterator iterator(CcTest::heap()); | 2358 HeapIterator iterator(CcTest::heap()); |
2361 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 2359 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
2362 if (obj->IsJSGlobalObject()) count++; | 2360 if (obj->IsJSGlobalObject()) count++; |
2363 } | 2361 } |
2364 // Subtract two to compensate for the two global objects (not global | 2362 return count; |
2365 // JSObjects, of which there would only be one) that are part of the code stub | |
2366 // context, which is always present. | |
2367 return count - 1; | |
2368 } | 2363 } |
2369 | 2364 |
2370 | 2365 |
2371 // Test that we don't embed maps from foreign contexts into | 2366 // Test that we don't embed maps from foreign contexts into |
2372 // optimized code. | 2367 // optimized code. |
2373 TEST(LeakNativeContextViaMap) { | 2368 TEST(LeakNativeContextViaMap) { |
2374 i::FLAG_allow_natives_syntax = true; | 2369 i::FLAG_allow_natives_syntax = true; |
2375 v8::Isolate* isolate = CcTest::isolate(); | 2370 v8::Isolate* isolate = CcTest::isolate(); |
2376 v8::HandleScope outer_scope(isolate); | 2371 v8::HandleScope outer_scope(isolate); |
2377 v8::Persistent<v8::Context> ctx1p; | 2372 v8::Persistent<v8::Context> ctx1p; |
(...skipping 4068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6446 isolate->IncrementJsCallsFromApiCounter(); | 6441 isolate->IncrementJsCallsFromApiCounter(); |
6447 isolate->IncrementJsCallsFromApiCounter(); | 6442 isolate->IncrementJsCallsFromApiCounter(); |
6448 isolate->IncrementJsCallsFromApiCounter(); | 6443 isolate->IncrementJsCallsFromApiCounter(); |
6449 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); | 6444 calls_per_ms = memory_reducer->SampleAndGetJsCallsPerMs(4); |
6450 CheckDoubleEquals(2, calls_per_ms); | 6445 CheckDoubleEquals(2, calls_per_ms); |
6451 } | 6446 } |
6452 | 6447 |
6453 | 6448 |
6454 } // namespace internal | 6449 } // namespace internal |
6455 } // namespace v8 | 6450 } // namespace v8 |
OLD | NEW |