OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/frames-inl.h" | 10 #include "src/frames-inl.h" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 source_shared->set_dont_flush(true); | 165 source_shared->set_dont_flush(true); |
166 | 166 |
167 // Set the code, scope info, formal parameter count, and the length | 167 // Set the code, scope info, formal parameter count, and the length |
168 // of the target shared function info. | 168 // of the target shared function info. |
169 target_shared->ReplaceCode(source_shared->code()); | 169 target_shared->ReplaceCode(source_shared->code()); |
170 if (source_shared->HasBytecodeArray()) { | 170 if (source_shared->HasBytecodeArray()) { |
171 target_shared->set_function_data(source_shared->bytecode_array()); | 171 target_shared->set_function_data(source_shared->bytecode_array()); |
172 } | 172 } |
173 target_shared->set_scope_info(source_shared->scope_info()); | 173 target_shared->set_scope_info(source_shared->scope_info()); |
174 target_shared->set_length(source_shared->length()); | 174 target_shared->set_length(source_shared->length()); |
175 target_shared->set_feedback_metadata(source_shared->feedback_metadata()); | 175 target_shared->set_feedback_vector(source_shared->feedback_vector()); |
176 target_shared->set_num_literals(source_shared->num_literals()); | |
177 target_shared->set_internal_formal_parameter_count( | 176 target_shared->set_internal_formal_parameter_count( |
178 source_shared->internal_formal_parameter_count()); | 177 source_shared->internal_formal_parameter_count()); |
179 target_shared->set_start_position_and_type( | 178 target_shared->set_start_position_and_type( |
180 source_shared->start_position_and_type()); | 179 source_shared->start_position_and_type()); |
181 target_shared->set_end_position(source_shared->end_position()); | 180 target_shared->set_end_position(source_shared->end_position()); |
182 bool was_native = target_shared->native(); | 181 bool was_native = target_shared->native(); |
183 target_shared->set_compiler_hints(source_shared->compiler_hints()); | 182 target_shared->set_compiler_hints(source_shared->compiler_hints()); |
184 target_shared->set_opt_count_and_bailout_reason( | 183 target_shared->set_opt_count_and_bailout_reason( |
185 source_shared->opt_count_and_bailout_reason()); | 184 source_shared->opt_count_and_bailout_reason()); |
186 target_shared->set_native(was_native); | 185 target_shared->set_native(was_native); |
187 target_shared->set_profiler_ticks(source_shared->profiler_ticks()); | 186 target_shared->set_profiler_ticks(source_shared->profiler_ticks()); |
188 SharedFunctionInfo::SetScript( | 187 SharedFunctionInfo::SetScript( |
189 target_shared, Handle<Object>(source_shared->script(), isolate)); | 188 target_shared, Handle<Object>(source_shared->script(), isolate)); |
190 | 189 |
191 // Set the code of the target function. | 190 // Set the code of the target function. |
192 target->ReplaceCode(source_shared->code()); | 191 target->ReplaceCode(source_shared->code()); |
193 DCHECK(target->next_function_link()->IsUndefined()); | 192 DCHECK(target->next_function_link()->IsUndefined()); |
194 | 193 |
| 194 // Make sure we get a fresh copy of the literal vector to avoid cross |
| 195 // context contamination. |
195 Handle<Context> context(source->context()); | 196 Handle<Context> context(source->context()); |
196 target->set_context(*context); | 197 target->set_context(*context); |
197 | 198 |
198 // Make sure we get a fresh copy of the literal vector to avoid cross | 199 int number_of_literals = source->NumberOfLiterals(); |
199 // context contamination, and that the literal vector makes it's way into | 200 Handle<LiteralsArray> literals = |
200 // the target_shared optimized code map. | 201 LiteralsArray::New(isolate, handle(target_shared->feedback_vector()), |
201 JSFunction::EnsureLiterals(target); | 202 number_of_literals, TENURED); |
| 203 target->set_literals(*literals); |
202 | 204 |
203 if (isolate->logger()->is_logging_code_events() || | 205 if (isolate->logger()->is_logging_code_events() || |
204 isolate->cpu_profiler()->is_profiling()) { | 206 isolate->cpu_profiler()->is_profiling()) { |
205 isolate->logger()->LogExistingFunction(source_shared, | 207 isolate->logger()->LogExistingFunction(source_shared, |
206 Handle<Code>(source_shared->code())); | 208 Handle<Code>(source_shared->code())); |
207 } | 209 } |
208 | 210 |
209 return *target; | 211 return *target; |
210 } | 212 } |
211 | 213 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 DCHECK_EQ(1, args.length()); | 356 DCHECK_EQ(1, args.length()); |
355 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); | 357 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, function, 0); |
356 return function->IsJSBoundFunction() | 358 return function->IsJSBoundFunction() |
357 ? *JSBoundFunction::ToString( | 359 ? *JSBoundFunction::ToString( |
358 Handle<JSBoundFunction>::cast(function)) | 360 Handle<JSBoundFunction>::cast(function)) |
359 : *JSFunction::ToString(Handle<JSFunction>::cast(function)); | 361 : *JSFunction::ToString(Handle<JSFunction>::cast(function)); |
360 } | 362 } |
361 | 363 |
362 } // namespace internal | 364 } // namespace internal |
363 } // namespace v8 | 365 } // namespace v8 |
OLD | NEW |