Commit f24b6f96 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[cleanup] Isolate::get_initial_js_array_map => Context:GetInitialJSArrayMap

- add some more const to Context getters

Change-Id: Ia7560b33cae71a6015515e4337b464648e03a6f2
Reviewed-on: https://chromium-review.googlesource.com/575993Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46799}
parent a45048e2
...@@ -683,10 +683,9 @@ Reduction JSCallReducer::ReduceArrayMap(Handle<JSFunction> function, ...@@ -683,10 +683,9 @@ Reduction JSCallReducer::ReduceArrayMap(Handle<JSFunction> function,
} }
// We want the input to be a generic Array. // We want the input to be a generic Array.
const int map_index = Context::ArrayMapIndex(kind);
Handle<JSFunction> handle_constructor( Handle<JSFunction> handle_constructor(
JSFunction::cast( JSFunction::cast(
Map::cast(native_context()->get(map_index))->GetConstructor()), native_context()->GetInitialJSArrayMap(kind)->GetConstructor()),
isolate()); isolate());
Node* array_constructor = jsgraph()->HeapConstant(handle_constructor); Node* array_constructor = jsgraph()->HeapConstant(handle_constructor);
if (receiver_map->prototype() != if (receiver_map->prototype() !=
......
...@@ -643,9 +643,8 @@ Reduction JSCreateLowering::ReduceNewArray(Node* node, Node* length, ...@@ -643,9 +643,8 @@ Reduction JSCreateLowering::ReduceNewArray(Node* node, Node* length,
dependencies()->AssumeTransitionStable(site); dependencies()->AssumeTransitionStable(site);
// Retrieve the initial map for the array. // Retrieve the initial map for the array.
int const array_map_index = Context::ArrayMapIndex(elements_kind);
Node* js_array_map = jsgraph()->HeapConstant( Node* js_array_map = jsgraph()->HeapConstant(
handle(Map::cast(native_context()->get(array_map_index)), isolate())); handle(native_context()->GetInitialJSArrayMap(elements_kind), isolate()));
// Setup elements and properties. // Setup elements and properties.
Node* elements; Node* elements;
...@@ -707,9 +706,8 @@ Reduction JSCreateLowering::ReduceNewArray(Node* node, ...@@ -707,9 +706,8 @@ Reduction JSCreateLowering::ReduceNewArray(Node* node,
} }
// Retrieve the initial map for the array. // Retrieve the initial map for the array.
int const array_map_index = Context::ArrayMapIndex(elements_kind);
Node* js_array_map = jsgraph()->HeapConstant( Node* js_array_map = jsgraph()->HeapConstant(
handle(Map::cast(native_context()->get(array_map_index)), isolate())); handle(native_context()->GetInitialJSArrayMap(elements_kind), isolate()));
// Setup elements, properties and length. // Setup elements, properties and length.
Node* elements = effect = Node* elements = effect =
......
...@@ -67,8 +67,7 @@ void Context::set_extension(HeapObject* object) { ...@@ -67,8 +67,7 @@ void Context::set_extension(HeapObject* object) {
set(EXTENSION_INDEX, object); set(EXTENSION_INDEX, object);
} }
Context* Context::native_context() const {
Context* Context::native_context() {
Object* result = get(NATIVE_CONTEXT_INDEX); Object* result = get(NATIVE_CONTEXT_INDEX);
DCHECK(IsBootstrappingOrNativeContext(this->GetIsolate(), result)); DCHECK(IsBootstrappingOrNativeContext(this->GetIsolate(), result));
return reinterpret_cast<Context*>(result); return reinterpret_cast<Context*>(result);
...@@ -79,72 +78,66 @@ void Context::set_native_context(Context* context) { ...@@ -79,72 +78,66 @@ void Context::set_native_context(Context* context) {
set(NATIVE_CONTEXT_INDEX, context); set(NATIVE_CONTEXT_INDEX, context);
} }
bool Context::IsNativeContext() const {
bool Context::IsNativeContext() {
Map* map = this->map(); Map* map = this->map();
return map == map->GetHeap()->native_context_map(); return map == map->GetHeap()->native_context_map();
} }
bool Context::IsFunctionContext() const {
bool Context::IsFunctionContext() {
Map* map = this->map(); Map* map = this->map();
return map == map->GetHeap()->function_context_map(); return map == map->GetHeap()->function_context_map();
} }
bool Context::IsCatchContext() const {
bool Context::IsCatchContext() {
Map* map = this->map(); Map* map = this->map();
return map == map->GetHeap()->catch_context_map(); return map == map->GetHeap()->catch_context_map();
} }
bool Context::IsWithContext() const {
bool Context::IsWithContext() {
Map* map = this->map(); Map* map = this->map();
return map == map->GetHeap()->with_context_map(); return map == map->GetHeap()->with_context_map();
} }
bool Context::IsDebugEvaluateContext() { bool Context::IsDebugEvaluateContext() const {
Map* map = this->map(); Map* map = this->map();
return map == map->GetHeap()->debug_evaluate_context_map(); return map == map->GetHeap()->debug_evaluate_context_map();
} }
bool Context::IsBlockContext() { bool Context::IsBlockContext() const {
Map* map = this->map(); Map* map = this->map();
return map == map->GetHeap()->block_context_map(); return map == map->GetHeap()->block_context_map();
} }
bool Context::IsModuleContext() const {
bool Context::IsModuleContext() {
Map* map = this->map(); Map* map = this->map();
return map == map->GetHeap()->module_context_map(); return map == map->GetHeap()->module_context_map();
} }
bool Context::IsEvalContext() { bool Context::IsEvalContext() const {
Map* map = this->map(); Map* map = this->map();
return map == map->GetHeap()->eval_context_map(); return map == map->GetHeap()->eval_context_map();
} }
bool Context::IsScriptContext() { bool Context::IsScriptContext() const {
Map* map = this->map(); Map* map = this->map();
return map == map->GetHeap()->script_context_map(); return map == map->GetHeap()->script_context_map();
} }
bool Context::HasSameSecurityTokenAs(Context* that) { bool Context::HasSameSecurityTokenAs(Context* that) const {
return this->native_context()->security_token() == return this->native_context()->security_token() ==
that->native_context()->security_token(); that->native_context()->security_token();
} }
#define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \
void Context::set_##name(type* value) { \ void Context::set_##name(type* value) { \
DCHECK(IsNativeContext()); \ DCHECK(IsNativeContext()); \
set(index, value); \ set(index, value); \
} \ } \
bool Context::is_##name(type* value) { \ bool Context::is_##name(type* value) const { \
DCHECK(IsNativeContext()); \ DCHECK(IsNativeContext()); \
return type::cast(get(index)) == value; \ return type::cast(get(index)) == value; \
} \ } \
type* Context::name() { \ type* Context::name() const { \
DCHECK(IsNativeContext()); \ DCHECK(IsNativeContext()); \
return type::cast(get(index)); \ return type::cast(get(index)); \
} }
...@@ -218,6 +211,15 @@ int Context::FunctionMapIndex(LanguageMode language_mode, FunctionKind kind, ...@@ -218,6 +211,15 @@ int Context::FunctionMapIndex(LanguageMode language_mode, FunctionKind kind,
#undef CHECK_FOLLOWS2 #undef CHECK_FOLLOWS2
#undef CHECK_FOLLOWS4 #undef CHECK_FOLLOWS4
Map* Context::GetInitialJSArrayMap(ElementsKind kind) const {
DCHECK(IsNativeContext());
if (!IsFastElementsKind(kind)) return nullptr;
DisallowHeapAllocation no_gc;
Object* const initial_js_array_map = get(Context::ArrayMapIndex(kind));
DCHECK(!initial_js_array_map->IsUndefined(GetIsolate()));
return Map::cast(initial_js_array_map);
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -601,23 +601,23 @@ class Context: public FixedArray { ...@@ -601,23 +601,23 @@ class Context: public FixedArray {
Context* script_context(); Context* script_context();
// Compute the native context. // Compute the native context.
inline Context* native_context(); inline Context* native_context() const;
inline void set_native_context(Context* context); inline void set_native_context(Context* context);
// Predicates for context types. IsNativeContext is also defined on Object // Predicates for context types. IsNativeContext is also defined on Object
// because we frequently have to know if arbitrary objects are natives // because we frequently have to know if arbitrary objects are natives
// contexts. // contexts.
inline bool IsNativeContext(); inline bool IsNativeContext() const;
inline bool IsFunctionContext(); inline bool IsFunctionContext() const;
inline bool IsCatchContext(); inline bool IsCatchContext() const;
inline bool IsWithContext(); inline bool IsWithContext() const;
inline bool IsDebugEvaluateContext(); inline bool IsDebugEvaluateContext() const;
inline bool IsBlockContext(); inline bool IsBlockContext() const;
inline bool IsModuleContext(); inline bool IsModuleContext() const;
inline bool IsEvalContext(); inline bool IsEvalContext() const;
inline bool IsScriptContext(); inline bool IsScriptContext() const;
inline bool HasSameSecurityTokenAs(Context* that); inline bool HasSameSecurityTokenAs(Context* that) const;
// A native context holds a list of all functions with optimized code. // A native context holds a list of all functions with optimized code.
void AddOptimizedFunction(JSFunction* function); void AddOptimizedFunction(JSFunction* function);
...@@ -641,8 +641,8 @@ class Context: public FixedArray { ...@@ -641,8 +641,8 @@ class Context: public FixedArray {
#define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \ #define NATIVE_CONTEXT_FIELD_ACCESSORS(index, type, name) \
inline void set_##name(type* value); \ inline void set_##name(type* value); \
inline bool is_##name(type* value); \ inline bool is_##name(type* value) const; \
inline type* name(); inline type* name() const;
NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS) NATIVE_CONTEXT_FIELDS(NATIVE_CONTEXT_FIELD_ACCESSORS)
#undef NATIVE_CONTEXT_FIELD_ACCESSORS #undef NATIVE_CONTEXT_FIELD_ACCESSORS
...@@ -686,6 +686,8 @@ class Context: public FixedArray { ...@@ -686,6 +686,8 @@ class Context: public FixedArray {
return elements_kind + FIRST_JS_ARRAY_MAP_SLOT; return elements_kind + FIRST_JS_ARRAY_MAP_SLOT;
} }
inline Map* GetInitialJSArrayMap(ElementsKind kind) const;
static const int kSize = kHeaderSize + NATIVE_CONTEXT_SLOTS * kPointerSize; static const int kSize = kHeaderSize + NATIVE_CONTEXT_SLOTS * kPointerSize;
static const int kNotFound = -1; static const int kNotFound = -1;
......
...@@ -1923,9 +1923,9 @@ Handle<JSObject> Factory::NewSlowJSObjectFromMap(Handle<Map> map, int capacity, ...@@ -1923,9 +1923,9 @@ Handle<JSObject> Factory::NewSlowJSObjectFromMap(Handle<Map> map, int capacity,
Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind, Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
PretenureFlag pretenure) { PretenureFlag pretenure) {
Map* map = isolate()->get_initial_js_array_map(elements_kind); Context* native_context = isolate()->raw_native_context();
Map* map = native_context->GetInitialJSArrayMap(elements_kind);
if (map == nullptr) { if (map == nullptr) {
Context* native_context = isolate()->context()->native_context();
JSFunction* array_function = native_context->array_function(); JSFunction* array_function = native_context->array_function();
map = array_function->initial_map(); map = array_function->initial_map();
} }
......
...@@ -1416,7 +1416,8 @@ Handle<Object> KeyedLoadIC::LoadElementHandler(Handle<Map> receiver_map) { ...@@ -1416,7 +1416,8 @@ Handle<Object> KeyedLoadIC::LoadElementHandler(Handle<Map> receiver_map) {
// TODO(jkummerow): Use IsHoleyOrDictionaryElementsKind(elements_kind). // TODO(jkummerow): Use IsHoleyOrDictionaryElementsKind(elements_kind).
bool convert_hole_to_undefined = bool convert_hole_to_undefined =
is_js_array && elements_kind == HOLEY_ELEMENTS && is_js_array && elements_kind == HOLEY_ELEMENTS &&
*receiver_map == isolate()->get_initial_js_array_map(elements_kind); *receiver_map ==
isolate()->raw_native_context()->GetInitialJSArrayMap(elements_kind);
TRACE_HANDLER_STATS(isolate(), KeyedLoadIC_LoadElementDH); TRACE_HANDLER_STATS(isolate(), KeyedLoadIC_LoadElementDH);
return LoadHandler::LoadElement(isolate(), elements_kind, return LoadHandler::LoadElement(isolate(), elements_kind,
convert_hole_to_undefined, is_js_array); convert_hole_to_undefined, is_js_array);
......
...@@ -139,8 +139,7 @@ void KeyedStoreGenericAssembler::TryRewriteElements( ...@@ -139,8 +139,7 @@ void KeyedStoreGenericAssembler::TryRewriteElements(
VARIABLE(var_target_map, MachineRepresentation::kTagged); VARIABLE(var_target_map, MachineRepresentation::kTagged);
// Check if the receiver has the default |from_kind| map. // Check if the receiver has the default |from_kind| map.
{ {
Node* packed_map = Node* packed_map = LoadJSArrayElementsMap(from_kind, native_context);
LoadContextElement(native_context, Context::ArrayMapIndex(from_kind));
GotoIf(WordNotEqual(receiver_map, packed_map), &check_holey_map); GotoIf(WordNotEqual(receiver_map, packed_map), &check_holey_map);
var_target_map.Bind( var_target_map.Bind(
LoadContextElement(native_context, Context::ArrayMapIndex(to_kind))); LoadContextElement(native_context, Context::ArrayMapIndex(to_kind)));
...@@ -174,8 +173,7 @@ void KeyedStoreGenericAssembler::TryChangeToHoleyMapHelper( ...@@ -174,8 +173,7 @@ void KeyedStoreGenericAssembler::TryChangeToHoleyMapHelper(
Node* receiver, Node* receiver_map, Node* native_context, Node* receiver, Node* receiver_map, Node* native_context,
ElementsKind packed_kind, ElementsKind holey_kind, Label* done, ElementsKind packed_kind, ElementsKind holey_kind, Label* done,
Label* map_mismatch, Label* bailout) { Label* map_mismatch, Label* bailout) {
Node* packed_map = Node* packed_map = LoadJSArrayElementsMap(packed_kind, native_context);
LoadContextElement(native_context, Context::ArrayMapIndex(packed_kind));
GotoIf(WordNotEqual(receiver_map, packed_map), map_mismatch); GotoIf(WordNotEqual(receiver_map, packed_map), map_mismatch);
if (AllocationSite::ShouldTrack(packed_kind, holey_kind)) { if (AllocationSite::ShouldTrack(packed_kind, holey_kind)) {
TrapAllocationMemento(receiver, bailout); TrapAllocationMemento(receiver, bailout);
......
...@@ -2991,18 +2991,6 @@ CodeTracer* Isolate::GetCodeTracer() { ...@@ -2991,18 +2991,6 @@ CodeTracer* Isolate::GetCodeTracer() {
return code_tracer(); return code_tracer();
} }
Map* Isolate::get_initial_js_array_map(ElementsKind kind) {
if (IsFastElementsKind(kind)) {
DisallowHeapAllocation no_gc;
Object* const initial_js_array_map =
context()->native_context()->get(Context::ArrayMapIndex(kind));
if (!initial_js_array_map->IsUndefined(this)) {
return Map::cast(initial_js_array_map);
}
}
return nullptr;
}
bool Isolate::use_optimizer() { bool Isolate::use_optimizer() {
return FLAG_opt && !serializer_enabled_ && return FLAG_opt && !serializer_enabled_ &&
CpuFeatures::SupportsCrankshaft() && CpuFeatures::SupportsCrankshaft() &&
...@@ -3054,7 +3042,7 @@ bool Isolate::IsFastArrayConstructorPrototypeChainIntact() { ...@@ -3054,7 +3042,7 @@ bool Isolate::IsFastArrayConstructorPrototypeChainIntact() {
#ifdef DEBUG #ifdef DEBUG
Map* root_array_map = Map* root_array_map =
get_initial_js_array_map(GetInitialFastElementsKind()); raw_native_context()->GetInitialJSArrayMap(GetInitialFastElementsKind());
Context* native_context = context()->native_context(); Context* native_context = context()->native_context();
JSObject* initial_array_proto = JSObject::cast( JSObject* initial_array_proto = JSObject::cast(
native_context->get(Context::INITIAL_ARRAY_PROTOTYPE_INDEX)); native_context->get(Context::INITIAL_ARRAY_PROTOTYPE_INDEX));
...@@ -3110,7 +3098,8 @@ bool Isolate::IsIsConcatSpreadableLookupChainIntact() { ...@@ -3110,7 +3098,8 @@ bool Isolate::IsIsConcatSpreadableLookupChainIntact() {
bool is_is_concat_spreadable_set = bool is_is_concat_spreadable_set =
Smi::ToInt(is_concat_spreadable_cell->value()) == kProtectorInvalid; Smi::ToInt(is_concat_spreadable_cell->value()) == kProtectorInvalid;
#ifdef DEBUG #ifdef DEBUG
Map* root_array_map = get_initial_js_array_map(GetInitialFastElementsKind()); Map* root_array_map =
raw_native_context()->GetInitialJSArrayMap(GetInitialFastElementsKind());
if (root_array_map == NULL) { if (root_array_map == NULL) {
// Ignore the value of is_concat_spreadable during bootstrap. // Ignore the value of is_concat_spreadable during bootstrap.
return !is_is_concat_spreadable_set; return !is_is_concat_spreadable_set;
......
...@@ -1047,8 +1047,6 @@ class Isolate { ...@@ -1047,8 +1047,6 @@ class Isolate {
date_cache_ = date_cache; date_cache_ = date_cache;
} }
Map* get_initial_js_array_map(ElementsKind kind);
static const int kProtectorValid = 1; static const int kProtectorValid = 1;
static const int kProtectorInvalid = 0; static const int kProtectorInvalid = 0;
......
...@@ -5331,7 +5331,7 @@ Handle<Map> Map::TransitionElementsTo(Handle<Map> map, ...@@ -5331,7 +5331,7 @@ Handle<Map> Map::TransitionElementsTo(Handle<Map> map,
} else if (IsFastElementsKind(from_kind) && IsFastElementsKind(to_kind)) { } else if (IsFastElementsKind(from_kind) && IsFastElementsKind(to_kind)) {
// Reuse map transitions for JSArrays. // Reuse map transitions for JSArrays.
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
if (native_context->get(Context::ArrayMapIndex(from_kind)) == *map) { if (native_context->GetInitialJSArrayMap(from_kind) == *map) {
Object* maybe_transitioned_map = Object* maybe_transitioned_map =
native_context->get(Context::ArrayMapIndex(to_kind)); native_context->get(Context::ArrayMapIndex(to_kind));
if (maybe_transitioned_map->IsMap()) { if (maybe_transitioned_map->IsMap()) {
......
...@@ -2543,7 +2543,8 @@ TEST(LoadJSArrayElementsMap) { ...@@ -2543,7 +2543,8 @@ TEST(LoadJSArrayElementsMap) {
Handle<Map> csa_result = Handle<Map> csa_result =
ft.CallChecked<Map>(handle(Smi::FromInt(kind), isolate)); ft.CallChecked<Map>(handle(Smi::FromInt(kind), isolate));
ElementsKind elements_kind = static_cast<ElementsKind>(kind); ElementsKind elements_kind = static_cast<ElementsKind>(kind);
Handle<Map> result(isolate->get_initial_js_array_map(elements_kind)); Handle<Map> result(
isolate->native_context()->GetInitialJSArrayMap(elements_kind));
CHECK_EQ(*csa_result, *result); CHECK_EQ(*csa_result, *result);
} }
} }
......
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