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 | 5 |
6 #include "v8.h" | 6 #include "v8.h" |
7 | 7 |
8 #include "liveedit.h" | 8 #include "liveedit.h" |
9 | 9 |
10 #include "code-stubs.h" | 10 #include "code-stubs.h" |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 | 932 |
933 // Finds all references to original and replaces them with substitution. | 933 // Finds all references to original and replaces them with substitution. |
934 static void ReplaceCodeObject(Handle<Code> original, | 934 static void ReplaceCodeObject(Handle<Code> original, |
935 Handle<Code> substitution) { | 935 Handle<Code> substitution) { |
936 // Perform a full GC in order to ensure that we are not in the middle of an | 936 // Perform a full GC in order to ensure that we are not in the middle of an |
937 // incremental marking phase when we are replacing the code object. | 937 // incremental marking phase when we are replacing the code object. |
938 // Since we are not in an incremental marking phase we can write pointers | 938 // Since we are not in an incremental marking phase we can write pointers |
939 // to code objects (that are never in new space) without worrying about | 939 // to code objects (that are never in new space) without worrying about |
940 // write barriers. | 940 // write barriers. |
941 Heap* heap = original->GetHeap(); | 941 Heap* heap = original->GetHeap(); |
942 HeapIterator iterator(heap); | 942 heap->CollectAllGarbage(Heap::kMakeHeapIterableMask, |
| 943 "liveedit.cc ReplaceCodeObject"); |
943 | 944 |
944 ASSERT(!heap->InNewSpace(*substitution)); | 945 ASSERT(!heap->InNewSpace(*substitution)); |
945 | 946 |
| 947 DisallowHeapAllocation no_allocation; |
| 948 |
946 ReplacingVisitor visitor(*original, *substitution); | 949 ReplacingVisitor visitor(*original, *substitution); |
947 | 950 |
948 // Iterate over all roots. Stack frames may have pointer into original code, | 951 // Iterate over all roots. Stack frames may have pointer into original code, |
949 // so temporary replace the pointers with offset numbers | 952 // so temporary replace the pointers with offset numbers |
950 // in prologue/epilogue. | 953 // in prologue/epilogue. |
951 heap->IterateRoots(&visitor, VISIT_ALL); | 954 heap->IterateRoots(&visitor, VISIT_ALL); |
952 | 955 |
953 // Now iterate over all pointers of all objects, including code_target | 956 // Now iterate over all pointers of all objects, including code_target |
954 // implicit pointers. | 957 // implicit pointers. |
| 958 HeapIterator iterator(heap); |
955 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { | 959 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
956 obj->Iterate(&visitor); | 960 obj->Iterate(&visitor); |
957 } | 961 } |
958 } | 962 } |
959 | 963 |
960 | 964 |
961 // Patch function literals. | 965 // Patch function literals. |
962 // Name 'literals' is a misnomer. Rather it's a cache for complex object | 966 // Name 'literals' is a misnomer. Rather it's a cache for complex object |
963 // boilerplates and for a native context. We must clean cached values. | 967 // boilerplates and for a native context. We must clean cached values. |
964 // Additionally we may need to allocate a new array if number of literals | 968 // Additionally we may need to allocate a new array if number of literals |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 shared_info->set_num_literals(new_literal_count); | 1012 shared_info->set_num_literals(new_literal_count); |
1009 } | 1013 } |
1010 } | 1014 } |
1011 | 1015 |
1012 private: | 1016 private: |
1013 // Iterates all function instances in the HEAP that refers to the | 1017 // Iterates all function instances in the HEAP that refers to the |
1014 // provided shared_info. | 1018 // provided shared_info. |
1015 template<typename Visitor> | 1019 template<typename Visitor> |
1016 static void IterateJSFunctions(SharedFunctionInfo* shared_info, | 1020 static void IterateJSFunctions(SharedFunctionInfo* shared_info, |
1017 Visitor* visitor) { | 1021 Visitor* visitor) { |
| 1022 DisallowHeapAllocation no_allocation; |
| 1023 |
1018 HeapIterator iterator(shared_info->GetHeap()); | 1024 HeapIterator iterator(shared_info->GetHeap()); |
1019 for (HeapObject* obj = iterator.next(); obj != NULL; | 1025 for (HeapObject* obj = iterator.next(); obj != NULL; |
1020 obj = iterator.next()) { | 1026 obj = iterator.next()) { |
1021 if (obj->IsJSFunction()) { | 1027 if (obj->IsJSFunction()) { |
1022 JSFunction* function = JSFunction::cast(obj); | 1028 JSFunction* function = JSFunction::cast(obj); |
1023 if (function->shared() == shared_info) { | 1029 if (function->shared() == shared_info) { |
1024 visitor->visit(function); | 1030 visitor->visit(function); |
1025 } | 1031 } |
1026 } | 1032 } |
1027 } | 1033 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 void LiveEdit::ReplaceFunctionCode( | 1158 void LiveEdit::ReplaceFunctionCode( |
1153 Handle<JSArray> new_compile_info_array, | 1159 Handle<JSArray> new_compile_info_array, |
1154 Handle<JSArray> shared_info_array) { | 1160 Handle<JSArray> shared_info_array) { |
1155 Isolate* isolate = new_compile_info_array->GetIsolate(); | 1161 Isolate* isolate = new_compile_info_array->GetIsolate(); |
1156 | 1162 |
1157 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); | 1163 FunctionInfoWrapper compile_info_wrapper(new_compile_info_array); |
1158 SharedInfoWrapper shared_info_wrapper(shared_info_array); | 1164 SharedInfoWrapper shared_info_wrapper(shared_info_array); |
1159 | 1165 |
1160 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); | 1166 Handle<SharedFunctionInfo> shared_info = shared_info_wrapper.GetInfo(); |
1161 | 1167 |
1162 isolate->heap()->MakeHeapIterable(); | 1168 isolate->heap()->EnsureHeapIsIterable(); |
1163 | 1169 |
1164 if (IsJSFunctionCode(shared_info->code())) { | 1170 if (IsJSFunctionCode(shared_info->code())) { |
1165 Handle<Code> code = compile_info_wrapper.GetFunctionCode(); | 1171 Handle<Code> code = compile_info_wrapper.GetFunctionCode(); |
1166 ReplaceCodeObject(Handle<Code>(shared_info->code()), code); | 1172 ReplaceCodeObject(Handle<Code>(shared_info->code()), code); |
1167 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); | 1173 Handle<Object> code_scope_info = compile_info_wrapper.GetCodeScopeInfo(); |
1168 if (code_scope_info->IsFixedArray()) { | 1174 if (code_scope_info->IsFixedArray()) { |
1169 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); | 1175 shared_info->set_scope_info(ScopeInfo::cast(*code_scope_info)); |
1170 } | 1176 } |
1171 shared_info->DisableOptimization(kLiveEdit); | 1177 shared_info->DisableOptimization(kLiveEdit); |
1172 // Update the type feedback vector | 1178 // Update the type feedback vector |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1389 position_change_array); | 1395 position_change_array); |
1390 int new_function_end = TranslatePosition(info->end_position(), | 1396 int new_function_end = TranslatePosition(info->end_position(), |
1391 position_change_array); | 1397 position_change_array); |
1392 int new_function_token_pos = | 1398 int new_function_token_pos = |
1393 TranslatePosition(info->function_token_position(), position_change_array); | 1399 TranslatePosition(info->function_token_position(), position_change_array); |
1394 | 1400 |
1395 info->set_start_position(new_function_start); | 1401 info->set_start_position(new_function_start); |
1396 info->set_end_position(new_function_end); | 1402 info->set_end_position(new_function_end); |
1397 info->set_function_token_position(new_function_token_pos); | 1403 info->set_function_token_position(new_function_token_pos); |
1398 | 1404 |
1399 info->GetIsolate()->heap()->MakeHeapIterable(); | 1405 info->GetIsolate()->heap()->EnsureHeapIsIterable(); |
1400 | 1406 |
1401 if (IsJSFunctionCode(info->code())) { | 1407 if (IsJSFunctionCode(info->code())) { |
1402 // Patch relocation info section of the code. | 1408 // Patch relocation info section of the code. |
1403 Handle<Code> patched_code = PatchPositionsInCode(Handle<Code>(info->code()), | 1409 Handle<Code> patched_code = PatchPositionsInCode(Handle<Code>(info->code()), |
1404 position_change_array); | 1410 position_change_array); |
1405 if (*patched_code != info->code()) { | 1411 if (*patched_code != info->code()) { |
1406 // Replace all references to the code across the heap. In particular, | 1412 // Replace all references to the code across the heap. In particular, |
1407 // some stubs may refer to this code and this code may be being executed | 1413 // some stubs may refer to this code and this code may be being executed |
1408 // on stack (it is safe to substitute the code object on stack, because | 1414 // on stack (it is safe to substitute the code object on stack, because |
1409 // we only change the structure of rinfo and leave instructions | 1415 // we only change the structure of rinfo and leave instructions |
(...skipping 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1964 void LiveEditFunctionTracker::RecordRootFunctionInfo(Handle<Code> code) { | 1970 void LiveEditFunctionTracker::RecordRootFunctionInfo(Handle<Code> code) { |
1965 isolate_->active_function_info_listener()->FunctionCode(code); | 1971 isolate_->active_function_info_listener()->FunctionCode(code); |
1966 } | 1972 } |
1967 | 1973 |
1968 | 1974 |
1969 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { | 1975 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) { |
1970 return isolate->active_function_info_listener() != NULL; | 1976 return isolate->active_function_info_listener() != NULL; |
1971 } | 1977 } |
1972 | 1978 |
1973 } } // namespace v8::internal | 1979 } } // namespace v8::internal |
OLD | NEW |