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