OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 9945 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9956 // which is found is not compiled it is compiled and the heap is iterated | 9956 // which is found is not compiled it is compiled and the heap is iterated |
9957 // again as the compilation might create inner functions from the newly | 9957 // again as the compilation might create inner functions from the newly |
9958 // compiled function and the actual requested break point might be in one of | 9958 // compiled function and the actual requested break point might be in one of |
9959 // these functions. | 9959 // these functions. |
9960 bool done = false; | 9960 bool done = false; |
9961 // The current candidate for the source position: | 9961 // The current candidate for the source position: |
9962 int target_start_position = RelocInfo::kNoPosition; | 9962 int target_start_position = RelocInfo::kNoPosition; |
9963 Handle<SharedFunctionInfo> target; | 9963 Handle<SharedFunctionInfo> target; |
9964 while (!done) { | 9964 while (!done) { |
9965 HeapIterator iterator; | 9965 HeapIterator iterator; |
9966 for (HeapObject* obj = iterator.next(); | 9966 for (HeapObject* obj = iterator.Next(); |
9967 obj != NULL; obj = iterator.next()) { | 9967 obj != NULL; obj = iterator.Next()) { |
9968 if (obj->IsSharedFunctionInfo()) { | 9968 if (obj->IsSharedFunctionInfo()) { |
9969 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(obj)); | 9969 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(obj)); |
9970 if (shared->script() == *script) { | 9970 if (shared->script() == *script) { |
9971 // If the SharedFunctionInfo found has the requested script data and | 9971 // If the SharedFunctionInfo found has the requested script data and |
9972 // contains the source position it is a candidate. | 9972 // contains the source position it is a candidate. |
9973 int start_position = shared->function_token_position(); | 9973 int start_position = shared->function_token_position(); |
9974 if (start_position == RelocInfo::kNoPosition) { | 9974 if (start_position == RelocInfo::kNoPosition) { |
9975 start_position = shared->start_position(); | 9975 start_position = shared->start_position(); |
9976 } | 9976 } |
9977 if (start_position <= position && | 9977 if (start_position <= position && |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10446 return *result; | 10446 return *result; |
10447 } | 10447 } |
10448 | 10448 |
10449 | 10449 |
10450 // Helper function used by Runtime_DebugReferencedBy below. | 10450 // Helper function used by Runtime_DebugReferencedBy below. |
10451 static int DebugReferencedBy(JSObject* target, | 10451 static int DebugReferencedBy(JSObject* target, |
10452 Object* instance_filter, int max_references, | 10452 Object* instance_filter, int max_references, |
10453 FixedArray* instances, int instances_size, | 10453 FixedArray* instances, int instances_size, |
10454 JSFunction* arguments_function) { | 10454 JSFunction* arguments_function) { |
10455 NoHandleAllocation ha; | 10455 NoHandleAllocation ha; |
| 10456 HeapIterator iterator; |
10456 AssertNoAllocation no_alloc; | 10457 AssertNoAllocation no_alloc; |
10457 | 10458 |
10458 // Iterate the heap. | 10459 // Iterate the heap. |
10459 int count = 0; | 10460 int count = 0; |
10460 JSObject* last = NULL; | 10461 JSObject* last = NULL; |
10461 HeapIterator iterator; | |
10462 HeapObject* heap_obj = NULL; | 10462 HeapObject* heap_obj = NULL; |
10463 while (((heap_obj = iterator.next()) != NULL) && | 10463 while (((heap_obj = iterator.Next()) != NULL) && |
10464 (max_references == 0 || count < max_references)) { | 10464 (max_references == 0 || count < max_references)) { |
10465 // Only look at all JSObjects. | 10465 // Only look at all JSObjects. |
10466 if (heap_obj->IsJSObject()) { | 10466 if (heap_obj->IsJSObject()) { |
10467 // Skip context extension objects and argument arrays as these are | 10467 // Skip context extension objects and argument arrays as these are |
10468 // checked in the context of functions using them. | 10468 // checked in the context of functions using them. |
10469 JSObject* obj = JSObject::cast(heap_obj); | 10469 JSObject* obj = JSObject::cast(heap_obj); |
10470 if (obj->IsJSContextExtensionObject() || | 10470 if (obj->IsJSContextExtensionObject() || |
10471 obj->map()->constructor() == arguments_function) { | 10471 obj->map()->constructor() == arguments_function) { |
10472 continue; | 10472 continue; |
10473 } | 10473 } |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10518 | 10518 |
10519 | 10519 |
10520 // Scan the heap for objects with direct references to an object | 10520 // Scan the heap for objects with direct references to an object |
10521 // args[0]: the object to find references to | 10521 // args[0]: the object to find references to |
10522 // args[1]: constructor function for instances to exclude (Mirror) | 10522 // args[1]: constructor function for instances to exclude (Mirror) |
10523 // args[2]: the the maximum number of objects to return | 10523 // args[2]: the the maximum number of objects to return |
10524 static MaybeObject* Runtime_DebugReferencedBy(Arguments args) { | 10524 static MaybeObject* Runtime_DebugReferencedBy(Arguments args) { |
10525 ASSERT(args.length() == 3); | 10525 ASSERT(args.length() == 3); |
10526 | 10526 |
10527 // First perform a full GC in order to avoid references from dead objects. | 10527 // First perform a full GC in order to avoid references from dead objects. |
10528 Heap::CollectAllGarbage(false); | 10528 Heap::CollectAllGarbage(Heap::kMakeHeapIterableMask); |
10529 | 10529 |
10530 // Check parameters. | 10530 // Check parameters. |
10531 CONVERT_CHECKED(JSObject, target, args[0]); | 10531 CONVERT_CHECKED(JSObject, target, args[0]); |
10532 Object* instance_filter = args[1]; | 10532 Object* instance_filter = args[1]; |
10533 RUNTIME_ASSERT(instance_filter->IsUndefined() || | 10533 RUNTIME_ASSERT(instance_filter->IsUndefined() || |
10534 instance_filter->IsJSObject()); | 10534 instance_filter->IsJSObject()); |
10535 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); | 10535 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); |
10536 RUNTIME_ASSERT(max_references >= 0); | 10536 RUNTIME_ASSERT(max_references >= 0); |
10537 | 10537 |
10538 // Get the constructor function for context extension and arguments array. | 10538 // Get the constructor function for context extension and arguments array. |
(...skipping 25 matching lines...) Expand all Loading... |
10564 if (!maybe_result->ToObject(&result)) return maybe_result; | 10564 if (!maybe_result->ToObject(&result)) return maybe_result; |
10565 } | 10565 } |
10566 JSArray::cast(result)->SetContent(instances); | 10566 JSArray::cast(result)->SetContent(instances); |
10567 return result; | 10567 return result; |
10568 } | 10568 } |
10569 | 10569 |
10570 | 10570 |
10571 // Helper function used by Runtime_DebugConstructedBy below. | 10571 // Helper function used by Runtime_DebugConstructedBy below. |
10572 static int DebugConstructedBy(JSFunction* constructor, int max_references, | 10572 static int DebugConstructedBy(JSFunction* constructor, int max_references, |
10573 FixedArray* instances, int instances_size) { | 10573 FixedArray* instances, int instances_size) { |
| 10574 HeapIterator iterator; |
10574 AssertNoAllocation no_alloc; | 10575 AssertNoAllocation no_alloc; |
10575 | 10576 |
10576 // Iterate the heap. | 10577 // Iterate the heap. |
10577 int count = 0; | 10578 int count = 0; |
10578 HeapIterator iterator; | |
10579 HeapObject* heap_obj = NULL; | 10579 HeapObject* heap_obj = NULL; |
10580 while (((heap_obj = iterator.next()) != NULL) && | 10580 while (((heap_obj = iterator.Next()) != NULL) && |
10581 (max_references == 0 || count < max_references)) { | 10581 (max_references == 0 || count < max_references)) { |
10582 // Only look at all JSObjects. | 10582 // Only look at all JSObjects. |
10583 if (heap_obj->IsJSObject()) { | 10583 if (heap_obj->IsJSObject()) { |
10584 JSObject* obj = JSObject::cast(heap_obj); | 10584 JSObject* obj = JSObject::cast(heap_obj); |
10585 if (obj->map()->constructor() == constructor) { | 10585 if (obj->map()->constructor() == constructor) { |
10586 // Valid reference found add to instance array if supplied an update | 10586 // Valid reference found add to instance array if supplied an update |
10587 // count. | 10587 // count. |
10588 if (instances != NULL && count < instances_size) { | 10588 if (instances != NULL && count < instances_size) { |
10589 instances->set(count, obj); | 10589 instances->set(count, obj); |
10590 } | 10590 } |
10591 count++; | 10591 count++; |
10592 } | 10592 } |
10593 } | 10593 } |
10594 } | 10594 } |
10595 | 10595 |
10596 // Return the number of referencing objects found. | 10596 // Return the number of referencing objects found. |
10597 return count; | 10597 return count; |
10598 } | 10598 } |
10599 | 10599 |
10600 | 10600 |
10601 // Scan the heap for objects constructed by a specific function. | 10601 // Scan the heap for objects constructed by a specific function. |
10602 // args[0]: the constructor to find instances of | 10602 // args[0]: the constructor to find instances of |
10603 // args[1]: the the maximum number of objects to return | 10603 // args[1]: the the maximum number of objects to return |
10604 static MaybeObject* Runtime_DebugConstructedBy(Arguments args) { | 10604 static MaybeObject* Runtime_DebugConstructedBy(Arguments args) { |
10605 ASSERT(args.length() == 2); | 10605 ASSERT(args.length() == 2); |
10606 | 10606 |
10607 // First perform a full GC in order to avoid dead objects. | 10607 // First perform a full GC in order to avoid dead objects. |
10608 Heap::CollectAllGarbage(false); | 10608 Heap::CollectAllGarbage(Heap::kMakeHeapIterableMask); |
10609 | 10609 |
10610 // Check parameters. | 10610 // Check parameters. |
10611 CONVERT_CHECKED(JSFunction, constructor, args[0]); | 10611 CONVERT_CHECKED(JSFunction, constructor, args[0]); |
10612 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); | 10612 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); |
10613 RUNTIME_ASSERT(max_references >= 0); | 10613 RUNTIME_ASSERT(max_references >= 0); |
10614 | 10614 |
10615 // Get the number of referencing objects. | 10615 // Get the number of referencing objects. |
10616 int count; | 10616 int count; |
10617 count = DebugConstructedBy(constructor, max_references, NULL, 0); | 10617 count = DebugConstructedBy(constructor, max_references, NULL, 0); |
10618 | 10618 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10691 static MaybeObject* Runtime_FunctionGetInferredName(Arguments args) { | 10691 static MaybeObject* Runtime_FunctionGetInferredName(Arguments args) { |
10692 NoHandleAllocation ha; | 10692 NoHandleAllocation ha; |
10693 ASSERT(args.length() == 1); | 10693 ASSERT(args.length() == 1); |
10694 | 10694 |
10695 CONVERT_CHECKED(JSFunction, f, args[0]); | 10695 CONVERT_CHECKED(JSFunction, f, args[0]); |
10696 return f->shared()->inferred_name(); | 10696 return f->shared()->inferred_name(); |
10697 } | 10697 } |
10698 | 10698 |
10699 | 10699 |
10700 static int FindSharedFunctionInfosForScript(Script* script, | 10700 static int FindSharedFunctionInfosForScript(Script* script, |
10701 FixedArray* buffer) { | 10701 FixedArray* buffer) { |
| 10702 HeapIterator iterator; |
10702 AssertNoAllocation no_allocations; | 10703 AssertNoAllocation no_allocations; |
10703 | 10704 |
10704 int counter = 0; | 10705 int counter = 0; |
10705 int buffer_size = buffer->length(); | 10706 int buffer_size = buffer->length(); |
10706 HeapIterator iterator; | 10707 for (HeapObject* obj = iterator.Next(); obj != NULL; obj = iterator.Next()) { |
10707 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | |
10708 ASSERT(obj != NULL); | 10708 ASSERT(obj != NULL); |
10709 if (!obj->IsSharedFunctionInfo()) { | 10709 if (!obj->IsSharedFunctionInfo()) { |
10710 continue; | 10710 continue; |
10711 } | 10711 } |
10712 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); | 10712 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); |
10713 if (shared->script() != script) { | 10713 if (shared->script() != script) { |
10714 continue; | 10714 continue; |
10715 } | 10715 } |
10716 if (counter < buffer_size) { | 10716 if (counter < buffer_size) { |
10717 buffer->set(counter, shared); | 10717 buffer->set(counter, shared); |
10718 } | 10718 } |
10719 counter++; | 10719 counter++; |
10720 } | 10720 } |
10721 return counter; | 10721 return counter; |
10722 } | 10722 } |
10723 | 10723 |
10724 // For a script finds all SharedFunctionInfo's in the heap that points | 10724 // For a script finds all SharedFunctionInfo's in the heap that points |
10725 // to this script. Returns JSArray of SharedFunctionInfo wrapped | 10725 // to this script. Returns JSArray of SharedFunctionInfo wrapped |
10726 // in OpaqueReferences. | 10726 // in OpaqueReferences. |
10727 static MaybeObject* Runtime_LiveEditFindSharedFunctionInfosForScript( | 10727 static MaybeObject* Runtime_LiveEditFindSharedFunctionInfosForScript( |
10728 Arguments args) { | 10728 Arguments args) { |
10729 ASSERT(args.length() == 1); | 10729 ASSERT(args.length() == 1); |
10730 HandleScope scope; | 10730 HandleScope scope; |
10731 CONVERT_CHECKED(JSValue, script_value, args[0]); | 10731 CONVERT_CHECKED(JSValue, script_value, args[0]); |
10732 | 10732 |
| 10733 |
10733 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); | 10734 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); |
10734 | 10735 |
10735 const int kBufferSize = 32; | 10736 const int kBufferSize = 32; |
10736 | 10737 |
10737 Handle<FixedArray> array; | 10738 Handle<FixedArray> array; |
10738 array = Factory::NewFixedArray(kBufferSize); | 10739 array = Factory::NewFixedArray(kBufferSize); |
10739 int number = FindSharedFunctionInfosForScript(*script, *array); | 10740 int number = FindSharedFunctionInfosForScript(*script, *array); |
10740 if (number > kBufferSize) { | 10741 if (number > kBufferSize) { |
10741 array = Factory::NewFixedArray(number); | 10742 array = Factory::NewFixedArray(number); |
10742 FindSharedFunctionInfosForScript(*script, *array); | 10743 FindSharedFunctionInfosForScript(*script, *array); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10972 SmartPointer<char> flags = | 10973 SmartPointer<char> flags = |
10973 arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); | 10974 arg->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL); |
10974 FlagList::SetFlagsFromString(*flags, StrLength(*flags)); | 10975 FlagList::SetFlagsFromString(*flags, StrLength(*flags)); |
10975 return Heap::undefined_value(); | 10976 return Heap::undefined_value(); |
10976 } | 10977 } |
10977 | 10978 |
10978 | 10979 |
10979 // Performs a GC. | 10980 // Performs a GC. |
10980 // Presently, it only does a full GC. | 10981 // Presently, it only does a full GC. |
10981 static MaybeObject* Runtime_CollectGarbage(Arguments args) { | 10982 static MaybeObject* Runtime_CollectGarbage(Arguments args) { |
10982 Heap::CollectAllGarbage(true); | 10983 Heap::CollectAllGarbage(Heap::kForceCompactionMask); |
10983 return Heap::undefined_value(); | 10984 return Heap::undefined_value(); |
10984 } | 10985 } |
10985 | 10986 |
10986 | 10987 |
10987 // Gets the current heap usage. | 10988 // Gets the current heap usage. |
10988 static MaybeObject* Runtime_GetHeapUsage(Arguments args) { | 10989 static MaybeObject* Runtime_GetHeapUsage(Arguments args) { |
10989 int usage = static_cast<int>(Heap::SizeOfObjects()); | 10990 int usage = static_cast<int>(Heap::SizeOfObjects()); |
10990 if (!Smi::IsValid(usage)) { | 10991 if (!Smi::IsValid(usage)) { |
10991 return *Factory::NewNumberFromInt(usage); | 10992 return *Factory::NewNumberFromInt(usage); |
10992 } | 10993 } |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11226 // traversals might be required rendering this operation as a rather slow | 11227 // traversals might be required rendering this operation as a rather slow |
11227 // operation. However for setting break points which is normally done through | 11228 // operation. However for setting break points which is normally done through |
11228 // some kind of user interaction the performance is not crucial. | 11229 // some kind of user interaction the performance is not crucial. |
11229 static Handle<Object> Runtime_GetScriptFromScriptName( | 11230 static Handle<Object> Runtime_GetScriptFromScriptName( |
11230 Handle<String> script_name) { | 11231 Handle<String> script_name) { |
11231 // Scan the heap for Script objects to find the script with the requested | 11232 // Scan the heap for Script objects to find the script with the requested |
11232 // script data. | 11233 // script data. |
11233 Handle<Script> script; | 11234 Handle<Script> script; |
11234 HeapIterator iterator; | 11235 HeapIterator iterator; |
11235 HeapObject* obj = NULL; | 11236 HeapObject* obj = NULL; |
11236 while (script.is_null() && ((obj = iterator.next()) != NULL)) { | 11237 while (script.is_null() && ((obj = iterator.Next()) != NULL)) { |
11237 // If a script is found check if it has the script data requested. | 11238 // If a script is found check if it has the script data requested. |
11238 if (obj->IsScript()) { | 11239 if (obj->IsScript()) { |
11239 if (Script::cast(obj)->name()->IsString()) { | 11240 if (Script::cast(obj)->name()->IsString()) { |
11240 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { | 11241 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { |
11241 script = Handle<Script>(Script::cast(obj)); | 11242 script = Handle<Script>(Script::cast(obj)); |
11242 } | 11243 } |
11243 } | 11244 } |
11244 } | 11245 } |
11245 } | 11246 } |
11246 | 11247 |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11633 void Runtime::PerformGC(Object* result) { | 11634 void Runtime::PerformGC(Object* result) { |
11634 Failure* failure = Failure::cast(result); | 11635 Failure* failure = Failure::cast(result); |
11635 if (failure->IsRetryAfterGC()) { | 11636 if (failure->IsRetryAfterGC()) { |
11636 // Try to do a garbage collection; ignore it if it fails. The C | 11637 // Try to do a garbage collection; ignore it if it fails. The C |
11637 // entry stub will throw an out-of-memory exception in that case. | 11638 // entry stub will throw an out-of-memory exception in that case. |
11638 Heap::CollectGarbage(failure->allocation_space()); | 11639 Heap::CollectGarbage(failure->allocation_space()); |
11639 } else { | 11640 } else { |
11640 // Handle last resort GC and make sure to allow future allocations | 11641 // Handle last resort GC and make sure to allow future allocations |
11641 // to grow the heap without causing GCs (if possible). | 11642 // to grow the heap without causing GCs (if possible). |
11642 Counters::gc_last_resort_from_js.Increment(); | 11643 Counters::gc_last_resort_from_js.Increment(); |
11643 Heap::CollectAllGarbage(false); | 11644 Heap::CollectAllGarbage(Heap::kNoGCFlags); |
11644 } | 11645 } |
11645 } | 11646 } |
11646 | 11647 |
11647 | 11648 |
11648 } } // namespace v8::internal | 11649 } } // namespace v8::internal |
OLD | NEW |