Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: src/runtime.cc

Issue 285693006: Fix Heap::IsHeapIterable. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rename EnsureHeapIsIterable => MakeHeapIterable Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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");
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->MakeHeapIterable();
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
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");
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->MakeHeapIterable();
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
13369 RUNTIME_ASSERT(script_value->value()->IsScript()); 13365 RUNTIME_ASSERT(script_value->value()->IsScript());
13370 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); 13366 Handle<Script> script = Handle<Script>(Script::cast(script_value->value()));
13371 13367
13372 const int kBufferSize = 32; 13368 const int kBufferSize = 32;
13373 13369
13374 Handle<FixedArray> array; 13370 Handle<FixedArray> array;
13375 array = isolate->factory()->NewFixedArray(kBufferSize); 13371 array = isolate->factory()->NewFixedArray(kBufferSize);
13376 int number; 13372 int number;
13377 Heap* heap = isolate->heap(); 13373 Heap* heap = isolate->heap();
13378 { 13374 {
13379 heap->EnsureHeapIsIterable(); 13375 heap->MakeHeapIterable();
13380 DisallowHeapAllocation no_allocation; 13376 DisallowHeapAllocation no_allocation;
13381 HeapIterator heap_iterator(heap); 13377 HeapIterator heap_iterator(heap);
13382 Script* scr = *script; 13378 Script* scr = *script;
13383 FixedArray* arr = *array; 13379 FixedArray* arr = *array;
13384 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); 13380 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr);
13385 } 13381 }
13386 if (number > kBufferSize) { 13382 if (number > kBufferSize) {
13387 array = isolate->factory()->NewFixedArray(number); 13383 array = isolate->factory()->NewFixedArray(number);
13388 heap->EnsureHeapIsIterable(); 13384 heap->MakeHeapIterable();
13389 DisallowHeapAllocation no_allocation; 13385 DisallowHeapAllocation no_allocation;
13390 HeapIterator heap_iterator(heap); 13386 HeapIterator heap_iterator(heap);
13391 Script* scr = *script; 13387 Script* scr = *script;
13392 FixedArray* arr = *array; 13388 FixedArray* arr = *array;
13393 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); 13389 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr);
13394 } 13390 }
13395 13391
13396 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); 13392 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array);
13397 result->set_length(Smi::FromInt(number)); 13393 result->set_length(Smi::FromInt(number));
13398 13394
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
14462 // traversals might be required rendering this operation as a rather slow 14458 // traversals might be required rendering this operation as a rather slow
14463 // operation. However for setting break points which is normally done through 14459 // operation. However for setting break points which is normally done through
14464 // some kind of user interaction the performance is not crucial. 14460 // some kind of user interaction the performance is not crucial.
14465 static Handle<Object> Runtime_GetScriptFromScriptName( 14461 static Handle<Object> Runtime_GetScriptFromScriptName(
14466 Handle<String> script_name) { 14462 Handle<String> script_name) {
14467 // Scan the heap for Script objects to find the script with the requested 14463 // Scan the heap for Script objects to find the script with the requested
14468 // script data. 14464 // script data.
14469 Handle<Script> script; 14465 Handle<Script> script;
14470 Factory* factory = script_name->GetIsolate()->factory(); 14466 Factory* factory = script_name->GetIsolate()->factory();
14471 Heap* heap = script_name->GetHeap(); 14467 Heap* heap = script_name->GetHeap();
14472 heap->EnsureHeapIsIterable(); 14468 heap->MakeHeapIterable();
14473 DisallowHeapAllocation no_allocation_during_heap_iteration; 14469 DisallowHeapAllocation no_allocation_during_heap_iteration;
14474 HeapIterator iterator(heap); 14470 HeapIterator iterator(heap);
14475 HeapObject* obj = NULL; 14471 HeapObject* obj = NULL;
14476 while (script.is_null() && ((obj = iterator.next()) != NULL)) { 14472 while (script.is_null() && ((obj = iterator.next()) != NULL)) {
14477 // If a script is found check if it has the script data requested. 14473 // If a script is found check if it has the script data requested.
14478 if (obj->IsScript()) { 14474 if (obj->IsScript()) {
14479 if (Script::cast(obj)->name()->IsString()) { 14475 if (Script::cast(obj)->name()->IsString()) {
14480 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { 14476 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) {
14481 script = Handle<Script>(Script::cast(obj)); 14477 script = Handle<Script>(Script::cast(obj));
14482 } 14478 }
(...skipping 745 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« src/heap.cc ('K') | « src/liveedit.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698