| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 #include "v8.h" | 8 #include "v8.h" |
| 9 | 9 |
| 10 #include "accessors.h" | 10 #include "accessors.h" |
| (...skipping 13097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13108 | 13108 |
| 13109 | 13109 |
| 13110 // Scan the heap for objects with direct references to an object | 13110 // Scan the heap for objects with direct references to an object |
| 13111 // args[0]: the object to find references to | 13111 // args[0]: the object to find references to |
| 13112 // args[1]: constructor function for instances to exclude (Mirror) | 13112 // args[1]: constructor function for instances to exclude (Mirror) |
| 13113 // args[2]: the the maximum number of objects to return | 13113 // args[2]: the the maximum number of objects to return |
| 13114 RUNTIME_FUNCTION(Runtime_DebugReferencedBy) { | 13114 RUNTIME_FUNCTION(Runtime_DebugReferencedBy) { |
| 13115 HandleScope scope(isolate); | 13115 HandleScope scope(isolate); |
| 13116 ASSERT(args.length() == 3); | 13116 ASSERT(args.length() == 3); |
| 13117 | 13117 |
| 13118 // First perform a full GC in order to avoid references from dead objects. | |
| 13119 Heap* heap = isolate->heap(); | |
| 13120 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugReferencedBy"); | |
| 13121 // The heap iterator reserves the right to do a GC to make the heap iterable. | |
| 13122 // Due to the GC above we know it won't need to do that, but it seems cleaner | |
| 13123 // to get the heap iterator constructed before we start having unprotected | |
| 13124 // Object* locals that are not protected by handles. | |
| 13125 | |
| 13126 // Check parameters. | 13118 // Check parameters. |
| 13127 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); | 13119 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); |
| 13128 CONVERT_ARG_HANDLE_CHECKED(Object, instance_filter, 1); | 13120 CONVERT_ARG_HANDLE_CHECKED(Object, instance_filter, 1); |
| 13129 RUNTIME_ASSERT(instance_filter->IsUndefined() || | 13121 RUNTIME_ASSERT(instance_filter->IsUndefined() || |
| 13130 instance_filter->IsJSObject()); | 13122 instance_filter->IsJSObject()); |
| 13131 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); | 13123 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); |
| 13132 RUNTIME_ASSERT(max_references >= 0); | 13124 RUNTIME_ASSERT(max_references >= 0); |
| 13133 | 13125 |
| 13134 | 13126 |
| 13135 // Get the constructor function for context extension and arguments array. | 13127 // Get the constructor function for context extension and arguments array. |
| 13136 Handle<JSObject> arguments_boilerplate( | 13128 Handle<JSObject> arguments_boilerplate( |
| 13137 isolate->context()->native_context()->sloppy_arguments_boilerplate()); | 13129 isolate->context()->native_context()->sloppy_arguments_boilerplate()); |
| 13138 Handle<JSFunction> arguments_function( | 13130 Handle<JSFunction> arguments_function( |
| 13139 JSFunction::cast(arguments_boilerplate->map()->constructor())); | 13131 JSFunction::cast(arguments_boilerplate->map()->constructor())); |
| 13140 | 13132 |
| 13141 // Get the number of referencing objects. | 13133 // Get the number of referencing objects. |
| 13142 int count; | 13134 int count; |
| 13143 HeapIterator heap_iterator(heap); | 13135 // First perform a full GC in order to avoid dead objects and to make the heap |
| 13144 count = DebugReferencedBy(&heap_iterator, | 13136 // iterable. |
| 13145 *target, *instance_filter, max_references, | 13137 Heap* heap = isolate->heap(); |
| 13146 NULL, 0, *arguments_function); | 13138 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); |
| 13139 { |
| 13140 HeapIterator heap_iterator(heap); |
| 13141 count = DebugReferencedBy(&heap_iterator, |
| 13142 *target, *instance_filter, max_references, |
| 13143 NULL, 0, *arguments_function); |
| 13144 } |
| 13147 | 13145 |
| 13148 // Allocate an array to hold the result. | 13146 // Allocate an array to hold the result. |
| 13149 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); | 13147 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); |
| 13150 | 13148 |
| 13151 // Fill the referencing objects. | 13149 // Fill the referencing objects. |
| 13152 // AllocateFixedArray above does not make the heap non-iterable. | 13150 { |
| 13153 ASSERT(heap->IsHeapIterable()); | 13151 HeapIterator heap_iterator(heap); |
| 13154 HeapIterator heap_iterator2(heap); | 13152 count = DebugReferencedBy(&heap_iterator, |
| 13155 count = DebugReferencedBy(&heap_iterator2, | 13153 *target, *instance_filter, max_references, |
| 13156 *target, *instance_filter, max_references, | 13154 *instances, count, *arguments_function); |
| 13157 *instances, count, *arguments_function); | 13155 } |
| 13158 | 13156 |
| 13159 // Return result as JS array. | 13157 // Return result as JS array. |
| 13160 Handle<JSFunction> constructor( | 13158 Handle<JSFunction> constructor( |
| 13161 isolate->context()->native_context()->array_function()); | 13159 isolate->context()->native_context()->array_function()); |
| 13162 | 13160 |
| 13163 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); | 13161 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); |
| 13164 JSArray::SetContent(Handle<JSArray>::cast(result), instances); | 13162 JSArray::SetContent(Handle<JSArray>::cast(result), instances); |
| 13165 return *result; | 13163 return *result; |
| 13166 } | 13164 } |
| 13167 | 13165 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 13198 } | 13196 } |
| 13199 | 13197 |
| 13200 | 13198 |
| 13201 // Scan the heap for objects constructed by a specific function. | 13199 // Scan the heap for objects constructed by a specific function. |
| 13202 // args[0]: the constructor to find instances of | 13200 // args[0]: the constructor to find instances of |
| 13203 // args[1]: the the maximum number of objects to return | 13201 // args[1]: the the maximum number of objects to return |
| 13204 RUNTIME_FUNCTION(Runtime_DebugConstructedBy) { | 13202 RUNTIME_FUNCTION(Runtime_DebugConstructedBy) { |
| 13205 HandleScope scope(isolate); | 13203 HandleScope scope(isolate); |
| 13206 ASSERT(args.length() == 2); | 13204 ASSERT(args.length() == 2); |
| 13207 | 13205 |
| 13208 // First perform a full GC in order to avoid dead objects. | |
| 13209 Heap* heap = isolate->heap(); | |
| 13210 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); | |
| 13211 | 13206 |
| 13212 // Check parameters. | 13207 // Check parameters. |
| 13213 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); | 13208 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); |
| 13214 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); | 13209 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); |
| 13215 RUNTIME_ASSERT(max_references >= 0); | 13210 RUNTIME_ASSERT(max_references >= 0); |
| 13216 | 13211 |
| 13217 // Get the number of referencing objects. | 13212 // Get the number of referencing objects. |
| 13218 int count; | 13213 int count; |
| 13219 HeapIterator heap_iterator(heap); | 13214 // First perform a full GC in order to avoid dead objects and to make the heap |
| 13220 count = DebugConstructedBy(&heap_iterator, | 13215 // iterable. |
| 13221 *constructor, | 13216 Heap* heap = isolate->heap(); |
| 13222 max_references, | 13217 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); |
| 13223 NULL, | 13218 { |
| 13224 0); | 13219 HeapIterator heap_iterator(heap); |
| 13220 count = DebugConstructedBy(&heap_iterator, |
| 13221 *constructor, |
| 13222 max_references, |
| 13223 NULL, |
| 13224 0); |
| 13225 } |
| 13225 | 13226 |
| 13226 // Allocate an array to hold the result. | 13227 // Allocate an array to hold the result. |
| 13227 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); | 13228 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); |
| 13228 | 13229 |
| 13229 ASSERT(heap->IsHeapIterable()); | |
| 13230 // Fill the referencing objects. | 13230 // Fill the referencing objects. |
| 13231 HeapIterator heap_iterator2(heap); | 13231 { |
| 13232 count = DebugConstructedBy(&heap_iterator2, | 13232 HeapIterator heap_iterator2(heap); |
| 13233 *constructor, | 13233 count = DebugConstructedBy(&heap_iterator2, |
| 13234 max_references, | 13234 *constructor, |
| 13235 *instances, | 13235 max_references, |
| 13236 count); | 13236 *instances, |
| 13237 count); |
| 13238 } |
| 13237 | 13239 |
| 13238 // Return result as JS array. | 13240 // Return result as JS array. |
| 13239 Handle<JSFunction> array_function( | 13241 Handle<JSFunction> array_function( |
| 13240 isolate->context()->native_context()->array_function()); | 13242 isolate->context()->native_context()->array_function()); |
| 13241 Handle<JSObject> result = isolate->factory()->NewJSObject(array_function); | 13243 Handle<JSObject> result = isolate->factory()->NewJSObject(array_function); |
| 13242 JSArray::SetContent(Handle<JSArray>::cast(result), instances); | 13244 JSArray::SetContent(Handle<JSArray>::cast(result), instances); |
| 13243 return *result; | 13245 return *result; |
| 13244 } | 13246 } |
| 13245 | 13247 |
| 13246 | 13248 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13358 RUNTIME_ASSERT(script_value->value()->IsScript()); | 13360 RUNTIME_ASSERT(script_value->value()->IsScript()); |
| 13359 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); | 13361 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); |
| 13360 | 13362 |
| 13361 const int kBufferSize = 32; | 13363 const int kBufferSize = 32; |
| 13362 | 13364 |
| 13363 Handle<FixedArray> array; | 13365 Handle<FixedArray> array; |
| 13364 array = isolate->factory()->NewFixedArray(kBufferSize); | 13366 array = isolate->factory()->NewFixedArray(kBufferSize); |
| 13365 int number; | 13367 int number; |
| 13366 Heap* heap = isolate->heap(); | 13368 Heap* heap = isolate->heap(); |
| 13367 { | 13369 { |
| 13368 heap->EnsureHeapIsIterable(); | |
| 13369 DisallowHeapAllocation no_allocation; | |
| 13370 HeapIterator heap_iterator(heap); | 13370 HeapIterator heap_iterator(heap); |
| 13371 Script* scr = *script; | 13371 Script* scr = *script; |
| 13372 FixedArray* arr = *array; | 13372 FixedArray* arr = *array; |
| 13373 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); | 13373 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); |
| 13374 } | 13374 } |
| 13375 if (number > kBufferSize) { | 13375 if (number > kBufferSize) { |
| 13376 array = isolate->factory()->NewFixedArray(number); | 13376 array = isolate->factory()->NewFixedArray(number); |
| 13377 heap->EnsureHeapIsIterable(); | |
| 13378 DisallowHeapAllocation no_allocation; | |
| 13379 HeapIterator heap_iterator(heap); | 13377 HeapIterator heap_iterator(heap); |
| 13380 Script* scr = *script; | 13378 Script* scr = *script; |
| 13381 FixedArray* arr = *array; | 13379 FixedArray* arr = *array; |
| 13382 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); | 13380 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); |
| 13383 } | 13381 } |
| 13384 | 13382 |
| 13385 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); | 13383 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); |
| 13386 result->set_length(Smi::FromInt(number)); | 13384 result->set_length(Smi::FromInt(number)); |
| 13387 | 13385 |
| 13388 LiveEdit::WrapSharedFunctionInfos(result); | 13386 LiveEdit::WrapSharedFunctionInfos(result); |
| (...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14451 // traversals might be required rendering this operation as a rather slow | 14449 // traversals might be required rendering this operation as a rather slow |
| 14452 // operation. However for setting break points which is normally done through | 14450 // operation. However for setting break points which is normally done through |
| 14453 // some kind of user interaction the performance is not crucial. | 14451 // some kind of user interaction the performance is not crucial. |
| 14454 static Handle<Object> Runtime_GetScriptFromScriptName( | 14452 static Handle<Object> Runtime_GetScriptFromScriptName( |
| 14455 Handle<String> script_name) { | 14453 Handle<String> script_name) { |
| 14456 // Scan the heap for Script objects to find the script with the requested | 14454 // Scan the heap for Script objects to find the script with the requested |
| 14457 // script data. | 14455 // script data. |
| 14458 Handle<Script> script; | 14456 Handle<Script> script; |
| 14459 Factory* factory = script_name->GetIsolate()->factory(); | 14457 Factory* factory = script_name->GetIsolate()->factory(); |
| 14460 Heap* heap = script_name->GetHeap(); | 14458 Heap* heap = script_name->GetHeap(); |
| 14461 heap->EnsureHeapIsIterable(); | |
| 14462 DisallowHeapAllocation no_allocation_during_heap_iteration; | |
| 14463 HeapIterator iterator(heap); | 14459 HeapIterator iterator(heap); |
| 14464 HeapObject* obj = NULL; | 14460 HeapObject* obj = NULL; |
| 14465 while (script.is_null() && ((obj = iterator.next()) != NULL)) { | 14461 while (script.is_null() && ((obj = iterator.next()) != NULL)) { |
| 14466 // If a script is found check if it has the script data requested. | 14462 // If a script is found check if it has the script data requested. |
| 14467 if (obj->IsScript()) { | 14463 if (obj->IsScript()) { |
| 14468 if (Script::cast(obj)->name()->IsString()) { | 14464 if (Script::cast(obj)->name()->IsString()) { |
| 14469 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { | 14465 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { |
| 14470 script = Handle<Script>(Script::cast(obj)); | 14466 script = Handle<Script>(Script::cast(obj)); |
| 14471 } | 14467 } |
| 14472 } | 14468 } |
| (...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15209 } | 15205 } |
| 15210 return NULL; | 15206 return NULL; |
| 15211 } | 15207 } |
| 15212 | 15208 |
| 15213 | 15209 |
| 15214 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15210 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
| 15215 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15211 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
| 15216 } | 15212 } |
| 15217 | 15213 |
| 15218 } } // namespace v8::internal | 15214 } } // namespace v8::internal |
| OLD | NEW |