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

Side by Side Diff: src/runtime.cc

Issue 7650010: Avoid some crashes when running without snapshots. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/gc
Patch Set: Address review comments Created 9 years, 4 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/profile-generator.cc ('k') | src/spaces.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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 11068 matching lines...) Expand 10 before | Expand all | Expand 10 after
11079 // which is found is not compiled it is compiled and the heap is iterated 11079 // which is found is not compiled it is compiled and the heap is iterated
11080 // again as the compilation might create inner functions from the newly 11080 // again as the compilation might create inner functions from the newly
11081 // compiled function and the actual requested break point might be in one of 11081 // compiled function and the actual requested break point might be in one of
11082 // these functions. 11082 // these functions.
11083 bool done = false; 11083 bool done = false;
11084 // The current candidate for the source position: 11084 // The current candidate for the source position:
11085 int target_start_position = RelocInfo::kNoPosition; 11085 int target_start_position = RelocInfo::kNoPosition;
11086 Handle<SharedFunctionInfo> target; 11086 Handle<SharedFunctionInfo> target;
11087 while (!done) { 11087 while (!done) {
11088 { // Extra scope for iterator and no-allocation. 11088 { // Extra scope for iterator and no-allocation.
11089 isolate->heap()->EnsureHeapIsIterable();
11090 AssertNoAllocation no_alloc_during_heap_iteration;
11089 HeapIterator iterator; 11091 HeapIterator iterator;
11090 AssertNoAllocation no_alloc_during_heap_iteration; 11092 for (HeapObject* obj = iterator.next();
11091 for (HeapObject* obj = iterator.Next(); 11093 obj != NULL; obj = iterator.next()) {
11092 obj != NULL; obj = iterator.Next()) {
11093 if (obj->IsSharedFunctionInfo()) { 11094 if (obj->IsSharedFunctionInfo()) {
11094 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(obj)); 11095 Handle<SharedFunctionInfo> shared(SharedFunctionInfo::cast(obj));
11095 if (shared->script() == *script) { 11096 if (shared->script() == *script) {
11096 // If the SharedFunctionInfo found has the requested script data and 11097 // If the SharedFunctionInfo found has the requested script data and
11097 // contains the source position it is a candidate. 11098 // contains the source position it is a candidate.
11098 int start_position = shared->function_token_position(); 11099 int start_position = shared->function_token_position();
11099 if (start_position == RelocInfo::kNoPosition) { 11100 if (start_position == RelocInfo::kNoPosition) {
11100 start_position = shared->start_position(); 11101 start_position = shared->start_position();
11101 } 11102 }
11102 if (start_position <= position && 11103 if (start_position <= position &&
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
11622 Object* instance_filter, int max_references, 11623 Object* instance_filter, int max_references,
11623 FixedArray* instances, int instances_size, 11624 FixedArray* instances, int instances_size,
11624 JSFunction* arguments_function) { 11625 JSFunction* arguments_function) {
11625 NoHandleAllocation ha; 11626 NoHandleAllocation ha;
11626 AssertNoAllocation no_alloc; 11627 AssertNoAllocation no_alloc;
11627 11628
11628 // Iterate the heap. 11629 // Iterate the heap.
11629 int count = 0; 11630 int count = 0;
11630 JSObject* last = NULL; 11631 JSObject* last = NULL;
11631 HeapObject* heap_obj = NULL; 11632 HeapObject* heap_obj = NULL;
11632 while (((heap_obj = iterator->Next()) != NULL) && 11633 while (((heap_obj = iterator->next()) != NULL) &&
11633 (max_references == 0 || count < max_references)) { 11634 (max_references == 0 || count < max_references)) {
11634 // Only look at all JSObjects. 11635 // Only look at all JSObjects.
11635 if (heap_obj->IsJSObject()) { 11636 if (heap_obj->IsJSObject()) {
11636 // Skip context extension objects and argument arrays as these are 11637 // Skip context extension objects and argument arrays as these are
11637 // checked in the context of functions using them. 11638 // checked in the context of functions using them.
11638 JSObject* obj = JSObject::cast(heap_obj); 11639 JSObject* obj = JSObject::cast(heap_obj);
11639 if (obj->IsJSContextExtensionObject() || 11640 if (obj->IsJSContextExtensionObject() ||
11640 obj->map()->constructor() == arguments_function) { 11641 obj->map()->constructor() == arguments_function) {
11641 continue; 11642 continue;
11642 } 11643 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
11692 // args[2]: the the maximum number of objects to return 11693 // args[2]: the the maximum number of objects to return
11693 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugReferencedBy) { 11694 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugReferencedBy) {
11694 ASSERT(args.length() == 3); 11695 ASSERT(args.length() == 3);
11695 11696
11696 // First perform a full GC in order to avoid references from dead objects. 11697 // First perform a full GC in order to avoid references from dead objects.
11697 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask); 11698 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask);
11698 // The heap iterator reserves the right to do a GC to make the heap iterable. 11699 // The heap iterator reserves the right to do a GC to make the heap iterable.
11699 // Due to the GC above we know it won't need to do that, but it seems cleaner 11700 // Due to the GC above we know it won't need to do that, but it seems cleaner
11700 // to get the heap iterator constructed before we start having unprotected 11701 // to get the heap iterator constructed before we start having unprotected
11701 // Object* locals that are not protected by handles. 11702 // Object* locals that are not protected by handles.
11702 HeapIterator heap_iterator;
11703 HeapIterator heap_iterator2;
11704 11703
11705 // Check parameters. 11704 // Check parameters.
11706 CONVERT_CHECKED(JSObject, target, args[0]); 11705 CONVERT_CHECKED(JSObject, target, args[0]);
11707 Object* instance_filter = args[1]; 11706 Object* instance_filter = args[1];
11708 RUNTIME_ASSERT(instance_filter->IsUndefined() || 11707 RUNTIME_ASSERT(instance_filter->IsUndefined() ||
11709 instance_filter->IsJSObject()); 11708 instance_filter->IsJSObject());
11710 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]); 11709 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[2]);
11711 RUNTIME_ASSERT(max_references >= 0); 11710 RUNTIME_ASSERT(max_references >= 0);
11712 11711
11713 11712
11714 // Get the constructor function for context extension and arguments array. 11713 // Get the constructor function for context extension and arguments array.
11715 JSObject* arguments_boilerplate = 11714 JSObject* arguments_boilerplate =
11716 isolate->context()->global_context()->arguments_boilerplate(); 11715 isolate->context()->global_context()->arguments_boilerplate();
11717 JSFunction* arguments_function = 11716 JSFunction* arguments_function =
11718 JSFunction::cast(arguments_boilerplate->map()->constructor()); 11717 JSFunction::cast(arguments_boilerplate->map()->constructor());
11719 11718
11720 // Get the number of referencing objects. 11719 // Get the number of referencing objects.
11721 int count; 11720 int count;
11721 HeapIterator heap_iterator;
11722 count = DebugReferencedBy(&heap_iterator, 11722 count = DebugReferencedBy(&heap_iterator,
11723 target, instance_filter, max_references, 11723 target, instance_filter, max_references,
11724 NULL, 0, arguments_function); 11724 NULL, 0, arguments_function);
11725 11725
11726 // Allocate an array to hold the result. 11726 // Allocate an array to hold the result.
11727 Object* object; 11727 Object* object;
11728 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count); 11728 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count);
11729 if (!maybe_object->ToObject(&object)) return maybe_object; 11729 if (!maybe_object->ToObject(&object)) return maybe_object;
11730 } 11730 }
11731 FixedArray* instances = FixedArray::cast(object); 11731 FixedArray* instances = FixedArray::cast(object);
11732 11732
11733 // Fill the referencing objects. 11733 // Fill the referencing objects.
11734 // AllocateFixedArray above does not make the heap non-iterable.
11735 ASSERT(HEAP->IsHeapIterable());
11736 HeapIterator heap_iterator2;
11734 count = DebugReferencedBy(&heap_iterator2, 11737 count = DebugReferencedBy(&heap_iterator2,
11735 target, instance_filter, max_references, 11738 target, instance_filter, max_references,
11736 instances, count, arguments_function); 11739 instances, count, arguments_function);
11737 11740
11738 // Return result as JS array. 11741 // Return result as JS array.
11739 Object* result; 11742 Object* result;
11740 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( 11743 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject(
11741 isolate->context()->global_context()->array_function()); 11744 isolate->context()->global_context()->array_function());
11742 if (!maybe_result->ToObject(&result)) return maybe_result; 11745 if (!maybe_result->ToObject(&result)) return maybe_result;
11743 } 11746 }
11744 JSArray::cast(result)->SetContent(instances); 11747 JSArray::cast(result)->SetContent(instances);
11745 return result; 11748 return result;
11746 } 11749 }
11747 11750
11748 11751
11749 // Helper function used by Runtime_DebugConstructedBy below. 11752 // Helper function used by Runtime_DebugConstructedBy below.
11750 static int DebugConstructedBy(HeapIterator* iterator, 11753 static int DebugConstructedBy(HeapIterator* iterator,
11751 JSFunction* constructor, 11754 JSFunction* constructor,
11752 int max_references, 11755 int max_references,
11753 FixedArray* instances, 11756 FixedArray* instances,
11754 int instances_size) { 11757 int instances_size) {
11755 AssertNoAllocation no_alloc; 11758 AssertNoAllocation no_alloc;
11756 11759
11757 // Iterate the heap. 11760 // Iterate the heap.
11758 int count = 0; 11761 int count = 0;
11759 HeapObject* heap_obj = NULL; 11762 HeapObject* heap_obj = NULL;
11760 while (((heap_obj = iterator->Next()) != NULL) && 11763 while (((heap_obj = iterator->next()) != NULL) &&
11761 (max_references == 0 || count < max_references)) { 11764 (max_references == 0 || count < max_references)) {
11762 // Only look at all JSObjects. 11765 // Only look at all JSObjects.
11763 if (heap_obj->IsJSObject()) { 11766 if (heap_obj->IsJSObject()) {
11764 JSObject* obj = JSObject::cast(heap_obj); 11767 JSObject* obj = JSObject::cast(heap_obj);
11765 if (obj->map()->constructor() == constructor) { 11768 if (obj->map()->constructor() == constructor) {
11766 // Valid reference found add to instance array if supplied an update 11769 // Valid reference found add to instance array if supplied an update
11767 // count. 11770 // count.
11768 if (instances != NULL && count < instances_size) { 11771 if (instances != NULL && count < instances_size) {
11769 instances->set(count, obj); 11772 instances->set(count, obj);
11770 } 11773 }
11771 count++; 11774 count++;
11772 } 11775 }
11773 } 11776 }
11774 } 11777 }
11775 11778
11776 // Return the number of referencing objects found. 11779 // Return the number of referencing objects found.
11777 return count; 11780 return count;
11778 } 11781 }
11779 11782
11780 11783
11781 // Scan the heap for objects constructed by a specific function. 11784 // Scan the heap for objects constructed by a specific function.
11782 // args[0]: the constructor to find instances of 11785 // args[0]: the constructor to find instances of
11783 // args[1]: the the maximum number of objects to return 11786 // args[1]: the the maximum number of objects to return
11784 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) { 11787 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugConstructedBy) {
11785 ASSERT(args.length() == 2); 11788 ASSERT(args.length() == 2);
11786 11789
11787 // First perform a full GC in order to avoid dead objects. 11790 // First perform a full GC in order to avoid dead objects.
11788 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask); 11791 isolate->heap()->CollectAllGarbage(Heap::kMakeHeapIterableMask);
11789 11792
11790 HeapIterator heap_iterator;
11791 HeapIterator heap_iterator2;
11792
11793 // Check parameters. 11793 // Check parameters.
11794 CONVERT_CHECKED(JSFunction, constructor, args[0]); 11794 CONVERT_CHECKED(JSFunction, constructor, args[0]);
11795 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]); 11795 CONVERT_NUMBER_CHECKED(int32_t, max_references, Int32, args[1]);
11796 RUNTIME_ASSERT(max_references >= 0); 11796 RUNTIME_ASSERT(max_references >= 0);
11797 11797
11798 // Get the number of referencing objects. 11798 // Get the number of referencing objects.
11799 int count; 11799 int count;
11800 HeapIterator heap_iterator;
11800 count = DebugConstructedBy(&heap_iterator, 11801 count = DebugConstructedBy(&heap_iterator,
11801 constructor, 11802 constructor,
11802 max_references, 11803 max_references,
11803 NULL, 11804 NULL,
11804 0); 11805 0);
11805 11806
11806 // Allocate an array to hold the result. 11807 // Allocate an array to hold the result.
11807 Object* object; 11808 Object* object;
11808 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count); 11809 { MaybeObject* maybe_object = isolate->heap()->AllocateFixedArray(count);
11809 if (!maybe_object->ToObject(&object)) return maybe_object; 11810 if (!maybe_object->ToObject(&object)) return maybe_object;
11810 } 11811 }
11811 FixedArray* instances = FixedArray::cast(object); 11812 FixedArray* instances = FixedArray::cast(object);
11812 11813
11814 ASSERT(HEAP->IsHeapIterable());
11813 // Fill the referencing objects. 11815 // Fill the referencing objects.
11816 HeapIterator heap_iterator2;
11814 count = DebugConstructedBy(&heap_iterator2, 11817 count = DebugConstructedBy(&heap_iterator2,
11815 constructor, 11818 constructor,
11816 max_references, 11819 max_references,
11817 instances, 11820 instances,
11818 count); 11821 count);
11819 11822
11820 // Return result as JS array. 11823 // Return result as JS array.
11821 Object* result; 11824 Object* result;
11822 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject( 11825 { MaybeObject* maybe_result = isolate->heap()->AllocateJSObject(
11823 isolate->context()->global_context()->array_function()); 11826 isolate->context()->global_context()->array_function());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
11887 return f->shared()->inferred_name(); 11890 return f->shared()->inferred_name();
11888 } 11891 }
11889 11892
11890 11893
11891 static int FindSharedFunctionInfosForScript(HeapIterator* iterator, 11894 static int FindSharedFunctionInfosForScript(HeapIterator* iterator,
11892 Script* script, 11895 Script* script,
11893 FixedArray* buffer) { 11896 FixedArray* buffer) {
11894 AssertNoAllocation no_allocations; 11897 AssertNoAllocation no_allocations;
11895 int counter = 0; 11898 int counter = 0;
11896 int buffer_size = buffer->length(); 11899 int buffer_size = buffer->length();
11897 for (HeapObject* obj = iterator->Next(); 11900 for (HeapObject* obj = iterator->next();
11898 obj != NULL; 11901 obj != NULL;
11899 obj = iterator->Next()) { 11902 obj = iterator->next()) {
11900 ASSERT(obj != NULL); 11903 ASSERT(obj != NULL);
11901 if (!obj->IsSharedFunctionInfo()) { 11904 if (!obj->IsSharedFunctionInfo()) {
11902 continue; 11905 continue;
11903 } 11906 }
11904 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); 11907 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj);
11905 if (shared->script() != script) { 11908 if (shared->script() != script) {
11906 continue; 11909 continue;
11907 } 11910 }
11908 if (counter < buffer_size) { 11911 if (counter < buffer_size) {
11909 buffer->set(counter, shared); 11912 buffer->set(counter, shared);
(...skipping 14 matching lines...) Expand all
11924 11927
11925 11928
11926 Handle<Script> script = Handle<Script>(Script::cast(script_value->value())); 11929 Handle<Script> script = Handle<Script>(Script::cast(script_value->value()));
11927 11930
11928 const int kBufferSize = 32; 11931 const int kBufferSize = 32;
11929 11932
11930 Handle<FixedArray> array; 11933 Handle<FixedArray> array;
11931 array = isolate->factory()->NewFixedArray(kBufferSize); 11934 array = isolate->factory()->NewFixedArray(kBufferSize);
11932 int number; 11935 int number;
11933 { 11936 {
11937 isolate->heap()->EnsureHeapIsIterable();
11938 AssertNoAllocation no_allocations;
11934 HeapIterator heap_iterator; 11939 HeapIterator heap_iterator;
11935 AssertNoAllocation no_allocations;
11936 Script* scr = *script; 11940 Script* scr = *script;
11937 FixedArray* arr = *array; 11941 FixedArray* arr = *array;
11938 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); 11942 number = FindSharedFunctionInfosForScript(&heap_iterator, scr, arr);
11939 } 11943 }
11940 if (number > kBufferSize) { 11944 if (number > kBufferSize) {
11941 array = isolate->factory()->NewFixedArray(number); 11945 array = isolate->factory()->NewFixedArray(number);
11946 isolate->heap()->EnsureHeapIsIterable();
11947 AssertNoAllocation no_allocations;
11942 HeapIterator heap_iterator; 11948 HeapIterator heap_iterator;
11943 AssertNoAllocation no_allocations;
11944 Script* scr = *script; 11949 Script* scr = *script;
11945 FixedArray* arr = *array; 11950 FixedArray* arr = *array;
11946 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr); 11951 FindSharedFunctionInfosForScript(&heap_iterator, scr, arr);
11947 } 11952 }
11948 11953
11949 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array); 11954 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(array);
11950 result->set_length(Smi::FromInt(number)); 11955 result->set_length(Smi::FromInt(number));
11951 11956
11952 LiveEdit::WrapSharedFunctionInfos(result); 11957 LiveEdit::WrapSharedFunctionInfos(result);
11953 11958
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
12417 // heap traversal to find the function generated for the source position 12422 // heap traversal to find the function generated for the source position
12418 // for the requested break point. For lazily compiled functions several heap 12423 // for the requested break point. For lazily compiled functions several heap
12419 // traversals might be required rendering this operation as a rather slow 12424 // traversals might be required rendering this operation as a rather slow
12420 // operation. However for setting break points which is normally done through 12425 // operation. However for setting break points which is normally done through
12421 // some kind of user interaction the performance is not crucial. 12426 // some kind of user interaction the performance is not crucial.
12422 static Handle<Object> Runtime_GetScriptFromScriptName( 12427 static Handle<Object> Runtime_GetScriptFromScriptName(
12423 Handle<String> script_name) { 12428 Handle<String> script_name) {
12424 // Scan the heap for Script objects to find the script with the requested 12429 // Scan the heap for Script objects to find the script with the requested
12425 // script data. 12430 // script data.
12426 Handle<Script> script; 12431 Handle<Script> script;
12432 script_name->GetHeap()->EnsureHeapIsIterable();
12433 AssertNoAllocation no_allocation_during_heap_iteration;
12427 HeapIterator iterator; 12434 HeapIterator iterator;
12428 AssertNoAllocation no_allocation_during_heap_iteration;
12429 HeapObject* obj = NULL; 12435 HeapObject* obj = NULL;
12430 while (script.is_null() && ((obj = iterator.Next()) != NULL)) { 12436 while (script.is_null() && ((obj = iterator.next()) != NULL)) {
12431 // If a script is found check if it has the script data requested. 12437 // If a script is found check if it has the script data requested.
12432 if (obj->IsScript()) { 12438 if (obj->IsScript()) {
12433 if (Script::cast(obj)->name()->IsString()) { 12439 if (Script::cast(obj)->name()->IsString()) {
12434 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) { 12440 if (String::cast(Script::cast(obj)->name())->Equals(*script_name)) {
12435 script = Handle<Script>(Script::cast(obj)); 12441 script = Handle<Script>(Script::cast(obj));
12436 } 12442 }
12437 } 12443 }
12438 } 12444 }
12439 } 12445 }
12440 12446
(...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
12883 } else { 12889 } else {
12884 // Handle last resort GC and make sure to allow future allocations 12890 // Handle last resort GC and make sure to allow future allocations
12885 // to grow the heap without causing GCs (if possible). 12891 // to grow the heap without causing GCs (if possible).
12886 isolate->counters()->gc_last_resort_from_js()->Increment(); 12892 isolate->counters()->gc_last_resort_from_js()->Increment();
12887 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 12893 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
12888 } 12894 }
12889 } 12895 }
12890 12896
12891 12897
12892 } } // namespace v8::internal 12898 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/profile-generator.cc ('k') | src/spaces.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698