From 62714a58cd11a4c26438a9e7675b385179b9fee6 Mon Sep 17 00:00:00 2001 From: "verwaest@chromium.org" Date: Tue, 5 Aug 2014 09:32:55 +0000 Subject: [PATCH] Inline LookupInHolder and NextHolder BUG= R=jkummerow@chromium.org Review URL: https://codereview.chromium.org/437513002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@22853 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- BUILD.gn | 1 + src/lookup-inl.h | 68 +++++++++++++++++++++++++++++++++++++++++++++ src/lookup.cc | 84 ++++++++++++++++---------------------------------------- src/lookup.h | 4 +-- tools/gyp/v8.gyp | 1 + 5 files changed, 96 insertions(+), 62 deletions(-) create mode 100644 src/lookup-inl.h diff --git a/BUILD.gn b/BUILD.gn index b1be576..b5830bf 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -747,6 +747,7 @@ source_set("v8_base") { "src/log-utils.h", "src/log.cc", "src/log.h", + "src/lookup-inl.h", "src/lookup.cc", "src/lookup.h", "src/macro-assembler.h", diff --git a/src/lookup-inl.h b/src/lookup-inl.h new file mode 100644 index 0000000..ccd1fbb --- /dev/null +++ b/src/lookup-inl.h @@ -0,0 +1,68 @@ +// Copyright 2014 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8_LOOKUP_INL_H_ +#define V8_LOOKUP_INL_H_ + +#include "src/lookup.h" + +namespace v8 { +namespace internal { + + +JSReceiver* LookupIterator::NextHolder(Map* map) { + DisallowHeapAllocation no_gc; + if (map->prototype()->IsNull()) return NULL; + + JSReceiver* next = JSReceiver::cast(map->prototype()); + DCHECK(!next->map()->IsGlobalObjectMap() || + next->map()->is_hidden_prototype()); + + if (!check_derived() && + !(check_hidden() && next->map()->is_hidden_prototype())) { + return NULL; + } + + return next; +} + + +LookupIterator::State LookupIterator::LookupInHolder(Map* map) { + DisallowHeapAllocation no_gc; + switch (state_) { + case NOT_FOUND: + if (map->IsJSProxyMap()) { + return JSPROXY; + } + if (check_access_check() && map->is_access_check_needed()) { + return ACCESS_CHECK; + } + // Fall through. + case ACCESS_CHECK: + if (check_interceptor() && map->has_named_interceptor()) { + return INTERCEPTOR; + } + // Fall through. + case INTERCEPTOR: + if (map->is_dictionary_map()) { + property_encoding_ = DICTIONARY; + } else { + DescriptorArray* descriptors = map->instance_descriptors(); + number_ = descriptors->SearchWithCache(*name_, map); + if (number_ == DescriptorArray::kNotFound) return NOT_FOUND; + property_encoding_ = DESCRIPTOR; + } + return PROPERTY; + case PROPERTY: + return NOT_FOUND; + case JSPROXY: + UNREACHABLE(); + } + UNREACHABLE(); + return state_; +} +} +} // namespace v8::internal + +#endif // V8_LOOKUP_INL_H_ diff --git a/src/lookup.cc b/src/lookup.cc index 36d11de..c51b057 100644 --- a/src/lookup.cc +++ b/src/lookup.cc @@ -6,16 +6,36 @@ #include "src/bootstrapper.h" #include "src/lookup.h" +#include "src/lookup-inl.h" namespace v8 { namespace internal { void LookupIterator::Next() { + DisallowHeapAllocation no_gc; has_property_ = false; - do { - state_ = LookupInHolder(); - } while (!IsFound() && NextHolder()); + + JSReceiver* holder = NULL; + Map* map = *holder_map_; + + // Perform lookup on current holder. + state_ = LookupInHolder(map); + + // Continue lookup if lookup on current holder failed. + while (!IsFound()) { + JSReceiver* maybe_holder = NextHolder(map); + if (maybe_holder == NULL) break; + holder = maybe_holder; + map = holder->map(); + state_ = LookupInHolder(map); + } + + // Either was found in the receiver, or the receiver has no prototype. + if (holder == NULL) return; + + maybe_holder_ = handle(holder); + holder_map_ = handle(map); } @@ -36,62 +56,6 @@ Handle LookupIterator::GetReceiverMap() const { } -bool LookupIterator::NextHolder() { - if (holder_map_->prototype()->IsNull()) return false; - - Handle next(JSReceiver::cast(holder_map_->prototype())); - - if (!check_derived() && - !(check_hidden() && - // TODO(verwaest): Check if this is actually necessary currently. If it - // is, this should be handled by setting is_hidden_prototype on the - // global object behind the proxy. - (holder_map_->IsJSGlobalProxyMap() || - next->map()->is_hidden_prototype()))) { - return false; - } - - holder_map_ = handle(next->map()); - maybe_holder_ = next; - return true; -} - - -LookupIterator::State LookupIterator::LookupInHolder() { - switch (state_) { - case NOT_FOUND: - if (holder_map_->IsJSProxyMap()) { - return JSPROXY; - } - if (check_access_check() && holder_map_->is_access_check_needed()) { - return ACCESS_CHECK; - } - // Fall through. - case ACCESS_CHECK: - if (check_interceptor() && holder_map_->has_named_interceptor()) { - return INTERCEPTOR; - } - // Fall through. - case INTERCEPTOR: - if (holder_map_->is_dictionary_map()) { - property_encoding_ = DICTIONARY; - } else { - DescriptorArray* descriptors = holder_map_->instance_descriptors(); - number_ = descriptors->SearchWithCache(*name_, *holder_map_); - if (number_ == DescriptorArray::kNotFound) return NOT_FOUND; - property_encoding_ = DESCRIPTOR; - } - return PROPERTY; - case PROPERTY: - return NOT_FOUND; - case JSPROXY: - UNREACHABLE(); - } - UNREACHABLE(); - return state_; -} - - bool LookupIterator::IsBootstrapping() const { return isolate_->bootstrapper()->IsActive(); } @@ -190,7 +154,7 @@ void LookupIterator::TransitionToDataProperty( // Reload the information. state_ = NOT_FOUND; configuration_ = CHECK_OWN_REAL; - state_ = LookupInHolder(); + state_ = LookupInHolder(*holder_map_); DCHECK(IsFound()); HasProperty(); } diff --git a/src/lookup.h b/src/lookup.h index 8de9724..3167cd8 100644 --- a/src/lookup.h +++ b/src/lookup.h @@ -150,8 +150,8 @@ class LookupIterator V8_FINAL BASE_EMBEDDED { private: Handle GetReceiverMap() const; - MUST_USE_RESULT bool NextHolder(); - State LookupInHolder(); + MUST_USE_RESULT inline JSReceiver* NextHolder(Map* map); + inline State LookupInHolder(Map* map); Handle FetchValue() const; bool IsBootstrapping() const; diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 1af0d17..23cf25c 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -649,6 +649,7 @@ '../../src/log-utils.h', '../../src/log.cc', '../../src/log.h', + '../../src/lookup-inl.h', '../../src/lookup.cc', '../../src/lookup.h', '../../src/macro-assembler.h', -- 2.7.4