| 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 #include "src/api.h" | 5 #include "src/api.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
| 8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
| 9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
| 10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 } | 393 } |
| 394 | 394 |
| 395 ArrayBufferAllocator allocator_; | 395 ArrayBufferAllocator allocator_; |
| 396 Isolate* isolate_; | 396 Isolate* isolate_; |
| 397 PersistentValueVector<Context> contexts_; | 397 PersistentValueVector<Context> contexts_; |
| 398 bool created_; | 398 bool created_; |
| 399 }; | 399 }; |
| 400 | 400 |
| 401 } // namespace | 401 } // namespace |
| 402 | 402 |
| 403 SnapshotCreator::SnapshotCreator(StartupData* existing_snapshot) { | 403 SnapshotCreator::SnapshotCreator(intptr_t* external_references, |
| 404 StartupData* existing_snapshot) { |
| 404 i::Isolate* internal_isolate = new i::Isolate(true); | 405 i::Isolate* internal_isolate = new i::Isolate(true); |
| 405 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); | 406 Isolate* isolate = reinterpret_cast<Isolate*>(internal_isolate); |
| 406 SnapshotCreatorData* data = new SnapshotCreatorData(isolate); | 407 SnapshotCreatorData* data = new SnapshotCreatorData(isolate); |
| 407 data->isolate_ = isolate; | 408 data->isolate_ = isolate; |
| 408 internal_isolate->set_array_buffer_allocator(&data->allocator_); | 409 internal_isolate->set_array_buffer_allocator(&data->allocator_); |
| 410 internal_isolate->set_api_external_references(external_references); |
| 409 isolate->Enter(); | 411 isolate->Enter(); |
| 410 if (existing_snapshot) { | 412 if (existing_snapshot) { |
| 411 internal_isolate->set_snapshot_blob(existing_snapshot); | 413 internal_isolate->set_snapshot_blob(existing_snapshot); |
| 412 i::Snapshot::Initialize(internal_isolate); | 414 i::Snapshot::Initialize(internal_isolate); |
| 413 } else { | 415 } else { |
| 414 internal_isolate->Init(nullptr); | 416 internal_isolate->Init(nullptr); |
| 415 } | 417 } |
| 416 data_ = data; | 418 data_ = data; |
| 417 } | 419 } |
| 418 | 420 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 // Use following steps to create a warmed up snapshot blob from a cold one: | 526 // Use following steps to create a warmed up snapshot blob from a cold one: |
| 525 // - Create a new isolate from the cold snapshot. | 527 // - Create a new isolate from the cold snapshot. |
| 526 // - Create a new context to run the warmup script. This will trigger | 528 // - Create a new context to run the warmup script. This will trigger |
| 527 // compilation of executed functions. | 529 // compilation of executed functions. |
| 528 // - Create a new context. This context will be unpolluted. | 530 // - Create a new context. This context will be unpolluted. |
| 529 // - Serialize the isolate and the second context into a new snapshot blob. | 531 // - Serialize the isolate and the second context into a new snapshot blob. |
| 530 StartupData result = {nullptr, 0}; | 532 StartupData result = {nullptr, 0}; |
| 531 base::ElapsedTimer timer; | 533 base::ElapsedTimer timer; |
| 532 timer.Start(); | 534 timer.Start(); |
| 533 { | 535 { |
| 534 SnapshotCreator snapshot_creator(&cold_snapshot_blob); | 536 SnapshotCreator snapshot_creator(nullptr, &cold_snapshot_blob); |
| 535 Isolate* isolate = snapshot_creator.GetIsolate(); | 537 Isolate* isolate = snapshot_creator.GetIsolate(); |
| 536 { | 538 { |
| 537 HandleScope scope(isolate); | 539 HandleScope scope(isolate); |
| 538 Local<Context> context = Context::New(isolate); | 540 Local<Context> context = Context::New(isolate); |
| 539 if (!RunExtraCode(isolate, context, warmup_source, "<warm-up>")) { | 541 if (!RunExtraCode(isolate, context, warmup_source, "<warm-up>")) { |
| 540 return result; | 542 return result; |
| 541 } | 543 } |
| 542 } | 544 } |
| 543 { | 545 { |
| 544 HandleScope handle_scope(isolate); | 546 HandleScope handle_scope(isolate); |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, | 1133 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, |
| 1132 v8::Local<Signature> signature, int length, bool do_not_cache) { | 1134 v8::Local<Signature> signature, int length, bool do_not_cache) { |
| 1133 i::Handle<i::Struct> struct_obj = | 1135 i::Handle<i::Struct> struct_obj = |
| 1134 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); | 1136 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
| 1135 i::Handle<i::FunctionTemplateInfo> obj = | 1137 i::Handle<i::FunctionTemplateInfo> obj = |
| 1136 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); | 1138 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
| 1137 InitializeFunctionTemplate(obj); | 1139 InitializeFunctionTemplate(obj); |
| 1138 obj->set_do_not_cache(do_not_cache); | 1140 obj->set_do_not_cache(do_not_cache); |
| 1139 int next_serial_number = 0; | 1141 int next_serial_number = 0; |
| 1140 if (!do_not_cache) { | 1142 if (!do_not_cache) { |
| 1141 next_serial_number = isolate->next_serial_number() + 1; | 1143 next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); |
| 1142 isolate->set_next_serial_number(next_serial_number); | |
| 1143 } | 1144 } |
| 1144 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); | 1145 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
| 1145 if (callback != 0) { | 1146 if (callback != 0) { |
| 1146 if (data.IsEmpty()) { | 1147 if (data.IsEmpty()) { |
| 1147 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1148 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1148 } | 1149 } |
| 1149 Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler); | 1150 Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler); |
| 1150 } | 1151 } |
| 1151 obj->set_length(length); | 1152 obj->set_length(length); |
| 1152 obj->set_undetectable(false); | 1153 obj->set_undetectable(false); |
| 1153 obj->set_needs_access_check(false); | 1154 obj->set_needs_access_check(false); |
| 1154 obj->set_accept_any_receiver(true); | 1155 obj->set_accept_any_receiver(true); |
| 1155 if (!signature.IsEmpty()) | 1156 if (!signature.IsEmpty()) |
| 1156 obj->set_signature(*Utils::OpenHandle(*signature)); | 1157 obj->set_signature(*Utils::OpenHandle(*signature)); |
| 1157 return Utils::ToLocal(obj); | 1158 return Utils::ToLocal(obj); |
| 1158 } | 1159 } |
| 1159 | 1160 |
| 1160 | 1161 |
| 1161 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, | 1162 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, |
| 1162 FunctionCallback callback, | 1163 FunctionCallback callback, |
| 1163 v8::Local<Value> data, | 1164 v8::Local<Value> data, |
| 1164 v8::Local<Signature> signature, | 1165 v8::Local<Signature> signature, |
| 1165 int length) { | 1166 int length) { |
| 1166 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | 1167 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
| 1167 // Changes to the environment cannot be captured in the snapshot. Expect no | 1168 // Changes to the environment cannot be captured in the snapshot. Expect no |
| 1168 // function templates when the isolate is created for serialization. | 1169 // function templates when the isolate is created for serialization. |
| 1169 DCHECK(!i_isolate->serializer_enabled()); | |
| 1170 LOG_API(i_isolate, FunctionTemplate, New); | 1170 LOG_API(i_isolate, FunctionTemplate, New); |
| 1171 ENTER_V8(i_isolate); | 1171 ENTER_V8(i_isolate); |
| 1172 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature, | 1172 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature, |
| 1173 length, false); | 1173 length, false); |
| 1174 } | 1174 } |
| 1175 | 1175 |
| 1176 | 1176 |
| 1177 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler( | 1177 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler( |
| 1178 Isolate* isolate, FunctionCallback callback, | 1178 Isolate* isolate, FunctionCallback callback, |
| 1179 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, | 1179 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data, |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1354 } | 1354 } |
| 1355 | 1355 |
| 1356 | 1356 |
| 1357 Local<ObjectTemplate> ObjectTemplate::New() { | 1357 Local<ObjectTemplate> ObjectTemplate::New() { |
| 1358 return New(i::Isolate::Current(), Local<FunctionTemplate>()); | 1358 return New(i::Isolate::Current(), Local<FunctionTemplate>()); |
| 1359 } | 1359 } |
| 1360 | 1360 |
| 1361 static Local<ObjectTemplate> ObjectTemplateNew( | 1361 static Local<ObjectTemplate> ObjectTemplateNew( |
| 1362 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor, | 1362 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor, |
| 1363 bool do_not_cache) { | 1363 bool do_not_cache) { |
| 1364 // Changes to the environment cannot be captured in the snapshot. Expect no | |
| 1365 // object templates when the isolate is created for serialization. | |
| 1366 DCHECK(!isolate->serializer_enabled()); | |
| 1367 LOG_API(isolate, ObjectTemplate, New); | 1364 LOG_API(isolate, ObjectTemplate, New); |
| 1368 ENTER_V8(isolate); | 1365 ENTER_V8(isolate); |
| 1369 i::Handle<i::Struct> struct_obj = | 1366 i::Handle<i::Struct> struct_obj = |
| 1370 isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); | 1367 isolate->factory()->NewStruct(i::OBJECT_TEMPLATE_INFO_TYPE); |
| 1371 i::Handle<i::ObjectTemplateInfo> obj = | 1368 i::Handle<i::ObjectTemplateInfo> obj = |
| 1372 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); | 1369 i::Handle<i::ObjectTemplateInfo>::cast(struct_obj); |
| 1373 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); | 1370 InitializeTemplate(obj, Consts::OBJECT_TEMPLATE); |
| 1374 int next_serial_number = 0; | 1371 int next_serial_number = 0; |
| 1375 if (!do_not_cache) { | 1372 if (!do_not_cache) { |
| 1376 next_serial_number = isolate->next_serial_number() + 1; | 1373 next_serial_number = isolate->heap()->GetNextTemplateSerialNumber(); |
| 1377 isolate->set_next_serial_number(next_serial_number); | |
| 1378 } | 1374 } |
| 1379 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); | 1375 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
| 1380 if (!constructor.IsEmpty()) | 1376 if (!constructor.IsEmpty()) |
| 1381 obj->set_constructor(*Utils::OpenHandle(*constructor)); | 1377 obj->set_constructor(*Utils::OpenHandle(*constructor)); |
| 1382 obj->set_internal_field_count(i::Smi::FromInt(0)); | 1378 obj->set_internal_field_count(i::Smi::FromInt(0)); |
| 1383 return Utils::ToLocal(obj); | 1379 return Utils::ToLocal(obj); |
| 1384 } | 1380 } |
| 1385 | 1381 |
| 1386 Local<ObjectTemplate> ObjectTemplate::New( | 1382 Local<ObjectTemplate> ObjectTemplate::New( |
| 1387 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) { | 1383 i::Isolate* isolate, v8::Local<FunctionTemplate> constructor) { |
| (...skipping 5884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7272 } | 7268 } |
| 7273 | 7269 |
| 7274 if (params.create_histogram_callback) { | 7270 if (params.create_histogram_callback) { |
| 7275 v8_isolate->SetCreateHistogramFunction(params.create_histogram_callback); | 7271 v8_isolate->SetCreateHistogramFunction(params.create_histogram_callback); |
| 7276 } | 7272 } |
| 7277 | 7273 |
| 7278 if (params.add_histogram_sample_callback) { | 7274 if (params.add_histogram_sample_callback) { |
| 7279 v8_isolate->SetAddHistogramSampleFunction( | 7275 v8_isolate->SetAddHistogramSampleFunction( |
| 7280 params.add_histogram_sample_callback); | 7276 params.add_histogram_sample_callback); |
| 7281 } | 7277 } |
| 7278 |
| 7279 isolate->set_api_external_references(params.external_references); |
| 7282 SetResourceConstraints(isolate, params.constraints); | 7280 SetResourceConstraints(isolate, params.constraints); |
| 7283 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. | 7281 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. |
| 7284 Isolate::Scope isolate_scope(v8_isolate); | 7282 Isolate::Scope isolate_scope(v8_isolate); |
| 7285 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) { | 7283 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) { |
| 7286 isolate->Init(NULL); | 7284 isolate->Init(NULL); |
| 7287 } | 7285 } |
| 7288 return v8_isolate; | 7286 return v8_isolate; |
| 7289 } | 7287 } |
| 7290 | 7288 |
| 7291 | 7289 |
| (...skipping 1532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8824 Address callback_address = | 8822 Address callback_address = |
| 8825 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8823 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8826 VMState<EXTERNAL> state(isolate); | 8824 VMState<EXTERNAL> state(isolate); |
| 8827 ExternalCallbackScope call_scope(isolate, callback_address); | 8825 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8828 callback(info); | 8826 callback(info); |
| 8829 } | 8827 } |
| 8830 | 8828 |
| 8831 | 8829 |
| 8832 } // namespace internal | 8830 } // namespace internal |
| 8833 } // namespace v8 | 8831 } // namespace v8 |
| OLD | NEW |