Move handler compilers to handler-compiler
BUG= R=yangguo@chromium.org Review URL: https://codereview.chromium.org/497083002 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23346 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
66dd869980
commit
2803733a3b
5
BUILD.gn
5
BUILD.gn
@ -718,6 +718,8 @@ source_set("v8_base") {
|
||||
"src/ic/access-compiler.h",
|
||||
"src/ic/call-optimization.cc",
|
||||
"src/ic/call-optimization.h",
|
||||
"src/ic/handler-compiler.cc",
|
||||
"src/ic/handler-compiler.h",
|
||||
"src/ic/ic-inl.h",
|
||||
"src/ic/ic.cc",
|
||||
"src/ic/ic.h",
|
||||
@ -934,6 +936,7 @@ source_set("v8_base") {
|
||||
"src/compiler/x64/instruction-selector-x64.cc",
|
||||
"src/compiler/x64/linkage-x64.cc",
|
||||
"src/ic/x64/access-compiler-x64.cc",
|
||||
"src/ic/x64/handler-compiler-x64.cc",
|
||||
"src/ic/x64/ic-x64.cc",
|
||||
"src/ic/x64/ic-compiler-x64.cc",
|
||||
"src/ic/x64/stub-cache-x64.cc",
|
||||
@ -973,6 +976,7 @@ source_set("v8_base") {
|
||||
"src/compiler/arm/instruction-selector-arm.cc",
|
||||
"src/compiler/arm/linkage-arm.cc",
|
||||
"src/ic/arm/access-compiler-arm.cc",
|
||||
"src/ic/arm/handler-compiler-arm.cc",
|
||||
"src/ic/arm/ic-arm.cc",
|
||||
"src/ic/arm/ic-compiler-arm.cc",
|
||||
"src/ic/arm/stub-cache-arm.cc",
|
||||
@ -1023,6 +1027,7 @@ source_set("v8_base") {
|
||||
"src/compiler/arm64/instruction-selector-arm64.cc",
|
||||
"src/compiler/arm64/linkage-arm64.cc",
|
||||
"src/ic/arm64/access-compiler-arm64.cc",
|
||||
"src/ic/arm64/handler-compiler-arm64.cc",
|
||||
"src/ic/arm64/ic-arm64.cc",
|
||||
"src/ic/arm64/ic-compiler-arm64.cc",
|
||||
"src/ic/arm64/stub-cache-arm64.cc",
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "src/bootstrapper.h"
|
||||
#include "src/code-stubs.h"
|
||||
#include "src/codegen.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/jsregexp.h"
|
||||
#include "src/regexp-macro-assembler.h"
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "src/bootstrapper.h"
|
||||
#include "src/code-stubs.h"
|
||||
#include "src/codegen.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/jsregexp.h"
|
||||
#include "src/regexp-macro-assembler.h"
|
||||
|
@ -13,8 +13,8 @@
|
||||
#include "src/gdb-jit.h"
|
||||
#include "src/heap/mark-compact.h"
|
||||
#include "src/heap-profiler.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
#include "src/ic/ic.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
#include "src/prototype.h"
|
||||
#include "src/vm-state-inl.h"
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "src/cpu-profiler.h"
|
||||
#include "src/factory.h"
|
||||
#include "src/gdb-jit.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
#include "src/macro-assembler.h"
|
||||
|
||||
namespace v8 {
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "src/bootstrapper.h"
|
||||
#include "src/code-stubs.h"
|
||||
#include "src/codegen.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/jsregexp.h"
|
||||
#include "src/regexp-macro-assembler.h"
|
||||
|
840
src/ic/arm/handler-compiler-arm.cc
Normal file
840
src/ic/arm/handler-compiler-arm.cc
Normal file
@ -0,0 +1,840 @@
|
||||
// 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.
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#if V8_TARGET_ARCH_ARM
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> getter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- r0 : receiver
|
||||
// -- r2 : name
|
||||
// -- lr : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
if (!getter.is_null()) {
|
||||
// Call the JavaScript getter with the receiver on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ ldr(receiver,
|
||||
FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ push(receiver);
|
||||
ParameterCount actual(0);
|
||||
ParameterCount expected(getter);
|
||||
__ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// Restore context register.
|
||||
__ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- lr : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
// Save value register, so we can restore it later.
|
||||
__ push(value());
|
||||
|
||||
if (!setter.is_null()) {
|
||||
// Call the JavaScript setter with receiver and value on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ ldr(receiver,
|
||||
FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver, value());
|
||||
ParameterCount actual(1);
|
||||
ParameterCount expected(setter);
|
||||
__ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// We have to return the passed value, not the return value of the setter.
|
||||
__ pop(r0);
|
||||
|
||||
// Restore context register.
|
||||
__ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
|
||||
MacroAssembler* masm, Label* miss_label, Register receiver,
|
||||
Handle<Name> name, Register scratch0, Register scratch1) {
|
||||
DCHECK(name->IsUniqueName());
|
||||
DCHECK(!receiver.is(scratch0));
|
||||
Counters* counters = masm->isolate()->counters();
|
||||
__ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
|
||||
__ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
|
||||
|
||||
Label done;
|
||||
|
||||
const int kInterceptorOrAccessCheckNeededMask =
|
||||
(1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
|
||||
|
||||
// Bail out if the receiver has a named interceptor or requires access checks.
|
||||
Register map = scratch1;
|
||||
__ ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
|
||||
__ ldrb(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
|
||||
__ tst(scratch0, Operand(kInterceptorOrAccessCheckNeededMask));
|
||||
__ b(ne, miss_label);
|
||||
|
||||
// Check that receiver is a JSObject.
|
||||
__ ldrb(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
|
||||
__ cmp(scratch0, Operand(FIRST_SPEC_OBJECT_TYPE));
|
||||
__ b(lt, miss_label);
|
||||
|
||||
// Load properties array.
|
||||
Register properties = scratch0;
|
||||
__ ldr(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
|
||||
// Check that the properties array is a dictionary.
|
||||
__ ldr(map, FieldMemOperand(properties, HeapObject::kMapOffset));
|
||||
Register tmp = properties;
|
||||
__ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
|
||||
__ cmp(map, tmp);
|
||||
__ b(ne, miss_label);
|
||||
|
||||
// Restore the temporarily used register.
|
||||
__ ldr(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
|
||||
|
||||
|
||||
NameDictionaryLookupStub::GenerateNegativeLookup(
|
||||
masm, miss_label, &done, receiver, properties, name, scratch1);
|
||||
__ bind(&done);
|
||||
__ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
|
||||
MacroAssembler* masm, int index, Register prototype, Label* miss) {
|
||||
Isolate* isolate = masm->isolate();
|
||||
// Get the global function with the given index.
|
||||
Handle<JSFunction> function(
|
||||
JSFunction::cast(isolate->native_context()->get(index)));
|
||||
|
||||
// Check we're still in the same context.
|
||||
Register scratch = prototype;
|
||||
const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
|
||||
__ ldr(scratch, MemOperand(cp, offset));
|
||||
__ ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
|
||||
__ ldr(scratch, MemOperand(scratch, Context::SlotOffset(index)));
|
||||
__ Move(ip, function);
|
||||
__ cmp(ip, scratch);
|
||||
__ b(ne, miss);
|
||||
|
||||
// Load its initial map. The global functions all have initial maps.
|
||||
__ Move(prototype, Handle<Map>(function->initial_map()));
|
||||
// Load the prototype from the initial map.
|
||||
__ ldr(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
|
||||
MacroAssembler* masm, Register receiver, Register scratch1,
|
||||
Register scratch2, Label* miss_label) {
|
||||
__ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
|
||||
__ mov(r0, scratch1);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
// Generate code to check that a global property cell is empty. Create
|
||||
// the property cell at compilation time if no cell exists for the
|
||||
// property.
|
||||
void PropertyHandlerCompiler::GenerateCheckPropertyCell(
|
||||
MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
|
||||
Register scratch, Label* miss) {
|
||||
Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
|
||||
DCHECK(cell->value()->IsTheHole());
|
||||
__ mov(scratch, Operand(cell));
|
||||
__ ldr(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
|
||||
__ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
||||
__ cmp(scratch, ip);
|
||||
__ b(ne, miss);
|
||||
}
|
||||
|
||||
|
||||
static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
|
||||
Register holder, Register name,
|
||||
Handle<JSObject> holder_obj) {
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
|
||||
__ push(name);
|
||||
Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
|
||||
DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
|
||||
Register scratch = name;
|
||||
__ mov(scratch, Operand(interceptor));
|
||||
__ push(scratch);
|
||||
__ push(receiver);
|
||||
__ push(holder);
|
||||
}
|
||||
|
||||
|
||||
static void CompileCallLoadPropertyWithInterceptor(
|
||||
MacroAssembler* masm, Register receiver, Register holder, Register name,
|
||||
Handle<JSObject> holder_obj, IC::UtilityId id) {
|
||||
PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
|
||||
__ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
|
||||
NamedLoadHandlerCompiler::kInterceptorArgsLength);
|
||||
}
|
||||
|
||||
|
||||
// Generate call to api function.
|
||||
void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
MacroAssembler* masm, const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver, Register scratch_in,
|
||||
bool is_store, int argc, Register* values) {
|
||||
DCHECK(!receiver.is(scratch_in));
|
||||
__ push(receiver);
|
||||
// Write the arguments to stack frame.
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Register arg = values[argc - 1 - i];
|
||||
DCHECK(!receiver.is(arg));
|
||||
DCHECK(!scratch_in.is(arg));
|
||||
__ push(arg);
|
||||
}
|
||||
DCHECK(optimization.is_simple_api_call());
|
||||
|
||||
// Abi for CallApiFunctionStub.
|
||||
Register callee = r0;
|
||||
Register call_data = r4;
|
||||
Register holder = r2;
|
||||
Register api_function_address = r1;
|
||||
|
||||
// Put holder in place.
|
||||
CallOptimization::HolderLookup holder_lookup;
|
||||
Handle<JSObject> api_holder =
|
||||
optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
|
||||
switch (holder_lookup) {
|
||||
case CallOptimization::kHolderIsReceiver:
|
||||
__ Move(holder, receiver);
|
||||
break;
|
||||
case CallOptimization::kHolderFound:
|
||||
__ Move(holder, api_holder);
|
||||
break;
|
||||
case CallOptimization::kHolderNotFound:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
Isolate* isolate = masm->isolate();
|
||||
Handle<JSFunction> function = optimization.constant_function();
|
||||
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
|
||||
Handle<Object> call_data_obj(api_call_info->data(), isolate);
|
||||
|
||||
// Put callee in place.
|
||||
__ Move(callee, function);
|
||||
|
||||
bool call_data_undefined = false;
|
||||
// Put call_data in place.
|
||||
if (isolate->heap()->InNewSpace(*call_data_obj)) {
|
||||
__ Move(call_data, api_call_info);
|
||||
__ ldr(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset));
|
||||
} else if (call_data_obj->IsUndefined()) {
|
||||
call_data_undefined = true;
|
||||
__ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
|
||||
} else {
|
||||
__ Move(call_data, call_data_obj);
|
||||
}
|
||||
|
||||
// Put api_function_address in place.
|
||||
Address function_address = v8::ToCData<Address>(api_call_info->callback());
|
||||
ApiFunction fun(function_address);
|
||||
ExternalReference::Type type = ExternalReference::DIRECT_API_CALL;
|
||||
ExternalReference ref = ExternalReference(&fun, type, masm->isolate());
|
||||
__ mov(api_function_address, Operand(ref));
|
||||
|
||||
// Jump to stub.
|
||||
CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void ElementHandlerCompiler::GenerateLoadDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
// The return address is in lr.
|
||||
Label slow, miss;
|
||||
|
||||
Register key = LoadIC::NameRegister();
|
||||
Register receiver = LoadIC::ReceiverRegister();
|
||||
DCHECK(receiver.is(r1));
|
||||
DCHECK(key.is(r2));
|
||||
|
||||
__ UntagAndJumpIfNotSmi(r6, key, &miss);
|
||||
__ ldr(r4, FieldMemOperand(receiver, JSObject::kElementsOffset));
|
||||
__ LoadFromNumberDictionary(&slow, r4, key, r0, r6, r3, r5);
|
||||
__ Ret();
|
||||
|
||||
__ bind(&slow);
|
||||
__ IncrementCounter(
|
||||
masm->isolate()->counters()->keyed_load_external_array_slow(), 1, r2, r3);
|
||||
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
|
||||
|
||||
// Miss case, call the runtime.
|
||||
__ bind(&miss);
|
||||
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
|
||||
Handle<Name> name) {
|
||||
if (!label->is_unused()) {
|
||||
__ bind(label);
|
||||
__ mov(this->name(), Operand(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Generate StoreTransition code, value is passed in r0 register.
|
||||
// When leaving generated code after success, the receiver_reg and name_reg
|
||||
// may be clobbered. Upon branch to miss_label, the receiver and name
|
||||
// registers have their original values.
|
||||
void NamedStoreHandlerCompiler::GenerateStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name, Register receiver_reg,
|
||||
Register storage_reg, Register value_reg, Register scratch1,
|
||||
Register scratch2, Register scratch3, Label* miss_label, Label* slow) {
|
||||
// r0 : value
|
||||
Label exit;
|
||||
|
||||
int descriptor = transition->LastAdded();
|
||||
DescriptorArray* descriptors = transition->instance_descriptors();
|
||||
PropertyDetails details = descriptors->GetDetails(descriptor);
|
||||
Representation representation = details.representation();
|
||||
DCHECK(!representation.IsNone());
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
|
||||
__ Move(scratch1, constant);
|
||||
__ cmp(value_reg, scratch1);
|
||||
__ b(ne, miss_label);
|
||||
} else if (representation.IsSmi()) {
|
||||
__ JumpIfNotSmi(value_reg, miss_label);
|
||||
} else if (representation.IsHeapObject()) {
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType* field_type = descriptors->GetFieldType(descriptor);
|
||||
HeapType::Iterator<Map> it = field_type->Classes();
|
||||
if (!it.Done()) {
|
||||
__ ldr(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(scratch1, it.Current(), &do_store);
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ b(ne, miss_label);
|
||||
break;
|
||||
}
|
||||
__ b(eq, &do_store);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
}
|
||||
} else if (representation.IsDouble()) {
|
||||
Label do_store, heap_number;
|
||||
__ LoadRoot(scratch3, Heap::kMutableHeapNumberMapRootIndex);
|
||||
__ AllocateHeapNumber(storage_reg, scratch1, scratch2, scratch3, slow,
|
||||
TAG_RESULT, MUTABLE);
|
||||
|
||||
__ JumpIfNotSmi(value_reg, &heap_number);
|
||||
__ SmiUntag(scratch1, value_reg);
|
||||
__ vmov(s0, scratch1);
|
||||
__ vcvt_f64_s32(d0, s0);
|
||||
__ jmp(&do_store);
|
||||
|
||||
__ bind(&heap_number);
|
||||
__ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex, miss_label,
|
||||
DONT_DO_SMI_CHECK);
|
||||
__ vldr(d0, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
|
||||
|
||||
__ bind(&do_store);
|
||||
__ vstr(d0, FieldMemOperand(storage_reg, HeapNumber::kValueOffset));
|
||||
}
|
||||
|
||||
// Stub never generated for objects that require access checks.
|
||||
DCHECK(!transition->is_access_check_needed());
|
||||
|
||||
// Perform map transition for the receiver if necessary.
|
||||
if (details.type() == FIELD &&
|
||||
Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
|
||||
// The properties must be extended before we can store the value.
|
||||
// We jump to a runtime call that extends the properties array.
|
||||
__ push(receiver_reg);
|
||||
__ mov(r2, Operand(transition));
|
||||
__ Push(r2, r0);
|
||||
__ TailCallExternalReference(
|
||||
ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
|
||||
isolate()),
|
||||
3, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the map of the object.
|
||||
__ mov(scratch1, Operand(transition));
|
||||
__ str(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
|
||||
|
||||
// Update the write barrier for the map field.
|
||||
__ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET,
|
||||
OMIT_SMI_CHECK);
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
DCHECK(value_reg.is(r0));
|
||||
__ Ret();
|
||||
return;
|
||||
}
|
||||
|
||||
int index = transition->instance_descriptors()->GetFieldIndex(
|
||||
transition->LastAdded());
|
||||
|
||||
// Adjust for the number of properties stored in the object. Even in the
|
||||
// face of a transition we can use the old map here because the size of the
|
||||
// object and the number of in-object properties is not going to change.
|
||||
index -= transition->inobject_properties();
|
||||
|
||||
// TODO(verwaest): Share this code as a code stub.
|
||||
SmiCheck smi_check =
|
||||
representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
|
||||
if (index < 0) {
|
||||
// Set the property straight into the object.
|
||||
int offset = transition->instance_size() + (index * kPointerSize);
|
||||
if (representation.IsDouble()) {
|
||||
__ str(storage_reg, FieldMemOperand(receiver_reg, offset));
|
||||
} else {
|
||||
__ str(value_reg, FieldMemOperand(receiver_reg, offset));
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs,
|
||||
EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
} else {
|
||||
// Write to the properties array.
|
||||
int offset = index * kPointerSize + FixedArray::kHeaderSize;
|
||||
// Get the properties array
|
||||
__ ldr(scratch1,
|
||||
FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
|
||||
if (representation.IsDouble()) {
|
||||
__ str(storage_reg, FieldMemOperand(scratch1, offset));
|
||||
} else {
|
||||
__ str(value_reg, FieldMemOperand(scratch1, offset));
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs,
|
||||
EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the value (register r0).
|
||||
DCHECK(value_reg.is(r0));
|
||||
__ bind(&exit);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
|
||||
Register value_reg,
|
||||
Label* miss_label) {
|
||||
DCHECK(lookup->representation().IsHeapObject());
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
|
||||
__ ldr(scratch1(), FieldMemOperand(value_reg, HeapObject::kMapOffset));
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(scratch1(), it.Current(), &do_store);
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ b(ne, miss_label);
|
||||
break;
|
||||
}
|
||||
__ b(eq, &do_store);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
|
||||
StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
|
||||
lookup->representation());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::CheckPrototypes(
|
||||
Register object_reg, Register holder_reg, Register scratch1,
|
||||
Register scratch2, Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check) {
|
||||
Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
|
||||
|
||||
// Make sure there's no overlap between holder and object registers.
|
||||
DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
|
||||
DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
|
||||
!scratch2.is(scratch1));
|
||||
|
||||
// Keep track of the current object in register reg.
|
||||
Register reg = object_reg;
|
||||
int depth = 0;
|
||||
|
||||
Handle<JSObject> current = Handle<JSObject>::null();
|
||||
if (type()->IsConstant()) {
|
||||
current = Handle<JSObject>::cast(type()->AsConstant()->Value());
|
||||
}
|
||||
Handle<JSObject> prototype = Handle<JSObject>::null();
|
||||
Handle<Map> current_map = receiver_map;
|
||||
Handle<Map> holder_map(holder()->map());
|
||||
// Traverse the prototype chain and check the maps in the prototype chain for
|
||||
// fast and global objects or do negative lookup for normal objects.
|
||||
while (!current_map.is_identical_to(holder_map)) {
|
||||
++depth;
|
||||
|
||||
// Only global objects and objects that do not require access
|
||||
// checks are allowed in stubs.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
|
||||
prototype = handle(JSObject::cast(current_map->prototype()));
|
||||
if (current_map->is_dictionary_map() &&
|
||||
!current_map->IsJSGlobalObjectMap()) {
|
||||
DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(current.is_null() ||
|
||||
current->property_dictionary()->FindEntry(name) ==
|
||||
NameDictionary::kNotFound);
|
||||
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
|
||||
scratch2);
|
||||
|
||||
__ ldr(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
__ ldr(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
Register map_reg = scratch1;
|
||||
if (depth != 1 || check == CHECK_ALL_MAPS) {
|
||||
// CheckMap implicitly loads the map of |reg| into |map_reg|.
|
||||
__ CheckMap(reg, map_reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
} else {
|
||||
__ ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
|
||||
}
|
||||
|
||||
// Check access rights to the global object. This has to happen after
|
||||
// the map check so that we know that the object is actually a global
|
||||
// object.
|
||||
// This allows us to install generated handlers for accesses to the
|
||||
// global proxy (as opposed to using slow ICs). See corresponding code
|
||||
// in LookupForRead().
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch2, miss);
|
||||
} else if (current_map->IsJSGlobalObjectMap()) {
|
||||
GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
|
||||
name, scratch2, miss);
|
||||
}
|
||||
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
|
||||
// Two possible reasons for loading the prototype from the map:
|
||||
// (1) Can't store references to new space in code.
|
||||
// (2) Handler is shared for all receivers with the same prototype
|
||||
// map (but not necessarily the same prototype instance).
|
||||
bool load_prototype_from_map =
|
||||
heap()->InNewSpace(*prototype) || depth == 1;
|
||||
if (load_prototype_from_map) {
|
||||
__ ldr(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
|
||||
} else {
|
||||
__ mov(reg, Operand(prototype));
|
||||
}
|
||||
}
|
||||
|
||||
// Go to the next object in the prototype chain.
|
||||
current = prototype;
|
||||
current_map = handle(current->map());
|
||||
}
|
||||
|
||||
// Log the check depth.
|
||||
LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
|
||||
|
||||
if (depth != 0 || check == CHECK_ALL_MAPS) {
|
||||
// Check the holder map.
|
||||
__ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Perform security check for access to the global object.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, miss);
|
||||
}
|
||||
|
||||
// Return the register containing the holder.
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ b(&success);
|
||||
__ bind(miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ b(&success);
|
||||
GenerateRestoreName(miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
|
||||
// Return the constant value.
|
||||
__ Move(r0, value);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadCallback(
|
||||
Register reg, Handle<ExecutableAccessorInfo> callback) {
|
||||
// Build AccessorInfo::args_ list on the stack and push property name below
|
||||
// the exit frame to make GC aware of them and store pointers to them.
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
|
||||
DCHECK(!scratch2().is(reg));
|
||||
DCHECK(!scratch3().is(reg));
|
||||
DCHECK(!scratch4().is(reg));
|
||||
__ push(receiver());
|
||||
if (heap()->InNewSpace(callback->data())) {
|
||||
__ Move(scratch3(), callback);
|
||||
__ ldr(scratch3(),
|
||||
FieldMemOperand(scratch3(), ExecutableAccessorInfo::kDataOffset));
|
||||
} else {
|
||||
__ Move(scratch3(), Handle<Object>(callback->data(), isolate()));
|
||||
}
|
||||
__ push(scratch3());
|
||||
__ LoadRoot(scratch3(), Heap::kUndefinedValueRootIndex);
|
||||
__ mov(scratch4(), scratch3());
|
||||
__ Push(scratch3(), scratch4());
|
||||
__ mov(scratch4(), Operand(ExternalReference::isolate_address(isolate())));
|
||||
__ Push(scratch4(), reg);
|
||||
__ mov(scratch2(), sp); // scratch2 = PropertyAccessorInfo::args_
|
||||
__ push(name());
|
||||
|
||||
// Abi for CallApiGetter
|
||||
Register getter_address_reg = r2;
|
||||
|
||||
Address getter_address = v8::ToCData<Address>(callback->getter());
|
||||
ApiFunction fun(getter_address);
|
||||
ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
|
||||
ExternalReference ref = ExternalReference(&fun, type, isolate());
|
||||
__ mov(getter_address_reg, Operand(ref));
|
||||
|
||||
CallApiGetterStub stub(isolate());
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
|
||||
LookupIterator* it, Register holder_reg) {
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
|
||||
// Compile the interceptor call, followed by inline code to load the
|
||||
// property from further up the prototype chain if the call fails.
|
||||
// Check that the maps haven't changed.
|
||||
DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
|
||||
|
||||
// Preserve the receiver register explicitly whenever it is different from the
|
||||
// holder and it is needed should the interceptor return without any result.
|
||||
// The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
|
||||
// case might cause a miss during the prototype check.
|
||||
bool must_perform_prototype_check =
|
||||
!holder().is_identical_to(it->GetHolder<JSObject>());
|
||||
bool must_preserve_receiver_reg =
|
||||
!receiver().is(holder_reg) &&
|
||||
(it->property_kind() == LookupIterator::ACCESSOR ||
|
||||
must_perform_prototype_check);
|
||||
|
||||
// Save necessary data before invoking an interceptor.
|
||||
// Requires a frame to make GC aware of pushed pointers.
|
||||
{
|
||||
FrameAndConstantPoolScope frame_scope(masm(), StackFrame::INTERNAL);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Push(receiver(), holder_reg, this->name());
|
||||
} else {
|
||||
__ Push(holder_reg, this->name());
|
||||
}
|
||||
// Invoke an interceptor. Note: map checks from receiver to
|
||||
// interceptor's holder has been compiled before (see a caller
|
||||
// of this method.)
|
||||
CompileCallLoadPropertyWithInterceptor(
|
||||
masm(), receiver(), holder_reg, this->name(), holder(),
|
||||
IC::kLoadPropertyWithInterceptorOnly);
|
||||
|
||||
// Check if interceptor provided a value for property. If it's
|
||||
// the case, return immediately.
|
||||
Label interceptor_failed;
|
||||
__ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
|
||||
__ cmp(r0, scratch1());
|
||||
__ b(eq, &interceptor_failed);
|
||||
frame_scope.GenerateLeaveFrame();
|
||||
__ Ret();
|
||||
|
||||
__ bind(&interceptor_failed);
|
||||
__ pop(this->name());
|
||||
__ pop(holder_reg);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ pop(receiver());
|
||||
}
|
||||
// Leave the internal frame.
|
||||
}
|
||||
|
||||
GenerateLoadPostInterceptor(it, holder_reg);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
|
||||
// Call the runtime system to load the interceptor.
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
|
||||
holder());
|
||||
|
||||
ExternalReference ref = ExternalReference(
|
||||
IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(
|
||||
ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback) {
|
||||
Register holder_reg = Frontend(receiver(), name);
|
||||
|
||||
__ push(receiver()); // receiver
|
||||
__ push(holder_reg);
|
||||
__ mov(ip, Operand(callback)); // callback info
|
||||
__ push(ip);
|
||||
__ mov(ip, Operand(name));
|
||||
__ Push(ip, value());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_callback_property =
|
||||
ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
|
||||
__ TailCallExternalReference(store_callback_property, 5, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
|
||||
Handle<Name> name) {
|
||||
__ Push(receiver(), this->name(), value());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_ic_property = ExternalReference(
|
||||
IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(store_ic_property, 3, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
|
||||
Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
|
||||
Label miss;
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
|
||||
// Get the value from the cell.
|
||||
Register result = StoreIC::ValueRegister();
|
||||
__ mov(result, Operand(cell));
|
||||
__ ldr(result, FieldMemOperand(result, Cell::kValueOffset));
|
||||
|
||||
// Check for deleted property if property can actually be deleted.
|
||||
if (is_configurable) {
|
||||
__ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
||||
__ cmp(result, ip);
|
||||
__ b(eq, &miss);
|
||||
}
|
||||
|
||||
Counters* counters = isolate()->counters();
|
||||
__ IncrementCounter(counters->named_load_global_stub(), 1, r1, r3);
|
||||
__ Ret();
|
||||
|
||||
FrontendFooter(name, &miss);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, name);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
||||
#endif // V8_TARGET_ARCH_ARM
|
@ -6,7 +6,6 @@
|
||||
|
||||
#if V8_TARGET_ARCH_ARM
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
|
||||
namespace v8 {
|
||||
@ -15,198 +14,16 @@ namespace internal {
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
|
||||
MacroAssembler* masm, Label* miss_label, Register receiver,
|
||||
Handle<Name> name, Register scratch0, Register scratch1) {
|
||||
DCHECK(name->IsUniqueName());
|
||||
DCHECK(!receiver.is(scratch0));
|
||||
Counters* counters = masm->isolate()->counters();
|
||||
__ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
|
||||
__ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
|
||||
void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
|
||||
StrictMode strict_mode) {
|
||||
__ Push(StoreIC::ReceiverRegister(), StoreIC::NameRegister(),
|
||||
StoreIC::ValueRegister());
|
||||
|
||||
Label done;
|
||||
__ mov(r0, Operand(Smi::FromInt(strict_mode)));
|
||||
__ Push(r0);
|
||||
|
||||
const int kInterceptorOrAccessCheckNeededMask =
|
||||
(1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
|
||||
|
||||
// Bail out if the receiver has a named interceptor or requires access checks.
|
||||
Register map = scratch1;
|
||||
__ ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
|
||||
__ ldrb(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
|
||||
__ tst(scratch0, Operand(kInterceptorOrAccessCheckNeededMask));
|
||||
__ b(ne, miss_label);
|
||||
|
||||
// Check that receiver is a JSObject.
|
||||
__ ldrb(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
|
||||
__ cmp(scratch0, Operand(FIRST_SPEC_OBJECT_TYPE));
|
||||
__ b(lt, miss_label);
|
||||
|
||||
// Load properties array.
|
||||
Register properties = scratch0;
|
||||
__ ldr(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
|
||||
// Check that the properties array is a dictionary.
|
||||
__ ldr(map, FieldMemOperand(properties, HeapObject::kMapOffset));
|
||||
Register tmp = properties;
|
||||
__ LoadRoot(tmp, Heap::kHashTableMapRootIndex);
|
||||
__ cmp(map, tmp);
|
||||
__ b(ne, miss_label);
|
||||
|
||||
// Restore the temporarily used register.
|
||||
__ ldr(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
|
||||
|
||||
|
||||
NameDictionaryLookupStub::GenerateNegativeLookup(
|
||||
masm, miss_label, &done, receiver, properties, name, scratch1);
|
||||
__ bind(&done);
|
||||
__ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
|
||||
MacroAssembler* masm, int index, Register prototype, Label* miss) {
|
||||
Isolate* isolate = masm->isolate();
|
||||
// Get the global function with the given index.
|
||||
Handle<JSFunction> function(
|
||||
JSFunction::cast(isolate->native_context()->get(index)));
|
||||
|
||||
// Check we're still in the same context.
|
||||
Register scratch = prototype;
|
||||
const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
|
||||
__ ldr(scratch, MemOperand(cp, offset));
|
||||
__ ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
|
||||
__ ldr(scratch, MemOperand(scratch, Context::SlotOffset(index)));
|
||||
__ Move(ip, function);
|
||||
__ cmp(ip, scratch);
|
||||
__ b(ne, miss);
|
||||
|
||||
// Load its initial map. The global functions all have initial maps.
|
||||
__ Move(prototype, Handle<Map>(function->initial_map()));
|
||||
// Load the prototype from the initial map.
|
||||
__ ldr(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
|
||||
MacroAssembler* masm, Register receiver, Register scratch1,
|
||||
Register scratch2, Label* miss_label) {
|
||||
__ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
|
||||
__ mov(r0, scratch1);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
// Generate code to check that a global property cell is empty. Create
|
||||
// the property cell at compilation time if no cell exists for the
|
||||
// property.
|
||||
void PropertyHandlerCompiler::GenerateCheckPropertyCell(
|
||||
MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
|
||||
Register scratch, Label* miss) {
|
||||
Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
|
||||
DCHECK(cell->value()->IsTheHole());
|
||||
__ mov(scratch, Operand(cell));
|
||||
__ ldr(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
|
||||
__ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
||||
__ cmp(scratch, ip);
|
||||
__ b(ne, miss);
|
||||
}
|
||||
|
||||
|
||||
static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
|
||||
Register holder, Register name,
|
||||
Handle<JSObject> holder_obj) {
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
|
||||
__ push(name);
|
||||
Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
|
||||
DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
|
||||
Register scratch = name;
|
||||
__ mov(scratch, Operand(interceptor));
|
||||
__ push(scratch);
|
||||
__ push(receiver);
|
||||
__ push(holder);
|
||||
}
|
||||
|
||||
|
||||
static void CompileCallLoadPropertyWithInterceptor(
|
||||
MacroAssembler* masm, Register receiver, Register holder, Register name,
|
||||
Handle<JSObject> holder_obj, IC::UtilityId id) {
|
||||
PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
|
||||
__ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
|
||||
NamedLoadHandlerCompiler::kInterceptorArgsLength);
|
||||
}
|
||||
|
||||
|
||||
// Generate call to api function.
|
||||
void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
MacroAssembler* masm, const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver, Register scratch_in,
|
||||
bool is_store, int argc, Register* values) {
|
||||
DCHECK(!receiver.is(scratch_in));
|
||||
__ push(receiver);
|
||||
// Write the arguments to stack frame.
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Register arg = values[argc - 1 - i];
|
||||
DCHECK(!receiver.is(arg));
|
||||
DCHECK(!scratch_in.is(arg));
|
||||
__ push(arg);
|
||||
}
|
||||
DCHECK(optimization.is_simple_api_call());
|
||||
|
||||
// Abi for CallApiFunctionStub.
|
||||
Register callee = r0;
|
||||
Register call_data = r4;
|
||||
Register holder = r2;
|
||||
Register api_function_address = r1;
|
||||
|
||||
// Put holder in place.
|
||||
CallOptimization::HolderLookup holder_lookup;
|
||||
Handle<JSObject> api_holder =
|
||||
optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
|
||||
switch (holder_lookup) {
|
||||
case CallOptimization::kHolderIsReceiver:
|
||||
__ Move(holder, receiver);
|
||||
break;
|
||||
case CallOptimization::kHolderFound:
|
||||
__ Move(holder, api_holder);
|
||||
break;
|
||||
case CallOptimization::kHolderNotFound:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
Isolate* isolate = masm->isolate();
|
||||
Handle<JSFunction> function = optimization.constant_function();
|
||||
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
|
||||
Handle<Object> call_data_obj(api_call_info->data(), isolate);
|
||||
|
||||
// Put callee in place.
|
||||
__ Move(callee, function);
|
||||
|
||||
bool call_data_undefined = false;
|
||||
// Put call_data in place.
|
||||
if (isolate->heap()->InNewSpace(*call_data_obj)) {
|
||||
__ Move(call_data, api_call_info);
|
||||
__ ldr(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset));
|
||||
} else if (call_data_obj->IsUndefined()) {
|
||||
call_data_undefined = true;
|
||||
__ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
|
||||
} else {
|
||||
__ Move(call_data, call_data_obj);
|
||||
}
|
||||
|
||||
// Put api_function_address in place.
|
||||
Address function_address = v8::ToCData<Address>(api_call_info->callback());
|
||||
ApiFunction fun(function_address);
|
||||
ExternalReference::Type type = ExternalReference::DIRECT_API_CALL;
|
||||
ExternalReference ref = ExternalReference(&fun, type, masm->isolate());
|
||||
__ mov(api_function_address, Operand(ref));
|
||||
|
||||
// Jump to stub.
|
||||
CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
|
||||
__ TailCallStub(&stub);
|
||||
// Do tail-call to runtime routine.
|
||||
__ TailCallRuntime(Runtime::kSetProperty, 4, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -214,613 +31,6 @@ void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
|
||||
Handle<Name> name) {
|
||||
if (!label->is_unused()) {
|
||||
__ bind(label);
|
||||
__ mov(this->name(), Operand(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Generate StoreTransition code, value is passed in r0 register.
|
||||
// When leaving generated code after success, the receiver_reg and name_reg
|
||||
// may be clobbered. Upon branch to miss_label, the receiver and name
|
||||
// registers have their original values.
|
||||
void NamedStoreHandlerCompiler::GenerateStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name, Register receiver_reg,
|
||||
Register storage_reg, Register value_reg, Register scratch1,
|
||||
Register scratch2, Register scratch3, Label* miss_label, Label* slow) {
|
||||
// r0 : value
|
||||
Label exit;
|
||||
|
||||
int descriptor = transition->LastAdded();
|
||||
DescriptorArray* descriptors = transition->instance_descriptors();
|
||||
PropertyDetails details = descriptors->GetDetails(descriptor);
|
||||
Representation representation = details.representation();
|
||||
DCHECK(!representation.IsNone());
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
|
||||
__ Move(scratch1, constant);
|
||||
__ cmp(value_reg, scratch1);
|
||||
__ b(ne, miss_label);
|
||||
} else if (representation.IsSmi()) {
|
||||
__ JumpIfNotSmi(value_reg, miss_label);
|
||||
} else if (representation.IsHeapObject()) {
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType* field_type = descriptors->GetFieldType(descriptor);
|
||||
HeapType::Iterator<Map> it = field_type->Classes();
|
||||
if (!it.Done()) {
|
||||
__ ldr(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(scratch1, it.Current(), &do_store);
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ b(ne, miss_label);
|
||||
break;
|
||||
}
|
||||
__ b(eq, &do_store);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
}
|
||||
} else if (representation.IsDouble()) {
|
||||
Label do_store, heap_number;
|
||||
__ LoadRoot(scratch3, Heap::kMutableHeapNumberMapRootIndex);
|
||||
__ AllocateHeapNumber(storage_reg, scratch1, scratch2, scratch3, slow,
|
||||
TAG_RESULT, MUTABLE);
|
||||
|
||||
__ JumpIfNotSmi(value_reg, &heap_number);
|
||||
__ SmiUntag(scratch1, value_reg);
|
||||
__ vmov(s0, scratch1);
|
||||
__ vcvt_f64_s32(d0, s0);
|
||||
__ jmp(&do_store);
|
||||
|
||||
__ bind(&heap_number);
|
||||
__ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex, miss_label,
|
||||
DONT_DO_SMI_CHECK);
|
||||
__ vldr(d0, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
|
||||
|
||||
__ bind(&do_store);
|
||||
__ vstr(d0, FieldMemOperand(storage_reg, HeapNumber::kValueOffset));
|
||||
}
|
||||
|
||||
// Stub never generated for objects that require access checks.
|
||||
DCHECK(!transition->is_access_check_needed());
|
||||
|
||||
// Perform map transition for the receiver if necessary.
|
||||
if (details.type() == FIELD &&
|
||||
Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
|
||||
// The properties must be extended before we can store the value.
|
||||
// We jump to a runtime call that extends the properties array.
|
||||
__ push(receiver_reg);
|
||||
__ mov(r2, Operand(transition));
|
||||
__ Push(r2, r0);
|
||||
__ TailCallExternalReference(
|
||||
ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
|
||||
isolate()),
|
||||
3, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the map of the object.
|
||||
__ mov(scratch1, Operand(transition));
|
||||
__ str(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
|
||||
|
||||
// Update the write barrier for the map field.
|
||||
__ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET,
|
||||
OMIT_SMI_CHECK);
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
DCHECK(value_reg.is(r0));
|
||||
__ Ret();
|
||||
return;
|
||||
}
|
||||
|
||||
int index = transition->instance_descriptors()->GetFieldIndex(
|
||||
transition->LastAdded());
|
||||
|
||||
// Adjust for the number of properties stored in the object. Even in the
|
||||
// face of a transition we can use the old map here because the size of the
|
||||
// object and the number of in-object properties is not going to change.
|
||||
index -= transition->inobject_properties();
|
||||
|
||||
// TODO(verwaest): Share this code as a code stub.
|
||||
SmiCheck smi_check =
|
||||
representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
|
||||
if (index < 0) {
|
||||
// Set the property straight into the object.
|
||||
int offset = transition->instance_size() + (index * kPointerSize);
|
||||
if (representation.IsDouble()) {
|
||||
__ str(storage_reg, FieldMemOperand(receiver_reg, offset));
|
||||
} else {
|
||||
__ str(value_reg, FieldMemOperand(receiver_reg, offset));
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs,
|
||||
EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
} else {
|
||||
// Write to the properties array.
|
||||
int offset = index * kPointerSize + FixedArray::kHeaderSize;
|
||||
// Get the properties array
|
||||
__ ldr(scratch1,
|
||||
FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
|
||||
if (representation.IsDouble()) {
|
||||
__ str(storage_reg, FieldMemOperand(scratch1, offset));
|
||||
} else {
|
||||
__ str(value_reg, FieldMemOperand(scratch1, offset));
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs,
|
||||
EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the value (register r0).
|
||||
DCHECK(value_reg.is(r0));
|
||||
__ bind(&exit);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
|
||||
Register value_reg,
|
||||
Label* miss_label) {
|
||||
DCHECK(lookup->representation().IsHeapObject());
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
|
||||
__ ldr(scratch1(), FieldMemOperand(value_reg, HeapObject::kMapOffset));
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(scratch1(), it.Current(), &do_store);
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ b(ne, miss_label);
|
||||
break;
|
||||
}
|
||||
__ b(eq, &do_store);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
|
||||
StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
|
||||
lookup->representation());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::CheckPrototypes(
|
||||
Register object_reg, Register holder_reg, Register scratch1,
|
||||
Register scratch2, Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check) {
|
||||
Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
|
||||
|
||||
// Make sure there's no overlap between holder and object registers.
|
||||
DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
|
||||
DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
|
||||
!scratch2.is(scratch1));
|
||||
|
||||
// Keep track of the current object in register reg.
|
||||
Register reg = object_reg;
|
||||
int depth = 0;
|
||||
|
||||
Handle<JSObject> current = Handle<JSObject>::null();
|
||||
if (type()->IsConstant()) {
|
||||
current = Handle<JSObject>::cast(type()->AsConstant()->Value());
|
||||
}
|
||||
Handle<JSObject> prototype = Handle<JSObject>::null();
|
||||
Handle<Map> current_map = receiver_map;
|
||||
Handle<Map> holder_map(holder()->map());
|
||||
// Traverse the prototype chain and check the maps in the prototype chain for
|
||||
// fast and global objects or do negative lookup for normal objects.
|
||||
while (!current_map.is_identical_to(holder_map)) {
|
||||
++depth;
|
||||
|
||||
// Only global objects and objects that do not require access
|
||||
// checks are allowed in stubs.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
|
||||
prototype = handle(JSObject::cast(current_map->prototype()));
|
||||
if (current_map->is_dictionary_map() &&
|
||||
!current_map->IsJSGlobalObjectMap()) {
|
||||
DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(current.is_null() ||
|
||||
current->property_dictionary()->FindEntry(name) ==
|
||||
NameDictionary::kNotFound);
|
||||
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
|
||||
scratch2);
|
||||
|
||||
__ ldr(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
__ ldr(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
Register map_reg = scratch1;
|
||||
if (depth != 1 || check == CHECK_ALL_MAPS) {
|
||||
// CheckMap implicitly loads the map of |reg| into |map_reg|.
|
||||
__ CheckMap(reg, map_reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
} else {
|
||||
__ ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
|
||||
}
|
||||
|
||||
// Check access rights to the global object. This has to happen after
|
||||
// the map check so that we know that the object is actually a global
|
||||
// object.
|
||||
// This allows us to install generated handlers for accesses to the
|
||||
// global proxy (as opposed to using slow ICs). See corresponding code
|
||||
// in LookupForRead().
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch2, miss);
|
||||
} else if (current_map->IsJSGlobalObjectMap()) {
|
||||
GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
|
||||
name, scratch2, miss);
|
||||
}
|
||||
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
|
||||
// Two possible reasons for loading the prototype from the map:
|
||||
// (1) Can't store references to new space in code.
|
||||
// (2) Handler is shared for all receivers with the same prototype
|
||||
// map (but not necessarily the same prototype instance).
|
||||
bool load_prototype_from_map =
|
||||
heap()->InNewSpace(*prototype) || depth == 1;
|
||||
if (load_prototype_from_map) {
|
||||
__ ldr(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
|
||||
} else {
|
||||
__ mov(reg, Operand(prototype));
|
||||
}
|
||||
}
|
||||
|
||||
// Go to the next object in the prototype chain.
|
||||
current = prototype;
|
||||
current_map = handle(current->map());
|
||||
}
|
||||
|
||||
// Log the check depth.
|
||||
LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
|
||||
|
||||
if (depth != 0 || check == CHECK_ALL_MAPS) {
|
||||
// Check the holder map.
|
||||
__ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Perform security check for access to the global object.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, miss);
|
||||
}
|
||||
|
||||
// Return the register containing the holder.
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ b(&success);
|
||||
__ bind(miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ b(&success);
|
||||
GenerateRestoreName(miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
|
||||
// Return the constant value.
|
||||
__ Move(r0, value);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadCallback(
|
||||
Register reg, Handle<ExecutableAccessorInfo> callback) {
|
||||
// Build AccessorInfo::args_ list on the stack and push property name below
|
||||
// the exit frame to make GC aware of them and store pointers to them.
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
|
||||
DCHECK(!scratch2().is(reg));
|
||||
DCHECK(!scratch3().is(reg));
|
||||
DCHECK(!scratch4().is(reg));
|
||||
__ push(receiver());
|
||||
if (heap()->InNewSpace(callback->data())) {
|
||||
__ Move(scratch3(), callback);
|
||||
__ ldr(scratch3(),
|
||||
FieldMemOperand(scratch3(), ExecutableAccessorInfo::kDataOffset));
|
||||
} else {
|
||||
__ Move(scratch3(), Handle<Object>(callback->data(), isolate()));
|
||||
}
|
||||
__ push(scratch3());
|
||||
__ LoadRoot(scratch3(), Heap::kUndefinedValueRootIndex);
|
||||
__ mov(scratch4(), scratch3());
|
||||
__ Push(scratch3(), scratch4());
|
||||
__ mov(scratch4(), Operand(ExternalReference::isolate_address(isolate())));
|
||||
__ Push(scratch4(), reg);
|
||||
__ mov(scratch2(), sp); // scratch2 = PropertyAccessorInfo::args_
|
||||
__ push(name());
|
||||
|
||||
// Abi for CallApiGetter
|
||||
Register getter_address_reg = r2;
|
||||
|
||||
Address getter_address = v8::ToCData<Address>(callback->getter());
|
||||
ApiFunction fun(getter_address);
|
||||
ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
|
||||
ExternalReference ref = ExternalReference(&fun, type, isolate());
|
||||
__ mov(getter_address_reg, Operand(ref));
|
||||
|
||||
CallApiGetterStub stub(isolate());
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
|
||||
LookupIterator* it, Register holder_reg) {
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
|
||||
// Compile the interceptor call, followed by inline code to load the
|
||||
// property from further up the prototype chain if the call fails.
|
||||
// Check that the maps haven't changed.
|
||||
DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
|
||||
|
||||
// Preserve the receiver register explicitly whenever it is different from the
|
||||
// holder and it is needed should the interceptor return without any result.
|
||||
// The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
|
||||
// case might cause a miss during the prototype check.
|
||||
bool must_perform_prototype_check =
|
||||
!holder().is_identical_to(it->GetHolder<JSObject>());
|
||||
bool must_preserve_receiver_reg =
|
||||
!receiver().is(holder_reg) &&
|
||||
(it->property_kind() == LookupIterator::ACCESSOR ||
|
||||
must_perform_prototype_check);
|
||||
|
||||
// Save necessary data before invoking an interceptor.
|
||||
// Requires a frame to make GC aware of pushed pointers.
|
||||
{
|
||||
FrameAndConstantPoolScope frame_scope(masm(), StackFrame::INTERNAL);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Push(receiver(), holder_reg, this->name());
|
||||
} else {
|
||||
__ Push(holder_reg, this->name());
|
||||
}
|
||||
// Invoke an interceptor. Note: map checks from receiver to
|
||||
// interceptor's holder has been compiled before (see a caller
|
||||
// of this method.)
|
||||
CompileCallLoadPropertyWithInterceptor(
|
||||
masm(), receiver(), holder_reg, this->name(), holder(),
|
||||
IC::kLoadPropertyWithInterceptorOnly);
|
||||
|
||||
// Check if interceptor provided a value for property. If it's
|
||||
// the case, return immediately.
|
||||
Label interceptor_failed;
|
||||
__ LoadRoot(scratch1(), Heap::kNoInterceptorResultSentinelRootIndex);
|
||||
__ cmp(r0, scratch1());
|
||||
__ b(eq, &interceptor_failed);
|
||||
frame_scope.GenerateLeaveFrame();
|
||||
__ Ret();
|
||||
|
||||
__ bind(&interceptor_failed);
|
||||
__ pop(this->name());
|
||||
__ pop(holder_reg);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ pop(receiver());
|
||||
}
|
||||
// Leave the internal frame.
|
||||
}
|
||||
|
||||
GenerateLoadPostInterceptor(it, holder_reg);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
|
||||
// Call the runtime system to load the interceptor.
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
|
||||
holder());
|
||||
|
||||
ExternalReference ref = ExternalReference(
|
||||
IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(
|
||||
ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback) {
|
||||
Register holder_reg = Frontend(receiver(), name);
|
||||
|
||||
__ push(receiver()); // receiver
|
||||
__ push(holder_reg);
|
||||
__ mov(ip, Operand(callback)); // callback info
|
||||
__ push(ip);
|
||||
__ mov(ip, Operand(name));
|
||||
__ Push(ip, value());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_callback_property =
|
||||
ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
|
||||
__ TailCallExternalReference(store_callback_property, 5, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- lr : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
// Save value register, so we can restore it later.
|
||||
__ push(value());
|
||||
|
||||
if (!setter.is_null()) {
|
||||
// Call the JavaScript setter with receiver and value on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ ldr(receiver,
|
||||
FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver, value());
|
||||
ParameterCount actual(1);
|
||||
ParameterCount expected(setter);
|
||||
__ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// We have to return the passed value, not the return value of the setter.
|
||||
__ pop(r0);
|
||||
|
||||
// Restore context register.
|
||||
__ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
|
||||
Handle<Name> name) {
|
||||
__ Push(receiver(), this->name(), value());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_ic_property = ExternalReference(
|
||||
IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(store_ic_property, 3, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> getter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- r0 : receiver
|
||||
// -- r2 : name
|
||||
// -- lr : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameAndConstantPoolScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
if (!getter.is_null()) {
|
||||
// Call the JavaScript getter with the receiver on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ ldr(receiver,
|
||||
FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ push(receiver);
|
||||
ParameterCount actual(0);
|
||||
ParameterCount expected(getter);
|
||||
__ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// Restore context register.
|
||||
__ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
|
||||
Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
|
||||
Label miss;
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
|
||||
// Get the value from the cell.
|
||||
Register result = StoreIC::ValueRegister();
|
||||
__ mov(result, Operand(cell));
|
||||
__ ldr(result, FieldMemOperand(result, Cell::kValueOffset));
|
||||
|
||||
// Check for deleted property if property can actually be deleted.
|
||||
if (is_configurable) {
|
||||
__ LoadRoot(ip, Heap::kTheHoleValueRootIndex);
|
||||
__ cmp(result, ip);
|
||||
__ b(eq, &miss);
|
||||
}
|
||||
|
||||
Counters* counters = isolate()->counters();
|
||||
__ IncrementCounter(counters->named_load_global_stub(), 1, r1, r3);
|
||||
__ Ret();
|
||||
|
||||
FrontendFooter(name, &miss);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
|
||||
CodeHandleList* handlers,
|
||||
Handle<Name> name,
|
||||
@ -908,51 +118,6 @@ Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void ElementHandlerCompiler::GenerateLoadDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
// The return address is in lr.
|
||||
Label slow, miss;
|
||||
|
||||
Register key = LoadIC::NameRegister();
|
||||
Register receiver = LoadIC::ReceiverRegister();
|
||||
DCHECK(receiver.is(r1));
|
||||
DCHECK(key.is(r2));
|
||||
|
||||
__ UntagAndJumpIfNotSmi(r6, key, &miss);
|
||||
__ ldr(r4, FieldMemOperand(receiver, JSObject::kElementsOffset));
|
||||
__ LoadFromNumberDictionary(&slow, r4, key, r0, r6, r3, r5);
|
||||
__ Ret();
|
||||
|
||||
__ bind(&slow);
|
||||
__ IncrementCounter(
|
||||
masm->isolate()->counters()->keyed_load_external_array_slow(), 1, r2, r3);
|
||||
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
|
||||
|
||||
// Miss case, call the runtime.
|
||||
__ bind(&miss);
|
||||
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
|
||||
}
|
||||
|
||||
|
||||
void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
|
||||
StrictMode strict_mode) {
|
||||
__ Push(StoreIC::ReceiverRegister(), StoreIC::NameRegister(),
|
||||
StoreIC::ValueRegister());
|
||||
|
||||
__ mov(r0, Operand(Smi::FromInt(strict_mode)));
|
||||
__ Push(r0);
|
||||
|
||||
// Do tail-call to runtime routine.
|
||||
__ TailCallRuntime(Runtime::kSetProperty, 4, 1);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
844
src/ic/arm64/handler-compiler-arm64.cc
Normal file
844
src/ic/arm64/handler-compiler-arm64.cc
Normal file
@ -0,0 +1,844 @@
|
||||
// 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.
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#if V8_TARGET_ARCH_ARM64
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
|
||||
MacroAssembler* masm, Label* miss_label, Register receiver,
|
||||
Handle<Name> name, Register scratch0, Register scratch1) {
|
||||
DCHECK(!AreAliased(receiver, scratch0, scratch1));
|
||||
DCHECK(name->IsUniqueName());
|
||||
Counters* counters = masm->isolate()->counters();
|
||||
__ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
|
||||
__ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
|
||||
|
||||
Label done;
|
||||
|
||||
const int kInterceptorOrAccessCheckNeededMask =
|
||||
(1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
|
||||
|
||||
// Bail out if the receiver has a named interceptor or requires access checks.
|
||||
Register map = scratch1;
|
||||
__ Ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
|
||||
__ Ldrb(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
|
||||
__ Tst(scratch0, kInterceptorOrAccessCheckNeededMask);
|
||||
__ B(ne, miss_label);
|
||||
|
||||
// Check that receiver is a JSObject.
|
||||
__ Ldrb(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
|
||||
__ Cmp(scratch0, FIRST_SPEC_OBJECT_TYPE);
|
||||
__ B(lt, miss_label);
|
||||
|
||||
// Load properties array.
|
||||
Register properties = scratch0;
|
||||
__ Ldr(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
|
||||
// Check that the properties array is a dictionary.
|
||||
__ Ldr(map, FieldMemOperand(properties, HeapObject::kMapOffset));
|
||||
__ JumpIfNotRoot(map, Heap::kHashTableMapRootIndex, miss_label);
|
||||
|
||||
NameDictionaryLookupStub::GenerateNegativeLookup(
|
||||
masm, miss_label, &done, receiver, properties, name, scratch1);
|
||||
__ Bind(&done);
|
||||
__ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
|
||||
MacroAssembler* masm, int index, Register prototype, Label* miss) {
|
||||
Isolate* isolate = masm->isolate();
|
||||
// Get the global function with the given index.
|
||||
Handle<JSFunction> function(
|
||||
JSFunction::cast(isolate->native_context()->get(index)));
|
||||
|
||||
// Check we're still in the same context.
|
||||
Register scratch = prototype;
|
||||
__ Ldr(scratch, GlobalObjectMemOperand());
|
||||
__ Ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
|
||||
__ Ldr(scratch, ContextMemOperand(scratch, index));
|
||||
__ Cmp(scratch, Operand(function));
|
||||
__ B(ne, miss);
|
||||
|
||||
// Load its initial map. The global functions all have initial maps.
|
||||
__ Mov(prototype, Operand(Handle<Map>(function->initial_map())));
|
||||
// Load the prototype from the initial map.
|
||||
__ Ldr(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
|
||||
MacroAssembler* masm, Register receiver, Register scratch1,
|
||||
Register scratch2, Label* miss_label) {
|
||||
__ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
|
||||
// TryGetFunctionPrototype can't put the result directly in x0 because the
|
||||
// 3 inputs registers can't alias and we call this function from
|
||||
// LoadIC::GenerateFunctionPrototype, where receiver is x0. So we explicitly
|
||||
// move the result in x0.
|
||||
__ Mov(x0, scratch1);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
// Generate code to check that a global property cell is empty. Create
|
||||
// the property cell at compilation time if no cell exists for the
|
||||
// property.
|
||||
void PropertyHandlerCompiler::GenerateCheckPropertyCell(
|
||||
MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
|
||||
Register scratch, Label* miss) {
|
||||
Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
|
||||
DCHECK(cell->value()->IsTheHole());
|
||||
__ Mov(scratch, Operand(cell));
|
||||
__ Ldr(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
|
||||
__ JumpIfNotRoot(scratch, Heap::kTheHoleValueRootIndex, miss);
|
||||
}
|
||||
|
||||
|
||||
static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
|
||||
Register holder, Register name,
|
||||
Handle<JSObject> holder_obj) {
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
|
||||
|
||||
__ Push(name);
|
||||
Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
|
||||
DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
|
||||
Register scratch = name;
|
||||
__ Mov(scratch, Operand(interceptor));
|
||||
__ Push(scratch, receiver, holder);
|
||||
}
|
||||
|
||||
|
||||
static void CompileCallLoadPropertyWithInterceptor(
|
||||
MacroAssembler* masm, Register receiver, Register holder, Register name,
|
||||
Handle<JSObject> holder_obj, IC::UtilityId id) {
|
||||
PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
|
||||
|
||||
__ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
|
||||
NamedLoadHandlerCompiler::kInterceptorArgsLength);
|
||||
}
|
||||
|
||||
|
||||
// Generate call to api function.
|
||||
void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
MacroAssembler* masm, const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver, Register scratch,
|
||||
bool is_store, int argc, Register* values) {
|
||||
DCHECK(!AreAliased(receiver, scratch));
|
||||
|
||||
MacroAssembler::PushPopQueue queue(masm);
|
||||
queue.Queue(receiver);
|
||||
// Write the arguments to the stack frame.
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Register arg = values[argc - 1 - i];
|
||||
DCHECK(!AreAliased(receiver, scratch, arg));
|
||||
queue.Queue(arg);
|
||||
}
|
||||
queue.PushQueued();
|
||||
|
||||
DCHECK(optimization.is_simple_api_call());
|
||||
|
||||
// Abi for CallApiFunctionStub.
|
||||
Register callee = x0;
|
||||
Register call_data = x4;
|
||||
Register holder = x2;
|
||||
Register api_function_address = x1;
|
||||
|
||||
// Put holder in place.
|
||||
CallOptimization::HolderLookup holder_lookup;
|
||||
Handle<JSObject> api_holder =
|
||||
optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
|
||||
switch (holder_lookup) {
|
||||
case CallOptimization::kHolderIsReceiver:
|
||||
__ Mov(holder, receiver);
|
||||
break;
|
||||
case CallOptimization::kHolderFound:
|
||||
__ LoadObject(holder, api_holder);
|
||||
break;
|
||||
case CallOptimization::kHolderNotFound:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
Isolate* isolate = masm->isolate();
|
||||
Handle<JSFunction> function = optimization.constant_function();
|
||||
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
|
||||
Handle<Object> call_data_obj(api_call_info->data(), isolate);
|
||||
|
||||
// Put callee in place.
|
||||
__ LoadObject(callee, function);
|
||||
|
||||
bool call_data_undefined = false;
|
||||
// Put call_data in place.
|
||||
if (isolate->heap()->InNewSpace(*call_data_obj)) {
|
||||
__ LoadObject(call_data, api_call_info);
|
||||
__ Ldr(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset));
|
||||
} else if (call_data_obj->IsUndefined()) {
|
||||
call_data_undefined = true;
|
||||
__ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
|
||||
} else {
|
||||
__ LoadObject(call_data, call_data_obj);
|
||||
}
|
||||
|
||||
// Put api_function_address in place.
|
||||
Address function_address = v8::ToCData<Address>(api_call_info->callback());
|
||||
ApiFunction fun(function_address);
|
||||
ExternalReference ref = ExternalReference(
|
||||
&fun, ExternalReference::DIRECT_API_CALL, masm->isolate());
|
||||
__ Mov(api_function_address, ref);
|
||||
|
||||
// Jump to stub.
|
||||
CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- lr : return address
|
||||
// -----------------------------------
|
||||
Label miss;
|
||||
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
// Save value register, so we can restore it later.
|
||||
__ Push(value());
|
||||
|
||||
if (!setter.is_null()) {
|
||||
// Call the JavaScript setter with receiver and value on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ Ldr(receiver,
|
||||
FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver, value());
|
||||
ParameterCount actual(1);
|
||||
ParameterCount expected(setter);
|
||||
__ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// We have to return the passed value, not the return value of the setter.
|
||||
__ Pop(x0);
|
||||
|
||||
// Restore context register.
|
||||
__ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> getter) {
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
if (!getter.is_null()) {
|
||||
// Call the JavaScript getter with the receiver on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ Ldr(receiver,
|
||||
FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver);
|
||||
ParameterCount actual(0);
|
||||
ParameterCount expected(getter);
|
||||
__ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// Restore context register.
|
||||
__ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void ElementHandlerCompiler::GenerateLoadDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
// The return address is in lr.
|
||||
Label slow, miss;
|
||||
|
||||
Register result = x0;
|
||||
Register key = LoadIC::NameRegister();
|
||||
Register receiver = LoadIC::ReceiverRegister();
|
||||
DCHECK(receiver.is(x1));
|
||||
DCHECK(key.is(x2));
|
||||
|
||||
__ JumpIfNotSmi(key, &miss);
|
||||
__ Ldr(x4, FieldMemOperand(receiver, JSObject::kElementsOffset));
|
||||
__ LoadFromNumberDictionary(&slow, x4, key, result, x7, x3, x5, x6);
|
||||
__ Ret();
|
||||
|
||||
__ Bind(&slow);
|
||||
__ IncrementCounter(
|
||||
masm->isolate()->counters()->keyed_load_external_array_slow(), 1, x4, x3);
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
|
||||
|
||||
// Miss case, call the runtime.
|
||||
__ Bind(&miss);
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
|
||||
Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
|
||||
Label miss;
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
|
||||
// Get the value from the cell.
|
||||
Register result = StoreIC::ValueRegister();
|
||||
__ Mov(result, Operand(cell));
|
||||
__ Ldr(result, FieldMemOperand(result, Cell::kValueOffset));
|
||||
|
||||
// Check for deleted property if property can actually be deleted.
|
||||
if (is_configurable) {
|
||||
__ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &miss);
|
||||
}
|
||||
|
||||
Counters* counters = isolate()->counters();
|
||||
__ IncrementCounter(counters->named_load_global_stub(), 1, x1, x3);
|
||||
__ Ret();
|
||||
|
||||
FrontendFooter(name, &miss);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
|
||||
Handle<Name> name) {
|
||||
Label miss;
|
||||
|
||||
ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreInterceptor");
|
||||
|
||||
__ Push(receiver(), this->name(), value());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_ic_property = ExternalReference(
|
||||
IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(store_ic_property, 3, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
|
||||
Handle<Name> name) {
|
||||
if (!label->is_unused()) {
|
||||
__ Bind(label);
|
||||
__ Mov(this->name(), Operand(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Generate StoreTransition code, value is passed in x0 register.
|
||||
// When leaving generated code after success, the receiver_reg and storage_reg
|
||||
// may be clobbered. Upon branch to miss_label, the receiver and name registers
|
||||
// have their original values.
|
||||
void NamedStoreHandlerCompiler::GenerateStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name, Register receiver_reg,
|
||||
Register storage_reg, Register value_reg, Register scratch1,
|
||||
Register scratch2, Register scratch3, Label* miss_label, Label* slow) {
|
||||
Label exit;
|
||||
|
||||
DCHECK(!AreAliased(receiver_reg, storage_reg, value_reg, scratch1, scratch2,
|
||||
scratch3));
|
||||
|
||||
// We don't need scratch3.
|
||||
scratch3 = NoReg;
|
||||
|
||||
int descriptor = transition->LastAdded();
|
||||
DescriptorArray* descriptors = transition->instance_descriptors();
|
||||
PropertyDetails details = descriptors->GetDetails(descriptor);
|
||||
Representation representation = details.representation();
|
||||
DCHECK(!representation.IsNone());
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
|
||||
__ LoadObject(scratch1, constant);
|
||||
__ Cmp(value_reg, scratch1);
|
||||
__ B(ne, miss_label);
|
||||
} else if (representation.IsSmi()) {
|
||||
__ JumpIfNotSmi(value_reg, miss_label);
|
||||
} else if (representation.IsHeapObject()) {
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType* field_type = descriptors->GetFieldType(descriptor);
|
||||
HeapType::Iterator<Map> it = field_type->Classes();
|
||||
if (!it.Done()) {
|
||||
__ Ldr(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(scratch1, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ B(ne, miss_label);
|
||||
break;
|
||||
}
|
||||
__ B(eq, &do_store);
|
||||
}
|
||||
__ Bind(&do_store);
|
||||
}
|
||||
} else if (representation.IsDouble()) {
|
||||
UseScratchRegisterScope temps(masm());
|
||||
DoubleRegister temp_double = temps.AcquireD();
|
||||
__ SmiUntagToDouble(temp_double, value_reg, kSpeculativeUntag);
|
||||
|
||||
Label do_store;
|
||||
__ JumpIfSmi(value_reg, &do_store);
|
||||
|
||||
__ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex, miss_label,
|
||||
DONT_DO_SMI_CHECK);
|
||||
__ Ldr(temp_double, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
|
||||
|
||||
__ Bind(&do_store);
|
||||
__ AllocateHeapNumber(storage_reg, slow, scratch1, scratch2, temp_double,
|
||||
NoReg, MUTABLE);
|
||||
}
|
||||
|
||||
// Stub never generated for objects that require access checks.
|
||||
DCHECK(!transition->is_access_check_needed());
|
||||
|
||||
// Perform map transition for the receiver if necessary.
|
||||
if (details.type() == FIELD &&
|
||||
Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
|
||||
// The properties must be extended before we can store the value.
|
||||
// We jump to a runtime call that extends the properties array.
|
||||
__ Mov(scratch1, Operand(transition));
|
||||
__ Push(receiver_reg, scratch1, value_reg);
|
||||
__ TailCallExternalReference(
|
||||
ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
|
||||
isolate()),
|
||||
3, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the map of the object.
|
||||
__ Mov(scratch1, Operand(transition));
|
||||
__ Str(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
|
||||
|
||||
// Update the write barrier for the map field.
|
||||
__ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET,
|
||||
OMIT_SMI_CHECK);
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
DCHECK(value_reg.is(x0));
|
||||
__ Ret();
|
||||
return;
|
||||
}
|
||||
|
||||
int index = transition->instance_descriptors()->GetFieldIndex(
|
||||
transition->LastAdded());
|
||||
|
||||
// Adjust for the number of properties stored in the object. Even in the
|
||||
// face of a transition we can use the old map here because the size of the
|
||||
// object and the number of in-object properties is not going to change.
|
||||
index -= transition->inobject_properties();
|
||||
|
||||
// TODO(verwaest): Share this code as a code stub.
|
||||
SmiCheck smi_check =
|
||||
representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
|
||||
Register prop_reg = representation.IsDouble() ? storage_reg : value_reg;
|
||||
if (index < 0) {
|
||||
// Set the property straight into the object.
|
||||
int offset = transition->instance_size() + (index * kPointerSize);
|
||||
__ Str(prop_reg, FieldMemOperand(receiver_reg, offset));
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ Mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs,
|
||||
EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
} else {
|
||||
// Write to the properties array.
|
||||
int offset = index * kPointerSize + FixedArray::kHeaderSize;
|
||||
// Get the properties array
|
||||
__ Ldr(scratch1,
|
||||
FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
|
||||
__ Str(prop_reg, FieldMemOperand(scratch1, offset));
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ Mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs,
|
||||
EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
}
|
||||
|
||||
__ Bind(&exit);
|
||||
// Return the value (register x0).
|
||||
DCHECK(value_reg.is(x0));
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
|
||||
Register value_reg,
|
||||
Label* miss_label) {
|
||||
DCHECK(lookup->representation().IsHeapObject());
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
|
||||
__ Ldr(scratch1(), FieldMemOperand(value_reg, HeapObject::kMapOffset));
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(scratch1(), it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ B(ne, miss_label);
|
||||
break;
|
||||
}
|
||||
__ B(eq, &do_store);
|
||||
}
|
||||
__ Bind(&do_store);
|
||||
|
||||
StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
|
||||
lookup->representation());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::CheckPrototypes(
|
||||
Register object_reg, Register holder_reg, Register scratch1,
|
||||
Register scratch2, Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check) {
|
||||
Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
|
||||
|
||||
// object_reg and holder_reg registers can alias.
|
||||
DCHECK(!AreAliased(object_reg, scratch1, scratch2));
|
||||
DCHECK(!AreAliased(holder_reg, scratch1, scratch2));
|
||||
|
||||
// Keep track of the current object in register reg.
|
||||
Register reg = object_reg;
|
||||
int depth = 0;
|
||||
|
||||
Handle<JSObject> current = Handle<JSObject>::null();
|
||||
if (type()->IsConstant()) {
|
||||
current = Handle<JSObject>::cast(type()->AsConstant()->Value());
|
||||
}
|
||||
Handle<JSObject> prototype = Handle<JSObject>::null();
|
||||
Handle<Map> current_map = receiver_map;
|
||||
Handle<Map> holder_map(holder()->map());
|
||||
// Traverse the prototype chain and check the maps in the prototype chain for
|
||||
// fast and global objects or do negative lookup for normal objects.
|
||||
while (!current_map.is_identical_to(holder_map)) {
|
||||
++depth;
|
||||
|
||||
// Only global objects and objects that do not require access
|
||||
// checks are allowed in stubs.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
|
||||
prototype = handle(JSObject::cast(current_map->prototype()));
|
||||
if (current_map->is_dictionary_map() &&
|
||||
!current_map->IsJSGlobalObjectMap()) {
|
||||
DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(current.is_null() || (current->property_dictionary()->FindEntry(
|
||||
name) == NameDictionary::kNotFound));
|
||||
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
|
||||
scratch2);
|
||||
|
||||
__ Ldr(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
__ Ldr(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
// Two possible reasons for loading the prototype from the map:
|
||||
// (1) Can't store references to new space in code.
|
||||
// (2) Handler is shared for all receivers with the same prototype
|
||||
// map (but not necessarily the same prototype instance).
|
||||
bool load_prototype_from_map =
|
||||
heap()->InNewSpace(*prototype) || depth == 1;
|
||||
Register map_reg = scratch1;
|
||||
__ Ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
|
||||
|
||||
if (depth != 1 || check == CHECK_ALL_MAPS) {
|
||||
__ CheckMap(map_reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Check access rights to the global object. This has to happen after
|
||||
// the map check so that we know that the object is actually a global
|
||||
// object.
|
||||
// This allows us to install generated handlers for accesses to the
|
||||
// global proxy (as opposed to using slow ICs). See corresponding code
|
||||
// in LookupForRead().
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
UseScratchRegisterScope temps(masm());
|
||||
__ CheckAccessGlobalProxy(reg, scratch2, temps.AcquireX(), miss);
|
||||
} else if (current_map->IsJSGlobalObjectMap()) {
|
||||
GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
|
||||
name, scratch2, miss);
|
||||
}
|
||||
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
|
||||
if (load_prototype_from_map) {
|
||||
__ Ldr(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
|
||||
} else {
|
||||
__ Mov(reg, Operand(prototype));
|
||||
}
|
||||
}
|
||||
|
||||
// Go to the next object in the prototype chain.
|
||||
current = prototype;
|
||||
current_map = handle(current->map());
|
||||
}
|
||||
|
||||
// Log the check depth.
|
||||
LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
|
||||
|
||||
// Check the holder map.
|
||||
if (depth != 0 || check == CHECK_ALL_MAPS) {
|
||||
// Check the holder map.
|
||||
__ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Perform security check for access to the global object.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
|
||||
}
|
||||
|
||||
// Return the register containing the holder.
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ B(&success);
|
||||
|
||||
__ Bind(miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
|
||||
__ Bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ B(&success);
|
||||
|
||||
GenerateRestoreName(miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
|
||||
__ Bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
|
||||
// Return the constant value.
|
||||
__ LoadObject(x0, value);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadCallback(
|
||||
Register reg, Handle<ExecutableAccessorInfo> callback) {
|
||||
DCHECK(!AreAliased(scratch2(), scratch3(), scratch4(), reg));
|
||||
|
||||
// Build ExecutableAccessorInfo::args_ list on the stack and push property
|
||||
// name below the exit frame to make GC aware of them and store pointers to
|
||||
// them.
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
|
||||
|
||||
__ Push(receiver());
|
||||
|
||||
if (heap()->InNewSpace(callback->data())) {
|
||||
__ Mov(scratch3(), Operand(callback));
|
||||
__ Ldr(scratch3(),
|
||||
FieldMemOperand(scratch3(), ExecutableAccessorInfo::kDataOffset));
|
||||
} else {
|
||||
__ Mov(scratch3(), Operand(Handle<Object>(callback->data(), isolate())));
|
||||
}
|
||||
__ LoadRoot(scratch4(), Heap::kUndefinedValueRootIndex);
|
||||
__ Mov(scratch2(), Operand(ExternalReference::isolate_address(isolate())));
|
||||
__ Push(scratch3(), scratch4(), scratch4(), scratch2(), reg, name());
|
||||
|
||||
Register args_addr = scratch2();
|
||||
__ Add(args_addr, __ StackPointer(), kPointerSize);
|
||||
|
||||
// Stack at this point:
|
||||
// sp[40] callback data
|
||||
// sp[32] undefined
|
||||
// sp[24] undefined
|
||||
// sp[16] isolate
|
||||
// args_addr -> sp[8] reg
|
||||
// sp[0] name
|
||||
|
||||
// Abi for CallApiGetter.
|
||||
Register getter_address_reg = x2;
|
||||
|
||||
// Set up the call.
|
||||
Address getter_address = v8::ToCData<Address>(callback->getter());
|
||||
ApiFunction fun(getter_address);
|
||||
ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
|
||||
ExternalReference ref = ExternalReference(&fun, type, isolate());
|
||||
__ Mov(getter_address_reg, ref);
|
||||
|
||||
CallApiGetterStub stub(isolate());
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
|
||||
LookupIterator* it, Register holder_reg) {
|
||||
DCHECK(!AreAliased(receiver(), this->name(), scratch1(), scratch2(),
|
||||
scratch3()));
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
|
||||
// Compile the interceptor call, followed by inline code to load the
|
||||
// property from further up the prototype chain if the call fails.
|
||||
// Check that the maps haven't changed.
|
||||
DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
|
||||
|
||||
// Preserve the receiver register explicitly whenever it is different from the
|
||||
// holder and it is needed should the interceptor return without any result.
|
||||
// The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
|
||||
// case might cause a miss during the prototype check.
|
||||
bool must_perform_prototype_check =
|
||||
!holder().is_identical_to(it->GetHolder<JSObject>());
|
||||
bool must_preserve_receiver_reg =
|
||||
!receiver().is(holder_reg) &&
|
||||
(it->property_kind() == LookupIterator::ACCESSOR ||
|
||||
must_perform_prototype_check);
|
||||
|
||||
// Save necessary data before invoking an interceptor.
|
||||
// Requires a frame to make GC aware of pushed pointers.
|
||||
{
|
||||
FrameScope frame_scope(masm(), StackFrame::INTERNAL);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Push(receiver(), holder_reg, this->name());
|
||||
} else {
|
||||
__ Push(holder_reg, this->name());
|
||||
}
|
||||
// Invoke an interceptor. Note: map checks from receiver to
|
||||
// interceptor's holder has been compiled before (see a caller
|
||||
// of this method.)
|
||||
CompileCallLoadPropertyWithInterceptor(
|
||||
masm(), receiver(), holder_reg, this->name(), holder(),
|
||||
IC::kLoadPropertyWithInterceptorOnly);
|
||||
|
||||
// Check if interceptor provided a value for property. If it's
|
||||
// the case, return immediately.
|
||||
Label interceptor_failed;
|
||||
__ JumpIfRoot(x0, Heap::kNoInterceptorResultSentinelRootIndex,
|
||||
&interceptor_failed);
|
||||
frame_scope.GenerateLeaveFrame();
|
||||
__ Ret();
|
||||
|
||||
__ Bind(&interceptor_failed);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Pop(this->name(), holder_reg, receiver());
|
||||
} else {
|
||||
__ Pop(this->name(), holder_reg);
|
||||
}
|
||||
// Leave the internal frame.
|
||||
}
|
||||
|
||||
GenerateLoadPostInterceptor(it, holder_reg);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
|
||||
// Call the runtime system to load the interceptor.
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
|
||||
holder());
|
||||
|
||||
ExternalReference ref = ExternalReference(
|
||||
IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(
|
||||
ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback) {
|
||||
ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreCallback");
|
||||
Register holder_reg = Frontend(receiver(), name);
|
||||
|
||||
// Stub never generated for non-global objects that require access checks.
|
||||
DCHECK(holder()->IsJSGlobalProxy() || !holder()->IsAccessCheckNeeded());
|
||||
|
||||
// receiver() and holder_reg can alias.
|
||||
DCHECK(!AreAliased(receiver(), scratch1(), scratch2(), value()));
|
||||
DCHECK(!AreAliased(holder_reg, scratch1(), scratch2(), value()));
|
||||
__ Mov(scratch1(), Operand(callback));
|
||||
__ Mov(scratch2(), Operand(name));
|
||||
__ Push(receiver(), holder_reg, scratch1(), scratch2(), value());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_callback_property =
|
||||
ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
|
||||
__ TailCallExternalReference(store_callback_property, 5, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
||||
#endif // V8_TARGET_ARCH_IA32
|
@ -6,7 +6,6 @@
|
||||
|
||||
#if V8_TARGET_ARCH_ARM64
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
|
||||
namespace v8 {
|
||||
@ -14,195 +13,18 @@ namespace internal {
|
||||
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
|
||||
StrictMode strict_mode) {
|
||||
ASM_LOCATION("PropertyICCompiler::GenerateRuntimeSetProperty");
|
||||
|
||||
void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
|
||||
MacroAssembler* masm, Label* miss_label, Register receiver,
|
||||
Handle<Name> name, Register scratch0, Register scratch1) {
|
||||
DCHECK(!AreAliased(receiver, scratch0, scratch1));
|
||||
DCHECK(name->IsUniqueName());
|
||||
Counters* counters = masm->isolate()->counters();
|
||||
__ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1);
|
||||
__ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
|
||||
__ Push(StoreIC::ReceiverRegister(), StoreIC::NameRegister(),
|
||||
StoreIC::ValueRegister());
|
||||
|
||||
Label done;
|
||||
__ Mov(x10, Smi::FromInt(strict_mode));
|
||||
__ Push(x10);
|
||||
|
||||
const int kInterceptorOrAccessCheckNeededMask =
|
||||
(1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
|
||||
|
||||
// Bail out if the receiver has a named interceptor or requires access checks.
|
||||
Register map = scratch1;
|
||||
__ Ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset));
|
||||
__ Ldrb(scratch0, FieldMemOperand(map, Map::kBitFieldOffset));
|
||||
__ Tst(scratch0, kInterceptorOrAccessCheckNeededMask);
|
||||
__ B(ne, miss_label);
|
||||
|
||||
// Check that receiver is a JSObject.
|
||||
__ Ldrb(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset));
|
||||
__ Cmp(scratch0, FIRST_SPEC_OBJECT_TYPE);
|
||||
__ B(lt, miss_label);
|
||||
|
||||
// Load properties array.
|
||||
Register properties = scratch0;
|
||||
__ Ldr(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset));
|
||||
// Check that the properties array is a dictionary.
|
||||
__ Ldr(map, FieldMemOperand(properties, HeapObject::kMapOffset));
|
||||
__ JumpIfNotRoot(map, Heap::kHashTableMapRootIndex, miss_label);
|
||||
|
||||
NameDictionaryLookupStub::GenerateNegativeLookup(
|
||||
masm, miss_label, &done, receiver, properties, name, scratch1);
|
||||
__ Bind(&done);
|
||||
__ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
|
||||
MacroAssembler* masm, int index, Register prototype, Label* miss) {
|
||||
Isolate* isolate = masm->isolate();
|
||||
// Get the global function with the given index.
|
||||
Handle<JSFunction> function(
|
||||
JSFunction::cast(isolate->native_context()->get(index)));
|
||||
|
||||
// Check we're still in the same context.
|
||||
Register scratch = prototype;
|
||||
__ Ldr(scratch, GlobalObjectMemOperand());
|
||||
__ Ldr(scratch, FieldMemOperand(scratch, GlobalObject::kNativeContextOffset));
|
||||
__ Ldr(scratch, ContextMemOperand(scratch, index));
|
||||
__ Cmp(scratch, Operand(function));
|
||||
__ B(ne, miss);
|
||||
|
||||
// Load its initial map. The global functions all have initial maps.
|
||||
__ Mov(prototype, Operand(Handle<Map>(function->initial_map())));
|
||||
// Load the prototype from the initial map.
|
||||
__ Ldr(prototype, FieldMemOperand(prototype, Map::kPrototypeOffset));
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
|
||||
MacroAssembler* masm, Register receiver, Register scratch1,
|
||||
Register scratch2, Label* miss_label) {
|
||||
__ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
|
||||
// TryGetFunctionPrototype can't put the result directly in x0 because the
|
||||
// 3 inputs registers can't alias and we call this function from
|
||||
// LoadIC::GenerateFunctionPrototype, where receiver is x0. So we explicitly
|
||||
// move the result in x0.
|
||||
__ Mov(x0, scratch1);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
// Generate code to check that a global property cell is empty. Create
|
||||
// the property cell at compilation time if no cell exists for the
|
||||
// property.
|
||||
void PropertyHandlerCompiler::GenerateCheckPropertyCell(
|
||||
MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
|
||||
Register scratch, Label* miss) {
|
||||
Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
|
||||
DCHECK(cell->value()->IsTheHole());
|
||||
__ Mov(scratch, Operand(cell));
|
||||
__ Ldr(scratch, FieldMemOperand(scratch, Cell::kValueOffset));
|
||||
__ JumpIfNotRoot(scratch, Heap::kTheHoleValueRootIndex, miss);
|
||||
}
|
||||
|
||||
|
||||
static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
|
||||
Register holder, Register name,
|
||||
Handle<JSObject> holder_obj) {
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
|
||||
|
||||
__ Push(name);
|
||||
Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
|
||||
DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
|
||||
Register scratch = name;
|
||||
__ Mov(scratch, Operand(interceptor));
|
||||
__ Push(scratch, receiver, holder);
|
||||
}
|
||||
|
||||
|
||||
static void CompileCallLoadPropertyWithInterceptor(
|
||||
MacroAssembler* masm, Register receiver, Register holder, Register name,
|
||||
Handle<JSObject> holder_obj, IC::UtilityId id) {
|
||||
PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
|
||||
|
||||
__ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
|
||||
NamedLoadHandlerCompiler::kInterceptorArgsLength);
|
||||
}
|
||||
|
||||
|
||||
// Generate call to api function.
|
||||
void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
MacroAssembler* masm, const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver, Register scratch,
|
||||
bool is_store, int argc, Register* values) {
|
||||
DCHECK(!AreAliased(receiver, scratch));
|
||||
|
||||
MacroAssembler::PushPopQueue queue(masm);
|
||||
queue.Queue(receiver);
|
||||
// Write the arguments to the stack frame.
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Register arg = values[argc - 1 - i];
|
||||
DCHECK(!AreAliased(receiver, scratch, arg));
|
||||
queue.Queue(arg);
|
||||
}
|
||||
queue.PushQueued();
|
||||
|
||||
DCHECK(optimization.is_simple_api_call());
|
||||
|
||||
// Abi for CallApiFunctionStub.
|
||||
Register callee = x0;
|
||||
Register call_data = x4;
|
||||
Register holder = x2;
|
||||
Register api_function_address = x1;
|
||||
|
||||
// Put holder in place.
|
||||
CallOptimization::HolderLookup holder_lookup;
|
||||
Handle<JSObject> api_holder =
|
||||
optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
|
||||
switch (holder_lookup) {
|
||||
case CallOptimization::kHolderIsReceiver:
|
||||
__ Mov(holder, receiver);
|
||||
break;
|
||||
case CallOptimization::kHolderFound:
|
||||
__ LoadObject(holder, api_holder);
|
||||
break;
|
||||
case CallOptimization::kHolderNotFound:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
Isolate* isolate = masm->isolate();
|
||||
Handle<JSFunction> function = optimization.constant_function();
|
||||
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
|
||||
Handle<Object> call_data_obj(api_call_info->data(), isolate);
|
||||
|
||||
// Put callee in place.
|
||||
__ LoadObject(callee, function);
|
||||
|
||||
bool call_data_undefined = false;
|
||||
// Put call_data in place.
|
||||
if (isolate->heap()->InNewSpace(*call_data_obj)) {
|
||||
__ LoadObject(call_data, api_call_info);
|
||||
__ Ldr(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset));
|
||||
} else if (call_data_obj->IsUndefined()) {
|
||||
call_data_undefined = true;
|
||||
__ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
|
||||
} else {
|
||||
__ LoadObject(call_data, call_data_obj);
|
||||
}
|
||||
|
||||
// Put api_function_address in place.
|
||||
Address function_address = v8::ToCData<Address>(api_call_info->callback());
|
||||
ApiFunction fun(function_address);
|
||||
ExternalReference ref = ExternalReference(
|
||||
&fun, ExternalReference::DIRECT_API_CALL, masm->isolate());
|
||||
__ Mov(api_function_address, ref);
|
||||
|
||||
// Jump to stub.
|
||||
CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
|
||||
__ TailCallStub(&stub);
|
||||
// Do tail-call to runtime routine.
|
||||
__ TailCallRuntime(Runtime::kSetProperty, 4, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -210,621 +32,6 @@ void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
|
||||
Handle<Name> name) {
|
||||
if (!label->is_unused()) {
|
||||
__ Bind(label);
|
||||
__ Mov(this->name(), Operand(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Generate StoreTransition code, value is passed in x0 register.
|
||||
// When leaving generated code after success, the receiver_reg and storage_reg
|
||||
// may be clobbered. Upon branch to miss_label, the receiver and name registers
|
||||
// have their original values.
|
||||
void NamedStoreHandlerCompiler::GenerateStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name, Register receiver_reg,
|
||||
Register storage_reg, Register value_reg, Register scratch1,
|
||||
Register scratch2, Register scratch3, Label* miss_label, Label* slow) {
|
||||
Label exit;
|
||||
|
||||
DCHECK(!AreAliased(receiver_reg, storage_reg, value_reg, scratch1, scratch2,
|
||||
scratch3));
|
||||
|
||||
// We don't need scratch3.
|
||||
scratch3 = NoReg;
|
||||
|
||||
int descriptor = transition->LastAdded();
|
||||
DescriptorArray* descriptors = transition->instance_descriptors();
|
||||
PropertyDetails details = descriptors->GetDetails(descriptor);
|
||||
Representation representation = details.representation();
|
||||
DCHECK(!representation.IsNone());
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
|
||||
__ LoadObject(scratch1, constant);
|
||||
__ Cmp(value_reg, scratch1);
|
||||
__ B(ne, miss_label);
|
||||
} else if (representation.IsSmi()) {
|
||||
__ JumpIfNotSmi(value_reg, miss_label);
|
||||
} else if (representation.IsHeapObject()) {
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType* field_type = descriptors->GetFieldType(descriptor);
|
||||
HeapType::Iterator<Map> it = field_type->Classes();
|
||||
if (!it.Done()) {
|
||||
__ Ldr(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(scratch1, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ B(ne, miss_label);
|
||||
break;
|
||||
}
|
||||
__ B(eq, &do_store);
|
||||
}
|
||||
__ Bind(&do_store);
|
||||
}
|
||||
} else if (representation.IsDouble()) {
|
||||
UseScratchRegisterScope temps(masm());
|
||||
DoubleRegister temp_double = temps.AcquireD();
|
||||
__ SmiUntagToDouble(temp_double, value_reg, kSpeculativeUntag);
|
||||
|
||||
Label do_store;
|
||||
__ JumpIfSmi(value_reg, &do_store);
|
||||
|
||||
__ CheckMap(value_reg, scratch1, Heap::kHeapNumberMapRootIndex, miss_label,
|
||||
DONT_DO_SMI_CHECK);
|
||||
__ Ldr(temp_double, FieldMemOperand(value_reg, HeapNumber::kValueOffset));
|
||||
|
||||
__ Bind(&do_store);
|
||||
__ AllocateHeapNumber(storage_reg, slow, scratch1, scratch2, temp_double,
|
||||
NoReg, MUTABLE);
|
||||
}
|
||||
|
||||
// Stub never generated for objects that require access checks.
|
||||
DCHECK(!transition->is_access_check_needed());
|
||||
|
||||
// Perform map transition for the receiver if necessary.
|
||||
if (details.type() == FIELD &&
|
||||
Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
|
||||
// The properties must be extended before we can store the value.
|
||||
// We jump to a runtime call that extends the properties array.
|
||||
__ Mov(scratch1, Operand(transition));
|
||||
__ Push(receiver_reg, scratch1, value_reg);
|
||||
__ TailCallExternalReference(
|
||||
ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
|
||||
isolate()),
|
||||
3, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the map of the object.
|
||||
__ Mov(scratch1, Operand(transition));
|
||||
__ Str(scratch1, FieldMemOperand(receiver_reg, HeapObject::kMapOffset));
|
||||
|
||||
// Update the write barrier for the map field.
|
||||
__ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs, OMIT_REMEMBERED_SET,
|
||||
OMIT_SMI_CHECK);
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
DCHECK(value_reg.is(x0));
|
||||
__ Ret();
|
||||
return;
|
||||
}
|
||||
|
||||
int index = transition->instance_descriptors()->GetFieldIndex(
|
||||
transition->LastAdded());
|
||||
|
||||
// Adjust for the number of properties stored in the object. Even in the
|
||||
// face of a transition we can use the old map here because the size of the
|
||||
// object and the number of in-object properties is not going to change.
|
||||
index -= transition->inobject_properties();
|
||||
|
||||
// TODO(verwaest): Share this code as a code stub.
|
||||
SmiCheck smi_check =
|
||||
representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
|
||||
Register prop_reg = representation.IsDouble() ? storage_reg : value_reg;
|
||||
if (index < 0) {
|
||||
// Set the property straight into the object.
|
||||
int offset = transition->instance_size() + (index * kPointerSize);
|
||||
__ Str(prop_reg, FieldMemOperand(receiver_reg, offset));
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ Mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs,
|
||||
EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
} else {
|
||||
// Write to the properties array.
|
||||
int offset = index * kPointerSize + FixedArray::kHeaderSize;
|
||||
// Get the properties array
|
||||
__ Ldr(scratch1,
|
||||
FieldMemOperand(receiver_reg, JSObject::kPropertiesOffset));
|
||||
__ Str(prop_reg, FieldMemOperand(scratch1, offset));
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ Mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
|
||||
kLRHasNotBeenSaved, kDontSaveFPRegs,
|
||||
EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
}
|
||||
|
||||
__ Bind(&exit);
|
||||
// Return the value (register x0).
|
||||
DCHECK(value_reg.is(x0));
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
|
||||
Register value_reg,
|
||||
Label* miss_label) {
|
||||
DCHECK(lookup->representation().IsHeapObject());
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
|
||||
__ Ldr(scratch1(), FieldMemOperand(value_reg, HeapObject::kMapOffset));
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(scratch1(), it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ B(ne, miss_label);
|
||||
break;
|
||||
}
|
||||
__ B(eq, &do_store);
|
||||
}
|
||||
__ Bind(&do_store);
|
||||
|
||||
StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
|
||||
lookup->representation());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::CheckPrototypes(
|
||||
Register object_reg, Register holder_reg, Register scratch1,
|
||||
Register scratch2, Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check) {
|
||||
Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
|
||||
|
||||
// object_reg and holder_reg registers can alias.
|
||||
DCHECK(!AreAliased(object_reg, scratch1, scratch2));
|
||||
DCHECK(!AreAliased(holder_reg, scratch1, scratch2));
|
||||
|
||||
// Keep track of the current object in register reg.
|
||||
Register reg = object_reg;
|
||||
int depth = 0;
|
||||
|
||||
Handle<JSObject> current = Handle<JSObject>::null();
|
||||
if (type()->IsConstant()) {
|
||||
current = Handle<JSObject>::cast(type()->AsConstant()->Value());
|
||||
}
|
||||
Handle<JSObject> prototype = Handle<JSObject>::null();
|
||||
Handle<Map> current_map = receiver_map;
|
||||
Handle<Map> holder_map(holder()->map());
|
||||
// Traverse the prototype chain and check the maps in the prototype chain for
|
||||
// fast and global objects or do negative lookup for normal objects.
|
||||
while (!current_map.is_identical_to(holder_map)) {
|
||||
++depth;
|
||||
|
||||
// Only global objects and objects that do not require access
|
||||
// checks are allowed in stubs.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
|
||||
prototype = handle(JSObject::cast(current_map->prototype()));
|
||||
if (current_map->is_dictionary_map() &&
|
||||
!current_map->IsJSGlobalObjectMap()) {
|
||||
DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(current.is_null() || (current->property_dictionary()->FindEntry(
|
||||
name) == NameDictionary::kNotFound));
|
||||
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
|
||||
scratch2);
|
||||
|
||||
__ Ldr(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset));
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
__ Ldr(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
// Two possible reasons for loading the prototype from the map:
|
||||
// (1) Can't store references to new space in code.
|
||||
// (2) Handler is shared for all receivers with the same prototype
|
||||
// map (but not necessarily the same prototype instance).
|
||||
bool load_prototype_from_map =
|
||||
heap()->InNewSpace(*prototype) || depth == 1;
|
||||
Register map_reg = scratch1;
|
||||
__ Ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset));
|
||||
|
||||
if (depth != 1 || check == CHECK_ALL_MAPS) {
|
||||
__ CheckMap(map_reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Check access rights to the global object. This has to happen after
|
||||
// the map check so that we know that the object is actually a global
|
||||
// object.
|
||||
// This allows us to install generated handlers for accesses to the
|
||||
// global proxy (as opposed to using slow ICs). See corresponding code
|
||||
// in LookupForRead().
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
UseScratchRegisterScope temps(masm());
|
||||
__ CheckAccessGlobalProxy(reg, scratch2, temps.AcquireX(), miss);
|
||||
} else if (current_map->IsJSGlobalObjectMap()) {
|
||||
GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
|
||||
name, scratch2, miss);
|
||||
}
|
||||
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
|
||||
if (load_prototype_from_map) {
|
||||
__ Ldr(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset));
|
||||
} else {
|
||||
__ Mov(reg, Operand(prototype));
|
||||
}
|
||||
}
|
||||
|
||||
// Go to the next object in the prototype chain.
|
||||
current = prototype;
|
||||
current_map = handle(current->map());
|
||||
}
|
||||
|
||||
// Log the check depth.
|
||||
LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
|
||||
|
||||
// Check the holder map.
|
||||
if (depth != 0 || check == CHECK_ALL_MAPS) {
|
||||
// Check the holder map.
|
||||
__ CheckMap(reg, scratch1, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Perform security check for access to the global object.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
|
||||
}
|
||||
|
||||
// Return the register containing the holder.
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ B(&success);
|
||||
|
||||
__ Bind(miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
|
||||
__ Bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ B(&success);
|
||||
|
||||
GenerateRestoreName(miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
|
||||
__ Bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
|
||||
// Return the constant value.
|
||||
__ LoadObject(x0, value);
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadCallback(
|
||||
Register reg, Handle<ExecutableAccessorInfo> callback) {
|
||||
DCHECK(!AreAliased(scratch2(), scratch3(), scratch4(), reg));
|
||||
|
||||
// Build ExecutableAccessorInfo::args_ list on the stack and push property
|
||||
// name below the exit frame to make GC aware of them and store pointers to
|
||||
// them.
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
|
||||
|
||||
__ Push(receiver());
|
||||
|
||||
if (heap()->InNewSpace(callback->data())) {
|
||||
__ Mov(scratch3(), Operand(callback));
|
||||
__ Ldr(scratch3(),
|
||||
FieldMemOperand(scratch3(), ExecutableAccessorInfo::kDataOffset));
|
||||
} else {
|
||||
__ Mov(scratch3(), Operand(Handle<Object>(callback->data(), isolate())));
|
||||
}
|
||||
__ LoadRoot(scratch4(), Heap::kUndefinedValueRootIndex);
|
||||
__ Mov(scratch2(), Operand(ExternalReference::isolate_address(isolate())));
|
||||
__ Push(scratch3(), scratch4(), scratch4(), scratch2(), reg, name());
|
||||
|
||||
Register args_addr = scratch2();
|
||||
__ Add(args_addr, __ StackPointer(), kPointerSize);
|
||||
|
||||
// Stack at this point:
|
||||
// sp[40] callback data
|
||||
// sp[32] undefined
|
||||
// sp[24] undefined
|
||||
// sp[16] isolate
|
||||
// args_addr -> sp[8] reg
|
||||
// sp[0] name
|
||||
|
||||
// Abi for CallApiGetter.
|
||||
Register getter_address_reg = x2;
|
||||
|
||||
// Set up the call.
|
||||
Address getter_address = v8::ToCData<Address>(callback->getter());
|
||||
ApiFunction fun(getter_address);
|
||||
ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL;
|
||||
ExternalReference ref = ExternalReference(&fun, type, isolate());
|
||||
__ Mov(getter_address_reg, ref);
|
||||
|
||||
CallApiGetterStub stub(isolate());
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
|
||||
LookupIterator* it, Register holder_reg) {
|
||||
DCHECK(!AreAliased(receiver(), this->name(), scratch1(), scratch2(),
|
||||
scratch3()));
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
|
||||
// Compile the interceptor call, followed by inline code to load the
|
||||
// property from further up the prototype chain if the call fails.
|
||||
// Check that the maps haven't changed.
|
||||
DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
|
||||
|
||||
// Preserve the receiver register explicitly whenever it is different from the
|
||||
// holder and it is needed should the interceptor return without any result.
|
||||
// The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
|
||||
// case might cause a miss during the prototype check.
|
||||
bool must_perform_prototype_check =
|
||||
!holder().is_identical_to(it->GetHolder<JSObject>());
|
||||
bool must_preserve_receiver_reg =
|
||||
!receiver().is(holder_reg) &&
|
||||
(it->property_kind() == LookupIterator::ACCESSOR ||
|
||||
must_perform_prototype_check);
|
||||
|
||||
// Save necessary data before invoking an interceptor.
|
||||
// Requires a frame to make GC aware of pushed pointers.
|
||||
{
|
||||
FrameScope frame_scope(masm(), StackFrame::INTERNAL);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Push(receiver(), holder_reg, this->name());
|
||||
} else {
|
||||
__ Push(holder_reg, this->name());
|
||||
}
|
||||
// Invoke an interceptor. Note: map checks from receiver to
|
||||
// interceptor's holder has been compiled before (see a caller
|
||||
// of this method.)
|
||||
CompileCallLoadPropertyWithInterceptor(
|
||||
masm(), receiver(), holder_reg, this->name(), holder(),
|
||||
IC::kLoadPropertyWithInterceptorOnly);
|
||||
|
||||
// Check if interceptor provided a value for property. If it's
|
||||
// the case, return immediately.
|
||||
Label interceptor_failed;
|
||||
__ JumpIfRoot(x0, Heap::kNoInterceptorResultSentinelRootIndex,
|
||||
&interceptor_failed);
|
||||
frame_scope.GenerateLeaveFrame();
|
||||
__ Ret();
|
||||
|
||||
__ Bind(&interceptor_failed);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Pop(this->name(), holder_reg, receiver());
|
||||
} else {
|
||||
__ Pop(this->name(), holder_reg);
|
||||
}
|
||||
// Leave the internal frame.
|
||||
}
|
||||
|
||||
GenerateLoadPostInterceptor(it, holder_reg);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
|
||||
// Call the runtime system to load the interceptor.
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
|
||||
holder());
|
||||
|
||||
ExternalReference ref = ExternalReference(
|
||||
IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(
|
||||
ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback) {
|
||||
ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreCallback");
|
||||
Register holder_reg = Frontend(receiver(), name);
|
||||
|
||||
// Stub never generated for non-global objects that require access checks.
|
||||
DCHECK(holder()->IsJSGlobalProxy() || !holder()->IsAccessCheckNeeded());
|
||||
|
||||
// receiver() and holder_reg can alias.
|
||||
DCHECK(!AreAliased(receiver(), scratch1(), scratch2(), value()));
|
||||
DCHECK(!AreAliased(holder_reg, scratch1(), scratch2(), value()));
|
||||
__ Mov(scratch1(), Operand(callback));
|
||||
__ Mov(scratch2(), Operand(name));
|
||||
__ Push(receiver(), holder_reg, scratch1(), scratch2(), value());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_callback_property =
|
||||
ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
|
||||
__ TailCallExternalReference(store_callback_property, 5, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- lr : return address
|
||||
// -----------------------------------
|
||||
Label miss;
|
||||
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
// Save value register, so we can restore it later.
|
||||
__ Push(value());
|
||||
|
||||
if (!setter.is_null()) {
|
||||
// Call the JavaScript setter with receiver and value on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ Ldr(receiver,
|
||||
FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver, value());
|
||||
ParameterCount actual(1);
|
||||
ParameterCount expected(setter);
|
||||
__ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// We have to return the passed value, not the return value of the setter.
|
||||
__ Pop(x0);
|
||||
|
||||
// Restore context register.
|
||||
__ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
|
||||
Handle<Name> name) {
|
||||
Label miss;
|
||||
|
||||
ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreInterceptor");
|
||||
|
||||
__ Push(receiver(), this->name(), value());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_ic_property = ExternalReference(
|
||||
IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(store_ic_property, 3, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> getter) {
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
if (!getter.is_null()) {
|
||||
// Call the JavaScript getter with the receiver on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ Ldr(receiver,
|
||||
FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver);
|
||||
ParameterCount actual(0);
|
||||
ParameterCount expected(getter);
|
||||
__ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// Restore context register.
|
||||
__ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ Ret();
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
|
||||
Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
|
||||
Label miss;
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
|
||||
// Get the value from the cell.
|
||||
Register result = StoreIC::ValueRegister();
|
||||
__ Mov(result, Operand(cell));
|
||||
__ Ldr(result, FieldMemOperand(result, Cell::kValueOffset));
|
||||
|
||||
// Check for deleted property if property can actually be deleted.
|
||||
if (is_configurable) {
|
||||
__ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &miss);
|
||||
}
|
||||
|
||||
Counters* counters = isolate()->counters();
|
||||
__ IncrementCounter(counters->named_load_global_stub(), 1, x1, x3);
|
||||
__ Ret();
|
||||
|
||||
FrontendFooter(name, &miss);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
|
||||
CodeHandleList* handlers,
|
||||
Handle<Name> name,
|
||||
@ -914,51 +121,6 @@ Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
void ElementHandlerCompiler::GenerateLoadDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
// The return address is in lr.
|
||||
Label slow, miss;
|
||||
|
||||
Register result = x0;
|
||||
Register key = LoadIC::NameRegister();
|
||||
Register receiver = LoadIC::ReceiverRegister();
|
||||
DCHECK(receiver.is(x1));
|
||||
DCHECK(key.is(x2));
|
||||
|
||||
__ JumpIfNotSmi(key, &miss);
|
||||
__ Ldr(x4, FieldMemOperand(receiver, JSObject::kElementsOffset));
|
||||
__ LoadFromNumberDictionary(&slow, x4, key, result, x7, x3, x5, x6);
|
||||
__ Ret();
|
||||
|
||||
__ Bind(&slow);
|
||||
__ IncrementCounter(
|
||||
masm->isolate()->counters()->keyed_load_external_array_slow(), 1, x4, x3);
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
|
||||
|
||||
// Miss case, call the runtime.
|
||||
__ Bind(&miss);
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
|
||||
}
|
||||
|
||||
|
||||
void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
|
||||
StrictMode strict_mode) {
|
||||
ASM_LOCATION("PropertyICCompiler::GenerateRuntimeSetProperty");
|
||||
|
||||
__ Push(StoreIC::ReceiverRegister(), StoreIC::NameRegister(),
|
||||
StoreIC::ValueRegister());
|
||||
|
||||
__ Mov(x10, Smi::FromInt(strict_mode));
|
||||
__ Push(x10);
|
||||
|
||||
// Do tail-call to runtime routine.
|
||||
__ TailCallRuntime(Runtime::kSetProperty, 4, 1);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
398
src/ic/handler-compiler.cc
Normal file
398
src/ic/handler-compiler.cc
Normal file
@ -0,0 +1,398 @@
|
||||
// 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.
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
#include "src/ic/ic-inl.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
|
||||
Handle<Code> PropertyHandlerCompiler::Find(Handle<Name> name,
|
||||
Handle<Map> stub_holder,
|
||||
Code::Kind kind,
|
||||
CacheHolderFlag cache_holder,
|
||||
Code::StubType type) {
|
||||
Code::Flags flags = Code::ComputeHandlerFlags(kind, type, cache_holder);
|
||||
Object* probe = stub_holder->FindInCodeCache(*name, flags);
|
||||
if (probe->IsCode()) return handle(Code::cast(probe));
|
||||
return Handle<Code>::null();
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::ComputeLoadNonexistent(
|
||||
Handle<Name> name, Handle<HeapType> type) {
|
||||
Isolate* isolate = name->GetIsolate();
|
||||
Handle<Map> receiver_map = IC::TypeToMap(*type, isolate);
|
||||
if (receiver_map->prototype()->IsNull()) {
|
||||
// TODO(jkummerow/verwaest): If there is no prototype and the property
|
||||
// is nonexistent, introduce a builtin to handle this (fast properties
|
||||
// -> return undefined, dictionary properties -> do negative lookup).
|
||||
return Handle<Code>();
|
||||
}
|
||||
CacheHolderFlag flag;
|
||||
Handle<Map> stub_holder_map =
|
||||
IC::GetHandlerCacheHolder(*type, false, isolate, &flag);
|
||||
|
||||
// If no dictionary mode objects are present in the prototype chain, the load
|
||||
// nonexistent IC stub can be shared for all names for a given map and we use
|
||||
// the empty string for the map cache in that case. If there are dictionary
|
||||
// mode objects involved, we need to do negative lookups in the stub and
|
||||
// therefore the stub will be specific to the name.
|
||||
Handle<Name> cache_name =
|
||||
receiver_map->is_dictionary_map()
|
||||
? name
|
||||
: Handle<Name>::cast(isolate->factory()->nonexistent_symbol());
|
||||
Handle<Map> current_map = stub_holder_map;
|
||||
Handle<JSObject> last(JSObject::cast(receiver_map->prototype()));
|
||||
while (true) {
|
||||
if (current_map->is_dictionary_map()) cache_name = name;
|
||||
if (current_map->prototype()->IsNull()) break;
|
||||
last = handle(JSObject::cast(current_map->prototype()));
|
||||
current_map = handle(last->map());
|
||||
}
|
||||
// Compile the stub that is either shared for all names or
|
||||
// name specific if there are global objects involved.
|
||||
Handle<Code> handler = PropertyHandlerCompiler::Find(
|
||||
cache_name, stub_holder_map, Code::LOAD_IC, flag, Code::FAST);
|
||||
if (!handler.is_null()) return handler;
|
||||
|
||||
NamedLoadHandlerCompiler compiler(isolate, type, last, flag);
|
||||
handler = compiler.CompileLoadNonexistent(cache_name);
|
||||
Map::UpdateCodeCache(stub_holder_map, cache_name, handler);
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyHandlerCompiler::GetCode(Code::Kind kind,
|
||||
Code::StubType type,
|
||||
Handle<Name> name) {
|
||||
Code::Flags flags = Code::ComputeHandlerFlags(kind, type, cache_holder());
|
||||
Handle<Code> code = GetCodeWithFlags(flags, name);
|
||||
PROFILE(isolate(), CodeCreateEvent(Logger::STUB_TAG, *code, *name));
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Register NamedLoadHandlerCompiler::FrontendHeader(Register object_reg,
|
||||
Handle<Name> name,
|
||||
Label* miss) {
|
||||
PrototypeCheckType check_type = CHECK_ALL_MAPS;
|
||||
int function_index = -1;
|
||||
if (type()->Is(HeapType::String())) {
|
||||
function_index = Context::STRING_FUNCTION_INDEX;
|
||||
} else if (type()->Is(HeapType::Symbol())) {
|
||||
function_index = Context::SYMBOL_FUNCTION_INDEX;
|
||||
} else if (type()->Is(HeapType::Number())) {
|
||||
function_index = Context::NUMBER_FUNCTION_INDEX;
|
||||
} else if (type()->Is(HeapType::Boolean())) {
|
||||
function_index = Context::BOOLEAN_FUNCTION_INDEX;
|
||||
} else {
|
||||
check_type = SKIP_RECEIVER;
|
||||
}
|
||||
|
||||
if (check_type == CHECK_ALL_MAPS) {
|
||||
GenerateDirectLoadGlobalFunctionPrototype(masm(), function_index,
|
||||
scratch1(), miss);
|
||||
Object* function = isolate()->native_context()->get(function_index);
|
||||
Object* prototype = JSFunction::cast(function)->instance_prototype();
|
||||
set_type_for_object(handle(prototype, isolate()));
|
||||
object_reg = scratch1();
|
||||
}
|
||||
|
||||
// Check that the maps starting from the prototype haven't changed.
|
||||
return CheckPrototypes(object_reg, scratch1(), scratch2(), scratch3(), name,
|
||||
miss, check_type);
|
||||
}
|
||||
|
||||
|
||||
// Frontend for store uses the name register. It has to be restored before a
|
||||
// miss.
|
||||
Register NamedStoreHandlerCompiler::FrontendHeader(Register object_reg,
|
||||
Handle<Name> name,
|
||||
Label* miss) {
|
||||
return CheckPrototypes(object_reg, this->name(), scratch1(), scratch2(), name,
|
||||
miss, SKIP_RECEIVER);
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::Frontend(Register object_reg,
|
||||
Handle<Name> name) {
|
||||
Label miss;
|
||||
Register reg = FrontendHeader(object_reg, name, &miss);
|
||||
FrontendFooter(name, &miss);
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void PropertyHandlerCompiler::NonexistentFrontendHeader(Handle<Name> name,
|
||||
Label* miss,
|
||||
Register scratch1,
|
||||
Register scratch2) {
|
||||
Register holder_reg;
|
||||
Handle<Map> last_map;
|
||||
if (holder().is_null()) {
|
||||
holder_reg = receiver();
|
||||
last_map = IC::TypeToMap(*type(), isolate());
|
||||
// If |type| has null as its prototype, |holder()| is
|
||||
// Handle<JSObject>::null().
|
||||
DCHECK(last_map->prototype() == isolate()->heap()->null_value());
|
||||
} else {
|
||||
holder_reg = FrontendHeader(receiver(), name, miss);
|
||||
last_map = handle(holder()->map());
|
||||
}
|
||||
|
||||
if (last_map->is_dictionary_map()) {
|
||||
if (last_map->IsJSGlobalObjectMap()) {
|
||||
Handle<JSGlobalObject> global =
|
||||
holder().is_null()
|
||||
? Handle<JSGlobalObject>::cast(type()->AsConstant()->Value())
|
||||
: Handle<JSGlobalObject>::cast(holder());
|
||||
GenerateCheckPropertyCell(masm(), global, name, scratch1, miss);
|
||||
} else {
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(holder().is_null() ||
|
||||
holder()->property_dictionary()->FindEntry(name) ==
|
||||
NameDictionary::kNotFound);
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, holder_reg, name, scratch1,
|
||||
scratch2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadField(Handle<Name> name,
|
||||
FieldIndex field) {
|
||||
Register reg = Frontend(receiver(), name);
|
||||
__ Move(receiver(), reg);
|
||||
LoadFieldStub stub(isolate(), field);
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadConstant(Handle<Name> name,
|
||||
int constant_index) {
|
||||
Register reg = Frontend(receiver(), name);
|
||||
__ Move(receiver(), reg);
|
||||
LoadConstantStub stub(isolate(), constant_index);
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadNonexistent(
|
||||
Handle<Name> name) {
|
||||
Label miss;
|
||||
NonexistentFrontendHeader(name, &miss, scratch2(), scratch3());
|
||||
GenerateLoadConstant(isolate()->factory()->undefined_value());
|
||||
FrontendFooter(name, &miss);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadCallback(
|
||||
Handle<Name> name, Handle<ExecutableAccessorInfo> callback) {
|
||||
Register reg = Frontend(receiver(), name);
|
||||
GenerateLoadCallback(reg, callback);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadCallback(
|
||||
Handle<Name> name, const CallOptimization& call_optimization) {
|
||||
DCHECK(call_optimization.is_simple_api_call());
|
||||
Frontend(receiver(), name);
|
||||
Handle<Map> receiver_map = IC::TypeToMap(*type(), isolate());
|
||||
GenerateFastApiCall(masm(), call_optimization, receiver_map, receiver(),
|
||||
scratch1(), false, 0, NULL);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadInterceptor(
|
||||
LookupIterator* it) {
|
||||
// So far the most popular follow ups for interceptor loads are FIELD and
|
||||
// ExecutableAccessorInfo, so inline only them. Other cases may be added
|
||||
// later.
|
||||
bool inline_followup = it->state() == LookupIterator::PROPERTY;
|
||||
if (inline_followup) {
|
||||
switch (it->property_kind()) {
|
||||
case LookupIterator::DATA:
|
||||
inline_followup = it->property_details().type() == FIELD;
|
||||
break;
|
||||
case LookupIterator::ACCESSOR: {
|
||||
Handle<Object> accessors = it->GetAccessors();
|
||||
inline_followup = accessors->IsExecutableAccessorInfo();
|
||||
if (!inline_followup) break;
|
||||
Handle<ExecutableAccessorInfo> info =
|
||||
Handle<ExecutableAccessorInfo>::cast(accessors);
|
||||
inline_followup = info->getter() != NULL &&
|
||||
ExecutableAccessorInfo::IsCompatibleReceiverType(
|
||||
isolate(), info, type());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Register reg = Frontend(receiver(), it->name());
|
||||
if (inline_followup) {
|
||||
// TODO(368): Compile in the whole chain: all the interceptors in
|
||||
// prototypes and ultimate answer.
|
||||
GenerateLoadInterceptorWithFollowup(it, reg);
|
||||
} else {
|
||||
GenerateLoadInterceptor(reg);
|
||||
}
|
||||
return GetCode(kind(), Code::FAST, it->name());
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadPostInterceptor(
|
||||
LookupIterator* it, Register interceptor_reg) {
|
||||
Handle<JSObject> real_named_property_holder(it->GetHolder<JSObject>());
|
||||
|
||||
set_type_for_object(holder());
|
||||
set_holder(real_named_property_holder);
|
||||
Register reg = Frontend(interceptor_reg, it->name());
|
||||
|
||||
switch (it->property_kind()) {
|
||||
case LookupIterator::DATA: {
|
||||
DCHECK_EQ(FIELD, it->property_details().type());
|
||||
__ Move(receiver(), reg);
|
||||
LoadFieldStub stub(isolate(), it->GetFieldIndex());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
break;
|
||||
}
|
||||
case LookupIterator::ACCESSOR:
|
||||
Handle<ExecutableAccessorInfo> info =
|
||||
Handle<ExecutableAccessorInfo>::cast(it->GetAccessors());
|
||||
DCHECK_NE(NULL, info->getter());
|
||||
GenerateLoadCallback(reg, info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadViaGetter(
|
||||
Handle<Name> name, Handle<JSFunction> getter) {
|
||||
Frontend(receiver(), name);
|
||||
GenerateLoadViaGetter(masm(), type(), receiver(), getter);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
// TODO(verwaest): Cleanup. holder() is actually the receiver.
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name) {
|
||||
Label miss, slow;
|
||||
|
||||
// Ensure no transitions to deprecated maps are followed.
|
||||
__ CheckMapDeprecated(transition, scratch1(), &miss);
|
||||
|
||||
// Check that we are allowed to write this.
|
||||
bool is_nonexistent = holder()->map() == transition->GetBackPointer();
|
||||
if (is_nonexistent) {
|
||||
// Find the top object.
|
||||
Handle<JSObject> last;
|
||||
PrototypeIterator iter(isolate(), holder());
|
||||
while (!iter.IsAtEnd()) {
|
||||
last = Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
|
||||
iter.Advance();
|
||||
}
|
||||
if (!last.is_null()) set_holder(last);
|
||||
NonexistentFrontendHeader(name, &miss, scratch1(), scratch2());
|
||||
} else {
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
DCHECK(holder()->HasFastProperties());
|
||||
}
|
||||
|
||||
GenerateStoreTransition(transition, name, receiver(), this->name(), value(),
|
||||
scratch1(), scratch2(), scratch3(), &miss, &slow);
|
||||
|
||||
GenerateRestoreName(&miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
|
||||
GenerateRestoreName(&slow, name);
|
||||
TailCallBuiltin(masm(), SlowBuiltin(kind()));
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreField(LookupIterator* it) {
|
||||
Label miss;
|
||||
GenerateStoreField(it, value(), &miss);
|
||||
__ bind(&miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
return GetCode(kind(), Code::FAST, it->name());
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreViaSetter(
|
||||
Handle<JSObject> object, Handle<Name> name, Handle<JSFunction> setter) {
|
||||
Frontend(receiver(), name);
|
||||
GenerateStoreViaSetter(masm(), type(), receiver(), setter);
|
||||
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
const CallOptimization& call_optimization) {
|
||||
Frontend(receiver(), name);
|
||||
Register values[] = {value()};
|
||||
GenerateFastApiCall(masm(), call_optimization, handle(object->map()),
|
||||
receiver(), scratch1(), true, 1, values);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
|
||||
|
||||
void ElementHandlerCompiler::CompileElementHandlers(
|
||||
MapHandleList* receiver_maps, CodeHandleList* handlers) {
|
||||
for (int i = 0; i < receiver_maps->length(); ++i) {
|
||||
Handle<Map> receiver_map = receiver_maps->at(i);
|
||||
Handle<Code> cached_stub;
|
||||
|
||||
if ((receiver_map->instance_type() & kNotStringTag) == 0) {
|
||||
cached_stub = isolate()->builtins()->KeyedLoadIC_String();
|
||||
} else if (receiver_map->instance_type() < FIRST_JS_RECEIVER_TYPE) {
|
||||
cached_stub = isolate()->builtins()->KeyedLoadIC_Slow();
|
||||
} else {
|
||||
bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE;
|
||||
ElementsKind elements_kind = receiver_map->elements_kind();
|
||||
|
||||
if (IsFastElementsKind(elements_kind) ||
|
||||
IsExternalArrayElementsKind(elements_kind) ||
|
||||
IsFixedTypedArrayElementsKind(elements_kind)) {
|
||||
cached_stub = LoadFastElementStub(isolate(), is_js_array, elements_kind)
|
||||
.GetCode();
|
||||
} else if (elements_kind == SLOPPY_ARGUMENTS_ELEMENTS) {
|
||||
cached_stub = isolate()->builtins()->KeyedLoadIC_SloppyArguments();
|
||||
} else {
|
||||
DCHECK(elements_kind == DICTIONARY_ELEMENTS);
|
||||
cached_stub = LoadDictionaryElementStub(isolate()).GetCode();
|
||||
}
|
||||
}
|
||||
|
||||
handlers->Add(cached_stub);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ElementHandlerCompiler::GenerateStoreDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
KeyedStoreIC::GenerateSlow(masm);
|
||||
}
|
||||
}
|
||||
} // namespace v8::internal
|
275
src/ic/handler-compiler.h
Normal file
275
src/ic/handler-compiler.h
Normal file
@ -0,0 +1,275 @@
|
||||
// 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_IC_HANDLER_COMPILER_H_
|
||||
#define V8_IC_HANDLER_COMPILER_H_
|
||||
|
||||
#include "src/ic/access-compiler.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
class CallOptimization;
|
||||
|
||||
enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER };
|
||||
|
||||
class PropertyHandlerCompiler : public PropertyAccessCompiler {
|
||||
public:
|
||||
static Handle<Code> Find(Handle<Name> name, Handle<Map> map, Code::Kind kind,
|
||||
CacheHolderFlag cache_holder, Code::StubType type);
|
||||
|
||||
protected:
|
||||
PropertyHandlerCompiler(Isolate* isolate, Code::Kind kind,
|
||||
Handle<HeapType> type, Handle<JSObject> holder,
|
||||
CacheHolderFlag cache_holder)
|
||||
: PropertyAccessCompiler(isolate, kind, cache_holder),
|
||||
type_(type),
|
||||
holder_(holder) {}
|
||||
|
||||
virtual ~PropertyHandlerCompiler() {}
|
||||
|
||||
virtual Register FrontendHeader(Register object_reg, Handle<Name> name,
|
||||
Label* miss) {
|
||||
UNREACHABLE();
|
||||
return receiver();
|
||||
}
|
||||
|
||||
virtual void FrontendFooter(Handle<Name> name, Label* miss) { UNREACHABLE(); }
|
||||
|
||||
Register Frontend(Register object_reg, Handle<Name> name);
|
||||
void NonexistentFrontendHeader(Handle<Name> name, Label* miss,
|
||||
Register scratch1, Register scratch2);
|
||||
|
||||
// TODO(verwaest): Make non-static.
|
||||
static void GenerateFastApiCall(MacroAssembler* masm,
|
||||
const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver,
|
||||
Register scratch, bool is_store, int argc,
|
||||
Register* values);
|
||||
|
||||
// Helper function used to check that the dictionary doesn't contain
|
||||
// the property. This function may return false negatives, so miss_label
|
||||
// must always call a backup property check that is complete.
|
||||
// This function is safe to call if the receiver has fast properties.
|
||||
// Name must be unique and receiver must be a heap object.
|
||||
static void GenerateDictionaryNegativeLookup(MacroAssembler* masm,
|
||||
Label* miss_label,
|
||||
Register receiver,
|
||||
Handle<Name> name, Register r0,
|
||||
Register r1);
|
||||
|
||||
// Generate code to check that a global property cell is empty. Create
|
||||
// the property cell at compilation time if no cell exists for the
|
||||
// property.
|
||||
static void GenerateCheckPropertyCell(MacroAssembler* masm,
|
||||
Handle<JSGlobalObject> global,
|
||||
Handle<Name> name, Register scratch,
|
||||
Label* miss);
|
||||
|
||||
// Generates code that verifies that the property holder has not changed
|
||||
// (checking maps of objects in the prototype chain for fast and global
|
||||
// objects or doing negative lookup for slow objects, ensures that the
|
||||
// property cells for global objects are still empty) and checks that the map
|
||||
// of the holder has not changed. If necessary the function also generates
|
||||
// code for security check in case of global object holders. Helps to make
|
||||
// sure that the current IC is still valid.
|
||||
//
|
||||
// The scratch and holder registers are always clobbered, but the object
|
||||
// register is only clobbered if it the same as the holder register. The
|
||||
// function returns a register containing the holder - either object_reg or
|
||||
// holder_reg.
|
||||
Register CheckPrototypes(Register object_reg, Register holder_reg,
|
||||
Register scratch1, Register scratch2,
|
||||
Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check = CHECK_ALL_MAPS);
|
||||
|
||||
Handle<Code> GetCode(Code::Kind kind, Code::StubType type, Handle<Name> name);
|
||||
void set_type_for_object(Handle<Object> object) {
|
||||
type_ = IC::CurrentTypeOf(object, isolate());
|
||||
}
|
||||
void set_holder(Handle<JSObject> holder) { holder_ = holder; }
|
||||
Handle<HeapType> type() const { return type_; }
|
||||
Handle<JSObject> holder() const { return holder_; }
|
||||
|
||||
private:
|
||||
Handle<HeapType> type_;
|
||||
Handle<JSObject> holder_;
|
||||
};
|
||||
|
||||
|
||||
class NamedLoadHandlerCompiler : public PropertyHandlerCompiler {
|
||||
public:
|
||||
NamedLoadHandlerCompiler(Isolate* isolate, Handle<HeapType> type,
|
||||
Handle<JSObject> holder,
|
||||
CacheHolderFlag cache_holder)
|
||||
: PropertyHandlerCompiler(isolate, Code::LOAD_IC, type, holder,
|
||||
cache_holder) {}
|
||||
|
||||
virtual ~NamedLoadHandlerCompiler() {}
|
||||
|
||||
Handle<Code> CompileLoadField(Handle<Name> name, FieldIndex index);
|
||||
|
||||
Handle<Code> CompileLoadCallback(Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback);
|
||||
|
||||
Handle<Code> CompileLoadCallback(Handle<Name> name,
|
||||
const CallOptimization& call_optimization);
|
||||
|
||||
Handle<Code> CompileLoadConstant(Handle<Name> name, int constant_index);
|
||||
|
||||
// The LookupIterator is used to perform a lookup behind the interceptor. If
|
||||
// the iterator points to a LookupIterator::PROPERTY, its access will be
|
||||
// inlined.
|
||||
Handle<Code> CompileLoadInterceptor(LookupIterator* it);
|
||||
|
||||
Handle<Code> CompileLoadViaGetter(Handle<Name> name,
|
||||
Handle<JSFunction> getter);
|
||||
|
||||
Handle<Code> CompileLoadGlobal(Handle<PropertyCell> cell, Handle<Name> name,
|
||||
bool is_configurable);
|
||||
|
||||
// Static interface
|
||||
static Handle<Code> ComputeLoadNonexistent(Handle<Name> name,
|
||||
Handle<HeapType> type);
|
||||
|
||||
static void GenerateLoadViaGetter(MacroAssembler* masm, Handle<HeapType> type,
|
||||
Register receiver,
|
||||
Handle<JSFunction> getter);
|
||||
|
||||
static void GenerateLoadViaGetterForDeopt(MacroAssembler* masm) {
|
||||
GenerateLoadViaGetter(masm, Handle<HeapType>::null(), no_reg,
|
||||
Handle<JSFunction>());
|
||||
}
|
||||
|
||||
static void GenerateLoadFunctionPrototype(MacroAssembler* masm,
|
||||
Register receiver,
|
||||
Register scratch1,
|
||||
Register scratch2,
|
||||
Label* miss_label);
|
||||
|
||||
// These constants describe the structure of the interceptor arguments on the
|
||||
// stack. The arguments are pushed by the (platform-specific)
|
||||
// PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and
|
||||
// LoadWithInterceptor.
|
||||
static const int kInterceptorArgsNameIndex = 0;
|
||||
static const int kInterceptorArgsInfoIndex = 1;
|
||||
static const int kInterceptorArgsThisIndex = 2;
|
||||
static const int kInterceptorArgsHolderIndex = 3;
|
||||
static const int kInterceptorArgsLength = 4;
|
||||
|
||||
protected:
|
||||
virtual Register FrontendHeader(Register object_reg, Handle<Name> name,
|
||||
Label* miss);
|
||||
|
||||
virtual void FrontendFooter(Handle<Name> name, Label* miss);
|
||||
|
||||
private:
|
||||
Handle<Code> CompileLoadNonexistent(Handle<Name> name);
|
||||
void GenerateLoadConstant(Handle<Object> value);
|
||||
void GenerateLoadCallback(Register reg,
|
||||
Handle<ExecutableAccessorInfo> callback);
|
||||
void GenerateLoadCallback(const CallOptimization& call_optimization,
|
||||
Handle<Map> receiver_map);
|
||||
void GenerateLoadInterceptor(Register holder_reg);
|
||||
void GenerateLoadInterceptorWithFollowup(LookupIterator* it,
|
||||
Register holder_reg);
|
||||
void GenerateLoadPostInterceptor(LookupIterator* it, Register reg);
|
||||
|
||||
// Generates prototype loading code that uses the objects from the
|
||||
// context we were in when this function was called. If the context
|
||||
// has changed, a jump to miss is performed. This ties the generated
|
||||
// code to a particular context and so must not be used in cases
|
||||
// where the generated code is not allowed to have references to
|
||||
// objects from a context.
|
||||
static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm,
|
||||
int index,
|
||||
Register prototype,
|
||||
Label* miss);
|
||||
|
||||
|
||||
Register scratch4() { return registers_[5]; }
|
||||
};
|
||||
|
||||
|
||||
class NamedStoreHandlerCompiler : public PropertyHandlerCompiler {
|
||||
public:
|
||||
explicit NamedStoreHandlerCompiler(Isolate* isolate, Handle<HeapType> type,
|
||||
Handle<JSObject> holder)
|
||||
: PropertyHandlerCompiler(isolate, Code::STORE_IC, type, holder,
|
||||
kCacheOnReceiver) {}
|
||||
|
||||
virtual ~NamedStoreHandlerCompiler() {}
|
||||
|
||||
Handle<Code> CompileStoreTransition(Handle<Map> transition,
|
||||
Handle<Name> name);
|
||||
Handle<Code> CompileStoreField(LookupIterator* it);
|
||||
Handle<Code> CompileStoreCallback(Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback);
|
||||
Handle<Code> CompileStoreCallback(Handle<JSObject> object, Handle<Name> name,
|
||||
const CallOptimization& call_optimization);
|
||||
Handle<Code> CompileStoreViaSetter(Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<JSFunction> setter);
|
||||
Handle<Code> CompileStoreInterceptor(Handle<Name> name);
|
||||
|
||||
static void GenerateStoreViaSetter(MacroAssembler* masm,
|
||||
Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter);
|
||||
|
||||
static void GenerateStoreViaSetterForDeopt(MacroAssembler* masm) {
|
||||
GenerateStoreViaSetter(masm, Handle<HeapType>::null(), no_reg,
|
||||
Handle<JSFunction>());
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual Register FrontendHeader(Register object_reg, Handle<Name> name,
|
||||
Label* miss);
|
||||
|
||||
virtual void FrontendFooter(Handle<Name> name, Label* miss);
|
||||
void GenerateRestoreName(Label* label, Handle<Name> name);
|
||||
|
||||
private:
|
||||
void GenerateStoreTransition(Handle<Map> transition, Handle<Name> name,
|
||||
Register receiver_reg, Register name_reg,
|
||||
Register value_reg, Register scratch1,
|
||||
Register scratch2, Register scratch3,
|
||||
Label* miss_label, Label* slow);
|
||||
|
||||
void GenerateStoreField(LookupIterator* lookup, Register value_reg,
|
||||
Label* miss_label);
|
||||
|
||||
static Builtins::Name SlowBuiltin(Code::Kind kind) {
|
||||
switch (kind) {
|
||||
case Code::STORE_IC:
|
||||
return Builtins::kStoreIC_Slow;
|
||||
case Code::KEYED_STORE_IC:
|
||||
return Builtins::kKeyedStoreIC_Slow;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
return Builtins::kStoreIC_Slow;
|
||||
}
|
||||
|
||||
static Register value();
|
||||
};
|
||||
|
||||
|
||||
class ElementHandlerCompiler : public PropertyHandlerCompiler {
|
||||
public:
|
||||
explicit ElementHandlerCompiler(Isolate* isolate)
|
||||
: PropertyHandlerCompiler(isolate, Code::KEYED_LOAD_IC,
|
||||
Handle<HeapType>::null(),
|
||||
Handle<JSObject>::null(), kCacheOnReceiver) {}
|
||||
|
||||
virtual ~ElementHandlerCompiler() {}
|
||||
|
||||
void CompileElementHandlers(MapHandleList* receiver_maps,
|
||||
CodeHandleList* handlers);
|
||||
|
||||
static void GenerateLoadDictionaryElement(MacroAssembler* masm);
|
||||
static void GenerateStoreDictionaryElement(MacroAssembler* masm);
|
||||
};
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
||||
#endif // V8_IC_HANDLER_COMPILER_H_
|
862
src/ic/ia32/handler-compiler-ia32.cc
Normal file
862
src/ic/ia32/handler-compiler-ia32.cc
Normal file
@ -0,0 +1,862 @@
|
||||
// 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.
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#if V8_TARGET_ARCH_IA32
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void ElementHandlerCompiler::GenerateLoadDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- ecx : key
|
||||
// -- edx : receiver
|
||||
// -- esp[0] : return address
|
||||
// -----------------------------------
|
||||
DCHECK(edx.is(LoadIC::ReceiverRegister()));
|
||||
DCHECK(ecx.is(LoadIC::NameRegister()));
|
||||
Label slow, miss;
|
||||
|
||||
// This stub is meant to be tail-jumped to, the receiver must already
|
||||
// have been verified by the caller to not be a smi.
|
||||
__ JumpIfNotSmi(ecx, &miss);
|
||||
__ mov(ebx, ecx);
|
||||
__ SmiUntag(ebx);
|
||||
__ mov(eax, FieldOperand(edx, JSObject::kElementsOffset));
|
||||
|
||||
// Push receiver on the stack to free up a register for the dictionary
|
||||
// probing.
|
||||
__ push(edx);
|
||||
__ LoadFromNumberDictionary(&slow, eax, ecx, ebx, edx, edi, eax);
|
||||
// Pop receiver before returning.
|
||||
__ pop(edx);
|
||||
__ ret(0);
|
||||
|
||||
__ bind(&slow);
|
||||
__ pop(edx);
|
||||
|
||||
// ----------- S t a t e -------------
|
||||
// -- ecx : key
|
||||
// -- edx : receiver
|
||||
// -- esp[0] : return address
|
||||
// -----------------------------------
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
|
||||
|
||||
__ bind(&miss);
|
||||
// ----------- S t a t e -------------
|
||||
// -- ecx : key
|
||||
// -- edx : receiver
|
||||
// -- esp[0] : return address
|
||||
// -----------------------------------
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> getter) {
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
if (!getter.is_null()) {
|
||||
// Call the JavaScript getter with the receiver on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ mov(receiver,
|
||||
FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ push(receiver);
|
||||
ParameterCount actual(0);
|
||||
ParameterCount expected(getter);
|
||||
__ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// Restore context register.
|
||||
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
|
||||
MacroAssembler* masm, Label* miss_label, Register receiver,
|
||||
Handle<Name> name, Register scratch0, Register scratch1) {
|
||||
DCHECK(name->IsUniqueName());
|
||||
DCHECK(!receiver.is(scratch0));
|
||||
Counters* counters = masm->isolate()->counters();
|
||||
__ IncrementCounter(counters->negative_lookups(), 1);
|
||||
__ IncrementCounter(counters->negative_lookups_miss(), 1);
|
||||
|
||||
__ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset));
|
||||
|
||||
const int kInterceptorOrAccessCheckNeededMask =
|
||||
(1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
|
||||
|
||||
// Bail out if the receiver has a named interceptor or requires access checks.
|
||||
__ test_b(FieldOperand(scratch0, Map::kBitFieldOffset),
|
||||
kInterceptorOrAccessCheckNeededMask);
|
||||
__ j(not_zero, miss_label);
|
||||
|
||||
// Check that receiver is a JSObject.
|
||||
__ CmpInstanceType(scratch0, FIRST_SPEC_OBJECT_TYPE);
|
||||
__ j(below, miss_label);
|
||||
|
||||
// Load properties array.
|
||||
Register properties = scratch0;
|
||||
__ mov(properties, FieldOperand(receiver, JSObject::kPropertiesOffset));
|
||||
|
||||
// Check that the properties array is a dictionary.
|
||||
__ cmp(FieldOperand(properties, HeapObject::kMapOffset),
|
||||
Immediate(masm->isolate()->factory()->hash_table_map()));
|
||||
__ j(not_equal, miss_label);
|
||||
|
||||
Label done;
|
||||
NameDictionaryLookupStub::GenerateNegativeLookup(masm, miss_label, &done,
|
||||
properties, name, scratch1);
|
||||
__ bind(&done);
|
||||
__ DecrementCounter(counters->negative_lookups_miss(), 1);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
|
||||
MacroAssembler* masm, int index, Register prototype, Label* miss) {
|
||||
// Get the global function with the given index.
|
||||
Handle<JSFunction> function(
|
||||
JSFunction::cast(masm->isolate()->native_context()->get(index)));
|
||||
// Check we're still in the same context.
|
||||
Register scratch = prototype;
|
||||
const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
|
||||
__ mov(scratch, Operand(esi, offset));
|
||||
__ mov(scratch, FieldOperand(scratch, GlobalObject::kNativeContextOffset));
|
||||
__ cmp(Operand(scratch, Context::SlotOffset(index)), function);
|
||||
__ j(not_equal, miss);
|
||||
|
||||
// Load its initial map. The global functions all have initial maps.
|
||||
__ Move(prototype, Immediate(Handle<Map>(function->initial_map())));
|
||||
// Load the prototype from the initial map.
|
||||
__ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset));
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
|
||||
MacroAssembler* masm, Register receiver, Register scratch1,
|
||||
Register scratch2, Label* miss_label) {
|
||||
__ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
|
||||
__ mov(eax, scratch1);
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
// Generate call to api function.
|
||||
// This function uses push() to generate smaller, faster code than
|
||||
// the version above. It is an optimization that should will be removed
|
||||
// when api call ICs are generated in hydrogen.
|
||||
void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
MacroAssembler* masm, const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver, Register scratch_in,
|
||||
bool is_store, int argc, Register* values) {
|
||||
// Copy return value.
|
||||
__ pop(scratch_in);
|
||||
// receiver
|
||||
__ push(receiver);
|
||||
// Write the arguments to stack frame.
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Register arg = values[argc - 1 - i];
|
||||
DCHECK(!receiver.is(arg));
|
||||
DCHECK(!scratch_in.is(arg));
|
||||
__ push(arg);
|
||||
}
|
||||
__ push(scratch_in);
|
||||
// Stack now matches JSFunction abi.
|
||||
DCHECK(optimization.is_simple_api_call());
|
||||
|
||||
// Abi for CallApiFunctionStub.
|
||||
Register callee = eax;
|
||||
Register call_data = ebx;
|
||||
Register holder = ecx;
|
||||
Register api_function_address = edx;
|
||||
Register scratch = edi; // scratch_in is no longer valid.
|
||||
|
||||
// Put holder in place.
|
||||
CallOptimization::HolderLookup holder_lookup;
|
||||
Handle<JSObject> api_holder =
|
||||
optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
|
||||
switch (holder_lookup) {
|
||||
case CallOptimization::kHolderIsReceiver:
|
||||
__ Move(holder, receiver);
|
||||
break;
|
||||
case CallOptimization::kHolderFound:
|
||||
__ LoadHeapObject(holder, api_holder);
|
||||
break;
|
||||
case CallOptimization::kHolderNotFound:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
Isolate* isolate = masm->isolate();
|
||||
Handle<JSFunction> function = optimization.constant_function();
|
||||
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
|
||||
Handle<Object> call_data_obj(api_call_info->data(), isolate);
|
||||
|
||||
// Put callee in place.
|
||||
__ LoadHeapObject(callee, function);
|
||||
|
||||
bool call_data_undefined = false;
|
||||
// Put call_data in place.
|
||||
if (isolate->heap()->InNewSpace(*call_data_obj)) {
|
||||
__ mov(scratch, api_call_info);
|
||||
__ mov(call_data, FieldOperand(scratch, CallHandlerInfo::kDataOffset));
|
||||
} else if (call_data_obj->IsUndefined()) {
|
||||
call_data_undefined = true;
|
||||
__ mov(call_data, Immediate(isolate->factory()->undefined_value()));
|
||||
} else {
|
||||
__ mov(call_data, call_data_obj);
|
||||
}
|
||||
|
||||
// Put api_function_address in place.
|
||||
Address function_address = v8::ToCData<Address>(api_call_info->callback());
|
||||
__ mov(api_function_address, Immediate(function_address));
|
||||
|
||||
// Jump to stub.
|
||||
CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
// Generate code to check that a global property cell is empty. Create
|
||||
// the property cell at compilation time if no cell exists for the
|
||||
// property.
|
||||
void PropertyHandlerCompiler::GenerateCheckPropertyCell(
|
||||
MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
|
||||
Register scratch, Label* miss) {
|
||||
Handle<PropertyCell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
|
||||
DCHECK(cell->value()->IsTheHole());
|
||||
Handle<Oddball> the_hole = masm->isolate()->factory()->the_hole_value();
|
||||
if (masm->serializer_enabled()) {
|
||||
__ mov(scratch, Immediate(cell));
|
||||
__ cmp(FieldOperand(scratch, PropertyCell::kValueOffset),
|
||||
Immediate(the_hole));
|
||||
} else {
|
||||
__ cmp(Operand::ForCell(cell), Immediate(the_hole));
|
||||
}
|
||||
__ j(not_equal, miss);
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- esp[0] : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
// Save value register, so we can restore it later.
|
||||
__ push(value());
|
||||
|
||||
if (!setter.is_null()) {
|
||||
// Call the JavaScript setter with receiver and value on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ mov(receiver,
|
||||
FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ push(receiver);
|
||||
__ push(value());
|
||||
ParameterCount actual(1);
|
||||
ParameterCount expected(setter);
|
||||
__ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// We have to return the passed value, not the return value of the setter.
|
||||
__ pop(eax);
|
||||
|
||||
// Restore context register.
|
||||
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
|
||||
Register holder, Register name,
|
||||
Handle<JSObject> holder_obj) {
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
|
||||
__ push(name);
|
||||
Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
|
||||
DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
|
||||
Register scratch = name;
|
||||
__ mov(scratch, Immediate(interceptor));
|
||||
__ push(scratch);
|
||||
__ push(receiver);
|
||||
__ push(holder);
|
||||
}
|
||||
|
||||
|
||||
static void CompileCallLoadPropertyWithInterceptor(
|
||||
MacroAssembler* masm, Register receiver, Register holder, Register name,
|
||||
Handle<JSObject> holder_obj, IC::UtilityId id) {
|
||||
PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
|
||||
__ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
|
||||
NamedLoadHandlerCompiler::kInterceptorArgsLength);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
|
||||
Handle<Name> name) {
|
||||
if (!label->is_unused()) {
|
||||
__ bind(label);
|
||||
__ mov(this->name(), Immediate(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Receiver_reg is preserved on jumps to miss_label, but may be destroyed if
|
||||
// store is successful.
|
||||
void NamedStoreHandlerCompiler::GenerateStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name, Register receiver_reg,
|
||||
Register storage_reg, Register value_reg, Register scratch1,
|
||||
Register scratch2, Register unused, Label* miss_label, Label* slow) {
|
||||
int descriptor = transition->LastAdded();
|
||||
DescriptorArray* descriptors = transition->instance_descriptors();
|
||||
PropertyDetails details = descriptors->GetDetails(descriptor);
|
||||
Representation representation = details.representation();
|
||||
DCHECK(!representation.IsNone());
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
|
||||
__ CmpObject(value_reg, constant);
|
||||
__ j(not_equal, miss_label);
|
||||
} else if (representation.IsSmi()) {
|
||||
__ JumpIfNotSmi(value_reg, miss_label);
|
||||
} else if (representation.IsHeapObject()) {
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType* field_type = descriptors->GetFieldType(descriptor);
|
||||
HeapType::Iterator<Map> it = field_type->Classes();
|
||||
if (!it.Done()) {
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(value_reg, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ j(not_equal, miss_label);
|
||||
break;
|
||||
}
|
||||
__ j(equal, &do_store, Label::kNear);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
}
|
||||
} else if (representation.IsDouble()) {
|
||||
Label do_store, heap_number;
|
||||
__ AllocateHeapNumber(storage_reg, scratch1, scratch2, slow, MUTABLE);
|
||||
|
||||
__ JumpIfNotSmi(value_reg, &heap_number);
|
||||
__ SmiUntag(value_reg);
|
||||
__ Cvtsi2sd(xmm0, value_reg);
|
||||
__ SmiTag(value_reg);
|
||||
__ jmp(&do_store);
|
||||
|
||||
__ bind(&heap_number);
|
||||
__ CheckMap(value_reg, isolate()->factory()->heap_number_map(), miss_label,
|
||||
DONT_DO_SMI_CHECK);
|
||||
__ movsd(xmm0, FieldOperand(value_reg, HeapNumber::kValueOffset));
|
||||
|
||||
__ bind(&do_store);
|
||||
__ movsd(FieldOperand(storage_reg, HeapNumber::kValueOffset), xmm0);
|
||||
}
|
||||
|
||||
// Stub never generated for objects that require access checks.
|
||||
DCHECK(!transition->is_access_check_needed());
|
||||
|
||||
// Perform map transition for the receiver if necessary.
|
||||
if (details.type() == FIELD &&
|
||||
Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
|
||||
// The properties must be extended before we can store the value.
|
||||
// We jump to a runtime call that extends the properties array.
|
||||
__ pop(scratch1); // Return address.
|
||||
__ push(receiver_reg);
|
||||
__ push(Immediate(transition));
|
||||
__ push(value_reg);
|
||||
__ push(scratch1);
|
||||
__ TailCallExternalReference(
|
||||
ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
|
||||
isolate()),
|
||||
3, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the map of the object.
|
||||
__ mov(scratch1, Immediate(transition));
|
||||
__ mov(FieldOperand(receiver_reg, HeapObject::kMapOffset), scratch1);
|
||||
|
||||
// Update the write barrier for the map field.
|
||||
__ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
|
||||
kDontSaveFPRegs, OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
DCHECK(value_reg.is(eax));
|
||||
__ ret(0);
|
||||
return;
|
||||
}
|
||||
|
||||
int index = transition->instance_descriptors()->GetFieldIndex(
|
||||
transition->LastAdded());
|
||||
|
||||
// Adjust for the number of properties stored in the object. Even in the
|
||||
// face of a transition we can use the old map here because the size of the
|
||||
// object and the number of in-object properties is not going to change.
|
||||
index -= transition->inobject_properties();
|
||||
|
||||
SmiCheck smi_check =
|
||||
representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
|
||||
// TODO(verwaest): Share this code as a code stub.
|
||||
if (index < 0) {
|
||||
// Set the property straight into the object.
|
||||
int offset = transition->instance_size() + (index * kPointerSize);
|
||||
if (representation.IsDouble()) {
|
||||
__ mov(FieldOperand(receiver_reg, offset), storage_reg);
|
||||
} else {
|
||||
__ mov(FieldOperand(receiver_reg, offset), value_reg);
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
|
||||
kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
} else {
|
||||
// Write to the properties array.
|
||||
int offset = index * kPointerSize + FixedArray::kHeaderSize;
|
||||
// Get the properties array (optimistically).
|
||||
__ mov(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset));
|
||||
if (representation.IsDouble()) {
|
||||
__ mov(FieldOperand(scratch1, offset), storage_reg);
|
||||
} else {
|
||||
__ mov(FieldOperand(scratch1, offset), value_reg);
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
|
||||
kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the value (register eax).
|
||||
DCHECK(value_reg.is(eax));
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
|
||||
Register value_reg,
|
||||
Label* miss_label) {
|
||||
DCHECK(lookup->representation().IsHeapObject());
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(value_reg, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ j(not_equal, miss_label);
|
||||
break;
|
||||
}
|
||||
__ j(equal, &do_store, Label::kNear);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
|
||||
StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
|
||||
lookup->representation());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::CheckPrototypes(
|
||||
Register object_reg, Register holder_reg, Register scratch1,
|
||||
Register scratch2, Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check) {
|
||||
Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
|
||||
|
||||
// Make sure there's no overlap between holder and object registers.
|
||||
DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
|
||||
DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
|
||||
!scratch2.is(scratch1));
|
||||
|
||||
// Keep track of the current object in register reg.
|
||||
Register reg = object_reg;
|
||||
int depth = 0;
|
||||
|
||||
Handle<JSObject> current = Handle<JSObject>::null();
|
||||
if (type()->IsConstant())
|
||||
current = Handle<JSObject>::cast(type()->AsConstant()->Value());
|
||||
Handle<JSObject> prototype = Handle<JSObject>::null();
|
||||
Handle<Map> current_map = receiver_map;
|
||||
Handle<Map> holder_map(holder()->map());
|
||||
// Traverse the prototype chain and check the maps in the prototype chain for
|
||||
// fast and global objects or do negative lookup for normal objects.
|
||||
while (!current_map.is_identical_to(holder_map)) {
|
||||
++depth;
|
||||
|
||||
// Only global objects and objects that do not require access
|
||||
// checks are allowed in stubs.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
|
||||
prototype = handle(JSObject::cast(current_map->prototype()));
|
||||
if (current_map->is_dictionary_map() &&
|
||||
!current_map->IsJSGlobalObjectMap()) {
|
||||
DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(current.is_null() ||
|
||||
current->property_dictionary()->FindEntry(name) ==
|
||||
NameDictionary::kNotFound);
|
||||
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
|
||||
scratch2);
|
||||
|
||||
__ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
__ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
bool in_new_space = heap()->InNewSpace(*prototype);
|
||||
// Two possible reasons for loading the prototype from the map:
|
||||
// (1) Can't store references to new space in code.
|
||||
// (2) Handler is shared for all receivers with the same prototype
|
||||
// map (but not necessarily the same prototype instance).
|
||||
bool load_prototype_from_map = in_new_space || depth == 1;
|
||||
if (depth != 1 || check == CHECK_ALL_MAPS) {
|
||||
__ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Check access rights to the global object. This has to happen after
|
||||
// the map check so that we know that the object is actually a global
|
||||
// object.
|
||||
// This allows us to install generated handlers for accesses to the
|
||||
// global proxy (as opposed to using slow ICs). See corresponding code
|
||||
// in LookupForRead().
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
|
||||
} else if (current_map->IsJSGlobalObjectMap()) {
|
||||
GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
|
||||
name, scratch2, miss);
|
||||
}
|
||||
|
||||
if (load_prototype_from_map) {
|
||||
// Save the map in scratch1 for later.
|
||||
__ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
|
||||
}
|
||||
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
|
||||
if (load_prototype_from_map) {
|
||||
__ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
__ mov(reg, prototype);
|
||||
}
|
||||
}
|
||||
|
||||
// Go to the next object in the prototype chain.
|
||||
current = prototype;
|
||||
current_map = handle(current->map());
|
||||
}
|
||||
|
||||
// Log the check depth.
|
||||
LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
|
||||
|
||||
if (depth != 0 || check == CHECK_ALL_MAPS) {
|
||||
// Check the holder map.
|
||||
__ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Perform security check for access to the global object.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
|
||||
}
|
||||
|
||||
// Return the register containing the holder.
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ jmp(&success);
|
||||
__ bind(miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ jmp(&success);
|
||||
GenerateRestoreName(miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadCallback(
|
||||
Register reg, Handle<ExecutableAccessorInfo> callback) {
|
||||
// Insert additional parameters into the stack frame above return address.
|
||||
DCHECK(!scratch3().is(reg));
|
||||
__ pop(scratch3()); // Get return address to place it below.
|
||||
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
|
||||
__ push(receiver()); // receiver
|
||||
// Push data from ExecutableAccessorInfo.
|
||||
if (isolate()->heap()->InNewSpace(callback->data())) {
|
||||
DCHECK(!scratch2().is(reg));
|
||||
__ mov(scratch2(), Immediate(callback));
|
||||
__ push(FieldOperand(scratch2(), ExecutableAccessorInfo::kDataOffset));
|
||||
} else {
|
||||
__ push(Immediate(Handle<Object>(callback->data(), isolate())));
|
||||
}
|
||||
__ push(Immediate(isolate()->factory()->undefined_value())); // ReturnValue
|
||||
// ReturnValue default value
|
||||
__ push(Immediate(isolate()->factory()->undefined_value()));
|
||||
__ push(Immediate(reinterpret_cast<int>(isolate())));
|
||||
__ push(reg); // holder
|
||||
|
||||
// Save a pointer to where we pushed the arguments. This will be
|
||||
// passed as the const PropertyAccessorInfo& to the C++ callback.
|
||||
__ push(esp);
|
||||
|
||||
__ push(name()); // name
|
||||
|
||||
__ push(scratch3()); // Restore return address.
|
||||
|
||||
// Abi for CallApiGetter
|
||||
Register getter_address = edx;
|
||||
Address function_address = v8::ToCData<Address>(callback->getter());
|
||||
__ mov(getter_address, Immediate(function_address));
|
||||
|
||||
CallApiGetterStub stub(isolate());
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
|
||||
// Return the constant value.
|
||||
__ LoadObject(eax, value);
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
|
||||
LookupIterator* it, Register holder_reg) {
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
|
||||
// Compile the interceptor call, followed by inline code to load the
|
||||
// property from further up the prototype chain if the call fails.
|
||||
// Check that the maps haven't changed.
|
||||
DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
|
||||
|
||||
// Preserve the receiver register explicitly whenever it is different from the
|
||||
// holder and it is needed should the interceptor return without any result.
|
||||
// The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
|
||||
// case might cause a miss during the prototype check.
|
||||
bool must_perform_prototype_check =
|
||||
!holder().is_identical_to(it->GetHolder<JSObject>());
|
||||
bool must_preserve_receiver_reg =
|
||||
!receiver().is(holder_reg) &&
|
||||
(it->property_kind() == LookupIterator::ACCESSOR ||
|
||||
must_perform_prototype_check);
|
||||
|
||||
// Save necessary data before invoking an interceptor.
|
||||
// Requires a frame to make GC aware of pushed pointers.
|
||||
{
|
||||
FrameScope frame_scope(masm(), StackFrame::INTERNAL);
|
||||
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ push(receiver());
|
||||
}
|
||||
__ push(holder_reg);
|
||||
__ push(this->name());
|
||||
|
||||
// Invoke an interceptor. Note: map checks from receiver to
|
||||
// interceptor's holder has been compiled before (see a caller
|
||||
// of this method.)
|
||||
CompileCallLoadPropertyWithInterceptor(
|
||||
masm(), receiver(), holder_reg, this->name(), holder(),
|
||||
IC::kLoadPropertyWithInterceptorOnly);
|
||||
|
||||
// Check if interceptor provided a value for property. If it's
|
||||
// the case, return immediately.
|
||||
Label interceptor_failed;
|
||||
__ cmp(eax, factory()->no_interceptor_result_sentinel());
|
||||
__ j(equal, &interceptor_failed);
|
||||
frame_scope.GenerateLeaveFrame();
|
||||
__ ret(0);
|
||||
|
||||
// Clobber registers when generating debug-code to provoke errors.
|
||||
__ bind(&interceptor_failed);
|
||||
if (FLAG_debug_code) {
|
||||
__ mov(receiver(), Immediate(BitCast<int32_t>(kZapValue)));
|
||||
__ mov(holder_reg, Immediate(BitCast<int32_t>(kZapValue)));
|
||||
__ mov(this->name(), Immediate(BitCast<int32_t>(kZapValue)));
|
||||
}
|
||||
|
||||
__ pop(this->name());
|
||||
__ pop(holder_reg);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ pop(receiver());
|
||||
}
|
||||
|
||||
// Leave the internal frame.
|
||||
}
|
||||
|
||||
GenerateLoadPostInterceptor(it, holder_reg);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
// Call the runtime system to load the interceptor.
|
||||
__ pop(scratch2()); // save old return address
|
||||
PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
|
||||
holder());
|
||||
__ push(scratch2()); // restore old return address
|
||||
|
||||
ExternalReference ref = ExternalReference(
|
||||
IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(
|
||||
ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback) {
|
||||
Register holder_reg = Frontend(receiver(), name);
|
||||
|
||||
__ pop(scratch1()); // remove the return address
|
||||
__ push(receiver());
|
||||
__ push(holder_reg);
|
||||
__ Push(callback);
|
||||
__ Push(name);
|
||||
__ push(value());
|
||||
__ push(scratch1()); // restore return address
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_callback_property =
|
||||
ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
|
||||
__ TailCallExternalReference(store_callback_property, 5, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
|
||||
Handle<Name> name) {
|
||||
__ pop(scratch1()); // remove the return address
|
||||
__ push(receiver());
|
||||
__ push(this->name());
|
||||
__ push(value());
|
||||
__ push(scratch1()); // restore return address
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_ic_property = ExternalReference(
|
||||
IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(store_ic_property, 3, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
|
||||
Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
|
||||
Label miss;
|
||||
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
// Get the value from the cell.
|
||||
Register result = StoreIC::ValueRegister();
|
||||
if (masm()->serializer_enabled()) {
|
||||
__ mov(result, Immediate(cell));
|
||||
__ mov(result, FieldOperand(result, PropertyCell::kValueOffset));
|
||||
} else {
|
||||
__ mov(result, Operand::ForCell(cell));
|
||||
}
|
||||
|
||||
// Check for deleted property if property can actually be deleted.
|
||||
if (is_configurable) {
|
||||
__ cmp(result, factory()->the_hole_value());
|
||||
__ j(equal, &miss);
|
||||
} else if (FLAG_debug_code) {
|
||||
__ cmp(result, factory()->the_hole_value());
|
||||
__ Check(not_equal, kDontDeleteCellsCannotContainTheHole);
|
||||
}
|
||||
|
||||
Counters* counters = isolate()->counters();
|
||||
__ IncrementCounter(counters->named_load_global_stub(), 1);
|
||||
// The code above already loads the result into the return register.
|
||||
__ ret(0);
|
||||
|
||||
FrontendFooter(name, &miss);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, name);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
||||
#endif // V8_TARGET_ARCH_IA32
|
@ -6,7 +6,6 @@
|
||||
|
||||
#if V8_TARGET_ARCH_IA32
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
|
||||
namespace v8 {
|
||||
@ -14,842 +13,27 @@ namespace internal {
|
||||
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
|
||||
MacroAssembler* masm, Label* miss_label, Register receiver,
|
||||
Handle<Name> name, Register scratch0, Register scratch1) {
|
||||
DCHECK(name->IsUniqueName());
|
||||
DCHECK(!receiver.is(scratch0));
|
||||
Counters* counters = masm->isolate()->counters();
|
||||
__ IncrementCounter(counters->negative_lookups(), 1);
|
||||
__ IncrementCounter(counters->negative_lookups_miss(), 1);
|
||||
|
||||
__ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset));
|
||||
void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
|
||||
StrictMode strict_mode) {
|
||||
// Return address is on the stack.
|
||||
DCHECK(!ebx.is(StoreIC::ReceiverRegister()) &&
|
||||
!ebx.is(StoreIC::NameRegister()) && !ebx.is(StoreIC::ValueRegister()));
|
||||
__ pop(ebx);
|
||||
__ push(StoreIC::ReceiverRegister());
|
||||
__ push(StoreIC::NameRegister());
|
||||
__ push(StoreIC::ValueRegister());
|
||||
__ push(Immediate(Smi::FromInt(strict_mode)));
|
||||
__ push(ebx); // return address
|
||||
|
||||
const int kInterceptorOrAccessCheckNeededMask =
|
||||
(1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
|
||||
|
||||
// Bail out if the receiver has a named interceptor or requires access checks.
|
||||
__ test_b(FieldOperand(scratch0, Map::kBitFieldOffset),
|
||||
kInterceptorOrAccessCheckNeededMask);
|
||||
__ j(not_zero, miss_label);
|
||||
|
||||
// Check that receiver is a JSObject.
|
||||
__ CmpInstanceType(scratch0, FIRST_SPEC_OBJECT_TYPE);
|
||||
__ j(below, miss_label);
|
||||
|
||||
// Load properties array.
|
||||
Register properties = scratch0;
|
||||
__ mov(properties, FieldOperand(receiver, JSObject::kPropertiesOffset));
|
||||
|
||||
// Check that the properties array is a dictionary.
|
||||
__ cmp(FieldOperand(properties, HeapObject::kMapOffset),
|
||||
Immediate(masm->isolate()->factory()->hash_table_map()));
|
||||
__ j(not_equal, miss_label);
|
||||
|
||||
Label done;
|
||||
NameDictionaryLookupStub::GenerateNegativeLookup(masm, miss_label, &done,
|
||||
properties, name, scratch1);
|
||||
__ bind(&done);
|
||||
__ DecrementCounter(counters->negative_lookups_miss(), 1);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
|
||||
MacroAssembler* masm, int index, Register prototype, Label* miss) {
|
||||
// Get the global function with the given index.
|
||||
Handle<JSFunction> function(
|
||||
JSFunction::cast(masm->isolate()->native_context()->get(index)));
|
||||
// Check we're still in the same context.
|
||||
Register scratch = prototype;
|
||||
const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
|
||||
__ mov(scratch, Operand(esi, offset));
|
||||
__ mov(scratch, FieldOperand(scratch, GlobalObject::kNativeContextOffset));
|
||||
__ cmp(Operand(scratch, Context::SlotOffset(index)), function);
|
||||
__ j(not_equal, miss);
|
||||
|
||||
// Load its initial map. The global functions all have initial maps.
|
||||
__ Move(prototype, Immediate(Handle<Map>(function->initial_map())));
|
||||
// Load the prototype from the initial map.
|
||||
__ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset));
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
|
||||
MacroAssembler* masm, Register receiver, Register scratch1,
|
||||
Register scratch2, Label* miss_label) {
|
||||
__ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label);
|
||||
__ mov(eax, scratch1);
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
|
||||
Register holder, Register name,
|
||||
Handle<JSObject> holder_obj) {
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
|
||||
__ push(name);
|
||||
Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
|
||||
DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
|
||||
Register scratch = name;
|
||||
__ mov(scratch, Immediate(interceptor));
|
||||
__ push(scratch);
|
||||
__ push(receiver);
|
||||
__ push(holder);
|
||||
}
|
||||
|
||||
|
||||
static void CompileCallLoadPropertyWithInterceptor(
|
||||
MacroAssembler* masm, Register receiver, Register holder, Register name,
|
||||
Handle<JSObject> holder_obj, IC::UtilityId id) {
|
||||
PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
|
||||
__ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
|
||||
NamedLoadHandlerCompiler::kInterceptorArgsLength);
|
||||
}
|
||||
|
||||
|
||||
// Generate call to api function.
|
||||
// This function uses push() to generate smaller, faster code than
|
||||
// the version above. It is an optimization that should will be removed
|
||||
// when api call ICs are generated in hydrogen.
|
||||
void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
MacroAssembler* masm, const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver, Register scratch_in,
|
||||
bool is_store, int argc, Register* values) {
|
||||
// Copy return value.
|
||||
__ pop(scratch_in);
|
||||
// receiver
|
||||
__ push(receiver);
|
||||
// Write the arguments to stack frame.
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Register arg = values[argc - 1 - i];
|
||||
DCHECK(!receiver.is(arg));
|
||||
DCHECK(!scratch_in.is(arg));
|
||||
__ push(arg);
|
||||
}
|
||||
__ push(scratch_in);
|
||||
// Stack now matches JSFunction abi.
|
||||
DCHECK(optimization.is_simple_api_call());
|
||||
|
||||
// Abi for CallApiFunctionStub.
|
||||
Register callee = eax;
|
||||
Register call_data = ebx;
|
||||
Register holder = ecx;
|
||||
Register api_function_address = edx;
|
||||
Register scratch = edi; // scratch_in is no longer valid.
|
||||
|
||||
// Put holder in place.
|
||||
CallOptimization::HolderLookup holder_lookup;
|
||||
Handle<JSObject> api_holder =
|
||||
optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
|
||||
switch (holder_lookup) {
|
||||
case CallOptimization::kHolderIsReceiver:
|
||||
__ Move(holder, receiver);
|
||||
break;
|
||||
case CallOptimization::kHolderFound:
|
||||
__ LoadHeapObject(holder, api_holder);
|
||||
break;
|
||||
case CallOptimization::kHolderNotFound:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
Isolate* isolate = masm->isolate();
|
||||
Handle<JSFunction> function = optimization.constant_function();
|
||||
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
|
||||
Handle<Object> call_data_obj(api_call_info->data(), isolate);
|
||||
|
||||
// Put callee in place.
|
||||
__ LoadHeapObject(callee, function);
|
||||
|
||||
bool call_data_undefined = false;
|
||||
// Put call_data in place.
|
||||
if (isolate->heap()->InNewSpace(*call_data_obj)) {
|
||||
__ mov(scratch, api_call_info);
|
||||
__ mov(call_data, FieldOperand(scratch, CallHandlerInfo::kDataOffset));
|
||||
} else if (call_data_obj->IsUndefined()) {
|
||||
call_data_undefined = true;
|
||||
__ mov(call_data, Immediate(isolate->factory()->undefined_value()));
|
||||
} else {
|
||||
__ mov(call_data, call_data_obj);
|
||||
}
|
||||
|
||||
// Put api_function_address in place.
|
||||
Address function_address = v8::ToCData<Address>(api_call_info->callback());
|
||||
__ mov(api_function_address, Immediate(function_address));
|
||||
|
||||
// Jump to stub.
|
||||
CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
// Generate code to check that a global property cell is empty. Create
|
||||
// the property cell at compilation time if no cell exists for the
|
||||
// property.
|
||||
void PropertyHandlerCompiler::GenerateCheckPropertyCell(
|
||||
MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
|
||||
Register scratch, Label* miss) {
|
||||
Handle<PropertyCell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
|
||||
DCHECK(cell->value()->IsTheHole());
|
||||
Handle<Oddball> the_hole = masm->isolate()->factory()->the_hole_value();
|
||||
if (masm->serializer_enabled()) {
|
||||
__ mov(scratch, Immediate(cell));
|
||||
__ cmp(FieldOperand(scratch, PropertyCell::kValueOffset),
|
||||
Immediate(the_hole));
|
||||
} else {
|
||||
__ cmp(Operand::ForCell(cell), Immediate(the_hole));
|
||||
}
|
||||
__ j(not_equal, miss);
|
||||
// Do tail-call to runtime routine.
|
||||
__ TailCallRuntime(Runtime::kSetProperty, 4, 1);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
|
||||
Handle<Name> name) {
|
||||
if (!label->is_unused()) {
|
||||
__ bind(label);
|
||||
__ mov(this->name(), Immediate(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Receiver_reg is preserved on jumps to miss_label, but may be destroyed if
|
||||
// store is successful.
|
||||
void NamedStoreHandlerCompiler::GenerateStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name, Register receiver_reg,
|
||||
Register storage_reg, Register value_reg, Register scratch1,
|
||||
Register scratch2, Register unused, Label* miss_label, Label* slow) {
|
||||
int descriptor = transition->LastAdded();
|
||||
DescriptorArray* descriptors = transition->instance_descriptors();
|
||||
PropertyDetails details = descriptors->GetDetails(descriptor);
|
||||
Representation representation = details.representation();
|
||||
DCHECK(!representation.IsNone());
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
|
||||
__ CmpObject(value_reg, constant);
|
||||
__ j(not_equal, miss_label);
|
||||
} else if (representation.IsSmi()) {
|
||||
__ JumpIfNotSmi(value_reg, miss_label);
|
||||
} else if (representation.IsHeapObject()) {
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType* field_type = descriptors->GetFieldType(descriptor);
|
||||
HeapType::Iterator<Map> it = field_type->Classes();
|
||||
if (!it.Done()) {
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(value_reg, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ j(not_equal, miss_label);
|
||||
break;
|
||||
}
|
||||
__ j(equal, &do_store, Label::kNear);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
}
|
||||
} else if (representation.IsDouble()) {
|
||||
Label do_store, heap_number;
|
||||
__ AllocateHeapNumber(storage_reg, scratch1, scratch2, slow, MUTABLE);
|
||||
|
||||
__ JumpIfNotSmi(value_reg, &heap_number);
|
||||
__ SmiUntag(value_reg);
|
||||
__ Cvtsi2sd(xmm0, value_reg);
|
||||
__ SmiTag(value_reg);
|
||||
__ jmp(&do_store);
|
||||
|
||||
__ bind(&heap_number);
|
||||
__ CheckMap(value_reg, isolate()->factory()->heap_number_map(), miss_label,
|
||||
DONT_DO_SMI_CHECK);
|
||||
__ movsd(xmm0, FieldOperand(value_reg, HeapNumber::kValueOffset));
|
||||
|
||||
__ bind(&do_store);
|
||||
__ movsd(FieldOperand(storage_reg, HeapNumber::kValueOffset), xmm0);
|
||||
}
|
||||
|
||||
// Stub never generated for objects that require access checks.
|
||||
DCHECK(!transition->is_access_check_needed());
|
||||
|
||||
// Perform map transition for the receiver if necessary.
|
||||
if (details.type() == FIELD &&
|
||||
Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
|
||||
// The properties must be extended before we can store the value.
|
||||
// We jump to a runtime call that extends the properties array.
|
||||
__ pop(scratch1); // Return address.
|
||||
__ push(receiver_reg);
|
||||
__ push(Immediate(transition));
|
||||
__ push(value_reg);
|
||||
__ push(scratch1);
|
||||
__ TailCallExternalReference(
|
||||
ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
|
||||
isolate()),
|
||||
3, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the map of the object.
|
||||
__ mov(scratch1, Immediate(transition));
|
||||
__ mov(FieldOperand(receiver_reg, HeapObject::kMapOffset), scratch1);
|
||||
|
||||
// Update the write barrier for the map field.
|
||||
__ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
|
||||
kDontSaveFPRegs, OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
DCHECK(value_reg.is(eax));
|
||||
__ ret(0);
|
||||
return;
|
||||
}
|
||||
|
||||
int index = transition->instance_descriptors()->GetFieldIndex(
|
||||
transition->LastAdded());
|
||||
|
||||
// Adjust for the number of properties stored in the object. Even in the
|
||||
// face of a transition we can use the old map here because the size of the
|
||||
// object and the number of in-object properties is not going to change.
|
||||
index -= transition->inobject_properties();
|
||||
|
||||
SmiCheck smi_check =
|
||||
representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
|
||||
// TODO(verwaest): Share this code as a code stub.
|
||||
if (index < 0) {
|
||||
// Set the property straight into the object.
|
||||
int offset = transition->instance_size() + (index * kPointerSize);
|
||||
if (representation.IsDouble()) {
|
||||
__ mov(FieldOperand(receiver_reg, offset), storage_reg);
|
||||
} else {
|
||||
__ mov(FieldOperand(receiver_reg, offset), value_reg);
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
|
||||
kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
} else {
|
||||
// Write to the properties array.
|
||||
int offset = index * kPointerSize + FixedArray::kHeaderSize;
|
||||
// Get the properties array (optimistically).
|
||||
__ mov(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset));
|
||||
if (representation.IsDouble()) {
|
||||
__ mov(FieldOperand(scratch1, offset), storage_reg);
|
||||
} else {
|
||||
__ mov(FieldOperand(scratch1, offset), value_reg);
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ mov(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
|
||||
kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the value (register eax).
|
||||
DCHECK(value_reg.is(eax));
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
|
||||
Register value_reg,
|
||||
Label* miss_label) {
|
||||
DCHECK(lookup->representation().IsHeapObject());
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(value_reg, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ j(not_equal, miss_label);
|
||||
break;
|
||||
}
|
||||
__ j(equal, &do_store, Label::kNear);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
|
||||
StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
|
||||
lookup->representation());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::CheckPrototypes(
|
||||
Register object_reg, Register holder_reg, Register scratch1,
|
||||
Register scratch2, Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check) {
|
||||
Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
|
||||
|
||||
// Make sure there's no overlap between holder and object registers.
|
||||
DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
|
||||
DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
|
||||
!scratch2.is(scratch1));
|
||||
|
||||
// Keep track of the current object in register reg.
|
||||
Register reg = object_reg;
|
||||
int depth = 0;
|
||||
|
||||
Handle<JSObject> current = Handle<JSObject>::null();
|
||||
if (type()->IsConstant())
|
||||
current = Handle<JSObject>::cast(type()->AsConstant()->Value());
|
||||
Handle<JSObject> prototype = Handle<JSObject>::null();
|
||||
Handle<Map> current_map = receiver_map;
|
||||
Handle<Map> holder_map(holder()->map());
|
||||
// Traverse the prototype chain and check the maps in the prototype chain for
|
||||
// fast and global objects or do negative lookup for normal objects.
|
||||
while (!current_map.is_identical_to(holder_map)) {
|
||||
++depth;
|
||||
|
||||
// Only global objects and objects that do not require access
|
||||
// checks are allowed in stubs.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
|
||||
prototype = handle(JSObject::cast(current_map->prototype()));
|
||||
if (current_map->is_dictionary_map() &&
|
||||
!current_map->IsJSGlobalObjectMap()) {
|
||||
DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(current.is_null() ||
|
||||
current->property_dictionary()->FindEntry(name) ==
|
||||
NameDictionary::kNotFound);
|
||||
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
|
||||
scratch2);
|
||||
|
||||
__ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
__ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
bool in_new_space = heap()->InNewSpace(*prototype);
|
||||
// Two possible reasons for loading the prototype from the map:
|
||||
// (1) Can't store references to new space in code.
|
||||
// (2) Handler is shared for all receivers with the same prototype
|
||||
// map (but not necessarily the same prototype instance).
|
||||
bool load_prototype_from_map = in_new_space || depth == 1;
|
||||
if (depth != 1 || check == CHECK_ALL_MAPS) {
|
||||
__ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Check access rights to the global object. This has to happen after
|
||||
// the map check so that we know that the object is actually a global
|
||||
// object.
|
||||
// This allows us to install generated handlers for accesses to the
|
||||
// global proxy (as opposed to using slow ICs). See corresponding code
|
||||
// in LookupForRead().
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
|
||||
} else if (current_map->IsJSGlobalObjectMap()) {
|
||||
GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
|
||||
name, scratch2, miss);
|
||||
}
|
||||
|
||||
if (load_prototype_from_map) {
|
||||
// Save the map in scratch1 for later.
|
||||
__ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
|
||||
}
|
||||
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
|
||||
if (load_prototype_from_map) {
|
||||
__ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
__ mov(reg, prototype);
|
||||
}
|
||||
}
|
||||
|
||||
// Go to the next object in the prototype chain.
|
||||
current = prototype;
|
||||
current_map = handle(current->map());
|
||||
}
|
||||
|
||||
// Log the check depth.
|
||||
LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
|
||||
|
||||
if (depth != 0 || check == CHECK_ALL_MAPS) {
|
||||
// Check the holder map.
|
||||
__ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Perform security check for access to the global object.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss);
|
||||
}
|
||||
|
||||
// Return the register containing the holder.
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ jmp(&success);
|
||||
__ bind(miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ jmp(&success);
|
||||
GenerateRestoreName(miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadCallback(
|
||||
Register reg, Handle<ExecutableAccessorInfo> callback) {
|
||||
// Insert additional parameters into the stack frame above return address.
|
||||
DCHECK(!scratch3().is(reg));
|
||||
__ pop(scratch3()); // Get return address to place it below.
|
||||
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
|
||||
__ push(receiver()); // receiver
|
||||
// Push data from ExecutableAccessorInfo.
|
||||
if (isolate()->heap()->InNewSpace(callback->data())) {
|
||||
DCHECK(!scratch2().is(reg));
|
||||
__ mov(scratch2(), Immediate(callback));
|
||||
__ push(FieldOperand(scratch2(), ExecutableAccessorInfo::kDataOffset));
|
||||
} else {
|
||||
__ push(Immediate(Handle<Object>(callback->data(), isolate())));
|
||||
}
|
||||
__ push(Immediate(isolate()->factory()->undefined_value())); // ReturnValue
|
||||
// ReturnValue default value
|
||||
__ push(Immediate(isolate()->factory()->undefined_value()));
|
||||
__ push(Immediate(reinterpret_cast<int>(isolate())));
|
||||
__ push(reg); // holder
|
||||
|
||||
// Save a pointer to where we pushed the arguments. This will be
|
||||
// passed as the const PropertyAccessorInfo& to the C++ callback.
|
||||
__ push(esp);
|
||||
|
||||
__ push(name()); // name
|
||||
|
||||
__ push(scratch3()); // Restore return address.
|
||||
|
||||
// Abi for CallApiGetter
|
||||
Register getter_address = edx;
|
||||
Address function_address = v8::ToCData<Address>(callback->getter());
|
||||
__ mov(getter_address, Immediate(function_address));
|
||||
|
||||
CallApiGetterStub stub(isolate());
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
|
||||
// Return the constant value.
|
||||
__ LoadObject(eax, value);
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
|
||||
LookupIterator* it, Register holder_reg) {
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
|
||||
// Compile the interceptor call, followed by inline code to load the
|
||||
// property from further up the prototype chain if the call fails.
|
||||
// Check that the maps haven't changed.
|
||||
DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
|
||||
|
||||
// Preserve the receiver register explicitly whenever it is different from the
|
||||
// holder and it is needed should the interceptor return without any result.
|
||||
// The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
|
||||
// case might cause a miss during the prototype check.
|
||||
bool must_perform_prototype_check =
|
||||
!holder().is_identical_to(it->GetHolder<JSObject>());
|
||||
bool must_preserve_receiver_reg =
|
||||
!receiver().is(holder_reg) &&
|
||||
(it->property_kind() == LookupIterator::ACCESSOR ||
|
||||
must_perform_prototype_check);
|
||||
|
||||
// Save necessary data before invoking an interceptor.
|
||||
// Requires a frame to make GC aware of pushed pointers.
|
||||
{
|
||||
FrameScope frame_scope(masm(), StackFrame::INTERNAL);
|
||||
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ push(receiver());
|
||||
}
|
||||
__ push(holder_reg);
|
||||
__ push(this->name());
|
||||
|
||||
// Invoke an interceptor. Note: map checks from receiver to
|
||||
// interceptor's holder has been compiled before (see a caller
|
||||
// of this method.)
|
||||
CompileCallLoadPropertyWithInterceptor(
|
||||
masm(), receiver(), holder_reg, this->name(), holder(),
|
||||
IC::kLoadPropertyWithInterceptorOnly);
|
||||
|
||||
// Check if interceptor provided a value for property. If it's
|
||||
// the case, return immediately.
|
||||
Label interceptor_failed;
|
||||
__ cmp(eax, factory()->no_interceptor_result_sentinel());
|
||||
__ j(equal, &interceptor_failed);
|
||||
frame_scope.GenerateLeaveFrame();
|
||||
__ ret(0);
|
||||
|
||||
// Clobber registers when generating debug-code to provoke errors.
|
||||
__ bind(&interceptor_failed);
|
||||
if (FLAG_debug_code) {
|
||||
__ mov(receiver(), Immediate(BitCast<int32_t>(kZapValue)));
|
||||
__ mov(holder_reg, Immediate(BitCast<int32_t>(kZapValue)));
|
||||
__ mov(this->name(), Immediate(BitCast<int32_t>(kZapValue)));
|
||||
}
|
||||
|
||||
__ pop(this->name());
|
||||
__ pop(holder_reg);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ pop(receiver());
|
||||
}
|
||||
|
||||
// Leave the internal frame.
|
||||
}
|
||||
|
||||
GenerateLoadPostInterceptor(it, holder_reg);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
// Call the runtime system to load the interceptor.
|
||||
__ pop(scratch2()); // save old return address
|
||||
PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
|
||||
holder());
|
||||
__ push(scratch2()); // restore old return address
|
||||
|
||||
ExternalReference ref = ExternalReference(
|
||||
IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(
|
||||
ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback) {
|
||||
Register holder_reg = Frontend(receiver(), name);
|
||||
|
||||
__ pop(scratch1()); // remove the return address
|
||||
__ push(receiver());
|
||||
__ push(holder_reg);
|
||||
__ Push(callback);
|
||||
__ Push(name);
|
||||
__ push(value());
|
||||
__ push(scratch1()); // restore return address
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_callback_property =
|
||||
ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
|
||||
__ TailCallExternalReference(store_callback_property, 5, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- esp[0] : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
// Save value register, so we can restore it later.
|
||||
__ push(value());
|
||||
|
||||
if (!setter.is_null()) {
|
||||
// Call the JavaScript setter with receiver and value on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ mov(receiver,
|
||||
FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ push(receiver);
|
||||
__ push(value());
|
||||
ParameterCount actual(1);
|
||||
ParameterCount expected(setter);
|
||||
__ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// We have to return the passed value, not the return value of the setter.
|
||||
__ pop(eax);
|
||||
|
||||
// Restore context register.
|
||||
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
|
||||
Handle<Name> name) {
|
||||
__ pop(scratch1()); // remove the return address
|
||||
__ push(receiver());
|
||||
__ push(this->name());
|
||||
__ push(value());
|
||||
__ push(scratch1()); // restore return address
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_ic_property = ExternalReference(
|
||||
IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(store_ic_property, 3, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
|
||||
MapHandleList* receiver_maps, CodeHandleList* handler_stubs,
|
||||
MapHandleList* transitioned_maps) {
|
||||
Label miss;
|
||||
__ JumpIfSmi(receiver(), &miss, Label::kNear);
|
||||
__ mov(scratch1(), FieldOperand(receiver(), HeapObject::kMapOffset));
|
||||
for (int i = 0; i < receiver_maps->length(); ++i) {
|
||||
__ cmp(scratch1(), receiver_maps->at(i));
|
||||
if (transitioned_maps->at(i).is_null()) {
|
||||
__ j(equal, handler_stubs->at(i));
|
||||
} else {
|
||||
Label next_map;
|
||||
__ j(not_equal, &next_map, Label::kNear);
|
||||
__ mov(transition_map(), Immediate(transitioned_maps->at(i)));
|
||||
__ jmp(handler_stubs->at(i), RelocInfo::CODE_TARGET);
|
||||
__ bind(&next_map);
|
||||
}
|
||||
}
|
||||
__ bind(&miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
|
||||
}
|
||||
|
||||
|
||||
Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> getter) {
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
if (!getter.is_null()) {
|
||||
// Call the JavaScript getter with the receiver on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ mov(receiver,
|
||||
FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ push(receiver);
|
||||
ParameterCount actual(0);
|
||||
ParameterCount expected(getter);
|
||||
__ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// Restore context register.
|
||||
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
|
||||
Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
|
||||
Label miss;
|
||||
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
// Get the value from the cell.
|
||||
Register result = StoreIC::ValueRegister();
|
||||
if (masm()->serializer_enabled()) {
|
||||
__ mov(result, Immediate(cell));
|
||||
__ mov(result, FieldOperand(result, PropertyCell::kValueOffset));
|
||||
} else {
|
||||
__ mov(result, Operand::ForCell(cell));
|
||||
}
|
||||
|
||||
// Check for deleted property if property can actually be deleted.
|
||||
if (is_configurable) {
|
||||
__ cmp(result, factory()->the_hole_value());
|
||||
__ j(equal, &miss);
|
||||
} else if (FLAG_debug_code) {
|
||||
__ cmp(result, factory()->the_hole_value());
|
||||
__ Check(not_equal, kDontDeleteCellsCannotContainTheHole);
|
||||
}
|
||||
|
||||
Counters* counters = isolate()->counters();
|
||||
__ IncrementCounter(counters->named_load_global_stub(), 1);
|
||||
// The code above already loads the result into the return register.
|
||||
__ ret(0);
|
||||
|
||||
FrontendFooter(name, &miss);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
|
||||
CodeHandleList* handlers,
|
||||
Handle<Name> name,
|
||||
@ -905,70 +89,29 @@ Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void ElementHandlerCompiler::GenerateLoadDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- ecx : key
|
||||
// -- edx : receiver
|
||||
// -- esp[0] : return address
|
||||
// -----------------------------------
|
||||
DCHECK(edx.is(LoadIC::ReceiverRegister()));
|
||||
DCHECK(ecx.is(LoadIC::NameRegister()));
|
||||
Label slow, miss;
|
||||
|
||||
// This stub is meant to be tail-jumped to, the receiver must already
|
||||
// have been verified by the caller to not be a smi.
|
||||
__ JumpIfNotSmi(ecx, &miss);
|
||||
__ mov(ebx, ecx);
|
||||
__ SmiUntag(ebx);
|
||||
__ mov(eax, FieldOperand(edx, JSObject::kElementsOffset));
|
||||
|
||||
// Push receiver on the stack to free up a register for the dictionary
|
||||
// probing.
|
||||
__ push(edx);
|
||||
__ LoadFromNumberDictionary(&slow, eax, ecx, ebx, edx, edi, eax);
|
||||
// Pop receiver before returning.
|
||||
__ pop(edx);
|
||||
__ ret(0);
|
||||
|
||||
__ bind(&slow);
|
||||
__ pop(edx);
|
||||
|
||||
// ----------- S t a t e -------------
|
||||
// -- ecx : key
|
||||
// -- edx : receiver
|
||||
// -- esp[0] : return address
|
||||
// -----------------------------------
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
|
||||
MapHandleList* receiver_maps, CodeHandleList* handler_stubs,
|
||||
MapHandleList* transitioned_maps) {
|
||||
Label miss;
|
||||
__ JumpIfSmi(receiver(), &miss, Label::kNear);
|
||||
__ mov(scratch1(), FieldOperand(receiver(), HeapObject::kMapOffset));
|
||||
for (int i = 0; i < receiver_maps->length(); ++i) {
|
||||
__ cmp(scratch1(), receiver_maps->at(i));
|
||||
if (transitioned_maps->at(i).is_null()) {
|
||||
__ j(equal, handler_stubs->at(i));
|
||||
} else {
|
||||
Label next_map;
|
||||
__ j(not_equal, &next_map, Label::kNear);
|
||||
__ mov(transition_map(), Immediate(transitioned_maps->at(i)));
|
||||
__ jmp(handler_stubs->at(i), RelocInfo::CODE_TARGET);
|
||||
__ bind(&next_map);
|
||||
}
|
||||
}
|
||||
__ bind(&miss);
|
||||
// ----------- S t a t e -------------
|
||||
// -- ecx : key
|
||||
// -- edx : receiver
|
||||
// -- esp[0] : return address
|
||||
// -----------------------------------
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
|
||||
}
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
|
||||
|
||||
void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
|
||||
StrictMode strict_mode) {
|
||||
// Return address is on the stack.
|
||||
DCHECK(!ebx.is(StoreIC::ReceiverRegister()) &&
|
||||
!ebx.is(StoreIC::NameRegister()) && !ebx.is(StoreIC::ValueRegister()));
|
||||
__ pop(ebx);
|
||||
__ push(StoreIC::ReceiverRegister());
|
||||
__ push(StoreIC::NameRegister());
|
||||
__ push(StoreIC::ValueRegister());
|
||||
__ push(Immediate(Smi::FromInt(strict_mode)));
|
||||
__ push(ebx); // return address
|
||||
|
||||
// Do tail-call to runtime routine.
|
||||
__ TailCallRuntime(Runtime::kSetProperty, 4, 1);
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
|
||||
}
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
#include "src/ic/ic-inl.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
|
||||
@ -25,15 +25,24 @@ Handle<Code> PropertyICCompiler::Find(Handle<Name> name,
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyHandlerCompiler::Find(Handle<Name> name,
|
||||
Handle<Map> stub_holder,
|
||||
Code::Kind kind,
|
||||
CacheHolderFlag cache_holder,
|
||||
Code::StubType type) {
|
||||
Code::Flags flags = Code::ComputeHandlerFlags(kind, type, cache_holder);
|
||||
Object* probe = stub_holder->FindInCodeCache(*name, flags);
|
||||
if (probe->IsCode()) return handle(Code::cast(probe));
|
||||
return Handle<Code>::null();
|
||||
bool PropertyICCompiler::IncludesNumberType(TypeHandleList* types) {
|
||||
for (int i = 0; i < types->length(); ++i) {
|
||||
if (types->at(i)->Is(HeapType::Number())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompileMonomorphic(Handle<HeapType> type,
|
||||
Handle<Code> handler,
|
||||
Handle<Name> name,
|
||||
IcCheckType check) {
|
||||
TypeHandleList types(1);
|
||||
CodeHandleList handlers(1);
|
||||
types.Add(type);
|
||||
handlers.Add(handler);
|
||||
Code::StubType stub_type = handler->type();
|
||||
return CompilePolymorphic(&types, &handlers, name, stub_type, check);
|
||||
}
|
||||
|
||||
|
||||
@ -74,50 +83,6 @@ Handle<Code> PropertyICCompiler::ComputeMonomorphic(
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::ComputeLoadNonexistent(
|
||||
Handle<Name> name, Handle<HeapType> type) {
|
||||
Isolate* isolate = name->GetIsolate();
|
||||
Handle<Map> receiver_map = IC::TypeToMap(*type, isolate);
|
||||
if (receiver_map->prototype()->IsNull()) {
|
||||
// TODO(jkummerow/verwaest): If there is no prototype and the property
|
||||
// is nonexistent, introduce a builtin to handle this (fast properties
|
||||
// -> return undefined, dictionary properties -> do negative lookup).
|
||||
return Handle<Code>();
|
||||
}
|
||||
CacheHolderFlag flag;
|
||||
Handle<Map> stub_holder_map =
|
||||
IC::GetHandlerCacheHolder(*type, false, isolate, &flag);
|
||||
|
||||
// If no dictionary mode objects are present in the prototype chain, the load
|
||||
// nonexistent IC stub can be shared for all names for a given map and we use
|
||||
// the empty string for the map cache in that case. If there are dictionary
|
||||
// mode objects involved, we need to do negative lookups in the stub and
|
||||
// therefore the stub will be specific to the name.
|
||||
Handle<Name> cache_name =
|
||||
receiver_map->is_dictionary_map()
|
||||
? name
|
||||
: Handle<Name>::cast(isolate->factory()->nonexistent_symbol());
|
||||
Handle<Map> current_map = stub_holder_map;
|
||||
Handle<JSObject> last(JSObject::cast(receiver_map->prototype()));
|
||||
while (true) {
|
||||
if (current_map->is_dictionary_map()) cache_name = name;
|
||||
if (current_map->prototype()->IsNull()) break;
|
||||
last = handle(JSObject::cast(current_map->prototype()));
|
||||
current_map = handle(last->map());
|
||||
}
|
||||
// Compile the stub that is either shared for all names or
|
||||
// name specific if there are global objects involved.
|
||||
Handle<Code> handler = PropertyHandlerCompiler::Find(
|
||||
cache_name, stub_holder_map, Code::LOAD_IC, flag, Code::FAST);
|
||||
if (!handler.is_null()) return handler;
|
||||
|
||||
NamedLoadHandlerCompiler compiler(isolate, type, last, flag);
|
||||
handler = compiler.CompileLoadNonexistent(cache_name);
|
||||
Map::UpdateCodeCache(stub_holder_map, cache_name, handler);
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::ComputeKeyedLoadMonomorphic(
|
||||
Handle<Map> receiver_map) {
|
||||
Isolate* isolate = receiver_map->GetIsolate();
|
||||
@ -400,330 +365,6 @@ Handle<Code> PropertyICCompiler::CompileStoreMegamorphic(Code::Flags flags) {
|
||||
}
|
||||
|
||||
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Register NamedLoadHandlerCompiler::FrontendHeader(Register object_reg,
|
||||
Handle<Name> name,
|
||||
Label* miss) {
|
||||
PrototypeCheckType check_type = CHECK_ALL_MAPS;
|
||||
int function_index = -1;
|
||||
if (type()->Is(HeapType::String())) {
|
||||
function_index = Context::STRING_FUNCTION_INDEX;
|
||||
} else if (type()->Is(HeapType::Symbol())) {
|
||||
function_index = Context::SYMBOL_FUNCTION_INDEX;
|
||||
} else if (type()->Is(HeapType::Number())) {
|
||||
function_index = Context::NUMBER_FUNCTION_INDEX;
|
||||
} else if (type()->Is(HeapType::Boolean())) {
|
||||
function_index = Context::BOOLEAN_FUNCTION_INDEX;
|
||||
} else {
|
||||
check_type = SKIP_RECEIVER;
|
||||
}
|
||||
|
||||
if (check_type == CHECK_ALL_MAPS) {
|
||||
GenerateDirectLoadGlobalFunctionPrototype(masm(), function_index,
|
||||
scratch1(), miss);
|
||||
Object* function = isolate()->native_context()->get(function_index);
|
||||
Object* prototype = JSFunction::cast(function)->instance_prototype();
|
||||
set_type_for_object(handle(prototype, isolate()));
|
||||
object_reg = scratch1();
|
||||
}
|
||||
|
||||
// Check that the maps starting from the prototype haven't changed.
|
||||
return CheckPrototypes(object_reg, scratch1(), scratch2(), scratch3(), name,
|
||||
miss, check_type);
|
||||
}
|
||||
|
||||
|
||||
// Frontend for store uses the name register. It has to be restored before a
|
||||
// miss.
|
||||
Register NamedStoreHandlerCompiler::FrontendHeader(Register object_reg,
|
||||
Handle<Name> name,
|
||||
Label* miss) {
|
||||
return CheckPrototypes(object_reg, this->name(), scratch1(), scratch2(), name,
|
||||
miss, SKIP_RECEIVER);
|
||||
}
|
||||
|
||||
|
||||
bool PropertyICCompiler::IncludesNumberType(TypeHandleList* types) {
|
||||
for (int i = 0; i < types->length(); ++i) {
|
||||
if (types->at(i)->Is(HeapType::Number())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::Frontend(Register object_reg,
|
||||
Handle<Name> name) {
|
||||
Label miss;
|
||||
Register reg = FrontendHeader(object_reg, name, &miss);
|
||||
FrontendFooter(name, &miss);
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void PropertyHandlerCompiler::NonexistentFrontendHeader(Handle<Name> name,
|
||||
Label* miss,
|
||||
Register scratch1,
|
||||
Register scratch2) {
|
||||
Register holder_reg;
|
||||
Handle<Map> last_map;
|
||||
if (holder().is_null()) {
|
||||
holder_reg = receiver();
|
||||
last_map = IC::TypeToMap(*type(), isolate());
|
||||
// If |type| has null as its prototype, |holder()| is
|
||||
// Handle<JSObject>::null().
|
||||
DCHECK(last_map->prototype() == isolate()->heap()->null_value());
|
||||
} else {
|
||||
holder_reg = FrontendHeader(receiver(), name, miss);
|
||||
last_map = handle(holder()->map());
|
||||
}
|
||||
|
||||
if (last_map->is_dictionary_map()) {
|
||||
if (last_map->IsJSGlobalObjectMap()) {
|
||||
Handle<JSGlobalObject> global =
|
||||
holder().is_null()
|
||||
? Handle<JSGlobalObject>::cast(type()->AsConstant()->Value())
|
||||
: Handle<JSGlobalObject>::cast(holder());
|
||||
GenerateCheckPropertyCell(masm(), global, name, scratch1, miss);
|
||||
} else {
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(holder().is_null() ||
|
||||
holder()->property_dictionary()->FindEntry(name) ==
|
||||
NameDictionary::kNotFound);
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, holder_reg, name, scratch1,
|
||||
scratch2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadField(Handle<Name> name,
|
||||
FieldIndex field) {
|
||||
Register reg = Frontend(receiver(), name);
|
||||
__ Move(receiver(), reg);
|
||||
LoadFieldStub stub(isolate(), field);
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadConstant(Handle<Name> name,
|
||||
int constant_index) {
|
||||
Register reg = Frontend(receiver(), name);
|
||||
__ Move(receiver(), reg);
|
||||
LoadConstantStub stub(isolate(), constant_index);
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadNonexistent(
|
||||
Handle<Name> name) {
|
||||
Label miss;
|
||||
NonexistentFrontendHeader(name, &miss, scratch2(), scratch3());
|
||||
GenerateLoadConstant(isolate()->factory()->undefined_value());
|
||||
FrontendFooter(name, &miss);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadCallback(
|
||||
Handle<Name> name, Handle<ExecutableAccessorInfo> callback) {
|
||||
Register reg = Frontend(receiver(), name);
|
||||
GenerateLoadCallback(reg, callback);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadCallback(
|
||||
Handle<Name> name, const CallOptimization& call_optimization) {
|
||||
DCHECK(call_optimization.is_simple_api_call());
|
||||
Frontend(receiver(), name);
|
||||
Handle<Map> receiver_map = IC::TypeToMap(*type(), isolate());
|
||||
GenerateFastApiCall(masm(), call_optimization, receiver_map, receiver(),
|
||||
scratch1(), false, 0, NULL);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadInterceptor(
|
||||
LookupIterator* it) {
|
||||
// So far the most popular follow ups for interceptor loads are FIELD and
|
||||
// ExecutableAccessorInfo, so inline only them. Other cases may be added
|
||||
// later.
|
||||
bool inline_followup = it->state() == LookupIterator::PROPERTY;
|
||||
if (inline_followup) {
|
||||
switch (it->property_kind()) {
|
||||
case LookupIterator::DATA:
|
||||
inline_followup = it->property_details().type() == FIELD;
|
||||
break;
|
||||
case LookupIterator::ACCESSOR: {
|
||||
Handle<Object> accessors = it->GetAccessors();
|
||||
inline_followup = accessors->IsExecutableAccessorInfo();
|
||||
if (!inline_followup) break;
|
||||
Handle<ExecutableAccessorInfo> info =
|
||||
Handle<ExecutableAccessorInfo>::cast(accessors);
|
||||
inline_followup = info->getter() != NULL &&
|
||||
ExecutableAccessorInfo::IsCompatibleReceiverType(
|
||||
isolate(), info, type());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Register reg = Frontend(receiver(), it->name());
|
||||
if (inline_followup) {
|
||||
// TODO(368): Compile in the whole chain: all the interceptors in
|
||||
// prototypes and ultimate answer.
|
||||
GenerateLoadInterceptorWithFollowup(it, reg);
|
||||
} else {
|
||||
GenerateLoadInterceptor(reg);
|
||||
}
|
||||
return GetCode(kind(), Code::FAST, it->name());
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadPostInterceptor(
|
||||
LookupIterator* it, Register interceptor_reg) {
|
||||
Handle<JSObject> real_named_property_holder(it->GetHolder<JSObject>());
|
||||
|
||||
set_type_for_object(holder());
|
||||
set_holder(real_named_property_holder);
|
||||
Register reg = Frontend(interceptor_reg, it->name());
|
||||
|
||||
switch (it->property_kind()) {
|
||||
case LookupIterator::DATA: {
|
||||
DCHECK_EQ(FIELD, it->property_details().type());
|
||||
__ Move(receiver(), reg);
|
||||
LoadFieldStub stub(isolate(), it->GetFieldIndex());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
break;
|
||||
}
|
||||
case LookupIterator::ACCESSOR:
|
||||
Handle<ExecutableAccessorInfo> info =
|
||||
Handle<ExecutableAccessorInfo>::cast(it->GetAccessors());
|
||||
DCHECK_NE(NULL, info->getter());
|
||||
GenerateLoadCallback(reg, info);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompileMonomorphic(Handle<HeapType> type,
|
||||
Handle<Code> handler,
|
||||
Handle<Name> name,
|
||||
IcCheckType check) {
|
||||
TypeHandleList types(1);
|
||||
CodeHandleList handlers(1);
|
||||
types.Add(type);
|
||||
handlers.Add(handler);
|
||||
Code::StubType stub_type = handler->type();
|
||||
return CompilePolymorphic(&types, &handlers, name, stub_type, check);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadViaGetter(
|
||||
Handle<Name> name, Handle<JSFunction> getter) {
|
||||
Frontend(receiver(), name);
|
||||
GenerateLoadViaGetter(masm(), type(), receiver(), getter);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
// TODO(verwaest): Cleanup. holder() is actually the receiver.
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name) {
|
||||
Label miss, slow;
|
||||
|
||||
// Ensure no transitions to deprecated maps are followed.
|
||||
__ CheckMapDeprecated(transition, scratch1(), &miss);
|
||||
|
||||
// Check that we are allowed to write this.
|
||||
bool is_nonexistent = holder()->map() == transition->GetBackPointer();
|
||||
if (is_nonexistent) {
|
||||
// Find the top object.
|
||||
Handle<JSObject> last;
|
||||
PrototypeIterator iter(isolate(), holder());
|
||||
while (!iter.IsAtEnd()) {
|
||||
last = Handle<JSObject>::cast(PrototypeIterator::GetCurrent(iter));
|
||||
iter.Advance();
|
||||
}
|
||||
if (!last.is_null()) set_holder(last);
|
||||
NonexistentFrontendHeader(name, &miss, scratch1(), scratch2());
|
||||
} else {
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
DCHECK(holder()->HasFastProperties());
|
||||
}
|
||||
|
||||
GenerateStoreTransition(transition, name, receiver(), this->name(), value(),
|
||||
scratch1(), scratch2(), scratch3(), &miss, &slow);
|
||||
|
||||
GenerateRestoreName(&miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
|
||||
GenerateRestoreName(&slow, name);
|
||||
TailCallBuiltin(masm(), SlowBuiltin(kind()));
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreField(LookupIterator* it) {
|
||||
Label miss;
|
||||
GenerateStoreField(it, value(), &miss);
|
||||
__ bind(&miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
return GetCode(kind(), Code::FAST, it->name());
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreViaSetter(
|
||||
Handle<JSObject> object, Handle<Name> name, Handle<JSFunction> setter) {
|
||||
Frontend(receiver(), name);
|
||||
GenerateStoreViaSetter(masm(), type(), receiver(), setter);
|
||||
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
const CallOptimization& call_optimization) {
|
||||
Frontend(receiver(), name);
|
||||
Register values[] = {value()};
|
||||
GenerateFastApiCall(masm(), call_optimization, handle(object->map()),
|
||||
receiver(), scratch1(), true, 1, values);
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompileKeyedStoreMonomorphic(
|
||||
Handle<Map> receiver_map, KeyedAccessStoreMode store_mode) {
|
||||
ElementsKind elements_kind = receiver_map->elements_kind();
|
||||
bool is_jsarray = receiver_map->instance_type() == JS_ARRAY_TYPE;
|
||||
Handle<Code> stub;
|
||||
if (receiver_map->has_fast_elements() ||
|
||||
receiver_map->has_external_array_elements() ||
|
||||
receiver_map->has_fixed_typed_array_elements()) {
|
||||
stub = StoreFastElementStub(isolate(), is_jsarray, elements_kind,
|
||||
store_mode).GetCode();
|
||||
} else {
|
||||
stub = StoreElementStub(isolate(), is_jsarray, elements_kind, store_mode)
|
||||
.GetCode();
|
||||
}
|
||||
|
||||
__ DispatchMap(receiver(), scratch1(), receiver_map, stub, DO_SMI_CHECK);
|
||||
|
||||
TailCallBuiltin(masm(), Builtins::kKeyedStoreIC_Miss);
|
||||
|
||||
return GetCode(kind(), Code::NORMAL, factory()->empty_string());
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::GetCode(Code::Kind kind, Code::StubType type,
|
||||
Handle<Name> name,
|
||||
InlineCacheState state) {
|
||||
@ -736,48 +377,6 @@ Handle<Code> PropertyICCompiler::GetCode(Code::Kind kind, Code::StubType type,
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyHandlerCompiler::GetCode(Code::Kind kind,
|
||||
Code::StubType type,
|
||||
Handle<Name> name) {
|
||||
Code::Flags flags = Code::ComputeHandlerFlags(kind, type, cache_holder());
|
||||
Handle<Code> code = GetCodeWithFlags(flags, name);
|
||||
PROFILE(isolate(), CodeCreateEvent(Logger::STUB_TAG, *code, *name));
|
||||
return code;
|
||||
}
|
||||
|
||||
|
||||
void ElementHandlerCompiler::CompileElementHandlers(
|
||||
MapHandleList* receiver_maps, CodeHandleList* handlers) {
|
||||
for (int i = 0; i < receiver_maps->length(); ++i) {
|
||||
Handle<Map> receiver_map = receiver_maps->at(i);
|
||||
Handle<Code> cached_stub;
|
||||
|
||||
if ((receiver_map->instance_type() & kNotStringTag) == 0) {
|
||||
cached_stub = isolate()->builtins()->KeyedLoadIC_String();
|
||||
} else if (receiver_map->instance_type() < FIRST_JS_RECEIVER_TYPE) {
|
||||
cached_stub = isolate()->builtins()->KeyedLoadIC_Slow();
|
||||
} else {
|
||||
bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE;
|
||||
ElementsKind elements_kind = receiver_map->elements_kind();
|
||||
|
||||
if (IsFastElementsKind(elements_kind) ||
|
||||
IsExternalArrayElementsKind(elements_kind) ||
|
||||
IsFixedTypedArrayElementsKind(elements_kind)) {
|
||||
cached_stub = LoadFastElementStub(isolate(), is_js_array, elements_kind)
|
||||
.GetCode();
|
||||
} else if (elements_kind == SLOPPY_ARGUMENTS_ELEMENTS) {
|
||||
cached_stub = isolate()->builtins()->KeyedLoadIC_SloppyArguments();
|
||||
} else {
|
||||
DCHECK(elements_kind == DICTIONARY_ELEMENTS);
|
||||
cached_stub = LoadDictionaryElementStub(isolate()).GetCode();
|
||||
}
|
||||
}
|
||||
|
||||
handlers->Add(cached_stub);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
|
||||
MapHandleList* receiver_maps, KeyedAccessStoreMode store_mode) {
|
||||
// Collect MONOMORPHIC stubs for all |receiver_maps|.
|
||||
@ -827,11 +426,32 @@ Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
|
||||
}
|
||||
|
||||
|
||||
void ElementHandlerCompiler::GenerateStoreDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
KeyedStoreIC::GenerateSlow(masm);
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompileKeyedStoreMonomorphic(
|
||||
Handle<Map> receiver_map, KeyedAccessStoreMode store_mode) {
|
||||
ElementsKind elements_kind = receiver_map->elements_kind();
|
||||
bool is_jsarray = receiver_map->instance_type() == JS_ARRAY_TYPE;
|
||||
Handle<Code> stub;
|
||||
if (receiver_map->has_fast_elements() ||
|
||||
receiver_map->has_external_array_elements() ||
|
||||
receiver_map->has_fixed_typed_array_elements()) {
|
||||
stub = StoreFastElementStub(isolate(), is_jsarray, elements_kind,
|
||||
store_mode).GetCode();
|
||||
} else {
|
||||
stub = StoreElementStub(isolate(), is_jsarray, elements_kind, store_mode)
|
||||
.GetCode();
|
||||
}
|
||||
|
||||
__ DispatchMap(receiver(), scratch1(), receiver_map, stub, DO_SMI_CHECK);
|
||||
|
||||
TailCallBuiltin(masm(), Builtins::kKeyedStoreIC_Miss);
|
||||
|
||||
return GetCode(kind(), Code::NORMAL, factory()->empty_string());
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
@ -5,19 +5,12 @@
|
||||
#ifndef V8_IC_IC_COMPILER_H_
|
||||
#define V8_IC_IC_COMPILER_H_
|
||||
|
||||
#include "src/code-stubs.h"
|
||||
#include "src/ic/access-compiler.h"
|
||||
#include "src/macro-assembler.h"
|
||||
#include "src/objects.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
|
||||
class CallOptimization;
|
||||
|
||||
|
||||
enum PrototypeCheckType { CHECK_ALL_MAPS, SKIP_RECEIVER };
|
||||
enum IcCheckType { ELEMENT, PROPERTY };
|
||||
|
||||
|
||||
@ -127,263 +120,6 @@ class PropertyICCompiler : public PropertyAccessCompiler {
|
||||
};
|
||||
|
||||
|
||||
class PropertyHandlerCompiler : public PropertyAccessCompiler {
|
||||
public:
|
||||
static Handle<Code> Find(Handle<Name> name, Handle<Map> map, Code::Kind kind,
|
||||
CacheHolderFlag cache_holder, Code::StubType type);
|
||||
|
||||
protected:
|
||||
PropertyHandlerCompiler(Isolate* isolate, Code::Kind kind,
|
||||
Handle<HeapType> type, Handle<JSObject> holder,
|
||||
CacheHolderFlag cache_holder)
|
||||
: PropertyAccessCompiler(isolate, kind, cache_holder),
|
||||
type_(type),
|
||||
holder_(holder) {}
|
||||
|
||||
virtual ~PropertyHandlerCompiler() {}
|
||||
|
||||
virtual Register FrontendHeader(Register object_reg, Handle<Name> name,
|
||||
Label* miss) {
|
||||
UNREACHABLE();
|
||||
return receiver();
|
||||
}
|
||||
|
||||
virtual void FrontendFooter(Handle<Name> name, Label* miss) { UNREACHABLE(); }
|
||||
|
||||
Register Frontend(Register object_reg, Handle<Name> name);
|
||||
void NonexistentFrontendHeader(Handle<Name> name, Label* miss,
|
||||
Register scratch1, Register scratch2);
|
||||
|
||||
// TODO(verwaest): Make non-static.
|
||||
static void GenerateFastApiCall(MacroAssembler* masm,
|
||||
const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver,
|
||||
Register scratch, bool is_store, int argc,
|
||||
Register* values);
|
||||
|
||||
// Helper function used to check that the dictionary doesn't contain
|
||||
// the property. This function may return false negatives, so miss_label
|
||||
// must always call a backup property check that is complete.
|
||||
// This function is safe to call if the receiver has fast properties.
|
||||
// Name must be unique and receiver must be a heap object.
|
||||
static void GenerateDictionaryNegativeLookup(MacroAssembler* masm,
|
||||
Label* miss_label,
|
||||
Register receiver,
|
||||
Handle<Name> name, Register r0,
|
||||
Register r1);
|
||||
|
||||
// Generate code to check that a global property cell is empty. Create
|
||||
// the property cell at compilation time if no cell exists for the
|
||||
// property.
|
||||
static void GenerateCheckPropertyCell(MacroAssembler* masm,
|
||||
Handle<JSGlobalObject> global,
|
||||
Handle<Name> name, Register scratch,
|
||||
Label* miss);
|
||||
|
||||
// Generates code that verifies that the property holder has not changed
|
||||
// (checking maps of objects in the prototype chain for fast and global
|
||||
// objects or doing negative lookup for slow objects, ensures that the
|
||||
// property cells for global objects are still empty) and checks that the map
|
||||
// of the holder has not changed. If necessary the function also generates
|
||||
// code for security check in case of global object holders. Helps to make
|
||||
// sure that the current IC is still valid.
|
||||
//
|
||||
// The scratch and holder registers are always clobbered, but the object
|
||||
// register is only clobbered if it the same as the holder register. The
|
||||
// function returns a register containing the holder - either object_reg or
|
||||
// holder_reg.
|
||||
Register CheckPrototypes(Register object_reg, Register holder_reg,
|
||||
Register scratch1, Register scratch2,
|
||||
Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check = CHECK_ALL_MAPS);
|
||||
|
||||
Handle<Code> GetCode(Code::Kind kind, Code::StubType type, Handle<Name> name);
|
||||
void set_type_for_object(Handle<Object> object) {
|
||||
type_ = IC::CurrentTypeOf(object, isolate());
|
||||
}
|
||||
void set_holder(Handle<JSObject> holder) { holder_ = holder; }
|
||||
Handle<HeapType> type() const { return type_; }
|
||||
Handle<JSObject> holder() const { return holder_; }
|
||||
|
||||
private:
|
||||
Handle<HeapType> type_;
|
||||
Handle<JSObject> holder_;
|
||||
};
|
||||
|
||||
|
||||
class NamedLoadHandlerCompiler : public PropertyHandlerCompiler {
|
||||
public:
|
||||
NamedLoadHandlerCompiler(Isolate* isolate, Handle<HeapType> type,
|
||||
Handle<JSObject> holder,
|
||||
CacheHolderFlag cache_holder)
|
||||
: PropertyHandlerCompiler(isolate, Code::LOAD_IC, type, holder,
|
||||
cache_holder) {}
|
||||
|
||||
virtual ~NamedLoadHandlerCompiler() {}
|
||||
|
||||
Handle<Code> CompileLoadField(Handle<Name> name, FieldIndex index);
|
||||
|
||||
Handle<Code> CompileLoadCallback(Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback);
|
||||
|
||||
Handle<Code> CompileLoadCallback(Handle<Name> name,
|
||||
const CallOptimization& call_optimization);
|
||||
|
||||
Handle<Code> CompileLoadConstant(Handle<Name> name, int constant_index);
|
||||
|
||||
// The LookupIterator is used to perform a lookup behind the interceptor. If
|
||||
// the iterator points to a LookupIterator::PROPERTY, its access will be
|
||||
// inlined.
|
||||
Handle<Code> CompileLoadInterceptor(LookupIterator* it);
|
||||
|
||||
Handle<Code> CompileLoadViaGetter(Handle<Name> name,
|
||||
Handle<JSFunction> getter);
|
||||
|
||||
Handle<Code> CompileLoadGlobal(Handle<PropertyCell> cell, Handle<Name> name,
|
||||
bool is_configurable);
|
||||
|
||||
// Static interface
|
||||
static Handle<Code> ComputeLoadNonexistent(Handle<Name> name,
|
||||
Handle<HeapType> type);
|
||||
|
||||
static void GenerateLoadViaGetter(MacroAssembler* masm, Handle<HeapType> type,
|
||||
Register receiver,
|
||||
Handle<JSFunction> getter);
|
||||
|
||||
static void GenerateLoadViaGetterForDeopt(MacroAssembler* masm) {
|
||||
GenerateLoadViaGetter(masm, Handle<HeapType>::null(), no_reg,
|
||||
Handle<JSFunction>());
|
||||
}
|
||||
|
||||
static void GenerateLoadFunctionPrototype(MacroAssembler* masm,
|
||||
Register receiver,
|
||||
Register scratch1,
|
||||
Register scratch2,
|
||||
Label* miss_label);
|
||||
|
||||
// These constants describe the structure of the interceptor arguments on the
|
||||
// stack. The arguments are pushed by the (platform-specific)
|
||||
// PushInterceptorArguments and read by LoadPropertyWithInterceptorOnly and
|
||||
// LoadWithInterceptor.
|
||||
static const int kInterceptorArgsNameIndex = 0;
|
||||
static const int kInterceptorArgsInfoIndex = 1;
|
||||
static const int kInterceptorArgsThisIndex = 2;
|
||||
static const int kInterceptorArgsHolderIndex = 3;
|
||||
static const int kInterceptorArgsLength = 4;
|
||||
|
||||
protected:
|
||||
virtual Register FrontendHeader(Register object_reg, Handle<Name> name,
|
||||
Label* miss);
|
||||
|
||||
virtual void FrontendFooter(Handle<Name> name, Label* miss);
|
||||
|
||||
private:
|
||||
Handle<Code> CompileLoadNonexistent(Handle<Name> name);
|
||||
void GenerateLoadConstant(Handle<Object> value);
|
||||
void GenerateLoadCallback(Register reg,
|
||||
Handle<ExecutableAccessorInfo> callback);
|
||||
void GenerateLoadCallback(const CallOptimization& call_optimization,
|
||||
Handle<Map> receiver_map);
|
||||
void GenerateLoadInterceptor(Register holder_reg);
|
||||
void GenerateLoadInterceptorWithFollowup(LookupIterator* it,
|
||||
Register holder_reg);
|
||||
void GenerateLoadPostInterceptor(LookupIterator* it, Register reg);
|
||||
|
||||
// Generates prototype loading code that uses the objects from the
|
||||
// context we were in when this function was called. If the context
|
||||
// has changed, a jump to miss is performed. This ties the generated
|
||||
// code to a particular context and so must not be used in cases
|
||||
// where the generated code is not allowed to have references to
|
||||
// objects from a context.
|
||||
static void GenerateDirectLoadGlobalFunctionPrototype(MacroAssembler* masm,
|
||||
int index,
|
||||
Register prototype,
|
||||
Label* miss);
|
||||
|
||||
|
||||
Register scratch4() { return registers_[5]; }
|
||||
};
|
||||
|
||||
|
||||
class NamedStoreHandlerCompiler : public PropertyHandlerCompiler {
|
||||
public:
|
||||
explicit NamedStoreHandlerCompiler(Isolate* isolate, Handle<HeapType> type,
|
||||
Handle<JSObject> holder)
|
||||
: PropertyHandlerCompiler(isolate, Code::STORE_IC, type, holder,
|
||||
kCacheOnReceiver) {}
|
||||
|
||||
virtual ~NamedStoreHandlerCompiler() {}
|
||||
|
||||
Handle<Code> CompileStoreTransition(Handle<Map> transition,
|
||||
Handle<Name> name);
|
||||
Handle<Code> CompileStoreField(LookupIterator* it);
|
||||
Handle<Code> CompileStoreCallback(Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback);
|
||||
Handle<Code> CompileStoreCallback(Handle<JSObject> object, Handle<Name> name,
|
||||
const CallOptimization& call_optimization);
|
||||
Handle<Code> CompileStoreViaSetter(Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<JSFunction> setter);
|
||||
Handle<Code> CompileStoreInterceptor(Handle<Name> name);
|
||||
|
||||
static void GenerateStoreViaSetter(MacroAssembler* masm,
|
||||
Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter);
|
||||
|
||||
static void GenerateStoreViaSetterForDeopt(MacroAssembler* masm) {
|
||||
GenerateStoreViaSetter(masm, Handle<HeapType>::null(), no_reg,
|
||||
Handle<JSFunction>());
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual Register FrontendHeader(Register object_reg, Handle<Name> name,
|
||||
Label* miss);
|
||||
|
||||
virtual void FrontendFooter(Handle<Name> name, Label* miss);
|
||||
void GenerateRestoreName(Label* label, Handle<Name> name);
|
||||
|
||||
private:
|
||||
void GenerateStoreTransition(Handle<Map> transition, Handle<Name> name,
|
||||
Register receiver_reg, Register name_reg,
|
||||
Register value_reg, Register scratch1,
|
||||
Register scratch2, Register scratch3,
|
||||
Label* miss_label, Label* slow);
|
||||
|
||||
void GenerateStoreField(LookupIterator* lookup, Register value_reg,
|
||||
Label* miss_label);
|
||||
|
||||
static Builtins::Name SlowBuiltin(Code::Kind kind) {
|
||||
switch (kind) {
|
||||
case Code::STORE_IC:
|
||||
return Builtins::kStoreIC_Slow;
|
||||
case Code::KEYED_STORE_IC:
|
||||
return Builtins::kKeyedStoreIC_Slow;
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
return Builtins::kStoreIC_Slow;
|
||||
}
|
||||
|
||||
static Register value();
|
||||
};
|
||||
|
||||
|
||||
class ElementHandlerCompiler : public PropertyHandlerCompiler {
|
||||
public:
|
||||
explicit ElementHandlerCompiler(Isolate* isolate)
|
||||
: PropertyHandlerCompiler(isolate, Code::KEYED_LOAD_IC,
|
||||
Handle<HeapType>::null(),
|
||||
Handle<JSObject>::null(), kCacheOnReceiver) {}
|
||||
|
||||
virtual ~ElementHandlerCompiler() {}
|
||||
|
||||
void CompileElementHandlers(MapHandleList* receiver_maps,
|
||||
CodeHandleList* handlers);
|
||||
|
||||
static void GenerateLoadDictionaryElement(MacroAssembler* masm);
|
||||
static void GenerateStoreDictionaryElement(MacroAssembler* masm);
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "src/conversions.h"
|
||||
#include "src/execution.h"
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
#include "src/ic/ic-inl.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
#include "src/ic/stub-cache.h"
|
||||
|
842
src/ic/x64/handler-compiler-x64.cc
Normal file
842
src/ic/x64/handler-compiler-x64.cc
Normal file
@ -0,0 +1,842 @@
|
||||
// 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.
|
||||
|
||||
#include "src/v8.h"
|
||||
|
||||
#if V8_TARGET_ARCH_X64
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
|
||||
MacroAssembler* masm, Label* miss_label, Register receiver,
|
||||
Handle<Name> name, Register scratch0, Register scratch1) {
|
||||
DCHECK(name->IsUniqueName());
|
||||
DCHECK(!receiver.is(scratch0));
|
||||
Counters* counters = masm->isolate()->counters();
|
||||
__ IncrementCounter(counters->negative_lookups(), 1);
|
||||
__ IncrementCounter(counters->negative_lookups_miss(), 1);
|
||||
|
||||
__ movp(scratch0, FieldOperand(receiver, HeapObject::kMapOffset));
|
||||
|
||||
const int kInterceptorOrAccessCheckNeededMask =
|
||||
(1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
|
||||
|
||||
// Bail out if the receiver has a named interceptor or requires access checks.
|
||||
__ testb(FieldOperand(scratch0, Map::kBitFieldOffset),
|
||||
Immediate(kInterceptorOrAccessCheckNeededMask));
|
||||
__ j(not_zero, miss_label);
|
||||
|
||||
// Check that receiver is a JSObject.
|
||||
__ CmpInstanceType(scratch0, FIRST_SPEC_OBJECT_TYPE);
|
||||
__ j(below, miss_label);
|
||||
|
||||
// Load properties array.
|
||||
Register properties = scratch0;
|
||||
__ movp(properties, FieldOperand(receiver, JSObject::kPropertiesOffset));
|
||||
|
||||
// Check that the properties array is a dictionary.
|
||||
__ CompareRoot(FieldOperand(properties, HeapObject::kMapOffset),
|
||||
Heap::kHashTableMapRootIndex);
|
||||
__ j(not_equal, miss_label);
|
||||
|
||||
Label done;
|
||||
NameDictionaryLookupStub::GenerateNegativeLookup(masm, miss_label, &done,
|
||||
properties, name, scratch1);
|
||||
__ bind(&done);
|
||||
__ DecrementCounter(counters->negative_lookups_miss(), 1);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
|
||||
MacroAssembler* masm, int index, Register prototype, Label* miss) {
|
||||
Isolate* isolate = masm->isolate();
|
||||
// Get the global function with the given index.
|
||||
Handle<JSFunction> function(
|
||||
JSFunction::cast(isolate->native_context()->get(index)));
|
||||
|
||||
// Check we're still in the same context.
|
||||
Register scratch = prototype;
|
||||
const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
|
||||
__ movp(scratch, Operand(rsi, offset));
|
||||
__ movp(scratch, FieldOperand(scratch, GlobalObject::kNativeContextOffset));
|
||||
__ Cmp(Operand(scratch, Context::SlotOffset(index)), function);
|
||||
__ j(not_equal, miss);
|
||||
|
||||
// Load its initial map. The global functions all have initial maps.
|
||||
__ Move(prototype, Handle<Map>(function->initial_map()));
|
||||
// Load the prototype from the initial map.
|
||||
__ movp(prototype, FieldOperand(prototype, Map::kPrototypeOffset));
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
|
||||
MacroAssembler* masm, Register receiver, Register result, Register scratch,
|
||||
Label* miss_label) {
|
||||
__ TryGetFunctionPrototype(receiver, result, miss_label);
|
||||
if (!result.is(rax)) __ movp(rax, result);
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
|
||||
Register holder, Register name,
|
||||
Handle<JSObject> holder_obj) {
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
|
||||
__ Push(name);
|
||||
Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
|
||||
DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
|
||||
__ Move(kScratchRegister, interceptor);
|
||||
__ Push(kScratchRegister);
|
||||
__ Push(receiver);
|
||||
__ Push(holder);
|
||||
}
|
||||
|
||||
|
||||
static void CompileCallLoadPropertyWithInterceptor(
|
||||
MacroAssembler* masm, Register receiver, Register holder, Register name,
|
||||
Handle<JSObject> holder_obj, IC::UtilityId id) {
|
||||
PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
|
||||
__ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
|
||||
NamedLoadHandlerCompiler::kInterceptorArgsLength);
|
||||
}
|
||||
|
||||
|
||||
// Generate call to api function.
|
||||
void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
MacroAssembler* masm, const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver, Register scratch_in,
|
||||
bool is_store, int argc, Register* values) {
|
||||
DCHECK(optimization.is_simple_api_call());
|
||||
|
||||
__ PopReturnAddressTo(scratch_in);
|
||||
// receiver
|
||||
__ Push(receiver);
|
||||
// Write the arguments to stack frame.
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Register arg = values[argc - 1 - i];
|
||||
DCHECK(!receiver.is(arg));
|
||||
DCHECK(!scratch_in.is(arg));
|
||||
__ Push(arg);
|
||||
}
|
||||
__ PushReturnAddressFrom(scratch_in);
|
||||
// Stack now matches JSFunction abi.
|
||||
|
||||
// Abi for CallApiFunctionStub.
|
||||
Register callee = rax;
|
||||
Register call_data = rbx;
|
||||
Register holder = rcx;
|
||||
Register api_function_address = rdx;
|
||||
Register scratch = rdi; // scratch_in is no longer valid.
|
||||
|
||||
// Put holder in place.
|
||||
CallOptimization::HolderLookup holder_lookup;
|
||||
Handle<JSObject> api_holder =
|
||||
optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
|
||||
switch (holder_lookup) {
|
||||
case CallOptimization::kHolderIsReceiver:
|
||||
__ Move(holder, receiver);
|
||||
break;
|
||||
case CallOptimization::kHolderFound:
|
||||
__ Move(holder, api_holder);
|
||||
break;
|
||||
case CallOptimization::kHolderNotFound:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
Isolate* isolate = masm->isolate();
|
||||
Handle<JSFunction> function = optimization.constant_function();
|
||||
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
|
||||
Handle<Object> call_data_obj(api_call_info->data(), isolate);
|
||||
|
||||
// Put callee in place.
|
||||
__ Move(callee, function);
|
||||
|
||||
bool call_data_undefined = false;
|
||||
// Put call_data in place.
|
||||
if (isolate->heap()->InNewSpace(*call_data_obj)) {
|
||||
__ Move(scratch, api_call_info);
|
||||
__ movp(call_data, FieldOperand(scratch, CallHandlerInfo::kDataOffset));
|
||||
} else if (call_data_obj->IsUndefined()) {
|
||||
call_data_undefined = true;
|
||||
__ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
|
||||
} else {
|
||||
__ Move(call_data, call_data_obj);
|
||||
}
|
||||
|
||||
// Put api_function_address in place.
|
||||
Address function_address = v8::ToCData<Address>(api_call_info->callback());
|
||||
__ Move(api_function_address, function_address,
|
||||
RelocInfo::EXTERNAL_REFERENCE);
|
||||
|
||||
// Jump to stub.
|
||||
CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void PropertyHandlerCompiler::GenerateCheckPropertyCell(
|
||||
MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
|
||||
Register scratch, Label* miss) {
|
||||
Handle<PropertyCell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
|
||||
DCHECK(cell->value()->IsTheHole());
|
||||
__ Move(scratch, cell);
|
||||
__ Cmp(FieldOperand(scratch, Cell::kValueOffset),
|
||||
masm->isolate()->factory()->the_hole_value());
|
||||
__ j(not_equal, miss);
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
// Save value register, so we can restore it later.
|
||||
__ Push(value());
|
||||
|
||||
if (!setter.is_null()) {
|
||||
// Call the JavaScript setter with receiver and value on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ movp(receiver,
|
||||
FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver);
|
||||
__ Push(value());
|
||||
ParameterCount actual(1);
|
||||
ParameterCount expected(setter);
|
||||
__ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// We have to return the passed value, not the return value of the setter.
|
||||
__ Pop(rax);
|
||||
|
||||
// Restore context register.
|
||||
__ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> getter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- rax : receiver
|
||||
// -- rcx : name
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
if (!getter.is_null()) {
|
||||
// Call the JavaScript getter with the receiver on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ movp(receiver,
|
||||
FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver);
|
||||
ParameterCount actual(0);
|
||||
ParameterCount expected(getter);
|
||||
__ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// Restore context register.
|
||||
__ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void ElementHandlerCompiler::GenerateLoadDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- rcx : key
|
||||
// -- rdx : receiver
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
DCHECK(rdx.is(LoadIC::ReceiverRegister()));
|
||||
DCHECK(rcx.is(LoadIC::NameRegister()));
|
||||
Label slow, miss;
|
||||
|
||||
// This stub is meant to be tail-jumped to, the receiver must already
|
||||
// have been verified by the caller to not be a smi.
|
||||
|
||||
__ JumpIfNotSmi(rcx, &miss);
|
||||
__ SmiToInteger32(rbx, rcx);
|
||||
__ movp(rax, FieldOperand(rdx, JSObject::kElementsOffset));
|
||||
|
||||
// Check whether the elements is a number dictionary.
|
||||
// rdx: receiver
|
||||
// rcx: key
|
||||
// rbx: key as untagged int32
|
||||
// rax: elements
|
||||
__ LoadFromNumberDictionary(&slow, rax, rcx, rbx, r9, rdi, rax);
|
||||
__ ret(0);
|
||||
|
||||
__ bind(&slow);
|
||||
// ----------- S t a t e -------------
|
||||
// -- rcx : key
|
||||
// -- rdx : receiver
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
|
||||
|
||||
__ bind(&miss);
|
||||
// ----------- S t a t e -------------
|
||||
// -- rcx : key
|
||||
// -- rdx : receiver
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM((masm()))
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
|
||||
Handle<Name> name) {
|
||||
if (!label->is_unused()) {
|
||||
__ bind(label);
|
||||
__ Move(this->name(), name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Receiver_reg is preserved on jumps to miss_label, but may be destroyed if
|
||||
// store is successful.
|
||||
void NamedStoreHandlerCompiler::GenerateStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name, Register receiver_reg,
|
||||
Register storage_reg, Register value_reg, Register scratch1,
|
||||
Register scratch2, Register unused, Label* miss_label, Label* slow) {
|
||||
int descriptor = transition->LastAdded();
|
||||
DescriptorArray* descriptors = transition->instance_descriptors();
|
||||
PropertyDetails details = descriptors->GetDetails(descriptor);
|
||||
Representation representation = details.representation();
|
||||
DCHECK(!representation.IsNone());
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
|
||||
__ Cmp(value_reg, constant);
|
||||
__ j(not_equal, miss_label);
|
||||
} else if (representation.IsSmi()) {
|
||||
__ JumpIfNotSmi(value_reg, miss_label);
|
||||
} else if (representation.IsHeapObject()) {
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType* field_type = descriptors->GetFieldType(descriptor);
|
||||
HeapType::Iterator<Map> it = field_type->Classes();
|
||||
if (!it.Done()) {
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(value_reg, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ j(not_equal, miss_label);
|
||||
break;
|
||||
}
|
||||
__ j(equal, &do_store, Label::kNear);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
}
|
||||
} else if (representation.IsDouble()) {
|
||||
Label do_store, heap_number;
|
||||
__ AllocateHeapNumber(storage_reg, scratch1, slow, MUTABLE);
|
||||
|
||||
__ JumpIfNotSmi(value_reg, &heap_number);
|
||||
__ SmiToInteger32(scratch1, value_reg);
|
||||
__ Cvtlsi2sd(xmm0, scratch1);
|
||||
__ jmp(&do_store);
|
||||
|
||||
__ bind(&heap_number);
|
||||
__ CheckMap(value_reg, isolate()->factory()->heap_number_map(), miss_label,
|
||||
DONT_DO_SMI_CHECK);
|
||||
__ movsd(xmm0, FieldOperand(value_reg, HeapNumber::kValueOffset));
|
||||
|
||||
__ bind(&do_store);
|
||||
__ movsd(FieldOperand(storage_reg, HeapNumber::kValueOffset), xmm0);
|
||||
}
|
||||
|
||||
// Stub never generated for objects that require access checks.
|
||||
DCHECK(!transition->is_access_check_needed());
|
||||
|
||||
// Perform map transition for the receiver if necessary.
|
||||
if (details.type() == FIELD &&
|
||||
Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
|
||||
// The properties must be extended before we can store the value.
|
||||
// We jump to a runtime call that extends the properties array.
|
||||
__ PopReturnAddressTo(scratch1);
|
||||
__ Push(receiver_reg);
|
||||
__ Push(transition);
|
||||
__ Push(value_reg);
|
||||
__ PushReturnAddressFrom(scratch1);
|
||||
__ TailCallExternalReference(
|
||||
ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
|
||||
isolate()),
|
||||
3, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the map of the object.
|
||||
__ Move(scratch1, transition);
|
||||
__ movp(FieldOperand(receiver_reg, HeapObject::kMapOffset), scratch1);
|
||||
|
||||
// Update the write barrier for the map field.
|
||||
__ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
|
||||
kDontSaveFPRegs, OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
DCHECK(value_reg.is(rax));
|
||||
__ ret(0);
|
||||
return;
|
||||
}
|
||||
|
||||
int index = transition->instance_descriptors()->GetFieldIndex(
|
||||
transition->LastAdded());
|
||||
|
||||
// Adjust for the number of properties stored in the object. Even in the
|
||||
// face of a transition we can use the old map here because the size of the
|
||||
// object and the number of in-object properties is not going to change.
|
||||
index -= transition->inobject_properties();
|
||||
|
||||
// TODO(verwaest): Share this code as a code stub.
|
||||
SmiCheck smi_check =
|
||||
representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
|
||||
if (index < 0) {
|
||||
// Set the property straight into the object.
|
||||
int offset = transition->instance_size() + (index * kPointerSize);
|
||||
if (representation.IsDouble()) {
|
||||
__ movp(FieldOperand(receiver_reg, offset), storage_reg);
|
||||
} else {
|
||||
__ movp(FieldOperand(receiver_reg, offset), value_reg);
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ movp(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
|
||||
kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
} else {
|
||||
// Write to the properties array.
|
||||
int offset = index * kPointerSize + FixedArray::kHeaderSize;
|
||||
// Get the properties array (optimistically).
|
||||
__ movp(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset));
|
||||
if (representation.IsDouble()) {
|
||||
__ movp(FieldOperand(scratch1, offset), storage_reg);
|
||||
} else {
|
||||
__ movp(FieldOperand(scratch1, offset), value_reg);
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ movp(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
|
||||
kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the value (register rax).
|
||||
DCHECK(value_reg.is(rax));
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
|
||||
Register value_reg,
|
||||
Label* miss_label) {
|
||||
DCHECK(lookup->representation().IsHeapObject());
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(value_reg, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ j(not_equal, miss_label);
|
||||
break;
|
||||
}
|
||||
__ j(equal, &do_store, Label::kNear);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
|
||||
StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
|
||||
lookup->representation());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::CheckPrototypes(
|
||||
Register object_reg, Register holder_reg, Register scratch1,
|
||||
Register scratch2, Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check) {
|
||||
Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
|
||||
|
||||
// Make sure there's no overlap between holder and object registers.
|
||||
DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
|
||||
DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
|
||||
!scratch2.is(scratch1));
|
||||
|
||||
// Keep track of the current object in register reg. On the first
|
||||
// iteration, reg is an alias for object_reg, on later iterations,
|
||||
// it is an alias for holder_reg.
|
||||
Register reg = object_reg;
|
||||
int depth = 0;
|
||||
|
||||
Handle<JSObject> current = Handle<JSObject>::null();
|
||||
if (type()->IsConstant()) {
|
||||
current = Handle<JSObject>::cast(type()->AsConstant()->Value());
|
||||
}
|
||||
Handle<JSObject> prototype = Handle<JSObject>::null();
|
||||
Handle<Map> current_map = receiver_map;
|
||||
Handle<Map> holder_map(holder()->map());
|
||||
// Traverse the prototype chain and check the maps in the prototype chain for
|
||||
// fast and global objects or do negative lookup for normal objects.
|
||||
while (!current_map.is_identical_to(holder_map)) {
|
||||
++depth;
|
||||
|
||||
// Only global objects and objects that do not require access
|
||||
// checks are allowed in stubs.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
|
||||
prototype = handle(JSObject::cast(current_map->prototype()));
|
||||
if (current_map->is_dictionary_map() &&
|
||||
!current_map->IsJSGlobalObjectMap()) {
|
||||
DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(current.is_null() ||
|
||||
current->property_dictionary()->FindEntry(name) ==
|
||||
NameDictionary::kNotFound);
|
||||
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
|
||||
scratch2);
|
||||
|
||||
__ movp(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
__ movp(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
bool in_new_space = heap()->InNewSpace(*prototype);
|
||||
// Two possible reasons for loading the prototype from the map:
|
||||
// (1) Can't store references to new space in code.
|
||||
// (2) Handler is shared for all receivers with the same prototype
|
||||
// map (but not necessarily the same prototype instance).
|
||||
bool load_prototype_from_map = in_new_space || depth == 1;
|
||||
if (load_prototype_from_map) {
|
||||
// Save the map in scratch1 for later.
|
||||
__ movp(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
|
||||
}
|
||||
if (depth != 1 || check == CHECK_ALL_MAPS) {
|
||||
__ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Check access rights to the global object. This has to happen after
|
||||
// the map check so that we know that the object is actually a global
|
||||
// object.
|
||||
// This allows us to install generated handlers for accesses to the
|
||||
// global proxy (as opposed to using slow ICs). See corresponding code
|
||||
// in LookupForRead().
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch2, miss);
|
||||
} else if (current_map->IsJSGlobalObjectMap()) {
|
||||
GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
|
||||
name, scratch2, miss);
|
||||
}
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
|
||||
if (load_prototype_from_map) {
|
||||
__ movp(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
__ Move(reg, prototype);
|
||||
}
|
||||
}
|
||||
|
||||
// Go to the next object in the prototype chain.
|
||||
current = prototype;
|
||||
current_map = handle(current->map());
|
||||
}
|
||||
|
||||
// Log the check depth.
|
||||
LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
|
||||
|
||||
if (depth != 0 || check == CHECK_ALL_MAPS) {
|
||||
// Check the holder map.
|
||||
__ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Perform security check for access to the global object.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, miss);
|
||||
}
|
||||
|
||||
// Return the register containing the holder.
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ jmp(&success);
|
||||
__ bind(miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ jmp(&success);
|
||||
GenerateRestoreName(miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadCallback(
|
||||
Register reg, Handle<ExecutableAccessorInfo> callback) {
|
||||
// Insert additional parameters into the stack frame above return address.
|
||||
DCHECK(!scratch4().is(reg));
|
||||
__ PopReturnAddressTo(scratch4());
|
||||
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
|
||||
__ Push(receiver()); // receiver
|
||||
if (heap()->InNewSpace(callback->data())) {
|
||||
DCHECK(!scratch2().is(reg));
|
||||
__ Move(scratch2(), callback);
|
||||
__ Push(FieldOperand(scratch2(),
|
||||
ExecutableAccessorInfo::kDataOffset)); // data
|
||||
} else {
|
||||
__ Push(Handle<Object>(callback->data(), isolate()));
|
||||
}
|
||||
DCHECK(!kScratchRegister.is(reg));
|
||||
__ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex);
|
||||
__ Push(kScratchRegister); // return value
|
||||
__ Push(kScratchRegister); // return value default
|
||||
__ PushAddress(ExternalReference::isolate_address(isolate()));
|
||||
__ Push(reg); // holder
|
||||
__ Push(name()); // name
|
||||
// Save a pointer to where we pushed the arguments pointer. This will be
|
||||
// passed as the const PropertyAccessorInfo& to the C++ callback.
|
||||
|
||||
__ PushReturnAddressFrom(scratch4());
|
||||
|
||||
// Abi for CallApiGetter
|
||||
Register api_function_address = r8;
|
||||
Address getter_address = v8::ToCData<Address>(callback->getter());
|
||||
__ Move(api_function_address, getter_address, RelocInfo::EXTERNAL_REFERENCE);
|
||||
|
||||
CallApiGetterStub stub(isolate());
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
|
||||
// Return the constant value.
|
||||
__ Move(rax, value);
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
|
||||
LookupIterator* it, Register holder_reg) {
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
|
||||
// Compile the interceptor call, followed by inline code to load the
|
||||
// property from further up the prototype chain if the call fails.
|
||||
// Check that the maps haven't changed.
|
||||
DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
|
||||
|
||||
// Preserve the receiver register explicitly whenever it is different from the
|
||||
// holder and it is needed should the interceptor return without any result.
|
||||
// The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
|
||||
// case might cause a miss during the prototype check.
|
||||
bool must_perform_prototype_check =
|
||||
!holder().is_identical_to(it->GetHolder<JSObject>());
|
||||
bool must_preserve_receiver_reg =
|
||||
!receiver().is(holder_reg) &&
|
||||
(it->property_kind() == LookupIterator::ACCESSOR ||
|
||||
must_perform_prototype_check);
|
||||
|
||||
// Save necessary data before invoking an interceptor.
|
||||
// Requires a frame to make GC aware of pushed pointers.
|
||||
{
|
||||
FrameScope frame_scope(masm(), StackFrame::INTERNAL);
|
||||
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Push(receiver());
|
||||
}
|
||||
__ Push(holder_reg);
|
||||
__ Push(this->name());
|
||||
|
||||
// Invoke an interceptor. Note: map checks from receiver to
|
||||
// interceptor's holder has been compiled before (see a caller
|
||||
// of this method.)
|
||||
CompileCallLoadPropertyWithInterceptor(
|
||||
masm(), receiver(), holder_reg, this->name(), holder(),
|
||||
IC::kLoadPropertyWithInterceptorOnly);
|
||||
|
||||
// Check if interceptor provided a value for property. If it's
|
||||
// the case, return immediately.
|
||||
Label interceptor_failed;
|
||||
__ CompareRoot(rax, Heap::kNoInterceptorResultSentinelRootIndex);
|
||||
__ j(equal, &interceptor_failed);
|
||||
frame_scope.GenerateLeaveFrame();
|
||||
__ ret(0);
|
||||
|
||||
__ bind(&interceptor_failed);
|
||||
__ Pop(this->name());
|
||||
__ Pop(holder_reg);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Pop(receiver());
|
||||
}
|
||||
|
||||
// Leave the internal frame.
|
||||
}
|
||||
|
||||
GenerateLoadPostInterceptor(it, holder_reg);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
|
||||
// Call the runtime system to load the interceptor.
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
__ PopReturnAddressTo(scratch2());
|
||||
PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
|
||||
holder());
|
||||
__ PushReturnAddressFrom(scratch2());
|
||||
|
||||
ExternalReference ref = ExternalReference(
|
||||
IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(
|
||||
ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback) {
|
||||
Register holder_reg = Frontend(receiver(), name);
|
||||
|
||||
__ PopReturnAddressTo(scratch1());
|
||||
__ Push(receiver());
|
||||
__ Push(holder_reg);
|
||||
__ Push(callback); // callback info
|
||||
__ Push(name);
|
||||
__ Push(value());
|
||||
__ PushReturnAddressFrom(scratch1());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_callback_property =
|
||||
ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
|
||||
__ TailCallExternalReference(store_callback_property, 5, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
|
||||
Handle<Name> name) {
|
||||
__ PopReturnAddressTo(scratch1());
|
||||
__ Push(receiver());
|
||||
__ Push(this->name());
|
||||
__ Push(value());
|
||||
__ PushReturnAddressFrom(scratch1());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_ic_property = ExternalReference(
|
||||
IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(store_ic_property, 3, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
|
||||
Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
|
||||
Label miss;
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
|
||||
// Get the value from the cell.
|
||||
Register result = StoreIC::ValueRegister();
|
||||
__ Move(result, cell);
|
||||
__ movp(result, FieldOperand(result, PropertyCell::kValueOffset));
|
||||
|
||||
// Check for deleted property if property can actually be deleted.
|
||||
if (is_configurable) {
|
||||
__ CompareRoot(result, Heap::kTheHoleValueRootIndex);
|
||||
__ j(equal, &miss);
|
||||
} else if (FLAG_debug_code) {
|
||||
__ CompareRoot(result, Heap::kTheHoleValueRootIndex);
|
||||
__ Check(not_equal, kDontDeleteCellsCannotContainTheHole);
|
||||
}
|
||||
|
||||
Counters* counters = isolate()->counters();
|
||||
__ IncrementCounter(counters->named_load_global_stub(), 1);
|
||||
__ ret(0);
|
||||
|
||||
FrontendFooter(name, &miss);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, name);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
||||
#endif // V8_TARGET_ARCH_X64
|
@ -6,7 +6,6 @@
|
||||
|
||||
#if V8_TARGET_ARCH_X64
|
||||
|
||||
#include "src/ic/call-optimization.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
|
||||
namespace v8 {
|
||||
@ -15,697 +14,21 @@ namespace internal {
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup(
|
||||
MacroAssembler* masm, Label* miss_label, Register receiver,
|
||||
Handle<Name> name, Register scratch0, Register scratch1) {
|
||||
DCHECK(name->IsUniqueName());
|
||||
DCHECK(!receiver.is(scratch0));
|
||||
Counters* counters = masm->isolate()->counters();
|
||||
__ IncrementCounter(counters->negative_lookups(), 1);
|
||||
__ IncrementCounter(counters->negative_lookups_miss(), 1);
|
||||
|
||||
__ movp(scratch0, FieldOperand(receiver, HeapObject::kMapOffset));
|
||||
|
||||
const int kInterceptorOrAccessCheckNeededMask =
|
||||
(1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded);
|
||||
|
||||
// Bail out if the receiver has a named interceptor or requires access checks.
|
||||
__ testb(FieldOperand(scratch0, Map::kBitFieldOffset),
|
||||
Immediate(kInterceptorOrAccessCheckNeededMask));
|
||||
__ j(not_zero, miss_label);
|
||||
|
||||
// Check that receiver is a JSObject.
|
||||
__ CmpInstanceType(scratch0, FIRST_SPEC_OBJECT_TYPE);
|
||||
__ j(below, miss_label);
|
||||
|
||||
// Load properties array.
|
||||
Register properties = scratch0;
|
||||
__ movp(properties, FieldOperand(receiver, JSObject::kPropertiesOffset));
|
||||
|
||||
// Check that the properties array is a dictionary.
|
||||
__ CompareRoot(FieldOperand(properties, HeapObject::kMapOffset),
|
||||
Heap::kHashTableMapRootIndex);
|
||||
__ j(not_equal, miss_label);
|
||||
|
||||
Label done;
|
||||
NameDictionaryLookupStub::GenerateNegativeLookup(masm, miss_label, &done,
|
||||
properties, name, scratch1);
|
||||
__ bind(&done);
|
||||
__ DecrementCounter(counters->negative_lookups_miss(), 1);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype(
|
||||
MacroAssembler* masm, int index, Register prototype, Label* miss) {
|
||||
Isolate* isolate = masm->isolate();
|
||||
// Get the global function with the given index.
|
||||
Handle<JSFunction> function(
|
||||
JSFunction::cast(isolate->native_context()->get(index)));
|
||||
|
||||
// Check we're still in the same context.
|
||||
Register scratch = prototype;
|
||||
const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX);
|
||||
__ movp(scratch, Operand(rsi, offset));
|
||||
__ movp(scratch, FieldOperand(scratch, GlobalObject::kNativeContextOffset));
|
||||
__ Cmp(Operand(scratch, Context::SlotOffset(index)), function);
|
||||
__ j(not_equal, miss);
|
||||
|
||||
// Load its initial map. The global functions all have initial maps.
|
||||
__ Move(prototype, Handle<Map>(function->initial_map()));
|
||||
// Load the prototype from the initial map.
|
||||
__ movp(prototype, FieldOperand(prototype, Map::kPrototypeOffset));
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype(
|
||||
MacroAssembler* masm, Register receiver, Register result, Register scratch,
|
||||
Label* miss_label) {
|
||||
__ TryGetFunctionPrototype(receiver, result, miss_label);
|
||||
if (!result.is(rax)) __ movp(rax, result);
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
static void PushInterceptorArguments(MacroAssembler* masm, Register receiver,
|
||||
Register holder, Register name,
|
||||
Handle<JSObject> holder_obj) {
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3);
|
||||
STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4);
|
||||
__ Push(name);
|
||||
Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor());
|
||||
DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor));
|
||||
__ Move(kScratchRegister, interceptor);
|
||||
__ Push(kScratchRegister);
|
||||
__ Push(receiver);
|
||||
__ Push(holder);
|
||||
}
|
||||
|
||||
|
||||
static void CompileCallLoadPropertyWithInterceptor(
|
||||
MacroAssembler* masm, Register receiver, Register holder, Register name,
|
||||
Handle<JSObject> holder_obj, IC::UtilityId id) {
|
||||
PushInterceptorArguments(masm, receiver, holder, name, holder_obj);
|
||||
__ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()),
|
||||
NamedLoadHandlerCompiler::kInterceptorArgsLength);
|
||||
}
|
||||
|
||||
|
||||
// Generate call to api function.
|
||||
void PropertyHandlerCompiler::GenerateFastApiCall(
|
||||
MacroAssembler* masm, const CallOptimization& optimization,
|
||||
Handle<Map> receiver_map, Register receiver, Register scratch_in,
|
||||
bool is_store, int argc, Register* values) {
|
||||
DCHECK(optimization.is_simple_api_call());
|
||||
|
||||
__ PopReturnAddressTo(scratch_in);
|
||||
// receiver
|
||||
__ Push(receiver);
|
||||
// Write the arguments to stack frame.
|
||||
for (int i = 0; i < argc; i++) {
|
||||
Register arg = values[argc - 1 - i];
|
||||
DCHECK(!receiver.is(arg));
|
||||
DCHECK(!scratch_in.is(arg));
|
||||
__ Push(arg);
|
||||
}
|
||||
__ PushReturnAddressFrom(scratch_in);
|
||||
// Stack now matches JSFunction abi.
|
||||
|
||||
// Abi for CallApiFunctionStub.
|
||||
Register callee = rax;
|
||||
Register call_data = rbx;
|
||||
Register holder = rcx;
|
||||
Register api_function_address = rdx;
|
||||
Register scratch = rdi; // scratch_in is no longer valid.
|
||||
|
||||
// Put holder in place.
|
||||
CallOptimization::HolderLookup holder_lookup;
|
||||
Handle<JSObject> api_holder =
|
||||
optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup);
|
||||
switch (holder_lookup) {
|
||||
case CallOptimization::kHolderIsReceiver:
|
||||
__ Move(holder, receiver);
|
||||
break;
|
||||
case CallOptimization::kHolderFound:
|
||||
__ Move(holder, api_holder);
|
||||
break;
|
||||
case CallOptimization::kHolderNotFound:
|
||||
UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
Isolate* isolate = masm->isolate();
|
||||
Handle<JSFunction> function = optimization.constant_function();
|
||||
Handle<CallHandlerInfo> api_call_info = optimization.api_call_info();
|
||||
Handle<Object> call_data_obj(api_call_info->data(), isolate);
|
||||
|
||||
// Put callee in place.
|
||||
__ Move(callee, function);
|
||||
|
||||
bool call_data_undefined = false;
|
||||
// Put call_data in place.
|
||||
if (isolate->heap()->InNewSpace(*call_data_obj)) {
|
||||
__ Move(scratch, api_call_info);
|
||||
__ movp(call_data, FieldOperand(scratch, CallHandlerInfo::kDataOffset));
|
||||
} else if (call_data_obj->IsUndefined()) {
|
||||
call_data_undefined = true;
|
||||
__ LoadRoot(call_data, Heap::kUndefinedValueRootIndex);
|
||||
} else {
|
||||
__ Move(call_data, call_data_obj);
|
||||
}
|
||||
|
||||
// Put api_function_address in place.
|
||||
Address function_address = v8::ToCData<Address>(api_call_info->callback());
|
||||
__ Move(api_function_address, function_address,
|
||||
RelocInfo::EXTERNAL_REFERENCE);
|
||||
|
||||
// Jump to stub.
|
||||
CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc);
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void PropertyHandlerCompiler::GenerateCheckPropertyCell(
|
||||
MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name,
|
||||
Register scratch, Label* miss) {
|
||||
Handle<PropertyCell> cell = JSGlobalObject::EnsurePropertyCell(global, name);
|
||||
DCHECK(cell->value()->IsTheHole());
|
||||
__ Move(scratch, cell);
|
||||
__ Cmp(FieldOperand(scratch, Cell::kValueOffset),
|
||||
masm->isolate()->factory()->the_hole_value());
|
||||
__ j(not_equal, miss);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM((masm()))
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label,
|
||||
Handle<Name> name) {
|
||||
if (!label->is_unused()) {
|
||||
__ bind(label);
|
||||
__ Move(this->name(), name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Receiver_reg is preserved on jumps to miss_label, but may be destroyed if
|
||||
// store is successful.
|
||||
void NamedStoreHandlerCompiler::GenerateStoreTransition(
|
||||
Handle<Map> transition, Handle<Name> name, Register receiver_reg,
|
||||
Register storage_reg, Register value_reg, Register scratch1,
|
||||
Register scratch2, Register unused, Label* miss_label, Label* slow) {
|
||||
int descriptor = transition->LastAdded();
|
||||
DescriptorArray* descriptors = transition->instance_descriptors();
|
||||
PropertyDetails details = descriptors->GetDetails(descriptor);
|
||||
Representation representation = details.representation();
|
||||
DCHECK(!representation.IsNone());
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
Handle<Object> constant(descriptors->GetValue(descriptor), isolate());
|
||||
__ Cmp(value_reg, constant);
|
||||
__ j(not_equal, miss_label);
|
||||
} else if (representation.IsSmi()) {
|
||||
__ JumpIfNotSmi(value_reg, miss_label);
|
||||
} else if (representation.IsHeapObject()) {
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType* field_type = descriptors->GetFieldType(descriptor);
|
||||
HeapType::Iterator<Map> it = field_type->Classes();
|
||||
if (!it.Done()) {
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(value_reg, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ j(not_equal, miss_label);
|
||||
break;
|
||||
}
|
||||
__ j(equal, &do_store, Label::kNear);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
}
|
||||
} else if (representation.IsDouble()) {
|
||||
Label do_store, heap_number;
|
||||
__ AllocateHeapNumber(storage_reg, scratch1, slow, MUTABLE);
|
||||
|
||||
__ JumpIfNotSmi(value_reg, &heap_number);
|
||||
__ SmiToInteger32(scratch1, value_reg);
|
||||
__ Cvtlsi2sd(xmm0, scratch1);
|
||||
__ jmp(&do_store);
|
||||
|
||||
__ bind(&heap_number);
|
||||
__ CheckMap(value_reg, isolate()->factory()->heap_number_map(), miss_label,
|
||||
DONT_DO_SMI_CHECK);
|
||||
__ movsd(xmm0, FieldOperand(value_reg, HeapNumber::kValueOffset));
|
||||
|
||||
__ bind(&do_store);
|
||||
__ movsd(FieldOperand(storage_reg, HeapNumber::kValueOffset), xmm0);
|
||||
}
|
||||
|
||||
// Stub never generated for objects that require access checks.
|
||||
DCHECK(!transition->is_access_check_needed());
|
||||
|
||||
// Perform map transition for the receiver if necessary.
|
||||
if (details.type() == FIELD &&
|
||||
Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) {
|
||||
// The properties must be extended before we can store the value.
|
||||
// We jump to a runtime call that extends the properties array.
|
||||
__ PopReturnAddressTo(scratch1);
|
||||
__ Push(receiver_reg);
|
||||
__ Push(transition);
|
||||
__ Push(value_reg);
|
||||
__ PushReturnAddressFrom(scratch1);
|
||||
__ TailCallExternalReference(
|
||||
ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage),
|
||||
isolate()),
|
||||
3, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Update the map of the object.
|
||||
__ Move(scratch1, transition);
|
||||
__ movp(FieldOperand(receiver_reg, HeapObject::kMapOffset), scratch1);
|
||||
|
||||
// Update the write barrier for the map field.
|
||||
__ RecordWriteField(receiver_reg, HeapObject::kMapOffset, scratch1, scratch2,
|
||||
kDontSaveFPRegs, OMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
|
||||
|
||||
if (details.type() == CONSTANT) {
|
||||
DCHECK(value_reg.is(rax));
|
||||
__ ret(0);
|
||||
return;
|
||||
}
|
||||
|
||||
int index = transition->instance_descriptors()->GetFieldIndex(
|
||||
transition->LastAdded());
|
||||
|
||||
// Adjust for the number of properties stored in the object. Even in the
|
||||
// face of a transition we can use the old map here because the size of the
|
||||
// object and the number of in-object properties is not going to change.
|
||||
index -= transition->inobject_properties();
|
||||
|
||||
// TODO(verwaest): Share this code as a code stub.
|
||||
SmiCheck smi_check =
|
||||
representation.IsTagged() ? INLINE_SMI_CHECK : OMIT_SMI_CHECK;
|
||||
if (index < 0) {
|
||||
// Set the property straight into the object.
|
||||
int offset = transition->instance_size() + (index * kPointerSize);
|
||||
if (representation.IsDouble()) {
|
||||
__ movp(FieldOperand(receiver_reg, offset), storage_reg);
|
||||
} else {
|
||||
__ movp(FieldOperand(receiver_reg, offset), value_reg);
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ movp(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(receiver_reg, offset, storage_reg, scratch1,
|
||||
kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
} else {
|
||||
// Write to the properties array.
|
||||
int offset = index * kPointerSize + FixedArray::kHeaderSize;
|
||||
// Get the properties array (optimistically).
|
||||
__ movp(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset));
|
||||
if (representation.IsDouble()) {
|
||||
__ movp(FieldOperand(scratch1, offset), storage_reg);
|
||||
} else {
|
||||
__ movp(FieldOperand(scratch1, offset), value_reg);
|
||||
}
|
||||
|
||||
if (!representation.IsSmi()) {
|
||||
// Update the write barrier for the array address.
|
||||
if (!representation.IsDouble()) {
|
||||
__ movp(storage_reg, value_reg);
|
||||
}
|
||||
__ RecordWriteField(scratch1, offset, storage_reg, receiver_reg,
|
||||
kDontSaveFPRegs, EMIT_REMEMBERED_SET, smi_check);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the value (register rax).
|
||||
DCHECK(value_reg.is(rax));
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup,
|
||||
Register value_reg,
|
||||
Label* miss_label) {
|
||||
DCHECK(lookup->representation().IsHeapObject());
|
||||
__ JumpIfSmi(value_reg, miss_label);
|
||||
HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes();
|
||||
Label do_store;
|
||||
while (true) {
|
||||
__ CompareMap(value_reg, it.Current());
|
||||
it.Advance();
|
||||
if (it.Done()) {
|
||||
__ j(not_equal, miss_label);
|
||||
break;
|
||||
}
|
||||
__ j(equal, &do_store, Label::kNear);
|
||||
}
|
||||
__ bind(&do_store);
|
||||
|
||||
StoreFieldStub stub(isolate(), lookup->GetFieldIndex(),
|
||||
lookup->representation());
|
||||
GenerateTailCall(masm(), stub.GetCode());
|
||||
}
|
||||
|
||||
|
||||
Register PropertyHandlerCompiler::CheckPrototypes(
|
||||
Register object_reg, Register holder_reg, Register scratch1,
|
||||
Register scratch2, Handle<Name> name, Label* miss,
|
||||
PrototypeCheckType check) {
|
||||
Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate()));
|
||||
|
||||
// Make sure there's no overlap between holder and object registers.
|
||||
DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg));
|
||||
DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) &&
|
||||
!scratch2.is(scratch1));
|
||||
|
||||
// Keep track of the current object in register reg. On the first
|
||||
// iteration, reg is an alias for object_reg, on later iterations,
|
||||
// it is an alias for holder_reg.
|
||||
Register reg = object_reg;
|
||||
int depth = 0;
|
||||
|
||||
Handle<JSObject> current = Handle<JSObject>::null();
|
||||
if (type()->IsConstant()) {
|
||||
current = Handle<JSObject>::cast(type()->AsConstant()->Value());
|
||||
}
|
||||
Handle<JSObject> prototype = Handle<JSObject>::null();
|
||||
Handle<Map> current_map = receiver_map;
|
||||
Handle<Map> holder_map(holder()->map());
|
||||
// Traverse the prototype chain and check the maps in the prototype chain for
|
||||
// fast and global objects or do negative lookup for normal objects.
|
||||
while (!current_map.is_identical_to(holder_map)) {
|
||||
++depth;
|
||||
|
||||
// Only global objects and objects that do not require access
|
||||
// checks are allowed in stubs.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
|
||||
prototype = handle(JSObject::cast(current_map->prototype()));
|
||||
if (current_map->is_dictionary_map() &&
|
||||
!current_map->IsJSGlobalObjectMap()) {
|
||||
DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast.
|
||||
if (!name->IsUniqueName()) {
|
||||
DCHECK(name->IsString());
|
||||
name = factory()->InternalizeString(Handle<String>::cast(name));
|
||||
}
|
||||
DCHECK(current.is_null() ||
|
||||
current->property_dictionary()->FindEntry(name) ==
|
||||
NameDictionary::kNotFound);
|
||||
|
||||
GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1,
|
||||
scratch2);
|
||||
|
||||
__ movp(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
__ movp(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
bool in_new_space = heap()->InNewSpace(*prototype);
|
||||
// Two possible reasons for loading the prototype from the map:
|
||||
// (1) Can't store references to new space in code.
|
||||
// (2) Handler is shared for all receivers with the same prototype
|
||||
// map (but not necessarily the same prototype instance).
|
||||
bool load_prototype_from_map = in_new_space || depth == 1;
|
||||
if (load_prototype_from_map) {
|
||||
// Save the map in scratch1 for later.
|
||||
__ movp(scratch1, FieldOperand(reg, HeapObject::kMapOffset));
|
||||
}
|
||||
if (depth != 1 || check == CHECK_ALL_MAPS) {
|
||||
__ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Check access rights to the global object. This has to happen after
|
||||
// the map check so that we know that the object is actually a global
|
||||
// object.
|
||||
// This allows us to install generated handlers for accesses to the
|
||||
// global proxy (as opposed to using slow ICs). See corresponding code
|
||||
// in LookupForRead().
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch2, miss);
|
||||
} else if (current_map->IsJSGlobalObjectMap()) {
|
||||
GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current),
|
||||
name, scratch2, miss);
|
||||
}
|
||||
reg = holder_reg; // From now on the object will be in holder_reg.
|
||||
|
||||
if (load_prototype_from_map) {
|
||||
__ movp(reg, FieldOperand(scratch1, Map::kPrototypeOffset));
|
||||
} else {
|
||||
__ Move(reg, prototype);
|
||||
}
|
||||
}
|
||||
|
||||
// Go to the next object in the prototype chain.
|
||||
current = prototype;
|
||||
current_map = handle(current->map());
|
||||
}
|
||||
|
||||
// Log the check depth.
|
||||
LOG(isolate(), IntEvent("check-maps-depth", depth + 1));
|
||||
|
||||
if (depth != 0 || check == CHECK_ALL_MAPS) {
|
||||
// Check the holder map.
|
||||
__ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK);
|
||||
}
|
||||
|
||||
// Perform security check for access to the global object.
|
||||
DCHECK(current_map->IsJSGlobalProxyMap() ||
|
||||
!current_map->is_access_check_needed());
|
||||
if (current_map->IsJSGlobalProxyMap()) {
|
||||
__ CheckAccessGlobalProxy(reg, scratch1, miss);
|
||||
}
|
||||
|
||||
// Return the register containing the holder.
|
||||
return reg;
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ jmp(&success);
|
||||
__ bind(miss);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) {
|
||||
if (!miss->is_unused()) {
|
||||
Label success;
|
||||
__ jmp(&success);
|
||||
GenerateRestoreName(miss, name);
|
||||
TailCallBuiltin(masm(), MissBuiltin(kind()));
|
||||
__ bind(&success);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadCallback(
|
||||
Register reg, Handle<ExecutableAccessorInfo> callback) {
|
||||
// Insert additional parameters into the stack frame above return address.
|
||||
DCHECK(!scratch4().is(reg));
|
||||
__ PopReturnAddressTo(scratch4());
|
||||
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5);
|
||||
STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6);
|
||||
__ Push(receiver()); // receiver
|
||||
if (heap()->InNewSpace(callback->data())) {
|
||||
DCHECK(!scratch2().is(reg));
|
||||
__ Move(scratch2(), callback);
|
||||
__ Push(FieldOperand(scratch2(),
|
||||
ExecutableAccessorInfo::kDataOffset)); // data
|
||||
} else {
|
||||
__ Push(Handle<Object>(callback->data(), isolate()));
|
||||
}
|
||||
DCHECK(!kScratchRegister.is(reg));
|
||||
__ LoadRoot(kScratchRegister, Heap::kUndefinedValueRootIndex);
|
||||
__ Push(kScratchRegister); // return value
|
||||
__ Push(kScratchRegister); // return value default
|
||||
__ PushAddress(ExternalReference::isolate_address(isolate()));
|
||||
__ Push(reg); // holder
|
||||
__ Push(name()); // name
|
||||
// Save a pointer to where we pushed the arguments pointer. This will be
|
||||
// passed as the const PropertyAccessorInfo& to the C++ callback.
|
||||
|
||||
__ PushReturnAddressFrom(scratch4());
|
||||
|
||||
// Abi for CallApiGetter
|
||||
Register api_function_address = r8;
|
||||
Address getter_address = v8::ToCData<Address>(callback->getter());
|
||||
__ Move(api_function_address, getter_address, RelocInfo::EXTERNAL_REFERENCE);
|
||||
|
||||
CallApiGetterStub stub(isolate());
|
||||
__ TailCallStub(&stub);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) {
|
||||
// Return the constant value.
|
||||
__ Move(rax, value);
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup(
|
||||
LookupIterator* it, Register holder_reg) {
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
|
||||
// Compile the interceptor call, followed by inline code to load the
|
||||
// property from further up the prototype chain if the call fails.
|
||||
// Check that the maps haven't changed.
|
||||
DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1()));
|
||||
|
||||
// Preserve the receiver register explicitly whenever it is different from the
|
||||
// holder and it is needed should the interceptor return without any result.
|
||||
// The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD
|
||||
// case might cause a miss during the prototype check.
|
||||
bool must_perform_prototype_check =
|
||||
!holder().is_identical_to(it->GetHolder<JSObject>());
|
||||
bool must_preserve_receiver_reg =
|
||||
!receiver().is(holder_reg) &&
|
||||
(it->property_kind() == LookupIterator::ACCESSOR ||
|
||||
must_perform_prototype_check);
|
||||
|
||||
// Save necessary data before invoking an interceptor.
|
||||
// Requires a frame to make GC aware of pushed pointers.
|
||||
{
|
||||
FrameScope frame_scope(masm(), StackFrame::INTERNAL);
|
||||
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Push(receiver());
|
||||
}
|
||||
__ Push(holder_reg);
|
||||
__ Push(this->name());
|
||||
|
||||
// Invoke an interceptor. Note: map checks from receiver to
|
||||
// interceptor's holder has been compiled before (see a caller
|
||||
// of this method.)
|
||||
CompileCallLoadPropertyWithInterceptor(
|
||||
masm(), receiver(), holder_reg, this->name(), holder(),
|
||||
IC::kLoadPropertyWithInterceptorOnly);
|
||||
|
||||
// Check if interceptor provided a value for property. If it's
|
||||
// the case, return immediately.
|
||||
Label interceptor_failed;
|
||||
__ CompareRoot(rax, Heap::kNoInterceptorResultSentinelRootIndex);
|
||||
__ j(equal, &interceptor_failed);
|
||||
frame_scope.GenerateLeaveFrame();
|
||||
__ ret(0);
|
||||
|
||||
__ bind(&interceptor_failed);
|
||||
__ Pop(this->name());
|
||||
__ Pop(holder_reg);
|
||||
if (must_preserve_receiver_reg) {
|
||||
__ Pop(receiver());
|
||||
}
|
||||
|
||||
// Leave the internal frame.
|
||||
}
|
||||
|
||||
GenerateLoadPostInterceptor(it, holder_reg);
|
||||
}
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) {
|
||||
// Call the runtime system to load the interceptor.
|
||||
DCHECK(holder()->HasNamedInterceptor());
|
||||
DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined());
|
||||
__ PopReturnAddressTo(scratch2());
|
||||
PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(),
|
||||
holder());
|
||||
__ PushReturnAddressFrom(scratch2());
|
||||
|
||||
ExternalReference ref = ExternalReference(
|
||||
IC_Utility(IC::kLoadPropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(
|
||||
ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback(
|
||||
Handle<JSObject> object, Handle<Name> name,
|
||||
Handle<ExecutableAccessorInfo> callback) {
|
||||
Register holder_reg = Frontend(receiver(), name);
|
||||
|
||||
__ PopReturnAddressTo(scratch1());
|
||||
__ Push(receiver());
|
||||
__ Push(holder_reg);
|
||||
__ Push(callback); // callback info
|
||||
__ Push(name);
|
||||
__ Push(value());
|
||||
__ PushReturnAddressFrom(scratch1());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_callback_property =
|
||||
ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate());
|
||||
__ TailCallExternalReference(store_callback_property, 5, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> setter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
// Save value register, so we can restore it later.
|
||||
__ Push(value());
|
||||
|
||||
if (!setter.is_null()) {
|
||||
// Call the JavaScript setter with receiver and value on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ movp(receiver,
|
||||
FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver);
|
||||
__ Push(value());
|
||||
ParameterCount actual(1);
|
||||
ParameterCount expected(setter);
|
||||
__ InvokeFunction(setter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// We have to return the passed value, not the return value of the setter.
|
||||
__ Pop(rax);
|
||||
|
||||
// Restore context register.
|
||||
__ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ ret(0);
|
||||
void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
|
||||
StrictMode strict_mode) {
|
||||
// Return address is on the stack.
|
||||
DCHECK(!rbx.is(StoreIC::ReceiverRegister()) &&
|
||||
!rbx.is(StoreIC::NameRegister()) && !rbx.is(StoreIC::ValueRegister()));
|
||||
|
||||
__ PopReturnAddressTo(rbx);
|
||||
__ Push(StoreIC::ReceiverRegister());
|
||||
__ Push(StoreIC::NameRegister());
|
||||
__ Push(StoreIC::ValueRegister());
|
||||
__ Push(Smi::FromInt(strict_mode));
|
||||
__ PushReturnAddressFrom(rbx);
|
||||
|
||||
// Do tail-call to runtime routine.
|
||||
__ TailCallRuntime(Runtime::kSetProperty, 4, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -713,24 +36,6 @@ void NamedStoreHandlerCompiler::GenerateStoreViaSetter(
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor(
|
||||
Handle<Name> name) {
|
||||
__ PopReturnAddressTo(scratch1());
|
||||
__ Push(receiver());
|
||||
__ Push(this->name());
|
||||
__ Push(value());
|
||||
__ PushReturnAddressFrom(scratch1());
|
||||
|
||||
// Do tail-call to the runtime system.
|
||||
ExternalReference store_ic_property = ExternalReference(
|
||||
IC_Utility(IC::kStorePropertyWithInterceptor), isolate());
|
||||
__ TailCallExternalReference(store_ic_property, 3, 1);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::FAST, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
|
||||
MapHandleList* receiver_maps, CodeHandleList* handler_stubs,
|
||||
MapHandleList* transitioned_maps) {
|
||||
@ -763,83 +68,6 @@ Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
|
||||
}
|
||||
|
||||
|
||||
Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); }
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void NamedLoadHandlerCompiler::GenerateLoadViaGetter(
|
||||
MacroAssembler* masm, Handle<HeapType> type, Register receiver,
|
||||
Handle<JSFunction> getter) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- rax : receiver
|
||||
// -- rcx : name
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
{
|
||||
FrameScope scope(masm, StackFrame::INTERNAL);
|
||||
|
||||
if (!getter.is_null()) {
|
||||
// Call the JavaScript getter with the receiver on the stack.
|
||||
if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) {
|
||||
// Swap in the global receiver.
|
||||
__ movp(receiver,
|
||||
FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset));
|
||||
}
|
||||
__ Push(receiver);
|
||||
ParameterCount actual(0);
|
||||
ParameterCount expected(getter);
|
||||
__ InvokeFunction(getter, expected, actual, CALL_FUNCTION,
|
||||
NullCallWrapper());
|
||||
} else {
|
||||
// If we generate a global code snippet for deoptimization only, remember
|
||||
// the place to continue after deoptimization.
|
||||
masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset());
|
||||
}
|
||||
|
||||
// Restore context register.
|
||||
__ movp(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
|
||||
}
|
||||
__ ret(0);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm())
|
||||
|
||||
|
||||
Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal(
|
||||
Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) {
|
||||
Label miss;
|
||||
FrontendHeader(receiver(), name, &miss);
|
||||
|
||||
// Get the value from the cell.
|
||||
Register result = StoreIC::ValueRegister();
|
||||
__ Move(result, cell);
|
||||
__ movp(result, FieldOperand(result, PropertyCell::kValueOffset));
|
||||
|
||||
// Check for deleted property if property can actually be deleted.
|
||||
if (is_configurable) {
|
||||
__ CompareRoot(result, Heap::kTheHoleValueRootIndex);
|
||||
__ j(equal, &miss);
|
||||
} else if (FLAG_debug_code) {
|
||||
__ CompareRoot(result, Heap::kTheHoleValueRootIndex);
|
||||
__ Check(not_equal, kDontDeleteCellsCannotContainTheHole);
|
||||
}
|
||||
|
||||
Counters* counters = isolate()->counters();
|
||||
__ IncrementCounter(counters->named_load_global_stub(), 1);
|
||||
__ ret(0);
|
||||
|
||||
FrontendFooter(name, &miss);
|
||||
|
||||
// Return the generated code.
|
||||
return GetCode(kind(), Code::NORMAL, name);
|
||||
}
|
||||
|
||||
|
||||
Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
|
||||
CodeHandleList* handlers,
|
||||
Handle<Name> name,
|
||||
@ -896,72 +124,6 @@ Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types,
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
#define __ ACCESS_MASM(masm)
|
||||
|
||||
|
||||
void ElementHandlerCompiler::GenerateLoadDictionaryElement(
|
||||
MacroAssembler* masm) {
|
||||
// ----------- S t a t e -------------
|
||||
// -- rcx : key
|
||||
// -- rdx : receiver
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
DCHECK(rdx.is(LoadIC::ReceiverRegister()));
|
||||
DCHECK(rcx.is(LoadIC::NameRegister()));
|
||||
Label slow, miss;
|
||||
|
||||
// This stub is meant to be tail-jumped to, the receiver must already
|
||||
// have been verified by the caller to not be a smi.
|
||||
|
||||
__ JumpIfNotSmi(rcx, &miss);
|
||||
__ SmiToInteger32(rbx, rcx);
|
||||
__ movp(rax, FieldOperand(rdx, JSObject::kElementsOffset));
|
||||
|
||||
// Check whether the elements is a number dictionary.
|
||||
// rdx: receiver
|
||||
// rcx: key
|
||||
// rbx: key as untagged int32
|
||||
// rax: elements
|
||||
__ LoadFromNumberDictionary(&slow, rax, rcx, rbx, r9, rdi, rax);
|
||||
__ ret(0);
|
||||
|
||||
__ bind(&slow);
|
||||
// ----------- S t a t e -------------
|
||||
// -- rcx : key
|
||||
// -- rdx : receiver
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow);
|
||||
|
||||
__ bind(&miss);
|
||||
// ----------- S t a t e -------------
|
||||
// -- rcx : key
|
||||
// -- rdx : receiver
|
||||
// -- rsp[0] : return address
|
||||
// -----------------------------------
|
||||
TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss);
|
||||
}
|
||||
|
||||
|
||||
void PropertyICCompiler::GenerateRuntimeSetProperty(MacroAssembler* masm,
|
||||
StrictMode strict_mode) {
|
||||
// Return address is on the stack.
|
||||
DCHECK(!rbx.is(StoreIC::ReceiverRegister()) &&
|
||||
!rbx.is(StoreIC::NameRegister()) && !rbx.is(StoreIC::ValueRegister()));
|
||||
|
||||
__ PopReturnAddressTo(rbx);
|
||||
__ Push(StoreIC::ReceiverRegister());
|
||||
__ Push(StoreIC::NameRegister());
|
||||
__ Push(StoreIC::ValueRegister());
|
||||
__ Push(Smi::FromInt(strict_mode));
|
||||
__ PushReturnAddressFrom(rbx);
|
||||
|
||||
// Do tail-call to runtime routine.
|
||||
__ TailCallRuntime(Runtime::kSetProperty, 4, 1);
|
||||
}
|
||||
|
||||
|
||||
#undef __
|
||||
}
|
||||
} // namespace v8::internal
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "src/bootstrapper.h"
|
||||
#include "src/code-stubs.h"
|
||||
#include "src/codegen.h"
|
||||
#include "src/ic/ic-compiler.h"
|
||||
#include "src/ic/handler-compiler.h"
|
||||
#include "src/isolate.h"
|
||||
#include "src/jsregexp.h"
|
||||
#include "src/regexp-macro-assembler.h"
|
||||
|
@ -603,6 +603,8 @@
|
||||
'../../src/ic/access-compiler.h',
|
||||
'../../src/ic/call-optimization.cc',
|
||||
'../../src/ic/call-optimization.h',
|
||||
'../../src/ic/handler-compiler.cc',
|
||||
'../../src/ic/handler-compiler.h',
|
||||
'../../src/ic/ic-inl.h',
|
||||
'../../src/ic/ic.cc',
|
||||
'../../src/ic/ic.h',
|
||||
@ -794,6 +796,7 @@
|
||||
'../../src/compiler/arm/instruction-selector-arm.cc',
|
||||
'../../src/compiler/arm/linkage-arm.cc',
|
||||
'../../src/ic/arm/access-compiler-arm.cc',
|
||||
'../../src/ic/arm/handler-compiler-arm.cc',
|
||||
'../../src/ic/arm/ic-arm.cc',
|
||||
'../../src/ic/arm/ic-compiler-arm.cc',
|
||||
'../../src/ic/arm/stub-cache-arm.cc',
|
||||
@ -848,6 +851,7 @@
|
||||
'../../src/compiler/arm64/instruction-selector-arm64.cc',
|
||||
'../../src/compiler/arm64/linkage-arm64.cc',
|
||||
'../../src/ic/arm64/access-compiler-arm64.cc',
|
||||
'../../src/ic/arm64/handler-compiler-arm64.cc',
|
||||
'../../src/ic/arm64/ic-arm64.cc',
|
||||
'../../src/ic/arm64/ic-compiler-arm64.cc',
|
||||
'../../src/ic/arm64/stub-cache-arm64.cc',
|
||||
@ -885,6 +889,7 @@
|
||||
'../../src/compiler/ia32/instruction-selector-ia32.cc',
|
||||
'../../src/compiler/ia32/linkage-ia32.cc',
|
||||
'../../src/ic/ia32/access-compiler-ia32.cc',
|
||||
'../../src/ic/ia32/handler-compiler-ia32.cc',
|
||||
'../../src/ic/ia32/ic-ia32.cc',
|
||||
'../../src/ic/ia32/ic-compiler-ia32.cc',
|
||||
'../../src/ic/ia32/stub-cache-ia32.cc',
|
||||
@ -1024,6 +1029,7 @@
|
||||
'../../src/compiler/x64/instruction-selector-x64.cc',
|
||||
'../../src/compiler/x64/linkage-x64.cc',
|
||||
'../../src/ic/x64/access-compiler-x64.cc',
|
||||
'../../src/ic/x64/handler-compiler-x64.cc',
|
||||
'../../src/ic/x64/ic-x64.cc',
|
||||
'../../src/ic/x64/ic-compiler-x64.cc',
|
||||
'../../src/ic/x64/stub-cache-x64.cc',
|
||||
|
Loading…
Reference in New Issue
Block a user