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

Side by Side Diff: src/runtime.cc

Issue 294903003: Reland "Fix Heap::IsHeapIterable." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Handlify IterateJSFunctions in LiveEdit 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
« no previous file with comments | « src/liveedit.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 13093 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
13122 // Check parameters. 13114 // Check parameters.
13123 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0); 13115 CONVERT_ARG_HANDLE_CHECKED(JSObject, target, 0);
13124 CONVERT_ARG_HANDLE_CHECKED(Object, instance_filter, 1); 13116 CONVERT_ARG_HANDLE_CHECKED(Object, instance_filter, 1);
13125 RUNTIME_ASSERT(instance_filter->IsUndefined() || 13117 RUNTIME_ASSERT(instance_filter->IsUndefined() ||
13126 instance_filter->IsJSObject()); 13118 instance_filter->IsJSObject());
13127 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); 13119 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]);
13128 RUNTIME_ASSERT(max_references >= 0); 13120 RUNTIME_ASSERT(max_references >= 0);
13129 13121
13130 13122
13131 // Get the constructor function for context extension and arguments array. 13123 // Get the constructor function for context extension and arguments array.
13132 Handle<JSObject> arguments_boilerplate( 13124 Handle<JSObject> arguments_boilerplate(
13133 isolate->context()->native_context()->sloppy_arguments_boilerplate()); 13125 isolate->context()->native_context()->sloppy_arguments_boilerplate());
13134 Handle<JSFunction> arguments_function( 13126 Handle<JSFunction> arguments_function(
13135 JSFunction::cast(arguments_boilerplate->map()->constructor())); 13127 JSFunction::cast(arguments_boilerplate->map()->constructor()));
13136 13128
13137 // Get the number of referencing objects. 13129 // Get the number of referencing objects.
13138 int count; 13130 int count;
13139 HeapIterator heap_iterator(heap); 13131 // First perform a full GC in order to avoid dead objects and to make the heap
13140 count = DebugReferencedBy(&heap_iterator, 13132 // iterable.
13141 *target, *instance_filter, max_references, 13133 Heap* heap = isolate->heap();
13142 NULL, 0, *arguments_function); 13134 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy");
13135 {
13136 HeapIterator heap_iterator(heap);
13137 count = DebugReferencedBy(&heap_iterator,
13138 *target, *instance_filter, max_references,
13139 NULL, 0, *arguments_function);
13140 }
13143 13141
13144 // Allocate an array to hold the result. 13142 // Allocate an array to hold the result.
13145 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); 13143 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count);
13146 13144
13147 // Fill the referencing objects. 13145 // Fill the referencing objects.
13148 // AllocateFixedArray above does not make the heap non-iterable. 13146 {
13149 ASSERT(heap->IsHeapIterable()); 13147 HeapIterator heap_iterator(heap);
13150 HeapIterator heap_iterator2(heap); 13148 count = DebugReferencedBy(&heap_iterator,
13151 count = DebugReferencedBy(&heap_iterator2, 13149 *target, *instance_filter, max_references,
13152 *target, *instance_filter, max_references, 13150 *instances, count, *arguments_function);
13153 *instances, count, *arguments_function); 13151 }
13154 13152
13155 // Return result as JS array. 13153 // Return result as JS array.
13156 Handle<JSFunction> constructor( 13154 Handle<JSFunction> constructor(
13157 isolate->context()->native_context()->array_function()); 13155 isolate->context()->native_context()->array_function());
13158 13156
13159 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor); 13157 Handle<JSObject> result = isolate->factory()->NewJSObject(constructor);
13160 JSArray::SetContent(Handle<JSArray>::cast(result), instances); 13158 JSArray::SetContent(Handle<JSArray>::cast(result), instances);
13161 return *result; 13159 return *result;
13162 } 13160 }
13163 13161
(...skipping 30 matching lines...) Expand all
13194 } 13192 }
13195 13193
13196 13194
13197 // Scan the heap for objects constructed by a specific function. 13195 // Scan the heap for objects constructed by a specific function.
13198 // args[0]: the constructor to find instances of 13196 // args[0]: the constructor to find instances of
13199 // args[1]: the the maximum number of objects to return 13197 // args[1]: the the maximum number of objects to return
13200 RUNTIME_FUNCTION(Runtime_DebugConstructedBy) { 13198 RUNTIME_FUNCTION(Runtime_DebugConstructedBy) {
13201 HandleScope scope(isolate); 13199 HandleScope scope(isolate);
13202 ASSERT(args.length() == 2); 13200 ASSERT(args.length() == 2);
13203 13201
13204 // First perform a full GC in order to avoid dead objects.
13205 Heap* heap = isolate->heap();
13206 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy");
13207 13202
13208 // Check parameters. 13203 // Check parameters.
13209 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0); 13204 CONVERT_ARG_HANDLE_CHECKED(JSFunction, constructor, 0);
13210 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); 13205 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]);
13211 RUNTIME_ASSERT(max_references >= 0); 13206 RUNTIME_ASSERT(max_references >= 0);
13212 13207
13213 // Get the number of referencing objects. 13208 // Get the number of referencing objects.
13214 int count; 13209 int count;
13215 HeapIterator heap_iterator(heap); 13210 // First perform a full GC in order to avoid dead objects and to make the heap
13216 count = DebugConstructedBy(&heap_iterator, 13211 // iterable.
13217 *constructor, 13212 Heap* heap = isolate->heap();
13218 max_references, 13213 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, "%DebugConstructedBy");
13219 NULL, 13214 {
13220 0); 13215 HeapIterator heap_iterator(heap);
13216 count = DebugConstructedBy(&heap_iterator,
13217 *constructor,
13218 max_references,
13219 NULL,
13220 0);
13221 }
13221 13222
13222 // Allocate an array to hold the result. 13223 // Allocate an array to hold the result.
13223 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count); 13224 Handle<FixedArray> instances = isolate->factory()->NewFixedArray(count);
13224 13225
13225 ASSERT(heap->IsHeapIterable());
13226 // Fill the referencing objects. 13226 // Fill the referencing objects.
13227 HeapIterator heap_iterator2(heap); 13227 {
13228 count = DebugConstructedBy(&heap_iterator2, 13228 HeapIterator heap_iterator2(heap);
13229 *constructor, 13229 count = DebugConstructedBy(&heap_iterator2,
13230 max_references, 13230 *constructor,
13231 *instances, 13231 max_references,
13232 count); 13232 *instances,
13233 count);
13234 }
13233 13235
13234 // Return result as JS array. 13236 // Return result as JS array.
13235 Handle<JSFunction> array_function( 13237 Handle<JSFunction> array_function(
13236 isolate->context()->native_context()->array_function()); 13238 isolate->context()->native_context()->array_function());
13237 Handle<JSObject> result = isolate->factory()->NewJSObject(array_function); 13239 Handle<JSObject> result = isolate->factory()->NewJSObject(array_function);
13238 JSArray::SetContent(Handle<JSArray>::cast(result), instances); 13240 JSArray::SetContent(Handle<JSArray>::cast(result), instances);
13239 return *result; 13241 return *result;
13240 } 13242 }
13241 13243
13242 13244
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
13354 RUNTIME_ASSERT(script_value->value()->IsScript()); 13356 RUNTIME_ASSERT(script_value->value()->IsScript());
13355 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); 13357 Handle<Script> script = Handle<Script>(Script::cast(script_value->value()));
13356 13358
13357 const int kBufferSize = 32; 13359 const int kBufferSize = 32;
13358 13360
13359 Handle<FixedArray> array; 13361 Handle<FixedArray> array;
13360 array = isolate->factory()->NewFixedArray(kBufferSize); 13362 array = isolate->factory()->NewFixedArray(kBufferSize);
13361 int number; 13363 int number;
13362 Heap* heap = isolate->heap(); 13364 Heap* heap = isolate->heap();
13363 { 13365 {
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;
13375 HeapIterator heap_iterator(heap); 13373 HeapIterator heap_iterator(heap);
13376 Script* scr = *script; 13374 Script* scr = *script;
13377 FixedArray* arr = *array; 13375 FixedArray* arr = *array;
13378 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); 13376 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr);
13379 } 13377 }
13380 13378
13381 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); 13379 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array);
13382 result->set_length(Smi::FromInt(number)); 13380 result->set_length(Smi::FromInt(number));
13383 13381
13384 LiveEdit::WrapSharedFunctionInfos(result); 13382 LiveEdit::WrapSharedFunctionInfos(result);
(...skipping 1062 matching lines...) Expand 10 before | Expand all | Expand 10 after
14447 // traversals might be required rendering this operation as a rather slow 14445 // traversals might be required rendering this operation as a rather slow
14448 // operation. However for setting break points which is normally done through 14446 // operation. However for setting break points which is normally done through
14449 // some kind of user interaction the performance is not crucial. 14447 // some kind of user interaction the performance is not crucial.
14450 static Handle<Object> Runtime_GetScriptFromScriptName( 14448 static Handle<Object> Runtime_GetScriptFromScriptName(
14451 Handle<String> script_name) { 14449 Handle<String> script_name) {
14452 // Scan the heap for Script objects to find the script with the requested 14450 // Scan the heap for Script objects to find the script with the requested
14453 // script data. 14451 // script data.
14454 Handle<Script> script; 14452 Handle<Script> script;
14455 Factory* factory = script_name->GetIsolate()->factory(); 14453 Factory* factory = script_name->GetIsolate()->factory();
14456 Heap* heap = script_name->GetHeap(); 14454 Heap* heap = script_name->GetHeap();
14457 heap->EnsureHeapIsIterable();
14458 DisallowHeapAllocation no_allocation_during_heap_iteration;
14459 HeapIterator iterator(heap); 14455 HeapIterator iterator(heap);
14460 HeapObject* obj = NULL; 14456 HeapObject* obj = NULL;
14461 while (script.is_null() && ((obj = iterator.next()) != NULL)) { 14457 while (script.is_null() && ((obj = iterator.next()) != NULL)) {
14462 // If a script is found check if it has the script data requested. 14458 // If a script is found check if it has the script data requested.
14463 if (obj->IsScript()) { 14459 if (obj->IsScript()) {
14464 if (Script::cast(obj)->name()->IsString()) { 14460 if (Script::cast(obj)->name()->IsString()) {
14465 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { 14461 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) {
14466 script = Handle<Script>(Script::cast(obj)); 14462 script = Handle<Script>(Script::cast(obj));
14467 } 14463 }
14468 } 14464 }
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
15205 } 15201 }
15206 return NULL; 15202 return NULL;
15207 } 15203 }
15208 15204
15209 15205
15210 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) { 15206 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
15211 return &(kIntrinsicFunctions[static_cast<int>(id)]); 15207 return &(kIntrinsicFunctions[static_cast<int>(id)]);
15212 } 15208 }
15213 15209
15214 } } // namespace v8::internal 15210 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/liveedit.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698