From ab5addd86d878ac5564d7638333f7f15544f2c6a Mon Sep 17 00:00:00 2001 From: "jochen@chromium.org" Date: Mon, 8 Jul 2013 11:29:55 +0000 Subject: [PATCH] Introduce a handle zapping setting, and enable it by default for release and debug The checks are split out from "extra checks" which are too expensive to turn on by default. R=danno@chromium.org Review URL: https://codereview.chromium.org/18316006 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15548 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- Makefile | 7 +++++++ build/common.gypi | 8 ++++++++ src/api.cc | 2 +- src/api.h | 11 ++++++++--- src/global-handles.cc | 4 ++-- src/handles-inl.h | 2 +- src/handles.cc | 6 +++--- src/handles.h | 2 +- 8 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 16c004f32..5c9b56bd6 100644 --- a/Makefile +++ b/Makefile @@ -80,6 +80,13 @@ endif ifeq ($(extrachecks), off) GYPFLAGS += -Dv8_enable_extra_checks=0 endif +# handlezapping=on/off +ifeq ($(handlezapping), on) + GYPFLAGS += -Dv8_enable_handle_zapping=1 +endif +ifeq ($(handlezapping), off) + GYPFLAGS += -Dv8_enable_handle_zapping=0 +endif # gdbjit=on/off ifeq ($(gdbjit), on) GYPFLAGS += -Dv8_enable_gdbjit=1 diff --git a/build/common.gypi b/build/common.gypi index dbb33a867..f73c8812f 100644 --- a/build/common.gypi +++ b/build/common.gypi @@ -490,6 +490,7 @@ 'Debug': { 'variables': { 'v8_enable_extra_checks%': 1, + 'v8_enable_handle_zapping%': 1, }, 'defines': [ 'DEBUG', @@ -518,6 +519,9 @@ ['v8_enable_extra_checks==1', { 'defines': ['ENABLE_EXTRA_CHECKS',], }], + ['v8_enable_handle_zapping==1', { + 'defines': ['ENABLE_HANDLE_ZAPPING',], + }], ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="netbsd"', { 'cflags': [ '-Wall', '<(werror)', '-W', '-Wno-unused-parameter', '-Wnon-virtual-dtor', '-Woverloaded-virtual' ], @@ -550,11 +554,15 @@ 'Release': { 'variables': { 'v8_enable_extra_checks%': 0, + 'v8_enable_handle_zapping%': 1, }, 'conditions': [ ['v8_enable_extra_checks==1', { 'defines': ['ENABLE_EXTRA_CHECKS',], }], + ['v8_enable_handle_zapping==1', { + 'defines': ['ENABLE_HANDLE_ZAPPING',], + }], ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="netbsd"', { 'cflags!': [ '-O2', diff --git a/src/api.cc b/src/api.cc index c56bc0560..4d654fb1e 100644 --- a/src/api.cc +++ b/src/api.cc @@ -7979,7 +7979,7 @@ DeferredHandles::~DeferredHandles() { isolate_->UnlinkDeferredHandles(this); for (int i = 0; i < blocks_.length(); i++) { -#ifdef ENABLE_EXTRA_CHECKS +#ifdef ENABLE_HANDLE_ZAPPING HandleScope::ZapRange(blocks_[i], &blocks_[i][kHandleBlockSize]); #endif isolate_->handle_scope_implementer()->ReturnBlock(blocks_[i]); diff --git a/src/api.h b/src/api.h index 0f33bc815..85b280728 100644 --- a/src/api.h +++ b/src/api.h @@ -665,17 +665,22 @@ void HandleScopeImplementer::DeleteExtensions(internal::Object** prev_limit) { #ifdef DEBUG // SealHandleScope may make the prev_limit to point inside the block. if (block_start <= prev_limit && prev_limit <= block_limit) { -#ifdef ENABLE_EXTRA_CHECKS +#ifdef ENABLE_HANDLE_ZAPPING internal::HandleScope::ZapRange(prev_limit, block_limit); #endif break; } #else - if (prev_limit == block_limit) break; + if (prev_limit == block_limit) { +#ifdef ENABLE_HANDLE_ZAPPING + internal::HandleScope::ZapRange(prev_limit, block_limit); +#endif + break; + } #endif blocks_.RemoveLast(); -#ifdef ENABLE_EXTRA_CHECKS +#ifdef ENABLE_HANDLE_ZAPPING internal::HandleScope::ZapRange(block_start, block_limit); #endif if (spare_ != NULL) { diff --git a/src/global-handles.cc b/src/global-handles.cc index c69b9e27b..274f30e14 100644 --- a/src/global-handles.cc +++ b/src/global-handles.cc @@ -78,7 +78,7 @@ class GlobalHandles::Node { Internals::kNodeIsPartiallyDependentShift); } -#ifdef ENABLE_EXTRA_CHECKS +#ifdef ENABLE_HANDLE_ZAPPING ~Node() { // TODO(1428): if it's a weak handle we should have invoked its callback. // Zap the values for eager trapping. @@ -117,7 +117,7 @@ class GlobalHandles::Node { void Release() { ASSERT(state() != FREE); set_state(FREE); -#ifdef ENABLE_EXTRA_CHECKS +#ifdef ENABLE_HANDLE_ZAPPING // Zap the values for eager trapping. object_ = reinterpret_cast(kGlobalHandleZapValue); class_id_ = v8::HeapProfiler::kPersistentHandleNoClassId; diff --git a/src/handles-inl.h b/src/handles-inl.h index 4f4490b75..f427d1287 100644 --- a/src/handles-inl.h +++ b/src/handles-inl.h @@ -134,7 +134,7 @@ void HandleScope::CloseScope(Isolate* isolate, DeleteExtensions(isolate); } -#ifdef ENABLE_EXTRA_CHECKS +#ifdef ENABLE_HANDLE_ZAPPING ZapRange(prev_next, prev_limit); #endif } diff --git a/src/handles.cc b/src/handles.cc index fc45aaa8b..fdfc01a42 100644 --- a/src/handles.cc +++ b/src/handles.cc @@ -101,7 +101,7 @@ void HandleScope::DeleteExtensions(Isolate* isolate) { } -#ifdef ENABLE_EXTRA_CHECKS +#ifdef ENABLE_HANDLE_ZAPPING void HandleScope::ZapRange(Object** start, Object** end) { ASSERT(end - start <= kHandleBlockSize); for (Object** p = start; p != end; p++) { @@ -554,7 +554,7 @@ v8::Handle GetKeysForNamedInterceptor(Handle receiver, LOG(isolate, ApiObjectAccess("interceptor-named-enum", *object)); result = args.Call(enum_fun); } -#if ENABLE_EXTRA_CHECKS +#if ENABLE_HANDLE_ZAPPING CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject()); #endif return v8::Local::New(reinterpret_cast(isolate), @@ -575,7 +575,7 @@ v8::Handle GetKeysForIndexedInterceptor(Handle receiver, v8::ToCData(interceptor->enumerator()); LOG(isolate, ApiObjectAccess("interceptor-indexed-enum", *object)); result = args.Call(enum_fun); -#if ENABLE_EXTRA_CHECKS +#if ENABLE_HANDLE_ZAPPING CHECK(result.IsEmpty() || v8::Utils::OpenHandle(*result)->IsJSObject()); #endif } diff --git a/src/handles.h b/src/handles.h index 140c34e9b..5dd9fe72a 100644 --- a/src/handles.h +++ b/src/handles.h @@ -177,7 +177,7 @@ class HandleScope { // Extend the handle scope making room for more handles. static internal::Object** Extend(Isolate* isolate); -#ifdef ENABLE_EXTRA_CHECKS +#ifdef ENABLE_HANDLE_ZAPPING // Zaps the handles in the half-open interval [start, end). static void ZapRange(Object** start, Object** end); #endif -- 2.34.1