| 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 12428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12439 | 12439 |
| 12440 | 12440 |
| 12441 // Get the constructor function for context extension and arguments array. | 12441 // Get the constructor function for context extension and arguments array. |
| 12442 JSObject* arguments_boilerplate = | 12442 JSObject* arguments_boilerplate = |
| 12443 isolate->context()->native_context()->arguments_boilerplate(); | 12443 isolate->context()->native_context()->arguments_boilerplate(); |
| 12444 JSFunction* arguments_function = | 12444 JSFunction* arguments_function = |
| 12445 JSFunction::cast(arguments_boilerplate->map()->constructor()); | 12445 JSFunction::cast(arguments_boilerplate->map()->constructor()); |
| 12446 | 12446 |
| 12447 // Get the number of referencing objects. | 12447 // Get the number of referencing objects. |
| 12448 int count; | 12448 int count; |
| 12449 HeapIterator heap_iterator; | 12449 Heap* heap = isolate->heap(); |
| 12450 HeapIterator heap_iterator(heap); |
| 12450 count = DebugReferencedBy(&heap_iterator, | 12451 count = DebugReferencedBy(&heap_iterator, |
| 12451 target, instance_filter, max_references, | 12452 target, instance_filter, max_references, |
| 12452 NULL, 0, arguments_function); | 12453 NULL, 0, arguments_function); |
| 12453 | 12454 |
| 12454 // Allocate an array to hold the result. | 12455 // Allocate an array to hold the result. |
| 12455 Object* object; | 12456 Object* object; |
| 12456 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count); | 12457 { MaybeObject* maybe_object = heap->AllocateFixedArray(count); |
| 12457 if (!maybe_object->ToObject(&object)) return maybe_object; | 12458 if (!maybe_object->ToObject(&object)) return maybe_object; |
| 12458 } | 12459 } |
| 12459 FixedArray* instances = FixedArray::cast(object); | 12460 FixedArray* instances = FixedArray::cast(object); |
| 12460 | 12461 |
| 12461 // Fill the referencing objects. | 12462 // Fill the referencing objects. |
| 12462 // AllocateFixedArray above does not make the heap non-iterable. | 12463 // AllocateFixedArray above does not make the heap non-iterable. |
| 12463 ASSERT(HEAP->IsHeapIterable()); | 12464 ASSERT(heap->IsHeapIterable()); |
| 12464 HeapIterator heap_iterator2; | 12465 HeapIterator heap_iterator2(heap); |
| 12465 count = DebugReferencedBy(&heap_iterator2, | 12466 count = DebugReferencedBy(&heap_iterator2, |
| 12466 target, instance_filter, max_references, | 12467 target, instance_filter, max_references, |
| 12467 instances, count, arguments_function); | 12468 instances, count, arguments_function); |
| 12468 | 12469 |
| 12469 // Return result as JS array. | 12470 // Return result as JS array. |
| 12470 Object* result; | 12471 Object* result; |
| 12471 MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( | 12472 MaybeObject* maybe_result = heap->AllocateJSObject( |
| 12472 isolate->context()->native_context()->array_function()); | 12473 isolate->context()->native_context()->array_function()); |
| 12473 if (!maybe_result->ToObject(&result)) return maybe_result; | 12474 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 12474 return JSArray::cast(result)->SetContent(instances); | 12475 return JSArray::cast(result)->SetContent(instances); |
| 12475 } | 12476 } |
| 12476 | 12477 |
| 12477 | 12478 |
| 12478 // Helper function used by Runtime_DebugConstructedBy below. | 12479 // Helper function used by Runtime_DebugConstructedBy below. |
| 12479 static int DebugConstructedBy(HeapIterator* iterator, | 12480 static int DebugConstructedBy(HeapIterator* iterator, |
| 12480 JSFunction* constructor, | 12481 JSFunction* constructor, |
| 12481 int max_references, | 12482 int max_references, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 12507 } | 12508 } |
| 12508 | 12509 |
| 12509 | 12510 |
| 12510 // Scan the heap for objects constructed by a specific function. | 12511 // Scan the heap for objects constructed by a specific function. |
| 12511 // args[0]: the constructor to find instances of | 12512 // args[0]: the constructor to find instances of |
| 12512 // args[1]: the the maximum number of objects to return | 12513 // args[1]: the the maximum number of objects to return |
| 12513 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) { | 12514 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) { |
| 12514 ASSERT(args.length() == 2); | 12515 ASSERT(args.length() == 2); |
| 12515 | 12516 |
| 12516 // First perform a full GC in order to avoid dead objects. | 12517 // First perform a full GC in order to avoid dead objects. |
| 12517 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask, | 12518 Heap* heap = isolate->heap(); |
| 12518 "%DebugConstructedBy"); | 12519 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); |
| 12519 | 12520 |
| 12520 // Check parameters. | 12521 // Check parameters. |
| 12521 CONVERT_ARG_CHECKED(JSFunction, constructor, 0); | 12522 CONVERT_ARG_CHECKED(JSFunction, constructor, 0); |
| 12522 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); | 12523 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); |
| 12523 RUNTIME_ASSERT(max_references >= 0); | 12524 RUNTIME_ASSERT(max_references >= 0); |
| 12524 | 12525 |
| 12525 // Get the number of referencing objects. | 12526 // Get the number of referencing objects. |
| 12526 int count; | 12527 int count; |
| 12527 HeapIterator heap_iterator; | 12528 HeapIterator heap_iterator(heap); |
| 12528 count = DebugConstructedBy(&heap_iterator, | 12529 count = DebugConstructedBy(&heap_iterator, |
| 12529 constructor, | 12530 constructor, |
| 12530 max_references, | 12531 max_references, |
| 12531 NULL, | 12532 NULL, |
| 12532 0); | 12533 0); |
| 12533 | 12534 |
| 12534 // Allocate an array to hold the result. | 12535 // Allocate an array to hold the result. |
| 12535 Object* object; | 12536 Object* object; |
| 12536 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count); | 12537 { MaybeObject* maybe_object = heap->AllocateFixedArray(count); |
| 12537 if (!maybe_object->ToObject(&object)) return maybe_object; | 12538 if (!maybe_object->ToObject(&object)) return maybe_object; |
| 12538 } | 12539 } |
| 12539 FixedArray* instances = FixedArray::cast(object); | 12540 FixedArray* instances = FixedArray::cast(object); |
| 12540 | 12541 |
| 12541 ASSERT(HEAP->IsHeapIterable()); | 12542 ASSERT(HEAP->IsHeapIterable()); |
| 12542 // Fill the referencing objects. | 12543 // Fill the referencing objects. |
| 12543 HeapIterator heap_iterator2; | 12544 HeapIterator heap_iterator2(heap); |
| 12544 count = DebugConstructedBy(&heap_iterator2, | 12545 count = DebugConstructedBy(&heap_iterator2, |
| 12545 constructor, | 12546 constructor, |
| 12546 max_references, | 12547 max_references, |
| 12547 instances, | 12548 instances, |
| 12548 count); | 12549 count); |
| 12549 | 12550 |
| 12550 // Return result as JS array. | 12551 // Return result as JS array. |
| 12551 Object* result; | 12552 Object* result; |
| 12552 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( | 12553 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( |
| 12553 isolate->context()->native_context()->array_function()); | 12554 isolate->context()->native_context()->array_function()); |
| 12554 if (!maybe_result->ToObject(&result)) return maybe_result; | 12555 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 12555 } | 12556 } |
| 12556 return JSArray::cast(result)->SetContent(instances); | 12557 return JSArray::cast(result)->SetContent(instances); |
| 12557 } | 12558 } |
| 12558 | 12559 |
| 12559 | 12560 |
| 12560 // Find the effective prototype object as returned by __proto__. | 12561 // Find the effective prototype object as returned by __proto__. |
| 12561 // args[0]: the object to find the prototype for. | 12562 // args[0]: the object to find the prototype for. |
| 12562 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) { | 12563 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugGetPrototype) { |
| 12563 ASSERT(args.length() == 1); | 12564 ASSERT(args.length() == 1); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12670 CONVERT_ARG_CHECKED(JSValue, script_value, 0); | 12671 CONVERT_ARG_CHECKED(JSValue, script_value, 0); |
| 12671 | 12672 |
| 12672 RUNTIME_ASSERT(script_value->value()->IsScript()); | 12673 RUNTIME_ASSERT(script_value->value()->IsScript()); |
| 12673 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); | 12674 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); |
| 12674 | 12675 |
| 12675 const int kBufferSize = 32; | 12676 const int kBufferSize = 32; |
| 12676 | 12677 |
| 12677 Handle<FixedArray> array; | 12678 Handle<FixedArray> array; |
| 12678 array = isolate->factory()->NewFixedArray(kBufferSize); | 12679 array = isolate->factory()->NewFixedArray(kBufferSize); |
| 12679 int number; | 12680 int number; |
| 12681 Heap* heap = isolate->heap(); |
| 12680 { | 12682 { |
| 12681 isolate->heap()->EnsureHeapIsIterable(); | 12683 heap->EnsureHeapIsIterable(); |
| 12682 AssertNoAllocation no_allocations; | 12684 AssertNoAllocation no_allocations; |
| 12683 HeapIterator heap_iterator; | 12685 HeapIterator heap_iterator(heap); |
| 12684 Script* scr = *script; | 12686 Script* scr = *script; |
| 12685 FixedArray* arr = *array; | 12687 FixedArray* arr = *array; |
| 12686 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); | 12688 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); |
| 12687 } | 12689 } |
| 12688 if (number > kBufferSize) { | 12690 if (number > kBufferSize) { |
| 12689 array = isolate->factory()->NewFixedArray(number); | 12691 array = isolate->factory()->NewFixedArray(number); |
| 12690 isolate->heap()->EnsureHeapIsIterable(); | 12692 heap->EnsureHeapIsIterable(); |
| 12691 AssertNoAllocation no_allocations; | 12693 AssertNoAllocation no_allocations; |
| 12692 HeapIterator heap_iterator; | 12694 HeapIterator heap_iterator(heap); |
| 12693 Script* scr = *script; | 12695 Script* scr = *script; |
| 12694 FixedArray* arr = *array; | 12696 FixedArray* arr = *array; |
| 12695 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); | 12697 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); |
| 12696 } | 12698 } |
| 12697 | 12699 |
| 12698 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); | 12700 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); |
| 12699 result->set_length(Smi::FromInt(number)); | 12701 result->set_length(Smi::FromInt(number)); |
| 12700 | 12702 |
| 12701 LiveEdit::WrapSharedFunctionInfos(result); | 12703 LiveEdit::WrapSharedFunctionInfos(result); |
| 12702 | 12704 |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13019 // heap traversal to find the function generated for the source position | 13021 // heap traversal to find the function generated for the source position |
| 13020 // for the requested break point. For lazily compiled functions several heap | 13022 // for the requested break point. For lazily compiled functions several heap |
| 13021 // traversals might be required rendering this operation as a rather slow | 13023 // traversals might be required rendering this operation as a rather slow |
| 13022 // operation. However for setting break points which is normally done through | 13024 // operation. However for setting break points which is normally done through |
| 13023 // some kind of user interaction the performance is not crucial. | 13025 // some kind of user interaction the performance is not crucial. |
| 13024 static Handle<Object> Runtime_GetScriptFromScriptName( | 13026 static Handle<Object> Runtime_GetScriptFromScriptName( |
| 13025 Handle<String> script_name) { | 13027 Handle<String> script_name) { |
| 13026 // Scan the heap for Script objects to find the script with the requested | 13028 // Scan the heap for Script objects to find the script with the requested |
| 13027 // script data. | 13029 // script data. |
| 13028 Handle<Script> script; | 13030 Handle<Script> script; |
| 13029 script_name->GetHeap()->EnsureHeapIsIterable(); | 13031 Heap* heap = script_name->GetHeap(); |
| 13032 heap->EnsureHeapIsIterable(); |
| 13030 AssertNoAllocation no_allocation_during_heap_iteration; | 13033 AssertNoAllocation no_allocation_during_heap_iteration; |
| 13031 HeapIterator iterator; | 13034 HeapIterator iterator(heap); |
| 13032 HeapObject* obj = NULL; | 13035 HeapObject* obj = NULL; |
| 13033 while (script.is_null() && ((obj = iterator.next()) != NULL)) { | 13036 while (script.is_null() && ((obj = iterator.next()) != NULL)) { |
| 13034 // If a script is found check if it has the script data requested. | 13037 // If a script is found check if it has the script data requested. |
| 13035 if (obj->IsScript()) { | 13038 if (obj->IsScript()) { |
| 13036 if (Script::cast(obj)->name()->IsString()) { | 13039 if (Script::cast(obj)->name()->IsString()) { |
| 13037 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { | 13040 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { |
| 13038 script = Handle<Script>(Script::cast(obj)); | 13041 script = Handle<Script>(Script::cast(obj)); |
| 13039 } | 13042 } |
| 13040 } | 13043 } |
| 13041 } | 13044 } |
| (...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13528 // Handle last resort GC and make sure to allow future allocations | 13531 // Handle last resort GC and make sure to allow future allocations |
| 13529 // to grow the heap without causing GCs (if possible). | 13532 // to grow the heap without causing GCs (if possible). |
| 13530 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13533 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13531 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13534 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13532 "Runtime::PerformGC"); | 13535 "Runtime::PerformGC"); |
| 13533 } | 13536 } |
| 13534 } | 13537 } |
| 13535 | 13538 |
| 13536 | 13539 |
| 13537 } } // namespace v8::internal | 13540 } } // namespace v8::internal |
| OLD | NEW |