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