diff --git a/build-artifacts/project-template-gradle/settings.json b/build-artifacts/project-template-gradle/settings.json index 0e44c524d..36c44b586 100644 --- a/build-artifacts/project-template-gradle/settings.json +++ b/build-artifacts/project-template-gradle/settings.json @@ -1,3 +1,3 @@ { - "v8Version": "6.9.427.23" + "v8Version": "6.7.288.46" } \ No newline at end of file diff --git a/package.json b/package.json index 092ed71fa..c2c752551 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tns-android", "description": "NativeScript Runtime for Android", - "version": "5.0.0", + "version": "4.3.0", "repository": { "type": "git", "url": "https://github.com/NativeScript/android-runtime.git" diff --git a/test-app/app/src/main/assets/app/modules/libCalc-arm.so b/test-app/app/src/main/assets/app/modules/libCalc-arm.so index d5d3a4c5b..9da0a92f0 100755 Binary files a/test-app/app/src/main/assets/app/modules/libCalc-arm.so and b/test-app/app/src/main/assets/app/modules/libCalc-arm.so differ diff --git a/test-app/app/src/main/assets/app/modules/libCalc-arm64.so b/test-app/app/src/main/assets/app/modules/libCalc-arm64.so index 0101abdb7..93350a38d 100755 Binary files a/test-app/app/src/main/assets/app/modules/libCalc-arm64.so and b/test-app/app/src/main/assets/app/modules/libCalc-arm64.so differ diff --git a/test-app/app/src/main/assets/app/modules/libCalc-x86.so b/test-app/app/src/main/assets/app/modules/libCalc-x86.so index 078aa7233..d71510551 100755 Binary files a/test-app/app/src/main/assets/app/modules/libCalc-x86.so and b/test-app/app/src/main/assets/app/modules/libCalc-x86.so differ diff --git a/test-app/runtime/CMakeLists.txt b/test-app/runtime/CMakeLists.txt index 201480572..81ef45d1d 100644 --- a/test-app/runtime/CMakeLists.txt +++ b/test-app/runtime/CMakeLists.txt @@ -179,12 +179,12 @@ MESSAGE( STATUS "# CMAKE_CXX_FLAGS: " ${CMAKE_CXX_FLAGS} ) # linking v8 and inspector libraries to runtime(NativeScript library) target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libzip.a ) target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libv8_base.a ) -target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libv8_snapshot.a ) target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libv8_init.a ) target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libv8_initializers.a ) target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libv8_libplatform.a ) target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libv8_libsampler.a ) target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libv8_libbase.a ) +target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROID_ABI}/libv8_snapshot.a ) # Command info: https://cmake.org/cmake/help/v3.4/command/find_library.html # Searches for a specified prebuilt library and stores the path as a @@ -195,6 +195,7 @@ target_link_libraries( NativeScript ${PROJECT_SOURCE_DIR}/src/main/libs/${ANDROI find_library( system-log log ) find_library( system-android android ) find_library( system-dl dl ) +find_library( system-atomic atomic ) # TODO: plamen5kov: can't be found in ndk for some reasong ... look at it later (maybe deprecated in newer NDK versions) find_library( system-z z ) # Command info: https://cmake.org/cmake/help/v3.4/command/target_link_libraries.html diff --git a/test-app/runtime/src/main/cpp/ObjectManager.cpp b/test-app/runtime/src/main/cpp/ObjectManager.cpp index 0c91445a1..30e6f7244 100644 --- a/test-app/runtime/src/main/cpp/ObjectManager.cpp +++ b/test-app/runtime/src/main/cpp/ObjectManager.cpp @@ -482,8 +482,8 @@ void ObjectManager::MarkReachableObjects(Isolate* isolate, const Local& } auto o = top.As(); - if (!isInFirstRun) { - unsigned long addr = NativeScriptExtension::GetAddress(o); + if(!isInFirstRun) { + uint8_t* addr = NativeScriptExtension::GetAddress(o); auto itFound = m_visited.find(addr); if (itFound != m_visited.end()) { continue; diff --git a/test-app/runtime/src/main/cpp/ObjectManager.h b/test-app/runtime/src/main/cpp/ObjectManager.h index b3f50c4c7..e30de684f 100644 --- a/test-app/runtime/src/main/cpp/ObjectManager.h +++ b/test-app/runtime/src/main/cpp/ObjectManager.h @@ -201,7 +201,7 @@ class ObjectManager { PersistentObjectIdSet m_released; - std::set m_visited; + std::set m_visited; LRUCache m_cache; diff --git a/test-app/runtime/src/main/cpp/Profiler.cpp b/test-app/runtime/src/main/cpp/Profiler.cpp index b71883eb2..19041181f 100644 --- a/test-app/runtime/src/main/cpp/Profiler.cpp +++ b/test-app/runtime/src/main/cpp/Profiler.cpp @@ -82,12 +82,12 @@ void Profiler::StopCPUProfilerCallbackImpl(const v8::FunctionCallbackInfo& name) { - auto v8prof = CpuProfiler::New(isolate); + auto v8prof = isolate->GetCpuProfiler(); v8prof->StartProfiling(name, true); } bool Profiler::StopCPUProfiler(Isolate* isolate, const Local& name) { - auto v8prof = CpuProfiler::New(isolate); + auto v8prof = isolate->GetCpuProfiler(); auto cpuProfile = v8prof->StopProfiling(name); auto success = false; diff --git a/test-app/runtime/src/main/cpp/include/V8NativeScriptExtension.h b/test-app/runtime/src/main/cpp/include/V8NativeScriptExtension.h index 55f86a776..60fe9ea7d 100644 --- a/test-app/runtime/src/main/cpp/include/V8NativeScriptExtension.h +++ b/test-app/runtime/src/main/cpp/include/V8NativeScriptExtension.h @@ -1,22 +1,23 @@ #include "v8.h" namespace v8 { + + class NativeScriptExtension { + public: + static uint8_t* GetAddress(const v8::Local& obj); -class NativeScriptExtension { - public: - static unsigned long GetAddress(const v8::Local& obj); + static v8::Local* GetClosureObjects(v8::Isolate *isolate, const v8::Local& func, int *length); - static v8::Local* GetClosureObjects(v8::Isolate* isolate, const v8::Local& func, int* length); + static void ReleaseClosureObjects(v8::Local* closureObjects); + + static void GetAssessorPair(v8::Isolate *isolate, const v8::Local& obj, const v8::Local& propName, v8::Local& getter, v8::Local& setter); - static void ReleaseClosureObjects(v8::Local* closureObjects); + static v8::Local GetPropertyKeys(v8::Isolate *isolate, const v8::Local& context, const v8::Local& object, bool& success); - static void GetAssessorPair(v8::Isolate* isolate, const v8::Local& obj, const v8::Local& propName, v8::Local& getter, v8::Local& setter); + static void CpuFeaturesProbe(bool cross_compile); + private: + NativeScriptExtension(); - static v8::Local GetPropertyKeys(v8::Isolate* isolate, const v8::Local& context, const v8::Local& object, bool& success); - - static void CpuFeaturesProbe(bool cross_compile); - private: - NativeScriptExtension(); -}; + // static v8::internal::Handle GetEnumPropertyKeys(const v8::internal::Handle& object, bool cache_result); + }; } - diff --git a/test-app/runtime/src/main/cpp/include/libplatform/libplatform.h b/test-app/runtime/src/main/cpp/include/libplatform/libplatform.h index 22713cbed..dc67fb3d4 100644 --- a/test-app/runtime/src/main/cpp/include/libplatform/libplatform.h +++ b/test-app/runtime/src/main/cpp/include/libplatform/libplatform.h @@ -62,7 +62,7 @@ V8_PLATFORM_EXPORT bool PumpMessageLoop( v8::Platform* platform, v8::Isolate* isolate, MessageLoopBehavior behavior = MessageLoopBehavior::kDoNotWait); -V8_PLATFORM_EXPORT V8_DEPRECATED( +V8_PLATFORM_EXPORT V8_DEPRECATE_SOON( "This function has become obsolete and is essentially a nop", void EnsureEventLoopInitialized(v8::Platform* platform, v8::Isolate* isolate)); diff --git a/test-app/runtime/src/main/cpp/include/libplatform/v8-tracing.h b/test-app/runtime/src/main/cpp/include/libplatform/v8-tracing.h index 02f15955b..9dcf3d7bc 100644 --- a/test-app/runtime/src/main/cpp/include/libplatform/v8-tracing.h +++ b/test-app/runtime/src/main/cpp/include/libplatform/v8-tracing.h @@ -25,242 +25,188 @@ namespace tracing { const int kTraceMaxNumArgs = 2; class V8_PLATFORM_EXPORT TraceObject { - public: - union ArgValue { - bool as_bool; - uint64_t as_uint; - int64_t as_int; - double as_double; - const void* as_pointer; - const char* as_string; - }; - - TraceObject() {} - ~TraceObject(); - void Initialize( - char phase, const uint8_t* category_enabled_flag, const char* name, - const char* scope, uint64_t id, uint64_t bind_id, int num_args, - const char** arg_names, const uint8_t* arg_types, - const uint64_t* arg_values, - std::unique_ptr* arg_convertables, - unsigned int flags, int64_t timestamp, int64_t cpu_timestamp); - void UpdateDuration(int64_t timestamp, int64_t cpu_timestamp); - void InitializeForTesting( - char phase, const uint8_t* category_enabled_flag, const char* name, - const char* scope, uint64_t id, uint64_t bind_id, int num_args, - const char** arg_names, const uint8_t* arg_types, - const uint64_t* arg_values, - std::unique_ptr* arg_convertables, - unsigned int flags, int pid, int tid, int64_t ts, int64_t tts, - uint64_t duration, uint64_t cpu_duration); - - int pid() const { - return pid_; - } - int tid() const { - return tid_; - } - char phase() const { - return phase_; - } - const uint8_t* category_enabled_flag() const { - return category_enabled_flag_; - } - const char* name() const { - return name_; - } - const char* scope() const { - return scope_; - } - uint64_t id() const { - return id_; - } - uint64_t bind_id() const { - return bind_id_; - } - int num_args() const { - return num_args_; - } - const char** arg_names() { - return arg_names_; - } - uint8_t* arg_types() { - return arg_types_; - } - ArgValue* arg_values() { - return arg_values_; - } - std::unique_ptr* arg_convertables() { - return arg_convertables_; - } - unsigned int flags() const { - return flags_; - } - int64_t ts() { - return ts_; - } - int64_t tts() { - return tts_; - } - uint64_t duration() { - return duration_; - } - uint64_t cpu_duration() { - return cpu_duration_; - } - - private: - int pid_; - int tid_; - char phase_; - const char* name_; - const char* scope_; - const uint8_t* category_enabled_flag_; - uint64_t id_; - uint64_t bind_id_; - int num_args_ = 0; - const char* arg_names_[kTraceMaxNumArgs]; - uint8_t arg_types_[kTraceMaxNumArgs]; - ArgValue arg_values_[kTraceMaxNumArgs]; - std::unique_ptr - arg_convertables_[kTraceMaxNumArgs]; - char* parameter_copy_storage_ = nullptr; - unsigned int flags_; - int64_t ts_; - int64_t tts_; - uint64_t duration_; - uint64_t cpu_duration_; - - // Disallow copy and assign - TraceObject(const TraceObject&) = delete; - void operator=(const TraceObject&) = delete; + public: + union ArgValue { + bool as_bool; + uint64_t as_uint; + int64_t as_int; + double as_double; + const void* as_pointer; + const char* as_string; + }; + + TraceObject() {} + ~TraceObject(); + void Initialize( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr* arg_convertables, + unsigned int flags, int64_t timestamp, int64_t cpu_timestamp); + void UpdateDuration(int64_t timestamp, int64_t cpu_timestamp); + void InitializeForTesting( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr* arg_convertables, + unsigned int flags, int pid, int tid, int64_t ts, int64_t tts, + uint64_t duration, uint64_t cpu_duration); + + int pid() const { return pid_; } + int tid() const { return tid_; } + char phase() const { return phase_; } + const uint8_t* category_enabled_flag() const { + return category_enabled_flag_; + } + const char* name() const { return name_; } + const char* scope() const { return scope_; } + uint64_t id() const { return id_; } + uint64_t bind_id() const { return bind_id_; } + int num_args() const { return num_args_; } + const char** arg_names() { return arg_names_; } + uint8_t* arg_types() { return arg_types_; } + ArgValue* arg_values() { return arg_values_; } + std::unique_ptr* arg_convertables() { + return arg_convertables_; + } + unsigned int flags() const { return flags_; } + int64_t ts() { return ts_; } + int64_t tts() { return tts_; } + uint64_t duration() { return duration_; } + uint64_t cpu_duration() { return cpu_duration_; } + + private: + int pid_; + int tid_; + char phase_; + const char* name_; + const char* scope_; + const uint8_t* category_enabled_flag_; + uint64_t id_; + uint64_t bind_id_; + int num_args_ = 0; + const char* arg_names_[kTraceMaxNumArgs]; + uint8_t arg_types_[kTraceMaxNumArgs]; + ArgValue arg_values_[kTraceMaxNumArgs]; + std::unique_ptr + arg_convertables_[kTraceMaxNumArgs]; + char* parameter_copy_storage_ = nullptr; + unsigned int flags_; + int64_t ts_; + int64_t tts_; + uint64_t duration_; + uint64_t cpu_duration_; + + // Disallow copy and assign + TraceObject(const TraceObject&) = delete; + void operator=(const TraceObject&) = delete; }; class V8_PLATFORM_EXPORT TraceWriter { - public: - TraceWriter() {} - virtual ~TraceWriter() {} - virtual void AppendTraceEvent(TraceObject* trace_event) = 0; - virtual void Flush() = 0; - - static TraceWriter* CreateJSONTraceWriter(std::ostream& stream); - static TraceWriter* CreateJSONTraceWriter(std::ostream& stream, - const std::string& tag); - - private: - // Disallow copy and assign - TraceWriter(const TraceWriter&) = delete; - void operator=(const TraceWriter&) = delete; + public: + TraceWriter() {} + virtual ~TraceWriter() {} + virtual void AppendTraceEvent(TraceObject* trace_event) = 0; + virtual void Flush() = 0; + + static TraceWriter* CreateJSONTraceWriter(std::ostream& stream); + + private: + // Disallow copy and assign + TraceWriter(const TraceWriter&) = delete; + void operator=(const TraceWriter&) = delete; }; class V8_PLATFORM_EXPORT TraceBufferChunk { - public: - explicit TraceBufferChunk(uint32_t seq); - - void Reset(uint32_t new_seq); - bool IsFull() const { - return next_free_ == kChunkSize; - } - TraceObject* AddTraceEvent(size_t* event_index); - TraceObject* GetEventAt(size_t index) { - return &chunk_[index]; - } - - uint32_t seq() const { - return seq_; - } - size_t size() const { - return next_free_; - } - - static const size_t kChunkSize = 64; - - private: - size_t next_free_ = 0; - TraceObject chunk_[kChunkSize]; - uint32_t seq_; - - // Disallow copy and assign - TraceBufferChunk(const TraceBufferChunk&) = delete; - void operator=(const TraceBufferChunk&) = delete; + public: + explicit TraceBufferChunk(uint32_t seq); + + void Reset(uint32_t new_seq); + bool IsFull() const { return next_free_ == kChunkSize; } + TraceObject* AddTraceEvent(size_t* event_index); + TraceObject* GetEventAt(size_t index) { return &chunk_[index]; } + + uint32_t seq() const { return seq_; } + size_t size() const { return next_free_; } + + static const size_t kChunkSize = 64; + + private: + size_t next_free_ = 0; + TraceObject chunk_[kChunkSize]; + uint32_t seq_; + + // Disallow copy and assign + TraceBufferChunk(const TraceBufferChunk&) = delete; + void operator=(const TraceBufferChunk&) = delete; }; class V8_PLATFORM_EXPORT TraceBuffer { - public: - TraceBuffer() {} - virtual ~TraceBuffer() {} + public: + TraceBuffer() {} + virtual ~TraceBuffer() {} - virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0; - virtual TraceObject* GetEventByHandle(uint64_t handle) = 0; - virtual bool Flush() = 0; + virtual TraceObject* AddTraceEvent(uint64_t* handle) = 0; + virtual TraceObject* GetEventByHandle(uint64_t handle) = 0; + virtual bool Flush() = 0; - static const size_t kRingBufferChunks = 1024; + static const size_t kRingBufferChunks = 1024; - static TraceBuffer* CreateTraceBufferRingBuffer(size_t max_chunks, - TraceWriter* trace_writer); + static TraceBuffer* CreateTraceBufferRingBuffer(size_t max_chunks, + TraceWriter* trace_writer); - private: - // Disallow copy and assign - TraceBuffer(const TraceBuffer&) = delete; - void operator=(const TraceBuffer&) = delete; + private: + // Disallow copy and assign + TraceBuffer(const TraceBuffer&) = delete; + void operator=(const TraceBuffer&) = delete; }; // Options determines how the trace buffer stores data. enum TraceRecordMode { - // Record until the trace buffer is full. - RECORD_UNTIL_FULL, + // Record until the trace buffer is full. + RECORD_UNTIL_FULL, - // Record until the user ends the trace. The trace buffer is a fixed size - // and we use it as a ring buffer during recording. - RECORD_CONTINUOUSLY, + // Record until the user ends the trace. The trace buffer is a fixed size + // and we use it as a ring buffer during recording. + RECORD_CONTINUOUSLY, - // Record until the trace buffer is full, but with a huge buffer size. - RECORD_AS_MUCH_AS_POSSIBLE, + // Record until the trace buffer is full, but with a huge buffer size. + RECORD_AS_MUCH_AS_POSSIBLE, - // Echo to console. Events are discarded. - ECHO_TO_CONSOLE, + // Echo to console. Events are discarded. + ECHO_TO_CONSOLE, }; class V8_PLATFORM_EXPORT TraceConfig { - public: - typedef std::vector StringList; - - static TraceConfig* CreateDefaultTraceConfig(); - - TraceConfig() : enable_systrace_(false), enable_argument_filter_(false) {} - TraceRecordMode GetTraceRecordMode() const { - return record_mode_; - } - bool IsSystraceEnabled() const { - return enable_systrace_; - } - bool IsArgumentFilterEnabled() const { - return enable_argument_filter_; - } - - void SetTraceRecordMode(TraceRecordMode mode) { - record_mode_ = mode; - } - void EnableSystrace() { - enable_systrace_ = true; - } - void EnableArgumentFilter() { - enable_argument_filter_ = true; - } - - void AddIncludedCategory(const char* included_category); - - bool IsCategoryGroupEnabled(const char* category_group) const; - - private: - TraceRecordMode record_mode_; - bool enable_systrace_ : 1; - bool enable_argument_filter_ : 1; - StringList included_categories_; - - // Disallow copy and assign - TraceConfig(const TraceConfig&) = delete; - void operator=(const TraceConfig&) = delete; + public: + typedef std::vector StringList; + + static TraceConfig* CreateDefaultTraceConfig(); + + TraceConfig() : enable_systrace_(false), enable_argument_filter_(false) {} + TraceRecordMode GetTraceRecordMode() const { return record_mode_; } + bool IsSystraceEnabled() const { return enable_systrace_; } + bool IsArgumentFilterEnabled() const { return enable_argument_filter_; } + + void SetTraceRecordMode(TraceRecordMode mode) { record_mode_ = mode; } + void EnableSystrace() { enable_systrace_ = true; } + void EnableArgumentFilter() { enable_argument_filter_ = true; } + + void AddIncludedCategory(const char* included_category); + + bool IsCategoryGroupEnabled(const char* category_group) const; + + private: + TraceRecordMode record_mode_; + bool enable_systrace_ : 1; + bool enable_argument_filter_ : 1; + StringList included_categories_; + + // Disallow copy and assign + TraceConfig(const TraceConfig&) = delete; + void operator=(const TraceConfig&) = delete; }; #if defined(_MSC_VER) @@ -272,72 +218,72 @@ class V8_PLATFORM_EXPORT TraceConfig { class V8_PLATFORM_EXPORT TracingController : public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) { - public: - enum Mode { DISABLED = 0, RECORDING_MODE }; - - // The pointer returned from GetCategoryGroupEnabledInternal() points to a - // value with zero or more of the following bits. Used in this class only. - // The TRACE_EVENT macros should only use the value as a bool. - // These values must be in sync with macro values in TraceEvent.h in Blink. - enum CategoryGroupEnabledFlags { - // Category group enabled for the recording mode. - ENABLED_FOR_RECORDING = 1 << 0, - // Category group enabled by SetEventCallbackEnabled(). - ENABLED_FOR_EVENT_CALLBACK = 1 << 2, - // Category group enabled to export events to ETW. - ENABLED_FOR_ETW_EXPORT = 1 << 3 - }; - - TracingController(); - ~TracingController() override; - void Initialize(TraceBuffer* trace_buffer); - - // v8::TracingController implementation. - const uint8_t* GetCategoryGroupEnabled(const char* category_group) override; - uint64_t AddTraceEvent( - char phase, const uint8_t* category_enabled_flag, const char* name, - const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, - const char** arg_names, const uint8_t* arg_types, - const uint64_t* arg_values, - std::unique_ptr* arg_convertables, - unsigned int flags) override; - uint64_t AddTraceEventWithTimestamp( - char phase, const uint8_t* category_enabled_flag, const char* name, - const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, - const char** arg_names, const uint8_t* arg_types, - const uint64_t* arg_values, - std::unique_ptr* arg_convertables, - unsigned int flags, int64_t timestamp) override; - void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, - const char* name, uint64_t handle) override; - void AddTraceStateObserver( - v8::TracingController::TraceStateObserver* observer) override; - void RemoveTraceStateObserver( - v8::TracingController::TraceStateObserver* observer) override; - - void StartTracing(TraceConfig* trace_config); - void StopTracing(); - - static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag); - - protected: - virtual int64_t CurrentTimestampMicroseconds(); - virtual int64_t CurrentCpuTimestampMicroseconds(); - - private: - const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group); - void UpdateCategoryGroupEnabledFlag(size_t category_index); - void UpdateCategoryGroupEnabledFlags(); - - std::unique_ptr trace_buffer_; - std::unique_ptr trace_config_; - std::unique_ptr mutex_; - std::unordered_set observers_; - Mode mode_ = DISABLED; - - // Disallow copy and assign - TracingController(const TracingController&) = delete; - void operator=(const TracingController&) = delete; + public: + enum Mode { DISABLED = 0, RECORDING_MODE }; + + // The pointer returned from GetCategoryGroupEnabledInternal() points to a + // value with zero or more of the following bits. Used in this class only. + // The TRACE_EVENT macros should only use the value as a bool. + // These values must be in sync with macro values in TraceEvent.h in Blink. + enum CategoryGroupEnabledFlags { + // Category group enabled for the recording mode. + ENABLED_FOR_RECORDING = 1 << 0, + // Category group enabled by SetEventCallbackEnabled(). + ENABLED_FOR_EVENT_CALLBACK = 1 << 2, + // Category group enabled to export events to ETW. + ENABLED_FOR_ETW_EXPORT = 1 << 3 + }; + + TracingController(); + ~TracingController() override; + void Initialize(TraceBuffer* trace_buffer); + + // v8::TracingController implementation. + const uint8_t* GetCategoryGroupEnabled(const char* category_group) override; + uint64_t AddTraceEvent( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr* arg_convertables, + unsigned int flags) override; + uint64_t AddTraceEventWithTimestamp( + char phase, const uint8_t* category_enabled_flag, const char* name, + const char* scope, uint64_t id, uint64_t bind_id, int32_t num_args, + const char** arg_names, const uint8_t* arg_types, + const uint64_t* arg_values, + std::unique_ptr* arg_convertables, + unsigned int flags, int64_t timestamp) override; + void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, + const char* name, uint64_t handle) override; + void AddTraceStateObserver( + v8::TracingController::TraceStateObserver* observer) override; + void RemoveTraceStateObserver( + v8::TracingController::TraceStateObserver* observer) override; + + void StartTracing(TraceConfig* trace_config); + void StopTracing(); + + static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag); + + protected: + virtual int64_t CurrentTimestampMicroseconds(); + virtual int64_t CurrentCpuTimestampMicroseconds(); + + private: + const uint8_t* GetCategoryGroupEnabledInternal(const char* category_group); + void UpdateCategoryGroupEnabledFlag(size_t category_index); + void UpdateCategoryGroupEnabledFlags(); + + std::unique_ptr trace_buffer_; + std::unique_ptr trace_config_; + std::unique_ptr mutex_; + std::unordered_set observers_; + Mode mode_ = DISABLED; + + // Disallow copy and assign + TracingController(const TracingController&) = delete; + void operator=(const TracingController&) = delete; }; #undef V8_PLATFORM_NON_EXPORTED_BASE diff --git a/test-app/runtime/src/main/cpp/include/v8-inspector.h b/test-app/runtime/src/main/cpp/include/v8-inspector.h index f28470b56..6de8234fb 100644 --- a/test-app/runtime/src/main/cpp/include/v8-inspector.h +++ b/test-app/runtime/src/main/cpp/include/v8-inspector.h @@ -34,269 +34,254 @@ class Domain; } // namespace protocol class V8_EXPORT StringView { - public: - StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {} - - StringView(const uint8_t* characters, size_t length) - : m_is8Bit(true), m_length(length), m_characters8(characters) {} - - StringView(const uint16_t* characters, size_t length) - : m_is8Bit(false), m_length(length), m_characters16(characters) {} - - bool is8Bit() const { - return m_is8Bit; - } - size_t length() const { - return m_length; - } - - // TODO(dgozman): add DCHECK(m_is8Bit) to accessors once platform can be used - // here. - const uint8_t* characters8() const { - return m_characters8; - } - const uint16_t* characters16() const { - return m_characters16; - } - - private: - bool m_is8Bit; - size_t m_length; - union { - const uint8_t* m_characters8; - const uint16_t* m_characters16; - }; + public: + StringView() : m_is8Bit(true), m_length(0), m_characters8(nullptr) {} + + StringView(const uint8_t* characters, size_t length) + : m_is8Bit(true), m_length(length), m_characters8(characters) {} + + StringView(const uint16_t* characters, size_t length) + : m_is8Bit(false), m_length(length), m_characters16(characters) {} + + bool is8Bit() const { return m_is8Bit; } + size_t length() const { return m_length; } + + // TODO(dgozman): add DCHECK(m_is8Bit) to accessors once platform can be used + // here. + const uint8_t* characters8() const { return m_characters8; } + const uint16_t* characters16() const { return m_characters16; } + + private: + bool m_is8Bit; + size_t m_length; + union { + const uint8_t* m_characters8; + const uint16_t* m_characters16; + }; }; class V8_EXPORT StringBuffer { - public: - virtual ~StringBuffer() {} - virtual const StringView& string() = 0; - // This method copies contents. - static std::unique_ptr create(const StringView&); + public: + virtual ~StringBuffer() {} + virtual const StringView& string() = 0; + // This method copies contents. + static std::unique_ptr create(const StringView&); }; class V8_EXPORT V8ContextInfo { - public: - V8ContextInfo(v8::Local context, int contextGroupId, - const StringView& humanReadableName) - : context(context), - contextGroupId(contextGroupId), - humanReadableName(humanReadableName), - hasMemoryOnConsole(false) {} - - v8::Local context; - // Each v8::Context is a part of a group. The group id must be non-zero. - int contextGroupId; - StringView humanReadableName; - StringView origin; - StringView auxData; - bool hasMemoryOnConsole; - - static int executionContextId(v8::Local context); - - private: - // Disallow copying and allocating this one. - enum NotNullTagEnum { NotNullLiteral }; - void* operator new(size_t) = delete; - void* operator new(size_t, NotNullTagEnum, void*) = delete; - void* operator new(size_t, void*) = delete; - V8ContextInfo(const V8ContextInfo&) = delete; - V8ContextInfo& operator=(const V8ContextInfo&) = delete; + public: + V8ContextInfo(v8::Local context, int contextGroupId, + const StringView& humanReadableName) + : context(context), + contextGroupId(contextGroupId), + humanReadableName(humanReadableName), + hasMemoryOnConsole(false) {} + + v8::Local context; + // Each v8::Context is a part of a group. The group id must be non-zero. + int contextGroupId; + StringView humanReadableName; + StringView origin; + StringView auxData; + bool hasMemoryOnConsole; + + static int executionContextId(v8::Local context); + + private: + // Disallow copying and allocating this one. + enum NotNullTagEnum { NotNullLiteral }; + void* operator new(size_t) = delete; + void* operator new(size_t, NotNullTagEnum, void*) = delete; + void* operator new(size_t, void*) = delete; + V8ContextInfo(const V8ContextInfo&) = delete; + V8ContextInfo& operator=(const V8ContextInfo&) = delete; }; class V8_EXPORT V8StackTrace { - public: - virtual StringView firstNonEmptySourceURL() const = 0; - virtual bool isEmpty() const = 0; - virtual StringView topSourceURL() const = 0; - virtual int topLineNumber() const = 0; - virtual int topColumnNumber() const = 0; - virtual StringView topScriptId() const = 0; - virtual StringView topFunctionName() const = 0; - - virtual ~V8StackTrace() {} - virtual std::unique_ptr - buildInspectorObject() const = 0; - virtual std::unique_ptr toString() const = 0; - - // Safe to pass between threads, drops async chain. - virtual std::unique_ptr clone() = 0; + public: + virtual bool isEmpty() const = 0; + virtual StringView topSourceURL() const = 0; + virtual int topLineNumber() const = 0; + virtual int topColumnNumber() const = 0; + virtual StringView topScriptId() const = 0; + virtual StringView topFunctionName() const = 0; + + virtual ~V8StackTrace() {} + virtual std::unique_ptr + buildInspectorObject() const = 0; + virtual std::unique_ptr toString() const = 0; + + // Safe to pass between threads, drops async chain. + virtual std::unique_ptr clone() = 0; }; class V8_EXPORT V8InspectorSession { - public: - virtual ~V8InspectorSession() {} - - // Cross-context inspectable values (DOM nodes in different worlds, etc.). - class V8_EXPORT Inspectable { - public: - virtual v8::Local get(v8::Local) = 0; - virtual ~Inspectable() {} - }; - virtual void addInspectedObject(std::unique_ptr) = 0; - - // Dispatching protocol messages. - static bool canDispatchMethod(const StringView& method); - virtual void dispatchProtocolMessage(const StringView& message) = 0; - virtual std::unique_ptr stateJSON() = 0; - virtual std::vector> - supportedDomains() = 0; - - // Debugger actions. - virtual void schedulePauseOnNextStatement(const StringView& breakReason, - const StringView& breakDetails) = 0; - virtual void cancelPauseOnNextStatement() = 0; - virtual void breakProgram(const StringView& breakReason, - const StringView& breakDetails) = 0; - virtual void setSkipAllPauses(bool) = 0; - virtual void resume() = 0; - virtual void stepOver() = 0; - virtual std::vector> - searchInTextByLines(const StringView& text, const StringView& query, - bool caseSensitive, bool isRegex) = 0; - - // Remote objects. - virtual std::unique_ptr wrapObject( - v8::Local, v8::Local, const StringView& groupName, - bool generatePreview) = 0; - - virtual bool unwrapObject(std::unique_ptr* error, - const StringView& objectId, v8::Local*, - v8::Local*, - std::unique_ptr* objectGroup) = 0; - virtual void releaseObjectGroup(const StringView&) = 0; + public: + virtual ~V8InspectorSession() {} + + // Cross-context inspectable values (DOM nodes in different worlds, etc.). + class V8_EXPORT Inspectable { + public: + virtual v8::Local get(v8::Local) = 0; + virtual ~Inspectable() {} + }; + virtual void addInspectedObject(std::unique_ptr) = 0; + + // Dispatching protocol messages. + static bool canDispatchMethod(const StringView& method); + virtual void dispatchProtocolMessage(const StringView& message) = 0; + virtual std::unique_ptr stateJSON() = 0; + virtual std::vector> + supportedDomains() = 0; + + // Debugger actions. + virtual void schedulePauseOnNextStatement(const StringView& breakReason, + const StringView& breakDetails) = 0; + virtual void cancelPauseOnNextStatement() = 0; + virtual void breakProgram(const StringView& breakReason, + const StringView& breakDetails) = 0; + virtual void setSkipAllPauses(bool) = 0; + virtual void resume() = 0; + virtual void stepOver() = 0; + virtual std::vector> + searchInTextByLines(const StringView& text, const StringView& query, + bool caseSensitive, bool isRegex) = 0; + + // Remote objects. + virtual std::unique_ptr wrapObject( + v8::Local, v8::Local, const StringView& groupName, + bool generatePreview) = 0; + + virtual bool unwrapObject(std::unique_ptr* error, + const StringView& objectId, v8::Local*, + v8::Local*, + std::unique_ptr* objectGroup) = 0; + virtual void releaseObjectGroup(const StringView&) = 0; }; class V8_EXPORT V8InspectorClient { - public: - virtual ~V8InspectorClient() {} - - virtual void runMessageLoopOnPause(int contextGroupId) {} - virtual void quitMessageLoopOnPause() {} - virtual void runIfWaitingForDebugger(int contextGroupId) {} - - virtual void muteMetrics(int contextGroupId) {} - virtual void unmuteMetrics(int contextGroupId) {} - - virtual void beginUserGesture() {} - virtual void endUserGesture() {} - - virtual std::unique_ptr valueSubtype(v8::Local) { - return nullptr; - } - virtual bool formatAccessorsAsProperties(v8::Local) { - return false; - } - virtual bool isInspectableHeapObject(v8::Local) { - return true; - } - - virtual v8::Local ensureDefaultContextInGroup( - int contextGroupId) { - return v8::Local(); - } - virtual void beginEnsureAllContextsInGroup(int contextGroupId) {} - virtual void endEnsureAllContextsInGroup(int contextGroupId) {} - - virtual void installAdditionalCommandLineAPI(v8::Local, - v8::Local) {} - virtual void consoleAPIMessage(int contextGroupId, - v8::Isolate::MessageErrorLevel level, - const StringView& message, - const StringView& url, unsigned lineNumber, - unsigned columnNumber, V8StackTrace*) {} - virtual v8::MaybeLocal memoryInfo(v8::Isolate*, - v8::Local) { - return v8::MaybeLocal(); - } - - virtual void consoleTime(const StringView& title) {} - virtual void consoleTimeEnd(const StringView& title) {} - virtual void consoleTimeStamp(const StringView& title) {} - virtual void consoleClear(int contextGroupId) {} - virtual double currentTimeMS() { - return 0; - } - typedef void (*TimerCallback)(void*); - virtual void startRepeatingTimer(double, TimerCallback, void* data) {} - virtual void cancelTimer(void* data) {} - - // TODO(dgozman): this was added to support service worker shadow page. We - // should not connect at all. - virtual bool canExecuteScripts(int contextGroupId) { - return true; - } - - virtual void maxAsyncCallStackDepthChanged(int depth) {} + public: + virtual ~V8InspectorClient() {} + + virtual void runMessageLoopOnPause(int contextGroupId) {} + virtual void quitMessageLoopOnPause() {} + virtual void runIfWaitingForDebugger(int contextGroupId) {} + + virtual void muteMetrics(int contextGroupId) {} + virtual void unmuteMetrics(int contextGroupId) {} + + virtual void beginUserGesture() {} + virtual void endUserGesture() {} + + virtual std::unique_ptr valueSubtype(v8::Local) { + return nullptr; + } + virtual bool formatAccessorsAsProperties(v8::Local) { + return false; + } + virtual bool isInspectableHeapObject(v8::Local) { return true; } + + virtual v8::Local ensureDefaultContextInGroup( + int contextGroupId) { + return v8::Local(); + } + virtual void beginEnsureAllContextsInGroup(int contextGroupId) {} + virtual void endEnsureAllContextsInGroup(int contextGroupId) {} + + virtual void installAdditionalCommandLineAPI(v8::Local, + v8::Local) {} + virtual void consoleAPIMessage(int contextGroupId, + v8::Isolate::MessageErrorLevel level, + const StringView& message, + const StringView& url, unsigned lineNumber, + unsigned columnNumber, V8StackTrace*) {} + virtual v8::MaybeLocal memoryInfo(v8::Isolate*, + v8::Local) { + return v8::MaybeLocal(); + } + + virtual void consoleTime(const StringView& title) {} + virtual void consoleTimeEnd(const StringView& title) {} + virtual void consoleTimeStamp(const StringView& title) {} + virtual void consoleClear(int contextGroupId) {} + virtual double currentTimeMS() { return 0; } + typedef void (*TimerCallback)(void*); + virtual void startRepeatingTimer(double, TimerCallback, void* data) {} + virtual void cancelTimer(void* data) {} + + // TODO(dgozman): this was added to support service worker shadow page. We + // should not connect at all. + virtual bool canExecuteScripts(int contextGroupId) { return true; } + + virtual void maxAsyncCallStackDepthChanged(int depth) {} }; // These stack trace ids are intended to be passed between debuggers and be // resolved later. This allows to track cross-debugger calls and step between // them if a single client connects to multiple debuggers. struct V8_EXPORT V8StackTraceId { - uintptr_t id; - std::pair debugger_id; + uintptr_t id; + std::pair debugger_id; - V8StackTraceId(); - V8StackTraceId(uintptr_t id, const std::pair debugger_id); - ~V8StackTraceId() = default; + V8StackTraceId(); + V8StackTraceId(uintptr_t id, const std::pair debugger_id); + ~V8StackTraceId() = default; - bool IsInvalid() const; + bool IsInvalid() const; }; class V8_EXPORT V8Inspector { - public: - static std::unique_ptr create(v8::Isolate*, V8InspectorClient*); - virtual ~V8Inspector() {} - - // Contexts instrumentation. - virtual void contextCreated(const V8ContextInfo&) = 0; - virtual void contextDestroyed(v8::Local) = 0; - virtual void resetContextGroup(int contextGroupId) = 0; - - // Various instrumentation. - virtual void idleStarted() = 0; - virtual void idleFinished() = 0; - - // Async stack traces instrumentation. - virtual void asyncTaskScheduled(const StringView& taskName, void* task, - bool recurring) = 0; - virtual void asyncTaskCanceled(void* task) = 0; - virtual void asyncTaskStarted(void* task) = 0; - virtual void asyncTaskFinished(void* task) = 0; - virtual void allAsyncTasksCanceled() = 0; - - virtual V8StackTraceId storeCurrentStackTrace( - const StringView& description) = 0; - virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0; - virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0; - - // Exceptions instrumentation. - virtual unsigned exceptionThrown( - v8::Local, const StringView& message, - v8::Local exception, const StringView& detailedMessage, - const StringView& url, unsigned lineNumber, unsigned columnNumber, - std::unique_ptr, int scriptId) = 0; - virtual void exceptionRevoked(v8::Local, unsigned exceptionId, - const StringView& message) = 0; - - // Connection. - class V8_EXPORT Channel { - public: - virtual ~Channel() {} - virtual void sendResponse(int callId, - std::unique_ptr message) = 0; - virtual void sendNotification(std::unique_ptr message) = 0; - virtual void flushProtocolNotifications() = 0; - }; - virtual std::unique_ptr connect( - int contextGroupId, Channel*, const StringView& state) = 0; - - // API methods. - virtual std::unique_ptr createStackTrace( - v8::Local) = 0; - virtual std::unique_ptr captureStackTrace(bool fullStack) = 0; + public: + static std::unique_ptr create(v8::Isolate*, V8InspectorClient*); + virtual ~V8Inspector() {} + + // Contexts instrumentation. + virtual void contextCreated(const V8ContextInfo&) = 0; + virtual void contextDestroyed(v8::Local) = 0; + virtual void resetContextGroup(int contextGroupId) = 0; + + // Various instrumentation. + virtual void idleStarted() = 0; + virtual void idleFinished() = 0; + + // Async stack traces instrumentation. + virtual void asyncTaskScheduled(const StringView& taskName, void* task, + bool recurring) = 0; + virtual void asyncTaskCanceled(void* task) = 0; + virtual void asyncTaskStarted(void* task) = 0; + virtual void asyncTaskFinished(void* task) = 0; + virtual void allAsyncTasksCanceled() = 0; + + virtual V8StackTraceId storeCurrentStackTrace( + const StringView& description) = 0; + virtual void externalAsyncTaskStarted(const V8StackTraceId& parent) = 0; + virtual void externalAsyncTaskFinished(const V8StackTraceId& parent) = 0; + + // Exceptions instrumentation. + virtual unsigned exceptionThrown( + v8::Local, const StringView& message, + v8::Local exception, const StringView& detailedMessage, + const StringView& url, unsigned lineNumber, unsigned columnNumber, + std::unique_ptr, int scriptId) = 0; + virtual void exceptionRevoked(v8::Local, unsigned exceptionId, + const StringView& message) = 0; + + // Connection. + class V8_EXPORT Channel { + public: + virtual ~Channel() {} + virtual void sendResponse(int callId, + std::unique_ptr message) = 0; + virtual void sendNotification(std::unique_ptr message) = 0; + virtual void flushProtocolNotifications() = 0; + }; + virtual std::unique_ptr connect( + int contextGroupId, Channel*, const StringView& state) = 0; + + // API methods. + virtual std::unique_ptr createStackTrace( + v8::Local) = 0; + virtual std::unique_ptr captureStackTrace(bool fullStack) = 0; }; } // namespace v8_inspector diff --git a/test-app/runtime/src/main/cpp/include/v8-platform.h b/test-app/runtime/src/main/cpp/include/v8-platform.h index 590ae2eaa..b6c08c103 100644 --- a/test-app/runtime/src/main/cpp/include/v8-platform.h +++ b/test-app/runtime/src/main/cpp/include/v8-platform.h @@ -207,7 +207,6 @@ class PageAllocator { */ enum Permission { kNoAccess, - kRead, kReadWrite, // TODO(hpayer): Remove this flag. Memory should never be rwx. kReadWriteExecute, @@ -246,6 +245,16 @@ class PageAllocator { */ class Platform { public: + /** + * This enum is used to indicate whether a task is potentially long running, + * or causes a long wait. The embedder might want to use this hint to decide + * whether to execute the task on a dedicated thread. + */ + enum ExpectedRuntime { + kShortRunningTask, + kLongRunningTask + }; + virtual ~Platform() = default; /** @@ -282,25 +291,101 @@ class Platform { } /** - * Gets the number of worker threads used by - * Call(BlockingTask)OnWorkerThread(). This can be used to estimate the number - * of tasks a work package should be split into. A return value of 0 means - * that there are no worker threads available. Note that a value of 0 won't - * prohibit V8 from posting tasks using |CallOnWorkerThread|. + * Gets the number of worker threads used by GetWorkerThreadsTaskRunner() and + * CallOnWorkerThread(). This can be used to estimate the number of tasks a + * work package should be split into. A return value of 0 means that there are + * no worker threads available. Note that a value of 0 won't prohibit V8 from + * posting tasks using |CallOnWorkerThread|. + */ + virtual int NumberOfWorkerThreads() { + return static_cast(NumberOfAvailableBackgroundThreads()); + } + + /** + * Deprecated. Use NumberOfWorkerThreads() instead. + * TODO(gab): Remove this when all embedders override + * NumberOfWorkerThreads() instead. */ - virtual int NumberOfWorkerThreads() = 0; + V8_DEPRECATE_SOON( + "NumberOfAvailableBackgroundThreads() is deprecated, use " + "NumberOfAvailableBackgroundThreads() instead.", + virtual size_t NumberOfAvailableBackgroundThreads()) { + return 0; + } /** * Returns a TaskRunner which can be used to post a task on the foreground. * This function should only be called from a foreground thread. */ virtual std::shared_ptr GetForegroundTaskRunner( - Isolate* isolate) = 0; + Isolate* isolate) { + // TODO(ahaas): Make this function abstract after it got implemented on all + // platforms. + return {}; + } + + /** + * Returns a TaskRunner which can be used to post a task on a background. + * This function should only be called from a foreground thread. + */ + V8_DEPRECATE_SOON( + "GetBackgroundTaskRunner() is deprecated, use " + "GetWorkerThreadsTaskRunner() " + "instead.", + virtual std::shared_ptr GetBackgroundTaskRunner( + Isolate* isolate)) { + // TODO(gab): Remove this method when all embedders have moved to + // GetWorkerThreadsTaskRunner(). + + // An implementation needs to be provided here because this is called by the + // default GetWorkerThreadsTaskRunner() implementation below. In practice + // however, all code either: + // - Overrides GetWorkerThreadsTaskRunner() (thus not making this call) -- + // i.e. all v8 code. + // - Overrides this method (thus not making this call) -- i.e. all + // unadapted embedders. + abort(); + } + + /** + * Returns a TaskRunner which can be used to post async tasks on a worker. + * This function should only be called from a foreground thread. + */ + virtual std::shared_ptr GetWorkerThreadsTaskRunner( + Isolate* isolate) { + // TODO(gab): Make this function abstract after it got implemented on all + // platforms. + return GetBackgroundTaskRunner(isolate); + } + + /** + * Schedules a task to be invoked on a background thread. |expected_runtime| + * indicates that the task will run a long time. The Platform implementation + * takes ownership of |task|. There is no guarantee about order of execution + * of tasks wrt order of scheduling, nor is there a guarantee about the + * thread the task will be run on. + */ + V8_DEPRECATE_SOON( + "ExpectedRuntime is deprecated, use CallOnWorkerThread() instead.", + virtual void CallOnBackgroundThread(Task* task, + ExpectedRuntime expected_runtime)) { + // An implementation needs to be provided here because this is called by the + // default implementation below. In practice however, all code either: + // - Overrides the new method (thus not making this call) -- i.e. all v8 + // code. + // - Overrides this method (thus not making this call) -- i.e. all + // unadapted embedders. + abort(); + } /** * Schedules a task to be invoked on a worker thread. + * TODO(gab): Make pure virtual when all embedders override this instead of + * CallOnBackgroundThread(). */ - virtual void CallOnWorkerThread(std::unique_ptr task) = 0; + virtual void CallOnWorkerThread(std::unique_ptr task) { + CallOnBackgroundThread(task.release(), kShortRunningTask); + } /** * Schedules a task that blocks the main thread to be invoked with @@ -312,13 +397,6 @@ class Platform { CallOnWorkerThread(std::move(task)); } - /** - * Schedules a task to be invoked on a worker thread after |delay_in_seconds| - * expires. - */ - virtual void CallDelayedOnWorkerThread(std::unique_ptr task, - double delay_in_seconds) = 0; - /** * Schedules a task to be invoked on a foreground thread wrt a specific * |isolate|. Tasks posted for the same isolate should be execute in order of @@ -344,14 +422,14 @@ class Platform { * The definition of "foreground" is opaque to V8. */ virtual void CallIdleOnForegroundThread(Isolate* isolate, IdleTask* task) { - // This must be overriden if |IdleTasksEnabled()|. - abort(); + // TODO(ulan): Make this function abstract after V8 roll in Chromium. } /** * Returns true if idle tasks are enabled for the given |isolate|. */ virtual bool IdleTasksEnabled(Isolate* isolate) { + // TODO(ulan): Make this function abstract after V8 roll in Chromium. return false; } diff --git a/test-app/runtime/src/main/cpp/include/v8-profiler.h b/test-app/runtime/src/main/cpp/include/v8-profiler.h index ca7b0c21b..4250ca985 100644 --- a/test-app/runtime/src/main/cpp/include/v8-profiler.h +++ b/test-app/runtime/src/main/cpp/include/v8-profiler.h @@ -54,11 +54,7 @@ namespace v8 { */ class V8_EXPORT TracingCpuProfiler { public: - V8_DEPRECATED( - "The profiler is created automatically with the isolate.\n" - "No need to create it explicitly.", - static std::unique_ptr Create(Isolate*)); - + static std::unique_ptr Create(Isolate*); virtual ~TracingCpuProfiler() = default; protected: @@ -278,16 +274,6 @@ class V8_EXPORT CpuProfile { void Delete(); }; -enum CpuProfilingMode { - // In the resulting CpuProfile tree, intermediate nodes in a stack trace - // (from the root to a leaf) will have line numbers that point to the start - // line of the function, rather than the line of the callsite of the child. - kLeafNodeLineNumbers, - // In the resulting CpuProfile tree, nodes are separated based on the line - // number of their callsite in their parent. - kCallerLineNumbers, -}; - /** * Interface for controlling CPU profiling. Instance of the * profiler can be created using v8::CpuProfiler::New method. @@ -331,13 +317,6 @@ class V8_EXPORT CpuProfiler { * |record_samples| parameter controls whether individual samples should * be recorded in addition to the aggregated tree. */ - void StartProfiling(Local title, CpuProfilingMode mode, - bool record_samples = false); - /** - * The same as StartProfiling above, but the CpuProfilingMode defaults to - * kLeafNodeLineNumbers mode, which was the previous default behavior of the - * profiler. - */ void StartProfiling(Local title, bool record_samples = false); /** @@ -660,7 +639,7 @@ class V8_EXPORT AllocationProfile { * Usage: * 1) Define derived class of EmbedderGraph::Node for embedder objects. * 2) Set the build embedder graph callback on the heap profiler using - * HeapProfiler::AddBuildEmbedderGraphCallback. + * HeapProfiler::SetBuildEmbedderGraphCallback. * 3) In the callback use graph->AddEdge(node1, node2) to add an edge from * node1 to node2. * 4) To represent references from/to V8 object, construct V8 nodes using @@ -714,14 +693,11 @@ class V8_EXPORT EmbedderGraph { virtual Node* AddNode(std::unique_ptr node) = 0; /** - * Adds an edge that represents a strong reference from the given - * node |from| to the given node |to|. The nodes must be added to the graph + * Adds an edge that represents a strong reference from the given node + * |from| to the given node |to|. The nodes must be added to the graph * before calling this function. - * - * If name is nullptr, the edge will have auto-increment indexes, otherwise - * it will be named accordingly. */ - virtual void AddEdge(Node* from, Node* to, const char* name = nullptr) = 0; + virtual void AddEdge(Node* from, Node* to) = 0; virtual ~EmbedderGraph() = default; }; @@ -771,11 +747,6 @@ class V8_EXPORT HeapProfiler { * The callback must not trigger garbage collection in V8. */ typedef void (*BuildEmbedderGraphCallback)(v8::Isolate* isolate, - v8::EmbedderGraph* graph, - void* data); - - /** TODO(addaleax): Remove */ - typedef void (*LegacyBuildEmbedderGraphCallback)(v8::Isolate* isolate, v8::EmbedderGraph* graph); /** Returns the number of snapshots taken. */ @@ -918,22 +889,15 @@ class V8_EXPORT HeapProfiler { /** Binds a callback to embedder's class ID. */ V8_DEPRECATED( - "Use AddBuildEmbedderGraphCallback to provide info about embedder nodes", + "Use SetBuildEmbedderGraphCallback to provide info about embedder nodes", void SetWrapperClassInfoProvider(uint16_t class_id, WrapperInfoCallback callback)); V8_DEPRECATED( - "Use AddBuildEmbedderGraphCallback to provide info about embedder nodes", + "Use SetBuildEmbedderGraphCallback to provide info about embedder nodes", void SetGetRetainerInfosCallback(GetRetainerInfosCallback callback)); - V8_DEPRECATE_SOON( - "Use AddBuildEmbedderGraphCallback to provide info about embedder nodes", - void SetBuildEmbedderGraphCallback( - LegacyBuildEmbedderGraphCallback callback)); - void AddBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback, - void* data); - void RemoveBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback, - void* data); + void SetBuildEmbedderGraphCallback(BuildEmbedderGraphCallback callback); /** * Default value of persistent handle class ID. Must not be used to @@ -1041,76 +1005,6 @@ struct HeapStatsUpdate { uint32_t size; // New value of size field for the interval with this index. }; -#define CODE_EVENTS_LIST(V) \ - V(Builtin) \ - V(Callback) \ - V(Eval) \ - V(Function) \ - V(InterpretedFunction) \ - V(Handler) \ - V(BytecodeHandler) \ - V(LazyCompile) \ - V(RegExp) \ - V(Script) \ - V(Stub) - -/** - * Note that this enum may be extended in the future. Please include a default - * case if this enum is used in a switch statement. - */ -enum CodeEventType { - kUnknownType = 0 -#define V(Name) , k##Name##Type - CODE_EVENTS_LIST(V) -#undef V -}; - -/** - * Representation of a code creation event - */ -class V8_EXPORT CodeEvent { - public: - uintptr_t GetCodeStartAddress(); - size_t GetCodeSize(); - Local GetFunctionName(); - Local GetScriptName(); - int GetScriptLine(); - int GetScriptColumn(); - /** - * NOTE (mmarchini): We can't allocate objects in the heap when we collect - * existing code, and both the code type and the comment are not stored in the - * heap, so we return those as const char*. - */ - CodeEventType GetCodeType(); - const char* GetComment(); - - static const char* GetCodeEventTypeName(CodeEventType code_event_type); -}; - -/** - * Interface to listen to code creation events. - */ -class V8_EXPORT CodeEventHandler { - public: - /** - * Creates a new listener for the |isolate|. The isolate must be initialized. - * The listener object must be disposed after use by calling |Dispose| method. - * Multiple listeners can be created for the same isolate. - */ - explicit CodeEventHandler(Isolate* isolate); - virtual ~CodeEventHandler(); - - virtual void Handle(CodeEvent* code_event) = 0; - - void Enable(); - void Disable(); - - private: - CodeEventHandler(); - CodeEventHandler(const CodeEventHandler&); - CodeEventHandler& operator=(const CodeEventHandler&); - void* internal_listener_; -}; } // namespace v8 diff --git a/test-app/runtime/src/main/cpp/include/v8-version.h b/test-app/runtime/src/main/cpp/include/v8-version.h index 57fbc6296..440a60686 100644 --- a/test-app/runtime/src/main/cpp/include/v8-version.h +++ b/test-app/runtime/src/main/cpp/include/v8-version.h @@ -9,9 +9,9 @@ // NOTE these macros are used by some of the tool scripts and the build // system so their names cannot be changed without changing the scripts. #define V8_MAJOR_VERSION 6 -#define V8_MINOR_VERSION 9 -#define V8_BUILD_NUMBER 427 -#define V8_PATCH_LEVEL 23 +#define V8_MINOR_VERSION 7 +#define V8_BUILD_NUMBER 288 +#define V8_PATCH_LEVEL 46 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) diff --git a/test-app/runtime/src/main/cpp/include/v8.h b/test-app/runtime/src/main/cpp/include/v8.h index 5bf0606f9..d685010c2 100644 --- a/test-app/runtime/src/main/cpp/include/v8.h +++ b/test-app/runtime/src/main/cpp/include/v8.h @@ -71,6 +71,7 @@ class BigIntObject; class Boolean; class BooleanObject; class Context; +class CpuProfiler; class Data; class Date; class External; @@ -145,8 +146,6 @@ class DeferredHandles; class Heap; class HeapObject; class Isolate; -class LocalEmbedderHeapTracer; -class NeverReadOnlySpaceObject; class Object; struct ScriptStreamingData; template class CustomArguments; @@ -155,118 +154,8 @@ class FunctionCallbackArguments; class GlobalHandles; namespace wasm { -class CompilationResultResolver; class StreamingDecoder; } // namespace wasm - -/** - * Configuration of tagging scheme. - */ -const int kApiPointerSize = sizeof(void*); // NOLINT -const int kApiDoubleSize = sizeof(double); // NOLINT -const int kApiIntSize = sizeof(int); // NOLINT -const int kApiInt64Size = sizeof(int64_t); // NOLINT - -// Tag information for HeapObject. -const int kHeapObjectTag = 1; -const int kWeakHeapObjectTag = 3; -const int kHeapObjectTagSize = 2; -const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; - -// Tag information for Smi. -const int kSmiTag = 0; -const int kSmiTagSize = 1; -const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; - -template -struct SmiTagging; - -template -V8_INLINE internal::Object* IntToSmi(int value) { - int smi_shift_bits = kSmiTagSize + kSmiShiftSize; - intptr_t tagged_value = - (static_cast(value) << smi_shift_bits) | kSmiTag; - return reinterpret_cast(tagged_value); -} - -// Smi constants for systems where tagged pointer is a 32-bit value. -template <> -struct SmiTagging<4> { - enum { kSmiShiftSize = 0, kSmiValueSize = 31 }; - static int SmiShiftSize() { - return kSmiShiftSize; - } - static int SmiValueSize() { - return kSmiValueSize; - } - V8_INLINE static int SmiToInt(const internal::Object* value) { - int shift_bits = kSmiTagSize + kSmiShiftSize; - // Throw away top 32 bits and shift down (requires >> to be sign extending). - return static_cast(reinterpret_cast(value)) >> shift_bits; - } - V8_INLINE static internal::Object* IntToSmi(int value) { - return internal::IntToSmi(value); - } - V8_INLINE static bool IsValidSmi(intptr_t value) { - // To be representable as an tagged small integer, the two - // most-significant bits of 'value' must be either 00 or 11 due to - // sign-extension. To check this we add 01 to the two - // most-significant bits, and check if the most-significant bit is 0 - // - // CAUTION: The original code below: - // bool result = ((value + 0x40000000) & 0x80000000) == 0; - // may lead to incorrect results according to the C language spec, and - // in fact doesn't work correctly with gcc4.1.1 in some cases: The - // compiler may produce undefined results in case of signed integer - // overflow. The computation must be done w/ unsigned ints. - return static_cast(value) + 0x40000000U < 0x80000000U; - } -}; - -// Smi constants for systems where tagged pointer is a 64-bit value. -template <> -struct SmiTagging<8> { - enum { kSmiShiftSize = 31, kSmiValueSize = 32 }; - static int SmiShiftSize() { - return kSmiShiftSize; - } - static int SmiValueSize() { - return kSmiValueSize; - } - V8_INLINE static int SmiToInt(const internal::Object* value) { - int shift_bits = kSmiTagSize + kSmiShiftSize; - // Shift down and throw away top 32 bits. - return static_cast(reinterpret_cast(value) >> shift_bits); - } - V8_INLINE static internal::Object* IntToSmi(int value) { - return internal::IntToSmi(value); - } - V8_INLINE static bool IsValidSmi(intptr_t value) { - // To be representable as a long smi, the value must be a 32-bit integer. - return (value == static_cast(value)); - } -}; - -#if V8_COMPRESS_POINTERS -static_assert( - kApiPointerSize == kApiInt64Size, - "Pointer compression can be enabled only for 64-bit architectures"); -typedef SmiTagging<4> PlatformSmiTagging; -#else -typedef SmiTagging PlatformSmiTagging; -#endif - -const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; -const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; -const int kSmiMinValue = (static_cast(-1)) << (kSmiValueSize - 1); -const int kSmiMaxValue = -(kSmiMinValue + 1); -constexpr bool SmiValuesAre31Bits() { - return kSmiValueSize == 31; -} -constexpr bool SmiValuesAre32Bits() { - return kSmiValueSize == 32; -} - } // namespace internal namespace debug { @@ -1061,8 +950,8 @@ class V8_EXPORT HandleScope { void operator delete[](void*, size_t); // Uses heap_object to obtain the current Isolate. - static internal::Object** CreateHandle( - internal::NeverReadOnlySpaceObject* heap_object, internal::Object* value); + static internal::Object** CreateHandle(internal::HeapObject* heap_object, + internal::Object* value); internal::Isolate* isolate_; internal::Object** prev_next_; @@ -1098,11 +987,6 @@ class V8_EXPORT EscapableHandleScope : public HandleScope { return Local(reinterpret_cast(slot)); } - template - V8_INLINE MaybeLocal EscapeMaybe(MaybeLocal value) { - return Escape(value.FromMaybe(Local())); - } - EscapableHandleScope(const EscapableHandleScope&) = delete; void operator=(const EscapableHandleScope&) = delete; @@ -1189,12 +1073,8 @@ class V8_EXPORT PrimitiveArray { public: static Local New(Isolate* isolate, int length); int Length() const; - void Set(Isolate* isolate, int index, Local item); - Local Get(Isolate* isolate, int index); - - V8_DEPRECATE_SOON("Use Isolate version", - void Set(int index, Local item)); - V8_DEPRECATE_SOON("Use Isolate version", Local Get(int index)); + void Set(int index, Local item); + Local Get(int index); }; /** @@ -1307,13 +1187,6 @@ class V8_EXPORT UnboundScript { static const int kNoScriptId = 0; }; -/** - * A compiled JavaScript module, not yet tied to a Context. - */ -class V8_EXPORT UnboundModuleScript { - // Only used as a container for code caching. -}; - /** * A location in JavaScript source. */ @@ -1417,14 +1290,6 @@ class V8_EXPORT Module { * The module's status must be at least kInstantiated. */ Local GetModuleNamespace(); - - /** - * Returns the corresponding context-unbound module script. - * - * The module must be unevaluated, i.e. its status must not be kEvaluating, - * kEvaluated or kErrored. - */ - Local GetUnboundModuleScript(); }; /** @@ -1567,10 +1432,6 @@ class V8_EXPORT ScriptCompiler { * more than two data chunks. The embedder can avoid this problem by always * returning at least 2 bytes of data. * - * When streaming UTF-16 data, V8 does not handle characters split between - * two data chunks. The embedder has to make sure that chunks have an even - * length. - * * If the embedder wants to cancel the streaming, they should make the next * GetMoreData call return 0. V8 will interpret it as end of data (and most * probably, parsing will fail). The streaming task will return as soon as @@ -1756,9 +1617,7 @@ class V8_EXPORT ScriptCompiler { * ECMAScript specification. */ static V8_WARN_UNUSED_RESULT MaybeLocal CompileModule( - Isolate* isolate, Source* source, - CompileOptions options = kNoCompileOptions, - NoCacheReason no_cache_reason = kNoCacheNoReason); + Isolate* isolate, Source* source); /** * Compile a function for a given context. This is equivalent to running @@ -1789,19 +1648,8 @@ class V8_EXPORT ScriptCompiler { * This will return nullptr if the script cannot be serialized. The * CachedData returned by this function should be owned by the caller. */ - static CachedData* CreateCodeCache(Local unbound_script); - - /** - * Creates and returns code cache for the specified unbound_module_script. - * This will return nullptr if the script cannot be serialized. The - * CachedData returned by this function should be owned by the caller. - */ - static CachedData* CreateCodeCache( - Local unbound_module_script); - - V8_DEPRECATED("Source string is no longer required", - static CachedData* CreateCodeCache( - Local unbound_script, Local source)); + static CachedData* CreateCodeCache(Local unbound_script, + Local source); /** * Creates and returns code cache for the specified function that was @@ -1809,11 +1657,8 @@ class V8_EXPORT ScriptCompiler { * This will return nullptr if the script cannot be serialized. The * CachedData returned by this function should be owned by the caller. */ - static CachedData* CreateCodeCacheForFunction(Local function); - - V8_DEPRECATED("Source string is no longer required", - static CachedData* CreateCodeCacheForFunction( - Local function, Local source)); + static CachedData* CreateCodeCacheForFunction(Local function, + Local source); private: static V8_WARN_UNUSED_RESULT MaybeLocal CompileUnboundInternal( @@ -1935,9 +1780,7 @@ class V8_EXPORT StackTrace { /** * Returns a StackFrame at a particular index. */ - V8_DEPRECATE_SOON("Use Isolate version", - Local GetFrame(uint32_t index) const); - Local GetFrame(Isolate* isolate, uint32_t index) const; + Local GetFrame(uint32_t index) const; /** * Returns the number of StackFrames. @@ -2134,16 +1977,12 @@ class V8_EXPORT ValueSerializer { * If the memory cannot be allocated, nullptr should be returned. * |actual_size| will be ignored. It is assumed that |old_buffer| is still * valid in this case and has not been modified. - * - * The default implementation uses the stdlib's `realloc()` function. */ virtual void* ReallocateBufferMemory(void* old_buffer, size_t size, size_t* actual_size); /** * Frees a buffer allocated with |ReallocateBufferMemory|. - * - * The default implementation uses the stdlib's `free()` function. */ virtual void FreeBufferMemory(void* buffer); }; @@ -2171,9 +2010,9 @@ class V8_EXPORT ValueSerializer { /** * Returns the stored data (allocated using the delegate's - * ReallocateBufferMemory) and its size. This serializer should not be used - * once the buffer is released. The contents are undefined if a previous write - * has failed. Ownership of the buffer is transferred to the caller. + * AllocateBufferMemory) and its size. This serializer should not be used once + * the buffer is released. The contents are undefined if a previous write has + * failed. */ V8_WARN_UNUSED_RESULT std::pair Release(); @@ -2609,11 +2448,6 @@ class V8_EXPORT Value : public Data { bool IsWebAssemblyCompiledModule() const; - /** - * Returns true if the value is a Module Namespace Object. - */ - bool IsModuleNamespaceObject() const; - V8_WARN_UNUSED_RESULT MaybeLocal ToBigInt( Local context) const; V8_WARN_UNUSED_RESULT MaybeLocal ToBoolean( @@ -2763,9 +2597,8 @@ enum class NewStringType { */ class V8_EXPORT String : public Name { public: - static constexpr int kMaxLength = internal::kApiPointerSize == 4 - ? (1 << 28) - 16 - : internal::kSmiMaxValue / 2 - 24; + static constexpr int kMaxLength = + sizeof(void*) == 4 ? (1 << 28) - 16 : (1 << 30) - 1 - 24; enum Encoding { UNKNOWN_ENCODING = 0x1, @@ -2781,9 +2614,7 @@ class V8_EXPORT String : public Name { * Returns the number of bytes in the UTF-8 encoded * representation of this string. */ - V8_DEPRECATE_SOON("Use Isolate version instead", int Utf8Length() const); - - int Utf8Length(Isolate* isolate) const; + int Utf8Length() const; /** * Returns whether this string is known to contain only one byte data, @@ -2837,25 +2668,20 @@ class V8_EXPORT String : public Name { }; // 16-bit character codes. - int Write(Isolate* isolate, uint16_t* buffer, int start = 0, int length = -1, + int Write(uint16_t* buffer, + int start = 0, + int length = -1, int options = NO_OPTIONS) const; - V8_DEPRECATE_SOON("Use Isolate* version", - int Write(uint16_t* buffer, int start = 0, int length = -1, - int options = NO_OPTIONS) const); // One byte characters. - int WriteOneByte(Isolate* isolate, uint8_t* buffer, int start = 0, - int length = -1, int options = NO_OPTIONS) const; - V8_DEPRECATE_SOON("Use Isolate* version", - int WriteOneByte(uint8_t* buffer, int start = 0, - int length = -1, int options = NO_OPTIONS) - const); + int WriteOneByte(uint8_t* buffer, + int start = 0, + int length = -1, + int options = NO_OPTIONS) const; // UTF-8 encoded characters. - int WriteUtf8(Isolate* isolate, char* buffer, int length = -1, - int* nchars_ref = NULL, int options = NO_OPTIONS) const; - V8_DEPRECATE_SOON("Use Isolate* version", - int WriteUtf8(char* buffer, int length = -1, - int* nchars_ref = NULL, - int options = NO_OPTIONS) const); + int WriteUtf8(char* buffer, + int length = -1, + int* nchars_ref = NULL, + int options = NO_OPTIONS) const; /** * A zero length string. @@ -3021,11 +2847,7 @@ class V8_EXPORT String : public Name { * Creates a new string by concatenating the left and the right strings * passed in as parameters. */ - static Local Concat(Isolate* isolate, Local left, - Local right); - static V8_DEPRECATE_SOON("Use Isolate* version", - Local Concat(Local left, - Local right)); + static Local Concat(Local left, Local right); /** * Creates a new external string using the data defined in the given @@ -3301,48 +3123,6 @@ class V8_EXPORT Uint32 : public Integer { class V8_EXPORT BigInt : public Primitive { public: static Local New(Isolate* isolate, int64_t value); - static Local NewFromUnsigned(Isolate* isolate, uint64_t value); - /** - * Creates a new BigInt object using a specified sign bit and a - * specified list of digits/words. - * The resulting number is calculated as: - * - * (-1)^sign_bit * (words[0] * (2^64)^0 + words[1] * (2^64)^1 + ...) - */ - static MaybeLocal NewFromWords(Local context, int sign_bit, - int word_count, const uint64_t* words); - - /** - * Returns the value of this BigInt as an unsigned 64-bit integer. - * If `lossless` is provided, it will reflect whether the return value was - * truncated or wrapped around. In particular, it is set to `false` if this - * BigInt is negative. - */ - uint64_t Uint64Value(bool* lossless = nullptr) const; - - /** - * Returns the value of this BigInt as a signed 64-bit integer. - * If `lossless` is provided, it will reflect whether this BigInt was - * truncated or not. - */ - int64_t Int64Value(bool* lossless = nullptr) const; - - /** - * Returns the number of 64-bit words needed to store the result of - * ToWordsArray(). - */ - int WordCount() const; - - /** - * Writes the contents of this BigInt to a specified memory location. - * `sign_bit` must be provided and will be set to 1 if this BigInt is - * negative. - * `*word_count` has to be initialized to the length of the `words` array. - * Upon return, it will be set to the actual number of words that would - * be needed to store this BigInt (i.e. the return value of `WordCount()`). - */ - void ToWordsArray(int* sign_bit, int* word_count, uint64_t* words) const; - V8_INLINE static BigInt* Cast(v8::Value* obj); private: @@ -3850,17 +3630,6 @@ class V8_EXPORT Object : public Value { */ Isolate* GetIsolate(); - /** - * If this object is a Set, Map, WeakSet or WeakMap, this returns a - * representation of the elements of this object as an array. - * If this object is a SetIterator or MapIterator, this returns all - * elements of the underlying collection, starting at the iterator's current - * position. - * For other types, this will return an empty MaybeLocal (without - * scheduling an exception). - */ - MaybeLocal PreviewEntries(bool* is_key_value); - static Local New(Isolate* isolate); V8_INLINE static Object* Cast(Value* obj); @@ -4213,15 +3982,6 @@ class V8_EXPORT Function : public Object { return NewInstance(context, 0, nullptr); } - /** - * When side effect checks are enabled, passing kHasNoSideEffect allows the - * constructor to be invoked without throwing. Calls made within the - * constructor are still checked. - */ - V8_WARN_UNUSED_RESULT MaybeLocal NewInstanceWithSideEffectType( - Local context, int argc, Local argv[], - SideEffectType side_effect_type = SideEffectType::kHasSideEffect) const; - V8_DEPRECATE_SOON("Use maybe version", Local Call(Local recv, int argc, Local argv[])); @@ -4476,29 +4236,10 @@ class V8_EXPORT Proxy : public Object { class V8_EXPORT WasmCompiledModule : public Object { public: typedef std::pair, size_t> SerializedModule; - -// The COMMA macro allows us to use ',' inside of the V8_DEPRECATE_SOON macro. -#define COMMA , - V8_DEPRECATE_SOON( - "Use BufferReference.", - typedef std::pair CallerOwnedBuffer); -#undef COMMA - - /** - * A unowned reference to a byte buffer. - */ - struct BufferReference { - const uint8_t* start; - size_t size; - BufferReference(const uint8_t* start, size_t size) - : start(start), size(size) {} - // Temporarily allow conversion to and from CallerOwnedBuffer. - V8_DEPRECATE_SOON( - "Use BufferReference directly.", - inline BufferReference(CallerOwnedBuffer)); // NOLINT(runtime/explicit) - V8_DEPRECATE_SOON("Use BufferReference directly.", - inline operator CallerOwnedBuffer()); - }; + /** + * A buffer that is owned by the caller. + */ + typedef std::pair CallerOwnedBuffer; /** * An opaque, native heap object for transferring wasm modules. It @@ -4515,7 +4256,7 @@ class V8_EXPORT WasmCompiledModule : public Object { private: typedef std::pair, size_t> OwnedBuffer; friend class WasmCompiledModule; - TransferrableModule(OwnedBuffer code, OwnedBuffer bytes) + TransferrableModule(OwnedBuffer&& code, OwnedBuffer&& bytes) : compiled_code(std::move(code)), wire_bytes(std::move(bytes)) {} OwnedBuffer compiled_code = {nullptr, 0}; @@ -4539,9 +4280,7 @@ class V8_EXPORT WasmCompiledModule : public Object { /** * Get the wasm-encoded bytes that were used to compile this module. */ - BufferReference GetWasmWireBytesRef(); - V8_DEPRECATE_SOON("Use GetWasmWireBytesRef version.", - Local GetWasmWireBytes()); + Local GetWasmWireBytes(); /** * Serialize the compiled module. The serialized data does not include the @@ -4554,18 +4293,18 @@ class V8_EXPORT WasmCompiledModule : public Object { * uncompiled bytes. */ static MaybeLocal DeserializeOrCompile( - Isolate* isolate, BufferReference serialized_module, - BufferReference wire_bytes); + Isolate* isolate, const CallerOwnedBuffer& serialized_module, + const CallerOwnedBuffer& wire_bytes); V8_INLINE static WasmCompiledModule* Cast(Value* obj); private: static MaybeLocal Deserialize( - Isolate* isolate, BufferReference serialized_module, - BufferReference wire_bytes); + Isolate* isolate, const CallerOwnedBuffer& serialized_module, + const CallerOwnedBuffer& wire_bytes); static MaybeLocal Compile(Isolate* isolate, const uint8_t* start, size_t length); - static BufferReference AsReference( + static CallerOwnedBuffer AsCallerOwned( const TransferrableModule::OwnedBuffer& buff) { return {buff.first.get(), buff.second}; } @@ -4574,61 +4313,6 @@ class V8_EXPORT WasmCompiledModule : public Object { static void CheckCast(Value* obj); }; -// TODO(clemensh): Remove after M69 branch. -WasmCompiledModule::BufferReference::BufferReference( - WasmCompiledModule::CallerOwnedBuffer buf) - : BufferReference(buf.first, buf.second) {} -WasmCompiledModule::BufferReference:: -operator WasmCompiledModule::CallerOwnedBuffer() { - return {start, size}; -} - -/** - * The V8 interface for WebAssembly streaming compilation. When streaming - * compilation is initiated, V8 passes a {WasmStreaming} object to the embedder - * such that the embedder can pass the input butes for streaming compilation to - * V8. - */ -class V8_EXPORT WasmStreaming final { - public: - class WasmStreamingImpl; - - WasmStreaming(std::unique_ptr impl); - - ~WasmStreaming(); - - /** - * Pass a new chunck of bytes to WebAssembly streaming compilation. - * The buffer passed into {OnBytesReceived} is owned by the caller. - */ - void OnBytesReceived(const uint8_t* bytes, size_t size); - - /** - * {Finish} should be called after all received bytes where passed to - * {OnBytesReceived} to tell V8 that there will be no more bytes. {Finish} - * does not have to be called after {Abort} has been called already. - */ - void Finish(); - - /** - * Abort streaming compilation. If {exception} has a value, then the promise - * associated with streaming compilation is rejected with that value. If - * {exception} does not have value, the promise does not get rejected. - */ - void Abort(MaybeLocal exception); - - /** - * Unpacks a {WasmStreaming} object wrapped in a {Managed} for the embedder. - * Since the embedder is on the other side of the API, it cannot unpack the - * {Managed} itself. - */ - static std::shared_ptr Unpack(Isolate* isolate, - Local value); - - private: - std::unique_ptr impl_; -}; - // TODO(mtrofin): when streaming compilation is done, we can rename this // to simply WasmModuleObjectBuilder class V8_EXPORT WasmModuleObjectBuilderStreaming final { @@ -4650,6 +4334,8 @@ class V8_EXPORT WasmModuleObjectBuilderStreaming final { ~WasmModuleObjectBuilderStreaming(); private: + typedef std::pair, size_t> Buffer; + WasmModuleObjectBuilderStreaming(const WasmModuleObjectBuilderStreaming&) = delete; WasmModuleObjectBuilderStreaming(WasmModuleObjectBuilderStreaming&&) = @@ -4672,6 +4358,8 @@ class V8_EXPORT WasmModuleObjectBuilderStreaming final { #else Persistent promise_; #endif + std::vector received_buffers_; + size_t total_size_ = 0; std::shared_ptr streaming_decoder_; }; @@ -4930,7 +4618,8 @@ class V8_EXPORT TypedArray : public ArrayBufferView { /* * The largest typed array size that can be constructed using New. */ - static constexpr size_t kMaxLength = internal::kSmiMaxValue; + static constexpr size_t kMaxLength = + sizeof(void*) == 4 ? (1u << 30) - 1 : (1u << 31) - 1; /** * Number of elements in this typed array @@ -5356,9 +5045,7 @@ class V8_EXPORT BooleanObject : public Object { */ class V8_EXPORT StringObject : public Object { public: - static Local New(Isolate* isolate, Local value); - static V8_DEPRECATE_SOON("Use Isolate* version", - Local New(Local value)); + static Local New(Local value); Local ValueOf() const; @@ -5525,25 +5212,22 @@ class V8_EXPORT Template : public Data { // TODO(dcarney): gcc can't handle Local below Local data = Local(), PropertyAttribute attribute = None, Local signature = Local(), - AccessControl settings = DEFAULT, - SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect); + AccessControl settings = DEFAULT); void SetNativeDataProperty( Local name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter = 0, // TODO(dcarney): gcc can't handle Local below Local data = Local(), PropertyAttribute attribute = None, Local signature = Local(), - AccessControl settings = DEFAULT, - SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect); + AccessControl settings = DEFAULT); /** * Like SetNativeDataProperty, but V8 will replace the native data property * with a real data property on first access. */ - void SetLazyDataProperty( - Local name, AccessorNameGetterCallback getter, - Local data = Local(), PropertyAttribute attribute = None, - SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect); + void SetLazyDataProperty(Local name, AccessorNameGetterCallback getter, + Local data = Local(), + PropertyAttribute attribute = None); /** * During template instantiation, sets the value with the intrinsic property @@ -6267,14 +5951,12 @@ class V8_EXPORT ObjectTemplate : public Template { Local name, AccessorGetterCallback getter, AccessorSetterCallback setter = 0, Local data = Local(), AccessControl settings = DEFAULT, PropertyAttribute attribute = None, - Local signature = Local(), - SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect); + Local signature = Local()); void SetAccessor( Local name, AccessorNameGetterCallback getter, AccessorNameSetterCallback setter = 0, Local data = Local(), AccessControl settings = DEFAULT, PropertyAttribute attribute = None, - Local signature = Local(), - SideEffectType getter_side_effect_type = SideEffectType::kHasSideEffect); + Local signature = Local()); /** * Sets a named property handler on the object template. @@ -6480,8 +6162,7 @@ class V8_EXPORT AccessorSignature : public Data { // --- Extensions --- -V8_DEPRECATE_SOON("Implementation detail", - class ExternalOneByteStringResourceImpl); + class V8_EXPORT ExternalOneByteStringResourceImpl : public String::ExternalOneByteStringResource { public: @@ -6512,9 +6193,7 @@ class V8_EXPORT Extension { // NOLINT int dep_count = 0, const char** deps = 0, int source_length = -1); - virtual ~Extension() { - delete source_; - } + virtual ~Extension() { } virtual Local GetNativeFunctionTemplate( Isolate* isolate, Local name) { return Local(); @@ -6527,7 +6206,7 @@ class V8_EXPORT Extension { // NOLINT return source_length_; } const String::ExternalOneByteStringResource* source() const { - return source_; + return &source_; } int dependency_count() { return dep_count_; @@ -6549,7 +6228,7 @@ class V8_EXPORT Extension { // NOLINT private: const char* name_; size_t source_length_; // expected to initialize before source_ - String::ExternalOneByteStringResource* source_; + ExternalOneByteStringResourceImpl source_; int dep_count_; const char** deps_; bool auto_enable_; @@ -6786,9 +6465,7 @@ typedef void (*PromiseHook)(PromiseHookType type, Local promise, // --- Promise Reject Callback --- enum PromiseRejectEvent { kPromiseRejectWithNoHandler = 0, - kPromiseHandlerAddedAfterReject = 1, - kPromiseRejectAfterResolved = 2, - kPromiseResolveAfterResolved = 3, + kPromiseHandlerAddedAfterReject = 1 }; class PromiseRejectMessage { @@ -6899,9 +6576,6 @@ typedef bool (*AllowWasmCodeGenerationCallback)(Local context, // by the embedder. Example: WebAssembly.{compile|instantiate}Streaming --- typedef void (*ApiImplementationCallback)(const FunctionCallbackInfo&); -// --- Callback for WebAssembly.compileStreaming --- -typedef void (*WasmStreamingCallback)(const FunctionCallbackInfo&); - // --- Garbage Collection Callbacks --- /** @@ -7088,14 +6762,10 @@ class V8_EXPORT HeapCodeStatistics { size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; } - size_t external_script_source_size() { - return external_script_source_size_; - } private: size_t code_and_metadata_size_; size_t bytecode_and_metadata_size_; - size_t external_script_source_size_; friend class Isolate; }; @@ -7188,8 +6858,6 @@ struct JitCodeEvent { // New location of instructions. Only valid for CODE_MOVED. void* new_code_start; }; - - Isolate* isolate; }; /** @@ -7311,14 +6979,6 @@ class V8_EXPORT EmbedderHeapTracer { virtual bool AdvanceTracing(double deadline_in_ms, AdvanceTracingActions actions) = 0; - /* - * Returns true if there no more tracing work to be done (see AdvanceTracing) - * and false otherwise. - */ - virtual bool IsTracingDone() { - return NumberOfWrappersToTrace() == 0; - } - /** * Called at the end of a GC cycle. * @@ -7340,39 +7000,15 @@ class V8_EXPORT EmbedderHeapTracer { */ virtual void AbortTracing() = 0; - /* - * Called by the embedder to request immediaet finalization of the currently - * running tracing phase that has been started with TracePrologue and not - * yet finished with TraceEpilogue. - * - * Will be a noop when currently not in tracing. - * - * This is an experimental feature. - */ - void FinalizeTracing(); - - /* - * Returns the v8::Isolate this tracer is attached too and |nullptr| if it - * is not attached to any v8::Isolate. - */ - v8::Isolate* isolate() const { - return isolate_; - } - /** * Returns the number of wrappers that are still to be traced by the embedder. */ - V8_DEPRECATE_SOON("Use IsTracingDone", virtual size_t NumberOfWrappersToTrace() { return 0; - }); + } protected: virtual ~EmbedderHeapTracer() = default; - - v8::Isolate* isolate_ = nullptr; - - friend class internal::LocalEmbedderHeapTracer; }; /** @@ -7431,8 +7067,7 @@ class V8_EXPORT Isolate { add_histogram_sample_callback(nullptr), array_buffer_allocator(nullptr), external_references(nullptr), - allow_atomics_wait(true), - only_terminate_in_safe_scope(false) {} + allow_atomics_wait(true) {} /** * The optional entry_hook allows the host application to provide the @@ -7495,11 +7130,6 @@ class V8_EXPORT Isolate { * this isolate. This can also be configured via SetAllowAtomicsWait. */ bool allow_atomics_wait; - - /** - * Termination is postponed when there is no active SafeForTerminationScope. - */ - bool only_terminate_in_safe_scope; }; @@ -7586,24 +7216,6 @@ class V8_EXPORT Isolate { internal::Isolate* const isolate_; }; - /** - * This scope allows terminations inside direct V8 API calls and forbid them - * inside any recursice API calls without explicit SafeForTerminationScope. - */ - class V8_EXPORT SafeForTerminationScope { - public: - explicit SafeForTerminationScope(v8::Isolate* isolate); - ~SafeForTerminationScope(); - - // Prevent copying of Scope objects. - SafeForTerminationScope(const SafeForTerminationScope&) = delete; - SafeForTerminationScope& operator=(const SafeForTerminationScope&) = delete; - - private: - internal::Isolate* isolate_; - bool prev_value_; - }; - /** * Types of garbage collections that can be requested via * RequestGarbageCollectionForTesting. @@ -7667,8 +7279,6 @@ class V8_EXPORT Isolate { kErrorStackTraceLimit = 45, kWebAssemblyInstantiation = 46, kDeoptimizerDisableSpeculation = 47, - kArrayPrototypeSortJSArrayModifiedPrototype = 48, - kFunctionTokenOffsetTooLongForToString = 49, // If you add new values here, you'll also need to update Chromium's: // web_feature.mojom, UseCounterCallback.cpp, and enums.xml. V8 changes to @@ -7689,26 +7299,6 @@ class V8_EXPORT Isolate { typedef void (*UseCounterCallback)(Isolate* isolate, UseCounterFeature feature); - /** - * Allocates a new isolate but does not initialize it. Does not change the - * currently entered isolate. - * - * Only Isolate::GetData() and Isolate::SetData(), which access the - * embedder-controlled parts of the isolate, are allowed to be called on the - * uninitialized isolate. To initialize the isolate, call - * Isolate::Initialize(). - * - * When an isolate is no longer used its resources should be freed - * by calling Dispose(). Using the delete operator is not allowed. - * - * V8::Initialize() must have run prior to this. - */ - static Isolate* Allocate(); - - /** - * Initialize an Isolate previously allocated by Isolate::Allocate(). - */ - static void Initialize(Isolate* isolate, const CreateParams& params); /** * Creates a new isolate. Does not change the currently entered @@ -7924,7 +7514,15 @@ class V8_EXPORT Isolate { HeapProfiler* GetHeapProfiler(); /** - * Tells the VM whether the embedder is idle or not. + * Returns CPU profiler for this isolate. Will return NULL unless the isolate + * is initialized. It is the embedder's responsibility to stop all CPU + * profiling activities if it has started any. + */ + V8_DEPRECATED("CpuProfiler should be created with CpuProfiler::New call.", + CpuProfiler* GetCpuProfiler()); + + /** + * Tells the CPU profiler whether the embedder is idle. */ void SetIdle(bool is_idle); @@ -8003,85 +7601,6 @@ class V8_EXPORT Isolate { */ void SetEmbedderHeapTracer(EmbedderHeapTracer* tracer); - /** - * Use for |AtomicsWaitCallback| to indicate the type of event it receives. - */ - enum class AtomicsWaitEvent { - /** Indicates that this call is happening before waiting. */ - kStartWait, - /** `Atomics.wait()` finished because of an `Atomics.wake()` call. */ - kWokenUp, - /** `Atomics.wait()` finished because it timed out. */ - kTimedOut, - /** `Atomics.wait()` was interrupted through |TerminateExecution()|. */ - kTerminatedExecution, - /** `Atomics.wait()` was stopped through |AtomicsWaitWakeHandle|. */ - kAPIStopped, - /** `Atomics.wait()` did not wait, as the initial condition was not met. */ - kNotEqual - }; - - /** - * Passed to |AtomicsWaitCallback| as a means of stopping an ongoing - * `Atomics.wait` call. - */ - class V8_EXPORT AtomicsWaitWakeHandle { - public: - /** - * Stop this `Atomics.wait()` call and call the |AtomicsWaitCallback| - * with |kAPIStopped|. - * - * This function may be called from another thread. The caller has to ensure - * through proper synchronization that it is not called after - * the finishing |AtomicsWaitCallback|. - * - * Note that the ECMAScript specification does not plan for the possibility - * of wakeups that are neither coming from a timeout or an `Atomics.wake()` - * call, so this may invalidate assumptions made by existing code. - * The embedder may accordingly wish to schedule an exception in the - * finishing |AtomicsWaitCallback|. - */ - void Wake(); - }; - - /** - * Embedder callback for `Atomics.wait()` that can be added through - * |SetAtomicsWaitCallback|. - * - * This will be called just before starting to wait with the |event| value - * |kStartWait| and after finishing waiting with one of the other - * values of |AtomicsWaitEvent| inside of an `Atomics.wait()` call. - * - * |array_buffer| will refer to the underlying SharedArrayBuffer, - * |offset_in_bytes| to the location of the waited-on memory address inside - * the SharedArrayBuffer. - * - * |value| and |timeout_in_ms| will be the values passed to - * the `Atomics.wait()` call. If no timeout was used, |timeout_in_ms| - * will be `INFINITY`. - * - * In the |kStartWait| callback, |stop_handle| will be an object that - * is only valid until the corresponding finishing callback and that - * can be used to stop the wait process while it is happening. - * - * This callback may schedule exceptions, *unless* |event| is equal to - * |kTerminatedExecution|. - */ - typedef void (*AtomicsWaitCallback)(AtomicsWaitEvent event, - Local array_buffer, - size_t offset_in_bytes, int32_t value, - double timeout_in_ms, - AtomicsWaitWakeHandle* stop_handle, - void* data); - - /** - * Set a new |AtomicsWaitCallback|. This overrides an earlier - * |AtomicsWaitCallback|, if there was any. If |callback| is nullptr, - * this unsets the callback. |data| will be passed to the callback - * as its last parameter. - */ - void SetAtomicsWaitCallback(AtomicsWaitCallback callback, void* data); - /** * Enables the host application to receive a notification after a * garbage collection. Allocations are allowed in the callback function, @@ -8335,18 +7854,6 @@ class V8_EXPORT Isolate { */ void IsolateInBackgroundNotification(); - /** - * Optional notification which will enable the memory savings mode. - * V8 uses this notification to guide heuristics which may result in a - * smaller memory footprint at the cost of reduced runtime performance. - */ - void EnableMemorySavingsMode(); - - /** - * Optional notification which will disable the memory savings mode. - */ - void DisableMemorySavingsMode(); - /** * Optional notification to tell V8 the current performance requirements * of the embedder based on RAIL. @@ -8470,8 +7977,6 @@ class V8_EXPORT Isolate { void SetWasmCompileStreamingCallback(ApiImplementationCallback callback); - void SetWasmStreamingCallback(WasmStreamingCallback callback); - /** * Check if V8 is dead and therefore unusable. This is the case after * fatal errors such as out-of-memory situations. @@ -8642,9 +8147,7 @@ class V8_EXPORT V8 { * Returns { NULL, 0 } on failure. * The caller acquires ownership of the data array in the return value. */ - V8_DEPRECATED("Use SnapshotCreator", - static StartupData CreateSnapshotDataBlob( - const char* embedded_source = NULL)); + static StartupData CreateSnapshotDataBlob(const char* embedded_source = NULL); /** * Bootstrap an isolate and a context from the cold startup blob, run the @@ -8654,9 +8157,8 @@ class V8_EXPORT V8 { * The caller acquires ownership of the data array in the return value. * The argument startup blob is untouched. */ - V8_DEPRECATED("Use SnapshotCreator", - static StartupData WarmUpSnapshotDataBlob( - StartupData cold_startup_blob, const char* warmup_source)); + static StartupData WarmUpSnapshotDataBlob(StartupData cold_startup_blob, + const char* warmup_source); /** Set the callback to invoke in case of Dcheck failures. */ static void SetDcheckErrorHandler(DcheckErrorCallback that); @@ -8851,18 +8353,6 @@ class V8_EXPORT SnapshotCreator { public: enum class FunctionCodeHandling { kClear, kKeep }; - /** - * Initialize and enter an isolate, and set it up for serialization. - * The isolate is either created from scratch or from an existing snapshot. - * The caller keeps ownership of the argument snapshot. - * \param existing_blob existing snapshot from which to create this one. - * \param external_references a null-terminated array of external references - * that must be equivalent to CreateParams::external_references. - */ - SnapshotCreator(Isolate* isolate, - const intptr_t* external_references = nullptr, - StartupData* existing_blob = nullptr); - /** * Create and enter an isolate, and set it up for serialization. * The isolate is either created from scratch or from an existing snapshot. @@ -9651,6 +9141,97 @@ class V8_EXPORT Locker { namespace internal { +const int kApiPointerSize = sizeof(void*); // NOLINT +const int kApiIntSize = sizeof(int); // NOLINT +const int kApiInt64Size = sizeof(int64_t); // NOLINT + +// Tag information for HeapObject. +const int kHeapObjectTag = 1; +const int kWeakHeapObjectTag = 3; +const int kHeapObjectTagSize = 2; +const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; + +// Tag information for Smi. +const int kSmiTag = 0; +const int kSmiTagSize = 1; +const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; + +template struct SmiTagging; + +template +V8_INLINE internal::Object* IntToSmi(int value) { + int smi_shift_bits = kSmiTagSize + kSmiShiftSize; + uintptr_t tagged_value = + (static_cast(value) << smi_shift_bits) | kSmiTag; + return reinterpret_cast(tagged_value); +} + +// Smi constants for 32-bit systems. +template <> struct SmiTagging<4> { + enum { kSmiShiftSize = 0, kSmiValueSize = 31 }; + static int SmiShiftSize() { + return kSmiShiftSize; + } + static int SmiValueSize() { + return kSmiValueSize; + } + V8_INLINE static int SmiToInt(const internal::Object* value) { + int shift_bits = kSmiTagSize + kSmiShiftSize; + // Throw away top 32 bits and shift down (requires >> to be sign extending). + return static_cast(reinterpret_cast(value)) >> shift_bits; + } + V8_INLINE static internal::Object* IntToSmi(int value) { + return internal::IntToSmi(value); + } + V8_INLINE static bool IsValidSmi(intptr_t value) { + // To be representable as an tagged small integer, the two + // most-significant bits of 'value' must be either 00 or 11 due to + // sign-extension. To check this we add 01 to the two + // most-significant bits, and check if the most-significant bit is 0 + // + // CAUTION: The original code below: + // bool result = ((value + 0x40000000) & 0x80000000) == 0; + // may lead to incorrect results according to the C language spec, and + // in fact doesn't work correctly with gcc4.1.1 in some cases: The + // compiler may produce undefined results in case of signed integer + // overflow. The computation must be done w/ unsigned ints. + return static_cast(value + 0x40000000U) < 0x80000000U; + } +}; + +// Smi constants for 64-bit systems. +template <> struct SmiTagging<8> { + enum { kSmiShiftSize = 31, kSmiValueSize = 32 }; + static int SmiShiftSize() { + return kSmiShiftSize; + } + static int SmiValueSize() { + return kSmiValueSize; + } + V8_INLINE static int SmiToInt(const internal::Object* value) { + int shift_bits = kSmiTagSize + kSmiShiftSize; + // Shift down and throw away top 32 bits. + return static_cast(reinterpret_cast(value) >> shift_bits); + } + V8_INLINE static internal::Object* IntToSmi(int value) { + return internal::IntToSmi(value); + } + V8_INLINE static bool IsValidSmi(intptr_t value) { + // To be representable as a long smi, the value must be a 32-bit integer. + return (value == static_cast(value)); + } +}; + +typedef SmiTagging PlatformSmiTagging; +const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; +const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; +V8_INLINE static bool SmiValuesAre31Bits() { + return kSmiValueSize == 31; +} +V8_INLINE static bool SmiValuesAre32Bits() { + return kSmiValueSize == 32; +} + /** * This class exports constants and functionality from within v8 that * is necessary to implement inline functions in the v8 api. Don't @@ -9664,7 +9245,7 @@ class Internals { static const int kMapInstanceTypeOffset = 1 * kApiPointerSize + kApiIntSize; static const int kStringResourceOffset = 3 * kApiPointerSize; - static const int kOddballKindOffset = 4 * kApiPointerSize + kApiDoubleSize; + static const int kOddballKindOffset = 4 * kApiPointerSize + sizeof(double); static const int kForeignAddressOffset = kApiPointerSize; static const int kJSObjectHeaderSize = 3 * kApiPointerSize; static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; @@ -10387,6 +9968,7 @@ AccessorSignature* AccessorSignature::Cast(Data* data) { Local Object::GetInternalField(int index) { #ifndef V8_ENABLE_CHECKS typedef internal::Object O; + typedef internal::HeapObject HO; typedef internal::Internals I; O* obj = *reinterpret_cast(this); // Fast path: If the object is a plain JSObject, which is the common case, we @@ -10397,8 +9979,7 @@ Local Object::GetInternalField(int index) { instance_type == I::kJSSpecialApiObjectType) { int offset = I::kJSObjectHeaderSize + (internal::kApiPointerSize * index); O* value = I::ReadField(obj, offset); - O** result = HandleScope::CreateHandle( - reinterpret_cast(obj), value); + O** result = HandleScope::CreateHandle(reinterpret_cast(obj), value); return Local(reinterpret_cast(result)); } #endif @@ -11054,8 +10635,9 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( Local Context::GetEmbedderData(int index) { #ifndef V8_ENABLE_CHECKS typedef internal::Object O; + typedef internal::HeapObject HO; typedef internal::Internals I; - auto* context = *reinterpret_cast(this); + HO* context = *reinterpret_cast(this); O** result = HandleScope::CreateHandle(context, I::ReadEmbedderData(this, index)); return Local(reinterpret_cast(result)); diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/allocation.h b/test-app/runtime/src/main/cpp/v8_inspector/src/allocation.h index 83eb9919d..b210f43cc 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/allocation.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/allocation.h @@ -79,10 +79,10 @@ char* StrNDup(const char* str, int n); // and free. Used as the default policy for lists. class FreeStoreAllocationPolicy { public: - V8_INLINE void* New(size_t size) { + INLINE(void* New(size_t size)) { return Malloced::New(size); } - V8_INLINE static void Delete(void* p) { + INLINE(static void Delete(void* p)) { Malloced::Delete(p); } }; @@ -138,10 +138,6 @@ V8_WARN_UNUSED_RESULT bool ReleasePages(void* address, size_t size, V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT bool SetPermissions(void* address, size_t size, PageAllocator::Permission access); -inline bool SetPermissions(Address address, size_t size, - PageAllocator::Permission access) { - return SetPermissions(reinterpret_cast(address), size, access); -} // Convenience function that allocates a single system page with read and write // permissions. |address| is a hint. Returns the base address of the memory and @@ -167,8 +163,7 @@ class V8_EXPORT_PRIVATE VirtualMemory { // Construct a virtual memory by assigning it some already mapped address // and size. - VirtualMemory(Address address, size_t size) - : address_(address), size_(size) {} + VirtualMemory(void* address, size_t size) : address_(address), size_(size) {} // Releases the reserved memory, if any, controlled by this VirtualMemory // object. @@ -176,7 +171,7 @@ class V8_EXPORT_PRIVATE VirtualMemory { // Returns whether the memory has been reserved. bool IsReserved() const { - return address_ != kNullAddress; + return address_ != nullptr; } // Initialize or resets an embedded VirtualMemory object. @@ -186,14 +181,15 @@ class V8_EXPORT_PRIVATE VirtualMemory { // If the memory was reserved with an alignment, this address is not // necessarily aligned. The user might need to round it up to a multiple of // the alignment to get the start of the aligned block. - Address address() const { + void* address() const { DCHECK(IsReserved()); return address_; } - Address end() const { + void* end() const { DCHECK(IsReserved()); - return address_ + size_; + return reinterpret_cast(reinterpret_cast(address_) + + size_); } // Returns the size of the reserved memory. The returned value is only @@ -206,11 +202,11 @@ class V8_EXPORT_PRIVATE VirtualMemory { // Sets permissions according to the access argument. address and size must be // multiples of CommitPageSize(). Returns true on success, otherwise false. - bool SetPermissions(Address address, size_t size, + bool SetPermissions(void* address, size_t size, PageAllocator::Permission access); // Releases memory after |free_start|. Returns the number of bytes released. - size_t Release(Address free_start); + size_t Release(void* free_start); // Frees all memory. void Free(); @@ -219,12 +215,15 @@ class V8_EXPORT_PRIVATE VirtualMemory { // The old object is no longer functional (IsReserved() returns false). void TakeControl(VirtualMemory* from); - bool InVM(Address address, size_t size) { - return (address_ <= address) && ((address_ + size_) >= (address + size)); + bool InVM(void* address, size_t size) { + return (reinterpret_cast(address_) <= + reinterpret_cast(address)) && + ((reinterpret_cast(address_) + size_) >= + (reinterpret_cast(address) + size)); } private: - Address address_; // Start address of the virtual memory. + void* address_; // Start address of the virtual memory. size_t size_; // Size of the virtual memory. }; diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/base/atomic-utils.h b/test-app/runtime/src/main/cpp/v8_inspector/src/base/atomic-utils.h index ce1ba3c38..80d4db083 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/base/atomic-utils.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/base/atomic-utils.h @@ -14,7 +14,50 @@ namespace v8 { namespace base { -// Deprecated. Use std::atomic for new code. +template +class AtomicNumber { + public: + AtomicNumber() : value_(0) {} + explicit AtomicNumber(T initial) : value_(initial) {} + + // Returns the value after incrementing. + V8_INLINE T Increment(T increment) { + return static_cast(base::Barrier_AtomicIncrement( + &value_, static_cast(increment))); + } + + // Returns the value after decrementing. + V8_INLINE T Decrement(T decrement) { + return static_cast(base::Barrier_AtomicIncrement( + &value_, -static_cast(decrement))); + } + + V8_INLINE T Value() const { + return static_cast(base::Acquire_Load(&value_)); + } + + V8_INLINE void SetValue(T new_value) { + base::Release_Store(&value_, static_cast(new_value)); + } + + V8_INLINE T operator=(T value) { + SetValue(value); + return value; + } + + V8_INLINE T operator+=(T value) { + return Increment(value); + } + V8_INLINE T operator-=(T value) { + return Decrement(value); + } + + private: + STATIC_ASSERT(sizeof(T) <= sizeof(base::AtomicWord)); + + base::AtomicWord value_; +}; + // Flag using T atomically. Also accepts void* as T. template class AtomicValue { diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/base/flags.h b/test-app/runtime/src/main/cpp/v8_inspector/src/base/flags.h index b8c3c3407..0a1778f91 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/base/flags.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/base/flags.h @@ -27,15 +27,15 @@ class Flags final { typedef T flag_type; typedef S mask_type; - constexpr Flags() : mask_(0) {} - constexpr Flags(flag_type flag) // NOLINT(runtime/explicit) + Flags() : mask_(0) {} + Flags(flag_type flag) // NOLINT(runtime/explicit) : mask_(static_cast(flag)) {} - constexpr explicit Flags(mask_type mask) : mask_(static_cast(mask)) {} + explicit Flags(mask_type mask) : mask_(static_cast(mask)) {} - constexpr bool operator==(flag_type flag) const { + bool operator==(flag_type flag) const { return mask_ == static_cast(flag); } - constexpr bool operator!=(flag_type flag) const { + bool operator!=(flag_type flag) const { return mask_ != static_cast(flag); } @@ -52,13 +52,13 @@ class Flags final { return *this; } - constexpr Flags operator&(const Flags& flags) const { + Flags operator&(const Flags& flags) const { return Flags(*this) &= flags; } - constexpr Flags operator|(const Flags& flags) const { + Flags operator|(const Flags& flags) const { return Flags(*this) |= flags; } - constexpr Flags operator^(const Flags& flags) const { + Flags operator^(const Flags& flags) const { return Flags(*this) ^= flags; } @@ -72,24 +72,24 @@ class Flags final { return operator^=(Flags(flag)); } - constexpr Flags operator&(flag_type flag) const { + Flags operator&(flag_type flag) const { return operator&(Flags(flag)); } - constexpr Flags operator|(flag_type flag) const { + Flags operator|(flag_type flag) const { return operator|(Flags(flag)); } - constexpr Flags operator^(flag_type flag) const { + Flags operator^(flag_type flag) const { return operator^(Flags(flag)); } - constexpr Flags operator~() const { + Flags operator~() const { return Flags(~mask_); } - constexpr operator mask_type() const { + operator mask_type() const { return mask_; } - constexpr bool operator!() const { + bool operator!() const { return !mask_; } diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/base/macros.h b/test-app/runtime/src/main/cpp/v8_inspector/src/base/macros.h index a2bb5f851..ff0e6aa7e 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/base/macros.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/base/macros.h @@ -43,6 +43,7 @@ template char (&ArraySizeHelper(const T (&array)[N]))[N]; #endif + // bit_cast is a template function that implements the // equivalent of "*reinterpret_cast(&source)". We need this in // very low-level functions like the protobuf library and fast math @@ -145,27 +146,24 @@ V8_INLINE Dest bit_cast(Source const& source) { void operator delete(void*, size_t) { base::OS::Abort(); } \ void operator delete[](void*, size_t) { base::OS::Abort(); } -// Define V8_USE_ADDRESS_SANITIZER macro. +// Newly written code should use V8_INLINE and V8_NOINLINE directly. +#define INLINE(declarator) V8_INLINE declarator +#define NO_INLINE(declarator) V8_NOINLINE declarator + +// Define V8_USE_ADDRESS_SANITIZER macros. #if defined(__has_feature) #if __has_feature(address_sanitizer) #define V8_USE_ADDRESS_SANITIZER 1 #endif #endif -// Define DISABLE_ASAN macro. +// Define DISABLE_ASAN macros. #ifdef V8_USE_ADDRESS_SANITIZER #define DISABLE_ASAN __attribute__((no_sanitize_address)) #else #define DISABLE_ASAN #endif -// Define V8_USE_MEMORY_SANITIZER macro. -#if defined(__has_feature) -#if __has_feature(memory_sanitizer) -#define V8_USE_MEMORY_SANITIZER 1 -#endif -#endif - // Helper macro to define no_sanitize attributes only with clang. #if defined(__clang__) && defined(__has_attribute) #if __has_attribute(no_sanitize) @@ -273,14 +271,6 @@ struct Use { } // namespace base } // namespace v8 -// implicit_cast(x) triggers an implicit cast from {x} to type {A}. This is -// useful in situations where static_cast(x) would do too much. -// Only use this for cheap-to-copy types, or use move semantics explicitly. -template -V8_INLINE A implicit_cast(A x) { - return x; -} - // Define our own macros for writing 64-bit constants. This is less fragile // than defining __STDC_CONSTANT_MACROS before including , and it // works on compilers that don't have it (like MSVC). @@ -306,14 +296,6 @@ V8_INLINE A implicit_cast(A x) { #define V8PRIdPTR V8_PTR_PREFIX "d" #define V8PRIuPTR V8_PTR_PREFIX "u" -#ifdef V8_TARGET_ARCH_64_BIT -#define V8_PTR_HEX_DIGITS 12 -#define V8PRIxPTR_FMT "0x%012" V8PRIxPTR -#else -#define V8_PTR_HEX_DIGITS 8 -#define V8PRIxPTR_FMT "0x%08" V8PRIxPTR -#endif - // ptrdiff_t is 't' according to the standard, but MSVC uses 'I'. #if V8_CC_MSVC #define V8PRIxPTRDIFF "Ix" diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/base/platform/mutex.h b/test-app/runtime/src/main/cpp/v8_inspector/src/base/platform/mutex.h index 2b63f9abc..d82959393 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/base/platform/mutex.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/base/platform/mutex.h @@ -203,22 +203,14 @@ typedef LazyStaticInstance +template class LockGuard final { public: explicit LockGuard(Mutex* mutex) : mutex_(mutex) { - if (Behavior == NullBehavior::kRequireNotNull || mutex_ != nullptr) { - mutex_->Lock(); - } + mutex_->Lock(); } ~LockGuard() { - if (mutex_ != nullptr) { - mutex_->Unlock(); - } + mutex_->Unlock(); } private: diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/base/platform/platform.h b/test-app/runtime/src/main/cpp/v8_inspector/src/base/platform/platform.h index e4b7eeb7e..358e9082b 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/base/platform/platform.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/base/platform/platform.h @@ -48,7 +48,7 @@ namespace base { #define V8_FAST_TLS_SUPPORTED 1 -V8_INLINE intptr_t InternalGetExistingThreadLocal(intptr_t index); +INLINE(intptr_t InternalGetExistingThreadLocal(intptr_t index)); inline intptr_t InternalGetExistingThreadLocal(intptr_t index) { const intptr_t kTibInlineTlsOffset = 0xE10; @@ -74,7 +74,7 @@ inline intptr_t InternalGetExistingThreadLocal(intptr_t index) { extern V8_BASE_EXPORT intptr_t kMacTlsBaseOffset; -V8_INLINE intptr_t InternalGetExistingThreadLocal(intptr_t index); +INLINE(intptr_t InternalGetExistingThreadLocal(intptr_t index)); inline intptr_t InternalGetExistingThreadLocal(intptr_t index) { intptr_t result; @@ -159,7 +159,6 @@ class V8_BASE_EXPORT OS { // v8::PageAllocator. enum class MemoryPermission { kNoAccess, - kRead, kReadWrite, // TODO(hpayer): Remove this flag. Memory should never be rwx. kReadWriteExecute, diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/base/template-utils.h b/test-app/runtime/src/main/cpp/v8_inspector/src/base/template-utils.h index 7e0c29149..463d341af 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/base/template-utils.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/base/template-utils.h @@ -56,6 +56,13 @@ std::unique_ptr make_unique(Args&& ... args) { return std::unique_ptr(new T(std::forward(args)...)); } +// implicit_cast(x) triggers an implicit cast from {x} to type {A}. This is +// useful in situations where static_cast(x) would do too much. +template +A implicit_cast(A x) { + return x; +} + // Helper to determine how to pass values: Pass scalars and arrays by value, // others by const reference (even if it was a non-const ref before; this is // disallowed by the style guide anyway). diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/checks.h b/test-app/runtime/src/main/cpp/v8_inspector/src/checks.h index 8eb10f43d..0d7eed348 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/checks.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/checks.h @@ -27,8 +27,9 @@ static const bool FLAG_enable_slow_asserts = false; } // namespace internal } // namespace v8 -#define DCHECK_TAG_ALIGNED(address) \ - DCHECK((address & ::v8::internal::kHeapObjectTagMask) == 0) +#define DCHECK_TAG_ALIGNED(address) \ + DCHECK((reinterpret_cast(address) & \ + ::v8::internal::kHeapObjectTagMask) == 0) #define DCHECK_SIZE_TAG_ALIGNED(size) \ DCHECK((size & ::v8::internal::kHeapObjectTagMask) == 0) diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/conversions.h b/test-app/runtime/src/main/cpp/v8_inspector/src/conversions.h index 9a8ee578d..5088e5b5c 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/conversions.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/conversions.h @@ -36,13 +36,12 @@ inline int FastD2IChecked(double x) { return static_cast(x); } + // The fast double-to-(unsigned-)int conversion routine does not guarantee // rounding towards zero. -// The result is undefined if x is infinite or NaN, or if the rounded +// The result is unspecified if x is infinite or NaN, or if the rounded // integer value is outside the range of type int. inline int FastD2I(double x) { - DCHECK(x <= INT_MAX); - DCHECK(x >= INT_MIN); return static_cast(x); } @@ -174,9 +173,8 @@ inline uint32_t NumberToUint32(Object* number); inline int64_t NumberToInt64(Object* number); inline uint64_t PositiveNumberToUint64(Object* number); -double StringToDouble(Isolate* isolate, UnicodeCache* unicode_cache, - Handle string, int flags, - double empty_string_val = 0.0); +double StringToDouble(UnicodeCache* unicode_cache, Handle string, + int flags, double empty_string_val = 0.0); inline bool TryNumberToSize(Object* number, size_t* result); diff --git a/test-app/runtime/src/main/cpp/v8_inspector/src/debug/debug-interface.h b/test-app/runtime/src/main/cpp/v8_inspector/src/debug/debug-interface.h index 71713bf75..717d5737c 100644 --- a/test-app/runtime/src/main/cpp/v8_inspector/src/debug/debug-interface.h +++ b/test-app/runtime/src/main/cpp/v8_inspector/src/debug/debug-interface.h @@ -21,7 +21,6 @@ struct CoverageScript; struct TypeProfileEntry; struct TypeProfileScript; class Coverage; -class PostponeInterruptsScope; class Script; class TypeProfile; } // namespace internal @@ -34,13 +33,51 @@ int GetContextId(Local context); void SetInspector(Isolate* isolate, v8_inspector::V8Inspector*); v8_inspector::V8Inspector* GetInspector(Isolate* isolate); -// Schedule a debugger break to happen when function is called inside given -// isolate. -void SetBreakOnNextFunctionCall(Isolate* isolate); +/** + * Debugger is running in its own context which is entered while debugger + * messages are being dispatched. This is an explicit getter for this + * debugger context. Note that the content of the debugger context is subject + * to change. The Context exists only when the debugger is active, i.e. at + * least one DebugEventListener or MessageHandler is set. + */ +Local GetDebugContext(Isolate* isolate); + +/** + * Run a JavaScript function in the debugger. + * \param fun the function to call + * \param data passed as second argument to the function + * With this call the debugger is entered and the function specified is called + * with the execution state as the first argument. This makes it possible to + * get access to information otherwise not available during normal JavaScript + * execution e.g. details on stack frames. Receiver of the function call will + * be the debugger context global object, however this is a subject to change. + * The following example shows a JavaScript function which when passed to + * v8::Debug::Call will return the current line of JavaScript execution. + * + * \code + * function frame_source_line(exec_state) { + * return exec_state.frame(0).sourceLine(); + * } + * \endcode + */ +// TODO(dcarney): data arg should be a MaybeLocal +MaybeLocal Call(Local context, v8::Local fun, + Local data = Local()); + +/** + * Enable/disable LiveEdit functionality for the given Isolate + * (default Isolate if not provided). V8 will abort if LiveEdit is + * unexpectedly used. LiveEdit is enabled by default. + */ +V8_EXPORT_PRIVATE void SetLiveEditEnabled(Isolate* isolate, bool enable); + +// Schedule a debugger break to happen when JavaScript code is run +// in the given isolate. +void DebugBreak(Isolate* isolate); // Remove scheduled debugger break in given isolate if it has not // happened yet. -void ClearBreakOnNextFunctionCall(Isolate* isolate); +void CancelDebugBreak(Isolate* isolate); /** * Returns array of internal properties specific to the value type. Result has @@ -79,28 +116,18 @@ void BreakRightNow(Isolate* isolate); bool AllFramesOnStackAreBlackboxed(Isolate* isolate); -class Script; +/** + * Out-of-memory callback function. + * The function is invoked when the heap size is close to the hard limit. + * + * \param data the parameter provided during callback installation. + */ +typedef void (*OutOfMemoryCallback)(void* data); -struct LiveEditResult { - enum Status { - OK, - COMPILE_ERROR, - BLOCKED_BY_RUNNING_GENERATOR, - BLOCKED_BY_FUNCTION_ABOVE_BREAK_FRAME, - BLOCKED_BY_FUNCTION_BELOW_NON_DROPPABLE_FRAME, - BLOCKED_BY_ACTIVE_FUNCTION, - BLOCKED_BY_NEW_TARGET_IN_RESTART_FRAME, - FRAME_RESTART_IS_NOT_SUPPORTED - }; - Status status = OK; - bool stack_changed = false; - // Available only for OK. - v8::Local script; - // Fields below are available only for COMPILE_ERROR. - v8::Local message; - int line_number = -1; - int column_number = -1; -}; +V8_DEPRECATED("Use v8::Isolate::AddNearHeapLimitCallback", + void SetOutOfMemoryCallback(Isolate* isolate, + OutOfMemoryCallback callback, + void* data)); /** * Native wrapper around v8::internal::Script object. @@ -130,7 +157,7 @@ class V8_EXPORT_PRIVATE Script { int GetSourceOffset(const debug::Location& location) const; v8::debug::Location GetSourceLocation(int offset) const; bool SetScriptSource(v8::Local newSource, bool preview, - LiveEditResult* result) const; + bool* stack_changed) const; bool SetBreakpoint(v8::Local condition, debug::Location* location, BreakpointId* id) const; }; @@ -157,14 +184,17 @@ MaybeLocal CompileInspectorScript(Isolate* isolate, class DebugDelegate { public: virtual ~DebugDelegate() {} + virtual void PromiseEventOccurred(debug::PromiseDebugActionType type, int id, + bool is_blackboxed) {} virtual void ScriptCompiled(v8::Local