From b74963fafb4670404809b48acf924469d98a726e Mon Sep 17 00:00:00 2001 From: drelaptop Date: Tue, 4 Dec 2018 16:51:07 +0800 Subject: [PATCH] update mac v8 --- mac/include/v8/libplatform/libplatform.h | 32 +- mac/include/v8/libplatform/v8-tracing.h | 47 +- mac/include/v8/v8-inspector.h | 26 +- mac/include/v8/v8-platform.h | 325 +++-- mac/include/v8/v8-profiler.h | 17 +- mac/include/v8/v8-util.h | 7 +- mac/include/v8/v8-version-string.h | 13 +- mac/include/v8/v8-version.h | 6 +- mac/include/v8/v8.h | 1369 +++++++++++----------- mac/include/v8/v8config.h | 19 +- mac/libs/libinspector.a | Bin 1725336 -> 1616936 bytes mac/libs/libv8_base.a | Bin 22313592 -> 20711160 bytes mac/libs/libv8_builtins_generators.a | Bin 1774616 -> 0 bytes mac/libs/libv8_builtins_setup.a | Bin 2208 -> 0 bytes mac/libs/libv8_libbase.a | Bin 170816 -> 176144 bytes mac/libs/libv8_libplatform.a | Bin 125472 -> 140680 bytes mac/libs/libv8_libsampler.a | Bin 10632 -> 14648 bytes mac/libs/libv8_nosnapshot.a | Bin 149936 -> 0 bytes mac/libs/libv8_snapshot.a | Bin 0 -> 1415464 bytes 19 files changed, 1077 insertions(+), 784 deletions(-) delete mode 100644 mac/libs/libv8_builtins_generators.a delete mode 100644 mac/libs/libv8_builtins_setup.a delete mode 100644 mac/libs/libv8_nosnapshot.a create mode 100644 mac/libs/libv8_snapshot.a diff --git a/mac/include/v8/libplatform/libplatform.h b/mac/include/v8/libplatform/libplatform.h index e9450456..04b47b8d 100644 --- a/mac/include/v8/libplatform/libplatform.h +++ b/mac/include/v8/libplatform/libplatform.h @@ -8,6 +8,7 @@ #include "libplatform/libplatform-export.h" #include "libplatform/v8-tracing.h" #include "v8-platform.h" // NOLINT(build/include) +#include "v8config.h" // NOLINT(build/include) namespace v8 { namespace platform { @@ -30,12 +31,24 @@ enum class MessageLoopBehavior : bool { * If |idle_task_support| is enabled then the platform will accept idle * tasks (IdleTasksEnabled will return true) and will rely on the embedder * calling v8::platform::RunIdleTasks to process the idle tasks. + * If |tracing_controller| is nullptr, the default platform will create a + * v8::platform::TracingController instance and use it. */ -V8_PLATFORM_EXPORT v8::Platform* CreateDefaultPlatform( +V8_PLATFORM_EXPORT std::unique_ptr NewDefaultPlatform( int thread_pool_size = 0, IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled, InProcessStackDumping in_process_stack_dumping = - InProcessStackDumping::kEnabled); + InProcessStackDumping::kEnabled, + std::unique_ptr tracing_controller = {}); + +V8_PLATFORM_EXPORT V8_DEPRECATE_SOON( + "Use NewDefaultPlatform instead", + v8::Platform* CreateDefaultPlatform( + int thread_pool_size = 0, + IdleTaskSupport idle_task_support = IdleTaskSupport::kDisabled, + InProcessStackDumping in_process_stack_dumping = + InProcessStackDumping::kEnabled, + v8::TracingController* tracing_controller = nullptr)); /** * Pumps the message loop for the given isolate. @@ -43,7 +56,7 @@ V8_PLATFORM_EXPORT v8::Platform* CreateDefaultPlatform( * The caller has to make sure that this is called from the right thread. * Returns true if a task was executed, and false otherwise. Unless requested * through the |behavior| parameter, this call does not block if no task is - * pending. The |platform| has to be created using |CreateDefaultPlatform|. + * pending. The |platform| has to be created using |NewDefaultPlatform|. */ V8_PLATFORM_EXPORT bool PumpMessageLoop( v8::Platform* platform, v8::Isolate* isolate, @@ -57,7 +70,7 @@ V8_PLATFORM_EXPORT void EnsureEventLoopInitialized(v8::Platform* platform, * * The caller has to make sure that this is called from the right thread. * This call does not block if no task is pending. The |platform| has to be - * created using |CreateDefaultPlatform|. + * created using |NewDefaultPlatform|. */ V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform, v8::Isolate* isolate, @@ -66,11 +79,14 @@ V8_PLATFORM_EXPORT void RunIdleTasks(v8::Platform* platform, /** * Attempts to set the tracing controller for the given platform. * - * The |platform| has to be created using |CreateDefaultPlatform|. + * The |platform| has to be created using |NewDefaultPlatform|. + * */ -V8_PLATFORM_EXPORT void SetTracingController( - v8::Platform* platform, - v8::platform::tracing::TracingController* tracing_controller); +V8_PLATFORM_EXPORT V8_DEPRECATE_SOON( + "Access the DefaultPlatform directly", + void SetTracingController( + v8::Platform* platform, + v8::platform::tracing::TracingController* tracing_controller)); } // namespace platform } // namespace v8 diff --git a/mac/include/v8/libplatform/v8-tracing.h b/mac/include/v8/libplatform/v8-tracing.h index 902f8ea9..9dcf3d7b 100644 --- a/mac/include/v8/libplatform/v8-tracing.h +++ b/mac/include/v8/libplatform/v8-tracing.h @@ -43,8 +43,8 @@ class V8_PLATFORM_EXPORT TraceObject { const char** arg_names, const uint8_t* arg_types, const uint64_t* arg_values, std::unique_ptr* arg_convertables, - unsigned int flags); - void UpdateDuration(); + 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, @@ -209,7 +209,15 @@ class V8_PLATFORM_EXPORT TraceConfig { void operator=(const TraceConfig&) = delete; }; -class V8_PLATFORM_EXPORT TracingController { +#if defined(_MSC_VER) +#define V8_PLATFORM_NON_EXPORTED_BASE(code) \ + __pragma(warning(suppress : 4275)) code +#else +#define V8_PLATFORM_NON_EXPORTED_BASE(code) code +#endif // defined(_MSC_VER) + +class V8_PLATFORM_EXPORT TracingController + : public V8_PLATFORM_NON_EXPORTED_BASE(v8::TracingController) { public: enum Mode { DISABLED = 0, RECORDING_MODE }; @@ -227,25 +235,40 @@ class V8_PLATFORM_EXPORT TracingController { }; TracingController(); - ~TracingController(); + ~TracingController() override; void Initialize(TraceBuffer* trace_buffer); - const uint8_t* GetCategoryGroupEnabled(const char* category_group); - static const char* GetCategoryGroupName(const uint8_t* category_enabled_flag); + + // 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); + 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); + 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(); - void AddTraceStateObserver(Platform::TraceStateObserver* observer); - void RemoveTraceStateObserver(Platform::TraceStateObserver* observer); + 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); @@ -255,7 +278,7 @@ class V8_PLATFORM_EXPORT TracingController { std::unique_ptr trace_buffer_; std::unique_ptr trace_config_; std::unique_ptr mutex_; - std::unordered_set observers_; + std::unordered_set observers_; Mode mode_ = DISABLED; // Disallow copy and assign @@ -263,6 +286,8 @@ class V8_PLATFORM_EXPORT TracingController { void operator=(const TracingController&) = delete; }; +#undef V8_PLATFORM_NON_EXPORTED_BASE + } // namespace tracing } // namespace platform } // namespace v8 diff --git a/mac/include/v8/v8-inspector.h b/mac/include/v8/v8-inspector.h index 43bf3b4f..6de8234f 100644 --- a/mac/include/v8/v8-inspector.h +++ b/mac/include/v8/v8-inspector.h @@ -149,8 +149,9 @@ class V8_EXPORT V8InspectorSession { // Remote objects. virtual std::unique_ptr wrapObject( - v8::Local, v8::Local, - const StringView& groupName) = 0; + v8::Local, v8::Local, const StringView& groupName, + bool generatePreview) = 0; + virtual bool unwrapObject(std::unique_ptr* error, const StringView& objectId, v8::Local*, v8::Local*, @@ -211,6 +212,22 @@ class V8_EXPORT V8InspectorClient { // 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; + + V8StackTraceId(); + V8StackTraceId(uintptr_t id, const std::pair debugger_id); + ~V8StackTraceId() = default; + + bool IsInvalid() const; }; class V8_EXPORT V8Inspector { @@ -235,6 +252,11 @@ class V8_EXPORT V8Inspector { 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, diff --git a/mac/include/v8/v8-platform.h b/mac/include/v8/v8-platform.h index 8f6d8042..2bb14df9 100644 --- a/mac/include/v8/v8-platform.h +++ b/mac/include/v8/v8-platform.h @@ -36,6 +36,51 @@ class IdleTask { virtual void Run(double deadline_in_seconds) = 0; }; +/** + * A TaskRunner allows scheduling of tasks. The TaskRunner may still be used to + * post tasks after the isolate gets destructed, but these tasks may not get + * executed anymore. All tasks posted to a given TaskRunner will be invoked in + * sequence. Tasks can be posted from any thread. + */ +class TaskRunner { + public: + /** + * Schedules a task to be invoked by this TaskRunner. The TaskRunner + * implementation takes ownership of |task|. + */ + virtual void PostTask(std::unique_ptr task) = 0; + + /** + * Schedules a task to be invoked by this TaskRunner. The task is scheduled + * after the given number of seconds |delay_in_seconds|. The TaskRunner + * implementation takes ownership of |task|. + */ + virtual void PostDelayedTask(std::unique_ptr task, + double delay_in_seconds) = 0; + + /** + * Schedules an idle task to be invoked by this TaskRunner. The task is + * scheduled when the embedder is idle. Requires that + * TaskRunner::SupportsIdleTasks(isolate) is true. Idle tasks may be reordered + * relative to other task types and may be starved for an arbitrarily long + * time if no idle time is available. The TaskRunner implementation takes + * ownership of |task|. + */ + virtual void PostIdleTask(std::unique_ptr task) = 0; + + /** + * Returns true if idle tasks are enabled for this TaskRunner. + */ + virtual bool IdleTasksEnabled() = 0; + + TaskRunner() = default; + virtual ~TaskRunner() = default; + + private: + TaskRunner(const TaskRunner&) = delete; + TaskRunner& operator=(const TaskRunner&) = delete; +}; + /** * The interface represents complex arguments to trace events. */ @@ -52,6 +97,143 @@ class ConvertableToTraceFormat { virtual void AppendAsTraceFormat(std::string* out) const = 0; }; +/** + * V8 Tracing controller. + * + * Can be implemented by an embedder to record trace events from V8. + */ +class TracingController { + public: + virtual ~TracingController() = default; + + /** + * Called by TRACE_EVENT* macros, don't call this directly. + * The name parameter is a category group for example: + * TRACE_EVENT0("v8,parse", "V8.Parse") + * The pointer returned points to a value with zero or more of the bits + * defined in CategoryGroupEnabledFlags. + **/ + virtual const uint8_t* GetCategoryGroupEnabled(const char* name) { + static uint8_t no = 0; + return &no; + } + + /** + * Adds a trace event to the platform tracing system. These function calls are + * usually the result of a TRACE_* macro from trace_event_common.h when + * tracing and the category of the particular trace are enabled. It is not + * advisable to call these functions on their own; they are really only meant + * to be used by the trace macros. The returned handle can be used by + * UpdateTraceEventDuration to update the duration of COMPLETE events. + */ + virtual 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) { + return 0; + } + virtual 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) { + return 0; + } + + /** + * Sets the duration field of a COMPLETE trace event. It must be called with + * the handle returned from AddTraceEvent(). + **/ + virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, + const char* name, uint64_t handle) {} + + class TraceStateObserver { + public: + virtual ~TraceStateObserver() = default; + virtual void OnTraceEnabled() = 0; + virtual void OnTraceDisabled() = 0; + }; + + /** Adds tracing state change observer. */ + virtual void AddTraceStateObserver(TraceStateObserver*) {} + + /** Removes tracing state change observer. */ + virtual void RemoveTraceStateObserver(TraceStateObserver*) {} +}; + +/** + * A V8 memory page allocator. + * + * Can be implemented by an embedder to manage large host OS allocations. + */ +class PageAllocator { + public: + virtual ~PageAllocator() = default; + + /** + * Gets the page granularity for AllocatePages and FreePages. Addresses and + * lengths for those calls should be multiples of AllocatePageSize(). + */ + virtual size_t AllocatePageSize() = 0; + + /** + * Gets the page granularity for SetPermissions and ReleasePages. Addresses + * and lengths for those calls should be multiples of CommitPageSize(). + */ + virtual size_t CommitPageSize() = 0; + + /** + * Sets the random seed so that GetRandomMmapAddr() will generate repeatable + * sequences of random mmap addresses. + */ + virtual void SetRandomMmapSeed(int64_t seed) = 0; + + /** + * Returns a randomized address, suitable for memory allocation under ASLR. + * The address will be aligned to AllocatePageSize. + */ + virtual void* GetRandomMmapAddr() = 0; + + /** + * Memory permissions. + */ + enum Permission { + kNoAccess, + kReadWrite, + // TODO(hpayer): Remove this flag. Memory should never be rwx. + kReadWriteExecute, + kReadExecute + }; + + /** + * Allocates memory in range with the given alignment and permission. + */ + virtual void* AllocatePages(void* address, size_t length, size_t alignment, + Permission permissions) = 0; + + /** + * Frees memory in a range that was allocated by a call to AllocatePages. + */ + virtual bool FreePages(void* address, size_t length) = 0; + + /** + * Releases memory in a range that was allocated by a call to AllocatePages. + */ + virtual bool ReleasePages(void* address, size_t length, + size_t new_length) = 0; + + /** + * Sets permissions on pages in an allocated range. + */ + virtual bool SetPermissions(void* address, size_t length, + Permission permissions) = 0; +}; + /** * V8 Platform abstraction layer. * @@ -72,6 +254,37 @@ class Platform { virtual ~Platform() = default; + /** + * Allows the embedder to manage memory page allocations. + */ + virtual PageAllocator* GetPageAllocator() { + // TODO(bbudge) Make this abstract after all embedders implement this. + return nullptr; + } + + /** + * Enables the embedder to respond in cases where V8 can't allocate large + * blocks of memory. V8 retries the failed allocation once after calling this + * method. On success, execution continues; otherwise V8 exits with a fatal + * error. + * Embedder overrides of this function must NOT call back into V8. + */ + virtual void OnCriticalMemoryPressure() { + // TODO(bbudge) Remove this when embedders override the following method. + // See crbug.com/634547. + } + + /** + * Enables the embedder to respond in cases where V8 can't allocate large + * memory regions. The |length| parameter is the amount of memory needed. + * Returns true if memory is now available. Returns false if no memory could + * be made available. V8 will retry allocations until this method returns + * false. + * + * Embedder overrides of this function must NOT call back into V8. + */ + virtual bool OnCriticalMemoryPressure(size_t length) { return false; } + /** * Gets the number of threads that are used to execute background tasks. Is * used to estimate the number of tasks a work package should be split into. @@ -81,6 +294,28 @@ class Platform { */ 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) { + // 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. + */ + virtual std::shared_ptr GetBackgroundTaskRunner( + Isolate* isolate) { + // TODO(ahaas): Make this function abstract after it got implemented on all + // platforms. + return {}; + } + /** * Schedules a task to be invoked on a background thread. |expected_runtime| * indicates that the task will run a long time. The Platform implementation @@ -137,81 +372,10 @@ class Platform { virtual double MonotonicallyIncreasingTime() = 0; /** - * Called by TRACE_EVENT* macros, don't call this directly. - * The name parameter is a category group for example: - * TRACE_EVENT0("v8,parse", "V8.Parse") - * The pointer returned points to a value with zero or more of the bits - * defined in CategoryGroupEnabledFlags. - **/ - virtual const uint8_t* GetCategoryGroupEnabled(const char* name) { - static uint8_t no = 0; - return &no; - } - - /** - * Gets the category group name of the given category_enabled_flag pointer. - * Usually used while serliazing TRACE_EVENTs. - **/ - virtual const char* GetCategoryGroupName( - const uint8_t* category_enabled_flag) { - static const char dummy[] = "dummy"; - return dummy; - } - - /** - * Adds a trace event to the platform tracing system. This function call is - * usually the result of a TRACE_* macro from trace_event_common.h when - * tracing and the category of the particular trace are enabled. It is not - * advisable to call this function on its own; it is really only meant to be - * used by the trace macros. The returned handle can be used by - * UpdateTraceEventDuration to update the duration of COMPLETE events. + * Current wall-clock time in milliseconds since epoch. + * This function is expected to return at least millisecond-precision values. */ - virtual 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, unsigned int flags) { - return 0; - } - - /** - * Adds a trace event to the platform tracing system. This function call is - * usually the result of a TRACE_* macro from trace_event_common.h when - * tracing and the category of the particular trace are enabled. It is not - * advisable to call this function on its own; it is really only meant to be - * used by the trace macros. The returned handle can be used by - * UpdateTraceEventDuration to update the duration of COMPLETE events. - */ - virtual 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) { - return AddTraceEvent(phase, category_enabled_flag, name, scope, id, bind_id, - num_args, arg_names, arg_types, arg_values, flags); - } - - /** - * Sets the duration field of a COMPLETE trace event. It must be called with - * the handle returned from AddTraceEvent(). - **/ - virtual void UpdateTraceEventDuration(const uint8_t* category_enabled_flag, - const char* name, uint64_t handle) {} - - class TraceStateObserver { - public: - virtual ~TraceStateObserver() = default; - virtual void OnTraceEnabled() = 0; - virtual void OnTraceDisabled() = 0; - }; - - /** Adds tracing state change observer. */ - virtual void AddTraceStateObserver(TraceStateObserver*) {} - - /** Removes tracing state change observer. */ - virtual void RemoveTraceStateObserver(TraceStateObserver*) {} + virtual double CurrentClockTimeMillis() = 0; typedef void (*StackTracePrinter)(); @@ -220,6 +384,19 @@ class Platform { * on invocation. Disables printing of the stack trace if nullptr. */ virtual StackTracePrinter GetStackTracePrinter() { return nullptr; } + + /** + * Returns an instance of a v8::TracingController. This must be non-nullptr. + */ + virtual TracingController* GetTracingController() = 0; + + protected: + /** + * Default implementation of current wall-clock time in milliseconds + * since epoch. Useful for implementing |CurrentClockTimeMillis| if + * nothing special needed. + */ + static double SystemClockTimeMillis(); }; } // namespace v8 diff --git a/mac/include/v8/v8-profiler.h b/mac/include/v8/v8-profiler.h index b60d137f..a86402be 100644 --- a/mac/include/v8/v8-profiler.h +++ b/mac/include/v8/v8-profiler.h @@ -286,6 +286,13 @@ class V8_EXPORT CpuProfiler { */ static CpuProfiler* New(Isolate* isolate); + /** + * Synchronously collect current stack sample in all profilers attached to + * the |isolate|. The call does not affect number of ticks recorded for + * the current top node. + */ + static void CollectSample(Isolate* isolate); + /** * Disposes the CPU profiler object. */ @@ -322,7 +329,8 @@ class V8_EXPORT CpuProfiler { * Recording the forced sample does not contribute to the aggregated * profile statistics. */ - void CollectSample(); + V8_DEPRECATED("Use static CollectSample(Isolate*) instead.", + void CollectSample()); /** * Tells the profiler whether the embedder is idle. @@ -389,7 +397,7 @@ class V8_EXPORT HeapGraphNode { kRegExp = 6, // RegExp. kHeapNumber = 7, // Number stored in the heap. kNative = 8, // Native object (not from V8 heap). - kSynthetic = 9, // Synthetic object, usualy used for grouping + kSynthetic = 9, // Synthetic object, usually used for grouping // snapshot items together. kConsString = 10, // Concatenated string. A pair of pointers to strings. kSlicedString = 11, // Sliced string. A fragment of another string. @@ -784,7 +792,7 @@ class V8_EXPORT HeapProfiler { /** * Returns the sampled profile of allocations allocated (and still live) since * StartSamplingHeapProfiler was called. The ownership of the pointer is - * transfered to the caller. Returns nullptr if sampling heap profiler is not + * transferred to the caller. Returns nullptr if sampling heap profiler is not * active. */ AllocationProfile* GetAllocationProfile(); @@ -809,9 +817,6 @@ class V8_EXPORT HeapProfiler { */ static const uint16_t kPersistentHandleNoClassId = 0; - /** Returns memory used for profiler internal data and snapshots. */ - size_t GetProfilerMemorySize(); - private: HeapProfiler(); ~HeapProfiler(); diff --git a/mac/include/v8/v8-util.h b/mac/include/v8/v8-util.h index a04a5e84..15ea225d 100644 --- a/mac/include/v8/v8-util.h +++ b/mac/include/v8/v8-util.h @@ -393,9 +393,14 @@ class PersistentValueMap : public PersistentValueMapBase { */ Global SetUnique(const K& key, Global* persistent) { if (Traits::kCallbackType != kNotWeak) { + WeakCallbackType callback_type = + Traits::kCallbackType == kWeakWithInternalFields + ? WeakCallbackType::kInternalFields + : WeakCallbackType::kParameter; Local value(Local::New(this->isolate(), *persistent)); persistent->template SetWeak( - Traits::WeakCallbackParameter(this, key, value), WeakCallback); + Traits::WeakCallbackParameter(this, key, value), WeakCallback, + callback_type); } PersistentContainerValue old_value = Traits::Set(this->impl(), key, this->ClearAndLeak(persistent)); diff --git a/mac/include/v8/v8-version-string.h b/mac/include/v8/v8-version-string.h index 075282de..fb84144d 100644 --- a/mac/include/v8/v8-version-string.h +++ b/mac/include/v8/v8-version-string.h @@ -16,6 +16,10 @@ #define V8_CANDIDATE_STRING "" #endif +#ifndef V8_EMBEDDER_STRING +#define V8_EMBEDDER_STRING "" +#endif + #define V8_SX(x) #x #define V8_S(x) V8_SX(x) @@ -23,11 +27,12 @@ #define V8_VERSION_STRING \ V8_S(V8_MAJOR_VERSION) \ "." V8_S(V8_MINOR_VERSION) "." V8_S(V8_BUILD_NUMBER) "." V8_S( \ - V8_PATCH_LEVEL) V8_CANDIDATE_STRING + V8_PATCH_LEVEL) V8_EMBEDDER_STRING V8_CANDIDATE_STRING #else -#define V8_VERSION_STRING \ - V8_S(V8_MAJOR_VERSION) \ - "." V8_S(V8_MINOR_VERSION) "." V8_S(V8_BUILD_NUMBER) V8_CANDIDATE_STRING +#define V8_VERSION_STRING \ + V8_S(V8_MAJOR_VERSION) \ + "." V8_S(V8_MINOR_VERSION) "." V8_S(V8_BUILD_NUMBER) \ + V8_EMBEDDER_STRING V8_CANDIDATE_STRING #endif #endif // V8_VERSION_STRING_H_ diff --git a/mac/include/v8/v8-version.h b/mac/include/v8/v8-version.h index 0889459c..71f3b774 100644 --- a/mac/include/v8/v8-version.h +++ b/mac/include/v8/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 0 -#define V8_BUILD_NUMBER 286 -#define V8_PATCH_LEVEL 52 +#define V8_MINOR_VERSION 5 +#define V8_BUILD_NUMBER 254 +#define V8_PATCH_LEVEL 43 // Use 1 for candidates and 0 otherwise. // (Boolean macro values are not supported by all preprocessors.) diff --git a/mac/include/v8/v8.h b/mac/include/v8/v8.h index da3cdfdc..acb3efbc 100644 --- a/mac/include/v8/v8.h +++ b/mac/include/v8/v8.h @@ -104,6 +104,7 @@ class String; class StringObject; class Symbol; class SymbolObject; +class PrimitiveArray; class Private; class Uint32; class Utils; @@ -139,6 +140,7 @@ template class ReturnValue; namespace internal { class Arguments; +class DeferredHandles; class Heap; class HeapObject; class Isolate; @@ -148,6 +150,10 @@ template class CustomArguments; class PropertyCallbackArguments; class FunctionCallbackArguments; class GlobalHandles; + +namespace wasm { +class StreamingDecoder; +} // namespace wasm } // namespace internal namespace debug { @@ -307,6 +313,7 @@ class Local { friend class String; friend class Object; friend class Context; + friend class Isolate; friend class Private; template friend class internal::CustomArguments; friend Local Undefined(Isolate* isolate); @@ -427,20 +434,6 @@ class WeakCallbackInfo { V8_INLINE T* GetParameter() const { return parameter_; } V8_INLINE void* GetInternalField(int index) const; - V8_INLINE V8_DEPRECATED("use indexed version", - void* GetInternalField1() const) { - return embedder_fields_[0]; - } - V8_INLINE V8_DEPRECATED("use indexed version", - void* GetInternalField2() const) { - return embedder_fields_[1]; - } - - V8_DEPRECATED("Not realiable once SetSecondPassCallback() was used.", - bool IsFirstPass() const) { - return callback_ != nullptr; - } - // When first called, the embedder MUST Reset() the Global which triggered the // callback. The Global itself is unusable for anything else. No v8 other api // calls may be called in the first callback. Should additional work be @@ -573,16 +566,22 @@ template class PersistentBase { * independent handle should not assume that it will be preceded by a global * GC prologue callback or followed by a global GC epilogue callback. */ - V8_INLINE void MarkIndependent(); + V8_DEPRECATE_SOON( + "Objects are always considered independent. " + "Use MarkActive to avoid collecting otherwise dead weak handles.", + V8_INLINE void MarkIndependent()); /** * Marks the reference to this object as active. The scavenge garbage - * collection should not reclaim the objects marked as active. + * collection should not reclaim the objects marked as active, even if the + * object held by the handle is otherwise unreachable. + * * This bit is cleared after the each garbage collection pass. */ V8_INLINE void MarkActive(); - V8_INLINE bool IsIndependent() const; + V8_DEPRECATE_SOON("See MarkIndependent.", + V8_INLINE bool IsIndependent() const); /** Checks if the handle holds the only reference to an object. */ V8_INLINE bool IsNearDeath() const; @@ -869,8 +868,6 @@ class V8_EXPORT HandleScope { HandleScope(const HandleScope&) = delete; void operator=(const HandleScope&) = delete; - void* operator new(size_t size); - void operator delete(void*, size_t); protected: V8_INLINE HandleScope() {} @@ -881,6 +878,13 @@ class V8_EXPORT HandleScope { internal::Object* value); private: + // Declaring operator new and delete as deleted is not spec compliant. + // Therefore declare them private instead to disable dynamic alloc + void* operator new(size_t size); + void* operator new[](size_t size); + void operator delete(void*, size_t); + void operator delete[](void*, size_t); + // Uses heap_object to obtain the current Isolate. static internal::Object** CreateHandle(internal::HeapObject* heap_object, internal::Object* value); @@ -921,10 +925,15 @@ class V8_EXPORT EscapableHandleScope : public HandleScope { EscapableHandleScope(const EscapableHandleScope&) = delete; void operator=(const EscapableHandleScope&) = delete; - void* operator new(size_t size); - void operator delete(void*, size_t); private: + // Declaring operator new and delete as deleted is not spec compliant. + // Therefore declare them private instead to disable dynamic alloc + void* operator new(size_t size); + void* operator new[](size_t size); + void operator delete(void*, size_t); + void operator delete[](void*, size_t); + internal::Object** Escape(internal::Object** escape_value); internal::Object** escape_slot_; }; @@ -941,10 +950,15 @@ class V8_EXPORT SealHandleScope { SealHandleScope(const SealHandleScope&) = delete; void operator=(const SealHandleScope&) = delete; - void* operator new(size_t size); - void operator delete(void*, size_t); private: + // Declaring operator new and delete as deleted is not spec compliant. + // Therefore declare them private instead to disable dynamic alloc + void* operator new(size_t size); + void* operator new[](size_t size); + void operator delete(void*, size_t); + void operator delete[](void*, size_t); + internal::Isolate* const isolate_; internal::Object** prev_limit_; int prev_sealed_level_; @@ -962,6 +976,42 @@ class V8_EXPORT Data { Data(); }; +/** + * A container type that holds relevant metadata for module loading. + * + * This is passed back to the embedder as part of + * HostImportModuleDynamicallyCallback for module loading. + */ +class V8_EXPORT ScriptOrModule { + public: + /** + * The name that was passed by the embedder as ResourceName to the + * ScriptOrigin. This can be either a v8::String or v8::Undefined. + */ + Local GetResourceName(); + + /** + * The options that were passed by the embedder as HostDefinedOptions to + * the ScriptOrigin. + */ + Local GetHostDefinedOptions(); +}; + +/** + * An array to hold Primitive values. This is used by the embedder to + * pass host defined options to the ScriptOptions during compilation. + * + * This is passed back to the embedder as part of + * HostImportModuleDynamicallyCallback for module loading. + * + */ +class V8_EXPORT PrimitiveArray { + public: + static Local New(Isolate* isolate, int length); + int Length() const; + void Set(int index, Local item); + Local Get(int index); +}; /** * The optional attributes of ScriptOrigin. @@ -1011,16 +1061,15 @@ class ScriptOrigin { Local source_map_url = Local(), Local resource_is_opaque = Local(), Local is_wasm = Local(), - Local is_module = Local()); + Local is_module = Local(), + Local host_defined_options = Local()); V8_INLINE Local ResourceName() const; V8_INLINE Local ResourceLineOffset() const; V8_INLINE Local ResourceColumnOffset() const; - /** - * Returns true for embedder's debugger scripts - */ V8_INLINE Local ScriptID() const; V8_INLINE Local SourceMapUrl() const; + V8_INLINE Local HostDefinedOptions() const; V8_INLINE ScriptOriginOptions Options() const { return options_; } private: @@ -1030,9 +1079,9 @@ class ScriptOrigin { ScriptOriginOptions options_; Local script_id_; Local source_map_url_; + Local host_defined_options_; }; - /** * A compiled JavaScript script, not yet tied to a Context. */ @@ -1065,13 +1114,51 @@ class V8_EXPORT UnboundScript { }; /** - * This is an unfinished experimental feature, and is only exposed - * here for internal testing purposes. DO NOT USE. - * + * A location in JavaScript source. + */ +class V8_EXPORT Location { + public: + int GetLineNumber() { return line_number_; } + int GetColumnNumber() { return column_number_; } + + Location(int line_number, int column_number) + : line_number_(line_number), column_number_(column_number) {} + + private: + int line_number_; + int column_number_; +}; + +/** * A compiled JavaScript module. */ class V8_EXPORT Module { public: + /** + * The different states a module can be in. + * This corresponds to the states used in ECMAScript except that "evaluated" + * is split into kEvaluated and kErrored, indicating success and failure, + * respectively. + */ + enum Status { + kUninstantiated, + kInstantiating, + kInstantiated, + kEvaluating, + kEvaluated, + kErrored + }; + + /** + * Returns the module's current status. + */ + Status GetStatus() const; + + /** + * For a module in kErrored status, this returns the corresponding exception. + */ + Local GetException() const; + /** * Returns the number of modules requested by this module. */ @@ -1083,6 +1170,12 @@ class V8_EXPORT Module { */ Local GetModuleRequest(int i) const; + /** + * Returns the source location (line number and column number) of the ith + * module specifier's first occurrence in this module. + */ + Location GetModuleRequestLocation(int i) const; + /** * Returns the identity hash for this object. */ @@ -1095,40 +1188,26 @@ class V8_EXPORT Module { /** * ModuleDeclarationInstantiation * - * Returns false if an exception occurred during instantiation. (In the case - * where the callback throws an exception, that exception is propagated.) + * Returns an empty Maybe if an exception occurred during + * instantiation. (In the case where the callback throws an exception, that + * exception is propagated.) */ - V8_WARN_UNUSED_RESULT bool Instantiate(Local context, - ResolveCallback callback); + V8_WARN_UNUSED_RESULT Maybe InstantiateModule(Local context, + ResolveCallback callback); /** * ModuleEvaluation * * Returns the completion value. + * TODO(neis): Be more precise or say nothing. */ V8_WARN_UNUSED_RESULT MaybeLocal Evaluate(Local context); -}; - -/** - * This is an unfinished experimental feature, and is only exposed - * here for internal testing purposes. DO NOT USE. - * - * A compiled JavaScript module. - */ -class V8_EXPORT DynamicImportResult { - public: - /** - * Resolves the promise with the namespace object of the given - * module. - */ - V8_WARN_UNUSED_RESULT bool FinishDynamicImportSuccess(Local context, - Local module); /** - * Rejects the promise with the given exception. + * Returns the namespace object of this module. + * The module's status must be kEvaluated. */ - V8_WARN_UNUSED_RESULT bool FinishDynamicImportFailure(Local context, - Local exception); + Local GetModuleNamespace(); }; /** @@ -1244,6 +1323,7 @@ class V8_EXPORT ScriptCompiler { Local resource_column_offset; ScriptOriginOptions resource_options; Local source_map_url; + Local host_defined_options; // Cached data from previous compilation (if a kConsume*Cache flag is // set), or hold newly generated cache data (kProduce*Cache flags) are @@ -1340,7 +1420,30 @@ class V8_EXPORT ScriptCompiler { kProduceParserCache, kConsumeParserCache, kProduceCodeCache, - kConsumeCodeCache + kProduceFullCodeCache, + kConsumeCodeCache, + kEagerCompile + }; + + /** + * The reason for which we are not requesting or providing a code cache. + */ + enum NoCacheReason { + kNoCacheNoReason = 0, + kNoCacheBecauseCachingDisabled, + kNoCacheBecauseNoResource, + kNoCacheBecauseInlineScript, + kNoCacheBecauseModule, + kNoCacheBecauseStreamingSource, + kNoCacheBecauseInspector, + kNoCacheBecauseScriptTooSmall, + kNoCacheBecauseCacheTooCold, + kNoCacheBecauseV8Extension, + kNoCacheBecauseExtensionModule, + kNoCacheBecausePacScript, + kNoCacheBecauseInDocumentWrite, + kNoCacheBecauseResourceWithNoCacheHandler, + kNoCacheBecauseDeferredProduceCodeCache }; /** @@ -1356,13 +1459,10 @@ class V8_EXPORT ScriptCompiler { * \return Compiled script object (context independent; for running it must be * bound to a context). */ - static V8_DEPRECATED("Use maybe version", - Local CompileUnbound( - Isolate* isolate, Source* source, - CompileOptions options = kNoCompileOptions)); static V8_WARN_UNUSED_RESULT MaybeLocal CompileUnboundScript( Isolate* isolate, Source* source, - CompileOptions options = kNoCompileOptions); + CompileOptions options = kNoCompileOptions, + NoCacheReason no_cache_reason = kNoCacheNoReason); /** * Compiles the specified script (bound to current context). @@ -1375,13 +1475,10 @@ class V8_EXPORT ScriptCompiler { * when this function was called. When run it will always use this * context. */ - static V8_DEPRECATED( - "Use maybe version", - Local