|
29 | 29 | #include <sys/stat.h> |
30 | 30 |
|
31 | 31 | #include "include/v8-extension.h" |
32 | | -#include "include/v8-fast-api-calls.h" |
33 | 32 | #include "include/v8-function.h" |
34 | 33 | #include "include/v8-locker.h" |
35 | 34 | #include "src/api/api-inl.h" |
@@ -3103,160 +3102,6 @@ UNINITIALIZED_TEST(SnapshotCreatorShortExternalReferences) { |
3103 | 3102 | FreeCurrentEmbeddedBlob(); |
3104 | 3103 | } |
3105 | 3104 |
|
3106 | | -class FastApiReceiver { |
3107 | | - public: |
3108 | | - static void FastCallback(v8::Local<v8::Object> receiver) { |
3109 | | - FastApiReceiver* receiver_ptr = static_cast<FastApiReceiver*>( |
3110 | | - receiver->GetAlignedPointerFromInternalField(0)); |
3111 | | - CHECK_EQ(receiver_ptr, &instance); |
3112 | | - receiver_ptr->result_ |= ApiCheckerResult::kFastCalled; |
3113 | | - } |
3114 | | - |
3115 | | - static void SlowCallback(const v8::FunctionCallbackInfo<v8::Value>& info) { |
3116 | | - v8::Object* receiver = v8::Object::Cast(*info.Holder()); |
3117 | | - FastApiReceiver* receiver_ptr = static_cast<FastApiReceiver*>( |
3118 | | - receiver->GetAlignedPointerFromInternalField(0)); |
3119 | | - CHECK_EQ(receiver_ptr, &instance); |
3120 | | - receiver_ptr->result_ |= ApiCheckerResult::kSlowCalled; |
3121 | | - } |
3122 | | - |
3123 | | - static v8::StartupData SerializeInternalFields(v8::Local<v8::Object> holder, |
3124 | | - int index, void* data) { |
3125 | | - void* ptr = holder->GetAlignedPointerFromInternalField(index); |
3126 | | - if (ptr != &instance) { |
3127 | | - return {nullptr, 0}; |
3128 | | - } |
3129 | | - // Use a 1-byte payload to tell that it's a FastApiReceiver. |
3130 | | - char* payload = new char[1]; |
3131 | | - return {payload, 1}; |
3132 | | - } |
3133 | | - |
3134 | | - static void DeserializeInternalFields(v8::Local<v8::Object> holder, int index, |
3135 | | - v8::StartupData payload, void* data) { |
3136 | | - if (payload.raw_size == 0) { |
3137 | | - holder->SetAlignedPointerInInternalField(index, nullptr); |
3138 | | - return; |
3139 | | - } |
3140 | | - |
3141 | | - // Reset the state for testing. |
3142 | | - instance.result_ = ApiCheckerResult::kNotCalled; |
3143 | | - holder->SetAlignedPointerInInternalField(index, &instance); |
3144 | | - } |
3145 | | - |
3146 | | - bool DidCallFast() const { return (result_ & ApiCheckerResult::kFastCalled); } |
3147 | | - bool DidCallSlow() const { return (result_ & ApiCheckerResult::kSlowCalled); } |
3148 | | - |
3149 | | - static FastApiReceiver instance; |
3150 | | - v8::CFunction c_function = v8::CFunction::Make(FastCallback); |
3151 | | - |
3152 | | - private: |
3153 | | - ApiCheckerResultFlags result_ = ApiCheckerResult::kNotCalled; |
3154 | | -}; |
3155 | | - |
3156 | | -FastApiReceiver FastApiReceiver::instance; |
3157 | | -// A CFunction comes with three external references: the fast calback, |
3158 | | -// the slow callback, and the type info. |
3159 | | -intptr_t c_function_external_references[] = { |
3160 | | - reinterpret_cast<intptr_t>(FastApiReceiver::FastCallback), |
3161 | | - reinterpret_cast<intptr_t>(FastApiReceiver::SlowCallback), |
3162 | | - reinterpret_cast<intptr_t>( |
3163 | | - FastApiReceiver::instance.c_function.GetTypeInfo()), |
3164 | | - 0}; |
3165 | | - |
3166 | | -UNINITIALIZED_TEST(CFunction) { |
3167 | | -#ifndef V8_LITE_MODE |
3168 | | - if (i::FLAG_jitless) return; |
3169 | | - if (!i::FLAG_opt) return; |
3170 | | - |
3171 | | - i::FLAG_turbo_fast_api_calls = true; |
3172 | | - i::FLAG_allow_natives_syntax = true; |
3173 | | - // Disable --always_opt, otherwise we haven't generated the necessary |
3174 | | - // feedback to go down the "best optimization" path for the fast call. |
3175 | | - // No optimization should be done before serialization, but after |
3176 | | - // deserialization we need optimization to check the fast calls. |
3177 | | - i::FLAG_always_opt = false; |
3178 | | - i::FlagList::EnforceFlagImplications(); |
3179 | | - DisableEmbeddedBlobRefcounting(); |
3180 | | - |
3181 | | - v8::StartupData blob; |
3182 | | - { |
3183 | | - v8::SnapshotCreator creator(c_function_external_references); |
3184 | | - v8::Isolate* isolate = creator.GetIsolate(); |
3185 | | - { |
3186 | | - v8::HandleScope handle_scope(isolate); |
3187 | | - v8::Local<v8::Context> context = v8::Context::New(isolate); |
3188 | | - v8::Context::Scope context_scope(context); |
3189 | | - |
3190 | | - v8::Local<v8::FunctionTemplate> callback = v8::FunctionTemplate::New( |
3191 | | - isolate, FastApiReceiver::SlowCallback, v8::Local<v8::Value>(), |
3192 | | - v8::Local<v8::Signature>(), 0, v8::ConstructorBehavior::kThrow, |
3193 | | - v8::SideEffectType::kHasSideEffect, |
3194 | | - &(FastApiReceiver::instance.c_function)); |
3195 | | - |
3196 | | - v8::Local<v8::ObjectTemplate> object_template = |
3197 | | - v8::ObjectTemplate::New(isolate); |
3198 | | - object_template->SetInternalFieldCount(1); |
3199 | | - object_template->Set(isolate, "api_func", callback); |
3200 | | - |
3201 | | - v8::Local<v8::Object> object = |
3202 | | - object_template->NewInstance(context).ToLocalChecked(); |
3203 | | - object->SetAlignedPointerInInternalField(0, &(FastApiReceiver::instance)); |
3204 | | - CHECK(context->Global() |
3205 | | - ->Set(context, v8_str("receiver"), object) |
3206 | | - .FromJust()); |
3207 | | - |
3208 | | - CHECK(!FastApiReceiver::instance.DidCallFast()); |
3209 | | - CHECK(!FastApiReceiver::instance.DidCallSlow()); |
3210 | | - |
3211 | | - CompileRun("receiver.api_func();"); |
3212 | | - CHECK(FastApiReceiver::instance.DidCallSlow()); |
3213 | | - |
3214 | | - creator.SetDefaultContext( |
3215 | | - context, v8::SerializeInternalFieldsCallback( |
3216 | | - FastApiReceiver::SerializeInternalFields, nullptr)); |
3217 | | - } |
3218 | | - blob = |
3219 | | - creator.CreateBlob(v8::SnapshotCreator::FunctionCodeHandling::kClear); |
3220 | | - } |
3221 | | - |
3222 | | - { |
3223 | | - v8::Isolate::CreateParams params; |
3224 | | - params.snapshot_blob = &blob; |
3225 | | - params.array_buffer_allocator = CcTest::array_buffer_allocator(); |
3226 | | - params.external_references = c_function_external_references; |
3227 | | - |
3228 | | - // Test-appropriate equivalent of v8::Isolate::New. |
3229 | | - v8::Isolate* isolate = TestSerializer::NewIsolate(params); |
3230 | | - { |
3231 | | - v8::Isolate::Scope isolate_scope(isolate); |
3232 | | - v8::HandleScope handle_scope(isolate); |
3233 | | - v8::Local<v8::Context> context = v8::Context::New( |
3234 | | - isolate, nullptr, v8::MaybeLocal<v8::ObjectTemplate>(), |
3235 | | - v8::MaybeLocal<v8::Value>(), |
3236 | | - v8::DeserializeInternalFieldsCallback( |
3237 | | - FastApiReceiver::DeserializeInternalFields, nullptr)); |
3238 | | - v8::Context::Scope context_scope(context); |
3239 | | - |
3240 | | - // Deserialize callback should reset the state of the instance. |
3241 | | - CHECK(!FastApiReceiver::instance.DidCallFast()); |
3242 | | - CHECK(!FastApiReceiver::instance.DidCallSlow()); |
3243 | | - CompileRun( |
3244 | | - "function foo(arg) {" |
3245 | | - " for (let i = 0; i < arg; ++i) { receiver.api_func(); }" |
3246 | | - "}" |
3247 | | - "%PrepareFunctionForOptimization(foo);" |
3248 | | - "foo(42); foo(42);" |
3249 | | - "%OptimizeFunctionOnNextCall(foo);" |
3250 | | - "foo(42);"); |
3251 | | - CHECK(FastApiReceiver::instance.DidCallFast()); |
3252 | | - } |
3253 | | - isolate->Dispose(); |
3254 | | - } |
3255 | | - delete[] blob.data; |
3256 | | - FreeCurrentEmbeddedBlob(); |
3257 | | -#endif |
3258 | | -} |
3259 | | - |
3260 | 3105 | v8::StartupData CreateSnapshotWithDefaultAndCustom() { |
3261 | 3106 | v8::SnapshotCreator creator(original_external_references); |
3262 | 3107 | v8::Isolate* isolate = creator.GetIsolate(); |
|
0 commit comments