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

Side by Side Diff: src/api.cc

Issue 1474543004: Implement Fast Accessor Builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years 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
OLDNEW
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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 #include "src/simulator.h" 52 #include "src/simulator.h"
53 #include "src/snapshot/natives.h" 53 #include "src/snapshot/natives.h"
54 #include "src/snapshot/snapshot.h" 54 #include "src/snapshot/snapshot.h"
55 #include "src/startup-data-util.h" 55 #include "src/startup-data-util.h"
56 #include "src/unicode-inl.h" 56 #include "src/unicode-inl.h"
57 #include "src/v8.h" 57 #include "src/v8.h"
58 #include "src/v8threads.h" 58 #include "src/v8threads.h"
59 #include "src/version.h" 59 #include "src/version.h"
60 #include "src/vm-state-inl.h" 60 #include "src/vm-state-inl.h"
61 61
62 // ???
63 #include "src/compiler/fast-accessor-assembler.h"
64
62 65
63 namespace v8 { 66 namespace v8 {
64 67
65 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) 68 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
66 69
67 70
68 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate)) 71 #define ENTER_V8(isolate) i::VMState<v8::OTHER> __state__((isolate))
69 72
70 73
71 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \ 74 #define PREPARE_FOR_EXECUTION_GENERIC(isolate, context, function_name, \
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
989 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { 992 void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) {
990 auto info = Utils::OpenHandle(this); 993 auto info = Utils::OpenHandle(this);
991 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit"); 994 EnsureNotInstantiated(info, "v8::FunctionTemplate::Inherit");
992 i::Isolate* isolate = info->GetIsolate(); 995 i::Isolate* isolate = info->GetIsolate();
993 ENTER_V8(isolate); 996 ENTER_V8(isolate);
994 info->set_parent_template(*Utils::OpenHandle(*value)); 997 info->set_parent_template(*Utils::OpenHandle(*value));
995 } 998 }
996 999
997 1000
998 static Local<FunctionTemplate> FunctionTemplateNew( 1001 static Local<FunctionTemplate> FunctionTemplateNew(
999 i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, 1002 i::Isolate* isolate, FunctionCallback callback,
1003 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data,
1000 v8::Local<Signature> signature, int length, bool do_not_cache) { 1004 v8::Local<Signature> signature, int length, bool do_not_cache) {
1001 i::Handle<i::Struct> struct_obj = 1005 i::Handle<i::Struct> struct_obj =
1002 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); 1006 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE);
1003 i::Handle<i::FunctionTemplateInfo> obj = 1007 i::Handle<i::FunctionTemplateInfo> obj =
1004 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); 1008 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj);
1005 InitializeFunctionTemplate(obj); 1009 InitializeFunctionTemplate(obj);
1006 obj->set_do_not_cache(do_not_cache); 1010 obj->set_do_not_cache(do_not_cache);
1007 int next_serial_number = 0; 1011 int next_serial_number = 0;
1008 if (!do_not_cache) { 1012 if (!do_not_cache) {
1009 next_serial_number = isolate->next_serial_number() + 1; 1013 next_serial_number = isolate->next_serial_number() + 1;
1010 isolate->set_next_serial_number(next_serial_number); 1014 isolate->set_next_serial_number(next_serial_number);
1011 } 1015 }
1012 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); 1016 obj->set_serial_number(i::Smi::FromInt(next_serial_number));
1013 if (callback != 0) { 1017 if (callback != 0) {
1014 if (data.IsEmpty()) { 1018 if (data.IsEmpty()) {
1015 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 1019 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1016 } 1020 }
1017 Utils::ToLocal(obj)->SetCallHandler(callback, data); 1021 Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler);
1018 } 1022 }
1019 obj->set_length(length); 1023 obj->set_length(length);
1020 obj->set_undetectable(false); 1024 obj->set_undetectable(false);
1021 obj->set_needs_access_check(false); 1025 obj->set_needs_access_check(false);
1022 obj->set_accept_any_receiver(true); 1026 obj->set_accept_any_receiver(true);
1023 if (!signature.IsEmpty()) 1027 if (!signature.IsEmpty())
1024 obj->set_signature(*Utils::OpenHandle(*signature)); 1028 obj->set_signature(*Utils::OpenHandle(*signature));
1025 return Utils::ToLocal(obj); 1029 return Utils::ToLocal(obj);
1026 } 1030 }
1027 1031
1032
1028 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, 1033 Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate,
1029 FunctionCallback callback, 1034 FunctionCallback callback,
1030 v8::Local<Value> data, 1035 v8::Local<Value> data,
1031 v8::Local<Signature> signature, 1036 v8::Local<Signature> signature,
1032 int length) { 1037 int length) {
1033 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 1038 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1034 // Changes to the environment cannot be captured in the snapshot. Expect no 1039 // Changes to the environment cannot be captured in the snapshot. Expect no
1035 // function templates when the isolate is created for serialization. 1040 // function templates when the isolate is created for serialization.
1036 DCHECK(!i_isolate->serializer_enabled()); 1041 DCHECK(!i_isolate->serializer_enabled());
1037 LOG_API(i_isolate, "FunctionTemplate::New"); 1042 LOG_API(i_isolate, "FunctionTemplate::New");
1038 ENTER_V8(i_isolate); 1043 ENTER_V8(i_isolate);
1039 return FunctionTemplateNew( 1044 return FunctionTemplateNew(i_isolate, callback, nullptr, data, signature,
1040 i_isolate, callback, data, signature, length, false); 1045 length, false);
1041 } 1046 }
1042 1047
1043 1048
1049 Local<FunctionTemplate> FunctionTemplate::NewWithFastHandler(
1050 Isolate* isolate, FunctionCallback callback,
1051 experimental::FastAccessorBuilder* fast_handler, v8::Local<Value> data,
1052 v8::Local<Signature> signature, int length) {
1053 // TODO(vogelheim): 'fast_handler' should have a more specific type than
1054 // Local<Value>.
1055 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
1056 DCHECK(!i_isolate->serializer_enabled());
1057 LOG_API(i_isolate, "FunctionTemplate::NewWithFastHandler");
1058 ENTER_V8(i_isolate);
1059 return FunctionTemplateNew(i_isolate, callback, fast_handler, data, signature,
1060 length, false);
1061 }
1062
1063
1044 Local<Signature> Signature::New(Isolate* isolate, 1064 Local<Signature> Signature::New(Isolate* isolate,
1045 Local<FunctionTemplate> receiver) { 1065 Local<FunctionTemplate> receiver) {
1046 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); 1066 return Utils::SignatureToLocal(Utils::OpenHandle(*receiver));
1047 } 1067 }
1048 1068
1049 1069
1050 Local<AccessorSignature> AccessorSignature::New( 1070 Local<AccessorSignature> AccessorSignature::New(
1051 Isolate* isolate, Local<FunctionTemplate> receiver) { 1071 Isolate* isolate, Local<FunctionTemplate> receiver) {
1052 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver)); 1072 return Utils::AccessorSignatureToLocal(Utils::OpenHandle(*receiver));
1053 } 1073 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 return 0; 1107 return 0;
1088 } 1108 }
1089 1109
1090 1110
1091 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \ 1111 #define SET_FIELD_WRAPPED(obj, setter, cdata) do { \
1092 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \ 1112 i::Handle<i::Object> foreign = FromCData(obj->GetIsolate(), cdata); \
1093 (obj)->setter(*foreign); \ 1113 (obj)->setter(*foreign); \
1094 } while (false) 1114 } while (false)
1095 1115
1096 1116
1097 void FunctionTemplate::SetCallHandler(FunctionCallback callback, 1117 void FunctionTemplate::SetCallHandler(
1098 v8::Local<Value> data) { 1118 FunctionCallback callback, v8::Local<Value> data,
1119 experimental::FastAccessorBuilder* fast_handler) {
1099 auto info = Utils::OpenHandle(this); 1120 auto info = Utils::OpenHandle(this);
1100 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); 1121 EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler");
1101 i::Isolate* isolate = info->GetIsolate(); 1122 i::Isolate* isolate = info->GetIsolate();
1102 ENTER_V8(isolate); 1123 ENTER_V8(isolate);
1103 i::HandleScope scope(isolate); 1124 i::HandleScope scope(isolate);
1104 i::Handle<i::Struct> struct_obj = 1125 i::Handle<i::Struct> struct_obj =
1105 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); 1126 isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE);
1106 i::Handle<i::CallHandlerInfo> obj = 1127 i::Handle<i::CallHandlerInfo> obj =
1107 i::Handle<i::CallHandlerInfo>::cast(struct_obj); 1128 i::Handle<i::CallHandlerInfo>::cast(struct_obj);
1108 SET_FIELD_WRAPPED(obj, set_callback, callback); 1129 SET_FIELD_WRAPPED(obj, set_callback, callback);
1130
1131 if (fast_handler != nullptr) {
1132 auto faa = *reinterpret_cast<internal::compiler::FastAccessorAssembler**>(
1133 fast_handler);
1134 i::Handle<i::Code> code = faa->Build();
1135 CHECK(!code.is_null());
1136 obj->set_fast_handler(*code);
1137 delete fast_handler;
1138 }
1139
1109 if (data.IsEmpty()) { 1140 if (data.IsEmpty()) {
1110 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); 1141 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
1111 } 1142 }
1112 obj->set_data(*Utils::OpenHandle(*data)); 1143 obj->set_data(*Utils::OpenHandle(*data));
1113 info->set_call_code(*obj); 1144 info->set_call_code(*obj);
1114 } 1145 }
1115 1146
1116 1147
1117 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( 1148 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties(
1118 i::Handle<i::AccessorInfo> obj, v8::Local<Name> name, 1149 i::Handle<i::AccessorInfo> obj, v8::Local<Name> name,
(...skipping 3242 matching lines...) Expand 10 before | Expand all | Expand 10 after
4361 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value); 4392 RETURN_TO_LOCAL_UNCHECKED(CallAsConstructor(context, argc, argv_cast), Value);
4362 } 4393 }
4363 4394
4364 4395
4365 MaybeLocal<Function> Function::New(Local<Context> context, 4396 MaybeLocal<Function> Function::New(Local<Context> context,
4366 FunctionCallback callback, Local<Value> data, 4397 FunctionCallback callback, Local<Value> data,
4367 int length) { 4398 int length) {
4368 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate(); 4399 i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
4369 LOG_API(isolate, "Function::New"); 4400 LOG_API(isolate, "Function::New");
4370 ENTER_V8(isolate); 4401 ENTER_V8(isolate);
4371 return FunctionTemplateNew(isolate, callback, data, Local<Signature>(), 4402 return FunctionTemplateNew(isolate, callback, nullptr, data,
4372 length, true)->GetFunction(context); 4403 Local<Signature>(), length, true)
4404 ->GetFunction(context);
4373 } 4405 }
4374 4406
4375 4407
4376 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback, 4408 Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback,
4377 Local<Value> data, int length) { 4409 Local<Value> data, int length) {
4378 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length) 4410 return Function::New(v8_isolate->GetCurrentContext(), callback, data, length)
4379 .FromMaybe(Local<Function>()); 4411 .FromMaybe(Local<Function>());
4380 } 4412 }
4381 4413
4382 4414
(...skipping 3956 matching lines...) Expand 10 before | Expand all | Expand 10 after
8339 8371
8340 8372
8341 // TODO(svenpanne) Deprecate this. 8373 // TODO(svenpanne) Deprecate this.
8342 void Testing::DeoptimizeAll() { 8374 void Testing::DeoptimizeAll() {
8343 i::Isolate* isolate = i::Isolate::Current(); 8375 i::Isolate* isolate = i::Isolate::Current();
8344 i::HandleScope scope(isolate); 8376 i::HandleScope scope(isolate);
8345 internal::Deoptimizer::DeoptimizeAll(isolate); 8377 internal::Deoptimizer::DeoptimizeAll(isolate);
8346 } 8378 }
8347 8379
8348 8380
8381 namespace experimental {
8382
8383
8384 FastAccessorBuilder::FastAccessorBuilder() : impl_(nullptr) {}
8385
8386
8387 FastAccessorBuilder::~FastAccessorBuilder() {
8388 CHECK_NOT_NULL(impl_);
8389 delete reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_);
8390 }
8391
8392
8393 FastAccessorBuilder* FastAccessorBuilder::New(Isolate* isolate) {
8394 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
8395 internal::compiler::FastAccessorAssembler* faa =
8396 new internal::compiler::FastAccessorAssembler(i_isolate);
8397 FastAccessorBuilder* fab = new FastAccessorBuilder;
8398 fab->impl_ = faa;
8399 return fab;
8400 }
8401
8402 FastAccessorBuilder::ValueId FastAccessorBuilder::IntegerConstant(
8403 int const_value) {
8404 return reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_)
8405 ->IntegerConstant(const_value);
8406 }
8407
8408
8409 void FastAccessorBuilder::ReturnValue(ValueId value) {
8410 reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_)
8411 ->ReturnValue(value);
8412 }
8413
8414
8415 FastAccessorBuilder::ValueId FastAccessorBuilder::GetParameter(
8416 size_t parameter_no) {
8417 return reinterpret_cast<internal::compiler::FastAccessorAssembler*>(impl_)
8418 ->GetParameter(parameter_no);
8419 }
8420 } // namespace experimental
8421
8422
8349 namespace internal { 8423 namespace internal {
8350 8424
8351 8425
8352 void HandleScopeImplementer::FreeThreadResources() { 8426 void HandleScopeImplementer::FreeThreadResources() {
8353 Free(); 8427 Free();
8354 } 8428 }
8355 8429
8356 8430
8357 char* HandleScopeImplementer::ArchiveThread(char* storage) { 8431 char* HandleScopeImplementer::ArchiveThread(char* storage) {
8358 HandleScopeData* current = isolate_->handle_scope_data(); 8432 HandleScopeData* current = isolate_->handle_scope_data();
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
8510 Address callback_address = 8584 Address callback_address =
8511 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8585 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8512 VMState<EXTERNAL> state(isolate); 8586 VMState<EXTERNAL> state(isolate);
8513 ExternalCallbackScope call_scope(isolate, callback_address); 8587 ExternalCallbackScope call_scope(isolate, callback_address);
8514 callback(info); 8588 callback(info);
8515 } 8589 }
8516 8590
8517 8591
8518 } // namespace internal 8592 } // namespace internal
8519 } // namespace v8 8593 } // namespace v8
OLDNEW
« no previous file with comments | « src/DEPS ('k') | src/api-natives.cc » ('j') | src/compiler/fast-accessor-assembler.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698