From 312f94916cbcc97977ab0d074b639e85a8e7d898 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Fri, 12 Jul 2019 12:10:28 +0800 Subject: [PATCH] deps: V8: backport d2ccc59 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [snapshot] print reference stack for JSFunctions in the isolate snapshot This helps debugging incorrect usage of the SnapshotCreator API in debug mode. Change-Id: Ibd9db76a5f460cdf7ea6d14e865592ebaf69aeef Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1648240 Reviewed-by: Yang Guo Commit-Queue: Yang Guo Cr-Commit-Position: refs/heads/master@{#62095} Refs: https://github.com/v8/v8/commit/d2ccc599c7a31838752350ae927e41bc386df414 PR-URL: https://github.com/nodejs/node/pull/28648 Reviewed-By: Michaƫl Zasso Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: James M Snell --- common.gypi | 2 +- deps/v8/src/snapshot/serializer.cc | 8 +++++--- deps/v8/src/snapshot/serializer.h | 1 + deps/v8/src/snapshot/startup-serializer.cc | 11 ++++++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/common.gypi b/common.gypi index 63cd2e29c3c123..36e9745009ee44 100644 --- a/common.gypi +++ b/common.gypi @@ -38,7 +38,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.14', + 'v8_embedder_string': '-node.15', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/snapshot/serializer.cc b/deps/v8/src/snapshot/serializer.cc index 0096b2c4fb41e3..447a69aea85f35 100644 --- a/deps/v8/src/snapshot/serializer.cc +++ b/deps/v8/src/snapshot/serializer.cc @@ -116,10 +116,12 @@ void Serializer::SerializeRootObject(Object object) { } #ifdef DEBUG -void Serializer::PrintStack() { +void Serializer::PrintStack() { PrintStack(std::cout); } + +void Serializer::PrintStack(std::ostream& out) { for (const auto o : stack_) { - o->Print(); - PrintF("\n"); + o.Print(out); + out << "\n"; } } #endif // DEBUG diff --git a/deps/v8/src/snapshot/serializer.h b/deps/v8/src/snapshot/serializer.h index 9f7c0ac90c3192..49ffddbefbd87e 100644 --- a/deps/v8/src/snapshot/serializer.h +++ b/deps/v8/src/snapshot/serializer.h @@ -250,6 +250,7 @@ class Serializer : public SerializerDeserializer { void PushStack(HeapObject o) { stack_.push_back(o); } void PopStack() { stack_.pop_back(); } void PrintStack(); + void PrintStack(std::ostream&); #endif // DEBUG SerializerReferenceMap* reference_map() { return &reference_map_; } diff --git a/deps/v8/src/snapshot/startup-serializer.cc b/deps/v8/src/snapshot/startup-serializer.cc index 907b3387429c4c..47b3f0f41b47ac 100644 --- a/deps/v8/src/snapshot/startup-serializer.cc +++ b/deps/v8/src/snapshot/startup-serializer.cc @@ -72,7 +72,16 @@ bool IsUnexpectedCodeObject(Isolate* isolate, HeapObject obj) { #endif // DEBUG void StartupSerializer::SerializeObject(HeapObject obj) { - DCHECK(!obj->IsJSFunction()); +#ifdef DEBUG + if (obj.IsJSFunction()) { + v8::base::OS::PrintError("Reference stack:\n"); + PrintStack(std::cerr); + obj.Print(std::cerr); + FATAL( + "JSFunction should be added through the context snapshot instead of " + "the isolate snapshot"); + } +#endif // DEBUG DCHECK(!IsUnexpectedCodeObject(isolate(), obj)); if (SerializeHotObject(obj)) return;