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