Commit feed21b6 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Add option to disable MirrorCache.

R=yurys@chromium.org

Review URL: https://codereview.chromium.org/307383002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21644 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 519c6c9c
......@@ -2459,17 +2459,17 @@ void Debug::ClearMirrorCache() {
PostponeInterruptsScope postpone(isolate_);
HandleScope scope(isolate_);
ASSERT(isolate_->context() == *Debug::debug_context());
// Clear the mirror cache.
Handle<Object> fun = Object::GetProperty(
isolate_,
isolate_->global_object(),
"ClearMirrorCache").ToHandleChecked();
ASSERT(fun->IsJSFunction());
Execution::TryCall(Handle<JSFunction>::cast(fun),
Handle<JSObject>(Debug::debug_context()->global_object()),
0,
NULL);
Factory* factory = isolate_->factory();
JSObject::SetProperty(isolate_->global_object(),
factory->NewStringFromAsciiChecked("next_handle_"),
handle(Smi::FromInt(0), isolate_),
NONE,
SLOPPY).Check();
JSObject::SetProperty(isolate_->global_object(),
factory->NewStringFromAsciiChecked("mirror_cache_"),
factory->NewJSArray(0, FAST_ELEMENTS),
NONE,
SLOPPY).Check();
}
......
......@@ -8,6 +8,14 @@ var next_transient_handle_ = -1;
// Mirror cache.
var mirror_cache_ = [];
var mirror_cache_enabled_ = true;
function ToggleMirrorCache(value) {
mirror_cache_enabled_ = value;
next_handle_ = 0;
mirror_cache_ = [];
}
/**
......@@ -44,7 +52,7 @@ function MakeMirror(value, opt_transient) {
var mirror;
// Look for non transient mirrors in the mirror cache.
if (!opt_transient) {
if (!opt_transient && mirror_cache_enabled_) {
for (id in mirror_cache_) {
mirror = mirror_cache_[id];
if (mirror.value() === value) {
......@@ -88,7 +96,7 @@ function MakeMirror(value, opt_transient) {
mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient);
}
mirror_cache_[mirror.handle()] = mirror;
if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror;
return mirror;
}
......@@ -101,6 +109,7 @@ function MakeMirror(value, opt_transient) {
* undefined if no mirror with the requested handle was found
*/
function LookupMirror(handle) {
if (!mirror_cache_enabled_) throw new Error("Mirror cache is disabled");
return mirror_cache_[handle];
}
......@@ -424,7 +433,7 @@ Mirror.prototype.isScope = function() {
* Allocate a handle id for this object.
*/
Mirror.prototype.allocateHandle_ = function() {
this.handle_ = next_handle_++;
if (mirror_cache_enabled_) this.handle_ = next_handle_++;
};
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Flags: --expose-debug-as debug
var handle1 = debug.MakeMirror(123).handle();
assertEquals("number", debug.LookupMirror(handle1).type());
debug.ToggleMirrorCache(false);
var handle2 = debug.MakeMirror(123).handle();
assertEquals(undefined, handle2);
assertThrows(function() { debug.LookupMirror(handle2) });
debug.ToggleMirrorCache(true);
var handle3 = debug.MakeMirror(123).handle();
assertEquals("number", debug.LookupMirror(handle3).type());
......@@ -51,7 +51,7 @@ EXPECTED_FUNCTION_COUNT = 358
EXPECTED_FUZZABLE_COUNT = 325
EXPECTED_CCTEST_COUNT = 6
EXPECTED_UNKNOWN_COUNT = 5
EXPECTED_BUILTINS_COUNT = 797
EXPECTED_BUILTINS_COUNT = 798
# Don't call these at all.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment