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 13111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13122 | 13122 |
13123 | 13123 |
13124 // Scan the heap for objects with direct references to an object | 13124 // Scan the heap for objects with direct references to an object |
13125 // args[0]: the object to find references to | 13125 // args[0]: the object to find references to |
13126 // args[1]: constructor function for instances to exclude (Mirror) | 13126 // args[1]: constructor function for instances to exclude (Mirror) |
13127 // args[2]: the the maximum number of objects to return | 13127 // args[2]: the the maximum number of objects to return |
13128 RUNTIME_FUNCTION(Runtime_DebugReferencedBy) { | 13128 RUNTIME_FUNCTION(Runtime_DebugReferencedBy) { |
13129 HandleScope scope(isolate); | 13129 HandleScope scope(isolate); |
13130 ASSERT(args.length() == 3); | 13130 ASSERT(args.length() == 3); |
13131 | 13131 |
13132 // First perform a full GC in order to avoid references from dead objects. | |
13133 Heap* heap = isolate->heap(); | |
13134 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugReferencedBy"); | |
13135 // The heap iterator reserves the right to do a GC to make the heap iterable. | |
13136 // Due to the GC above we know it won't need to do that, but it seems cleaner | |
13137 // to get the heap iterator constructed before we start having unprotected | |
13138 // Object* locals that are not protected by handles. | |
13139 | |
13140 // Check parameters. | 13132 // Check parameters. |
13141 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); | 13133 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); |
13142 CONVERT_ARG_HANDLE_CHECKED(Object, instance_filter, 1); | 13134 CONVERT_ARG_HANDLE_CHECKED(Object, instance_filter, 1); |
13143 RUNTIME_ASSERT(instance_filter->IsUndefined() || | 13135 RUNTIME_ASSERT(instance_filter->IsUndefined() || |
13144 instance_filter->IsJSObject()); | 13136 instance_filter->IsJSObject()); |
13145 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); | 13137 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); |
13146 RUNTIME_ASSERT(max_references >= 0); | 13138 RUNTIME_ASSERT(max_references >= 0); |
13147 | 13139 |
13148 | 13140 |
13149 // Get the constructor function for context extension and arguments array. | 13141 // Get the constructor function for context extension and arguments array. |
13150 Handle<JSObject> arguments_boilerplate( | 13142 Handle<JSObject> arguments_boilerplate( |
13151 isolate->context()->native_context()->sloppy_arguments_boilerplate()); | 13143 isolate->context()->native_context()->sloppy_arguments_boilerplate()); |
13152 Handle<JSFunction> arguments_function( | 13144 Handle<JSFunction> arguments_function( |
13153 JSFunction::cast(arguments_boilerplate->map()->constructor())); | 13145 JSFunction::cast(arguments_boilerplate->map()->constructor())); |
13154 | 13146 |
13155 // Get the number of referencing objects. | 13147 // Get the number of referencing objects. |
13156 int count; | 13148 int count; |
13157 HeapIterator heap_iterator(heap); | 13149 // First perform a full GC in order to avoid dead objects and to make the heap |
13158 count = DebugReferencedBy(&heap_iterator, | 13150 // iterable. |
13159 *target, *instance_filter, max_references, | 13151 Heap* heap = isolate->heap(); |
13160 NULL, 0, *arguments_function); | 13152 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); |
| 13153 { |
| 13154 HeapIterator heap_iterator(heap); |
| 13155 count = DebugReferencedBy(&heap_iterator, |
| 13156 *target, *instance_filter, max_references, |
| 13157 NULL, 0, *arguments_function); |
| 13158 } |
13161 | 13159 |
13162 // Allocate an array to hold the result. | 13160 // Allocate an array to hold the result. |
13163 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); | 13161 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); |
13164 | 13162 |
13165 // Fill the referencing objects. | 13163 // Fill the referencing objects. |
13166 // AllocateFixedArray above does not make the heap non-iterable. | 13164 { |
13167 ASSERT(heap->IsHeapIterable()); | 13165 HeapIterator heap_iterator(heap); |
13168 HeapIterator heap_iterator2(heap); | 13166 count = DebugReferencedBy(&heap_iterator, |
13169 count = DebugReferencedBy(&heap_iterator2, | 13167 *target, *instance_filter, max_references, |
13170 *target, *instance_filter, max_references, | 13168 *instances, count, *arguments_function); |
13171 *instances, count, *arguments_function); | 13169 } |
13172 | 13170 |
13173 // Return result as JS array. | 13171 // Return result as JS array. |
13174 Handle<JSFunction> constructor( | 13172 Handle<JSFunction> constructor( |
13175 isolate->context()->native_context()->array_function()); | 13173 isolate->context()->native_context()->array_function()); |
13176 | 13174 |
13177 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); | 13175 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); |
13178 JSArray::SetContent(Handle<JSArray>::cast(result), instances); | 13176 JSArray::SetContent(Handle<JSArray>::cast(result), instances); |
13179 return *result; | 13177 return *result; |
13180 } | 13178 } |
13181 | 13179 |
(...skipping 30 matching lines...) Expand all Loading... |
13212 } | 13210 } |
13213 | 13211 |
13214 | 13212 |
13215 // Scan the heap for objects constructed by a specific function. | 13213 // Scan the heap for objects constructed by a specific function. |
13216 // args[0]: the constructor to find instances of | 13214 // args[0]: the constructor to find instances of |
13217 // args[1]: the the maximum number of objects to return | 13215 // args[1]: the the maximum number of objects to return |
13218 RUNTIME_FUNCTION(Runtime_DebugConstructedBy) { | 13216 RUNTIME_FUNCTION(Runtime_DebugConstructedBy) { |
13219 HandleScope scope(isolate); | 13217 HandleScope scope(isolate); |
13220 ASSERT(args.length() == 2); | 13218 ASSERT(args.length() == 2); |
13221 | 13219 |
13222 // First perform a full GC in order to avoid dead objects. | |
13223 Heap* heap = isolate->heap(); | |
13224 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); | |
13225 | 13220 |
13226 // Check parameters. | 13221 // Check parameters. |
13227 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); | 13222 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); |
13228 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); | 13223 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); |
13229 RUNTIME_ASSERT(max_references >= 0); | 13224 RUNTIME_ASSERT(max_references >= 0); |
13230 | 13225 |
13231 // Get the number of referencing objects. | 13226 // Get the number of referencing objects. |
13232 int count; | 13227 int count; |
13233 HeapIterator heap_iterator(heap); | 13228 // First perform a full GC in order to avoid dead objects and to make the heap |
13234 count = DebugConstructedBy(&heap_iterator, | 13229 // iterable. |
13235 *constructor, | 13230 Heap* heap = isolate->heap(); |
13236 max_references, | 13231 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); |
13237 NULL, | 13232 { |
13238 0); | 13233 HeapIterator heap_iterator(heap); |
| 13234 count = DebugConstructedBy(&heap_iterator, |
| 13235 *constructor, |
| 13236 max_references, |
| 13237 NULL, |
| 13238 0); |
| 13239 } |
13239 | 13240 |
13240 // Allocate an array to hold the result. | 13241 // Allocate an array to hold the result. |
13241 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); | 13242 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); |
13242 | 13243 |
13243 ASSERT(heap->IsHeapIterable()); | |
13244 // Fill the referencing objects. | 13244 // Fill the referencing objects. |
13245 HeapIterator heap_iterator2(heap); | 13245 { |
13246 count = DebugConstructedBy(&heap_iterator2, | 13246 HeapIterator heap_iterator2(heap); |
13247 *constructor, | 13247 count = DebugConstructedBy(&heap_iterator2, |
13248 max_references, | 13248 *constructor, |
13249 *instances, | 13249 max_references, |
13250 count); | 13250 *instances, |
| 13251 count); |
| 13252 } |
13251 | 13253 |
13252 // Return result as JS array. | 13254 // Return result as JS array. |
13253 Handle<JSFunction> array_function( | 13255 Handle<JSFunction> array_function( |
13254 isolate->context()->native_context()->array_function()); | 13256 isolate->context()->native_context()->array_function()); |
13255 Handle<JSObject> result = isolate->factory()->NewJSObject(array_function); | 13257 Handle<JSObject> result = isolate->factory()->NewJSObject(array_function); |
13256 JSArray::SetContent(Handle<JSArray>::cast(result), instances); | 13258 JSArray::SetContent(Handle<JSArray>::cast(result), instances); |
13257 return *result; | 13259 return *result; |
13258 } | 13260 } |
13259 | 13261 |
13260 | 13262 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13372 RUNTIME_ASSERT(script_value->value()->IsScript()); | 13374 RUNTIME_ASSERT(script_value->value()->IsScript()); |
13373 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); | 13375 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); |
13374 | 13376 |
13375 const int kBufferSize = 32; | 13377 const int kBufferSize = 32; |
13376 | 13378 |
13377 Handle<FixedArray> array; | 13379 Handle<FixedArray> array; |
13378 array = isolate->factory()->NewFixedArray(kBufferSize); | 13380 array = isolate->factory()->NewFixedArray(kBufferSize); |
13379 int number; | 13381 int number; |
13380 Heap* heap = isolate->heap(); | 13382 Heap* heap = isolate->heap(); |
13381 { | 13383 { |
13382 heap->EnsureHeapIsIterable(); | |
13383 DisallowHeapAllocation no_allocation; | |
13384 HeapIterator heap_iterator(heap); | 13384 HeapIterator heap_iterator(heap); |
13385 Script* scr = *script; | 13385 Script* scr = *script; |
13386 FixedArray* arr = *array; | 13386 FixedArray* arr = *array; |
13387 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); | 13387 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); |
13388 } | 13388 } |
13389 if (number > kBufferSize) { | 13389 if (number > kBufferSize) { |
13390 array = isolate->factory()->NewFixedArray(number); | 13390 array = isolate->factory()->NewFixedArray(number); |
13391 heap->EnsureHeapIsIterable(); | |
13392 DisallowHeapAllocation no_allocation; | |
13393 HeapIterator heap_iterator(heap); | 13391 HeapIterator heap_iterator(heap); |
13394 Script* scr = *script; | 13392 Script* scr = *script; |
13395 FixedArray* arr = *array; | 13393 FixedArray* arr = *array; |
13396 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); | 13394 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); |
13397 } | 13395 } |
13398 | 13396 |
13399 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); | 13397 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); |
13400 result->set_length(Smi::FromInt(number)); | 13398 result->set_length(Smi::FromInt(number)); |
13401 | 13399 |
13402 LiveEdit::WrapSharedFunctionInfos(result); | 13400 LiveEdit::WrapSharedFunctionInfos(result); |
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
14465 // traversals might be required rendering this operation as a rather slow | 14463 // traversals might be required rendering this operation as a rather slow |
14466 // operation. However for setting break points which is normally done through | 14464 // operation. However for setting break points which is normally done through |
14467 // some kind of user interaction the performance is not crucial. | 14465 // some kind of user interaction the performance is not crucial. |
14468 static Handle<Object> Runtime_GetScriptFromScriptName( | 14466 static Handle<Object> Runtime_GetScriptFromScriptName( |
14469 Handle<String> script_name) { | 14467 Handle<String> script_name) { |
14470 // Scan the heap for Script objects to find the script with the requested | 14468 // Scan the heap for Script objects to find the script with the requested |
14471 // script data. | 14469 // script data. |
14472 Handle<Script> script; | 14470 Handle<Script> script; |
14473 Factory* factory = script_name->GetIsolate()->factory(); | 14471 Factory* factory = script_name->GetIsolate()->factory(); |
14474 Heap* heap = script_name->GetHeap(); | 14472 Heap* heap = script_name->GetHeap(); |
14475 heap->EnsureHeapIsIterable(); | |
14476 DisallowHeapAllocation no_allocation_during_heap_iteration; | |
14477 HeapIterator iterator(heap); | 14473 HeapIterator iterator(heap); |
14478 HeapObject* obj = NULL; | 14474 HeapObject* obj = NULL; |
14479 while (script.is_null() && ((obj = iterator.next()) != NULL)) { | 14475 while (script.is_null() && ((obj = iterator.next()) != NULL)) { |
14480 // If a script is found check if it has the script data requested. | 14476 // If a script is found check if it has the script data requested. |
14481 if (obj->IsScript()) { | 14477 if (obj->IsScript()) { |
14482 if (Script::cast(obj)->name()->IsString()) { | 14478 if (Script::cast(obj)->name()->IsString()) { |
14483 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { | 14479 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { |
14484 script = Handle<Script>(Script::cast(obj)); | 14480 script = Handle<Script>(Script::cast(obj)); |
14485 } | 14481 } |
14486 } | 14482 } |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15223 } | 15219 } |
15224 return NULL; | 15220 return NULL; |
15225 } | 15221 } |
15226 | 15222 |
15227 | 15223 |
15228 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15224 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
15229 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15225 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
15230 } | 15226 } |
15231 | 15227 |
15232 } } // namespace v8::internal | 15228 } } // namespace v8::internal |
OLD | NEW |