| 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/factory.h" | 5 #include "src/factory.h" |
| 6 | 6 |
| 7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
| 8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 1189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 PretenureFlag pretenure) { | 1200 PretenureFlag pretenure) { |
| 1201 AllocationSpace space = pretenure == TENURED ? OLD_SPACE : NEW_SPACE; | 1201 AllocationSpace space = pretenure == TENURED ? OLD_SPACE : NEW_SPACE; |
| 1202 Handle<JSFunction> function = New<JSFunction>(map, space); | 1202 Handle<JSFunction> function = New<JSFunction>(map, space); |
| 1203 | 1203 |
| 1204 function->initialize_properties(); | 1204 function->initialize_properties(); |
| 1205 function->initialize_elements(); | 1205 function->initialize_elements(); |
| 1206 function->set_shared(*info); | 1206 function->set_shared(*info); |
| 1207 function->set_code(info->code()); | 1207 function->set_code(info->code()); |
| 1208 function->set_context(*context); | 1208 function->set_context(*context); |
| 1209 function->set_prototype_or_initial_map(*the_hole_value()); | 1209 function->set_prototype_or_initial_map(*the_hole_value()); |
| 1210 function->set_literals(LiteralsArray::cast(*empty_fixed_array())); | 1210 function->set_literals(LiteralsArray::cast(*empty_literals_array())); |
| 1211 function->set_next_function_link(*undefined_value(), SKIP_WRITE_BARRIER); | 1211 function->set_next_function_link(*undefined_value(), SKIP_WRITE_BARRIER); |
| 1212 isolate()->heap()->InitializeJSObjectBody(*function, *map, JSFunction::kSize); | 1212 isolate()->heap()->InitializeJSObjectBody(*function, *map, JSFunction::kSize); |
| 1213 return function; | 1213 return function; |
| 1214 } | 1214 } |
| 1215 | 1215 |
| 1216 | 1216 |
| 1217 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, | 1217 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, |
| 1218 Handle<String> name, | 1218 Handle<String> name, |
| 1219 MaybeHandle<Code> code) { | 1219 MaybeHandle<Code> code) { |
| 1220 Handle<Context> context(isolate()->native_context()); | 1220 Handle<Context> context(isolate()->native_context()); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 context->native_context(), BailoutId::None()); | 1366 context->native_context(), BailoutId::None()); |
| 1367 if (cached.code != nullptr) { | 1367 if (cached.code != nullptr) { |
| 1368 // Caching of optimized code enabled and optimized code found. | 1368 // Caching of optimized code enabled and optimized code found. |
| 1369 DCHECK(!cached.code->marked_for_deoptimization()); | 1369 DCHECK(!cached.code->marked_for_deoptimization()); |
| 1370 DCHECK(result->shared()->is_compiled()); | 1370 DCHECK(result->shared()->is_compiled()); |
| 1371 result->ReplaceCode(cached.code); | 1371 result->ReplaceCode(cached.code); |
| 1372 } | 1372 } |
| 1373 | 1373 |
| 1374 if (cached.literals != nullptr) { | 1374 if (cached.literals != nullptr) { |
| 1375 result->set_literals(cached.literals); | 1375 result->set_literals(cached.literals); |
| 1376 } else { | 1376 } else if (info->is_compiled()) { |
| 1377 int number_of_literals = info->num_literals(); | 1377 int number_of_literals = info->num_literals(); |
| 1378 Handle<TypeFeedbackVector> vector = |
| 1379 TypeFeedbackVector::New(isolate(), handle(info->feedback_metadata())); |
| 1378 Handle<LiteralsArray> literals = | 1380 Handle<LiteralsArray> literals = |
| 1379 LiteralsArray::New(isolate(), handle(info->feedback_vector()), | 1381 LiteralsArray::New(isolate(), vector, number_of_literals, pretenure); |
| 1380 number_of_literals, pretenure); | |
| 1381 result->set_literals(*literals); | 1382 result->set_literals(*literals); |
| 1382 | 1383 |
| 1383 // Cache context-specific literals. | 1384 // Cache context-specific literals. |
| 1384 Handle<Context> native_context(context->native_context()); | 1385 Handle<Context> native_context(context->native_context()); |
| 1385 SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(info, native_context, | 1386 SharedFunctionInfo::AddLiteralsToOptimizedCodeMap(info, native_context, |
| 1386 literals); | 1387 literals); |
| 1387 } | 1388 } |
| 1388 | 1389 |
| 1389 return result; | 1390 return result; |
| 1390 } | 1391 } |
| (...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2080 heap->InitializeJSObjectFromMap(*object, *properties, *map); | 2081 heap->InitializeJSObjectFromMap(*object, *properties, *map); |
| 2081 | 2082 |
| 2082 // Restore the saved hash. | 2083 // Restore the saved hash. |
| 2083 object->set_hash(*hash); | 2084 object->set_hash(*hash); |
| 2084 } | 2085 } |
| 2085 | 2086 |
| 2086 | 2087 |
| 2087 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( | 2088 Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( |
| 2088 Handle<String> name, int number_of_literals, FunctionKind kind, | 2089 Handle<String> name, int number_of_literals, FunctionKind kind, |
| 2089 Handle<Code> code, Handle<ScopeInfo> scope_info, | 2090 Handle<Code> code, Handle<ScopeInfo> scope_info, |
| 2090 Handle<TypeFeedbackVector> feedback_vector) { | 2091 Handle<TypeFeedbackMetadata> feedback_metadata) { |
| 2091 DCHECK(IsValidFunctionKind(kind)); | 2092 DCHECK(IsValidFunctionKind(kind)); |
| 2092 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo( | 2093 Handle<SharedFunctionInfo> shared = NewSharedFunctionInfo( |
| 2093 name, code, IsConstructable(kind, scope_info->language_mode())); | 2094 name, code, IsConstructable(kind, scope_info->language_mode())); |
| 2094 shared->set_scope_info(*scope_info); | 2095 shared->set_scope_info(*scope_info); |
| 2095 shared->set_feedback_vector(*feedback_vector); | 2096 shared->set_feedback_metadata(*feedback_metadata); |
| 2096 shared->set_kind(kind); | 2097 shared->set_kind(kind); |
| 2097 shared->set_num_literals(number_of_literals); | 2098 shared->set_num_literals(number_of_literals); |
| 2098 if (IsGeneratorFunction(kind)) { | 2099 if (IsGeneratorFunction(kind)) { |
| 2099 shared->set_instance_class_name(isolate()->heap()->Generator_string()); | 2100 shared->set_instance_class_name(isolate()->heap()->Generator_string()); |
| 2100 shared->DisableOptimization(kGenerator); | 2101 shared->DisableOptimization(kGenerator); |
| 2101 } | 2102 } |
| 2102 return shared; | 2103 return shared; |
| 2103 } | 2104 } |
| 2104 | 2105 |
| 2105 | 2106 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2141 : isolate()->builtins()->ConstructedNonConstructable(); | 2142 : isolate()->builtins()->ConstructedNonConstructable(); |
| 2142 share->set_construct_stub(*construct_stub); | 2143 share->set_construct_stub(*construct_stub); |
| 2143 share->set_instance_class_name(*Object_string()); | 2144 share->set_instance_class_name(*Object_string()); |
| 2144 share->set_function_data(*undefined_value(), SKIP_WRITE_BARRIER); | 2145 share->set_function_data(*undefined_value(), SKIP_WRITE_BARRIER); |
| 2145 share->set_script(*undefined_value(), SKIP_WRITE_BARRIER); | 2146 share->set_script(*undefined_value(), SKIP_WRITE_BARRIER); |
| 2146 share->set_debug_info(*undefined_value(), SKIP_WRITE_BARRIER); | 2147 share->set_debug_info(*undefined_value(), SKIP_WRITE_BARRIER); |
| 2147 share->set_inferred_name(*empty_string(), SKIP_WRITE_BARRIER); | 2148 share->set_inferred_name(*empty_string(), SKIP_WRITE_BARRIER); |
| 2148 StaticFeedbackVectorSpec empty_spec; | 2149 StaticFeedbackVectorSpec empty_spec; |
| 2149 Handle<TypeFeedbackMetadata> feedback_metadata = | 2150 Handle<TypeFeedbackMetadata> feedback_metadata = |
| 2150 TypeFeedbackMetadata::New(isolate(), &empty_spec); | 2151 TypeFeedbackMetadata::New(isolate(), &empty_spec); |
| 2151 Handle<TypeFeedbackVector> feedback_vector = | 2152 share->set_feedback_metadata(*feedback_metadata, SKIP_WRITE_BARRIER); |
| 2152 TypeFeedbackVector::New(isolate(), feedback_metadata); | |
| 2153 share->set_feedback_vector(*feedback_vector, SKIP_WRITE_BARRIER); | |
| 2154 #if TRACE_MAPS | 2153 #if TRACE_MAPS |
| 2155 share->set_unique_id(isolate()->GetNextUniqueSharedFunctionInfoId()); | 2154 share->set_unique_id(isolate()->GetNextUniqueSharedFunctionInfoId()); |
| 2156 #endif | 2155 #endif |
| 2157 share->set_profiler_ticks(0); | 2156 share->set_profiler_ticks(0); |
| 2158 share->set_ast_node_count(0); | 2157 share->set_ast_node_count(0); |
| 2159 share->set_counters(0); | 2158 share->set_counters(0); |
| 2160 | 2159 |
| 2161 // Set integer fields (smi or int, depending on the architecture). | 2160 // Set integer fields (smi or int, depending on the architecture). |
| 2162 share->set_length(0); | 2161 share->set_length(0); |
| 2163 share->set_internal_formal_parameter_count(0); | 2162 share->set_internal_formal_parameter_count(0); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2398 } | 2397 } |
| 2399 | 2398 |
| 2400 | 2399 |
| 2401 Handle<Object> Factory::ToBoolean(bool value) { | 2400 Handle<Object> Factory::ToBoolean(bool value) { |
| 2402 return value ? true_value() : false_value(); | 2401 return value ? true_value() : false_value(); |
| 2403 } | 2402 } |
| 2404 | 2403 |
| 2405 | 2404 |
| 2406 } // namespace internal | 2405 } // namespace internal |
| 2407 } // namespace v8 | 2406 } // namespace v8 |
| OLD | NEW |