diff options
Diffstat (limited to 'chromium/v8/src/api')
-rw-r--r-- | chromium/v8/src/api/api-arguments-inl.h | 6 | ||||
-rw-r--r-- | chromium/v8/src/api/api-inl.h | 67 | ||||
-rw-r--r-- | chromium/v8/src/api/api-natives.cc | 18 | ||||
-rw-r--r-- | chromium/v8/src/api/api.cc | 447 | ||||
-rw-r--r-- | chromium/v8/src/api/api.h | 4 |
5 files changed, 363 insertions, 179 deletions
diff --git a/chromium/v8/src/api/api-arguments-inl.h b/chromium/v8/src/api/api-arguments-inl.h index 4edd0dad29d..786f849be6c 100644 --- a/chromium/v8/src/api/api-arguments-inl.h +++ b/chromium/v8/src/api/api-arguments-inl.h @@ -6,11 +6,10 @@ #define V8_API_API_ARGUMENTS_INL_H_ #include "src/api/api-arguments.h" - #include "src/api/api-inl.h" #include "src/debug/debug.h" #include "src/execution/vm-state-inl.h" -#include "src/logging/counters.h" +#include "src/logging/runtime-call-stats-scope.h" #include "src/objects/api-callbacks.h" #include "src/objects/slots-inl.h" #include "src/tracing/trace-event.h" @@ -77,7 +76,6 @@ inline JSReceiver FunctionCallbackArguments::holder() { CALLBACK_INFO, RECEIVER, Debug::k##ACCESSOR_KIND)) { \ return RETURN_VALUE(); \ } \ - VMState<EXTERNAL> state(ISOLATE); \ ExternalCallbackScope call_scope(ISOLATE, FUNCTION_ADDR(F)); \ PropertyCallbackInfo<API_RETURN_TYPE> callback_info(values_); @@ -86,7 +84,6 @@ inline JSReceiver FunctionCallbackArguments::holder() { if (ISOLATE->debug_execution_mode() == DebugInfo::kSideEffects) { \ return RETURN_VALUE(); \ } \ - VMState<EXTERNAL> state(ISOLATE); \ ExternalCallbackScope call_scope(ISOLATE, FUNCTION_ADDR(F)); \ PropertyCallbackInfo<API_RETURN_TYPE> callback_info(values_); @@ -150,7 +147,6 @@ Handle<Object> FunctionCallbackArguments::Call(CallHandlerInfo handler) { Debug::kNotAccessor)) { return Handle<Object>(); } - VMState<EXTERNAL> state(isolate); ExternalCallbackScope call_scope(isolate, FUNCTION_ADDR(f)); FunctionCallbackInfo<v8::Value> info(values_, argv_, argc_); f(info); diff --git a/chromium/v8/src/api/api-inl.h b/chromium/v8/src/api/api-inl.h index 84b9b288bb0..c5c774800b7 100644 --- a/chromium/v8/src/api/api-inl.h +++ b/chromium/v8/src/api/api-inl.h @@ -5,10 +5,13 @@ #ifndef V8_API_API_INL_H_ #define V8_API_API_INL_H_ +#include "include/v8-fast-api-calls.h" #include "src/api/api.h" #include "src/execution/interrupts-scope.h" #include "src/execution/microtask-queue.h" +#include "src/execution/protectors.h" #include "src/handles/handles-inl.h" +#include "src/heap/heap-inl.h" #include "src/objects/foreign-inl.h" #include "src/objects/js-weak-refs.h" #include "src/objects/objects-inl.h" @@ -239,6 +242,70 @@ inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { return false; } +template <typename T> +void CopySmiElementsToTypedBuffer(T* dst, uint32_t length, + i::FixedArray elements) { + for (uint32_t i = 0; i < length; ++i) { + double value = elements.get(static_cast<int>(i)).Number(); + // TODO(mslekova): Avoid converting back-and-forth when possible, e.g + // avoid int->double->int conversions to boost performance. + dst[i] = i::ConvertDouble<T>(value); + } +} + +template <typename T> +void CopyDoubleElementsToTypedBuffer(T* dst, uint32_t length, + i::FixedDoubleArray elements) { + for (uint32_t i = 0; i < length; ++i) { + double value = elements.get_scalar(static_cast<int>(i)); + // TODO(mslekova): There are certain cases, e.g. double->double, in which + // we could do a memcpy directly. + dst[i] = i::ConvertDouble<T>(value); + } +} + +template <const CTypeInfo* type_info, typename T> +bool CopyAndConvertArrayToCppBuffer(Local<Array> src, T* dst, + uint32_t max_length) { + static_assert( + std::is_same< + T, typename i::CTypeInfoTraits<type_info->GetType()>::ctype>::value, + "Type mismatch between the expected CTypeInfo::Type and the destination " + "array"); + + uint32_t length = src->Length(); + if (length > max_length) { + return false; + } + + i::DisallowGarbageCollection no_gc; + i::JSArray obj = *reinterpret_cast<i::JSArray*>(*src); + if (obj.IterationHasObservableEffects()) { + // The array has a custom iterator. + return false; + } + + i::FixedArrayBase elements = obj.elements(); + switch (obj.GetElementsKind()) { + case i::PACKED_SMI_ELEMENTS: + CopySmiElementsToTypedBuffer(dst, length, i::FixedArray::cast(elements)); + return true; + case i::PACKED_DOUBLE_ELEMENTS: + CopyDoubleElementsToTypedBuffer(dst, length, + i::FixedDoubleArray::cast(elements)); + return true; + default: + return false; + } +} + +template <const CTypeInfo* type_info, typename T> +inline bool V8_EXPORT TryCopyAndConvertArrayToCppBuffer(Local<Array> src, + T* dst, + uint32_t max_length) { + return CopyAndConvertArrayToCppBuffer<type_info, T>(src, dst, max_length); +} + namespace internal { Handle<Context> HandleScopeImplementer::LastEnteredContext() { diff --git a/chromium/v8/src/api/api-natives.cc b/chromium/v8/src/api/api-natives.cc index 46d54f6f587..c64107f3b8c 100644 --- a/chromium/v8/src/api/api-natives.cc +++ b/chromium/v8/src/api/api-natives.cc @@ -7,6 +7,8 @@ #include "src/api/api-inl.h" #include "src/common/message-template.h" #include "src/execution/isolate-inl.h" +#include "src/heap/heap-inl.h" +#include "src/logging/runtime-call-stats-scope.h" #include "src/objects/api-callbacks.h" #include "src/objects/hash-table-inl.h" #include "src/objects/lookup.h" @@ -109,7 +111,7 @@ MaybeHandle<Object> DefineDataProperty(Isolate* isolate, ASSIGN_RETURN_ON_EXCEPTION(isolate, value, Instantiate(isolate, prop_data, name), Object); - LookupIterator::Key key(isolate, name); + PropertyKey key(isolate, name); LookupIterator it(isolate, object, key, LookupIterator::OWN_SKIP_INTERCEPTOR); #ifdef DEBUG @@ -526,12 +528,14 @@ MaybeHandle<JSFunction> InstantiateFunction( Handle<HeapObject>::cast(parent_prototype)); } } - InstanceType function_type = - (!data->needs_access_check() && - data->GetNamedPropertyHandler().IsUndefined(isolate) && - data->GetIndexedPropertyHandler().IsUndefined(isolate)) - ? JS_API_OBJECT_TYPE - : JS_SPECIAL_API_OBJECT_TYPE; + InstanceType function_type = JS_SPECIAL_API_OBJECT_TYPE; + if (!data->needs_access_check() && + data->GetNamedPropertyHandler().IsUndefined(isolate) && + data->GetIndexedPropertyHandler().IsUndefined(isolate)) { + function_type = FLAG_embedder_instance_types && data->HasInstanceType() + ? static_cast<InstanceType>(data->InstanceType()) + : JS_API_OBJECT_TYPE; + } Handle<JSFunction> function = ApiNatives::CreateApiFunction( isolate, native_context, data, prototype, function_type, maybe_name); diff --git a/chromium/v8/src/api/api.cc b/chromium/v8/src/api/api.cc index 9d1e53d3bb6..a8af304a530 100644 --- a/chromium/v8/src/api/api.cc +++ b/chromium/v8/src/api/api.cc @@ -25,14 +25,16 @@ #include "src/base/platform/time.h" #include "src/base/safe_conversions.h" #include "src/base/utils/random-number-generator.h" +#include "src/baseline/baseline-batch-compiler.h" #include "src/builtins/accessors.h" #include "src/builtins/builtins-utils.h" #include "src/codegen/compiler.h" #include "src/codegen/cpu-features.h" +#include "src/codegen/script-details.h" #include "src/common/assert-scope.h" #include "src/common/external-pointer.h" #include "src/common/globals.h" -#include "src/compiler-dispatcher/compiler-dispatcher.h" +#include "src/compiler-dispatcher/lazy-compile-dispatcher.h" #include "src/date/date.h" #include "src/debug/liveedit.h" #include "src/deoptimizer/deoptimizer.h" @@ -56,8 +58,9 @@ #include "src/init/v8.h" #include "src/json/json-parser.h" #include "src/json/json-stringifier.h" -#include "src/logging/counters.h" +#include "src/logging/counters-scopes.h" #include "src/logging/metrics.h" +#include "src/logging/runtime-call-stats-scope.h" #include "src/logging/tracing-flags.h" #include "src/numbers/conversions-inl.h" #include "src/objects/api-callbacks.h" @@ -107,11 +110,11 @@ #include "src/strings/string-hasher.h" #include "src/strings/unicode-inl.h" #include "src/tracing/trace-event.h" -#include "src/trap-handler/trap-handler.h" #include "src/utils/detachable-vector.h" #include "src/utils/version.h" #if V8_ENABLE_WEBASSEMBLY +#include "src/trap-handler/trap-handler.h" #include "src/wasm/streaming-decoder.h" #include "src/wasm/value-type.h" #include "src/wasm/wasm-engine.h" @@ -128,9 +131,11 @@ #endif #if V8_OS_WIN -#include <versionhelpers.h> #include <windows.h> +// This has to come after windows.h. +#include <versionhelpers.h> + #include "include/v8-wasm-trap-handler-win.h" #include "src/trap-handler/handler-inside-win.h" #if defined(V8_OS_WIN64) @@ -409,6 +414,8 @@ SnapshotCreator::SnapshotCreator(Isolate* isolate, internal_isolate->InitWithoutSnapshot(); } data_ = data; + // Disable batch compilation during snapshot creation. + internal_isolate->baseline_batch_compiler()->set_enabled(false); } SnapshotCreator::SnapshotCreator(const intptr_t* external_references, @@ -1218,7 +1225,10 @@ static Local<FunctionTemplate> FunctionTemplateNew( bool do_not_cache, v8::Local<Private> cached_property_name = v8::Local<Private>(), SideEffectType side_effect_type = SideEffectType::kHasSideEffect, - const MemorySpan<const CFunction>& c_function_overloads = {}) { + const MemorySpan<const CFunction>& c_function_overloads = {}, + uint8_t instance_type = 0, + uint8_t allowed_receiver_instance_type_range_start = 0, + uint8_t allowed_receiver_instance_type_range_end = 0) { i::Handle<i::Struct> struct_obj = isolate->factory()->NewStruct( i::FUNCTION_TEMPLATE_INFO_TYPE, i::AllocationType::kOld); i::Handle<i::FunctionTemplateInfo> obj = @@ -1240,6 +1250,11 @@ static Local<FunctionTemplate> FunctionTemplateNew( ? i::ReadOnlyRoots(isolate).the_hole_value() : *Utils::OpenHandle(*cached_property_name)); if (behavior == ConstructorBehavior::kThrow) raw.set_remove_prototype(true); + raw.SetInstanceType(instance_type); + raw.set_allowed_receiver_instance_type_range_start( + allowed_receiver_instance_type_range_start); + raw.set_allowed_receiver_instance_type_range_end( + allowed_receiver_instance_type_range_end); } if (callback != nullptr) { Utils::ToLocal(obj)->SetCallHandler(callback, data, side_effect_type, @@ -1251,7 +1266,9 @@ static Local<FunctionTemplate> FunctionTemplateNew( Local<FunctionTemplate> FunctionTemplate::New( Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, v8::Local<Signature> signature, int length, ConstructorBehavior behavior, - SideEffectType side_effect_type, const CFunction* c_function) { + SideEffectType side_effect_type, const CFunction* c_function, + uint16_t instance_type, uint16_t allowed_receiver_instance_type_range_start, + uint16_t allowed_receiver_instance_type_range_end) { i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); // Changes to the environment cannot be captured in the snapshot. Expect no // function templates when the isolate is created for serialization. @@ -1261,7 +1278,9 @@ Local<FunctionTemplate> FunctionTemplate::New( i_isolate, callback, data, signature, length, behavior, false, Local<Private>(), side_effect_type, c_function ? MemorySpan<const CFunction>{c_function, 1} - : MemorySpan<const CFunction>{}); + : MemorySpan<const CFunction>{}, + instance_type, allowed_receiver_instance_type_range_start, + allowed_receiver_instance_type_range_end); } Local<FunctionTemplate> FunctionTemplate::NewWithCFunctionOverloads( @@ -1269,6 +1288,15 @@ Local<FunctionTemplate> FunctionTemplate::NewWithCFunctionOverloads( v8::Local<Signature> signature, int length, ConstructorBehavior behavior, SideEffectType side_effect_type, const MemorySpan<const CFunction>& c_function_overloads) { + // TODO(mslekova): Once runtime overload resolution between sequences is + // supported, check that if (c_function_overloads.size() == 2), then + // c_function_overloads.data()[0]. + // CanResolveOverload(c_function_overloads.data()[1]). We won't support + // the case where the size is greater than 2 for runtime resolution, until + // we've added support for ArrayBuffers and ArrayBufferViews. OTOH the + // overloads list might contain more than 2 functions with different arity, + // the resolution between which is available at compile time. + i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); LOG_API(i_isolate, FunctionTemplate, New); ENTER_V8_NO_SCRIPT_NO_EXCEPTION(i_isolate); @@ -1853,10 +1881,6 @@ bool ScriptCompiler::ExternalSourceStream::SetBookmark() { return false; } void ScriptCompiler::ExternalSourceStream::ResetToBookmark() { UNREACHABLE(); } -ScriptCompiler::StreamedSource::StreamedSource(ExternalSourceStream* stream, - Encoding encoding) - : StreamedSource(std::unique_ptr<ExternalSourceStream>(stream), encoding) {} - ScriptCompiler::StreamedSource::StreamedSource( std::unique_ptr<ExternalSourceStream> stream, Encoding encoding) : impl_(new i::ScriptStreamingData(std::move(stream), encoding)) {} @@ -1943,10 +1967,11 @@ MaybeLocal<Value> Script::Run(Local<Context> context) { TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute"); ENTER_V8(isolate, context, Script, Run, MaybeLocal<Value>(), InternalEscapableScope); - i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); + i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); + i::NestedTimedHistogramScope execute_timer( + isolate->counters()->execute_precise()); i::AggregatingHistogramTimerScope histogram_timer( isolate->counters()->compile_lazy()); - i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); auto fun = i::Handle<i::JSFunction>::cast(Utils::OpenHandle(this)); // TODO(crbug.com/1193459): remove once ablation study is completed @@ -2081,14 +2106,15 @@ Local<FixedArray> ModuleRequest::GetImportAssertions() const { Module::Status Module::GetStatus() const { i::Handle<i::Module> self = Utils::OpenHandle(this); switch (self->status()) { - case i::Module::kUninstantiated: - case i::Module::kPreInstantiating: + case i::Module::kUnlinked: + case i::Module::kPreLinking: return kUninstantiated; - case i::Module::kInstantiating: + case i::Module::kLinking: return kInstantiating; - case i::Module::kInstantiated: + case i::Module::kLinked: return kInstantiated; case i::Module::kEvaluating: + case i::Module::kEvaluatingAsync: return kEvaluating; case i::Module::kEvaluated: return kEvaluated; @@ -2269,13 +2295,14 @@ MaybeLocal<Value> Module::Evaluate(Local<Context> context) { TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.Execute"); ENTER_V8(isolate, context, Module, Evaluate, MaybeLocal<Value>(), InternalEscapableScope); - i::HistogramTimerScope execute_timer(isolate->counters()->execute(), true); - i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); + i::NestedTimedHistogramScope execute_timer( + isolate->counters()->execute_precise()); + i::AggregatingHistogramTimerScope timer(isolate->counters()->compile_lazy()); i::Handle<i::Module> self = Utils::OpenHandle(this); - Utils::ApiCheck(self->status() >= i::Module::kInstantiated, - "Module::Evaluate", "Expected instantiated module"); + Utils::ApiCheck(self->status() >= i::Module::kLinked, "Module::Evaluate", + "Expected instantiated module"); Local<Value> result; has_pending_exception = !ToLocal(i::Module::Evaluate(isolate, self), &result); @@ -2324,31 +2351,17 @@ Maybe<bool> Module::SetSyntheticModuleExport(Isolate* isolate, return Just(true); } -void Module::SetSyntheticModuleExport(Local<String> export_name, - Local<v8::Value> export_value) { - i::Handle<i::String> i_export_name = Utils::OpenHandle(*export_name); - i::Handle<i::Object> i_export_value = Utils::OpenHandle(*export_value); - i::Handle<i::Module> self = Utils::OpenHandle(this); - ASSERT_NO_SCRIPT_NO_EXCEPTION(self->GetIsolate()); - Utils::ApiCheck(self->IsSyntheticModule(), - "v8::Module::SetSyntheticModuleExport", - "v8::Module::SetSyntheticModuleExport must only be called on " - "a SyntheticModule"); - i::SyntheticModule::SetExportStrict(self->GetIsolate(), - i::Handle<i::SyntheticModule>::cast(self), - i_export_name, i_export_value); -} - namespace { -i::Compiler::ScriptDetails GetScriptDetails( - i::Isolate* isolate, Local<Value> resource_name, int resource_line_offset, - int resource_column_offset, Local<Value> source_map_url, - Local<PrimitiveArray> host_defined_options) { - i::Compiler::ScriptDetails script_details; - if (!resource_name.IsEmpty()) { - script_details.name_obj = Utils::OpenHandle(*(resource_name)); - } +i::ScriptDetails GetScriptDetails(i::Isolate* isolate, + Local<Value> resource_name, + int resource_line_offset, + int resource_column_offset, + Local<Value> source_map_url, + Local<PrimitiveArray> host_defined_options, + ScriptOriginOptions origin_options) { + i::ScriptDetails script_details(Utils::OpenHandle(*(resource_name), true), + origin_options); script_details.line_offset = resource_line_offset; script_details.column_offset = resource_column_offset; script_details.host_defined_options = @@ -2372,29 +2385,44 @@ MaybeLocal<UnboundScript> ScriptCompiler::CompileUnboundInternal( CompileUnbound, MaybeLocal<UnboundScript>(), InternalEscapableScope); - i::ScriptData* script_data = nullptr; + i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); + + std::unique_ptr<i::AlignedCachedData> cached_data; if (options == kConsumeCodeCache) { - DCHECK(source->cached_data); - // ScriptData takes care of pointer-aligning the data. - script_data = new i::ScriptData(source->cached_data->data, - source->cached_data->length); + if (source->consume_cache_task) { + // If there's a cache consume task, finish it + i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info = + source->consume_cache_task->impl_->Finish(isolate, str, + source->resource_options); + i::Handle<i::SharedFunctionInfo> result; + if (maybe_function_info.ToHandle(&result)) { + RETURN_ESCAPED(ToApiHandle<UnboundScript>(result)); + } + // If the above failed, then we must have rejected the cache. Continue + // with normal compilation, disabling the code cache consumption. + source->cached_data->rejected = true; + options = kNoCompileOptions; + } else { + DCHECK(source->cached_data); + // AlignedCachedData takes care of pointer-aligning the data. + cached_data.reset(new i::AlignedCachedData(source->cached_data->data, + source->cached_data->length)); + } } - i::Handle<i::String> str = Utils::OpenHandle(*(source->source_string)); i::Handle<i::SharedFunctionInfo> result; TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileScript"); - i::Compiler::ScriptDetails script_details = GetScriptDetails( + i::ScriptDetails script_details = GetScriptDetails( isolate, source->resource_name, source->resource_line_offset, source->resource_column_offset, source->source_map_url, - source->host_defined_options); + source->host_defined_options, source->resource_options); i::MaybeHandle<i::SharedFunctionInfo> maybe_function_info = i::Compiler::GetSharedFunctionInfoForScript( - isolate, str, script_details, source->resource_options, nullptr, - script_data, options, no_cache_reason, i::NOT_NATIVES_CODE); + isolate, str, script_details, nullptr, cached_data.get(), options, + no_cache_reason, i::NOT_NATIVES_CODE); if (options == kConsumeCodeCache) { - source->cached_data->rejected = script_data->rejected(); + source->cached_data->rejected = cached_data->rejected(); } - delete script_data; has_pending_exception = !maybe_function_info.ToHandle(&result); RETURN_ON_FAILED_EXECUTION(UnboundScript); RETURN_ESCAPED(ToApiHandle<UnboundScript>(result)); @@ -2511,30 +2539,28 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext( extension); } - i::Compiler::ScriptDetails script_details = GetScriptDetails( + i::ScriptDetails script_details = GetScriptDetails( isolate, source->resource_name, source->resource_line_offset, source->resource_column_offset, source->source_map_url, - source->host_defined_options); + source->host_defined_options, source->resource_options); - i::ScriptData* script_data = nullptr; + std::unique_ptr<i::AlignedCachedData> cached_data; if (options == kConsumeCodeCache) { DCHECK(source->cached_data); // ScriptData takes care of pointer-aligning the data. - script_data = new i::ScriptData(source->cached_data->data, - source->cached_data->length); + cached_data.reset(new i::AlignedCachedData(source->cached_data->data, + source->cached_data->length)); } i::Handle<i::JSFunction> scoped_result; has_pending_exception = !i::Compiler::GetWrappedFunction( Utils::OpenHandle(*source->source_string), arguments_list, context, - script_details, source->resource_options, script_data, options, - no_cache_reason) + script_details, cached_data.get(), options, no_cache_reason) .ToHandle(&scoped_result); if (options == kConsumeCodeCache) { - source->cached_data->rejected = script_data->rejected(); + source->cached_data->rejected = cached_data->rejected(); } - delete script_data; RETURN_ON_FAILED_EXECUTION(Function); result = handle_scope.Escape(Utils::CallableToLocal(scoped_result)); } @@ -2553,14 +2579,6 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext( void ScriptCompiler::ScriptStreamingTask::Run() { data_->task->Run(); } -ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreamingScript( - Isolate* v8_isolate, StreamedSource* source, CompileOptions options) { - // We don't support other compile options on streaming background compiles. - // TODO(rmcilroy): remove CompileOptions from the API. - CHECK(options == ScriptCompiler::kNoCompileOptions); - return StartStreaming(v8_isolate, source); -} - ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreaming( Isolate* v8_isolate, StreamedSource* source, v8::ScriptType type) { if (!i::FLAG_script_streaming) return nullptr; @@ -2573,18 +2591,36 @@ ScriptCompiler::ScriptStreamingTask* ScriptCompiler::StartStreaming( return new ScriptCompiler::ScriptStreamingTask(data); } +ScriptCompiler::ConsumeCodeCacheTask::ConsumeCodeCacheTask( + std::unique_ptr<i::BackgroundDeserializeTask> impl) + : impl_(std::move(impl)) {} + +ScriptCompiler::ConsumeCodeCacheTask::~ConsumeCodeCacheTask() = default; + +void ScriptCompiler::ConsumeCodeCacheTask::Run() { impl_->Run(); } + +ScriptCompiler::ConsumeCodeCacheTask* ScriptCompiler::StartConsumingCodeCache( + Isolate* v8_isolate, std::unique_ptr<CachedData> cached_data) { + if (!i::FLAG_concurrent_cache_deserialization) return nullptr; + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate); + ASSERT_NO_SCRIPT_NO_EXCEPTION(isolate); + return new ScriptCompiler::ConsumeCodeCacheTask( + std::make_unique<i::BackgroundDeserializeTask>(isolate, + std::move(cached_data))); +} + namespace { i::MaybeHandle<i::SharedFunctionInfo> CompileStreamedSource( i::Isolate* isolate, ScriptCompiler::StreamedSource* v8_source, Local<String> full_source_string, const ScriptOrigin& origin) { i::Handle<i::String> str = Utils::OpenHandle(*(full_source_string)); - i::Compiler::ScriptDetails script_details = + i::ScriptDetails script_details = GetScriptDetails(isolate, origin.ResourceName(), origin.LineOffset(), origin.ColumnOffset(), origin.SourceMapUrl(), - origin.HostDefinedOptions()); + origin.HostDefinedOptions(), origin.Options()); i::ScriptStreamingData* data = v8_source->impl(); return i::Compiler::GetSharedFunctionInfoForStreamedScript( - isolate, str, script_details, origin.Options(), data); + isolate, str, script_details, data); } } // namespace @@ -3234,7 +3270,8 @@ ValueDeserializer::Delegate::GetSharedArrayBufferFromId(Isolate* v8_isolate, } struct ValueDeserializer::PrivateData { - PrivateData(i::Isolate* i, i::Vector<const uint8_t> data, Delegate* delegate) + PrivateData(i::Isolate* i, base::Vector<const uint8_t> data, + Delegate* delegate) : isolate(i), deserializer(i, data, delegate) {} i::Isolate* isolate; i::ValueDeserializer deserializer; @@ -3251,10 +3288,11 @@ ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data, if (base::IsValueInRangeForNumericType<int>(size)) { private_ = new PrivateData( reinterpret_cast<i::Isolate*>(isolate), - i::Vector<const uint8_t>(data, static_cast<int>(size)), delegate); + base::Vector<const uint8_t>(data, static_cast<int>(size)), delegate); } else { - private_ = new PrivateData(reinterpret_cast<i::Isolate*>(isolate), - i::Vector<const uint8_t>(nullptr, 0), nullptr); + private_ = + new PrivateData(reinterpret_cast<i::Isolate*>(isolate), + base::Vector<const uint8_t>(nullptr, 0), nullptr); private_->has_aborted = true; } } @@ -3653,6 +3691,13 @@ bool i::ShouldThrowOnError(i::Isolate* isolate) { i::ShouldThrow::kThrowOnError; } +bool i::CanHaveInternalField(int instance_type) { + return instance_type == i::Internals::kJSObjectType || + instance_type == i::Internals::kJSSpecialApiObjectType || + v8::internal::InstanceTypeChecker::IsJSApiObject( + static_cast<v8::internal::InstanceType>(instance_type)); +} + void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) { i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); Utils::ApiCheck(isolate != nullptr && !isolate->IsDead(), @@ -4099,7 +4144,7 @@ Maybe<bool> v8::Object::CreateDataProperty(v8::Local<v8::Context> context, i::Handle<i::Name> key_obj = Utils::OpenHandle(*key); i::Handle<i::Object> value_obj = Utils::OpenHandle(*value); - i::LookupIterator::Key lookup_key(isolate, key_obj); + i::PropertyKey lookup_key(isolate, key_obj); i::LookupIterator it(isolate, self, lookup_key, i::LookupIterator::OWN); if (self->IsJSProxy()) { ENTER_V8(isolate, context, Object, CreateDataProperty, Nothing<bool>(), @@ -4775,7 +4820,7 @@ MaybeLocal<Value> v8::Object::GetRealNamedPropertyInPrototypeChain( if (iter.IsAtEnd()) return MaybeLocal<Value>(); i::Handle<i::JSReceiver> proto = i::PrototypeIterator::GetCurrent<i::JSReceiver>(iter); - i::LookupIterator::Key lookup_key(isolate, key_obj); + i::PropertyKey lookup_key(isolate, key_obj); i::LookupIterator it(isolate, self, lookup_key, proto, i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); Local<Value> result; @@ -4799,7 +4844,7 @@ v8::Object::GetRealNamedPropertyAttributesInPrototypeChain( if (iter.IsAtEnd()) return Nothing<PropertyAttribute>(); i::Handle<i::JSReceiver> proto = i::PrototypeIterator::GetCurrent<i::JSReceiver>(iter); - i::LookupIterator::Key lookup_key(isolate, key_obj); + i::PropertyKey lookup_key(isolate, key_obj); i::LookupIterator it(isolate, self, lookup_key, proto, i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); Maybe<i::PropertyAttributes> result = @@ -4816,7 +4861,7 @@ MaybeLocal<Value> v8::Object::GetRealNamedProperty(Local<Context> context, PREPARE_FOR_EXECUTION(context, Object, GetRealNamedProperty, Value); i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); i::Handle<i::Name> key_obj = Utils::OpenHandle(*key); - i::LookupIterator::Key lookup_key(isolate, key_obj); + i::PropertyKey lookup_key(isolate, key_obj); i::LookupIterator it(isolate, self, lookup_key, self, i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); Local<Value> result; @@ -4833,7 +4878,7 @@ Maybe<PropertyAttribute> v8::Object::GetRealNamedPropertyAttributes( Nothing<PropertyAttribute>(), i::HandleScope); i::Handle<i::JSReceiver> self = Utils::OpenHandle(this); i::Handle<i::Name> key_obj = Utils::OpenHandle(*key); - i::LookupIterator::Key lookup_key(isolate, key_obj); + i::PropertyKey lookup_key(isolate, key_obj); i::LookupIterator it(isolate, self, lookup_key, self, i::LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR); auto result = i::JSReceiver::GetPropertyAttributes(&it); @@ -4924,6 +4969,8 @@ MaybeLocal<Value> Object::CallAsFunction(Local<Context> context, ENTER_V8(isolate, context, Object, CallAsFunction, MaybeLocal<Value>(), InternalEscapableScope); i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); + i::NestedTimedHistogramScope execute_timer( + isolate->counters()->execute_precise()); auto self = Utils::OpenHandle(this); auto recv_obj = Utils::OpenHandle(*recv); STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>)); @@ -4942,6 +4989,8 @@ MaybeLocal<Value> Object::CallAsConstructor(Local<Context> context, int argc, ENTER_V8(isolate, context, Object, CallAsConstructor, MaybeLocal<Value>(), InternalEscapableScope); i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); + i::NestedTimedHistogramScope execute_timer( + isolate->counters()->execute_precise()); auto self = Utils::OpenHandle(this); STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>)); i::Handle<i::Object>* args = reinterpret_cast<i::Handle<i::Object>*>(argv); @@ -4979,6 +5028,8 @@ MaybeLocal<Object> Function::NewInstanceWithSideEffectType( ENTER_V8(isolate, context, Function, NewInstance, MaybeLocal<Object>(), InternalEscapableScope); i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); + i::NestedTimedHistogramScope execute_timer( + isolate->counters()->execute_precise()); auto self = Utils::OpenHandle(this); STATIC_ASSERT(sizeof(v8::Local<v8::Value>) == sizeof(i::Handle<i::Object>)); bool should_set_has_no_side_effect = @@ -5028,6 +5079,8 @@ MaybeLocal<v8::Value> Function::Call(Local<Context> context, ENTER_V8(isolate, context, Function, Call, MaybeLocal<Value>(), InternalEscapableScope); i::TimerEventScope<i::TimerEventExecute> timer_scope(isolate); + i::NestedTimedHistogramScope execute_timer( + isolate->counters()->execute_precise()); auto self = Utils::OpenHandle(this); Utils::ApiCheck(!self.is_null(), "v8::Function::Call", "Function to be called is a null pointer"); @@ -5330,7 +5383,7 @@ namespace { // units until the buffer capacity is reached, would be exceeded by the next // unit, or all code units have been written out. template <typename Char> -static int WriteUtf8Impl(i::Vector<const Char> string, char* write_start, +static int WriteUtf8Impl(base::Vector<const Char> string, char* write_start, int write_capacity, int options, int* utf16_chars_read_out) { bool write_null = !(options & v8::String::NO_NULL_TERMINATION); @@ -5362,7 +5415,7 @@ static int WriteUtf8Impl(i::Vector<const Char> string, char* write_start, for (int i = read_index; i < up_to; i++) char_mask |= read_start[i]; if ((char_mask & 0x80) == 0) { int copy_length = up_to - read_index; - base::Memcpy(current_write, read_start + read_index, copy_length); + memcpy(current_write, read_start + read_index, copy_length); current_write += copy_length; read_index = up_to; } else { @@ -5836,36 +5889,30 @@ bool v8::V8::Initialize(const int build_config) { #if V8_OS_LINUX || V8_OS_MACOSX bool TryHandleWebAssemblyTrapPosix(int sig_code, siginfo_t* info, void* context) { - // When the target code runs on the V8 arm simulator, the trap handler does - // not behave as expected: the instruction pointer points inside the simulator - // code rather than the wasm code, so the trap handler cannot find the landing - // pad and lets the process crash. Therefore, only enable trap handlers if - // the host and target arch are the same. -#if (V8_TARGET_ARCH_X64 && !V8_OS_ANDROID) || \ - (V8_HOST_ARCH_ARM64 && V8_TARGET_ARCH_ARM64 && V8_OS_MACOSX) +#if V8_ENABLE_WEBASSEMBLY && V8_TRAP_HANDLER_SUPPORTED return i::trap_handler::TryHandleSignal(sig_code, info, context); #else return false; #endif } - -bool V8::TryHandleSignal(int signum, void* info, void* context) { - return TryHandleWebAssemblyTrapPosix( - signum, reinterpret_cast<siginfo_t*>(info), context); -} #endif #if V8_OS_WIN bool TryHandleWebAssemblyTrapWindows(EXCEPTION_POINTERS* exception) { -#if V8_TARGET_ARCH_X64 +#if V8_ENABLE_WEBASSEMBLY && V8_TRAP_HANDLER_SUPPORTED return i::trap_handler::TryHandleWasmTrap(exception); -#endif +#else return false; +#endif } #endif bool V8::EnableWebAssemblyTrapHandler(bool use_v8_signal_handler) { +#if V8_ENABLE_WEBASSEMBLY return v8::internal::trap_handler::EnableTrapHandler(use_v8_signal_handler); +#else + return false; +#endif } #if defined(V8_OS_WIN) @@ -5955,8 +6002,6 @@ void V8::GetSharedMemoryStatistics(SharedMemoryStatistics* statistics) { i::ReadOnlyHeap::PopulateReadOnlySpaceStatistics(statistics); } -void V8::SetIsCrossOriginIsolated() {} - template <typename ObjectType> struct InvokeBootstrapper; @@ -6104,7 +6149,7 @@ Local<Context> NewContext( // TODO(jkummerow): This is for crbug.com/713699. Remove it if it doesn't // fail. // Sanity-check that the isolate is initialized and usable. - CHECK(isolate->builtins()->builtin(i::Builtins::kIllegal).IsCode()); + CHECK(isolate->builtins()->code(i::Builtin::kIllegal).IsCode()); TRACE_EVENT_CALL_STATS_SCOPED(isolate, "v8", "V8.NewContext"); LOG_API(isolate, Context, New); @@ -6210,7 +6255,7 @@ v8::Local<v8::Object> Context::Global() { i::Handle<i::Context> context = Utils::OpenHandle(this); i::Isolate* isolate = context->GetIsolate(); i::Handle<i::Object> global(context->global_proxy(), isolate); - // TODO(dcarney): This should always return the global proxy + // TODO(chromium:324812): This should always return the global proxy // but can't presently as calls to GetProtoype will return the wrong result. if (i::Handle<i::JSGlobalProxy>::cast(global)->IsDetachedFrom( context->global_object())) { @@ -6506,7 +6551,7 @@ inline int StringLength(const uint16_t* string) { V8_WARN_UNUSED_RESULT inline i::MaybeHandle<i::String> NewString(i::Factory* factory, NewStringType type, - i::Vector<const char> string) { + base::Vector<const char> string) { if (type == NewStringType::kInternalized) { return factory->InternalizeUtf8String(string); } @@ -6516,7 +6561,7 @@ inline i::MaybeHandle<i::String> NewString(i::Factory* factory, V8_WARN_UNUSED_RESULT inline i::MaybeHandle<i::String> NewString(i::Factory* factory, NewStringType type, - i::Vector<const uint8_t> string) { + base::Vector<const uint8_t> string) { if (type == NewStringType::kInternalized) { return factory->InternalizeString(string); } @@ -6524,9 +6569,9 @@ inline i::MaybeHandle<i::String> NewString(i::Factory* factory, } V8_WARN_UNUSED_RESULT -inline i::MaybeHandle<i::String> NewString(i::Factory* factory, - NewStringType type, - i::Vector<const uint16_t> string) { +inline i::MaybeHandle<i::String> NewString( + i::Factory* factory, NewStringType type, + base::Vector<const uint16_t> string) { if (type == NewStringType::kInternalized) { return factory->InternalizeString(string); } @@ -6552,7 +6597,7 @@ STATIC_ASSERT(v8::String::kMaxLength == i::String::kMaxLength); if (length < 0) length = StringLength(data); \ i::Handle<i::String> handle_result = \ NewString(i_isolate->factory(), type, \ - i::Vector<const Char>(data, length)) \ + base::Vector<const Char>(data, length)) \ .ToHandleChecked(); \ result = Utils::ToLocal(handle_result); \ } @@ -6565,7 +6610,7 @@ Local<String> String::NewFromUtf8Literal(Isolate* isolate, const char* literal, LOG_API(i_isolate, String, NewFromUtf8Literal); i::Handle<i::String> handle_result = NewString(i_isolate->factory(), type, - i::Vector<const char>(literal, length)) + base::Vector<const char>(literal, length)) .ToHandleChecked(); return Utils::ToLocal(handle_result); } @@ -7003,7 +7048,7 @@ MaybeLocal<v8::RegExp> v8::RegExp::NewWithBacktrackLimit( Local<v8::String> v8::RegExp::GetSource() const { i::Handle<i::JSRegExp> obj = Utils::OpenHandle(this); return Utils::ToLocal( - i::Handle<i::String>(obj->Pattern(), obj->GetIsolate())); + i::Handle<i::String>(obj->EscapedPattern(), obj->GetIsolate())); } // Assert that the static flags cast in GetFlags is valid. @@ -7453,6 +7498,11 @@ void Promise::MarkAsHandled() { js_promise->set_has_handler(true); } +void Promise::MarkAsSilent() { + i::Handle<i::JSPromise> js_promise = Utils::OpenHandle(this); + js_promise->set_is_silent(true); +} + Local<Value> Proxy::GetTarget() { i::Handle<i::JSProxy> self = Utils::OpenHandle(this); i::Handle<i::Object> target(self->target(), self->GetIsolate()); @@ -7511,7 +7561,7 @@ OwnedBuffer CompiledWasmModule::Serialize() { MemorySpan<const uint8_t> CompiledWasmModule::GetWireBytesRef() { #if V8_ENABLE_WEBASSEMBLY - i::Vector<const uint8_t> bytes_vec = native_module_->wire_bytes(); + base::Vector<const uint8_t> bytes_vec = native_module_->wire_bytes(); return {bytes_vec.begin(), bytes_vec.size()}; #else UNREACHABLE(); @@ -7548,9 +7598,9 @@ MaybeLocal<WasmModuleObject> WasmModuleObject::FromCompiledModule( #if V8_ENABLE_WEBASSEMBLY i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); i::Handle<i::WasmModuleObject> module_object = - i_isolate->wasm_engine()->ImportNativeModule( + i::wasm::GetWasmEngine()->ImportNativeModule( i_isolate, compiled_module.native_module_, - i::VectorOf(compiled_module.source_url())); + base::VectorOf(compiled_module.source_url())); return Local<WasmModuleObject>::Cast( Utils::ToLocal(i::Handle<i::JSObject>::cast(module_object))); #else @@ -7579,7 +7629,7 @@ void* v8::ArrayBuffer::Allocator::Reallocate(void* data, size_t old_length, reinterpret_cast<uint8_t*>(AllocateUninitialized(new_length)); if (new_data == nullptr) return nullptr; size_t bytes_to_copy = std::min(old_length, new_length); - base::Memcpy(new_data, data, bytes_to_copy); + memcpy(new_data, data, bytes_to_copy); if (new_length > bytes_to_copy) { memset(new_data + bytes_to_copy, 0, new_length - bytes_to_copy); } @@ -7713,7 +7763,7 @@ size_t v8::ArrayBufferView::CopyContents(void* dest, size_t byte_length) { isolate); source = reinterpret_cast<char*>(typed_array->DataPtr()); } - base::Memcpy(dest, source + byte_offset, bytes_to_copy); + memcpy(dest, source + byte_offset, bytes_to_copy); } return bytes_to_copy; } @@ -8209,7 +8259,7 @@ void Isolate::RequestInterrupt(InterruptCallback callback, void* data) { bool Isolate::HasPendingBackgroundTasks() { #if V8_ENABLE_WEBASSEMBLY i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); - return isolate->wasm_engine()->HasRunningCompileJob(isolate); + return i::wasm::GetWasmEngine()->HasRunningCompileJob(isolate); #else return false; #endif // V8_ENABLE_WEBASSEMBLY @@ -8236,6 +8286,11 @@ Isolate* Isolate::GetCurrent() { return reinterpret_cast<Isolate*>(isolate); } +Isolate* Isolate::TryGetCurrent() { + i::Isolate* isolate = i::Isolate::TryGetCurrent(); + return reinterpret_cast<Isolate*>(isolate); +} + // static Isolate* Isolate::Allocate() { return reinterpret_cast<Isolate*>(i::Isolate::New()); @@ -8264,23 +8319,6 @@ void Isolate::Initialize(Isolate* isolate, } else { i_isolate->set_snapshot_blob(i::Snapshot::DefaultSnapshotBlob()); } - auto code_event_handler = params.code_event_handler; -#ifdef ENABLE_GDB_JIT_INTERFACE - if (code_event_handler == nullptr && i::FLAG_gdbjit) { - code_event_handler = i::GDBJITInterface::EventHandler; - } -#endif // ENABLE_GDB_JIT_INTERFACE -#if defined(V8_OS_WIN) && defined(V8_ENABLE_SYSTEM_INSTRUMENTATION) - if (code_event_handler == nullptr && i::FLAG_enable_system_instrumentation) { - code_event_handler = i::ETWJITInterface::EventHandler; - } -#endif // defined(V8_OS_WIN) - - if (code_event_handler) { - i_isolate->InitializeLoggingAndCounters(); - i_isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault, - code_event_handler); - } if (params.counter_lookup_callback) { isolate->SetCounterFunction(params.counter_lookup_callback); } @@ -8305,22 +8343,40 @@ void Isolate::Initialize(Isolate* isolate, } // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. Isolate::Scope isolate_scope(isolate); + if (i_isolate->snapshot_blob() == nullptr) { + FATAL( + "V8 snapshot blob was not set during initialization. This can mean " + "that the snapshot blob file is corrupted or missing."); + } if (!i::Snapshot::Initialize(i_isolate)) { // If snapshot data was provided and we failed to deserialize it must // have been corrupted. - if (i_isolate->snapshot_blob() != nullptr) { - FATAL( - "Failed to deserialize the V8 snapshot blob. This can mean that the " - "snapshot blob file is corrupted or missing."); + FATAL( + "Failed to deserialize the V8 snapshot blob. This can mean that the " + "snapshot blob file is corrupted or missing."); + } + + { + // Set up code event handlers. Needs to be after i::Snapshot::Initialize + // because that is where we add the isolate to WasmEngine. + auto code_event_handler = params.code_event_handler; +#ifdef ENABLE_GDB_JIT_INTERFACE + if (code_event_handler == nullptr && i::FLAG_gdbjit) { + code_event_handler = i::GDBJITInterface::EventHandler; } - base::ElapsedTimer timer; - if (i::FLAG_profile_deserialization) timer.Start(); - i_isolate->InitWithoutSnapshot(); - if (i::FLAG_profile_deserialization) { - double ms = timer.Elapsed().InMillisecondsF(); - i::PrintF("[Initializing isolate from scratch took %0.3f ms]\n", ms); +#endif // ENABLE_GDB_JIT_INTERFACE +#if defined(V8_OS_WIN) && defined(V8_ENABLE_SYSTEM_INSTRUMENTATION) + if (code_event_handler == nullptr && + i::FLAG_enable_system_instrumentation) { + code_event_handler = i::ETWJITInterface::EventHandler; + } +#endif // defined(V8_OS_WIN) + + if (code_event_handler) { + isolate->SetJitCodeEventHandler(kJitCodeEventDefault, code_event_handler); } } + i_isolate->set_only_terminate_in_safe_scope( params.only_terminate_in_safe_scope); i_isolate->set_embedder_wrapper_type_index( @@ -8534,7 +8590,12 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { heap_statistics->malloced_memory_ = isolate->allocator()->GetCurrentMemoryUsage() + isolate->string_table()->GetCurrentMemoryUsage(); - heap_statistics->external_memory_ = isolate->heap()->backing_store_bytes(); + // On 32-bit systems backing_store_bytes() might overflow size_t temporarily + // due to concurrent array buffer sweeping. + heap_statistics->external_memory_ = + isolate->heap()->backing_store_bytes() < SIZE_MAX + ? static_cast<size_t>(isolate->heap()->backing_store_bytes()) + : SIZE_MAX; heap_statistics->peak_malloced_memory_ = isolate->allocator()->GetMaxMemoryUsage(); heap_statistics->number_of_native_contexts_ = heap->NumberOfNativeContexts(); @@ -8544,9 +8605,9 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { #if V8_ENABLE_WEBASSEMBLY heap_statistics->malloced_memory_ += - isolate->wasm_engine()->allocator()->GetCurrentMemoryUsage(); + i::wasm::GetWasmEngine()->allocator()->GetCurrentMemoryUsage(); heap_statistics->peak_malloced_memory_ += - isolate->wasm_engine()->allocator()->GetMaxMemoryUsage(); + i::wasm::GetWasmEngine()->allocator()->GetMaxMemoryUsage(); #endif // V8_ENABLE_WEBASSEMBLY } @@ -8639,11 +8700,6 @@ bool Isolate::GetHeapCodeAndMetadataStatistics( return true; } -v8::MaybeLocal<v8::Promise> Isolate::MeasureMemory( - v8::Local<v8::Context> context, MeasureMemoryMode mode) { - return v8::MaybeLocal<v8::Promise>(); -} - bool Isolate::MeasureMemory(std::unique_ptr<MeasureMemoryDelegate> delegate, MeasureMemoryExecution execution) { i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); @@ -8824,7 +8880,7 @@ void Isolate::SetAddHistogramSampleFunction( void Isolate::SetMetricsRecorder( const std::shared_ptr<metrics::Recorder>& metrics_recorder) { i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); - isolate->metrics_recorder()->SetRecorder(isolate, metrics_recorder); + isolate->metrics_recorder()->SetEmbedderRecorder(isolate, metrics_recorder); } void Isolate::SetAddCrashKeyCallback(AddCrashKeyCallback callback) { @@ -8843,7 +8899,7 @@ bool Isolate::IdleNotificationDeadline(double deadline_in_seconds) { void Isolate::LowMemoryNotification() { i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); { - i::HistogramTimerScope idle_notification_scope( + i::NestedTimedHistogramScope idle_notification_scope( isolate->counters()->gc_low_memory_notification()); TRACE_EVENT0("v8", "V8.GCLowMemoryNotification"); isolate->heap()->CollectAllAvailableGarbage( @@ -8860,7 +8916,7 @@ int Isolate::ContextDisposedNotification(bool dependant_context) { // of that context. // A handle scope for the native context. i::HandleScope handle_scope(isolate); - isolate->wasm_engine()->DeleteCompileJobsOnContext( + i::wasm::GetWasmEngine()->DeleteCompileJobsOnContext( isolate->native_context()); } } @@ -8888,6 +8944,12 @@ void Isolate::MemoryPressureNotification(MemoryPressureLevel level) { isolate->heap()->MemoryPressureNotification(level, on_isolate_thread); } +void Isolate::ClearCachesForTesting() { + i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); + isolate->AbortConcurrentOptimization(i::BlockingBehavior::kBlock); + isolate->ClearSerializerData(); +} + void Isolate::EnableMemorySavingsMode() { i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); isolate->EnableMemorySavingsMode(); @@ -8951,10 +9013,10 @@ JSEntryStubs Isolate::GetJSEntryStubs() { JSEntryStubs entry_stubs; i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); - std::array<std::pair<i::Builtins::Name, JSEntryStub*>, 3> stubs = { - {{i::Builtins::kJSEntry, &entry_stubs.js_entry_stub}, - {i::Builtins::kJSConstructEntry, &entry_stubs.js_construct_entry_stub}, - {i::Builtins::kJSRunMicrotasksEntry, + std::array<std::pair<i::Builtin, JSEntryStub*>, 3> stubs = { + {{i::Builtin::kJSEntry, &entry_stubs.js_entry_stub}, + {i::Builtin::kJSConstructEntry, &entry_stubs.js_construct_entry_stub}, + {i::Builtin::kJSRunMicrotasksEntry, &entry_stubs.js_run_microtasks_entry_stub}}}; for (auto& pair : stubs) { i::Code js_entry = isolate->heap()->builtin(pair.first); @@ -9580,7 +9642,7 @@ CpuProfile* CpuProfiler::StopProfiling(Local<String> title) { void CpuProfiler::UseDetailedSourcePositionsForProfiling(Isolate* isolate) { reinterpret_cast<i::Isolate*>(isolate) - ->set_detailed_source_positions_for_profiling(true); + ->SetDetailedSourcePositionsForProfiling(true); } uintptr_t CodeEvent::GetCodeStartAddress() { @@ -9633,8 +9695,6 @@ const char* CodeEvent::GetCodeEventTypeName(CodeEventType code_event_type) { } // The execution should never pass here UNREACHABLE(); - // NOTE(mmarchini): Workaround to fix a compiler failure on GCC 4.9 - return "Unknown"; } CodeEventHandler::CodeEventHandler(Isolate* isolate) { @@ -9683,7 +9743,6 @@ Local<Value> HeapGraphEdge::GetName() const { default: UNREACHABLE(); } - return v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); } const HeapGraphNode* HeapGraphEdge::GetFromNode() const { @@ -9957,6 +10016,14 @@ void EmbedderHeapTracer::ResetHandleInNonTracingGC( UNREACHABLE(); } +void TracedReferenceBase::CheckValue() const { +#ifdef V8_HOST_ARCH_64_BIT + if (!val_) return; + + CHECK_NE(internal::kGlobalHandleZapValue, *reinterpret_cast<uint64_t*>(val_)); +#endif // V8_HOST_ARCH_64_BIT +} + CFunction::CFunction(const void* address, const CFunctionInfo* type_info) : address_(address), type_info_(type_info) { CHECK_NOT_NULL(address_); @@ -9978,6 +10045,10 @@ const CTypeInfo& CFunctionInfo::ArgumentInfo(unsigned int index) const { return arg_info_[index]; } +void FastApiTypedArrayBase::ValidateIndex(size_t index) const { + DCHECK_LT(index, length_); +} + RegisterState::RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr), lr(nullptr) {} RegisterState::~RegisterState() = default; @@ -10178,7 +10249,6 @@ void InvokeAccessorGetterCallback( Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); RCS_SCOPE(isolate, RuntimeCallCounterId::kAccessorGetterCallback); Address getter_address = reinterpret_cast<Address>(getter); - VMState<EXTERNAL> state(isolate); ExternalCallbackScope call_scope(isolate, getter_address); getter(property, info); } @@ -10188,7 +10258,6 @@ void InvokeFunctionCallback(const v8::FunctionCallbackInfo<v8::Value>& info, Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); RCS_SCOPE(isolate, RuntimeCallCounterId::kFunctionCallback); Address callback_address = reinterpret_cast<Address>(callback); - VMState<EXTERNAL> state(isolate); ExternalCallbackScope call_scope(isolate, callback_address); callback(info); } @@ -10217,12 +10286,56 @@ void InvokeFinalizationRegistryCleanupFromTask( } } +template <> +EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) +int32_t ConvertDouble(double d) { + return internal::DoubleToInt32(d); +} + +template <> +EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) +uint32_t ConvertDouble(double d) { + return internal::DoubleToUint32(d); +} + +template <> +EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) +float ConvertDouble(double d) { + return internal::DoubleToFloat32(d); +} + +template <> +EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) +double ConvertDouble(double d) { + return d; +} + +template <> +EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) +int64_t ConvertDouble(double d) { + return internal::DoubleToWebIDLInt64(d); +} + +template <> +EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) +uint64_t ConvertDouble(double d) { + return internal::DoubleToWebIDLUint64(d); +} + +template <> +EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) +bool ConvertDouble(double d) { + // Implements https://tc39.es/ecma262/#sec-toboolean. + return !std::isnan(d) && d != 0; +} + // Undefine macros for jumbo build. #undef SET_FIELD_WRAPPED #undef NEW_STRING #undef CALLBACK_SETTER } // namespace internal + } // namespace v8 #undef TRACE_BS diff --git a/chromium/v8/src/api/api.h b/chromium/v8/src/api/api.h index efb25c0e01b..7d2a0c3e9cf 100644 --- a/chromium/v8/src/api/api.h +++ b/chromium/v8/src/api/api.h @@ -536,6 +536,10 @@ void InvokeFinalizationRegistryCleanupFromTask( Handle<JSFinalizationRegistry> finalization_registry, Handle<Object> callback); +template <typename T> +EXPORT_TEMPLATE_DECLARE(V8_EXPORT_PRIVATE) +T ConvertDouble(double d); + } // namespace internal } // namespace v8 |