diff --git a/src/mips/builtins-mips.cc b/src/mips/builtins-mips.cc index 3f4aab3d74..f875c9609d 100644 --- a/src/mips/builtins-mips.cc +++ b/src/mips/builtins-mips.cc @@ -116,9 +116,7 @@ static void AllocateEmptyJSArray(MacroAssembler* masm, Label* gc_required) { const int initial_capacity = JSArray::kPreallocatedArrayElements; STATIC_ASSERT(initial_capacity >= 0); - // Load the initial map from the array function. - __ lw(scratch1, FieldMemOperand(array_function, - JSFunction::kPrototypeOrInitialMapOffset)); + __ LoadGlobalInitialConstructedArrayMap(array_function, scratch2, scratch1); // Allocate the JSArray object together with space for a fixed array with the // requested elements. @@ -214,9 +212,8 @@ static void AllocateJSArray(MacroAssembler* masm, bool fill_with_hole, Label* gc_required) { // Load the initial map from the array function. - __ lw(elements_array_storage, - FieldMemOperand(array_function, - JSFunction::kPrototypeOrInitialMapOffset)); + __ LoadGlobalInitialConstructedArrayMap(array_function, scratch2, + elements_array_storage); if (FLAG_debug_code) { // Assert that array size is not zero. __ Assert( diff --git a/src/mips/macro-assembler-mips.cc b/src/mips/macro-assembler-mips.cc index 941c7fe4ea..9eb1fc7639 100644 --- a/src/mips/macro-assembler-mips.cc +++ b/src/mips/macro-assembler-mips.cc @@ -4279,6 +4279,31 @@ void MacroAssembler::LoadContext(Register dst, int context_chain_length) { } +void MacroAssembler::LoadGlobalInitialConstructedArrayMap( + Register function_in, Register scratch, Register map_out) { + ASSERT(!function_in.is(map_out)); + Label done; + lw(map_out, FieldMemOperand(function_in, + JSFunction::kPrototypeOrInitialMapOffset)); + if (!FLAG_smi_only_arrays) { + // Load the global or builtins object from the current context. + lw(scratch, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); + lw(scratch, FieldMemOperand(scratch, GlobalObject::kGlobalContextOffset)); + + // Check that the function's map is same as the cached map. + lw(at, MemOperand( + scratch, Context::SlotOffset(Context::SMI_JS_ARRAY_MAP_INDEX))); + Branch(&done, ne, map_out, Operand(at)); + + // Use the cached transitioned map. + lw(map_out, + MemOperand(scratch, + Context::SlotOffset(Context::OBJECT_JS_ARRAY_MAP_INDEX))); + } + bind(&done); +} + + void MacroAssembler::LoadGlobalFunction(int index, Register function) { // Load the global or builtins object from the current context. lw(function, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); diff --git a/src/mips/macro-assembler-mips.h b/src/mips/macro-assembler-mips.h index b976f6ee0c..7798c8205e 100644 --- a/src/mips/macro-assembler-mips.h +++ b/src/mips/macro-assembler-mips.h @@ -772,6 +772,11 @@ class MacroAssembler: public Assembler { void LoadContext(Register dst, int context_chain_length); + // Load the initial map for new Arrays of a given type. + void LoadGlobalInitialConstructedArrayMap(Register function_in, + Register scratch, + Register map_out); + void LoadGlobalFunction(int index, Register function); // Load the initial map from the global function. The registers