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 13108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13119 | 13119 |
13120 | 13120 |
13121 // Scan the heap for objects with direct references to an object | 13121 // Scan the heap for objects with direct references to an object |
13122 // args[0]: the object to find references to | 13122 // args[0]: the object to find references to |
13123 // args[1]: constructor function for instances to exclude (Mirror) | 13123 // args[1]: constructor function for instances to exclude (Mirror) |
13124 // args[2]: the the maximum number of objects to return | 13124 // args[2]: the the maximum number of objects to return |
13125 RUNTIME_FUNCTION(Runtime_DebugReferencedBy) { | 13125 RUNTIME_FUNCTION(Runtime_DebugReferencedBy) { |
13126 HandleScope scope(isolate); | 13126 HandleScope scope(isolate); |
13127 ASSERT(args.length() == 3); | 13127 ASSERT(args.length() == 3); |
13128 | 13128 |
13129 // First perform a full GC in order to avoid references from dead objects. | |
13130 Heap* heap = isolate->heap(); | |
13131 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugReferencedBy"); | |
13132 // The heap iterator reserves the right to do a GC to make the heap iterable. | |
13133 // Due to the GC above we know it won't need to do that, but it seems cleaner | |
13134 // to get the heap iterator constructed before we start having unprotected | |
13135 // Object* locals that are not protected by handles. | |
13136 | |
13137 // Check parameters. | 13129 // Check parameters. |
13138 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); | 13130 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); |
13139 CONVERT_ARG_HANDLE_CHECKED(Object, instance_filter, 1); | 13131 CONVERT_ARG_HANDLE_CHECKED(Object, instance_filter, 1); |
13140 RUNTIME_ASSERT(instance_filter->IsUndefined() || | 13132 RUNTIME_ASSERT(instance_filter->IsUndefined() || |
13141 instance_filter->IsJSObject()); | 13133 instance_filter->IsJSObject()); |
13142 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); | 13134 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); |
13143 RUNTIME_ASSERT(max_references >= 0); | 13135 RUNTIME_ASSERT(max_references >= 0); |
13144 | 13136 |
13145 | 13137 |
13146 // Get the constructor function for context extension and arguments array. | 13138 // Get the constructor function for context extension and arguments array. |
13147 Handle<JSObject> arguments_boilerplate( | 13139 Handle<JSObject> arguments_boilerplate( |
13148 isolate->context()->native_context()->sloppy_arguments_boilerplate()); | 13140 isolate->context()->native_context()->sloppy_arguments_boilerplate()); |
13149 Handle<JSFunction> arguments_function( | 13141 Handle<JSFunction> arguments_function( |
13150 JSFunction::cast(arguments_boilerplate->map()->constructor())); | 13142 JSFunction::cast(arguments_boilerplate->map()->constructor())); |
13151 | 13143 |
13152 // Get the number of referencing objects. | 13144 // Get the number of referencing objects. |
13153 int count; | 13145 int count; |
13146 // First perform a full GC in order to avoid dead objects and to make the heap | |
13147 // iterable. | |
13148 Heap* heap = isolate->heap(); | |
13149 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); | |
Hannes Payer (out of office)
2014/05/18 18:25:43
Call MakeIterable instead.
Jarin
2014/05/19 06:06:42
I think this should still call CollectAllGarbage b
| |
13154 HeapIterator heap_iterator(heap); | 13150 HeapIterator heap_iterator(heap); |
13155 count = DebugReferencedBy(&heap_iterator, | 13151 count = DebugReferencedBy(&heap_iterator, |
13156 *target, *instance_filter, max_references, | 13152 *target, *instance_filter, max_references, |
13157 NULL, 0, *arguments_function); | 13153 NULL, 0, *arguments_function); |
13158 | 13154 |
13159 // Allocate an array to hold the result. | 13155 // Allocate an array to hold the result. |
13160 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); | 13156 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); |
13161 | 13157 |
13162 // Fill the referencing objects. | 13158 // Fill the referencing objects. |
13163 // AllocateFixedArray above does not make the heap non-iterable. | 13159 heap->EnsureHeapIsIterable(); |
13164 ASSERT(heap->IsHeapIterable()); | |
13165 HeapIterator heap_iterator2(heap); | 13160 HeapIterator heap_iterator2(heap); |
13166 count = DebugReferencedBy(&heap_iterator2, | 13161 count = DebugReferencedBy(&heap_iterator2, |
13167 *target, *instance_filter, max_references, | 13162 *target, *instance_filter, max_references, |
13168 *instances, count, *arguments_function); | 13163 *instances, count, *arguments_function); |
13169 | 13164 |
13170 // Return result as JS array. | 13165 // Return result as JS array. |
13171 Handle<JSFunction> constructor( | 13166 Handle<JSFunction> constructor( |
13172 isolate->context()->native_context()->array_function()); | 13167 isolate->context()->native_context()->array_function()); |
13173 | 13168 |
13174 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); | 13169 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
13209 } | 13204 } |
13210 | 13205 |
13211 | 13206 |
13212 // Scan the heap for objects constructed by a specific function. | 13207 // Scan the heap for objects constructed by a specific function. |
13213 // args[0]: the constructor to find instances of | 13208 // args[0]: the constructor to find instances of |
13214 // args[1]: the the maximum number of objects to return | 13209 // args[1]: the the maximum number of objects to return |
13215 RUNTIME_FUNCTION(Runtime_DebugConstructedBy) { | 13210 RUNTIME_FUNCTION(Runtime_DebugConstructedBy) { |
13216 HandleScope scope(isolate); | 13211 HandleScope scope(isolate); |
13217 ASSERT(args.length() == 2); | 13212 ASSERT(args.length() == 2); |
13218 | 13213 |
13219 // First perform a full GC in order to avoid dead objects. | |
13220 Heap* heap = isolate->heap(); | |
13221 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); | |
13222 | 13214 |
13223 // Check parameters. | 13215 // Check parameters. |
13224 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); | 13216 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); |
13225 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); | 13217 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); |
13226 RUNTIME_ASSERT(max_references >= 0); | 13218 RUNTIME_ASSERT(max_references >= 0); |
13227 | 13219 |
13228 // Get the number of referencing objects. | 13220 // Get the number of referencing objects. |
13229 int count; | 13221 int count; |
13222 // First perform a full GC in order to avoid dead objects and to make the heap | |
13223 // iterable. | |
13224 Heap* heap = isolate->heap(); | |
13225 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy"); | |
Hannes Payer (out of office)
2014/05/18 18:25:43
Call MakeIterable instead.
Jarin
2014/05/19 06:06:42
See above.
| |
13230 HeapIterator heap_iterator(heap); | 13226 HeapIterator heap_iterator(heap); |
13231 count = DebugConstructedBy(&heap_iterator, | 13227 count = DebugConstructedBy(&heap_iterator, |
13232 *constructor, | 13228 *constructor, |
13233 max_references, | 13229 max_references, |
13234 NULL, | 13230 NULL, |
13235 0); | 13231 0); |
13236 | 13232 |
13237 // Allocate an array to hold the result. | 13233 // Allocate an array to hold the result. |
13238 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); | 13234 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); |
13239 | 13235 |
13240 ASSERT(heap->IsHeapIterable()); | |
13241 // Fill the referencing objects. | 13236 // Fill the referencing objects. |
13237 heap->EnsureHeapIsIterable(); | |
13242 HeapIterator heap_iterator2(heap); | 13238 HeapIterator heap_iterator2(heap); |
13243 count = DebugConstructedBy(&heap_iterator2, | 13239 count = DebugConstructedBy(&heap_iterator2, |
13244 *constructor, | 13240 *constructor, |
13245 max_references, | 13241 max_references, |
13246 *instances, | 13242 *instances, |
13247 count); | 13243 count); |
13248 | 13244 |
13249 // Return result as JS array. | 13245 // Return result as JS array. |
13250 Handle<JSFunction> array_function( | 13246 Handle<JSFunction> array_function( |
13251 isolate->context()->native_context()->array_function()); | 13247 isolate->context()->native_context()->array_function()); |
(...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
15228 } | 15224 } |
15229 return NULL; | 15225 return NULL; |
15230 } | 15226 } |
15231 | 15227 |
15232 | 15228 |
15233 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { | 15229 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { |
15234 return &(kIntrinsicFunctions[static_cast<int>(id)]); | 15230 return &(kIntrinsicFunctions[static_cast<int>(id)]); |
15235 } | 15231 } |
15236 | 15232 |
15237 } } // namespace v8::internal | 15233 } } // namespace v8::internal |
OLD | NEW |