Commit 1f2c5052 authored by yangguo's avatar yangguo Committed by Commit bot

Revert of Debugger: use a Map to cache mirrors. (patchset #1 id:1 of...

Revert of Debugger: use a Map to cache mirrors. (patchset #1 id:1 of https://codereview.chromium.org/1287243002/ )

Reason for revert:
Several nosnap and custom snapshot failures.

Original issue's description:
> Debugger: use a Map to cache mirrors.
>
> This makes mirror cache lookup O(1) instead of O(n).
> The downside is that the lookup via handle is O(n). This
> is fine because handles are only used in the JSON api,
> which is not used by Chrome and on death row.
>
> Committed: https://crrev.com/890b1dfca84d9dfecdcfc56517ef541076c6eb1d
> Cr-Commit-Position: refs/heads/master@{#30150}

TBR=bmeurer@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

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

Cr-Commit-Position: refs/heads/master@{#30153}
parent 40c11d06
...@@ -1802,9 +1802,6 @@ Data* SetBuiltinTypedArray(Isolate* isolate, Handle<JSBuiltinsObject> builtins, ...@@ -1802,9 +1802,6 @@ Data* SetBuiltinTypedArray(Isolate* isolate, Handle<JSBuiltinsObject> builtins,
void Genesis::InitializeBuiltinTypedArrays() { void Genesis::InitializeBuiltinTypedArrays() {
// The serializer cannot serialize typed arrays. Reset those typed arrays
// for each new context.
DCHECK(!isolate()->serializer_enabled());
Handle<JSBuiltinsObject> builtins(native_context()->builtins()); Handle<JSBuiltinsObject> builtins(native_context()->builtins());
{ // Initially seed the per-context random number generator using the { // Initially seed the per-context random number generator using the
// per-isolate random number generator. // per-isolate random number generator.
...@@ -3233,21 +3230,25 @@ Genesis::Genesis(Isolate* isolate, ...@@ -3233,21 +3230,25 @@ Genesis::Genesis(Isolate* isolate,
// Install experimental and extra natives. Do not include them into the // Install experimental and extra natives. Do not include them into the
// snapshot as we should be able to turn them off at runtime. Re-installing // snapshot as we should be able to turn them off at runtime. Re-installing
// them after they have already been deserialized would also fail. // them after they have already been deserialized would also fail.
if (!isolate->serializer_enabled() && context_type != THIN_CONTEXT) { if (context_type == FULL_CONTEXT) {
InitializeExperimentalGlobal(); if (!isolate->serializer_enabled()) {
InitializeBuiltinTypedArrays(); InitializeExperimentalGlobal();
if (context_type == FULL_CONTEXT) {
if (!InstallExperimentalNatives()) return; if (!InstallExperimentalNatives()) return;
if (!InstallExtraNatives()) return; if (!InstallExtraNatives()) return;
// By now the utils object is useless and can be removed. // By now the utils object is useless and can be removed.
native_context()->set_natives_utils_object( native_context()->set_natives_utils_object(
isolate->heap()->undefined_value()); isolate->heap()->undefined_value());
InitializeBuiltinTypedArrays();
} else {
DCHECK_EQ(DEBUG_CONTEXT, context_type);
if (!InstallDebuggerNatives()) return;
} }
// The serializer cannot serialize typed arrays. Reset those typed arrays
// for each new context.
InitializeBuiltinTypedArrays();
} else if (context_type == DEBUG_CONTEXT) {
DCHECK(!isolate->serializer_enabled());
InitializeExperimentalGlobal();
if (!InstallDebuggerNatives()) return;
} }
result_ = native_context(); result_ = native_context();
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
var GlobalArray = global.Array; var GlobalArray = global.Array;
var IsNaN = global.isNaN; var IsNaN = global.isNaN;
var JSONStringify = global.JSON.stringify; var JSONStringify = global.JSON.stringify;
var GlobalMap = global.Map;
var MathMin = global.Math.min; var MathMin = global.Math.min;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -74,12 +73,12 @@ var next_handle_ = 0; ...@@ -74,12 +73,12 @@ var next_handle_ = 0;
var next_transient_handle_ = -1; var next_transient_handle_ = -1;
// Mirror cache. // Mirror cache.
var mirror_cache_ = new GlobalMap(); var mirror_cache_ = [];
var mirror_cache_enabled_ = true; var mirror_cache_enabled_ = true;
function MirrorCacheIsEmpty() { function MirrorCacheIsEmpty() {
return mirror_cache_.size === 0; return next_handle_ == 0 && mirror_cache_.length == 0;
} }
...@@ -91,7 +90,7 @@ function ToggleMirrorCache(value) { ...@@ -91,7 +90,7 @@ function ToggleMirrorCache(value) {
function ClearMirrorCache(value) { function ClearMirrorCache(value) {
next_handle_ = 0; next_handle_ = 0;
mirror_cache_.clear(); mirror_cache_ = [];
} }
...@@ -121,7 +120,17 @@ function MakeMirror(value, opt_transient) { ...@@ -121,7 +120,17 @@ function MakeMirror(value, opt_transient) {
// Look for non transient mirrors in the mirror cache. // Look for non transient mirrors in the mirror cache.
if (!opt_transient && mirror_cache_enabled_) { if (!opt_transient && mirror_cache_enabled_) {
if (mirror_cache_.has(value)) return mirror_cache_.get(value); for (var id in mirror_cache_) {
mirror = mirror_cache_[id];
if (mirror.value() === value) {
return mirror;
}
// Special check for NaN as NaN == NaN is false.
if (mirror.isNumber() && IsNaN(mirror.value()) &&
typeof value == 'number' && IsNaN(value)) {
return mirror;
}
}
} }
if (IS_UNDEFINED(value)) { if (IS_UNDEFINED(value)) {
...@@ -162,7 +171,7 @@ function MakeMirror(value, opt_transient) { ...@@ -162,7 +171,7 @@ function MakeMirror(value, opt_transient) {
mirror = new ObjectMirror(value, MirrorType.OBJECT_TYPE, opt_transient); mirror = new ObjectMirror(value, MirrorType.OBJECT_TYPE, opt_transient);
} }
if (mirror_cache_enabled_) mirror_cache_.set(value, mirror); if (mirror_cache_enabled_) mirror_cache_[mirror.handle()] = mirror;
return mirror; return mirror;
} }
...@@ -178,10 +187,7 @@ function LookupMirror(handle) { ...@@ -178,10 +187,7 @@ function LookupMirror(handle) {
if (!mirror_cache_enabled_) { if (!mirror_cache_enabled_) {
throw MakeError(kDebugger, "Mirror cache is disabled"); throw MakeError(kDebugger, "Mirror cache is disabled");
} }
for (var value of mirror_cache_.values()) { return mirror_cache_[handle];
if (value.handle() == handle) return value;
}
return UNDEFINED;
} }
......
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