| 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 12425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12436 | 12436 |
| 12437 | 12437 |
| 12438 // Scan the heap for objects with direct references to an object | 12438 // Scan the heap for objects with direct references to an object |
| 12439 // args[0]: the object to find references to | 12439 // args[0]: the object to find references to |
| 12440 // args[1]: constructor function for instances to exclude (Mirror) | 12440 // args[1]: constructor function for instances to exclude (Mirror) |
| 12441 // args[2]: the the maximum number of objects to return | 12441 // args[2]: the the maximum number of objects to return |
| 12442 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugReferencedBy) { | 12442 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugReferencedBy) { |
| 12443 ASSERT(args.length() == 3); | 12443 ASSERT(args.length() == 3); |
| 12444 | 12444 |
| 12445 // First perform a full GC in order to avoid references from dead objects. | 12445 // First perform a full GC in order to avoid references from dead objects. |
| 12446 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask); | 12446 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 12447 "%DebugReferencedBy"); |
| 12447 // The heap iterator reserves the right to do a GC to make the heap iterable. | 12448 // The heap iterator reserves the right to do a GC to make the heap iterable. |
| 12448 // Due to the GC above we know it won't need to do that, but it seems cleaner | 12449 // Due to the GC above we know it won't need to do that, but it seems cleaner |
| 12449 // to get the heap iterator constructed before we start having unprotected | 12450 // to get the heap iterator constructed before we start having unprotected |
| 12450 // Object* locals that are not protected by handles. | 12451 // Object* locals that are not protected by handles. |
| 12451 | 12452 |
| 12452 // Check parameters. | 12453 // Check parameters. |
| 12453 CONVERT_CHECKED(JSObject, target, args[0]); | 12454 CONVERT_CHECKED(JSObject, target, args[0]); |
| 12454 Object* instance_filter = args[1]; | 12455 Object* instance_filter = args[1]; |
| 12455 RUNTIME_ASSERT(instance_filter->IsUndefined() || | 12456 RUNTIME_ASSERT(instance_filter->IsUndefined() || |
| 12456 instance_filter->IsJSObject()); | 12457 instance_filter->IsJSObject()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12527 } | 12528 } |
| 12528 | 12529 |
| 12529 | 12530 |
| 12530 // Scan the heap for objects constructed by a specific function. | 12531 // Scan the heap for objects constructed by a specific function. |
| 12531 // args[0]: the constructor to find instances of | 12532 // args[0]: the constructor to find instances of |
| 12532 // args[1]: the the maximum number of objects to return | 12533 // args[1]: the the maximum number of objects to return |
| 12533 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) { | 12534 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) { |
| 12534 ASSERT(args.length() == 2); | 12535 ASSERT(args.length() == 2); |
| 12535 | 12536 |
| 12536 // First perform a full GC in order to avoid dead objects. | 12537 // First perform a full GC in order to avoid dead objects. |
| 12537 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask); | 12538 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 12539 "%DebugConstructedBy"); |
| 12538 | 12540 |
| 12539 // Check parameters. | 12541 // Check parameters. |
| 12540 CONVERT_CHECKED(JSFunction, constructor, args[0]); | 12542 CONVERT_CHECKED(JSFunction, constructor, args[0]); |
| 12541 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); | 12543 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); |
| 12542 RUNTIME_ASSERT(max_references >= 0); | 12544 RUNTIME_ASSERT(max_references >= 0); |
| 12543 | 12545 |
| 12544 // Get the number of referencing objects. | 12546 // Get the number of referencing objects. |
| 12545 int count; | 12547 int count; |
| 12546 HeapIterator heap_iterator; | 12548 HeapIterator heap_iterator; |
| 12547 count = DebugConstructedBy(&heap_iterator, | 12549 count = DebugConstructedBy(&heap_iterator, |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12925 SmartArrayPointer<char> flags = | 12927 SmartArrayPointer<char> flags = |
| 12926 arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 12928 arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
| 12927 FlagList::SetFlagsFromString(*flags, StrLength(*flags)); | 12929 FlagList::SetFlagsFromString(*flags, StrLength(*flags)); |
| 12928 return isolate->heap()->undefined_value(); | 12930 return isolate->heap()->undefined_value(); |
| 12929 } | 12931 } |
| 12930 | 12932 |
| 12931 | 12933 |
| 12932 // Performs a GC. | 12934 // Performs a GC. |
| 12933 // Presently, it only does a full GC. | 12935 // Presently, it only does a full GC. |
| 12934 RUNTIME_FUNCTION(MaybeObject*, Runtime_CollectGarbage) { | 12936 RUNTIME_FUNCTION(MaybeObject*, Runtime_CollectGarbage) { |
| 12935 isolate->heap()->CollectAllGarbage(true); | 12937 isolate->heap()->CollectAllGarbage(true, "%CollectGarbage"); |
| 12936 return isolate->heap()->undefined_value(); | 12938 return isolate->heap()->undefined_value(); |
| 12937 } | 12939 } |
| 12938 | 12940 |
| 12939 | 12941 |
| 12940 // Gets the current heap usage. | 12942 // Gets the current heap usage. |
| 12941 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetHeapUsage) { | 12943 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetHeapUsage) { |
| 12942 int usage = static_cast<int>(isolate->heap()->SizeOfObjects()); | 12944 int usage = static_cast<int>(isolate->heap()->SizeOfObjects()); |
| 12943 if (!Smi::IsValid(usage)) { | 12945 if (!Smi::IsValid(usage)) { |
| 12944 return *isolate->factory()->NewNumberFromInt(usage); | 12946 return *isolate->factory()->NewNumberFromInt(usage); |
| 12945 } | 12947 } |
| (...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13636 | 13638 |
| 13637 void Runtime::PerformGC(Object* result) { | 13639 void Runtime::PerformGC(Object* result) { |
| 13638 Isolate* isolate = Isolate::Current(); | 13640 Isolate* isolate = Isolate::Current(); |
| 13639 Failure* failure = Failure::cast(result); | 13641 Failure* failure = Failure::cast(result); |
| 13640 if (failure->IsRetryAfterGC()) { | 13642 if (failure->IsRetryAfterGC()) { |
| 13641 if (isolate->heap()->new_space()->AddFreshPage()) { | 13643 if (isolate->heap()->new_space()->AddFreshPage()) { |
| 13642 return; | 13644 return; |
| 13643 } | 13645 } |
| 13644 // Try to do a garbage collection; ignore it if it fails. The C | 13646 // Try to do a garbage collection; ignore it if it fails. The C |
| 13645 // entry stub will throw an out-of-memory exception in that case. | 13647 // entry stub will throw an out-of-memory exception in that case. |
| 13646 isolate->heap()->CollectGarbage(failure->allocation_space()); | 13648 isolate->heap()->CollectGarbage(failure->allocation_space(), |
| 13649 "Runtime::PerformGC"); |
| 13647 } else { | 13650 } else { |
| 13648 // Handle last resort GC and make sure to allow future allocations | 13651 // Handle last resort GC and make sure to allow future allocations |
| 13649 // to grow the heap without causing GCs (if possible). | 13652 // to grow the heap without causing GCs (if possible). |
| 13650 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13653 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13651 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 13654 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13655 "Runtime::PerformGC"); |
| 13652 } | 13656 } |
| 13653 } | 13657 } |
| 13654 | 13658 |
| 13655 | 13659 |
| 13656 } } // namespace v8::internal | 13660 } } // namespace v8::internal |
| OLD | NEW |