Merge V8 5.3.332.45. DO NOT MERGE
Test: Manual
FPIIM-449
Change-Id: Id3254828b068abdea3cb10442e0172a8c9a98e03
(cherry picked from commit 13e2dadd00298019ed862f2b2fc5068bba730bcf)
diff --git a/include/v8.h b/include/v8.h
index 3f02ce8..c62a1fd 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -1613,21 +1613,21 @@
// A StateTag represents a possible state of the VM.
enum StateTag { JS, GC, COMPILER, OTHER, EXTERNAL, IDLE };
-
// A RegisterState represents the current state of registers used
// by the sampling profiler API.
struct RegisterState {
- RegisterState() : pc(NULL), sp(NULL), fp(NULL) {}
+ RegisterState() : pc(nullptr), sp(nullptr), fp(nullptr) {}
void* pc; // Instruction pointer.
void* sp; // Stack pointer.
void* fp; // Frame pointer.
};
-
// The output structure filled up by GetStackSample API function.
struct SampleInfo {
- size_t frames_count;
- StateTag vm_state;
+ size_t frames_count; // Number of frames collected.
+ StateTag vm_state; // Current VM state.
+ void* external_callback_entry; // External callback address if VM is
+ // executing an external callback.
};
/**
@@ -1658,7 +1658,8 @@
* \return The corresponding string if successfully stringified.
*/
static V8_WARN_UNUSED_RESULT MaybeLocal<String> Stringify(
- Local<Context> context, Local<Object> json_object);
+ Local<Context> context, Local<Object> json_object,
+ Local<String> gap = Local<String>());
};
@@ -2631,6 +2632,21 @@
};
/**
+ * Keys/Properties filter enums:
+ *
+ * KeyCollectionMode limits the range of collected properties. kOwnOnly limits
+ * the collected properties to the given Object only. kIncludesPrototypes will
+ * include all keys of the objects's prototype chain as well.
+ */
+enum class KeyCollectionMode { kOwnOnly, kIncludePrototypes };
+
+/**
+ * kIncludesIndices allows for integer indices to be collected, while
+ * kSkipIndices will exclude integer indicies from being collected.
+ */
+enum class IndexFilter { kIncludeIndices, kSkipIndices };
+
+/**
* Integrity level for objects.
*/
enum class IntegrityLevel { kFrozen, kSealed };
@@ -2779,6 +2795,9 @@
V8_DEPRECATE_SOON("Use maybe version", Local<Array> GetPropertyNames());
V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
Local<Context> context);
+ V8_WARN_UNUSED_RESULT MaybeLocal<Array> GetPropertyNames(
+ Local<Context> context, KeyCollectionMode mode,
+ PropertyFilter property_filter, IndexFilter index_filter);
/**
* This function has the same functionality as GetPropertyNames but
@@ -4367,28 +4386,6 @@
typedef bool (*AccessCheckCallback)(Local<Context> accessing_context,
Local<Object> accessed_object,
Local<Value> data);
-typedef bool (*DeprecatedAccessCheckCallback)(Local<Context> accessing_context,
- Local<Object> accessed_object);
-
-/**
- * Returns true if cross-context access should be allowed to the named
- * property with the given key on the host object.
- */
-typedef bool (*NamedSecurityCallback)(Local<Object> host,
- Local<Value> key,
- AccessType type,
- Local<Value> data);
-
-
-/**
- * Returns true if cross-context access should be allowed to the indexed
- * property with the given index on the host object.
- */
-typedef bool (*IndexedSecurityCallback)(Local<Object> host,
- uint32_t index,
- AccessType type,
- Local<Value> data);
-
/**
* A FunctionTemplate is used to create functions at runtime. There
@@ -4494,6 +4491,9 @@
Local<Signature> signature = Local<Signature>(), int length = 0,
ConstructorBehavior behavior = ConstructorBehavior::kAllow);
+ /** Get a template included in the snapshot by index. */
+ static Local<FunctionTemplate> FromSnapshot(Isolate* isolate, size_t index);
+
/**
* Creates a function template with a fast handler. If a fast handler is set,
* the callback cannot be null.
@@ -4669,6 +4669,9 @@
Local<FunctionTemplate> constructor = Local<FunctionTemplate>());
static V8_DEPRECATED("Use isolate version", Local<ObjectTemplate> New());
+ /** Get a template included in the snapshot by index. */
+ static Local<ObjectTemplate> FromSnapshot(Isolate* isolate, size_t index);
+
/** Creates a new instance of this template.*/
V8_DEPRECATE_SOON("Use maybe version", Local<Object> NewInstance());
V8_WARN_UNUSED_RESULT MaybeLocal<Object> NewInstance(Local<Context> context);
@@ -4799,16 +4802,18 @@
*/
void SetAccessCheckCallback(AccessCheckCallback callback,
Local<Value> data = Local<Value>());
- V8_DEPRECATED(
- "Use SetAccessCheckCallback with new AccessCheckCallback signature.",
- void SetAccessCheckCallback(DeprecatedAccessCheckCallback callback,
- Local<Value> data = Local<Value>()));
- V8_DEPRECATED(
- "Use SetAccessCheckCallback instead",
- void SetAccessCheckCallbacks(NamedSecurityCallback named_handler,
- IndexedSecurityCallback indexed_handler,
- Local<Value> data = Local<Value>()));
+ /**
+ * Like SetAccessCheckCallback but invokes an interceptor on failed access
+ * checks instead of looking up all-can-read properties. You can only use
+ * either this method or SetAccessCheckCallback, but not both at the same
+ * time.
+ */
+ void SetAccessCheckCallbackAndHandler(
+ AccessCheckCallback callback,
+ const NamedPropertyHandlerConfiguration& named_handler,
+ const IndexedPropertyHandlerConfiguration& indexed_handler,
+ Local<Value> data = Local<Value>());
/**
* Gets the number of internal fields for objects generated from
@@ -5053,10 +5058,6 @@
kAllocationActionAll = kAllocationActionAllocate | kAllocationActionFree
};
-typedef void (*MemoryAllocationCallback)(ObjectSpace space,
- AllocationAction action,
- int size);
-
// --- Enter/Leave Script Callback ---
typedef void (*BeforeCallEnteredCallback)(Isolate*);
typedef void (*CallCompletedCallback)(Isolate*);
@@ -5277,6 +5278,18 @@
friend class Isolate;
};
+class V8_EXPORT HeapCodeStatistics {
+ public:
+ HeapCodeStatistics();
+ size_t code_and_metadata_size() { return code_and_metadata_size_; }
+ size_t bytecode_and_metadata_size() { return bytecode_and_metadata_size_; }
+
+ private:
+ size_t code_and_metadata_size_;
+ size_t bytecode_and_metadata_size_;
+
+ friend class Isolate;
+};
class RetainedObjectInfo;
@@ -5360,6 +5373,31 @@
};
/**
+ * Option flags passed to the SetRAILMode function.
+ * See documentation https://developers.google.com/web/tools/chrome-devtools/
+ * profile/evaluate-performance/rail
+ */
+enum RAILMode {
+ // Default performance mode: V8 will optimize for both latency and
+ // throughput in this mode.
+ PERFORMANCE_DEFAULT,
+ // Response performance mode: In this mode very low virtual machine latency
+ // is provided. V8 will try to avoid JavaScript execution interruptions.
+ // Throughput may be throttled.
+ PERFORMANCE_RESPONSE,
+ // Animation performance mode: In this mode low virtual machine latency is
+ // provided. V8 will try to avoid as many JavaScript execution interruptions
+ // as possible. Throughput may be throttled
+ PERFORMANCE_ANIMATION,
+ // Idle performance mode: The embedder is idle. V8 can complete deferred work
+ // in this mode.
+ PERFORMANCE_IDLE,
+ // Load performance mode: In this mode high throughput is provided. V8 may
+ // turn off latency optimizations.
+ PERFORMANCE_LOAD
+};
+
+/**
* Option flags passed to the SetJitCodeEventHandler function.
*/
enum JitCodeEventOptions {
@@ -5420,24 +5458,51 @@
*/
class V8_EXPORT EmbedderHeapTracer {
public:
+ enum ForceCompletionAction { FORCE_COMPLETION, DO_NOT_FORCE_COMPLETION };
+ struct AdvanceTracingActions {
+ explicit AdvanceTracingActions(ForceCompletionAction force_completion_)
+ : force_completion(force_completion_) {}
+
+ ForceCompletionAction force_completion;
+ };
+ /**
+ * V8 will call this method with internal fields of found wrappers.
+ * Embedder is expected to store them in it's marking deque and trace
+ * reachable wrappers from them when asked by AdvanceTracing method.
+ */
+ virtual void RegisterV8References(
+ const std::vector<std::pair<void*, void*> >& internal_fields) = 0;
/**
* V8 will call this method at the beginning of the gc cycle.
*/
virtual void TracePrologue() = 0;
/**
- * V8 will call this method with internal fields of a potential wrappers.
- * Embedder is expected to trace its heap (synchronously) and call
- * PersistentBase::RegisterExternalReference() on all wrappers reachable from
- * any of the given wrappers.
+ * Embedder is expected to trace its heap starting from wrappers reported by
+ * RegisterV8References method, and call
+ * PersistentBase::RegisterExternalReference() on all reachable wrappers.
+ * Embedder is expected to stop tracing by the given deadline.
+ *
+ * Returns true if there is still work to do.
*/
- virtual void TraceWrappersFrom(
- const std::vector<std::pair<void*, void*> >& internal_fields) = 0;
+ virtual bool AdvanceTracing(double deadline_in_ms,
+ AdvanceTracingActions actions) = 0;
/**
* V8 will call this method at the end of the gc cycle. Allocation is *not*
* allowed in the TraceEpilogue.
*/
virtual void TraceEpilogue() = 0;
+ /**
+ * Let embedder know v8 entered final marking pause (no more incremental steps
+ * will follow).
+ */
+ virtual void EnterFinalPause() {}
+
+ /**
+ * Throw away all intermediate data and reset to the initial state.
+ */
+ virtual void AbortTracing() {}
+
protected:
virtual ~EmbedderHeapTracer() = default;
};
@@ -5457,20 +5522,21 @@
*/
struct CreateParams {
CreateParams()
- : entry_hook(NULL),
- code_event_handler(NULL),
- snapshot_blob(NULL),
- counter_lookup_callback(NULL),
- create_histogram_callback(NULL),
- add_histogram_sample_callback(NULL),
- array_buffer_allocator(NULL) {}
+ : entry_hook(nullptr),
+ code_event_handler(nullptr),
+ snapshot_blob(nullptr),
+ counter_lookup_callback(nullptr),
+ create_histogram_callback(nullptr),
+ add_histogram_sample_callback(nullptr),
+ array_buffer_allocator(nullptr),
+ external_references(nullptr) {}
/**
* The optional entry_hook allows the host application to provide the
* address of a function that's invoked on entry to every V8-generated
* function. Note that entry_hook is invoked at the very start of each
- * generated function. Furthermore, if an entry_hook is given, V8 will
- * always run without a context snapshot.
+ * generated function. Furthermore, if an entry_hook is given, V8 will
+ * not use a snapshot, including custom snapshots.
*/
FunctionEntryHook entry_hook;
@@ -5511,6 +5577,14 @@
* store of ArrayBuffers.
*/
ArrayBuffer::Allocator* array_buffer_allocator;
+
+ /**
+ * Specifies an optional nullptr-terminated array of raw addresses in the
+ * embedder that V8 can match against during serialization and use for
+ * deserialization. This array and its content must stay valid for the
+ * entire lifetime of the isolate.
+ */
+ intptr_t* external_references;
};
@@ -5640,6 +5714,8 @@
kRegExpPrototypeSourceGetter = 30,
kRegExpPrototypeOldFlagGetter = 31,
kDecimalWithLeadingZeroInStrictMode = 32,
+ kLegacyDateParser = 33,
+ kDefineGetterOrSetterWouldThrow = 34,
// If you add new values here, you'll also need to update Chromium's:
// UseCounter.h, V8PerIsolateData.cpp, histograms.xml
@@ -5784,6 +5860,15 @@
size_t type_index);
/**
+ * Get statistics about code and its metadata in the heap.
+ *
+ * \param object_statistics The HeapCodeStatistics object to fill in
+ * statistics of code, bytecode and their metadata.
+ * \returns true on success.
+ */
+ bool GetHeapCodeAndMetadataStatistics(HeapCodeStatistics* object_statistics);
+
+ /**
* Get a call stack sample from the isolate.
* \param state Execution state.
* \param frames Caller allocated buffer to store stack frames.
@@ -6161,6 +6246,15 @@
void IsolateInBackgroundNotification();
/**
+ * Optional notification to tell V8 the current performance requirements
+ * of the embedder based on RAIL.
+ * V8 uses these notifications to guide heuristics.
+ * This is an unfinished experimental feature. Semantics and implementation
+ * may change frequently.
+ */
+ void SetRAILMode(RAILMode rail_mode);
+
+ /**
* Allows the host application to provide the address of a function that is
* notified each time code is added, moved or removed.
*
@@ -6256,22 +6350,6 @@
StackTrace::StackTraceOptions options = StackTrace::kOverview);
/**
- * Enables the host application to provide a mechanism to be notified
- * and perform custom logging when V8 Allocates Executable Memory.
- */
- void V8_DEPRECATED(
- "Use a combination of RequestInterrupt and GCCallback instead",
- AddMemoryAllocationCallback(MemoryAllocationCallback callback,
- ObjectSpace space, AllocationAction action));
-
- /**
- * Removes callback that was installed by AddMemoryAllocationCallback.
- */
- void V8_DEPRECATED(
- "Use a combination of RequestInterrupt and GCCallback instead",
- RemoveMemoryAllocationCallback(MemoryAllocationCallback callback));
-
- /**
* Iterates through all external resources referenced from current isolate
* heap. GC is not invoked prior to iterating, therefore there is no
* guarantee that visited objects are still alive.
@@ -6300,6 +6378,12 @@
*/
void VisitWeakHandles(PersistentHandleVisitor* visitor);
+ /**
+ * Check if this isolate is in use.
+ * True if at least one thread Enter'ed this isolate.
+ */
+ bool IsInUse();
+
private:
template <class K, class V, class Traits>
friend class PersistentValueMapBase;
@@ -6625,7 +6709,24 @@
* If V8 was compiled with the ICU data in an external file, the location
* of the data file has to be provided.
*/
- static bool InitializeICU(const char* icu_data_file = NULL);
+ V8_DEPRECATE_SOON(
+ "Use version with default location.",
+ static bool InitializeICU(const char* icu_data_file = nullptr));
+
+ /**
+ * Initialize the ICU library bundled with V8. The embedder should only
+ * invoke this method when using the bundled ICU. If V8 was compiled with
+ * the ICU data in an external file and when the default location of that
+ * file should be used, a path to the executable must be provided.
+ * Returns true on success.
+ *
+ * The default is a file called icudtl.dat side-by-side with the executable.
+ *
+ * Optionally, the location of the data file can be provided to override the
+ * default.
+ */
+ static bool InitializeICUDefaultLocation(const char* exec_path,
+ const char* icu_data_file = nullptr);
/**
* Initialize the external startup data. The embedder only needs to
@@ -6702,6 +6803,60 @@
friend class Context;
};
+/**
+ * Helper class to create a snapshot data blob.
+ */
+class SnapshotCreator {
+ public:
+ enum class FunctionCodeHandling { kClear, kKeep };
+
+ /**
+ * Create 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(intptr_t* external_references = nullptr,
+ StartupData* existing_blob = nullptr);
+
+ ~SnapshotCreator();
+
+ /**
+ * \returns the isolate prepared by the snapshot creator.
+ */
+ Isolate* GetIsolate();
+
+ /**
+ * Add a context to be included in the snapshot blob.
+ * \returns the index of the context in the snapshot blob.
+ */
+ size_t AddContext(Local<Context> context);
+
+ /**
+ * Add a template to be included in the snapshot blob.
+ * \returns the index of the template in the snapshot blob.
+ */
+ size_t AddTemplate(Local<Template> template_obj);
+
+ /**
+ * Created a snapshot data blob.
+ * This must not be called from within a handle scope.
+ * \param function_code_handling whether to include compiled function code
+ * in the snapshot.
+ * \returns { nullptr, 0 } on failure, and a startup snapshot on success. The
+ * caller acquires ownership of the data array in the return value.
+ */
+ StartupData CreateBlob(FunctionCodeHandling function_code_handling);
+
+ private:
+ void* data_;
+
+ // Disallow copying and assigning.
+ SnapshotCreator(const SnapshotCreator&);
+ void operator=(const SnapshotCreator&);
+};
/**
* A simple Maybe type, representing an object which may or may not have a
@@ -6988,7 +7143,8 @@
static Local<Context> New(
Isolate* isolate, ExtensionConfiguration* extensions = NULL,
Local<ObjectTemplate> global_template = Local<ObjectTemplate>(),
- Local<Value> global_object = Local<Value>());
+ Local<Value> global_object = Local<Value>(),
+ size_t context_snapshot_index = 0);
/**
* Sets the security token for the context. To access an object in
@@ -7355,13 +7511,12 @@
static const int kExternalOneByteRepresentationTag = 0x06;
static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
- static const int kAmountOfExternalAllocatedMemoryOffset =
- 4 * kApiPointerSize;
- static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset =
- kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size;
- static const int kIsolateRootsOffset =
- kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size +
- kApiPointerSize;
+ static const int kExternalMemoryOffset = 4 * kApiPointerSize;
+ static const int kExternalMemoryLimitOffset =
+ kExternalMemoryOffset + kApiInt64Size;
+ static const int kIsolateRootsOffset = kExternalMemoryLimitOffset +
+ kApiInt64Size + kApiInt64Size +
+ kApiPointerSize + kApiPointerSize;
static const int kUndefinedValueRootIndex = 4;
static const int kTheHoleValueRootIndex = 5;
static const int kNullValueRootIndex = 6;
@@ -7369,10 +7524,6 @@
static const int kFalseValueRootIndex = 8;
static const int kEmptyStringRootIndex = 9;
- // The external allocation limit should be below 256 MB on all architectures
- // to avoid that resource-constrained embedders run low on memory.
- static const int kExternalAllocationLimit = 192 * 1024 * 1024;
-
static const int kNodeClassIdOffset = 1 * kApiPointerSize;
static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
static const int kNodeStateMask = 0x7;
@@ -8567,21 +8718,16 @@
int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
int64_t change_in_bytes) {
typedef internal::Internals I;
- int64_t* amount_of_external_allocated_memory =
- reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
- I::kAmountOfExternalAllocatedMemoryOffset);
- int64_t* amount_of_external_allocated_memory_at_last_global_gc =
- reinterpret_cast<int64_t*>(
- reinterpret_cast<uint8_t*>(this) +
- I::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset);
- int64_t amount = *amount_of_external_allocated_memory + change_in_bytes;
- if (change_in_bytes > 0 &&
- amount - *amount_of_external_allocated_memory_at_last_global_gc >
- I::kExternalAllocationLimit) {
+ int64_t* external_memory = reinterpret_cast<int64_t*>(
+ reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryOffset);
+ const int64_t external_memory_limit = *reinterpret_cast<int64_t*>(
+ reinterpret_cast<uint8_t*>(this) + I::kExternalMemoryLimitOffset);
+ const int64_t amount = *external_memory + change_in_bytes;
+ *external_memory = amount;
+ if (change_in_bytes > 0 && amount > external_memory_limit) {
ReportExternalAllocationLimitReached();
}
- *amount_of_external_allocated_memory = amount;
- return *amount_of_external_allocated_memory;
+ return *external_memory;
}