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

Side by Side Diff: src/runtime.cc

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