Skip to content

Commit d629051

Browse files
Erik CorryV8 LUCI CQ
authored andcommitted
Make it possible to enable only global handle zapping.
Local handle zapping is too expensive to use in production. With this change you can define v8_enable_handle_zapping = true v8_enable_local_handle_zapping = false which gets some checking without as big a performance hit. Change-Id: I13fb5ef9eb5a69f56f85e21e5f11c68d34a9e311 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6109037 Commit-Queue: Erik Corry <[email protected]> Reviewed-by: Michael Lippautz <[email protected]> Cr-Commit-Position: refs/heads/main@{#98018}
1 parent 7b598f3 commit d629051

13 files changed

Lines changed: 50 additions & 21 deletions

.bazelrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ build:debug --compilation_mode=dbg
1717
build:debug --config=v8_enable_debugging_features
1818
build:debug --//:v8_enable_fast_mksnapshot
1919
build:debug --//:v8_enable_backtrace
20-
build:debug --//:v8_enable_handle_zapping
20+
build:debug --//:v8_enable_local_handle_zapping
21+
build:debug --//:v8_enable_global_handle_zapping
2122

2223
# v8_enable_debugging_features flags
2324
build:v8_enable_debugging_features --//:v8_enable_verify_heap

BUILD.bazel

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ v8_flag(name = "v8_enable_debug_code")
108108

109109
v8_flag(name = "v8_enable_disassembler")
110110

111-
v8_flag(name = "v8_enable_handle_zapping")
111+
v8_flag(name = "v8_enable_local_handle_zapping")
112+
113+
v8_flag(name = "v8_enable_global_handle_zapping")
112114

113115
v8_flag(name = "v8_enable_runtime_call_stats")
114116

@@ -447,7 +449,8 @@ v8_config(
447449
"v8_imminent_deprecation_warnings": "V8_IMMINENT_DEPRECATION_WARNINGS",
448450
"v8_enable_debug_code": "V8_ENABLE_DEBUG_CODE",
449451
"v8_enable_disassembler": "ENABLE_DISASSEMBLER",
450-
"v8_enable_handle_zapping": "ENABLE_HANDLE_ZAPPING",
452+
"v8_enable_global_handle_zapping": "ENABLE_GLOBAL_HANDLE_ZAPPING",
453+
"v8_enable_local_handle_zapping": "ENABLE_LOCAL_HANDLE_ZAPPING",
451454
"v8_enable_hugepage": "ENABLE_HUGEPAGE",
452455
"v8_enable_future": "V8_ENABLE_FUTURE",
453456
"v8_enable_lazy_source_positions": "V8_ENABLE_LAZY_SOURCE_POSITIONS",

BUILD.gn

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,19 @@ declare_args() {
9494
# See v8:7381 for more details.
9595
v8_enable_private_mapping_fork_optimization = false
9696

97-
# Sets -DENABLE_HANDLE_ZAPPING.
97+
# Sets the default for v8_enable_local_handle_zapping and
98+
# v8_enable_global_handle_zapping.
9899
v8_enable_handle_zapping = is_asan || is_debug
99100

101+
# Sets -DENABLE_LOCAL_HANDLE_ZAPPING, which is more expensive than just
102+
# the global handles. By default it is enabled if v8_enable_handle_zapping
103+
# is enabled.
104+
v8_enable_local_handle_zapping = ""
105+
106+
# Sets -DENABLE_GLOBAL_HANDLE_ZAPPING. By default it is enabled if
107+
# v8_enable_handle_zapping is enabled.
108+
v8_enable_global_handle_zapping = ""
109+
100110
# Enable slow dchecks.
101111
v8_enable_slow_dchecks = false
102112

@@ -542,6 +552,12 @@ if (v8_enable_pointer_compression_shared_cage == "") {
542552
if (v8_enable_pointer_compression_8gb == "") {
543553
v8_enable_pointer_compression_8gb = false
544554
}
555+
if (v8_enable_local_handle_zapping == "") {
556+
v8_enable_local_handle_zapping = v8_enable_handle_zapping
557+
}
558+
if (v8_enable_global_handle_zapping == "") {
559+
v8_enable_global_handle_zapping = v8_enable_handle_zapping
560+
}
545561
if (v8_enable_fast_torque == "") {
546562
v8_enable_fast_torque = v8_enable_fast_mksnapshot
547563
}
@@ -1187,8 +1203,11 @@ config("features") {
11871203
if (v8_enable_i18n_support) {
11881204
defines += [ "V8_INTL_SUPPORT" ]
11891205
}
1190-
if (v8_enable_handle_zapping) {
1191-
defines += [ "ENABLE_HANDLE_ZAPPING" ]
1206+
if (v8_enable_local_handle_zapping) {
1207+
defines += [ "ENABLE_LOCAL_HANDLE_ZAPPING" ]
1208+
}
1209+
if (v8_enable_global_handle_zapping) {
1210+
defines += [ "ENABLE_GLOBAL_HANDLE_ZAPPING" ]
11921211
}
11931212
if (v8_code_comments == true) {
11941213
defines += [ "V8_CODE_COMMENTS" ]

src/api/api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,14 @@ void HandleScopeImplementer::DeleteExtensions(internal::Address* prev_limit) {
488488
reinterpret_cast<Address>(prev_limit) &&
489489
reinterpret_cast<Address>(prev_limit) <=
490490
reinterpret_cast<Address>(block_limit)) {
491-
#ifdef ENABLE_HANDLE_ZAPPING
491+
#ifdef ENABLE_LOCAL_HANDLE_ZAPPING
492492
internal::HandleScope::ZapRange(prev_limit, block_limit);
493493
#endif
494494
break;
495495
}
496496

497497
blocks_.pop_back();
498-
#ifdef ENABLE_HANDLE_ZAPPING
498+
#ifdef ENABLE_LOCAL_HANDLE_ZAPPING
499499
internal::HandleScope::ZapRange(block_start, block_limit);
500500
#endif
501501
if (spare_ != nullptr) {

src/common/globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,7 @@ constexpr uint64_t kClearedFreeMemoryValue = 0;
978978
constexpr uint64_t kZapValue = uint64_t{0xdeadbeedbeadbeef};
979979
constexpr uint64_t kHandleZapValue = uint64_t{0x1baddead0baddeaf};
980980
constexpr uint64_t kGlobalHandleZapValue = uint64_t{0x1baffed00baffedf};
981+
constexpr uint64_t kPersistentHandleZapValue = uint64_t{0x1baffed66baffedf};
981982
constexpr uint64_t kTracedHandleEagerResetZapValue =
982983
uint64_t{0x1beffedaabaffedf};
983984
constexpr uint64_t kTracedHandleMinorGCResetZapValue =
@@ -995,6 +996,7 @@ constexpr uint32_t kClearedFreeMemoryValue = 0;
995996
constexpr uint32_t kZapValue = 0xdeadbeef;
996997
constexpr uint32_t kHandleZapValue = 0xbaddeaf;
997998
constexpr uint32_t kGlobalHandleZapValue = 0xbaffedf;
999+
constexpr uint32_t kPersistentHandleZapValue = 0xbaff6df;
9981000
constexpr uint32_t kTracedHandleEagerResetZapValue = 0xbeffedf;
9991001
constexpr uint32_t kTracedHandleMinorGCResetZapValue = 0xbeffadf;
10001002
constexpr uint32_t kTracedHandleMinorGCWeakResetZapValue = 0xbe11adf;

src/handles/global-handles.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class NodeBase {
304304
DCHECK_EQ(offsetof(NodeBase, flags_), Internals::kNodeFlagsOffset);
305305
}
306306

307-
#ifdef ENABLE_HANDLE_ZAPPING
307+
#ifdef ENABLE_GLOBAL_HANDLE_ZAPPING
308308
~NodeBase() {
309309
ClearFields();
310310
data_.next_free = nullptr;

src/handles/handles-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ void HandleScope::CloseScope(Isolate* isolate, Address* prev_next,
236236
limit = prev_limit;
237237
DeleteExtensions(isolate);
238238
}
239-
#ifdef ENABLE_HANDLE_ZAPPING
239+
#ifdef ENABLE_LOCAL_HANDLE_ZAPPING
240240
ZapRange(current->next, limit);
241241
#endif
242242
MSAN_ALLOCATED_UNINITIALIZED_MEMORY(

src/handles/handles.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,12 @@ void HandleScope::DeleteExtensions(Isolate* isolate) {
222222
isolate->handle_scope_implementer()->DeleteExtensions(current->limit);
223223
}
224224

225-
#ifdef ENABLE_HANDLE_ZAPPING
226-
void HandleScope::ZapRange(Address* start, Address* end) {
225+
#if defined(ENABLE_GLOBAL_HANDLE_ZAPPING) || \
226+
defined(ENABLE_LOCAL_HANDLE_ZAPPING)
227+
void HandleScope::ZapRange(Address* start, Address* end, uintptr_t zap_value) {
227228
DCHECK_LE(end - start, kHandleBlockSize);
228229
for (Address* p = start; p != end; p++) {
229-
*p = static_cast<Address>(kHandleZapValue);
230+
*p = static_cast<Address>(zap_value);
230231
}
231232
}
232233
#endif

src/handles/handles.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,11 @@ class V8_NODISCARD HandleScope {
325325
// Extend the handle scope making room for more handles.
326326
V8_EXPORT_PRIVATE V8_NOINLINE static Address* Extend(Isolate* isolate);
327327

328-
#ifdef ENABLE_HANDLE_ZAPPING
328+
#if defined(ENABLE_GLOBAL_HANDLE_ZAPPING) || \
329+
defined(ENABLE_LOCAL_HANDLE_ZAPPING)
329330
// Zaps the handles in the half-open interval [start, end).
330-
V8_EXPORT_PRIVATE static void ZapRange(Address* start, Address* end);
331+
V8_EXPORT_PRIVATE static void ZapRange(Address* start, Address* end,
332+
uintptr_t value = kHandleZapValue);
331333
#endif
332334

333335
friend class v8::HandleScope;

src/handles/local-handles-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ void LocalHandleScope::CloseScope(LocalHeap* local_heap, Address* prev_next,
100100
old_limit = handles->scope_.limit;
101101
}
102102

103-
#ifdef ENABLE_HANDLE_ZAPPING
103+
#ifdef ENABLE_LOCAL_HANDLE_ZAPPING
104104
LocalHandles::ZapRange(handles->scope_.next, old_limit);
105105
#endif
106106

0 commit comments

Comments
 (0)