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 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1516 | 1516 |
1517 | 1517 |
1518 // Count the number of native contexts in the weak list of native contexts. | 1518 // Count the number of native contexts in the weak list of native contexts. |
1519 int CountNativeContexts() { | 1519 int CountNativeContexts() { |
1520 int count = 0; | 1520 int count = 0; |
1521 Object* object = CcTest::heap()->native_contexts_list(); | 1521 Object* object = CcTest::heap()->native_contexts_list(); |
1522 while (!object->IsUndefined()) { | 1522 while (!object->IsUndefined()) { |
1523 count++; | 1523 count++; |
1524 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK); | 1524 object = Context::cast(object)->get(Context::NEXT_CONTEXT_LINK); |
1525 } | 1525 } |
1526 return count; | 1526 // Subtract one to compensate for the code stub context that is always present |
| 1527 return count - 1; |
1527 } | 1528 } |
1528 | 1529 |
1529 | 1530 |
1530 // Count the number of user functions in the weak list of optimized | 1531 // Count the number of user functions in the weak list of optimized |
1531 // functions attached to a native context. | 1532 // functions attached to a native context. |
1532 static int CountOptimizedUserFunctions(v8::Handle<v8::Context> context) { | 1533 static int CountOptimizedUserFunctions(v8::Handle<v8::Context> context) { |
1533 int count = 0; | 1534 int count = 0; |
1534 Handle<Context> icontext = v8::Utils::OpenHandle(*context); | 1535 Handle<Context> icontext = v8::Utils::OpenHandle(*context); |
1535 Object* object = icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST); | 1536 Object* object = icontext->get(Context::OPTIMIZED_FUNCTIONS_LIST); |
1536 while (object->IsJSFunction() && !JSFunction::cast(object)->IsBuiltin()) { | 1537 while (object->IsJSFunction() && !JSFunction::cast(object)->IsBuiltin()) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 Heap* heap = isolate->heap(); | 1655 Heap* heap = isolate->heap(); |
1655 int count = 0; | 1656 int count = 0; |
1656 Handle<Object> object(heap->native_contexts_list(), isolate); | 1657 Handle<Object> object(heap->native_contexts_list(), isolate); |
1657 while (!object->IsUndefined()) { | 1658 while (!object->IsUndefined()) { |
1658 count++; | 1659 count++; |
1659 if (count == n) heap->CollectAllGarbage(); | 1660 if (count == n) heap->CollectAllGarbage(); |
1660 object = | 1661 object = |
1661 Handle<Object>(Context::cast(*object)->get(Context::NEXT_CONTEXT_LINK), | 1662 Handle<Object>(Context::cast(*object)->get(Context::NEXT_CONTEXT_LINK), |
1662 isolate); | 1663 isolate); |
1663 } | 1664 } |
1664 return count; | 1665 // Subtract one to compensate for the code stub context that is always present |
| 1666 return count - 1; |
1665 } | 1667 } |
1666 | 1668 |
1667 | 1669 |
1668 // Count the number of user functions in the weak list of optimized | 1670 // Count the number of user functions in the weak list of optimized |
1669 // functions attached to a native context causing a GC after the | 1671 // functions attached to a native context causing a GC after the |
1670 // specified number of elements. | 1672 // specified number of elements. |
1671 static int CountOptimizedUserFunctionsWithGC(v8::Handle<v8::Context> context, | 1673 static int CountOptimizedUserFunctionsWithGC(v8::Handle<v8::Context> context, |
1672 int n) { | 1674 int n) { |
1673 int count = 0; | 1675 int count = 0; |
1674 Handle<Context> icontext = v8::Utils::OpenHandle(*context); | 1676 Handle<Context> icontext = v8::Utils::OpenHandle(*context); |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2231 CHECK(old_capacity == new_capacity); | 2233 CHECK(old_capacity == new_capacity); |
2232 } | 2234 } |
2233 | 2235 |
2234 | 2236 |
2235 static int NumberOfGlobalObjects() { | 2237 static int NumberOfGlobalObjects() { |
2236 int count = 0; | 2238 int count = 0; |
2237 HeapIterator iterator(CcTest::heap()); | 2239 HeapIterator iterator(CcTest::heap()); |
2238 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 2240 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
2239 if (obj->IsGlobalObject()) count++; | 2241 if (obj->IsGlobalObject()) count++; |
2240 } | 2242 } |
2241 return count; | 2243 // Subtract two to compensate for the two global objects (not global |
| 2244 // JSObjects, of which there would only be one) that are part of the code stub |
| 2245 // context, which is always present. |
| 2246 return count - 2; |
2242 } | 2247 } |
2243 | 2248 |
2244 | 2249 |
2245 // Test that we don't embed maps from foreign contexts into | 2250 // Test that we don't embed maps from foreign contexts into |
2246 // optimized code. | 2251 // optimized code. |
2247 TEST(LeakNativeContextViaMap) { | 2252 TEST(LeakNativeContextViaMap) { |
2248 i::FLAG_allow_natives_syntax = true; | 2253 i::FLAG_allow_natives_syntax = true; |
2249 v8::Isolate* isolate = CcTest::isolate(); | 2254 v8::Isolate* isolate = CcTest::isolate(); |
2250 v8::HandleScope outer_scope(isolate); | 2255 v8::HandleScope outer_scope(isolate); |
2251 v8::Persistent<v8::Context> ctx1p; | 2256 v8::Persistent<v8::Context> ctx1p; |
(...skipping 3796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6048 array->address(), | 6053 array->address(), |
6049 array->address() + array->Size()); | 6054 array->address() + array->Size()); |
6050 DCHECK(reinterpret_cast<void*>(buffer->Get(1)) == | 6055 DCHECK(reinterpret_cast<void*>(buffer->Get(1)) == |
6051 HeapObject::RawField(heap->empty_fixed_array(), | 6056 HeapObject::RawField(heap->empty_fixed_array(), |
6052 FixedArrayBase::kLengthOffset)); | 6057 FixedArrayBase::kLengthOffset)); |
6053 DCHECK(reinterpret_cast<void*>(buffer->Get(2)) == | 6058 DCHECK(reinterpret_cast<void*>(buffer->Get(2)) == |
6054 HeapObject::RawField(heap->empty_fixed_array(), | 6059 HeapObject::RawField(heap->empty_fixed_array(), |
6055 FixedArrayBase::kLengthOffset)); | 6060 FixedArrayBase::kLengthOffset)); |
6056 delete buffer; | 6061 delete buffer; |
6057 } | 6062 } |
OLD | NEW |