2013-07-05 10:34:02 +00:00
|
|
|
// Copyright 2013 the V8 project authors. All rights reserved.
|
2010-08-25 09:44:44 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#include "v8.h"
|
|
|
|
|
2013-06-28 15:34:48 +00:00
|
|
|
#if V8_TARGET_ARCH_X64
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
#include "bootstrapper.h"
|
2010-08-30 11:48:07 +00:00
|
|
|
#include "code-stubs.h"
|
2010-08-25 09:44:44 +00:00
|
|
|
#include "regexp-macro-assembler.h"
|
2013-01-21 14:53:29 +00:00
|
|
|
#include "stub-cache.h"
|
2013-02-04 12:01:59 +00:00
|
|
|
#include "runtime.h"
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
|
2013-08-27 11:55:08 +00:00
|
|
|
void FastNewClosureStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rbx };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-23 08:36:22 +00:00
|
|
|
void FastNewContextStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rdi };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-23 06:02:54 +00:00
|
|
|
void ToNumberStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rax };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-24 09:31:07 +00:00
|
|
|
void NumberToStringStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rax };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
2013-10-21 12:42:08 +00:00
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
Runtime::FunctionForId(Runtime::kNumberToString)->entry;
|
2013-09-24 09:31:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-04 17:55:43 +00:00
|
|
|
void FastCloneShallowArrayStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rax, rbx, rcx };
|
|
|
|
descriptor->register_param_count_ = 3;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
2013-11-25 12:41:27 +00:00
|
|
|
Runtime::FunctionForId(Runtime::kCreateArrayLiteralStubBailout)->entry;
|
2013-04-04 17:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-26 13:08:08 +00:00
|
|
|
void FastCloneShallowObjectStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rax, rbx, rcx, rdx };
|
|
|
|
descriptor->register_param_count_ = 4;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
2013-09-18 15:08:17 +00:00
|
|
|
Runtime::FunctionForId(Runtime::kCreateObjectLiteral)->entry;
|
2013-02-26 13:08:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-08 10:02:16 +00:00
|
|
|
void CreateAllocationSiteStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
2014-02-10 21:38:17 +00:00
|
|
|
static Register registers[] = { rbx, rdx };
|
|
|
|
descriptor->register_param_count_ = 2;
|
2013-07-08 10:02:16 +00:00
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
void KeyedLoadFastElementStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rdx, rax };
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
2013-01-30 14:25:34 +00:00
|
|
|
FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure);
|
2012-12-18 16:25:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-15 17:53:35 +00:00
|
|
|
void KeyedLoadDictionaryElementStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
2013-11-16 15:22:09 +00:00
|
|
|
static Register registers[] = { rdx, rax };
|
2013-11-15 17:53:35 +00:00
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-29 13:10:35 +00:00
|
|
|
void RegExpConstructResultStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rcx, rbx, rax };
|
|
|
|
descriptor->register_param_count_ = 3;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
Runtime::FunctionForId(Runtime::kRegExpConstructResult)->entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-02 16:32:47 +00:00
|
|
|
void LoadFieldStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rax };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KeyedLoadFieldStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rdx };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-20 10:37:13 +00:00
|
|
|
void KeyedStoreFastElementStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rdx, rcx, rax };
|
|
|
|
descriptor->register_param_count_ = 3;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-04 12:01:59 +00:00
|
|
|
void TransitionElementsKindStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rax, rbx };
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-25 16:00:32 +00:00
|
|
|
static void InitializeArrayConstructorDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor,
|
|
|
|
int constant_stack_parameter_count) {
|
2013-03-01 16:06:34 +00:00
|
|
|
// register state
|
2013-04-25 16:00:32 +00:00
|
|
|
// rax -- number of arguments
|
2013-05-07 21:01:53 +00:00
|
|
|
// rdi -- function
|
2014-01-21 16:04:39 +00:00
|
|
|
// rbx -- allocation site with elements kind
|
2013-11-13 10:07:04 +00:00
|
|
|
static Register registers_variable_args[] = { rdi, rbx, rax };
|
|
|
|
static Register registers_no_args[] = { rdi, rbx };
|
|
|
|
|
|
|
|
if (constant_stack_parameter_count == 0) {
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers_no_args;
|
|
|
|
} else {
|
2013-04-25 16:00:32 +00:00
|
|
|
// stack param count needs (constructor pointer, and single argument)
|
2013-11-13 10:07:04 +00:00
|
|
|
descriptor->handler_arguments_mode_ = PASS_ARGUMENTS;
|
2013-10-18 14:55:21 +00:00
|
|
|
descriptor->stack_parameter_count_ = rax;
|
2013-11-13 10:07:04 +00:00
|
|
|
descriptor->register_param_count_ = 3;
|
|
|
|
descriptor->register_params_ = registers_variable_args;
|
2013-04-25 16:00:32 +00:00
|
|
|
}
|
2013-11-13 10:07:04 +00:00
|
|
|
|
2013-04-25 16:00:32 +00:00
|
|
|
descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count;
|
2013-04-02 11:28:01 +00:00
|
|
|
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
|
2013-03-01 16:06:34 +00:00
|
|
|
descriptor->deoptimization_handler_ =
|
2013-06-06 13:22:42 +00:00
|
|
|
Runtime::FunctionForId(Runtime::kArrayConstructor)->entry;
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
static void InitializeInternalArrayConstructorDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor,
|
|
|
|
int constant_stack_parameter_count) {
|
|
|
|
// register state
|
|
|
|
// rax -- number of arguments
|
|
|
|
// rdi -- constructor function
|
2013-11-13 10:07:04 +00:00
|
|
|
static Register registers_variable_args[] = { rdi, rax };
|
|
|
|
static Register registers_no_args[] = { rdi };
|
2013-06-05 10:43:18 +00:00
|
|
|
|
2013-11-13 10:07:04 +00:00
|
|
|
if (constant_stack_parameter_count == 0) {
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers_no_args;
|
|
|
|
} else {
|
2013-06-05 10:43:18 +00:00
|
|
|
// stack param count needs (constructor pointer, and single argument)
|
2013-11-13 10:07:04 +00:00
|
|
|
descriptor->handler_arguments_mode_ = PASS_ARGUMENTS;
|
2013-10-18 14:55:21 +00:00
|
|
|
descriptor->stack_parameter_count_ = rax;
|
2013-11-13 10:07:04 +00:00
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers_variable_args;
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
2013-11-13 10:07:04 +00:00
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count;
|
|
|
|
descriptor->function_mode_ = JS_FUNCTION_STUB_MODE;
|
|
|
|
descriptor->deoptimization_handler_ =
|
2013-06-06 13:22:42 +00:00
|
|
|
Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry;
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-01 16:06:34 +00:00
|
|
|
void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
2013-04-25 16:00:32 +00:00
|
|
|
InitializeArrayConstructorDescriptor(isolate, descriptor, 0);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
2013-04-25 16:00:32 +00:00
|
|
|
InitializeArrayConstructorDescriptor(isolate, descriptor, 1);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
2013-04-25 16:00:32 +00:00
|
|
|
InitializeArrayConstructorDescriptor(isolate, descriptor, -1);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
void InternalArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InternalArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
InitializeInternalArrayConstructorDescriptor(isolate, descriptor, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-24 11:32:17 +00:00
|
|
|
void CompareNilICStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rax };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(CompareNilIC_Miss);
|
2013-05-24 11:44:55 +00:00
|
|
|
descriptor->SetMissHandler(
|
|
|
|
ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate));
|
2013-04-24 11:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-29 14:49:28 +00:00
|
|
|
void ToBooleanStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rax };
|
|
|
|
descriptor->register_param_count_ = 1;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(ToBooleanIC_Miss);
|
|
|
|
descriptor->SetMissHandler(
|
2013-07-05 09:26:22 +00:00
|
|
|
ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-05 10:34:02 +00:00
|
|
|
void StoreGlobalStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rdx, rcx, rax };
|
|
|
|
descriptor->register_param_count_ = 3;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(StoreIC_MissFromStubFailure);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-17 11:37:20 +00:00
|
|
|
void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rax, rbx, rcx, rdx };
|
|
|
|
descriptor->register_param_count_ = 4;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-02 15:31:27 +00:00
|
|
|
void BinaryOpICStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rdx, rax };
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ = FUNCTION_ADDR(BinaryOpIC_Miss);
|
|
|
|
descriptor->SetMissHandler(
|
|
|
|
ExternalReference(IC_Utility(IC::kBinaryOpIC_Miss), isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void BinaryOpWithAllocationSiteStub::InitializeInterfaceDescriptor(
|
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rcx, rdx, rax };
|
|
|
|
descriptor->register_param_count_ = 3;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
FUNCTION_ADDR(BinaryOpIC_MissWithAllocationSite);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-22 13:48:05 +00:00
|
|
|
void StringAddStub::InitializeInterfaceDescriptor(
|
2013-11-12 10:21:08 +00:00
|
|
|
Isolate* isolate,
|
|
|
|
CodeStubInterfaceDescriptor* descriptor) {
|
|
|
|
static Register registers[] = { rdx, rax };
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->deoptimization_handler_ =
|
|
|
|
Runtime::FunctionForId(Runtime::kStringAdd)->entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
This is a preview of a first step towards unification of the hydrogen
call machinery. The change replaces CallNamed, CallKeyed,
CallConstantFunction and CallKnownGlobal hydrogen instructions with two
new instructions with a more lower level semantics:
1. CallJSFunction for direct calls of JSFunction objects (no
argument adaptation)
2. CallWithDescriptor for calls of a given Code object according to
the supplied calling convention.
Details:
CallJSFunction should be straightforward, the main difference from the
existing InvokeFunction instruction is the absence of argument adaptor
handling. (As a next step, we will replace InvokeFunction with an
equivalent hydrogen code.)
For CallWithDescriptor, the calling conventions are represented by a
tweaked version of CallStubInterfaceDescriptor. In addition to the
parameter-register mapping, we also define parameter-representation
mapping there. The CallWithDescriptor instruction has variable number of
parameters now - this required some simple tweaks in Lithium, which
assumed fixed number of arguments in some places.
The calling conventions used in the calls are initialized in the
CallDescriptors class (code-stubs.h, <arch>/code-stubs-<arch>.cc), and
they live in a new table in the Isolate class. I should say I am not
quite sure about Representation::Integer32() representation for some of
the params of ArgumentAdaptorCall - it is not clear to me wether the
params could not end up on the stack and thus confuse the GC.
The change also includes an earlier small change to argument adaptor
(https://codereview.chromium.org/98463007) that avoids passing a naked
pointer to the code entry as a parameter. I am sorry for packaging that
with an already biggish change.
Performance implications:
Locally, I see a small regression (.2% or so). It is hard to say where
exactly it comes from, but I do see inefficient call sequences to the
adaptor trampoline. For example:
;;; <@78,#24> constant-t
bf85aa515a mov edi,0x5a51aa85 ;; debug: position 29
;;; <@72,#53> load-named-field
8b7717 mov esi,[edi+0x17] ;; debug: position 195
;;; <@80,#51> constant-s
b902000000 mov ecx,0x2 ;; debug: position 195
;;; <@81,#51> gap
894df0 mov [ebp+0xf0],ecx
;;; <@82,#103> constant-i
bb01000000 mov ebx,0x1
;;; <@84,#102> constant-i
b902000000 mov ecx,0x2
;;; <@85,#102> gap
89d8 mov eax,ebx
89cb mov ebx,ecx
8b4df0 mov ecx,[ebp+0xf0]
;;; <@86,#58> call-with-descriptor
e8ef57fcff call ArgumentsAdaptorTrampoline (0x2d80e6e0) ;; code: BUILTIN
Note the silly handling of ecx; the hydrogen for this code is:
0 4 s27 Constant 1 range:1_1 <|@
0 3 t30 Constant 0x5bc1aa85 <JS Function xyz (SharedFunctionInfo 0x5bc1a919)> type:object <|@
0 1 t36 LoadNamedField t30.[in-object]@24 <|@
0 1 t38 Constant 0x2300e6a1 <Code> <|@
0 1 i102 Constant 2 range:2_2 <|@
0 1 i103 Constant 1 range:1_1 <|@
0 2 t41 CallWithDescriptor t38 t30 t36 s27 i103 i102 #2 changes[*] <|@
BUG=
R=verwaest@chromium.org, danno@chromium.org
Review URL: https://codereview.chromium.org/104663004
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-15 17:00:35 +00:00
|
|
|
void CallDescriptors::InitializeForIsolate(Isolate* isolate) {
|
|
|
|
{
|
|
|
|
CallInterfaceDescriptor* descriptor =
|
|
|
|
isolate->call_descriptor(Isolate::ArgumentAdaptorCall);
|
|
|
|
static Register registers[] = { rdi, // JSFunction
|
|
|
|
rsi, // context
|
|
|
|
rax, // actual number of arguments
|
|
|
|
rbx, // expected number of arguments
|
|
|
|
};
|
|
|
|
static Representation representations[] = {
|
|
|
|
Representation::Tagged(), // JSFunction
|
|
|
|
Representation::Tagged(), // context
|
|
|
|
Representation::Integer32(), // actual number of arguments
|
|
|
|
Representation::Integer32(), // expected number of arguments
|
|
|
|
};
|
|
|
|
descriptor->register_param_count_ = 4;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->param_representations_ = representations;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
CallInterfaceDescriptor* descriptor =
|
|
|
|
isolate->call_descriptor(Isolate::KeyedCall);
|
|
|
|
static Register registers[] = { rsi, // context
|
|
|
|
rcx, // key
|
|
|
|
};
|
|
|
|
static Representation representations[] = {
|
|
|
|
Representation::Tagged(), // context
|
|
|
|
Representation::Tagged(), // key
|
|
|
|
};
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->param_representations_ = representations;
|
|
|
|
}
|
|
|
|
{
|
|
|
|
CallInterfaceDescriptor* descriptor =
|
|
|
|
isolate->call_descriptor(Isolate::NamedCall);
|
|
|
|
static Register registers[] = { rsi, // context
|
|
|
|
rcx, // name
|
|
|
|
};
|
|
|
|
static Representation representations[] = {
|
|
|
|
Representation::Tagged(), // context
|
|
|
|
Representation::Tagged(), // name
|
|
|
|
};
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->param_representations_ = representations;
|
|
|
|
}
|
2014-01-24 11:47:53 +00:00
|
|
|
{
|
|
|
|
CallInterfaceDescriptor* descriptor =
|
|
|
|
isolate->call_descriptor(Isolate::CallHandler);
|
|
|
|
static Register registers[] = { rsi, // context
|
|
|
|
rdx, // receiver
|
|
|
|
};
|
|
|
|
static Representation representations[] = {
|
|
|
|
Representation::Tagged(), // context
|
|
|
|
Representation::Tagged(), // receiver
|
|
|
|
};
|
|
|
|
descriptor->register_param_count_ = 2;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->param_representations_ = representations;
|
|
|
|
}
|
2014-01-30 13:18:41 +00:00
|
|
|
{
|
|
|
|
CallInterfaceDescriptor* descriptor =
|
|
|
|
isolate->call_descriptor(Isolate::ApiFunctionCall);
|
|
|
|
static Register registers[] = { rax, // callee
|
|
|
|
rbx, // call_data
|
|
|
|
rcx, // holder
|
|
|
|
rdx, // api_function_address
|
|
|
|
rsi, // context
|
|
|
|
};
|
|
|
|
static Representation representations[] = {
|
|
|
|
Representation::Tagged(), // callee
|
|
|
|
Representation::Tagged(), // call_data
|
|
|
|
Representation::Tagged(), // holder
|
|
|
|
Representation::External(), // api_function_address
|
|
|
|
Representation::Tagged(), // context
|
|
|
|
};
|
|
|
|
descriptor->register_param_count_ = 5;
|
|
|
|
descriptor->register_params_ = registers;
|
|
|
|
descriptor->param_representations_ = representations;
|
|
|
|
}
|
This is a preview of a first step towards unification of the hydrogen
call machinery. The change replaces CallNamed, CallKeyed,
CallConstantFunction and CallKnownGlobal hydrogen instructions with two
new instructions with a more lower level semantics:
1. CallJSFunction for direct calls of JSFunction objects (no
argument adaptation)
2. CallWithDescriptor for calls of a given Code object according to
the supplied calling convention.
Details:
CallJSFunction should be straightforward, the main difference from the
existing InvokeFunction instruction is the absence of argument adaptor
handling. (As a next step, we will replace InvokeFunction with an
equivalent hydrogen code.)
For CallWithDescriptor, the calling conventions are represented by a
tweaked version of CallStubInterfaceDescriptor. In addition to the
parameter-register mapping, we also define parameter-representation
mapping there. The CallWithDescriptor instruction has variable number of
parameters now - this required some simple tweaks in Lithium, which
assumed fixed number of arguments in some places.
The calling conventions used in the calls are initialized in the
CallDescriptors class (code-stubs.h, <arch>/code-stubs-<arch>.cc), and
they live in a new table in the Isolate class. I should say I am not
quite sure about Representation::Integer32() representation for some of
the params of ArgumentAdaptorCall - it is not clear to me wether the
params could not end up on the stack and thus confuse the GC.
The change also includes an earlier small change to argument adaptor
(https://codereview.chromium.org/98463007) that avoids passing a naked
pointer to the code entry as a parameter. I am sorry for packaging that
with an already biggish change.
Performance implications:
Locally, I see a small regression (.2% or so). It is hard to say where
exactly it comes from, but I do see inefficient call sequences to the
adaptor trampoline. For example:
;;; <@78,#24> constant-t
bf85aa515a mov edi,0x5a51aa85 ;; debug: position 29
;;; <@72,#53> load-named-field
8b7717 mov esi,[edi+0x17] ;; debug: position 195
;;; <@80,#51> constant-s
b902000000 mov ecx,0x2 ;; debug: position 195
;;; <@81,#51> gap
894df0 mov [ebp+0xf0],ecx
;;; <@82,#103> constant-i
bb01000000 mov ebx,0x1
;;; <@84,#102> constant-i
b902000000 mov ecx,0x2
;;; <@85,#102> gap
89d8 mov eax,ebx
89cb mov ebx,ecx
8b4df0 mov ecx,[ebp+0xf0]
;;; <@86,#58> call-with-descriptor
e8ef57fcff call ArgumentsAdaptorTrampoline (0x2d80e6e0) ;; code: BUILTIN
Note the silly handling of ecx; the hydrogen for this code is:
0 4 s27 Constant 1 range:1_1 <|@
0 3 t30 Constant 0x5bc1aa85 <JS Function xyz (SharedFunctionInfo 0x5bc1a919)> type:object <|@
0 1 t36 LoadNamedField t30.[in-object]@24 <|@
0 1 t38 Constant 0x2300e6a1 <Code> <|@
0 1 i102 Constant 2 range:2_2 <|@
0 1 i103 Constant 1 range:1_1 <|@
0 2 t41 CallWithDescriptor t38 t30 t36 s27 i103 i102 #2 changes[*] <|@
BUG=
R=verwaest@chromium.org, danno@chromium.org
Review URL: https://codereview.chromium.org/104663004
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-01-15 17:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
#define __ ACCESS_MASM(masm)
|
2011-01-28 14:18:26 +00:00
|
|
|
|
2013-04-18 20:37:27 +00:00
|
|
|
|
|
|
|
void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) {
|
|
|
|
// Update the static counter each time a new code stub is generated.
|
|
|
|
Isolate* isolate = masm->isolate();
|
|
|
|
isolate->counters()->code_stubs()->Increment();
|
|
|
|
|
|
|
|
CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate);
|
|
|
|
int param_count = descriptor->register_param_count_;
|
|
|
|
{
|
|
|
|
// Call the runtime system in a fresh internal frame.
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
ASSERT(descriptor->register_param_count_ == 0 ||
|
|
|
|
rax.is(descriptor->register_params_[param_count - 1]));
|
|
|
|
// Push arguments
|
|
|
|
for (int i = 0; i < param_count; ++i) {
|
|
|
|
__ push(descriptor->register_params_[i]);
|
|
|
|
}
|
2013-05-24 11:44:55 +00:00
|
|
|
ExternalReference miss = descriptor->miss_handler();
|
2013-04-18 20:37:27 +00:00
|
|
|
__ CallExternalReference(miss, descriptor->register_param_count_);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
void StoreBufferOverflowStub::Generate(MacroAssembler* masm) {
|
|
|
|
__ PushCallerSaved(save_doubles_);
|
|
|
|
const int argument_count = 1;
|
|
|
|
__ PrepareCallCFunction(argument_count);
|
2013-04-24 12:01:08 +00:00
|
|
|
__ LoadAddress(arg_reg_1,
|
|
|
|
ExternalReference::isolate_address(masm->isolate()));
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::store_buffer_overflow_function(masm->isolate()),
|
|
|
|
argument_count);
|
|
|
|
__ PopCallerSaved(save_doubles_);
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
class FloatingPointHelper : public AllStatic {
|
|
|
|
public:
|
2012-11-14 15:59:45 +00:00
|
|
|
enum ConvertUndefined {
|
|
|
|
CONVERT_UNDEFINED_TO_ZERO,
|
|
|
|
BAILOUT_ON_UNDEFINED
|
|
|
|
};
|
2010-08-25 09:44:44 +00:00
|
|
|
// Load the operands from rdx and rax into xmm0 and xmm1, as doubles.
|
|
|
|
// If the operands are not both numbers, jump to not_numbers.
|
|
|
|
// Leaves rdx and rax unchanged. SmiOperands assumes both are smis.
|
|
|
|
// NumberOperands assumes both are smis or heap numbers.
|
|
|
|
static void LoadSSE2UnknownOperands(MacroAssembler* masm,
|
|
|
|
Label* not_numbers);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-07-19 08:21:41 +00:00
|
|
|
void DoubleToIStub::Generate(MacroAssembler* masm) {
|
|
|
|
Register input_reg = this->source();
|
|
|
|
Register final_result_reg = this->destination();
|
|
|
|
ASSERT(is_truncating());
|
2011-04-28 17:49:55 +00:00
|
|
|
|
2013-07-19 08:21:41 +00:00
|
|
|
Label check_negative, process_64_bits, done;
|
2011-04-28 17:49:55 +00:00
|
|
|
|
2013-07-19 08:21:41 +00:00
|
|
|
int double_offset = offset();
|
|
|
|
|
|
|
|
// Account for return address and saved regs if input is rsp.
|
|
|
|
if (input_reg.is(rsp)) double_offset += 3 * kPointerSize;
|
|
|
|
|
|
|
|
MemOperand mantissa_operand(MemOperand(input_reg, double_offset));
|
|
|
|
MemOperand exponent_operand(MemOperand(input_reg,
|
|
|
|
double_offset + kDoubleSize / 2));
|
|
|
|
|
|
|
|
Register scratch1;
|
|
|
|
Register scratch_candidates[3] = { rbx, rdx, rdi };
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
scratch1 = scratch_candidates[i];
|
|
|
|
if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since we must use rcx for shifts below, use some other register (rax)
|
|
|
|
// to calculate the result if ecx is the requested return register.
|
|
|
|
Register result_reg = final_result_reg.is(rcx) ? rax : final_result_reg;
|
|
|
|
// Save ecx if it isn't the return register and therefore volatile, or if it
|
|
|
|
// is the return register, then save the temp register we use in its stead
|
|
|
|
// for the result.
|
|
|
|
Register save_reg = final_result_reg.is(rcx) ? rax : rcx;
|
|
|
|
__ push(scratch1);
|
|
|
|
__ push(save_reg);
|
|
|
|
|
|
|
|
bool stash_exponent_copy = !input_reg.is(rsp);
|
|
|
|
__ movl(scratch1, mantissa_operand);
|
|
|
|
__ movsd(xmm0, mantissa_operand);
|
|
|
|
__ movl(rcx, exponent_operand);
|
|
|
|
if (stash_exponent_copy) __ push(rcx);
|
|
|
|
|
|
|
|
__ andl(rcx, Immediate(HeapNumber::kExponentMask));
|
|
|
|
__ shrl(rcx, Immediate(HeapNumber::kExponentShift));
|
|
|
|
__ leal(result_reg, MemOperand(rcx, -HeapNumber::kExponentBias));
|
|
|
|
__ cmpl(result_reg, Immediate(HeapNumber::kMantissaBits));
|
|
|
|
__ j(below, &process_64_bits);
|
|
|
|
|
|
|
|
// Result is entirely in lower 32-bits of mantissa
|
|
|
|
int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize;
|
|
|
|
__ subl(rcx, Immediate(delta));
|
|
|
|
__ xorl(result_reg, result_reg);
|
|
|
|
__ cmpl(rcx, Immediate(31));
|
|
|
|
__ j(above, &done);
|
|
|
|
__ shll_cl(scratch1);
|
|
|
|
__ jmp(&check_negative);
|
|
|
|
|
|
|
|
__ bind(&process_64_bits);
|
|
|
|
__ cvttsd2siq(result_reg, xmm0);
|
|
|
|
__ jmp(&done, Label::kNear);
|
|
|
|
|
|
|
|
// If the double was negative, negate the integer result.
|
|
|
|
__ bind(&check_negative);
|
|
|
|
__ movl(result_reg, scratch1);
|
|
|
|
__ negl(result_reg);
|
|
|
|
if (stash_exponent_copy) {
|
|
|
|
__ cmpl(MemOperand(rsp, 0), Immediate(0));
|
|
|
|
} else {
|
|
|
|
__ cmpl(exponent_operand, Immediate(0));
|
|
|
|
}
|
|
|
|
__ cmovl(greater, result_reg, scratch1);
|
|
|
|
|
|
|
|
// Restore registers
|
|
|
|
__ bind(&done);
|
|
|
|
if (stash_exponent_copy) {
|
|
|
|
__ addq(rsp, Immediate(kDoubleSize));
|
|
|
|
}
|
|
|
|
if (!final_result_reg.is(result_reg)) {
|
|
|
|
ASSERT(final_result_reg.is(rcx));
|
|
|
|
__ movl(final_result_reg, result_reg);
|
|
|
|
}
|
|
|
|
__ pop(save_reg);
|
|
|
|
__ pop(scratch1);
|
|
|
|
__ ret(0);
|
2011-04-28 17:49:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void FloatingPointHelper::LoadSSE2UnknownOperands(MacroAssembler* masm,
|
|
|
|
Label* not_numbers) {
|
|
|
|
Label load_smi_rdx, load_nonsmi_rax, load_smi_rax, load_float_rax, done;
|
|
|
|
// Load operand in rdx into xmm0, or branch to not_numbers.
|
|
|
|
__ LoadRoot(rcx, Heap::kHeapNumberMapRootIndex);
|
|
|
|
__ JumpIfSmi(rdx, &load_smi_rdx);
|
|
|
|
__ cmpq(FieldOperand(rdx, HeapObject::kMapOffset), rcx);
|
|
|
|
__ j(not_equal, not_numbers); // Argument in rdx is not a number.
|
|
|
|
__ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset));
|
|
|
|
// Load operand in rax into xmm1, or branch to not_numbers.
|
|
|
|
__ JumpIfSmi(rax, &load_smi_rax);
|
|
|
|
|
|
|
|
__ bind(&load_nonsmi_rax);
|
|
|
|
__ cmpq(FieldOperand(rax, HeapObject::kMapOffset), rcx);
|
|
|
|
__ j(not_equal, not_numbers);
|
|
|
|
__ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset));
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
__ bind(&load_smi_rdx);
|
|
|
|
__ SmiToInteger32(kScratchRegister, rdx);
|
2013-09-13 07:59:48 +00:00
|
|
|
__ Cvtlsi2sd(xmm0, kScratchRegister);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ JumpIfNotSmi(rax, &load_nonsmi_rax);
|
|
|
|
|
|
|
|
__ bind(&load_smi_rax);
|
|
|
|
__ SmiToInteger32(kScratchRegister, rax);
|
2013-09-13 07:59:48 +00:00
|
|
|
__ Cvtlsi2sd(xmm1, kScratchRegister);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-28 14:57:14 +00:00
|
|
|
void MathPowStub::Generate(MacroAssembler* masm) {
|
2011-12-07 08:34:27 +00:00
|
|
|
const Register exponent = rdx;
|
|
|
|
const Register base = rax;
|
|
|
|
const Register scratch = rcx;
|
|
|
|
const XMMRegister double_result = xmm3;
|
|
|
|
const XMMRegister double_base = xmm2;
|
|
|
|
const XMMRegister double_exponent = xmm1;
|
|
|
|
const XMMRegister double_scratch = xmm4;
|
|
|
|
|
2011-12-07 16:15:18 +00:00
|
|
|
Label call_runtime, done, exponent_not_smi, int_exponent;
|
2011-12-07 08:34:27 +00:00
|
|
|
|
|
|
|
// Save 1 in double_result - we need this several times later on.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, Immediate(1));
|
2013-09-13 07:59:48 +00:00
|
|
|
__ Cvtlsi2sd(double_result, scratch);
|
2011-12-07 08:34:27 +00:00
|
|
|
|
|
|
|
if (exponent_type_ == ON_STACK) {
|
|
|
|
Label base_is_smi, unpack_exponent;
|
|
|
|
// The exponent and base are supplied as arguments on the stack.
|
|
|
|
// This can only happen if the stub is called from non-optimized code.
|
|
|
|
// Load input parameters from stack.
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(base, args.GetArgumentOperand(0));
|
|
|
|
__ movp(exponent, args.GetArgumentOperand(1));
|
2011-12-07 08:34:27 +00:00
|
|
|
__ JumpIfSmi(base, &base_is_smi, Label::kNear);
|
|
|
|
__ CompareRoot(FieldOperand(base, HeapObject::kMapOffset),
|
|
|
|
Heap::kHeapNumberMapRootIndex);
|
2011-12-07 16:15:18 +00:00
|
|
|
__ j(not_equal, &call_runtime);
|
2011-12-07 08:34:27 +00:00
|
|
|
|
|
|
|
__ movsd(double_base, FieldOperand(base, HeapNumber::kValueOffset));
|
|
|
|
__ jmp(&unpack_exponent, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(&base_is_smi);
|
|
|
|
__ SmiToInteger32(base, base);
|
2013-09-13 07:59:48 +00:00
|
|
|
__ Cvtlsi2sd(double_base, base);
|
2011-12-07 08:34:27 +00:00
|
|
|
__ bind(&unpack_exponent);
|
|
|
|
|
|
|
|
__ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear);
|
|
|
|
__ SmiToInteger32(exponent, exponent);
|
|
|
|
__ jmp(&int_exponent);
|
|
|
|
|
|
|
|
__ bind(&exponent_not_smi);
|
|
|
|
__ CompareRoot(FieldOperand(exponent, HeapObject::kMapOffset),
|
|
|
|
Heap::kHeapNumberMapRootIndex);
|
2011-12-07 16:15:18 +00:00
|
|
|
__ j(not_equal, &call_runtime);
|
2011-12-07 08:34:27 +00:00
|
|
|
__ movsd(double_exponent, FieldOperand(exponent, HeapNumber::kValueOffset));
|
|
|
|
} else if (exponent_type_ == TAGGED) {
|
|
|
|
__ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear);
|
|
|
|
__ SmiToInteger32(exponent, exponent);
|
|
|
|
__ jmp(&int_exponent);
|
|
|
|
|
|
|
|
__ bind(&exponent_not_smi);
|
|
|
|
__ movsd(double_exponent, FieldOperand(exponent, HeapNumber::kValueOffset));
|
|
|
|
}
|
2011-02-28 14:57:14 +00:00
|
|
|
|
2011-12-07 08:34:27 +00:00
|
|
|
if (exponent_type_ != INTEGER) {
|
2013-09-10 12:37:30 +00:00
|
|
|
Label fast_power, try_arithmetic_simplification;
|
2011-12-07 08:34:27 +00:00
|
|
|
// Detect integer exponents stored as double.
|
2013-09-10 12:37:30 +00:00
|
|
|
__ DoubleToI(exponent, double_exponent, double_scratch,
|
|
|
|
TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification);
|
|
|
|
__ jmp(&int_exponent);
|
|
|
|
|
|
|
|
__ bind(&try_arithmetic_simplification);
|
2011-12-07 08:34:27 +00:00
|
|
|
__ cvttsd2si(exponent, double_exponent);
|
|
|
|
// Skip to runtime if possibly NaN (indicated by the indefinite integer).
|
|
|
|
__ cmpl(exponent, Immediate(0x80000000u));
|
2011-12-07 16:15:18 +00:00
|
|
|
__ j(equal, &call_runtime);
|
2011-12-07 08:34:27 +00:00
|
|
|
|
|
|
|
if (exponent_type_ == ON_STACK) {
|
|
|
|
// Detect square root case. Crankshaft detects constant +/-0.5 at
|
|
|
|
// compile time and uses DoMathPowHalf instead. We then skip this check
|
|
|
|
// for non-constant cases of +/-0.5 as these hardly occur.
|
|
|
|
Label continue_sqrt, continue_rsqrt, not_plus_half;
|
|
|
|
// Test for 0.5.
|
|
|
|
// Load double_scratch with 0.5.
|
2013-11-07 08:14:27 +00:00
|
|
|
__ movq(scratch, V8_UINT64_C(0x3FE0000000000000));
|
2011-12-07 08:34:27 +00:00
|
|
|
__ movq(double_scratch, scratch);
|
|
|
|
// Already ruled out NaNs for exponent.
|
|
|
|
__ ucomisd(double_scratch, double_exponent);
|
|
|
|
__ j(not_equal, ¬_plus_half, Label::kNear);
|
|
|
|
|
|
|
|
// Calculates square root of base. Check for the special case of
|
|
|
|
// Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13).
|
|
|
|
// According to IEEE-754, double-precision -Infinity has the highest
|
|
|
|
// 12 bits set and the lowest 52 bits cleared.
|
2013-11-07 08:14:27 +00:00
|
|
|
__ movq(scratch, V8_UINT64_C(0xFFF0000000000000));
|
2011-12-07 08:34:27 +00:00
|
|
|
__ movq(double_scratch, scratch);
|
|
|
|
__ ucomisd(double_scratch, double_base);
|
|
|
|
// Comparing -Infinity with NaN results in "unordered", which sets the
|
|
|
|
// zero flag as if both were equal. However, it also sets the carry flag.
|
|
|
|
__ j(not_equal, &continue_sqrt, Label::kNear);
|
|
|
|
__ j(carry, &continue_sqrt, Label::kNear);
|
|
|
|
|
|
|
|
// Set result to Infinity in the special case.
|
|
|
|
__ xorps(double_result, double_result);
|
|
|
|
__ subsd(double_result, double_scratch);
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
__ bind(&continue_sqrt);
|
|
|
|
// sqrtsd returns -0 when input is -0. ECMA spec requires +0.
|
|
|
|
__ xorps(double_scratch, double_scratch);
|
|
|
|
__ addsd(double_scratch, double_base); // Convert -0 to 0.
|
|
|
|
__ sqrtsd(double_result, double_scratch);
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
// Test for -0.5.
|
|
|
|
__ bind(¬_plus_half);
|
|
|
|
// Load double_scratch with -0.5 by substracting 1.
|
|
|
|
__ subsd(double_scratch, double_result);
|
|
|
|
// Already ruled out NaNs for exponent.
|
|
|
|
__ ucomisd(double_scratch, double_exponent);
|
|
|
|
__ j(not_equal, &fast_power, Label::kNear);
|
|
|
|
|
|
|
|
// Calculates reciprocal of square root of base. Check for the special
|
|
|
|
// case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13).
|
|
|
|
// According to IEEE-754, double-precision -Infinity has the highest
|
|
|
|
// 12 bits set and the lowest 52 bits cleared.
|
2013-11-07 08:14:27 +00:00
|
|
|
__ movq(scratch, V8_UINT64_C(0xFFF0000000000000));
|
2011-12-07 08:34:27 +00:00
|
|
|
__ movq(double_scratch, scratch);
|
|
|
|
__ ucomisd(double_scratch, double_base);
|
|
|
|
// Comparing -Infinity with NaN results in "unordered", which sets the
|
|
|
|
// zero flag as if both were equal. However, it also sets the carry flag.
|
|
|
|
__ j(not_equal, &continue_rsqrt, Label::kNear);
|
|
|
|
__ j(carry, &continue_rsqrt, Label::kNear);
|
|
|
|
|
|
|
|
// Set result to 0 in the special case.
|
|
|
|
__ xorps(double_result, double_result);
|
|
|
|
__ jmp(&done);
|
|
|
|
|
|
|
|
__ bind(&continue_rsqrt);
|
|
|
|
// sqrtsd returns -0 when input is -0. ECMA spec requires +0.
|
|
|
|
__ xorps(double_exponent, double_exponent);
|
|
|
|
__ addsd(double_exponent, double_base); // Convert -0 to +0.
|
|
|
|
__ sqrtsd(double_exponent, double_exponent);
|
|
|
|
__ divsd(double_result, double_exponent);
|
|
|
|
__ jmp(&done);
|
|
|
|
}
|
2011-02-28 14:57:14 +00:00
|
|
|
|
2011-12-07 08:34:27 +00:00
|
|
|
// Using FPU instructions to calculate power.
|
|
|
|
Label fast_power_failed;
|
|
|
|
__ bind(&fast_power);
|
|
|
|
__ fnclex(); // Clear flags to catch exceptions later.
|
|
|
|
// Transfer (B)ase and (E)xponent onto the FPU register stack.
|
|
|
|
__ subq(rsp, Immediate(kDoubleSize));
|
|
|
|
__ movsd(Operand(rsp, 0), double_exponent);
|
|
|
|
__ fld_d(Operand(rsp, 0)); // E
|
|
|
|
__ movsd(Operand(rsp, 0), double_base);
|
|
|
|
__ fld_d(Operand(rsp, 0)); // B, E
|
|
|
|
|
|
|
|
// Exponent is in st(1) and base is in st(0)
|
|
|
|
// B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B)
|
|
|
|
// FYL2X calculates st(1) * log2(st(0))
|
|
|
|
__ fyl2x(); // X
|
|
|
|
__ fld(0); // X, X
|
|
|
|
__ frndint(); // rnd(X), X
|
|
|
|
__ fsub(1); // rnd(X), X-rnd(X)
|
|
|
|
__ fxch(1); // X - rnd(X), rnd(X)
|
|
|
|
// F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1
|
|
|
|
__ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X)
|
|
|
|
__ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X)
|
2012-11-26 13:12:35 +00:00
|
|
|
__ faddp(1); // 2^(X-rnd(X)), rnd(X)
|
2011-12-07 08:34:27 +00:00
|
|
|
// FSCALE calculates st(0) * 2^st(1)
|
|
|
|
__ fscale(); // 2^X, rnd(X)
|
|
|
|
__ fstp(1);
|
|
|
|
// Bail out to runtime in case of exceptions in the status word.
|
|
|
|
__ fnstsw_ax();
|
|
|
|
__ testb(rax, Immediate(0x5F)); // Check for all but precision exception.
|
|
|
|
__ j(not_zero, &fast_power_failed, Label::kNear);
|
|
|
|
__ fstp_d(Operand(rsp, 0));
|
|
|
|
__ movsd(double_result, Operand(rsp, 0));
|
|
|
|
__ addq(rsp, Immediate(kDoubleSize));
|
|
|
|
__ jmp(&done);
|
2011-02-28 14:57:14 +00:00
|
|
|
|
2011-12-07 08:34:27 +00:00
|
|
|
__ bind(&fast_power_failed);
|
|
|
|
__ fninit();
|
|
|
|
__ addq(rsp, Immediate(kDoubleSize));
|
2011-12-07 16:15:18 +00:00
|
|
|
__ jmp(&call_runtime);
|
2011-12-07 08:34:27 +00:00
|
|
|
}
|
2011-02-28 14:57:14 +00:00
|
|
|
|
2011-12-07 08:34:27 +00:00
|
|
|
// Calculate power with integer exponent.
|
|
|
|
__ bind(&int_exponent);
|
|
|
|
const XMMRegister double_scratch2 = double_exponent;
|
|
|
|
// Back up exponent as we need to check if exponent is negative later.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, exponent); // Back up exponent.
|
2011-12-07 08:34:27 +00:00
|
|
|
__ movsd(double_scratch, double_base); // Back up base.
|
|
|
|
__ movsd(double_scratch2, double_result); // Load double_exponent with 1.
|
2011-02-28 14:57:14 +00:00
|
|
|
|
|
|
|
// Get absolute value of exponent.
|
2012-09-18 08:04:31 +00:00
|
|
|
Label no_neg, while_true, while_false;
|
2011-12-07 16:15:18 +00:00
|
|
|
__ testl(scratch, scratch);
|
|
|
|
__ j(positive, &no_neg, Label::kNear);
|
|
|
|
__ negl(scratch);
|
|
|
|
__ bind(&no_neg);
|
2011-02-28 14:57:14 +00:00
|
|
|
|
2012-09-18 08:04:31 +00:00
|
|
|
__ j(zero, &while_false, Label::kNear);
|
2011-12-07 08:34:27 +00:00
|
|
|
__ shrl(scratch, Immediate(1));
|
2012-09-18 08:04:31 +00:00
|
|
|
// Above condition means CF==0 && ZF==0. This means that the
|
|
|
|
// bit that has been shifted out is 0 and the result is not 0.
|
|
|
|
__ j(above, &while_true, Label::kNear);
|
|
|
|
__ movsd(double_result, double_scratch);
|
|
|
|
__ j(zero, &while_false, Label::kNear);
|
2011-12-07 08:34:27 +00:00
|
|
|
|
2012-09-18 08:04:31 +00:00
|
|
|
__ bind(&while_true);
|
|
|
|
__ shrl(scratch, Immediate(1));
|
2011-12-07 08:34:27 +00:00
|
|
|
__ mulsd(double_scratch, double_scratch);
|
2012-09-18 08:04:31 +00:00
|
|
|
__ j(above, &while_true, Label::kNear);
|
|
|
|
__ mulsd(double_result, double_scratch);
|
2011-02-28 14:57:14 +00:00
|
|
|
__ j(not_zero, &while_true);
|
|
|
|
|
2012-09-18 08:04:31 +00:00
|
|
|
__ bind(&while_false);
|
2011-12-07 16:15:18 +00:00
|
|
|
// If the exponent is negative, return 1/result.
|
2011-12-07 08:34:27 +00:00
|
|
|
__ testl(exponent, exponent);
|
|
|
|
__ j(greater, &done);
|
|
|
|
__ divsd(double_scratch2, double_result);
|
|
|
|
__ movsd(double_result, double_scratch2);
|
|
|
|
// Test whether result is zero. Bail out to check for subnormal result.
|
|
|
|
// Due to subnormals, x^-y == (1/x)^y does not hold in all cases.
|
|
|
|
__ xorps(double_scratch2, double_scratch2);
|
|
|
|
__ ucomisd(double_scratch2, double_result);
|
2011-12-07 16:15:18 +00:00
|
|
|
// double_exponent aliased as double_scratch2 has already been overwritten
|
|
|
|
// and may not have contained the exponent value in the first place when the
|
|
|
|
// input was a smi. We reset it with exponent value before bailing out.
|
|
|
|
__ j(not_equal, &done);
|
2013-09-13 07:59:48 +00:00
|
|
|
__ Cvtlsi2sd(double_exponent, exponent);
|
2011-12-07 08:34:27 +00:00
|
|
|
|
|
|
|
// Returning or bailing out.
|
2011-12-07 16:15:18 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
2011-12-07 08:34:27 +00:00
|
|
|
if (exponent_type_ == ON_STACK) {
|
2011-12-07 16:15:18 +00:00
|
|
|
// The arguments are still on the stack.
|
|
|
|
__ bind(&call_runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1);
|
|
|
|
|
2011-12-07 08:34:27 +00:00
|
|
|
// The stub is called from non-optimized code, which expects the result
|
2013-07-03 15:36:49 +00:00
|
|
|
// as heap number in rax.
|
2011-12-07 08:34:27 +00:00
|
|
|
__ bind(&done);
|
2011-12-07 16:15:18 +00:00
|
|
|
__ AllocateHeapNumber(rax, rcx, &call_runtime);
|
2011-12-07 08:34:27 +00:00
|
|
|
__ movsd(FieldOperand(rax, HeapNumber::kValueOffset), double_result);
|
2011-12-07 16:15:18 +00:00
|
|
|
__ IncrementCounter(counters->math_pow(), 1);
|
2011-12-07 08:34:27 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
} else {
|
2011-12-07 16:15:18 +00:00
|
|
|
__ bind(&call_runtime);
|
2011-12-07 08:34:27 +00:00
|
|
|
// Move base to the correct argument register. Exponent is already in xmm1.
|
|
|
|
__ movsd(xmm0, double_base);
|
|
|
|
ASSERT(double_exponent.is(xmm1));
|
|
|
|
{
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
__ PrepareCallCFunction(2);
|
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::power_double_double_function(masm->isolate()), 2);
|
|
|
|
}
|
|
|
|
// Return value is in xmm0.
|
|
|
|
__ movsd(double_result, xmm0);
|
2011-02-28 14:57:14 +00:00
|
|
|
|
2011-12-07 08:34:27 +00:00
|
|
|
__ bind(&done);
|
2011-12-07 16:15:18 +00:00
|
|
|
__ IncrementCounter(counters->math_pow(), 1);
|
2011-12-07 08:34:27 +00:00
|
|
|
__ ret(0);
|
|
|
|
}
|
2011-02-28 14:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-21 17:54:36 +00:00
|
|
|
void FunctionPrototypeStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label miss;
|
|
|
|
Register receiver;
|
|
|
|
if (kind() == Code::KEYED_LOAD_IC) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- rax : key
|
|
|
|
// -- rdx : receiver
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -----------------------------------
|
2013-02-28 17:03:34 +00:00
|
|
|
__ Cmp(rax, masm->isolate()->factory()->prototype_string());
|
2013-03-06 18:19:35 +00:00
|
|
|
__ j(not_equal, &miss);
|
2013-01-21 17:54:36 +00:00
|
|
|
receiver = rdx;
|
|
|
|
} else {
|
|
|
|
ASSERT(kind() == Code::LOAD_IC);
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- rax : receiver
|
|
|
|
// -- rcx : name
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -----------------------------------
|
|
|
|
receiver = rax;
|
|
|
|
}
|
|
|
|
|
|
|
|
StubCompiler::GenerateLoadFunctionPrototype(masm, receiver, r8, r9, &miss);
|
|
|
|
__ bind(&miss);
|
2013-07-09 08:22:41 +00:00
|
|
|
StubCompiler::TailCallBuiltin(
|
|
|
|
masm, BaseLoadStoreStubCompiler::MissBuiltin(kind()));
|
2013-01-21 17:54:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-21 14:53:29 +00:00
|
|
|
void StringLengthStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label miss;
|
|
|
|
Register receiver;
|
|
|
|
if (kind() == Code::KEYED_LOAD_IC) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- rax : key
|
|
|
|
// -- rdx : receiver
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -----------------------------------
|
2013-02-28 17:03:34 +00:00
|
|
|
__ Cmp(rax, masm->isolate()->factory()->length_string());
|
2013-03-06 18:19:35 +00:00
|
|
|
__ j(not_equal, &miss);
|
2013-01-21 14:53:29 +00:00
|
|
|
receiver = rdx;
|
|
|
|
} else {
|
|
|
|
ASSERT(kind() == Code::LOAD_IC);
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- rax : receiver
|
|
|
|
// -- rcx : name
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -----------------------------------
|
|
|
|
receiver = rax;
|
|
|
|
}
|
|
|
|
|
2013-09-13 09:57:48 +00:00
|
|
|
StubCompiler::GenerateLoadStringLength(masm, receiver, r8, r9, &miss);
|
2013-01-21 14:53:29 +00:00
|
|
|
__ bind(&miss);
|
2013-07-09 08:22:41 +00:00
|
|
|
StubCompiler::TailCallBuiltin(
|
|
|
|
masm, BaseLoadStoreStubCompiler::MissBuiltin(kind()));
|
2013-01-21 14:53:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-25 11:55:29 +00:00
|
|
|
void StoreArrayLengthStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- rax : value
|
|
|
|
// -- rcx : key
|
|
|
|
// -- rdx : receiver
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -----------------------------------
|
|
|
|
//
|
|
|
|
// This accepts as a receiver anything JSArray::SetElementsLength accepts
|
|
|
|
// (currently anything except for external arrays which means anything with
|
|
|
|
// elements of FixedArray type). Value must be a number, but only smis are
|
|
|
|
// accepted as the most common case.
|
|
|
|
|
|
|
|
Label miss;
|
|
|
|
|
|
|
|
Register receiver = rdx;
|
|
|
|
Register value = rax;
|
|
|
|
Register scratch = rbx;
|
|
|
|
if (kind() == Code::KEYED_STORE_IC) {
|
2013-02-28 17:03:34 +00:00
|
|
|
__ Cmp(rcx, masm->isolate()->factory()->length_string());
|
2013-03-05 16:31:11 +00:00
|
|
|
__ j(not_equal, &miss);
|
2013-01-25 11:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the receiver isn't a smi.
|
|
|
|
__ JumpIfSmi(receiver, &miss);
|
|
|
|
|
|
|
|
// Check that the object is a JS array.
|
|
|
|
__ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch);
|
|
|
|
__ j(not_equal, &miss);
|
|
|
|
|
|
|
|
// Check that elements are FixedArray.
|
|
|
|
// We rely on StoreIC_ArrayLength below to deal with all types of
|
|
|
|
// fast elements (including COW).
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, FieldOperand(receiver, JSArray::kElementsOffset));
|
2013-01-25 11:55:29 +00:00
|
|
|
__ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch);
|
|
|
|
__ j(not_equal, &miss);
|
|
|
|
|
|
|
|
// Check that the array has fast properties, otherwise the length
|
|
|
|
// property might have been redefined.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset));
|
2013-01-25 11:55:29 +00:00
|
|
|
__ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset),
|
|
|
|
Heap::kHashTableMapRootIndex);
|
|
|
|
__ j(equal, &miss);
|
|
|
|
|
|
|
|
// Check that value is a smi.
|
|
|
|
__ JumpIfNotSmi(value, &miss);
|
|
|
|
|
|
|
|
// Prepare tail call to StoreIC_ArrayLength.
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PopReturnAddressTo(scratch);
|
2013-01-25 11:55:29 +00:00
|
|
|
__ push(receiver);
|
|
|
|
__ push(value);
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PushReturnAddressFrom(scratch);
|
2013-01-25 11:55:29 +00:00
|
|
|
|
|
|
|
ExternalReference ref =
|
|
|
|
ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate());
|
|
|
|
__ TailCallExternalReference(ref, 2, 1);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
|
2013-07-09 08:22:41 +00:00
|
|
|
StubCompiler::TailCallBuiltin(
|
|
|
|
masm, BaseLoadStoreStubCompiler::MissBuiltin(kind()));
|
2013-01-25 11:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) {
|
|
|
|
// The key is in rdx and the parameter count is in rax.
|
|
|
|
|
|
|
|
// Check that the key is a smi.
|
|
|
|
Label slow;
|
|
|
|
__ JumpIfNotSmi(rdx, &slow);
|
|
|
|
|
2011-03-15 10:03:57 +00:00
|
|
|
// Check if the calling frame is an arguments adaptor frame. We look at the
|
|
|
|
// context offset, and if the frame is not a regular one, then we find a
|
|
|
|
// Smi instead of the context. We can't use SmiCompare here, because that
|
|
|
|
// only works for comparing two smis.
|
2010-08-25 09:44:44 +00:00
|
|
|
Label adaptor;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
|
2011-03-15 10:03:57 +00:00
|
|
|
__ Cmp(Operand(rbx, StandardFrameConstants::kContextOffset),
|
|
|
|
Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(equal, &adaptor);
|
|
|
|
|
|
|
|
// Check index against formal parameters count limit passed in
|
|
|
|
// through register rax. Use unsigned comparison to get negative
|
|
|
|
// check for free.
|
|
|
|
__ cmpq(rdx, rax);
|
|
|
|
__ j(above_equal, &slow);
|
|
|
|
|
|
|
|
// Read the argument from the stack and return it.
|
2013-10-03 01:22:25 +00:00
|
|
|
__ SmiSub(rax, rax, rdx);
|
|
|
|
__ SmiToInteger32(rax, rax);
|
|
|
|
StackArgumentsAccessor args(rbp, rax, ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, args.GetArgumentOperand(0));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Arguments adaptor case: Check index against actual arguments
|
|
|
|
// limit found in the arguments adaptor frame. Use unsigned
|
|
|
|
// comparison to get negative check for free.
|
|
|
|
__ bind(&adaptor);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, Operand(rbx, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmpq(rdx, rcx);
|
|
|
|
__ j(above_equal, &slow);
|
|
|
|
|
|
|
|
// Read the argument from the stack and return it.
|
2013-10-03 01:22:25 +00:00
|
|
|
__ SmiSub(rcx, rcx, rdx);
|
|
|
|
__ SmiToInteger32(rcx, rcx);
|
|
|
|
StackArgumentsAccessor adaptor_args(rbx, rcx,
|
|
|
|
ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, adaptor_args.GetArgumentOperand(0));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Ret();
|
|
|
|
|
|
|
|
// Slow-case: Handle non-smi or out-of-bounds access to arguments
|
|
|
|
// by calling the runtime system.
|
|
|
|
__ bind(&slow);
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PopReturnAddressTo(rbx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ push(rdx);
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PushReturnAddressFrom(rbx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-16 14:12:58 +00:00
|
|
|
void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) {
|
|
|
|
// Stack layout:
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0] : return address
|
|
|
|
// rsp[8] : number of parameters (tagged)
|
2011-06-16 14:12:58 +00:00
|
|
|
// rsp[16] : receiver displacement
|
|
|
|
// rsp[24] : function
|
|
|
|
// Registers used over the whole function:
|
|
|
|
// rbx: the mapped parameter count (untagged)
|
|
|
|
// rax: the allocated object (tagged).
|
|
|
|
|
|
|
|
Factory* factory = masm->isolate()->factory();
|
|
|
|
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 3, ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
|
|
|
__ SmiToInteger64(rbx, args.GetArgumentOperand(2));
|
2011-06-16 14:12:58 +00:00
|
|
|
// rbx = parameter count (untagged)
|
|
|
|
|
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
|
|
|
Label runtime;
|
|
|
|
Label adaptor_frame, try_allocate;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ movp(rcx, Operand(rdx, StandardFrameConstants::kContextOffset));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
|
|
|
|
__ j(equal, &adaptor_frame);
|
|
|
|
|
|
|
|
// No adaptor, parameter count = argument count.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, rbx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ jmp(&try_allocate, Label::kNear);
|
|
|
|
|
|
|
|
// We have an adaptor frame. Patch the parameters pointer.
|
|
|
|
__ bind(&adaptor_frame);
|
|
|
|
__ SmiToInteger64(rcx,
|
|
|
|
Operand(rdx,
|
|
|
|
ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ lea(rdx, Operand(rdx, rcx, times_pointer_size,
|
|
|
|
StandardFrameConstants::kCallerSPOffset));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(args.GetArgumentOperand(1), rdx);
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
// rbx = parameter count (untagged)
|
|
|
|
// rcx = argument count (untagged)
|
|
|
|
// Compute the mapped parameter count = min(rbx, rcx) in rbx.
|
|
|
|
__ cmpq(rbx, rcx);
|
|
|
|
__ j(less_equal, &try_allocate, Label::kNear);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, rcx);
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
__ bind(&try_allocate);
|
|
|
|
|
|
|
|
// Compute the sizes of backing store, parameter map, and arguments object.
|
|
|
|
// 1. Parameter map, has 2 extra words containing context and backing store.
|
|
|
|
const int kParameterMapHeaderSize =
|
|
|
|
FixedArray::kHeaderSize + 2 * kPointerSize;
|
|
|
|
Label no_parameter_map;
|
2012-01-16 15:11:56 +00:00
|
|
|
__ xor_(r8, r8);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ testq(rbx, rbx);
|
|
|
|
__ j(zero, &no_parameter_map, Label::kNear);
|
|
|
|
__ lea(r8, Operand(rbx, times_pointer_size, kParameterMapHeaderSize));
|
|
|
|
__ bind(&no_parameter_map);
|
|
|
|
|
|
|
|
// 2. Backing store.
|
|
|
|
__ lea(r8, Operand(r8, rcx, times_pointer_size, FixedArray::kHeaderSize));
|
|
|
|
|
|
|
|
// 3. Arguments object.
|
|
|
|
__ addq(r8, Immediate(Heap::kArgumentsObjectSize));
|
|
|
|
|
|
|
|
// Do the allocation of all three objects in one go.
|
2013-03-25 15:54:15 +00:00
|
|
|
__ Allocate(r8, rax, rdx, rdi, &runtime, TAG_OBJECT);
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
// rax = address of new object(s) (tagged)
|
|
|
|
// rcx = argument count (untagged)
|
2012-08-17 12:59:00 +00:00
|
|
|
// Get the arguments boilerplate from the current native context into rdi.
|
2011-06-16 14:12:58 +00:00
|
|
|
Label has_mapped_parameters, copy;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
|
|
|
|
__ movp(rdi, FieldOperand(rdi, GlobalObject::kNativeContextOffset));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ testq(rbx, rbx);
|
|
|
|
__ j(not_zero, &has_mapped_parameters, Label::kNear);
|
|
|
|
|
|
|
|
const int kIndex = Context::ARGUMENTS_BOILERPLATE_INDEX;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, Operand(rdi, Context::SlotOffset(kIndex)));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ jmp(©, Label::kNear);
|
|
|
|
|
|
|
|
const int kAliasedIndex = Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX;
|
|
|
|
__ bind(&has_mapped_parameters);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, Operand(rdi, Context::SlotOffset(kAliasedIndex)));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ bind(©);
|
|
|
|
|
|
|
|
// rax = address of new object (tagged)
|
|
|
|
// rbx = mapped parameter count (untagged)
|
|
|
|
// rcx = argument count (untagged)
|
|
|
|
// rdi = address of boilerplate object (tagged)
|
|
|
|
// Copy the JS object part.
|
|
|
|
for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) {
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, FieldOperand(rdi, i));
|
|
|
|
__ movp(FieldOperand(rax, i), rdx);
|
2011-06-16 14:12:58 +00:00
|
|
|
}
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the callee in-object property.
|
2011-06-16 14:12:58 +00:00
|
|
|
STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, args.GetArgumentOperand(0));
|
|
|
|
__ movp(FieldOperand(rax, JSObject::kHeaderSize +
|
2011-06-16 14:12:58 +00:00
|
|
|
Heap::kArgumentsCalleeIndex * kPointerSize),
|
|
|
|
rdx);
|
|
|
|
|
|
|
|
// Use the length (smi tagged) and set that as an in-object property too.
|
|
|
|
// Note: rcx is tagged from here on.
|
|
|
|
STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
|
|
|
|
__ Integer32ToSmi(rcx, rcx);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rax, JSObject::kHeaderSize +
|
2011-06-16 14:12:58 +00:00
|
|
|
Heap::kArgumentsLengthIndex * kPointerSize),
|
|
|
|
rcx);
|
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the elements pointer in the allocated arguments object.
|
2011-06-16 14:12:58 +00:00
|
|
|
// If we allocated a parameter map, edi will point there, otherwise to the
|
|
|
|
// backing store.
|
|
|
|
__ lea(rdi, Operand(rax, Heap::kArgumentsObjectSize));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rax, JSObject::kElementsOffset), rdi);
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
// rax = address of new object (tagged)
|
|
|
|
// rbx = mapped parameter count (untagged)
|
|
|
|
// rcx = argument count (tagged)
|
|
|
|
// rdi = address of parameter map or backing store (tagged)
|
|
|
|
|
|
|
|
// Initialize parameter map. If there are no mapped arguments, we're done.
|
|
|
|
Label skip_parameter_map;
|
|
|
|
__ testq(rbx, rbx);
|
|
|
|
__ j(zero, &skip_parameter_map);
|
|
|
|
|
|
|
|
__ LoadRoot(kScratchRegister, Heap::kNonStrictArgumentsElementsMapRootIndex);
|
|
|
|
// rbx contains the untagged argument count. Add 2 and tag to write.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rdi, FixedArray::kMapOffset), kScratchRegister);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ Integer64PlusConstantToSmi(r9, rbx, 2);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rdi, FixedArray::kLengthOffset), r9);
|
|
|
|
__ movp(FieldOperand(rdi, FixedArray::kHeaderSize + 0 * kPointerSize), rsi);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ lea(r9, Operand(rdi, rbx, times_pointer_size, kParameterMapHeaderSize));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rdi, FixedArray::kHeaderSize + 1 * kPointerSize), r9);
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
// Copy the parameter slots and the holes in the arguments.
|
|
|
|
// We need to fill in mapped_parameter_count slots. They index the context,
|
|
|
|
// where parameters are stored in reverse order, at
|
|
|
|
// MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1
|
|
|
|
// The mapped parameter thus need to get indices
|
|
|
|
// MIN_CONTEXT_SLOTS+parameter_count-1 ..
|
|
|
|
// MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count
|
|
|
|
// We loop from right to left.
|
|
|
|
Label parameters_loop, parameters_test;
|
|
|
|
|
|
|
|
// Load tagged parameter count into r9.
|
2012-01-16 15:11:56 +00:00
|
|
|
__ Integer32ToSmi(r9, rbx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ Move(r8, Smi::FromInt(Context::MIN_CONTEXT_SLOTS));
|
2013-08-27 01:21:39 +00:00
|
|
|
__ addq(r8, args.GetArgumentOperand(2));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ subq(r8, r9);
|
|
|
|
__ Move(r11, factory->the_hole_value());
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, rdi);
|
2012-01-16 15:11:56 +00:00
|
|
|
__ lea(rdi, Operand(rdi, rbx, times_pointer_size, kParameterMapHeaderSize));
|
2011-06-16 14:12:58 +00:00
|
|
|
// r9 = loop variable (tagged)
|
|
|
|
// r8 = mapping index (tagged)
|
|
|
|
// r11 = the hole value
|
|
|
|
// rdx = address of parameter map (tagged)
|
|
|
|
// rdi = address of backing store (tagged)
|
|
|
|
__ jmp(¶meters_test, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(¶meters_loop);
|
|
|
|
__ SmiSubConstant(r9, r9, Smi::FromInt(1));
|
|
|
|
__ SmiToInteger64(kScratchRegister, r9);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rdx, kScratchRegister,
|
2011-06-16 14:12:58 +00:00
|
|
|
times_pointer_size,
|
|
|
|
kParameterMapHeaderSize),
|
|
|
|
r8);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rdi, kScratchRegister,
|
2011-06-16 14:12:58 +00:00
|
|
|
times_pointer_size,
|
|
|
|
FixedArray::kHeaderSize),
|
|
|
|
r11);
|
|
|
|
__ SmiAddConstant(r8, r8, Smi::FromInt(1));
|
|
|
|
__ bind(¶meters_test);
|
|
|
|
__ SmiTest(r9);
|
|
|
|
__ j(not_zero, ¶meters_loop, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(&skip_parameter_map);
|
|
|
|
|
|
|
|
// rcx = argument count (tagged)
|
|
|
|
// rdi = address of backing store (tagged)
|
|
|
|
// Copy arguments header and remaining slots (if there are any).
|
|
|
|
__ Move(FieldOperand(rdi, FixedArray::kMapOffset),
|
|
|
|
factory->fixed_array_map());
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rdi, FixedArray::kLengthOffset), rcx);
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
Label arguments_loop, arguments_test;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r8, rbx);
|
|
|
|
__ movp(rdx, args.GetArgumentOperand(1));
|
2012-01-16 15:11:56 +00:00
|
|
|
// Untag rcx for the loop below.
|
2011-06-16 14:12:58 +00:00
|
|
|
__ SmiToInteger64(rcx, rcx);
|
|
|
|
__ lea(kScratchRegister, Operand(r8, times_pointer_size, 0));
|
|
|
|
__ subq(rdx, kScratchRegister);
|
|
|
|
__ jmp(&arguments_test, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(&arguments_loop);
|
|
|
|
__ subq(rdx, Immediate(kPointerSize));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r9, Operand(rdx, 0));
|
|
|
|
__ movp(FieldOperand(rdi, r8,
|
2011-06-16 14:12:58 +00:00
|
|
|
times_pointer_size,
|
|
|
|
FixedArray::kHeaderSize),
|
|
|
|
r9);
|
|
|
|
__ addq(r8, Immediate(1));
|
|
|
|
|
|
|
|
__ bind(&arguments_test);
|
|
|
|
__ cmpq(r8, rcx);
|
|
|
|
__ j(less, &arguments_loop, Label::kNear);
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameters.
|
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
// Do the runtime call to allocate the arguments object.
|
|
|
|
// rcx = argument count (untagged)
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ Integer32ToSmi(rcx, rcx);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(args.GetArgumentOperand(2), rcx); // Patch argument count.
|
2012-10-26 10:55:25 +00:00
|
|
|
__ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1);
|
2011-06-16 14:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) {
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0] : return address
|
|
|
|
// rsp[8] : number of parameters
|
|
|
|
// rsp[16] : receiver displacement
|
|
|
|
// rsp[24] : function
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
|
|
|
Label runtime;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ movp(rcx, Operand(rdx, StandardFrameConstants::kContextOffset));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
|
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
|
|
|
|
// Patch the arguments.length and the parameters pointer.
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 3, ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, Operand(rdx, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ movp(args.GetArgumentOperand(2), rcx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ SmiToInteger64(rcx, rcx);
|
|
|
|
__ lea(rdx, Operand(rdx, rcx, times_pointer_size,
|
|
|
|
StandardFrameConstants::kCallerSPOffset));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(args.GetArgumentOperand(1), rdx);
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) {
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0] : return address
|
|
|
|
// rsp[8] : number of parameters
|
2010-08-25 09:44:44 +00:00
|
|
|
// rsp[16] : receiver displacement
|
|
|
|
// rsp[24] : function
|
|
|
|
|
|
|
|
// Check if the calling frame is an arguments adaptor frame.
|
|
|
|
Label adaptor_frame, try_allocate, runtime;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, Operand(rbp, StandardFrameConstants::kCallerFPOffset));
|
|
|
|
__ movp(rcx, Operand(rdx, StandardFrameConstants::kContextOffset));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ Cmp(rcx, Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(equal, &adaptor_frame);
|
|
|
|
|
|
|
|
// Get the length from the frame.
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 3, ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, args.GetArgumentOperand(2));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ SmiToInteger64(rcx, rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(&try_allocate);
|
|
|
|
|
|
|
|
// Patch the arguments.length and the parameters pointer.
|
|
|
|
__ bind(&adaptor_frame);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, Operand(rdx, ArgumentsAdaptorFrameConstants::kLengthOffset));
|
|
|
|
__ movp(args.GetArgumentOperand(2), rcx);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ SmiToInteger64(rcx, rcx);
|
|
|
|
__ lea(rdx, Operand(rdx, rcx, times_pointer_size,
|
|
|
|
StandardFrameConstants::kCallerSPOffset));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(args.GetArgumentOperand(1), rdx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Try the new space allocation. Start out with computing the size of
|
|
|
|
// the arguments object and the elements array.
|
|
|
|
Label add_arguments_object;
|
|
|
|
__ bind(&try_allocate);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ testq(rcx, rcx);
|
|
|
|
__ j(zero, &add_arguments_object, Label::kNear);
|
|
|
|
__ lea(rcx, Operand(rcx, times_pointer_size, FixedArray::kHeaderSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&add_arguments_object);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ addq(rcx, Immediate(Heap::kArgumentsObjectSizeStrict));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Do the allocation of both objects in one go.
|
2013-03-25 15:54:15 +00:00
|
|
|
__ Allocate(rcx, rax, rdx, rbx, &runtime, TAG_OBJECT);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-08-17 12:59:00 +00:00
|
|
|
// Get the arguments boilerplate from the current native context.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, Operand(rsi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)));
|
|
|
|
__ movp(rdi, FieldOperand(rdi, GlobalObject::kNativeContextOffset));
|
2011-06-16 14:12:58 +00:00
|
|
|
const int offset =
|
|
|
|
Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, Operand(rdi, offset));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Copy the JS object part.
|
2011-06-16 14:12:58 +00:00
|
|
|
for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) {
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, FieldOperand(rdi, i));
|
|
|
|
__ movp(FieldOperand(rax, i), rbx);
|
2011-03-17 20:28:41 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Get the length (smi tagged) and set that as an in-object property too.
|
2011-06-16 14:12:58 +00:00
|
|
|
STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, args.GetArgumentOperand(2));
|
|
|
|
__ movp(FieldOperand(rax, JSObject::kHeaderSize +
|
2011-06-16 14:12:58 +00:00
|
|
|
Heap::kArgumentsLengthIndex * kPointerSize),
|
2011-03-17 20:28:41 +00:00
|
|
|
rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If there are no actual arguments, we're done.
|
|
|
|
Label done;
|
2011-06-16 14:12:58 +00:00
|
|
|
__ testq(rcx, rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(zero, &done);
|
|
|
|
|
2011-06-16 14:12:58 +00:00
|
|
|
// Get the parameters pointer from the stack.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, args.GetArgumentOperand(1));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up the elements pointer in the allocated arguments object and
|
2010-08-25 09:44:44 +00:00
|
|
|
// initialize the header in the elements fixed array.
|
2011-06-16 14:12:58 +00:00
|
|
|
__ lea(rdi, Operand(rax, Heap::kArgumentsObjectSizeStrict));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rax, JSObject::kElementsOffset), rdi);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ LoadRoot(kScratchRegister, Heap::kFixedArrayMapRootIndex);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rdi, FixedArray::kMapOffset), kScratchRegister);
|
2011-06-16 14:12:58 +00:00
|
|
|
|
|
|
|
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rdi, FixedArray::kLengthOffset), rcx);
|
2011-06-16 14:12:58 +00:00
|
|
|
// Untag the length for the loop below.
|
|
|
|
__ SmiToInteger64(rcx, rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Copy the fixed array slots.
|
|
|
|
Label loop;
|
|
|
|
__ bind(&loop);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, Operand(rdx, -1 * kPointerSize)); // Skip receiver.
|
|
|
|
__ movp(FieldOperand(rdi, FixedArray::kHeaderSize), rbx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ addq(rdi, Immediate(kPointerSize));
|
|
|
|
__ subq(rdx, Immediate(kPointerSize));
|
2011-06-16 14:12:58 +00:00
|
|
|
__ decq(rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_zero, &loop);
|
|
|
|
|
|
|
|
// Return and remove the on-stack parameters.
|
|
|
|
__ bind(&done);
|
|
|
|
__ ret(3 * kPointerSize);
|
|
|
|
|
|
|
|
// Do the runtime call to allocate the arguments object.
|
|
|
|
__ bind(&runtime);
|
2011-06-16 14:12:58 +00:00
|
|
|
__ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RegExpExecStub::Generate(MacroAssembler* masm) {
|
|
|
|
// Just jump directly to runtime if native RegExp is not selected at compile
|
|
|
|
// time or if regexp entry in generated code is turned off runtime switch or
|
|
|
|
// at compilation.
|
|
|
|
#ifdef V8_INTERPRETED_REGEXP
|
|
|
|
__ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
|
|
|
|
#else // V8_INTERPRETED_REGEXP
|
|
|
|
|
|
|
|
// Stack frame on entry.
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0] : return address
|
|
|
|
// rsp[8] : last_match_info (expected JSArray)
|
|
|
|
// rsp[16] : previous index
|
|
|
|
// rsp[24] : subject string
|
|
|
|
// rsp[32] : JSRegExp object
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-10-03 01:22:25 +00:00
|
|
|
enum RegExpExecStubArgumentIndices {
|
|
|
|
JS_REG_EXP_OBJECT_ARGUMENT_INDEX,
|
|
|
|
SUBJECT_STRING_ARGUMENT_INDEX,
|
|
|
|
PREVIOUS_INDEX_ARGUMENT_INDEX,
|
|
|
|
LAST_MATCH_INFO_ARGUMENT_INDEX,
|
|
|
|
REG_EXP_EXEC_ARGUMENT_COUNT
|
|
|
|
};
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-10-03 01:22:25 +00:00
|
|
|
StackArgumentsAccessor args(rsp, REG_EXP_EXEC_ARGUMENT_COUNT,
|
|
|
|
ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2010-08-25 09:44:44 +00:00
|
|
|
Label runtime;
|
|
|
|
// Ensure that a RegExp stack is allocated.
|
2011-03-22 13:20:04 +00:00
|
|
|
Isolate* isolate = masm->isolate();
|
2010-08-25 09:44:44 +00:00
|
|
|
ExternalReference address_of_regexp_stack_memory_address =
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::address_of_regexp_stack_memory_address(isolate);
|
2010-08-25 09:44:44 +00:00
|
|
|
ExternalReference address_of_regexp_stack_memory_size =
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::address_of_regexp_stack_memory_size(isolate);
|
2011-03-23 09:05:13 +00:00
|
|
|
__ Load(kScratchRegister, address_of_regexp_stack_memory_size);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ testq(kScratchRegister, kScratchRegister);
|
|
|
|
__ j(zero, &runtime);
|
|
|
|
|
|
|
|
// Check that the first argument is a JSRegExp object.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, args.GetArgumentOperand(JS_REG_EXP_OBJECT_ARGUMENT_INDEX));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ JumpIfSmi(rax, &runtime);
|
|
|
|
__ CmpObjectType(rax, JS_REGEXP_TYPE, kScratchRegister);
|
|
|
|
__ j(not_equal, &runtime);
|
2013-02-26 09:53:07 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Check that the RegExp has been compiled (data contains a fixed array).
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, FieldOperand(rax, JSRegExp::kDataOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
if (FLAG_debug_code) {
|
2011-03-08 14:15:25 +00:00
|
|
|
Condition is_smi = masm->CheckSmi(rax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Check(NegateCondition(is_smi),
|
2013-08-02 09:53:11 +00:00
|
|
|
kUnexpectedTypeForRegExpDataFixedArrayExpected);
|
2011-03-08 14:15:25 +00:00
|
|
|
__ CmpObjectType(rax, FIXED_ARRAY_TYPE, kScratchRegister);
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
2011-03-08 14:15:25 +00:00
|
|
|
// rax: RegExp data (FixedArray)
|
2010-08-25 09:44:44 +00:00
|
|
|
// Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP.
|
2011-03-08 14:15:25 +00:00
|
|
|
__ SmiToInteger32(rbx, FieldOperand(rax, JSRegExp::kDataTagOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmpl(rbx, Immediate(JSRegExp::IRREGEXP));
|
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
|
2011-03-08 14:15:25 +00:00
|
|
|
// rax: RegExp data (FixedArray)
|
2010-08-25 09:44:44 +00:00
|
|
|
// Check that the number of captures fit in the static offsets vector buffer.
|
|
|
|
__ SmiToInteger32(rdx,
|
2011-03-08 14:15:25 +00:00
|
|
|
FieldOperand(rax, JSRegExp::kIrregexpCaptureCountOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
// Check (number_of_captures + 1) * 2 <= offsets vector size
|
|
|
|
// Or number_of_captures <= offsets vector size / 2 - 1
|
|
|
|
STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2);
|
|
|
|
__ cmpl(rdx, Immediate(Isolate::kJSRegexpStaticOffsetsVectorSize / 2 - 1));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above, &runtime);
|
|
|
|
|
2011-08-26 13:03:30 +00:00
|
|
|
// Reset offset for possibly sliced string.
|
|
|
|
__ Set(r14, 0);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, args.GetArgumentOperand(SUBJECT_STRING_ARGUMENT_INDEX));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ JumpIfSmi(rdi, &runtime);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r15, rdi); // Make a copy of the original subject string.
|
|
|
|
__ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
// rax: RegExp data (FixedArray)
|
|
|
|
// rdi: subject string
|
|
|
|
// r15: subject string
|
|
|
|
// Handle subject string according to its encoding and representation:
|
|
|
|
// (1) Sequential two byte? If yes, go to (9).
|
|
|
|
// (2) Sequential one byte? If yes, go to (6).
|
|
|
|
// (3) Anything but sequential or cons? If yes, go to (7).
|
|
|
|
// (4) Cons string. If the string is flat, replace subject with first string.
|
|
|
|
// Otherwise bailout.
|
|
|
|
// (5a) Is subject sequential two byte? If yes, go to (9).
|
|
|
|
// (5b) Is subject external? If yes, go to (8).
|
|
|
|
// (6) One byte sequential. Load regexp code for one byte.
|
|
|
|
// (E) Carry on.
|
|
|
|
/// [...]
|
|
|
|
|
|
|
|
// Deferred code at the end of the stub:
|
|
|
|
// (7) Not a long external string? If yes, go to (10).
|
|
|
|
// (8) External string. Make it, offset-wise, look like a sequential string.
|
|
|
|
// (8a) Is the external string one byte? If yes, go to (6).
|
|
|
|
// (9) Two byte sequential. Load regexp code for one byte. Go to (E).
|
|
|
|
// (10) Short external string or not a string? If yes, bail out to runtime.
|
|
|
|
// (11) Sliced string. Replace subject with parent. Go to (5a).
|
|
|
|
|
|
|
|
Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */,
|
|
|
|
external_string /* 8 */, check_underlying /* 5a */,
|
|
|
|
not_seq_nor_cons /* 7 */, check_code /* E */,
|
|
|
|
not_long_external /* 10 */;
|
|
|
|
|
|
|
|
// (1) Sequential two byte? If yes, go to (9).
|
2011-11-25 14:04:47 +00:00
|
|
|
__ andb(rbx, Immediate(kIsNotStringMask |
|
|
|
|
kStringRepresentationMask |
|
|
|
|
kStringEncodingMask |
|
|
|
|
kShortExternalStringMask));
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0);
|
2013-02-26 09:53:07 +00:00
|
|
|
__ j(zero, &seq_two_byte_string); // Go to (9).
|
|
|
|
|
|
|
|
// (2) Sequential one byte? If yes, go to (6).
|
|
|
|
// Any other sequential string must be one byte.
|
2011-11-25 14:04:47 +00:00
|
|
|
__ andb(rbx, Immediate(kIsNotStringMask |
|
|
|
|
kStringRepresentationMask |
|
|
|
|
kShortExternalStringMask));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6).
|
|
|
|
|
|
|
|
// (3) Anything but sequential or cons? If yes, go to (7).
|
|
|
|
// We check whether the subject string is a cons, since sequential strings
|
|
|
|
// have already been covered.
|
2011-08-29 11:41:23 +00:00
|
|
|
STATIC_ASSERT(kConsStringTag < kExternalStringTag);
|
|
|
|
STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
|
2011-11-24 18:36:24 +00:00
|
|
|
STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
|
2011-11-25 14:04:47 +00:00
|
|
|
STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
|
2011-08-26 13:03:30 +00:00
|
|
|
__ cmpq(rbx, Immediate(kExternalStringTag));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ j(greater_equal, ¬_seq_nor_cons); // Go to (7).
|
2011-11-24 18:36:24 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// (4) Cons string. Check that it's flat.
|
|
|
|
// Replace subject with first string and reload instance type.
|
2011-03-11 13:33:39 +00:00
|
|
|
__ CompareRoot(FieldOperand(rdi, ConsString::kSecondOffset),
|
2013-02-28 17:03:34 +00:00
|
|
|
Heap::kempty_stringRootIndex);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, &runtime);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, FieldOperand(rdi, ConsString::kFirstOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ bind(&check_underlying);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
|
|
|
|
__ movp(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
|
|
|
|
// (5a) Is subject sequential two byte? If yes, go to (9).
|
|
|
|
__ testb(rbx, Immediate(kStringRepresentationMask | kStringEncodingMask));
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0);
|
2013-02-26 09:53:07 +00:00
|
|
|
__ j(zero, &seq_two_byte_string); // Go to (9).
|
|
|
|
// (5b) Is subject external? If yes, go to (8).
|
|
|
|
__ testb(rbx, Immediate(kStringRepresentationMask));
|
|
|
|
// The underlying external string is never a short external string.
|
|
|
|
STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength);
|
|
|
|
STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength);
|
|
|
|
__ j(not_zero, &external_string); // Go to (8)
|
|
|
|
|
|
|
|
// (6) One byte sequential. Load regexp code for one byte.
|
|
|
|
__ bind(&seq_one_byte_string);
|
2011-02-15 13:53:51 +00:00
|
|
|
// rax: RegExp data (FixedArray)
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r11, FieldOperand(rax, JSRegExp::kDataAsciiCodeOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ Set(rcx, 1); // Type is one byte.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// (E) Carry on. String handling is done.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&check_code);
|
2013-02-26 09:53:07 +00:00
|
|
|
// r11: irregexp code
|
2010-08-25 09:44:44 +00:00
|
|
|
// Check that the irregexp code has been generated for the actual string
|
|
|
|
// encoding. If it has, the field contains a code object otherwise it contains
|
2011-07-05 06:19:53 +00:00
|
|
|
// smi (code flushing support)
|
|
|
|
__ JumpIfSmi(r11, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// rdi: sequential subject string (or look-alike, external string)
|
|
|
|
// r15: original subject string
|
2012-01-16 12:38:59 +00:00
|
|
|
// rcx: encoding of subject string (1 if ASCII, 0 if two_byte);
|
2010-08-25 09:44:44 +00:00
|
|
|
// r11: code
|
|
|
|
// Load used arguments before starting to push arguments for call to native
|
|
|
|
// RegExp code to avoid handling changing stack height.
|
2013-02-26 09:53:07 +00:00
|
|
|
// We have to use r15 instead of rdi to load the length because rdi might
|
|
|
|
// have been only made to look like a sequential string when it actually
|
|
|
|
// is an external string.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, args.GetArgumentOperand(PREVIOUS_INDEX_ARGUMENT_INDEX));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ JumpIfNotSmi(rbx, &runtime);
|
|
|
|
__ SmiCompare(rbx, FieldOperand(r15, String::kLengthOffset));
|
|
|
|
__ j(above_equal, &runtime);
|
|
|
|
__ SmiToInteger64(rbx, rbx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-02-15 13:53:51 +00:00
|
|
|
// rdi: subject string
|
2010-08-25 09:44:44 +00:00
|
|
|
// rbx: previous index
|
2012-01-16 12:38:59 +00:00
|
|
|
// rcx: encoding of subject string (1 if ASCII 0 if two_byte);
|
2010-08-25 09:44:44 +00:00
|
|
|
// r11: code
|
|
|
|
// All checks done. Now push arguments for native regexp code.
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->regexp_entry_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
// Isolates: note we add an additional parameter here (isolate pointer).
|
2012-05-22 14:05:44 +00:00
|
|
|
static const int kRegExpExecuteArguments = 9;
|
2010-08-25 09:44:44 +00:00
|
|
|
int argument_slots_on_stack =
|
|
|
|
masm->ArgumentStackSlotsForCFunctionCall(kRegExpExecuteArguments);
|
2011-03-08 14:15:25 +00:00
|
|
|
__ EnterApiExitFrame(argument_slots_on_stack);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-05-22 14:05:44 +00:00
|
|
|
// Argument 9: Pass current isolate address.
|
2013-04-24 07:39:35 +00:00
|
|
|
__ LoadAddress(kScratchRegister,
|
|
|
|
ExternalReference::isolate_address(masm->isolate()));
|
2014-01-20 01:52:21 +00:00
|
|
|
__ movq(Operand(rsp, (argument_slots_on_stack - 1) * kRegisterSize),
|
2011-03-18 20:35:07 +00:00
|
|
|
kScratchRegister);
|
|
|
|
|
2012-05-22 14:05:44 +00:00
|
|
|
// Argument 8: Indicate that this is a direct call from JavaScript.
|
2014-01-20 01:52:21 +00:00
|
|
|
__ movq(Operand(rsp, (argument_slots_on_stack - 2) * kRegisterSize),
|
2010-08-25 09:44:44 +00:00
|
|
|
Immediate(1));
|
|
|
|
|
2012-05-22 14:05:44 +00:00
|
|
|
// Argument 7: Start (high end) of backtracking stack memory area.
|
2013-11-07 02:08:53 +00:00
|
|
|
__ Move(kScratchRegister, address_of_regexp_stack_memory_address);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r9, Operand(kScratchRegister, 0));
|
2013-11-07 02:08:53 +00:00
|
|
|
__ Move(kScratchRegister, address_of_regexp_stack_memory_size);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ addq(r9, Operand(kScratchRegister, 0));
|
2014-01-20 01:52:21 +00:00
|
|
|
__ movq(Operand(rsp, (argument_slots_on_stack - 3) * kRegisterSize), r9);
|
2012-05-22 14:05:44 +00:00
|
|
|
|
|
|
|
// Argument 6: Set the number of capture registers to zero to force global
|
|
|
|
// regexps to behave as non-global. This does not affect non-global regexps.
|
|
|
|
// Argument 6 is passed in r9 on Linux and on the stack on Windows.
|
|
|
|
#ifdef _WIN64
|
2014-01-20 01:52:21 +00:00
|
|
|
__ movq(Operand(rsp, (argument_slots_on_stack - 4) * kRegisterSize),
|
2012-05-22 14:05:44 +00:00
|
|
|
Immediate(0));
|
|
|
|
#else
|
|
|
|
__ Set(r9, 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Argument 5: static offsets vector buffer.
|
2011-03-23 09:05:13 +00:00
|
|
|
__ LoadAddress(r8,
|
|
|
|
ExternalReference::address_of_static_offsets_vector(isolate));
|
2010-08-25 09:44:44 +00:00
|
|
|
// Argument 5 passed in r8 on Linux and on the stack on Windows.
|
|
|
|
#ifdef _WIN64
|
2014-01-20 01:52:21 +00:00
|
|
|
__ movq(Operand(rsp, (argument_slots_on_stack - 5) * kRegisterSize), r8);
|
2010-08-25 09:44:44 +00:00
|
|
|
#endif
|
|
|
|
|
2011-02-15 13:53:51 +00:00
|
|
|
// rdi: subject string
|
2010-08-25 09:44:44 +00:00
|
|
|
// rbx: previous index
|
2012-01-16 12:38:59 +00:00
|
|
|
// rcx: encoding of subject string (1 if ASCII 0 if two_byte);
|
2010-08-25 09:44:44 +00:00
|
|
|
// r11: code
|
2011-08-26 13:03:30 +00:00
|
|
|
// r14: slice offset
|
|
|
|
// r15: original subject string
|
|
|
|
|
|
|
|
// Argument 2: Previous index.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(arg_reg_2, rbx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Argument 4: End of string data
|
|
|
|
// Argument 3: Start of string data
|
2011-08-26 13:03:30 +00:00
|
|
|
Label setup_two_byte, setup_rest, got_length, length_not_from_slice;
|
|
|
|
// Prepare start and end index of the input.
|
|
|
|
// Load the length from the original sliced string if that is the case.
|
|
|
|
__ addq(rbx, r14);
|
2013-04-24 12:01:08 +00:00
|
|
|
__ SmiToInteger32(arg_reg_3, FieldOperand(r15, String::kLengthOffset));
|
|
|
|
__ addq(r14, arg_reg_3); // Using arg3 as scratch.
|
2011-08-26 13:03:30 +00:00
|
|
|
|
|
|
|
// rbx: start index of the input
|
|
|
|
// r14: end index of the input
|
|
|
|
// r15: original subject string
|
2011-02-15 13:53:51 +00:00
|
|
|
__ testb(rcx, rcx); // Last use of rcx as encoding of subject string.
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &setup_two_byte, Label::kNear);
|
2013-04-24 12:01:08 +00:00
|
|
|
__ lea(arg_reg_4,
|
|
|
|
FieldOperand(rdi, r14, times_1, SeqOneByteString::kHeaderSize));
|
|
|
|
__ lea(arg_reg_3,
|
|
|
|
FieldOperand(rdi, rbx, times_1, SeqOneByteString::kHeaderSize));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ jmp(&setup_rest, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&setup_two_byte);
|
2013-04-24 12:01:08 +00:00
|
|
|
__ lea(arg_reg_4,
|
|
|
|
FieldOperand(rdi, r14, times_2, SeqTwoByteString::kHeaderSize));
|
|
|
|
__ lea(arg_reg_3,
|
|
|
|
FieldOperand(rdi, rbx, times_2, SeqTwoByteString::kHeaderSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&setup_rest);
|
|
|
|
|
2011-08-26 13:03:30 +00:00
|
|
|
// Argument 1: Original subject string.
|
|
|
|
// The original subject is in the previous stack frame. Therefore we have to
|
|
|
|
// use rbp, which points exactly to one pointer size below the previous rsp.
|
|
|
|
// (Because creating a new stack frame pushes the previous rbp onto the stack
|
|
|
|
// and thereby moves up rsp by one kPointerSize.)
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(arg_reg_1, r15);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Locate the code entry and call it.
|
|
|
|
__ addq(r11, Immediate(Code::kHeaderSize - kHeapObjectTag));
|
2011-02-15 13:53:51 +00:00
|
|
|
__ call(r11);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-09-17 11:37:48 +00:00
|
|
|
__ LeaveApiExitFrame(true);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check the result.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label success;
|
2011-02-15 13:53:51 +00:00
|
|
|
Label exception;
|
2012-05-22 14:05:44 +00:00
|
|
|
__ cmpl(rax, Immediate(1));
|
|
|
|
// We expect exactly one result since we force the called regexp to behave
|
|
|
|
// as non-global.
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &success, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmpl(rax, Immediate(NativeRegExpMacroAssembler::EXCEPTION));
|
2011-02-15 13:53:51 +00:00
|
|
|
__ j(equal, &exception);
|
|
|
|
__ cmpl(rax, Immediate(NativeRegExpMacroAssembler::FAILURE));
|
|
|
|
// If none of the above, it can only be retry.
|
|
|
|
// Handle that in the runtime system.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, &runtime);
|
2011-02-15 13:53:51 +00:00
|
|
|
|
|
|
|
// For failure return null.
|
|
|
|
__ LoadRoot(rax, Heap::kNullValueRootIndex);
|
2013-10-03 01:22:25 +00:00
|
|
|
__ ret(REG_EXP_EXEC_ARGUMENT_COUNT * kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Load RegExp data.
|
|
|
|
__ bind(&success);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, args.GetArgumentOperand(JS_REG_EXP_OBJECT_ARGUMENT_INDEX));
|
|
|
|
__ movp(rcx, FieldOperand(rax, JSRegExp::kDataOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ SmiToInteger32(rax,
|
|
|
|
FieldOperand(rcx, JSRegExp::kIrregexpCaptureCountOffset));
|
|
|
|
// Calculate number of capture registers (number_of_captures + 1) * 2.
|
|
|
|
__ leal(rdx, Operand(rax, rax, times_1, 2));
|
|
|
|
|
|
|
|
// rdx: Number of capture registers
|
2013-02-26 09:53:07 +00:00
|
|
|
// Check that the fourth object is a JSArray object.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r15, args.GetArgumentOperand(LAST_MATCH_INFO_ARGUMENT_INDEX));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ JumpIfSmi(r15, &runtime);
|
|
|
|
__ CmpObjectType(r15, JS_ARRAY_TYPE, kScratchRegister);
|
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
// Check that the JSArray is in fast case.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, FieldOperand(r15, JSArray::kElementsOffset));
|
|
|
|
__ movp(rax, FieldOperand(rbx, HeapObject::kMapOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ CompareRoot(rax, Heap::kFixedArrayMapRootIndex);
|
|
|
|
__ j(not_equal, &runtime);
|
|
|
|
// Check that the last match info has space for the capture registers and the
|
|
|
|
// additional information. Ensure no overflow in add.
|
|
|
|
STATIC_ASSERT(FixedArray::kMaxLength < kMaxInt - FixedArray::kLengthOffset);
|
|
|
|
__ SmiToInteger32(rax, FieldOperand(rbx, FixedArray::kLengthOffset));
|
|
|
|
__ subl(rax, Immediate(RegExpImpl::kLastMatchOverhead));
|
|
|
|
__ cmpl(rdx, rax);
|
|
|
|
__ j(greater, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// rbx: last_match_info backing store (FixedArray)
|
|
|
|
// rdx: number of capture registers
|
|
|
|
// Store the capture count.
|
|
|
|
__ Integer32ToSmi(kScratchRegister, rdx);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rbx, RegExpImpl::kLastCaptureCountOffset),
|
2010-08-25 09:44:44 +00:00
|
|
|
kScratchRegister);
|
|
|
|
// Store last subject and last input.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, args.GetArgumentOperand(SUBJECT_STRING_ARGUMENT_INDEX));
|
|
|
|
__ movp(FieldOperand(rbx, RegExpImpl::kLastSubjectOffset), rax);
|
|
|
|
__ movp(rcx, rax);
|
2011-09-19 18:36:47 +00:00
|
|
|
__ RecordWriteField(rbx,
|
|
|
|
RegExpImpl::kLastSubjectOffset,
|
|
|
|
rax,
|
|
|
|
rdi,
|
|
|
|
kDontSaveFPRegs);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, rcx);
|
|
|
|
__ movp(FieldOperand(rbx, RegExpImpl::kLastInputOffset), rax);
|
2011-09-19 18:36:47 +00:00
|
|
|
__ RecordWriteField(rbx,
|
|
|
|
RegExpImpl::kLastInputOffset,
|
|
|
|
rax,
|
|
|
|
rdi,
|
|
|
|
kDontSaveFPRegs);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Get the static offsets vector filled by the native regexp code.
|
2011-03-23 09:05:13 +00:00
|
|
|
__ LoadAddress(rcx,
|
|
|
|
ExternalReference::address_of_static_offsets_vector(isolate));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// rbx: last_match_info backing store (FixedArray)
|
|
|
|
// rcx: offsets vector
|
|
|
|
// rdx: number of capture registers
|
2011-05-10 09:03:42 +00:00
|
|
|
Label next_capture, done;
|
2010-08-25 09:44:44 +00:00
|
|
|
// Capture register counter starts from number of capture registers and
|
|
|
|
// counts down until wraping after zero.
|
|
|
|
__ bind(&next_capture);
|
|
|
|
__ subq(rdx, Immediate(1));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(negative, &done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Read the value from the static offsets vector buffer and make it a smi.
|
|
|
|
__ movl(rdi, Operand(rcx, rdx, times_int_size, 0));
|
2010-09-16 08:17:46 +00:00
|
|
|
__ Integer32ToSmi(rdi, rdi);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Store the smi value in the last match info.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rbx,
|
2010-08-25 09:44:44 +00:00
|
|
|
rdx,
|
|
|
|
times_pointer_size,
|
|
|
|
RegExpImpl::kFirstCaptureOffset),
|
|
|
|
rdi);
|
|
|
|
__ jmp(&next_capture);
|
|
|
|
__ bind(&done);
|
|
|
|
|
|
|
|
// Return last match info.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, r15);
|
2013-10-03 01:22:25 +00:00
|
|
|
__ ret(REG_EXP_EXEC_ARGUMENT_COUNT * kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-02-15 13:53:51 +00:00
|
|
|
__ bind(&exception);
|
|
|
|
// Result must now be exception. If there is no pending exception already a
|
|
|
|
// stack overflow (on the backtrack stack) was detected in RegExp code but
|
|
|
|
// haven't created the exception yet. Handle that in the runtime system.
|
|
|
|
// TODO(592): Rerunning the RegExp to get the stack overflow exception.
|
2011-03-18 20:35:07 +00:00
|
|
|
ExternalReference pending_exception_address(
|
2011-09-08 16:29:57 +00:00
|
|
|
Isolate::kPendingExceptionAddress, isolate);
|
2011-03-23 09:05:13 +00:00
|
|
|
Operand pending_exception_operand =
|
|
|
|
masm->ExternalOperand(pending_exception_address, rbx);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, pending_exception_operand);
|
2011-02-15 13:53:51 +00:00
|
|
|
__ LoadRoot(rdx, Heap::kTheHoleValueRootIndex);
|
|
|
|
__ cmpq(rax, rdx);
|
|
|
|
__ j(equal, &runtime);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(pending_exception_operand, rdx);
|
2011-02-15 13:53:51 +00:00
|
|
|
|
|
|
|
__ CompareRoot(rax, Heap::kTerminationExceptionRootIndex);
|
2011-05-10 09:03:42 +00:00
|
|
|
Label termination_exception;
|
|
|
|
__ j(equal, &termination_exception, Label::kNear);
|
2011-02-15 13:53:51 +00:00
|
|
|
__ Throw(rax);
|
|
|
|
|
|
|
|
__ bind(&termination_exception);
|
2012-02-10 08:47:35 +00:00
|
|
|
__ ThrowUncatchable(rax);
|
2011-02-15 13:53:51 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// Do the runtime call to execute the regexp.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kRegExpExec, 4, 1);
|
|
|
|
|
|
|
|
// Deferred code for string handling.
|
|
|
|
// (7) Not a long external string? If yes, go to (10).
|
|
|
|
__ bind(¬_seq_nor_cons);
|
|
|
|
// Compare flags are still set from (3).
|
|
|
|
__ j(greater, ¬_long_external, Label::kNear); // Go to (10).
|
|
|
|
|
|
|
|
// (8) External string. Short external strings have been ruled out.
|
2011-11-25 14:04:47 +00:00
|
|
|
__ bind(&external_string);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
|
2011-11-25 14:04:47 +00:00
|
|
|
__ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// Assert that we do not have a cons or slice (indirect strings) here.
|
|
|
|
// Sequential strings have already been ruled out.
|
|
|
|
__ testb(rbx, Immediate(kIsIndirectStringMask));
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Assert(zero, kExternalStringExpectedButNotFound);
|
2011-11-25 14:04:47 +00:00
|
|
|
}
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset));
|
2011-11-25 14:04:47 +00:00
|
|
|
// Move the pointer so that offset-wise, it looks like a sequential string.
|
2012-11-15 13:31:27 +00:00
|
|
|
STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
|
2011-11-25 14:04:47 +00:00
|
|
|
__ subq(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
|
|
|
STATIC_ASSERT(kTwoByteStringTag == 0);
|
2013-02-26 09:53:07 +00:00
|
|
|
// (8a) Is the external string one byte? If yes, go to (6).
|
2011-11-25 14:04:47 +00:00
|
|
|
__ testb(rbx, Immediate(kStringEncodingMask));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ j(not_zero, &seq_one_byte_string); // Goto (6).
|
2011-11-25 14:04:47 +00:00
|
|
|
|
2013-02-26 09:53:07 +00:00
|
|
|
// rdi: subject string (flat two-byte)
|
|
|
|
// rax: RegExp data (FixedArray)
|
|
|
|
// (9) Two byte sequential. Load regexp code for one byte. Go to (E).
|
|
|
|
__ bind(&seq_two_byte_string);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r11, FieldOperand(rax, JSRegExp::kDataUC16CodeOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ Set(rcx, 0); // Type is two byte.
|
|
|
|
__ jmp(&check_code); // Go to (E).
|
|
|
|
|
|
|
|
// (10) Not a string or a short external string? If yes, bail out to runtime.
|
|
|
|
__ bind(¬_long_external);
|
|
|
|
// Catch non-string subject or short external string.
|
|
|
|
STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
|
|
|
|
__ testb(rbx, Immediate(kIsNotStringMask | kShortExternalStringMask));
|
|
|
|
__ j(not_zero, &runtime);
|
|
|
|
|
|
|
|
// (11) Sliced string. Replace subject with parent. Go to (5a).
|
|
|
|
// Load offset into r14 and replace subject string with parent.
|
|
|
|
__ SmiToInteger32(r14, FieldOperand(rdi, SlicedString::kOffsetOffset));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, FieldOperand(rdi, SlicedString::kParentOffset));
|
2013-02-26 09:53:07 +00:00
|
|
|
__ jmp(&check_underlying);
|
2010-08-25 09:44:44 +00:00
|
|
|
#endif // V8_INTERPRETED_REGEXP
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int NegativeComparisonResult(Condition cc) {
|
|
|
|
ASSERT(cc != equal);
|
|
|
|
ASSERT((cc == less) || (cc == less_equal)
|
|
|
|
|| (cc == greater) || (cc == greater_equal));
|
|
|
|
return (cc == greater || cc == greater_equal) ? LESS : GREATER;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
static void CheckInputType(MacroAssembler* masm,
|
|
|
|
Register input,
|
|
|
|
CompareIC::State expected,
|
|
|
|
Label* fail) {
|
|
|
|
Label ok;
|
|
|
|
if (expected == CompareIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(input, fail);
|
2013-02-28 14:43:57 +00:00
|
|
|
} else if (expected == CompareIC::NUMBER) {
|
2012-11-14 15:59:45 +00:00
|
|
|
__ JumpIfSmi(input, &ok);
|
2013-11-08 10:52:07 +00:00
|
|
|
__ CompareMap(input, masm->isolate()->factory()->heap_number_map());
|
2012-11-14 15:59:45 +00:00
|
|
|
__ j(not_equal, fail);
|
|
|
|
}
|
2013-02-28 17:03:34 +00:00
|
|
|
// We could be strict about internalized/non-internalized here, but as long as
|
2012-11-14 15:59:45 +00:00
|
|
|
// hydrogen doesn't care, the stub doesn't have to care either.
|
|
|
|
__ bind(&ok);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
static void BranchIfNotInternalizedString(MacroAssembler* masm,
|
|
|
|
Label* label,
|
|
|
|
Register object,
|
|
|
|
Register scratch) {
|
2012-11-14 15:59:45 +00:00
|
|
|
__ JumpIfSmi(object, label);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, FieldOperand(object, HeapObject::kMapOffset));
|
2012-11-14 15:59:45 +00:00
|
|
|
__ movzxbq(scratch,
|
|
|
|
FieldOperand(scratch, Map::kInstanceTypeOffset));
|
2013-07-19 11:29:11 +00:00
|
|
|
STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
|
|
|
|
__ testb(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
|
|
|
|
__ j(not_zero, label);
|
2012-11-14 15:59:45 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
void ICCompareStub::GenerateGeneric(MacroAssembler* masm) {
|
2010-08-25 09:44:44 +00:00
|
|
|
Label check_unequal_objects, done;
|
2012-11-14 15:59:45 +00:00
|
|
|
Condition cc = GetCondition();
|
2011-04-14 08:01:19 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
2010-09-15 10:14:25 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
Label miss;
|
|
|
|
CheckInputType(masm, rdx, left_, &miss);
|
|
|
|
CheckInputType(masm, rax, right_, &miss);
|
|
|
|
|
|
|
|
// Compare two smis.
|
|
|
|
Label non_smi, smi_done;
|
|
|
|
__ JumpIfNotBothSmi(rax, rdx, &non_smi);
|
|
|
|
__ subq(rdx, rax);
|
|
|
|
__ j(no_overflow, &smi_done);
|
|
|
|
__ not_(rdx); // Correct sign in case of overflow. rdx cannot be 0 here.
|
|
|
|
__ bind(&smi_done);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, rdx);
|
2012-11-14 15:59:45 +00:00
|
|
|
__ ret(0);
|
|
|
|
__ bind(&non_smi);
|
2010-09-15 10:14:25 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// The compare stub returns a positive, negative, or zero 64-bit integer
|
|
|
|
// value in rax, corresponding to result of comparing the two inputs.
|
|
|
|
// NOTICE! This code is only reached after a smi-fast-case check, so
|
|
|
|
// it is certain that at least one operand isn't a smi.
|
|
|
|
|
|
|
|
// Two identical objects are equal unless they are both NaN or undefined.
|
|
|
|
{
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_identical;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmpq(rax, rdx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, ¬_identical, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc != equal) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// Check for undefined. undefined OP undefined is false even though
|
|
|
|
// undefined == undefined.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label check_for_nan;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ CompareRoot(rdx, Heap::kUndefinedValueRootIndex);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &check_for_nan, Label::kNear);
|
2012-11-14 15:59:45 +00:00
|
|
|
__ Set(rax, NegativeComparisonResult(cc));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(0);
|
|
|
|
__ bind(&check_for_nan);
|
|
|
|
}
|
|
|
|
|
2013-06-04 10:30:05 +00:00
|
|
|
// Test for NaN. Sadly, we can't just compare to Factory::nan_value(),
|
2010-08-25 09:44:44 +00:00
|
|
|
// so we do the second best thing - test it ourselves.
|
2012-11-14 15:59:45 +00:00
|
|
|
Label heap_number;
|
|
|
|
// If it's not a heap number, then return equal for (in)equality operator.
|
|
|
|
__ Cmp(FieldOperand(rdx, HeapObject::kMapOffset),
|
|
|
|
factory->heap_number_map());
|
|
|
|
__ j(equal, &heap_number, Label::kNear);
|
|
|
|
if (cc != equal) {
|
|
|
|
// Call runtime on identical objects. Otherwise return equal.
|
|
|
|
__ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
|
|
|
|
__ j(above_equal, ¬_identical, Label::kNear);
|
|
|
|
}
|
|
|
|
__ Set(rax, EQUAL);
|
|
|
|
__ ret(0);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
__ bind(&heap_number);
|
|
|
|
// It is a heap number, so return equal if it's not NaN.
|
|
|
|
// For NaN, return 1 for every condition except greater and
|
|
|
|
// greater-equal. Return -1 for them, so the comparison yields
|
|
|
|
// false for all conditions except not-equal.
|
|
|
|
__ Set(rax, EQUAL);
|
|
|
|
__ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset));
|
|
|
|
__ ucomisd(xmm0, xmm0);
|
|
|
|
__ setcc(parity_even, rax);
|
|
|
|
// rax is 0 for equal non-NaN heapnumbers, 1 for NaNs.
|
|
|
|
if (cc == greater_equal || cc == greater) {
|
|
|
|
__ neg(rax);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
__ ret(0);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(¬_identical);
|
|
|
|
}
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc == equal) { // Both strict and non-strict.
|
2010-08-25 09:44:44 +00:00
|
|
|
Label slow; // Fallthrough label.
|
|
|
|
|
|
|
|
// If we're doing a strict equality comparison, we don't have to do
|
|
|
|
// type conversion, so we generate code to do fast comparison for objects
|
|
|
|
// and oddballs. Non-smi numbers and strings still go through the usual
|
|
|
|
// slow-case code.
|
2012-11-14 15:59:45 +00:00
|
|
|
if (strict()) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// If either is a Smi (we know that not both are), then they can only
|
|
|
|
// be equal if the other is a HeapNumber. If so, use the slow case.
|
|
|
|
{
|
|
|
|
Label not_smis;
|
|
|
|
__ SelectNonSmi(rbx, rax, rdx, ¬_smis);
|
|
|
|
|
|
|
|
// Check if the non-smi operand is a heap number.
|
|
|
|
__ Cmp(FieldOperand(rbx, HeapObject::kMapOffset),
|
2011-04-14 08:01:19 +00:00
|
|
|
factory->heap_number_map());
|
2010-08-25 09:44:44 +00:00
|
|
|
// If heap number, handle it in the slow case.
|
|
|
|
__ j(equal, &slow);
|
|
|
|
// Return non-equal. ebx (the lower half of rbx) is not zero.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, rbx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(¬_smis);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If either operand is a JSObject or an oddball value, then they are not
|
|
|
|
// equal since their pointers are different
|
|
|
|
// There is no test for undetectability in strict equality.
|
|
|
|
|
|
|
|
// If the first object is a JS object, we have done pointer comparison.
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE);
|
2011-05-10 09:03:42 +00:00
|
|
|
Label first_non_object;
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(below, &first_non_object, Label::kNear);
|
2013-07-19 08:21:41 +00:00
|
|
|
// Return non-zero (rax (not rax) is not zero)
|
2010-08-25 09:44:44 +00:00
|
|
|
Label return_not_equal;
|
|
|
|
STATIC_ASSERT(kHeapObjectTag != 0);
|
|
|
|
__ bind(&return_not_equal);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&first_non_object);
|
|
|
|
// Check for oddballs: true, false, null, undefined.
|
|
|
|
__ CmpInstanceType(rcx, ODDBALL_TYPE);
|
|
|
|
__ j(equal, &return_not_equal);
|
|
|
|
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CmpObjectType(rdx, FIRST_SPEC_OBJECT_TYPE, rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above_equal, &return_not_equal);
|
|
|
|
|
|
|
|
// Check for oddballs: true, false, null, undefined.
|
|
|
|
__ CmpInstanceType(rcx, ODDBALL_TYPE);
|
|
|
|
__ j(equal, &return_not_equal);
|
|
|
|
|
|
|
|
// Fall through to the general case.
|
|
|
|
}
|
|
|
|
__ bind(&slow);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the number comparison code.
|
2012-11-14 15:59:45 +00:00
|
|
|
Label non_number_comparison;
|
|
|
|
Label unordered;
|
|
|
|
FloatingPointHelper::LoadSSE2UnknownOperands(masm, &non_number_comparison);
|
|
|
|
__ xorl(rax, rax);
|
|
|
|
__ xorl(rcx, rcx);
|
|
|
|
__ ucomisd(xmm0, xmm1);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
// Don't base result on EFLAGS when a NaN is involved.
|
|
|
|
__ j(parity_even, &unordered, Label::kNear);
|
|
|
|
// Return a result of -1, 0, or 1, based on EFLAGS.
|
|
|
|
__ setcc(above, rax);
|
|
|
|
__ setcc(below, rcx);
|
|
|
|
__ subq(rax, rcx);
|
|
|
|
__ ret(0);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
// If one of the numbers was NaN, then the result is always false.
|
|
|
|
// The cc is never not-equal.
|
|
|
|
__ bind(&unordered);
|
|
|
|
ASSERT(cc != not_equal);
|
|
|
|
if (cc == less || cc == less_equal) {
|
|
|
|
__ Set(rax, 1);
|
|
|
|
} else {
|
|
|
|
__ Set(rax, -1);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2012-11-14 15:59:45 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// The number comparison code did not provide a valid result.
|
|
|
|
__ bind(&non_number_comparison);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Fast negative check for internalized-to-internalized equality.
|
2010-08-25 09:44:44 +00:00
|
|
|
Label check_for_strings;
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc == equal) {
|
2013-02-28 17:03:34 +00:00
|
|
|
BranchIfNotInternalizedString(
|
|
|
|
masm, &check_for_strings, rax, kScratchRegister);
|
|
|
|
BranchIfNotInternalizedString(
|
|
|
|
masm, &check_for_strings, rdx, kScratchRegister);
|
|
|
|
|
|
|
|
// We've already checked for object identity, so if both operands are
|
2013-07-19 08:21:41 +00:00
|
|
|
// internalized strings they aren't equal. Register rax (not rax) already
|
2013-02-28 17:03:34 +00:00
|
|
|
// holds a non-zero value, which indicates not equal, so just return.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&check_for_strings);
|
|
|
|
|
|
|
|
__ JumpIfNotBothSequentialAsciiStrings(
|
|
|
|
rdx, rax, rcx, rbx, &check_unequal_objects);
|
|
|
|
|
2012-01-16 12:38:59 +00:00
|
|
|
// Inline comparison of ASCII strings.
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc == equal) {
|
2011-05-05 11:40:08 +00:00
|
|
|
StringCompareStub::GenerateFlatAsciiStringEquals(masm,
|
2010-08-25 09:44:44 +00:00
|
|
|
rdx,
|
|
|
|
rax,
|
|
|
|
rcx,
|
2011-05-05 11:40:08 +00:00
|
|
|
rbx);
|
|
|
|
} else {
|
|
|
|
StringCompareStub::GenerateCompareFlatAsciiStrings(masm,
|
|
|
|
rdx,
|
|
|
|
rax,
|
|
|
|
rcx,
|
|
|
|
rbx,
|
|
|
|
rdi,
|
|
|
|
r8);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Abort(kUnexpectedFallThroughFromStringComparison);
|
2010-08-25 09:44:44 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
__ bind(&check_unequal_objects);
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc == equal && !strict()) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// Not strict equality. Objects are unequal if
|
|
|
|
// they are both JSObjects and not undetectable,
|
|
|
|
// and their pointers are different.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_both_objects, return_unequal;
|
2010-08-25 09:44:44 +00:00
|
|
|
// At most one is a smi, so we can test for smi by adding the two.
|
|
|
|
// A smi plus a heap object has the low bit set, a heap object plus
|
|
|
|
// a heap object has the low bit clear.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
STATIC_ASSERT(kSmiTagMask == 1);
|
|
|
|
__ lea(rcx, Operand(rax, rdx, times_1, 0));
|
|
|
|
__ testb(rcx, Immediate(kSmiTagMask));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_zero, ¬_both_objects, Label::kNear);
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rbx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(below, ¬_both_objects, Label::kNear);
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CmpObjectType(rdx, FIRST_SPEC_OBJECT_TYPE, rcx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(below, ¬_both_objects, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ testb(FieldOperand(rbx, Map::kBitFieldOffset),
|
|
|
|
Immediate(1 << Map::kIsUndetectable));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &return_unequal, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ testb(FieldOperand(rcx, Map::kBitFieldOffset),
|
|
|
|
Immediate(1 << Map::kIsUndetectable));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &return_unequal, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// The objects are both undetectable, so they both compare as the value
|
|
|
|
// undefined, and are equal.
|
|
|
|
__ Set(rax, EQUAL);
|
|
|
|
__ bind(&return_unequal);
|
2011-02-03 15:36:44 +00:00
|
|
|
// Return non-equal by returning the non-zero object pointer in rax,
|
2010-08-25 09:44:44 +00:00
|
|
|
// or return equal if we fell through to here.
|
|
|
|
__ ret(0);
|
|
|
|
__ bind(¬_both_objects);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push arguments below the return address to prepare jump to builtin.
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PopReturnAddressTo(rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ push(rdx);
|
|
|
|
__ push(rax);
|
|
|
|
|
|
|
|
// Figure out which native to call and setup the arguments.
|
|
|
|
Builtins::JavaScript builtin;
|
2012-11-14 15:59:45 +00:00
|
|
|
if (cc == equal) {
|
|
|
|
builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS;
|
2010-08-25 09:44:44 +00:00
|
|
|
} else {
|
|
|
|
builtin = Builtins::COMPARE;
|
2012-11-14 15:59:45 +00:00
|
|
|
__ Push(Smi::FromInt(NegativeComparisonResult(cc)));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PushReturnAddressFrom(rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Call the native; it returns -1 (less), 0 (equal), or 1 (greater)
|
|
|
|
// tagged as a small integer.
|
|
|
|
__ InvokeBuiltin(builtin, JUMP_FUNCTION);
|
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-01 16:06:34 +00:00
|
|
|
static void GenerateRecordCallTarget(MacroAssembler* masm) {
|
2014-02-10 21:38:17 +00:00
|
|
|
// Cache the called function in a feedback vector slot. Cache states
|
2013-03-01 16:06:34 +00:00
|
|
|
// are uninitialized, monomorphic (indicated by a JSFunction), and
|
|
|
|
// megamorphic.
|
2013-09-20 09:27:40 +00:00
|
|
|
// rax : number of arguments to the construct function
|
2014-02-10 21:38:17 +00:00
|
|
|
// rbx : Feedback vector
|
|
|
|
// rdx : slot in feedback vector (Smi)
|
2013-03-01 16:06:34 +00:00
|
|
|
// rdi : the function to call
|
|
|
|
Isolate* isolate = masm->isolate();
|
2014-02-19 13:55:25 +00:00
|
|
|
Label initialize, done, miss, megamorphic, not_array_function,
|
|
|
|
done_no_smi_convert;
|
2013-03-01 16:06:34 +00:00
|
|
|
|
|
|
|
// Load the cache state into rcx.
|
2014-02-10 21:38:17 +00:00
|
|
|
__ SmiToInteger32(rdx, rdx);
|
|
|
|
__ movp(rcx, FieldOperand(rbx, rdx, times_pointer_size,
|
|
|
|
FixedArray::kHeaderSize));
|
2013-03-01 16:06:34 +00:00
|
|
|
|
|
|
|
// A monomorphic cache hit or an already megamorphic state: invoke the
|
|
|
|
// function without changing the state.
|
|
|
|
__ cmpq(rcx, rdi);
|
|
|
|
__ j(equal, &done);
|
2014-02-10 21:38:17 +00:00
|
|
|
__ Cmp(rcx, TypeFeedbackInfo::MegamorphicSentinel(isolate));
|
2013-03-01 16:06:34 +00:00
|
|
|
__ j(equal, &done);
|
|
|
|
|
2014-02-19 13:55:25 +00:00
|
|
|
// If we came here, we need to see if we are the array function.
|
|
|
|
// If we didn't have a matching function, and we didn't find the megamorph
|
|
|
|
// sentinel, then we have in the slot either some other function or an
|
|
|
|
// AllocationSite. Do a map check on the object in rcx.
|
|
|
|
Handle<Map> allocation_site_map =
|
|
|
|
masm->isolate()->factory()->allocation_site_map();
|
|
|
|
__ Cmp(FieldOperand(rcx, 0), allocation_site_map);
|
|
|
|
__ j(not_equal, &miss);
|
|
|
|
|
|
|
|
// Make sure the function is the Array() function
|
2014-02-28 10:39:36 +00:00
|
|
|
__ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rcx);
|
2013-03-01 16:06:34 +00:00
|
|
|
__ cmpq(rdi, rcx);
|
|
|
|
__ j(not_equal, &megamorphic);
|
2014-02-19 13:55:25 +00:00
|
|
|
__ jmp(&done);
|
2013-03-01 16:06:34 +00:00
|
|
|
|
2014-02-19 13:55:25 +00:00
|
|
|
__ bind(&miss);
|
2014-02-18 15:33:34 +00:00
|
|
|
|
2014-02-19 13:55:25 +00:00
|
|
|
// A monomorphic miss (i.e, here the cache is not uninitialized) goes
|
|
|
|
// megamorphic.
|
2014-02-10 21:38:17 +00:00
|
|
|
__ Cmp(rcx, TypeFeedbackInfo::UninitializedSentinel(isolate));
|
2014-02-19 13:55:25 +00:00
|
|
|
__ j(equal, &initialize);
|
|
|
|
// MegamorphicSentinel is an immortal immovable object (undefined) so no
|
|
|
|
// write-barrier is needed.
|
2013-03-01 16:06:34 +00:00
|
|
|
__ bind(&megamorphic);
|
2014-02-10 21:38:17 +00:00
|
|
|
__ Move(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize),
|
|
|
|
TypeFeedbackInfo::MegamorphicSentinel(isolate));
|
2013-07-08 10:02:16 +00:00
|
|
|
__ jmp(&done);
|
2013-03-01 16:06:34 +00:00
|
|
|
|
2014-02-19 13:55:25 +00:00
|
|
|
// An uninitialized cache is patched with the function or sentinel to
|
|
|
|
// indicate the ElementsKind if function is the Array constructor.
|
|
|
|
__ bind(&initialize);
|
|
|
|
// Make sure the function is the Array() function
|
2014-02-28 10:39:36 +00:00
|
|
|
__ LoadGlobalFunction(Context::ARRAY_FUNCTION_INDEX, rcx);
|
2014-02-19 13:55:25 +00:00
|
|
|
__ cmpq(rdi, rcx);
|
|
|
|
__ j(not_equal, ¬_array_function);
|
|
|
|
|
|
|
|
// The target function is the Array constructor,
|
|
|
|
// Create an AllocationSite if we don't already have it, store it in the slot.
|
2013-07-08 10:02:16 +00:00
|
|
|
{
|
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
|
2013-09-20 09:27:40 +00:00
|
|
|
// Arguments register must be smi-tagged to call out.
|
2013-08-27 13:31:15 +00:00
|
|
|
__ Integer32ToSmi(rax, rax);
|
2013-07-08 10:02:16 +00:00
|
|
|
__ push(rax);
|
|
|
|
__ push(rdi);
|
2014-02-10 21:38:17 +00:00
|
|
|
__ Integer32ToSmi(rdx, rdx);
|
|
|
|
__ push(rdx);
|
2013-07-08 10:02:16 +00:00
|
|
|
__ push(rbx);
|
|
|
|
|
|
|
|
CreateAllocationSiteStub create_stub;
|
|
|
|
__ CallStub(&create_stub);
|
|
|
|
|
|
|
|
__ pop(rbx);
|
2014-02-10 21:38:17 +00:00
|
|
|
__ pop(rdx);
|
2013-07-08 10:02:16 +00:00
|
|
|
__ pop(rdi);
|
|
|
|
__ pop(rax);
|
2013-08-27 13:31:15 +00:00
|
|
|
__ SmiToInteger32(rax, rax);
|
2013-07-08 10:02:16 +00:00
|
|
|
}
|
2014-02-10 21:38:17 +00:00
|
|
|
__ jmp(&done_no_smi_convert);
|
2013-03-01 16:06:34 +00:00
|
|
|
|
2014-02-19 13:55:25 +00:00
|
|
|
__ bind(¬_array_function);
|
2014-02-10 21:38:17 +00:00
|
|
|
__ movp(FieldOperand(rbx, rdx, times_pointer_size, FixedArray::kHeaderSize),
|
|
|
|
rdi);
|
2014-02-19 13:55:25 +00:00
|
|
|
|
|
|
|
// We won't need rdx or rbx anymore, just save rdi
|
2014-02-10 21:38:17 +00:00
|
|
|
__ push(rdi);
|
|
|
|
__ push(rbx);
|
|
|
|
__ push(rdx);
|
|
|
|
__ RecordWriteArray(rbx, rdi, rdx, kDontSaveFPRegs,
|
|
|
|
EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
|
|
|
|
__ pop(rdx);
|
|
|
|
__ pop(rbx);
|
|
|
|
__ pop(rdi);
|
2013-03-01 16:06:34 +00:00
|
|
|
|
|
|
|
__ bind(&done);
|
2014-02-10 21:38:17 +00:00
|
|
|
__ Integer32ToSmi(rdx, rdx);
|
|
|
|
|
|
|
|
__ bind(&done_no_smi_convert);
|
2013-03-01 16:06:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void CallFunctionStub::Generate(MacroAssembler* masm) {
|
2014-02-10 21:38:17 +00:00
|
|
|
// rbx : feedback vector
|
2014-03-07 09:10:18 +00:00
|
|
|
// rdx : (only if rbx is not the megamorphic symbol) slot in feedback
|
|
|
|
// vector (Smi)
|
2012-04-19 14:17:12 +00:00
|
|
|
// rdi : the function to call
|
|
|
|
Isolate* isolate = masm->isolate();
|
2014-01-31 16:52:17 +00:00
|
|
|
Label slow, non_function, wrap, cont;
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, argc_);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2014-01-31 16:52:17 +00:00
|
|
|
if (NeedsChecks()) {
|
|
|
|
// Check that the function really is a JavaScript function.
|
|
|
|
__ JumpIfSmi(rdi, &non_function);
|
2014-01-07 10:46:39 +00:00
|
|
|
|
2014-01-31 16:52:17 +00:00
|
|
|
// Goto slow case if we do not have a function.
|
|
|
|
__ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
|
|
|
|
__ j(not_equal, &slow);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2014-01-31 16:52:17 +00:00
|
|
|
if (RecordCallTarget()) {
|
|
|
|
GenerateRecordCallTarget(masm);
|
|
|
|
}
|
2012-04-19 14:17:12 +00:00
|
|
|
}
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Fast-case: Just invoke the function.
|
|
|
|
ParameterCount actual(argc_);
|
2011-05-24 14:01:36 +00:00
|
|
|
|
2014-01-31 16:52:17 +00:00
|
|
|
if (CallAsMethod()) {
|
|
|
|
if (NeedsChecks()) {
|
|
|
|
// Do not transform the receiver for strict mode functions.
|
|
|
|
__ movp(rcx, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
|
|
|
|
__ testb(FieldOperand(rcx, SharedFunctionInfo::kStrictModeByteOffset),
|
|
|
|
Immediate(1 << SharedFunctionInfo::kStrictModeBitWithinByte));
|
|
|
|
__ j(not_equal, &cont);
|
|
|
|
|
|
|
|
// Do not transform the receiver for natives.
|
|
|
|
// SharedFunctionInfo is already loaded into rcx.
|
|
|
|
__ testb(FieldOperand(rcx, SharedFunctionInfo::kNativeByteOffset),
|
|
|
|
Immediate(1 << SharedFunctionInfo::kNativeBitWithinByte));
|
|
|
|
__ j(not_equal, &cont);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2014-02-10 21:38:17 +00:00
|
|
|
|
2014-01-31 16:52:17 +00:00
|
|
|
// Load the receiver from the stack.
|
2014-02-07 02:21:18 +00:00
|
|
|
__ movp(rax, args.GetReceiverOperand());
|
2014-01-31 16:52:17 +00:00
|
|
|
|
|
|
|
if (NeedsChecks()) {
|
|
|
|
__ JumpIfSmi(rax, &wrap);
|
|
|
|
|
|
|
|
__ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rcx);
|
|
|
|
__ j(below, &wrap);
|
|
|
|
} else {
|
|
|
|
__ jmp(&wrap);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&cont);
|
2012-04-19 14:17:12 +00:00
|
|
|
}
|
2014-01-31 16:52:17 +00:00
|
|
|
__ InvokeFunction(rdi, actual, JUMP_FUNCTION, NullCallWrapper());
|
|
|
|
|
|
|
|
if (NeedsChecks()) {
|
|
|
|
// Slow-case: Non-function called.
|
|
|
|
__ bind(&slow);
|
|
|
|
if (RecordCallTarget()) {
|
|
|
|
// If there is a call target cache, mark it megamorphic in the
|
|
|
|
// non-function case. MegamorphicSentinel is an immortal immovable
|
2014-03-07 09:10:18 +00:00
|
|
|
// object (megamorphic symbol) so no write barrier is needed.
|
2014-02-10 21:38:17 +00:00
|
|
|
__ SmiToInteger32(rdx, rdx);
|
|
|
|
__ Move(FieldOperand(rbx, rdx, times_pointer_size,
|
|
|
|
FixedArray::kHeaderSize),
|
|
|
|
TypeFeedbackInfo::MegamorphicSentinel(isolate));
|
|
|
|
__ Integer32ToSmi(rdx, rdx);
|
2014-01-31 16:52:17 +00:00
|
|
|
}
|
|
|
|
// Check for function proxy.
|
|
|
|
__ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE);
|
|
|
|
__ j(not_equal, &non_function);
|
|
|
|
__ PopReturnAddressTo(rcx);
|
|
|
|
__ push(rdi); // put proxy as additional argument under return address
|
|
|
|
__ PushReturnAddressFrom(rcx);
|
|
|
|
__ Set(rax, argc_ + 1);
|
|
|
|
__ Set(rbx, 0);
|
|
|
|
__ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY);
|
|
|
|
{
|
|
|
|
Handle<Code> adaptor =
|
|
|
|
masm->isolate()->builtins()->ArgumentsAdaptorTrampoline();
|
|
|
|
__ jmp(adaptor, RelocInfo::CODE_TARGET);
|
|
|
|
}
|
|
|
|
|
|
|
|
// CALL_NON_FUNCTION expects the non-function callee as receiver (instead
|
|
|
|
// of the original receiver from the call site).
|
|
|
|
__ bind(&non_function);
|
|
|
|
__ movp(args.GetReceiverOperand(), rdi);
|
|
|
|
__ Set(rax, argc_);
|
|
|
|
__ Set(rbx, 0);
|
|
|
|
__ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION);
|
2011-09-13 11:42:57 +00:00
|
|
|
Handle<Code> adaptor =
|
2014-01-31 16:52:17 +00:00
|
|
|
isolate->builtins()->ArgumentsAdaptorTrampoline();
|
|
|
|
__ Jump(adaptor, RelocInfo::CODE_TARGET);
|
2011-09-13 11:42:57 +00:00
|
|
|
}
|
|
|
|
|
2014-01-31 16:52:17 +00:00
|
|
|
if (CallAsMethod()) {
|
|
|
|
__ bind(&wrap);
|
|
|
|
// Wrap the receiver and patch it back onto the stack.
|
|
|
|
{ FrameScope frame_scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ push(rdi);
|
|
|
|
__ push(rax);
|
|
|
|
__ InvokeBuiltin(Builtins::TO_OBJECT, CALL_FUNCTION);
|
|
|
|
__ pop(rdi);
|
|
|
|
}
|
2014-02-07 02:21:18 +00:00
|
|
|
__ movp(args.GetReceiverOperand(), rax);
|
2014-01-31 16:52:17 +00:00
|
|
|
__ jmp(&cont);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-27 13:03:19 +00:00
|
|
|
void CallConstructStub::Generate(MacroAssembler* masm) {
|
|
|
|
// rax : number of arguments
|
2014-02-10 21:38:17 +00:00
|
|
|
// rbx : feedback vector
|
2014-03-07 09:10:18 +00:00
|
|
|
// rdx : (only if rbx is not the megamorphic symbol) slot in feedback
|
|
|
|
// vector (Smi)
|
2012-01-27 13:03:19 +00:00
|
|
|
// rdi : constructor function
|
|
|
|
Label slow, non_function_call;
|
|
|
|
|
|
|
|
// Check that function is not a smi.
|
|
|
|
__ JumpIfSmi(rdi, &non_function_call);
|
|
|
|
// Check that function is a JSFunction.
|
|
|
|
__ CmpObjectType(rdi, JS_FUNCTION_TYPE, rcx);
|
|
|
|
__ j(not_equal, &slow);
|
|
|
|
|
|
|
|
if (RecordCallTarget()) {
|
2013-06-25 16:31:07 +00:00
|
|
|
GenerateRecordCallTarget(masm);
|
2012-01-27 13:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Jump to the function-specific construct stub.
|
2013-06-25 16:31:07 +00:00
|
|
|
Register jmp_reg = rcx;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(jmp_reg, FieldOperand(rdi, JSFunction::kSharedFunctionInfoOffset));
|
|
|
|
__ movp(jmp_reg, FieldOperand(jmp_reg,
|
2013-03-01 16:06:34 +00:00
|
|
|
SharedFunctionInfo::kConstructStubOffset));
|
|
|
|
__ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize));
|
|
|
|
__ jmp(jmp_reg);
|
2012-01-27 13:03:19 +00:00
|
|
|
|
|
|
|
// rdi: called object
|
|
|
|
// rax: number of arguments
|
|
|
|
// rcx: object map
|
|
|
|
Label do_call;
|
|
|
|
__ bind(&slow);
|
|
|
|
__ CmpInstanceType(rcx, JS_FUNCTION_PROXY_TYPE);
|
|
|
|
__ j(not_equal, &non_function_call);
|
|
|
|
__ GetBuiltinEntry(rdx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR);
|
|
|
|
__ jmp(&do_call);
|
|
|
|
|
|
|
|
__ bind(&non_function_call);
|
|
|
|
__ GetBuiltinEntry(rdx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR);
|
|
|
|
__ bind(&do_call);
|
|
|
|
// Set expected number of arguments to zero (not changing rax).
|
|
|
|
__ Set(rbx, 0);
|
|
|
|
__ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(),
|
|
|
|
RelocInfo::CODE_TARGET);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-09 10:38:19 +00:00
|
|
|
bool CEntryStub::NeedsImmovableCode() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) {
|
|
|
|
CEntryStub::GenerateAheadOfTime(isolate);
|
|
|
|
StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate);
|
2013-04-04 17:55:43 +00:00
|
|
|
StubFailureTrampolineStub::GenerateAheadOfTime(isolate);
|
2011-09-19 18:36:47 +00:00
|
|
|
// It is important that the store buffer overflow stubs are generated first.
|
2013-06-25 16:31:07 +00:00
|
|
|
ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate);
|
2013-07-08 10:02:16 +00:00
|
|
|
CreateAllocationSiteStub::GenerateAheadOfTime(isolate);
|
2013-12-02 13:14:07 +00:00
|
|
|
BinaryOpICStub::GenerateAheadOfTime(isolate);
|
2014-01-02 15:31:27 +00:00
|
|
|
BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate);
|
2011-09-16 11:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void CodeStub::GenerateFPStubs(Isolate* isolate) {
|
2011-09-16 13:06:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void CEntryStub::GenerateAheadOfTime(Isolate* isolate) {
|
2011-09-28 12:23:40 +00:00
|
|
|
CEntryStub stub(1, kDontSaveFPRegs);
|
2013-12-02 09:46:35 +00:00
|
|
|
stub.GetCode(isolate);
|
2011-09-28 12:23:40 +00:00
|
|
|
CEntryStub save_doubles(1, kSaveFPRegs);
|
2013-12-02 09:46:35 +00:00
|
|
|
save_doubles.GetCode(isolate);
|
2011-09-28 12:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-01-09 12:29:06 +00:00
|
|
|
static void JumpIfOOM(MacroAssembler* masm,
|
|
|
|
Register value,
|
|
|
|
Register scratch,
|
|
|
|
Label* oom_label) {
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, value);
|
2013-01-09 12:29:06 +00:00
|
|
|
STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3);
|
|
|
|
STATIC_ASSERT(kFailureTag == 3);
|
|
|
|
__ and_(scratch, Immediate(0xf));
|
|
|
|
__ cmpq(scratch, Immediate(0xf));
|
|
|
|
__ j(equal, oom_label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void CEntryStub::GenerateCore(MacroAssembler* masm,
|
|
|
|
Label* throw_normal_exception,
|
|
|
|
Label* throw_termination_exception,
|
|
|
|
Label* throw_out_of_memory_exception,
|
|
|
|
bool do_gc,
|
2011-01-25 07:49:39 +00:00
|
|
|
bool always_allocate_scope) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// rax: result parameter for PerformGC, if any.
|
|
|
|
// rbx: pointer to C function (C callee-saved).
|
|
|
|
// rbp: frame pointer (restored after C call).
|
|
|
|
// rsp: stack pointer (restored after C call).
|
|
|
|
// r14: number of arguments including receiver (C callee-saved).
|
2011-03-10 10:14:24 +00:00
|
|
|
// r15: pointer to the first argument (C callee-saved).
|
2010-08-25 09:44:44 +00:00
|
|
|
// This pointer is reused in LeaveExitFrame(), so it is stored in a
|
|
|
|
// callee-saved register.
|
|
|
|
|
|
|
|
// Simple results returned in rax (both AMD64 and Win64 calling conventions).
|
|
|
|
// Complex results must be written to address passed as first argument.
|
|
|
|
// AMD64 calling convention: a struct of two pointers in rax+rdx
|
|
|
|
|
|
|
|
// Check stack alignment.
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ CheckStackAlignment();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (do_gc) {
|
|
|
|
// Pass failure code returned from last attempt as first argument to
|
|
|
|
// PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the
|
|
|
|
// stack is known to be aligned. This function takes one argument which is
|
|
|
|
// passed in register.
|
2013-11-07 02:08:53 +00:00
|
|
|
__ Move(arg_reg_2, ExternalReference::isolate_address(masm->isolate()));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(arg_reg_1, rax);
|
2013-11-07 02:08:53 +00:00
|
|
|
__ Move(kScratchRegister,
|
2012-12-28 14:36:55 +00:00
|
|
|
ExternalReference::perform_gc_function(masm->isolate()));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ call(kScratchRegister);
|
|
|
|
}
|
|
|
|
|
|
|
|
ExternalReference scope_depth =
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference::heap_always_allocate_scope_depth(masm->isolate());
|
2010-08-25 09:44:44 +00:00
|
|
|
if (always_allocate_scope) {
|
2011-03-23 09:05:13 +00:00
|
|
|
Operand scope_depth_operand = masm->ExternalOperand(scope_depth);
|
|
|
|
__ incl(scope_depth_operand);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Call C function.
|
|
|
|
#ifdef _WIN64
|
2013-04-30 11:34:43 +00:00
|
|
|
// Windows 64-bit ABI passes arguments in rcx, rdx, r8, r9.
|
|
|
|
// Pass argv and argc as two parameters. The arguments object will
|
|
|
|
// be created by stubs declared by DECLARE_RUNTIME_FUNCTION().
|
2010-08-25 09:44:44 +00:00
|
|
|
if (result_size_ < 2) {
|
|
|
|
// Pass a pointer to the Arguments object as the first argument.
|
|
|
|
// Return result in single register (rax).
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, r14); // argc.
|
|
|
|
__ movp(rdx, r15); // argv.
|
2013-11-07 07:17:57 +00:00
|
|
|
__ Move(r8, ExternalReference::isolate_address(masm->isolate()));
|
2010-08-25 09:44:44 +00:00
|
|
|
} else {
|
|
|
|
ASSERT_EQ(2, result_size_);
|
|
|
|
// Pass a pointer to the result location as the first argument.
|
2010-11-16 16:08:57 +00:00
|
|
|
__ lea(rcx, StackSpaceOperand(2));
|
2010-08-25 09:44:44 +00:00
|
|
|
// Pass a pointer to the Arguments object as the second argument.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, r14); // argc.
|
|
|
|
__ movp(r8, r15); // argv.
|
2013-11-07 07:17:57 +00:00
|
|
|
__ Move(r9, ExternalReference::isolate_address(masm->isolate()));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#else // _WIN64
|
|
|
|
// GCC passes arguments in rdi, rsi, rdx, rcx, r8, r9.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, r14); // argc.
|
|
|
|
__ movp(rsi, r15); // argv.
|
2013-11-07 02:08:53 +00:00
|
|
|
__ Move(rdx, ExternalReference::isolate_address(masm->isolate()));
|
2010-08-25 09:44:44 +00:00
|
|
|
#endif
|
|
|
|
__ call(rbx);
|
|
|
|
// Result is in rax - do not destroy this register!
|
|
|
|
|
|
|
|
if (always_allocate_scope) {
|
2011-03-23 09:05:13 +00:00
|
|
|
Operand scope_depth_operand = masm->ExternalOperand(scope_depth);
|
|
|
|
__ decl(scope_depth_operand);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check for failure result.
|
|
|
|
Label failure_returned;
|
|
|
|
STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0);
|
|
|
|
#ifdef _WIN64
|
|
|
|
// If return value is on the stack, pop it to registers.
|
|
|
|
if (result_size_ > 1) {
|
|
|
|
ASSERT_EQ(2, result_size_);
|
|
|
|
// Read result values stored on stack. Result is stored
|
|
|
|
// above the four argument mirror slots and the two
|
|
|
|
// Arguments object slots.
|
2014-01-20 01:52:21 +00:00
|
|
|
__ movq(rax, Operand(rsp, 6 * kRegisterSize));
|
|
|
|
__ movq(rdx, Operand(rsp, 7 * kRegisterSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
__ lea(rcx, Operand(rax, 1));
|
|
|
|
// Lower 2 bits of rcx are 0 iff rax has failure tag.
|
|
|
|
__ testl(rcx, Immediate(kFailureTagMask));
|
|
|
|
__ j(zero, &failure_returned);
|
|
|
|
|
|
|
|
// Exit the JavaScript to C++ exit frame.
|
2011-01-25 11:30:47 +00:00
|
|
|
__ LeaveExitFrame(save_doubles_);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Handling of failure.
|
|
|
|
__ bind(&failure_returned);
|
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
Label retry;
|
2010-08-25 09:44:44 +00:00
|
|
|
// If the returned exception is RETRY_AFTER_GC continue at retry label
|
|
|
|
STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0);
|
|
|
|
__ testl(rax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &retry, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Special handling of out of memory exceptions.
|
2013-01-09 12:29:06 +00:00
|
|
|
JumpIfOOM(masm, rax, kScratchRegister, throw_out_of_memory_exception);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-04-16 12:16:55 +00:00
|
|
|
// Retrieve the pending exception.
|
2011-03-18 20:35:07 +00:00
|
|
|
ExternalReference pending_exception_address(
|
2011-09-08 16:29:57 +00:00
|
|
|
Isolate::kPendingExceptionAddress, masm->isolate());
|
2011-03-23 09:05:13 +00:00
|
|
|
Operand pending_exception_operand =
|
|
|
|
masm->ExternalOperand(pending_exception_address);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, pending_exception_operand);
|
2013-04-16 12:16:55 +00:00
|
|
|
|
|
|
|
// See if we just retrieved an OOM exception.
|
|
|
|
JumpIfOOM(masm, rax, kScratchRegister, throw_out_of_memory_exception);
|
|
|
|
|
|
|
|
// Clear the pending exception.
|
|
|
|
pending_exception_operand =
|
|
|
|
masm->ExternalOperand(pending_exception_address);
|
2011-03-23 09:05:13 +00:00
|
|
|
__ LoadRoot(rdx, Heap::kTheHoleValueRootIndex);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(pending_exception_operand, rdx);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Special handling of termination exceptions which are uncatchable
|
|
|
|
// by javascript code.
|
|
|
|
__ CompareRoot(rax, Heap::kTerminationExceptionRootIndex);
|
|
|
|
__ j(equal, throw_termination_exception);
|
|
|
|
|
|
|
|
// Handle normal exception.
|
|
|
|
__ jmp(throw_normal_exception);
|
|
|
|
|
|
|
|
// Retry.
|
|
|
|
__ bind(&retry);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CEntryStub::Generate(MacroAssembler* masm) {
|
|
|
|
// rax: number of arguments including receiver
|
|
|
|
// rbx: pointer to C function (C callee-saved)
|
|
|
|
// rbp: frame pointer of calling JS frame (restored after C call)
|
|
|
|
// rsp: stack pointer (restored after C call)
|
|
|
|
// rsi: current context (restored)
|
|
|
|
|
|
|
|
// NOTE: Invocations of builtins may return failure objects
|
|
|
|
// instead of a proper result. The builtin entry handles
|
|
|
|
// this by performing a garbage collection and retrying the
|
|
|
|
// builtin once.
|
|
|
|
|
2013-06-28 13:40:41 +00:00
|
|
|
ProfileEntryHookStub::MaybeCallEntryHook(masm);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Enter the exit frame that transitions from JavaScript to C++.
|
2010-11-16 16:08:57 +00:00
|
|
|
#ifdef _WIN64
|
|
|
|
int arg_stack_space = (result_size_ < 2 ? 2 : 4);
|
|
|
|
#else
|
|
|
|
int arg_stack_space = 0;
|
|
|
|
#endif
|
2011-01-25 11:30:47 +00:00
|
|
|
__ EnterExitFrame(arg_stack_space, save_doubles_);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// rax: Holds the context at this point, but should not be used.
|
|
|
|
// On entry to code generated by GenerateCore, it must hold
|
|
|
|
// a failure result if the collect_garbage argument to GenerateCore
|
|
|
|
// is true. This failure result can be the result of code
|
|
|
|
// generated by a previous call to GenerateCore. The value
|
|
|
|
// of rax is then passed to Runtime::PerformGC.
|
|
|
|
// rbx: pointer to builtin function (C callee-saved).
|
|
|
|
// rbp: frame pointer of exit frame (restored after C call).
|
|
|
|
// rsp: stack pointer (restored after C call).
|
|
|
|
// r14: number of arguments including receiver (C callee-saved).
|
2011-03-10 10:14:24 +00:00
|
|
|
// r15: argv pointer (C callee-saved).
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
Label throw_normal_exception;
|
|
|
|
Label throw_termination_exception;
|
|
|
|
Label throw_out_of_memory_exception;
|
|
|
|
|
|
|
|
// Call into the runtime system.
|
|
|
|
GenerateCore(masm,
|
|
|
|
&throw_normal_exception,
|
|
|
|
&throw_termination_exception,
|
|
|
|
&throw_out_of_memory_exception,
|
|
|
|
false,
|
|
|
|
false);
|
|
|
|
|
|
|
|
// Do space-specific GC and retry runtime call.
|
|
|
|
GenerateCore(masm,
|
|
|
|
&throw_normal_exception,
|
|
|
|
&throw_termination_exception,
|
|
|
|
&throw_out_of_memory_exception,
|
|
|
|
true,
|
|
|
|
false);
|
|
|
|
|
|
|
|
// Do full GC and retry runtime call one final time.
|
|
|
|
Failure* failure = Failure::InternalError();
|
2014-01-24 01:45:53 +00:00
|
|
|
__ Move(rax, failure, Assembler::RelocInfoNone());
|
2010-08-25 09:44:44 +00:00
|
|
|
GenerateCore(masm,
|
|
|
|
&throw_normal_exception,
|
|
|
|
&throw_termination_exception,
|
|
|
|
&throw_out_of_memory_exception,
|
|
|
|
true,
|
|
|
|
true);
|
|
|
|
|
|
|
|
__ bind(&throw_out_of_memory_exception);
|
2012-02-10 08:47:35 +00:00
|
|
|
// Set external caught exception to false.
|
|
|
|
Isolate* isolate = masm->isolate();
|
|
|
|
ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress,
|
|
|
|
isolate);
|
|
|
|
__ Set(rax, static_cast<int64_t>(false));
|
|
|
|
__ Store(external_caught, rax);
|
|
|
|
|
|
|
|
// Set pending exception and rax to out of memory exception.
|
|
|
|
ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
|
|
|
|
isolate);
|
2013-01-09 12:29:06 +00:00
|
|
|
Label already_have_failure;
|
|
|
|
JumpIfOOM(masm, rax, kScratchRegister, &already_have_failure);
|
2014-01-24 01:45:53 +00:00
|
|
|
__ Move(rax, Failure::OutOfMemoryException(0x1), Assembler::RelocInfoNone());
|
2013-01-09 12:29:06 +00:00
|
|
|
__ bind(&already_have_failure);
|
2012-02-10 08:47:35 +00:00
|
|
|
__ Store(pending_exception, rax);
|
|
|
|
// Fall through to the next label.
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&throw_termination_exception);
|
2012-02-10 08:47:35 +00:00
|
|
|
__ ThrowUncatchable(rax);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&throw_normal_exception);
|
2012-02-10 08:47:35 +00:00
|
|
|
__ Throw(rax);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) {
|
2011-11-11 13:48:14 +00:00
|
|
|
Label invoke, handler_entry, exit;
|
2010-08-25 09:44:44 +00:00
|
|
|
Label not_outermost_js, not_outermost_js_2;
|
2013-04-17 09:54:17 +00:00
|
|
|
|
2013-06-28 13:40:41 +00:00
|
|
|
ProfileEntryHookStub::MaybeCallEntryHook(masm);
|
|
|
|
|
2011-03-23 09:05:13 +00:00
|
|
|
{ // NOLINT. Scope block confuses linter.
|
|
|
|
MacroAssembler::NoRootArrayScope uninitialized_root_register(masm);
|
2012-01-13 13:09:52 +00:00
|
|
|
// Set up frame.
|
2011-03-23 09:05:13 +00:00
|
|
|
__ push(rbp);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbp, rsp);
|
2011-03-23 09:05:13 +00:00
|
|
|
|
|
|
|
// Push the stack frame type marker twice.
|
|
|
|
int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY;
|
|
|
|
// Scratch register is neither callee-save, nor an argument register on any
|
|
|
|
// platform. It's free to use at this point.
|
|
|
|
// Cannot use smi-register for loading yet.
|
2014-01-24 01:45:53 +00:00
|
|
|
__ Move(kScratchRegister, Smi::FromInt(marker), Assembler::RelocInfoNone());
|
2011-03-23 09:05:13 +00:00
|
|
|
__ push(kScratchRegister); // context slot
|
|
|
|
__ push(kScratchRegister); // function slot
|
|
|
|
// Save callee-saved registers (X64/Win64 calling conventions).
|
|
|
|
__ push(r12);
|
|
|
|
__ push(r13);
|
|
|
|
__ push(r14);
|
|
|
|
__ push(r15);
|
2010-08-25 09:44:44 +00:00
|
|
|
#ifdef _WIN64
|
2011-03-23 09:05:13 +00:00
|
|
|
__ push(rdi); // Only callee save in Win64 ABI, argument in AMD64 ABI.
|
|
|
|
__ push(rsi); // Only callee save in Win64 ABI, argument in AMD64 ABI.
|
2010-08-25 09:44:44 +00:00
|
|
|
#endif
|
2011-03-23 09:05:13 +00:00
|
|
|
__ push(rbx);
|
2013-04-17 09:54:17 +00:00
|
|
|
|
|
|
|
#ifdef _WIN64
|
|
|
|
// On Win64 XMM6-XMM15 are callee-save
|
2013-04-17 15:36:04 +00:00
|
|
|
__ subq(rsp, Immediate(EntryFrameConstants::kXMMRegistersBlockSize));
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 0), xmm6);
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 1), xmm7);
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 2), xmm8);
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 3), xmm9);
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 4), xmm10);
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 5), xmm11);
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 6), xmm12);
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 7), xmm13);
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 8), xmm14);
|
|
|
|
__ movdqu(Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 9), xmm15);
|
2013-04-17 09:54:17 +00:00
|
|
|
#endif
|
2011-03-23 09:05:13 +00:00
|
|
|
|
|
|
|
// Set up the roots and smi constant registers.
|
|
|
|
// Needs to be done before any further smi loads.
|
|
|
|
__ InitializeSmiConstantRegister();
|
|
|
|
__ InitializeRootRegister();
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
Isolate* isolate = masm->isolate();
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Save copies of the top frame descriptor on the stack.
|
2011-09-08 16:29:57 +00:00
|
|
|
ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, isolate);
|
2011-03-23 09:05:13 +00:00
|
|
|
{
|
|
|
|
Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp);
|
|
|
|
__ push(c_entry_fp_operand);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If this is the outermost JS call, set js_entry_sp value.
|
2011-09-08 16:29:57 +00:00
|
|
|
ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, isolate);
|
2011-03-23 09:05:13 +00:00
|
|
|
__ Load(rax, js_entry_sp);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ testq(rax, rax);
|
|
|
|
__ j(not_zero, ¬_outermost_js);
|
2011-05-17 11:11:12 +00:00
|
|
|
__ Push(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, rbp);
|
2011-03-23 09:05:13 +00:00
|
|
|
__ Store(js_entry_sp, rax);
|
2011-05-17 11:11:12 +00:00
|
|
|
Label cont;
|
|
|
|
__ jmp(&cont);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(¬_outermost_js);
|
2011-05-17 11:11:12 +00:00
|
|
|
__ Push(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME));
|
|
|
|
__ bind(&cont);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
// Jump to a faked try block that does the invoke, with a faked catch
|
|
|
|
// block that sets the pending exception.
|
|
|
|
__ jmp(&invoke);
|
|
|
|
__ bind(&handler_entry);
|
|
|
|
handler_offset_ = handler_entry.pos();
|
|
|
|
// Caught exception: Store result (exception) in the pending exception
|
|
|
|
// field in the JSEnv and return a failure sentinel.
|
2011-09-08 16:29:57 +00:00
|
|
|
ExternalReference pending_exception(Isolate::kPendingExceptionAddress,
|
2011-03-22 13:20:04 +00:00
|
|
|
isolate);
|
2011-03-23 09:05:13 +00:00
|
|
|
__ Store(pending_exception, rax);
|
2014-01-24 01:45:53 +00:00
|
|
|
__ Move(rax, Failure::Exception(), Assembler::RelocInfoNone());
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(&exit);
|
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
// Invoke: Link this frame into the handler chain. There's only one
|
|
|
|
// handler block in this code object, so its index is 0.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&invoke);
|
2012-02-09 09:43:37 +00:00
|
|
|
__ PushTryHandler(StackHandler::JS_ENTRY, 0);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Clear any pending exceptions.
|
2011-03-23 09:05:13 +00:00
|
|
|
__ LoadRoot(rax, Heap::kTheHoleValueRootIndex);
|
|
|
|
__ Store(pending_exception, rax);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Fake a receiver (NULL).
|
|
|
|
__ push(Immediate(0)); // receiver
|
|
|
|
|
2011-11-11 13:48:14 +00:00
|
|
|
// Invoke the function by calling through JS entry trampoline builtin and
|
|
|
|
// pop the faked function when we return. We load the address from an
|
|
|
|
// external reference instead of inlining the call target address directly
|
|
|
|
// in the code, because the builtin stubs may not have been generated yet
|
|
|
|
// at the time this code is generated.
|
2010-08-25 09:44:44 +00:00
|
|
|
if (is_construct) {
|
2011-03-23 13:40:07 +00:00
|
|
|
ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline,
|
2011-03-22 13:20:04 +00:00
|
|
|
isolate);
|
2011-03-23 09:05:13 +00:00
|
|
|
__ Load(rax, construct_entry);
|
2010-08-25 09:44:44 +00:00
|
|
|
} else {
|
2011-03-23 13:40:07 +00:00
|
|
|
ExternalReference entry(Builtins::kJSEntryTrampoline, isolate);
|
2011-03-23 09:05:13 +00:00
|
|
|
__ Load(rax, entry);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
__ lea(kScratchRegister, FieldOperand(rax, Code::kHeaderSize));
|
|
|
|
__ call(kScratchRegister);
|
|
|
|
|
|
|
|
// Unlink this frame from the handler chain.
|
2011-05-17 11:11:12 +00:00
|
|
|
__ PopTryHandler();
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-05-17 11:11:12 +00:00
|
|
|
__ bind(&exit);
|
|
|
|
// Check if the current stack frame is marked as the outermost JS frame.
|
|
|
|
__ pop(rbx);
|
|
|
|
__ Cmp(rbx, Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(not_equal, ¬_outermost_js_2);
|
2013-11-07 02:08:53 +00:00
|
|
|
__ Move(kScratchRegister, js_entry_sp);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(Operand(kScratchRegister, 0), Immediate(0));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(¬_outermost_js_2);
|
|
|
|
|
|
|
|
// Restore the top frame descriptor from the stack.
|
2011-05-17 11:24:38 +00:00
|
|
|
{ Operand c_entry_fp_operand = masm->ExternalOperand(c_entry_fp);
|
2011-03-23 09:05:13 +00:00
|
|
|
__ pop(c_entry_fp_operand);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Restore callee-saved registers (X64 conventions).
|
2013-04-17 09:54:17 +00:00
|
|
|
#ifdef _WIN64
|
|
|
|
// On Win64 XMM6-XMM15 are callee-save
|
2013-04-17 15:36:04 +00:00
|
|
|
__ movdqu(xmm6, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 0));
|
|
|
|
__ movdqu(xmm7, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 1));
|
|
|
|
__ movdqu(xmm8, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 2));
|
2013-04-17 16:41:02 +00:00
|
|
|
__ movdqu(xmm9, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 3));
|
2013-04-17 15:36:04 +00:00
|
|
|
__ movdqu(xmm10, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 4));
|
|
|
|
__ movdqu(xmm11, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 5));
|
|
|
|
__ movdqu(xmm12, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 6));
|
|
|
|
__ movdqu(xmm13, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 7));
|
|
|
|
__ movdqu(xmm14, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 8));
|
|
|
|
__ movdqu(xmm15, Operand(rsp, EntryFrameConstants::kXMMRegisterSize * 9));
|
|
|
|
__ addq(rsp, Immediate(EntryFrameConstants::kXMMRegistersBlockSize));
|
2013-04-17 09:54:17 +00:00
|
|
|
#endif
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
__ pop(rbx);
|
|
|
|
#ifdef _WIN64
|
|
|
|
// Callee save on in Win64 ABI, arguments/volatile in AMD64 ABI.
|
|
|
|
__ pop(rsi);
|
|
|
|
__ pop(rdi);
|
|
|
|
#endif
|
|
|
|
__ pop(r15);
|
|
|
|
__ pop(r14);
|
|
|
|
__ pop(r13);
|
|
|
|
__ pop(r12);
|
|
|
|
__ addq(rsp, Immediate(2 * kPointerSize)); // remove markers
|
|
|
|
|
|
|
|
// Restore frame pointer and return.
|
|
|
|
__ pop(rbp);
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InstanceofStub::Generate(MacroAssembler* masm) {
|
|
|
|
// Implements "value instanceof function" operator.
|
2011-03-09 15:57:47 +00:00
|
|
|
// Expected input state with no inline cache:
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0] : return address
|
|
|
|
// rsp[8] : function pointer
|
|
|
|
// rsp[16] : value
|
2011-03-09 15:57:47 +00:00
|
|
|
// Expected input state with an inline one-element cache:
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0] : return address
|
|
|
|
// rsp[8] : offset from return address to location of inline cache
|
|
|
|
// rsp[16] : function pointer
|
|
|
|
// rsp[24] : value
|
2010-08-25 09:44:44 +00:00
|
|
|
// Returns a bitwise zero to indicate that the value
|
|
|
|
// is and instance of the function and anything else to
|
|
|
|
// indicate that the value is not an instance.
|
|
|
|
|
2011-04-07 13:32:45 +00:00
|
|
|
static const int kOffsetToMapCheckValue = 2;
|
|
|
|
static const int kOffsetToResultValue = 18;
|
2011-03-09 15:57:47 +00:00
|
|
|
// The last 4 bytes of the instruction sequence
|
2011-04-07 13:32:45 +00:00
|
|
|
// movq(rdi, FieldOperand(rax, HeapObject::kMapOffset))
|
2013-06-04 10:30:05 +00:00
|
|
|
// Move(kScratchRegister, Factory::the_hole_value())
|
2011-03-09 15:57:47 +00:00
|
|
|
// in front of the hole value address.
|
|
|
|
static const unsigned int kWordBeforeMapCheckValue = 0xBA49FF78;
|
|
|
|
// The last 4 bytes of the instruction sequence
|
|
|
|
// __ j(not_equal, &cache_miss);
|
|
|
|
// __ LoadRoot(ToRegister(instr->result()), Heap::kTheHoleValueRootIndex);
|
|
|
|
// before the offset of the hole value in the root array.
|
2013-11-08 10:52:07 +00:00
|
|
|
static const unsigned int kWordBeforeResultValue = 0x458B4906;
|
2011-03-09 15:57:47 +00:00
|
|
|
// Only the inline check flag is supported on X64.
|
|
|
|
ASSERT(flags_ == kNoFlags || HasCallSiteInlineCheck());
|
2013-08-27 01:21:39 +00:00
|
|
|
int extra_argument_offset = HasCallSiteInlineCheck() ? 1 : 0;
|
2011-02-16 15:15:20 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Get the object - go slow case if it's a smi.
|
|
|
|
Label slow;
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 2 + extra_argument_offset,
|
|
|
|
ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, args.GetArgumentOperand(0));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ JumpIfSmi(rax, &slow);
|
|
|
|
|
|
|
|
// Check that the left hand is a JS object. Leave its map in rax.
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CmpObjectType(rax, FIRST_SPEC_OBJECT_TYPE, rax);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(below, &slow);
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CmpInstanceType(rax, LAST_SPEC_OBJECT_TYPE);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above, &slow);
|
|
|
|
|
|
|
|
// Get the prototype of the function.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, args.GetArgumentOperand(1));
|
2010-08-25 09:44:44 +00:00
|
|
|
// rdx is function, rax is map.
|
|
|
|
|
2011-03-09 15:57:47 +00:00
|
|
|
// If there is a call site cache don't look in the global cache, but do the
|
|
|
|
// real lookup and update the call site cache.
|
|
|
|
if (!HasCallSiteInlineCheck()) {
|
|
|
|
// Look up the function and the map in the instanceof cache.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label miss;
|
2011-03-09 15:57:47 +00:00
|
|
|
__ CompareRoot(rdx, Heap::kInstanceofCacheFunctionRootIndex);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2011-03-09 15:57:47 +00:00
|
|
|
__ CompareRoot(rax, Heap::kInstanceofCacheMapRootIndex);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2011-03-09 15:57:47 +00:00
|
|
|
__ LoadRoot(rax, Heap::kInstanceofCacheAnswerRootIndex);
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
__ bind(&miss);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-10-17 12:44:16 +00:00
|
|
|
__ TryGetFunctionPrototype(rdx, rbx, &slow, true);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check that the function prototype is a JS object.
|
|
|
|
__ JumpIfSmi(rbx, &slow);
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CmpObjectType(rbx, FIRST_SPEC_OBJECT_TYPE, kScratchRegister);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(below, &slow);
|
Implement set trap for proxies, and revamp class hierarchy in preparation:
- Introduce a class JSReceiver, that is a common superclass of JSObject and
JSProxy. Use JSReceiver where appropriate (probably lots of places that we
still have to migrate, but we will find those later with proxy test suite).
- Move appropriate methods to JSReceiver class (SetProperty,
GetPropertyAttribute, Get/SetPrototype, Lookup, and so on).
- Introduce new JSFunctionProxy subclass of JSProxy. Currently only a stub.
- Overhaul enum InstanceType:
* Introduce FIRST/LAST_SPEC_OBJECT_TYPE that ranges over all types that
represent JS objects, and use that consistently to check language types.
* Rename FIRST/LAST_JS_OBJECT_TYPE and FIRST/LAST_FUNCTION_CLASS_TYPE
to FIRST/LAST_[NON]CALLABLE_SPEC_OBJECT_TYPE for clarity.
* Eliminate the overlap over JS_REGEXP_TYPE.
* Also replace FIRST_JS_OBJECT with FIRST_JS_RECEIVER, but only use it where
we exclusively talk about the internal representation type.
* Insert JS_PROXY and JS_FUNCTION_PROXY in the appropriate places.
- Fix all checks concerning classification, especially for functions, to
use the CALLABLE_SPEC_OBJECT range (that includes funciton proxies).
- Handle proxies in SetProperty (that was the easiest part :) ).
- A few simple test cases.
R=kmillikin@chromium.org
Review URL: http://codereview.chromium.org/6992072
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8126 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2011-05-31 16:38:40 +00:00
|
|
|
__ CmpInstanceType(kScratchRegister, LAST_SPEC_OBJECT_TYPE);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above, &slow);
|
|
|
|
|
|
|
|
// Register mapping:
|
|
|
|
// rax is object map.
|
|
|
|
// rdx is function.
|
|
|
|
// rbx is function prototype.
|
2011-03-09 15:57:47 +00:00
|
|
|
if (!HasCallSiteInlineCheck()) {
|
|
|
|
__ StoreRoot(rdx, Heap::kInstanceofCacheFunctionRootIndex);
|
|
|
|
__ StoreRoot(rax, Heap::kInstanceofCacheMapRootIndex);
|
|
|
|
} else {
|
2011-09-19 18:36:47 +00:00
|
|
|
// Get return address and delta to inlined map check.
|
2014-02-07 02:21:18 +00:00
|
|
|
__ movq(kScratchRegister, StackOperandForReturnAddress(0));
|
2013-08-27 01:21:39 +00:00
|
|
|
__ subq(kScratchRegister, args.GetArgumentOperand(2));
|
2011-03-09 15:57:47 +00:00
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ movl(rdi, Immediate(kWordBeforeMapCheckValue));
|
|
|
|
__ cmpl(Operand(kScratchRegister, kOffsetToMapCheckValue - 4), rdi);
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCheck);
|
2011-03-09 15:57:47 +00:00
|
|
|
}
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(kScratchRegister,
|
2012-01-11 09:39:37 +00:00
|
|
|
Operand(kScratchRegister, kOffsetToMapCheckValue));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(Operand(kScratchRegister, 0), rax);
|
2011-03-09 15:57:47 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, FieldOperand(rax, Map::kPrototypeOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Loop through the prototype chain looking for the function prototype.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label loop, is_instance, is_not_instance;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ LoadRoot(kScratchRegister, Heap::kNullValueRootIndex);
|
|
|
|
__ bind(&loop);
|
|
|
|
__ cmpq(rcx, rbx);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &is_instance, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmpq(rcx, kScratchRegister);
|
|
|
|
// The code at is_not_instance assumes that kScratchRegister contains a
|
|
|
|
// non-zero GCable value (the null object in this case).
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &is_not_instance, Label::kNear);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, FieldOperand(rcx, HeapObject::kMapOffset));
|
|
|
|
__ movp(rcx, FieldOperand(rcx, Map::kPrototypeOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ jmp(&loop);
|
|
|
|
|
|
|
|
__ bind(&is_instance);
|
2011-03-09 15:57:47 +00:00
|
|
|
if (!HasCallSiteInlineCheck()) {
|
|
|
|
__ xorl(rax, rax);
|
|
|
|
// Store bitwise zero in the cache. This is a Smi in GC terms.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ StoreRoot(rax, Heap::kInstanceofCacheAnswerRootIndex);
|
|
|
|
} else {
|
|
|
|
// Store offset of true in the root array at the inline check site.
|
2011-09-19 18:36:47 +00:00
|
|
|
int true_offset = 0x100 +
|
|
|
|
(Heap::kTrueValueRootIndex << kPointerSizeLog2) - kRootRegisterBias;
|
|
|
|
// Assert it is a 1-byte signed value.
|
|
|
|
ASSERT(true_offset >= 0 && true_offset < 0x100);
|
|
|
|
__ movl(rax, Immediate(true_offset));
|
2014-02-07 02:21:18 +00:00
|
|
|
__ movq(kScratchRegister, StackOperandForReturnAddress(0));
|
2013-08-27 01:21:39 +00:00
|
|
|
__ subq(kScratchRegister, args.GetArgumentOperand(2));
|
2011-03-09 15:57:47 +00:00
|
|
|
__ movb(Operand(kScratchRegister, kOffsetToResultValue), rax);
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ movl(rax, Immediate(kWordBeforeResultValue));
|
|
|
|
__ cmpl(Operand(kScratchRegister, kOffsetToResultValue - 4), rax);
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov);
|
2011-03-09 15:57:47 +00:00
|
|
|
}
|
2011-04-12 13:20:51 +00:00
|
|
|
__ Set(rax, 0);
|
2011-03-09 15:57:47 +00:00
|
|
|
}
|
2013-08-27 01:21:39 +00:00
|
|
|
__ ret((2 + extra_argument_offset) * kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&is_not_instance);
|
2011-03-09 15:57:47 +00:00
|
|
|
if (!HasCallSiteInlineCheck()) {
|
|
|
|
// We have to store a non-zero value in the cache.
|
|
|
|
__ StoreRoot(kScratchRegister, Heap::kInstanceofCacheAnswerRootIndex);
|
|
|
|
} else {
|
|
|
|
// Store offset of false in the root array at the inline check site.
|
2011-09-19 18:36:47 +00:00
|
|
|
int false_offset = 0x100 +
|
|
|
|
(Heap::kFalseValueRootIndex << kPointerSizeLog2) - kRootRegisterBias;
|
|
|
|
// Assert it is a 1-byte signed value.
|
|
|
|
ASSERT(false_offset >= 0 && false_offset < 0x100);
|
|
|
|
__ movl(rax, Immediate(false_offset));
|
2014-02-07 02:21:18 +00:00
|
|
|
__ movq(kScratchRegister, StackOperandForReturnAddress(0));
|
2013-08-27 01:21:39 +00:00
|
|
|
__ subq(kScratchRegister, args.GetArgumentOperand(2));
|
2011-03-09 15:57:47 +00:00
|
|
|
__ movb(Operand(kScratchRegister, kOffsetToResultValue), rax);
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ movl(rax, Immediate(kWordBeforeResultValue));
|
|
|
|
__ cmpl(Operand(kScratchRegister, kOffsetToResultValue - 4), rax);
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov);
|
2011-03-09 15:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
2013-08-27 01:21:39 +00:00
|
|
|
__ ret((2 + extra_argument_offset) * kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Slow-case: Go through the JavaScript implementation.
|
|
|
|
__ bind(&slow);
|
2011-03-09 15:57:47 +00:00
|
|
|
if (HasCallSiteInlineCheck()) {
|
|
|
|
// Remove extra value from the stack.
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PopReturnAddressTo(rcx);
|
2011-03-09 15:57:47 +00:00
|
|
|
__ pop(rax);
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PushReturnAddressFrom(rcx);
|
2011-03-09 15:57:47 +00:00
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
__ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-16 15:15:20 +00:00
|
|
|
// Passing arguments in registers is not supported.
|
|
|
|
Register InstanceofStub::left() { return no_reg; }
|
2011-01-19 10:17:18 +00:00
|
|
|
|
|
|
|
|
2011-02-16 15:15:20 +00:00
|
|
|
Register InstanceofStub::right() { return no_reg; }
|
2011-01-19 10:17:18 +00:00
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// StringCharCodeAtGenerator
|
|
|
|
|
|
|
|
void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) {
|
|
|
|
Label flat_string;
|
|
|
|
Label ascii_string;
|
|
|
|
Label got_char_code;
|
2011-08-26 13:03:30 +00:00
|
|
|
Label sliced_string;
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// If the receiver is a smi trigger the non-string case.
|
|
|
|
__ JumpIfSmi(object_, receiver_not_string_);
|
|
|
|
|
|
|
|
// Fetch the instance type of the receiver into result register.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(result_, FieldOperand(object_, HeapObject::kMapOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
|
|
|
|
// If the receiver is not a string trigger the non-string case.
|
|
|
|
__ testb(result_, Immediate(kIsNotStringMask));
|
|
|
|
__ j(not_zero, receiver_not_string_);
|
|
|
|
|
|
|
|
// If the index is non-smi trigger the non-smi case.
|
|
|
|
__ JumpIfNotSmi(index_, &index_not_smi_);
|
|
|
|
__ bind(&got_smi_index_);
|
|
|
|
|
|
|
|
// Check for index out of range.
|
2011-11-09 14:32:51 +00:00
|
|
|
__ SmiCompare(index_, FieldOperand(object_, String::kLengthOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above_equal, index_out_of_range_);
|
|
|
|
|
2011-11-09 14:32:51 +00:00
|
|
|
__ SmiToInteger32(index_, index_);
|
2011-11-24 10:16:39 +00:00
|
|
|
|
|
|
|
StringCharLoadGenerator::Generate(
|
|
|
|
masm, object_, index_, result_, &call_runtime_);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Integer32ToSmi(result_, result_);
|
|
|
|
__ bind(&exit_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringCharCodeAtGenerator::GenerateSlow(
|
2011-10-28 12:37:29 +00:00
|
|
|
MacroAssembler* masm,
|
|
|
|
const RuntimeCallHelper& call_helper) {
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-04-14 08:01:19 +00:00
|
|
|
Factory* factory = masm->isolate()->factory();
|
2010-08-25 09:44:44 +00:00
|
|
|
// Index is not a smi.
|
|
|
|
__ bind(&index_not_smi_);
|
|
|
|
// If index is a heap number, try converting it to an integer.
|
2011-05-17 12:05:06 +00:00
|
|
|
__ CheckMap(index_,
|
|
|
|
factory->heap_number_map(),
|
|
|
|
index_not_number_,
|
|
|
|
DONT_DO_SMI_CHECK);
|
2010-08-25 09:44:44 +00:00
|
|
|
call_helper.BeforeCall(masm);
|
|
|
|
__ push(object_);
|
|
|
|
__ push(index_); // Consumed by runtime conversion function.
|
|
|
|
if (index_flags_ == STRING_INDEX_IS_NUMBER) {
|
|
|
|
__ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1);
|
|
|
|
} else {
|
|
|
|
ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX);
|
|
|
|
// NumberToSmi discards numbers that are not exact integers.
|
|
|
|
__ CallRuntime(Runtime::kNumberToSmi, 1);
|
|
|
|
}
|
2011-11-09 14:32:51 +00:00
|
|
|
if (!index_.is(rax)) {
|
2010-08-25 09:44:44 +00:00
|
|
|
// Save the conversion result before the pop instructions below
|
|
|
|
// have a chance to overwrite it.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(index_, rax);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
__ pop(object_);
|
|
|
|
// Reload the instance type.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(result_, FieldOperand(object_, HeapObject::kMapOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ movzxbl(result_, FieldOperand(result_, Map::kInstanceTypeOffset));
|
|
|
|
call_helper.AfterCall(masm);
|
|
|
|
// If index is still not a smi, it must be out of range.
|
2011-11-09 14:32:51 +00:00
|
|
|
__ JumpIfNotSmi(index_, index_out_of_range_);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Otherwise, return to the fast path.
|
|
|
|
__ jmp(&got_smi_index_);
|
|
|
|
|
|
|
|
// Call runtime. We get here when the receiver is a string and the
|
|
|
|
// index is a number, but the code of getting the actual character
|
|
|
|
// is too complex (e.g., when the string needs to be flattened).
|
|
|
|
__ bind(&call_runtime_);
|
|
|
|
call_helper.BeforeCall(masm);
|
|
|
|
__ push(object_);
|
2011-11-24 10:16:39 +00:00
|
|
|
__ Integer32ToSmi(index_, index_);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ push(index_);
|
|
|
|
__ CallRuntime(Runtime::kStringCharCodeAt, 2);
|
|
|
|
if (!result_.is(rax)) {
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(result_, rax);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
call_helper.AfterCall(masm);
|
|
|
|
__ jmp(&exit_);
|
|
|
|
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// StringCharFromCodeGenerator
|
|
|
|
|
|
|
|
void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) {
|
|
|
|
// Fast case of Heap::LookupSingleCharacterStringFromCode.
|
|
|
|
__ JumpIfNotSmi(code_, &slow_case_);
|
2013-01-09 10:30:54 +00:00
|
|
|
__ SmiCompare(code_, Smi::FromInt(String::kMaxOneByteCharCode));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ j(above, &slow_case_);
|
|
|
|
|
|
|
|
__ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex);
|
|
|
|
SmiIndex index = masm->SmiToIndex(kScratchRegister, code_, kPointerSizeLog2);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(result_, FieldOperand(result_, index.reg, index.scale,
|
2010-08-25 09:44:44 +00:00
|
|
|
FixedArray::kHeaderSize));
|
|
|
|
__ CompareRoot(result_, Heap::kUndefinedValueRootIndex);
|
|
|
|
__ j(equal, &slow_case_);
|
|
|
|
__ bind(&exit_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringCharFromCodeGenerator::GenerateSlow(
|
2011-10-28 12:37:29 +00:00
|
|
|
MacroAssembler* masm,
|
|
|
|
const RuntimeCallHelper& call_helper) {
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
__ bind(&slow_case_);
|
|
|
|
call_helper.BeforeCall(masm);
|
|
|
|
__ push(code_);
|
|
|
|
__ CallRuntime(Runtime::kCharFromCode, 1);
|
|
|
|
if (!result_.is(rax)) {
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(result_, rax);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
call_helper.AfterCall(masm);
|
|
|
|
__ jmp(&exit_);
|
|
|
|
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm,
|
|
|
|
Register dest,
|
|
|
|
Register src,
|
|
|
|
Register count,
|
|
|
|
bool ascii) {
|
|
|
|
// Copy characters using rep movs of doublewords. Align destination on 4 byte
|
|
|
|
// boundary before starting rep movs. Copy remaining characters after running
|
|
|
|
// rep movs.
|
|
|
|
// Count is positive int32, dest and src are character pointers.
|
|
|
|
ASSERT(dest.is(rdi)); // rep movs destination
|
|
|
|
ASSERT(src.is(rsi)); // rep movs source
|
|
|
|
ASSERT(count.is(rcx)); // rep movs count
|
|
|
|
|
|
|
|
// Nothing to do for zero characters.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label done;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ testl(count, count);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Make count the number of bytes to copy.
|
|
|
|
if (!ascii) {
|
|
|
|
STATIC_ASSERT(2 == sizeof(uc16));
|
|
|
|
__ addl(count, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't enter the rep movs if there are less than 4 bytes to copy.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label last_bytes;
|
2013-06-28 15:26:01 +00:00
|
|
|
__ testl(count, Immediate(~(kPointerSize - 1)));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &last_bytes, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Copy from edi to esi using rep movs instruction.
|
|
|
|
__ movl(kScratchRegister, count);
|
2013-06-28 15:26:01 +00:00
|
|
|
__ shr(count, Immediate(kPointerSizeLog2)); // Number of doublewords to copy.
|
2010-08-25 09:44:44 +00:00
|
|
|
__ repmovsq();
|
|
|
|
|
|
|
|
// Find number of bytes left.
|
|
|
|
__ movl(count, kScratchRegister);
|
2013-06-28 15:26:01 +00:00
|
|
|
__ and_(count, Immediate(kPointerSize - 1));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check if there are more bytes to copy.
|
|
|
|
__ bind(&last_bytes);
|
|
|
|
__ testl(count, count);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &done, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Copy remaining characters.
|
|
|
|
Label loop;
|
|
|
|
__ bind(&loop);
|
|
|
|
__ movb(kScratchRegister, Operand(src, 0));
|
|
|
|
__ movb(Operand(dest, 0), kScratchRegister);
|
|
|
|
__ incq(src);
|
|
|
|
__ incq(dest);
|
|
|
|
__ decl(count);
|
|
|
|
__ j(not_zero, &loop);
|
|
|
|
|
|
|
|
__ bind(&done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateHashInit(MacroAssembler* masm,
|
|
|
|
Register hash,
|
|
|
|
Register character,
|
|
|
|
Register scratch) {
|
2012-01-04 15:12:15 +00:00
|
|
|
// hash = (seed + character) + ((seed + character) << 10);
|
2012-01-10 13:24:18 +00:00
|
|
|
__ LoadRoot(scratch, Heap::kHashSeedRootIndex);
|
2012-01-04 15:12:15 +00:00
|
|
|
__ SmiToInteger32(scratch, scratch);
|
|
|
|
__ addl(scratch, character);
|
|
|
|
__ movl(hash, scratch);
|
|
|
|
__ shll(scratch, Immediate(10));
|
|
|
|
__ addl(hash, scratch);
|
2010-08-25 09:44:44 +00:00
|
|
|
// hash ^= hash >> 6;
|
|
|
|
__ movl(scratch, hash);
|
2011-11-10 14:26:57 +00:00
|
|
|
__ shrl(scratch, Immediate(6));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ xorl(hash, scratch);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm,
|
|
|
|
Register hash,
|
|
|
|
Register character,
|
|
|
|
Register scratch) {
|
|
|
|
// hash += character;
|
|
|
|
__ addl(hash, character);
|
|
|
|
// hash += hash << 10;
|
|
|
|
__ movl(scratch, hash);
|
|
|
|
__ shll(scratch, Immediate(10));
|
|
|
|
__ addl(hash, scratch);
|
|
|
|
// hash ^= hash >> 6;
|
|
|
|
__ movl(scratch, hash);
|
2011-11-10 14:26:57 +00:00
|
|
|
__ shrl(scratch, Immediate(6));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ xorl(hash, scratch);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void StringHelper::GenerateHashGetHash(MacroAssembler* masm,
|
|
|
|
Register hash,
|
|
|
|
Register scratch) {
|
|
|
|
// hash += hash << 3;
|
|
|
|
__ leal(hash, Operand(hash, hash, times_8, 0));
|
|
|
|
// hash ^= hash >> 11;
|
|
|
|
__ movl(scratch, hash);
|
2011-11-10 14:26:57 +00:00
|
|
|
__ shrl(scratch, Immediate(11));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ xorl(hash, scratch);
|
|
|
|
// hash += hash << 15;
|
|
|
|
__ movl(scratch, hash);
|
|
|
|
__ shll(scratch, Immediate(15));
|
|
|
|
__ addl(hash, scratch);
|
|
|
|
|
2012-01-10 12:01:04 +00:00
|
|
|
__ andl(hash, Immediate(String::kHashBitMask));
|
2011-11-10 14:26:57 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// if (hash == 0) hash = 27;
|
|
|
|
Label hash_not_zero;
|
|
|
|
__ j(not_zero, &hash_not_zero);
|
2012-01-10 12:01:04 +00:00
|
|
|
__ Set(hash, StringHasher::kZeroHash);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&hash_not_zero);
|
|
|
|
}
|
|
|
|
|
2013-07-05 09:52:11 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void SubStringStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label runtime;
|
|
|
|
|
|
|
|
// Stack frame on entry.
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0] : return address
|
|
|
|
// rsp[8] : to
|
|
|
|
// rsp[16] : from
|
|
|
|
// rsp[24] : string
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-10-03 01:22:25 +00:00
|
|
|
enum SubStringStubArgumentIndices {
|
|
|
|
STRING_ARGUMENT_INDEX,
|
|
|
|
FROM_ARGUMENT_INDEX,
|
|
|
|
TO_ARGUMENT_INDEX,
|
|
|
|
SUB_STRING_ARGUMENT_COUNT
|
|
|
|
};
|
|
|
|
|
|
|
|
StackArgumentsAccessor args(rsp, SUB_STRING_ARGUMENT_COUNT,
|
|
|
|
ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Make sure first argument is a string.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, args.GetArgumentOperand(STRING_ARGUMENT_INDEX));
|
2010-08-25 09:44:44 +00:00
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ testl(rax, Immediate(kSmiTagMask));
|
|
|
|
__ j(zero, &runtime);
|
|
|
|
Condition is_string = masm->IsObjectStringType(rax, rbx, rbx);
|
|
|
|
__ j(NegateCondition(is_string), &runtime);
|
|
|
|
|
|
|
|
// rax: string
|
|
|
|
// rbx: instance type
|
|
|
|
// Calculate length of sub string using the smi values.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, args.GetArgumentOperand(TO_ARGUMENT_INDEX));
|
|
|
|
__ movp(rdx, args.GetArgumentOperand(FROM_ARGUMENT_INDEX));
|
2010-09-30 11:48:03 +00:00
|
|
|
__ JumpUnlessBothNonNegativeSmi(rcx, rdx, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2010-09-16 07:24:15 +00:00
|
|
|
__ SmiSub(rcx, rcx, rdx); // Overflow doesn't happen.
|
2012-04-17 10:49:15 +00:00
|
|
|
__ cmpq(rcx, FieldOperand(rax, String::kLengthOffset));
|
2011-12-14 10:26:24 +00:00
|
|
|
Label not_original_string;
|
2012-04-17 10:49:15 +00:00
|
|
|
// Shorter than original string's length: an actual substring.
|
|
|
|
__ j(below, ¬_original_string, Label::kNear);
|
|
|
|
// Longer than original string's length or negative: unsafe arguments.
|
|
|
|
__ j(above, &runtime);
|
|
|
|
// Return original string.
|
2011-12-14 10:26:24 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->sub_string_native(), 1);
|
2013-10-03 01:22:25 +00:00
|
|
|
__ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
|
2011-12-14 10:26:24 +00:00
|
|
|
__ bind(¬_original_string);
|
2013-02-20 14:29:40 +00:00
|
|
|
|
|
|
|
Label single_char;
|
|
|
|
__ SmiCompare(rcx, Smi::FromInt(1));
|
|
|
|
__ j(equal, &single_char);
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
__ SmiToInteger32(rcx, rcx);
|
2011-12-14 10:26:24 +00:00
|
|
|
|
|
|
|
// rax: string
|
|
|
|
// rbx: instance type
|
|
|
|
// rcx: sub string length
|
|
|
|
// rdx: from index (smi)
|
|
|
|
// Deal with different string types: update the index if necessary
|
|
|
|
// and put the underlying string into edi.
|
|
|
|
Label underlying_unpacked, sliced_string, seq_or_external_string;
|
|
|
|
// If the string is not indirect, it can only be sequential or external.
|
|
|
|
STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag));
|
|
|
|
STATIC_ASSERT(kIsIndirectStringMask != 0);
|
|
|
|
__ testb(rbx, Immediate(kIsIndirectStringMask));
|
|
|
|
__ j(zero, &seq_or_external_string, Label::kNear);
|
|
|
|
|
|
|
|
__ testb(rbx, Immediate(kSlicedNotConsMask));
|
|
|
|
__ j(not_zero, &sliced_string, Label::kNear);
|
|
|
|
// Cons string. Check whether it is flat, then fetch first part.
|
|
|
|
// Flat cons strings have an empty second part.
|
|
|
|
__ CompareRoot(FieldOperand(rax, ConsString::kSecondOffset),
|
2013-02-28 17:03:34 +00:00
|
|
|
Heap::kempty_stringRootIndex);
|
2011-12-14 10:26:24 +00:00
|
|
|
__ j(not_equal, &runtime);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, FieldOperand(rax, ConsString::kFirstOffset));
|
2011-12-14 10:26:24 +00:00
|
|
|
// Update instance type.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
|
2011-12-14 10:26:24 +00:00
|
|
|
__ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
|
|
|
|
__ jmp(&underlying_unpacked, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(&sliced_string);
|
|
|
|
// Sliced string. Fetch parent and correct start index by offset.
|
|
|
|
__ addq(rdx, FieldOperand(rax, SlicedString::kOffsetOffset));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, FieldOperand(rax, SlicedString::kParentOffset));
|
2011-12-14 10:26:24 +00:00
|
|
|
// Update instance type.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, FieldOperand(rdi, HeapObject::kMapOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
__ movzxbl(rbx, FieldOperand(rbx, Map::kInstanceTypeOffset));
|
2011-12-14 10:26:24 +00:00
|
|
|
__ jmp(&underlying_unpacked, Label::kNear);
|
|
|
|
|
|
|
|
__ bind(&seq_or_external_string);
|
|
|
|
// Sequential or external string. Just move string to the correct register.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, rax);
|
2011-12-14 10:26:24 +00:00
|
|
|
|
|
|
|
__ bind(&underlying_unpacked);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-09-01 15:24:26 +00:00
|
|
|
if (FLAG_string_slices) {
|
|
|
|
Label copy_routine;
|
2011-12-14 10:26:24 +00:00
|
|
|
// rdi: underlying subject string
|
|
|
|
// rbx: instance type of underlying subject string
|
|
|
|
// rdx: adjusted start index (smi)
|
|
|
|
// rcx: length
|
2011-09-01 15:24:26 +00:00
|
|
|
// If coming from the make_two_character_string path, the string
|
|
|
|
// is too short to be sliced anyways.
|
|
|
|
__ cmpq(rcx, Immediate(SlicedString::kMinLength));
|
|
|
|
// Short slice. Copy instead of slicing.
|
|
|
|
__ j(less, ©_routine);
|
|
|
|
// Allocate new sliced string. At this point we do not reload the instance
|
|
|
|
// type including the string encoding because we simply rely on the info
|
|
|
|
// provided by the original string. It does not matter if the original
|
|
|
|
// string's encoding is wrong because we always have to recheck encoding of
|
|
|
|
// the newly created string's parent anyways due to externalized strings.
|
|
|
|
Label two_byte_slice, set_slice_header;
|
2012-11-08 12:14:29 +00:00
|
|
|
STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0);
|
2011-09-01 15:24:26 +00:00
|
|
|
STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0);
|
|
|
|
__ testb(rbx, Immediate(kStringEncodingMask));
|
2013-11-14 16:03:55 +00:00
|
|
|
__ j(zero, &two_byte_slice, Label::kNear);
|
2011-12-14 10:26:24 +00:00
|
|
|
__ AllocateAsciiSlicedString(rax, rbx, r14, &runtime);
|
2013-11-14 16:03:55 +00:00
|
|
|
__ jmp(&set_slice_header, Label::kNear);
|
2011-09-01 15:24:26 +00:00
|
|
|
__ bind(&two_byte_slice);
|
2011-12-14 10:26:24 +00:00
|
|
|
__ AllocateTwoByteSlicedString(rax, rbx, r14, &runtime);
|
2011-09-01 15:24:26 +00:00
|
|
|
__ bind(&set_slice_header);
|
|
|
|
__ Integer32ToSmi(rcx, rcx);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rax, SlicedString::kLengthOffset), rcx);
|
|
|
|
__ movp(FieldOperand(rax, SlicedString::kHashFieldOffset),
|
2011-09-01 15:24:26 +00:00
|
|
|
Immediate(String::kEmptyHashField));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(FieldOperand(rax, SlicedString::kParentOffset), rdi);
|
|
|
|
__ movp(FieldOperand(rax, SlicedString::kOffsetOffset), rdx);
|
2011-12-14 10:26:24 +00:00
|
|
|
__ IncrementCounter(counters->sub_string_native(), 1);
|
2013-10-03 01:22:25 +00:00
|
|
|
__ ret(3 * kPointerSize);
|
2011-09-01 15:24:26 +00:00
|
|
|
|
|
|
|
__ bind(©_routine);
|
|
|
|
}
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-12-14 10:26:24 +00:00
|
|
|
// rdi: underlying subject string
|
|
|
|
// rbx: instance type of underlying subject string
|
|
|
|
// rdx: adjusted start index (smi)
|
|
|
|
// rcx: length
|
|
|
|
// The subject string can only be external or sequential string of either
|
|
|
|
// encoding at this point.
|
|
|
|
Label two_byte_sequential, sequential_string;
|
|
|
|
STATIC_ASSERT(kExternalStringTag != 0);
|
|
|
|
STATIC_ASSERT(kSeqStringTag == 0);
|
|
|
|
__ testb(rbx, Immediate(kExternalStringTag));
|
|
|
|
__ j(zero, &sequential_string);
|
|
|
|
|
|
|
|
// Handle external string.
|
|
|
|
// Rule out short external strings.
|
|
|
|
STATIC_CHECK(kShortExternalStringTag != 0);
|
|
|
|
__ testb(rbx, Immediate(kShortExternalStringMask));
|
|
|
|
__ j(not_zero, &runtime);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdi, FieldOperand(rdi, ExternalString::kResourceDataOffset));
|
2011-12-14 10:26:24 +00:00
|
|
|
// Move the pointer so that offset-wise, it looks like a sequential string.
|
2012-11-15 13:31:27 +00:00
|
|
|
STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize);
|
2011-12-14 10:26:24 +00:00
|
|
|
__ subq(rdi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag));
|
|
|
|
|
|
|
|
__ bind(&sequential_string);
|
2012-11-08 12:14:29 +00:00
|
|
|
STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0);
|
2011-12-14 10:26:24 +00:00
|
|
|
__ testb(rbx, Immediate(kStringEncodingMask));
|
|
|
|
__ j(zero, &two_byte_sequential);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Allocate the result.
|
2011-12-14 10:26:24 +00:00
|
|
|
__ AllocateAsciiString(rax, rcx, r11, r14, r15, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// rax: result string
|
|
|
|
// rcx: result string length
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r14, rsi); // esi used by following code.
|
2011-12-14 10:26:24 +00:00
|
|
|
{ // Locate character of sub string start.
|
|
|
|
SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_1);
|
|
|
|
__ lea(rsi, Operand(rdi, smi_as_index.reg, smi_as_index.scale,
|
2012-11-15 13:31:27 +00:00
|
|
|
SeqOneByteString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2011-12-14 10:26:24 +00:00
|
|
|
// Locate first character of result.
|
2012-11-15 13:31:27 +00:00
|
|
|
__ lea(rdi, FieldOperand(rax, SeqOneByteString::kHeaderSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// rax: result string
|
|
|
|
// rcx: result length
|
|
|
|
// rdi: first character of result
|
|
|
|
// rsi: character of sub string start
|
2011-12-14 10:26:24 +00:00
|
|
|
// r14: original value of rsi
|
2010-08-25 09:44:44 +00:00
|
|
|
StringHelper::GenerateCopyCharactersREP(masm, rdi, rsi, rcx, true);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rsi, r14); // Restore rsi.
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->sub_string_native(), 1);
|
2013-10-03 01:22:25 +00:00
|
|
|
__ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-12-14 10:26:24 +00:00
|
|
|
__ bind(&two_byte_sequential);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Allocate the result.
|
2011-12-14 10:26:24 +00:00
|
|
|
__ AllocateTwoByteString(rax, rcx, r11, r14, r15, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// rax: result string
|
|
|
|
// rcx: result string length
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r14, rsi); // esi used by following code.
|
2011-12-14 10:26:24 +00:00
|
|
|
{ // Locate character of sub string start.
|
|
|
|
SmiIndex smi_as_index = masm->SmiToIndex(rdx, rdx, times_2);
|
|
|
|
__ lea(rsi, Operand(rdi, smi_as_index.reg, smi_as_index.scale,
|
2012-11-15 13:31:27 +00:00
|
|
|
SeqOneByteString::kHeaderSize - kHeapObjectTag));
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
2011-12-14 10:26:24 +00:00
|
|
|
// Locate first character of result.
|
|
|
|
__ lea(rdi, FieldOperand(rax, SeqTwoByteString::kHeaderSize));
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// rax: result string
|
|
|
|
// rcx: result length
|
|
|
|
// rdi: first character of result
|
|
|
|
// rsi: character of sub string start
|
2011-12-14 10:26:24 +00:00
|
|
|
// r14: original value of rsi
|
2010-08-25 09:44:44 +00:00
|
|
|
StringHelper::GenerateCopyCharactersREP(masm, rdi, rsi, rcx, false);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rsi, r14); // Restore esi.
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->sub_string_native(), 1);
|
2013-10-03 01:22:25 +00:00
|
|
|
__ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Just jump to runtime to create the sub string.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kSubString, 3, 1);
|
2013-02-20 14:29:40 +00:00
|
|
|
|
|
|
|
__ bind(&single_char);
|
|
|
|
// rax: string
|
|
|
|
// rbx: instance type
|
|
|
|
// rcx: sub string length (smi)
|
|
|
|
// rdx: from index (smi)
|
|
|
|
StringCharAtGenerator generator(
|
|
|
|
rax, rdx, rcx, rax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER);
|
|
|
|
generator.GenerateFast(masm);
|
2013-10-03 01:22:25 +00:00
|
|
|
__ ret(SUB_STRING_ARGUMENT_COUNT * kPointerSize);
|
2013-02-20 14:29:40 +00:00
|
|
|
generator.SkipSlow(masm, &runtime);
|
2010-08-25 09:44:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-05 11:40:08 +00:00
|
|
|
void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm,
|
|
|
|
Register left,
|
|
|
|
Register right,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2) {
|
|
|
|
Register length = scratch1;
|
|
|
|
|
|
|
|
// Compare lengths.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label check_zero_length;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(length, FieldOperand(left, String::kLengthOffset));
|
2011-05-05 11:40:08 +00:00
|
|
|
__ SmiCompare(length, FieldOperand(right, String::kLengthOffset));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(equal, &check_zero_length, Label::kNear);
|
2011-05-05 11:40:08 +00:00
|
|
|
__ Move(rax, Smi::FromInt(NOT_EQUAL));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Check if the length is zero.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label compare_chars;
|
2011-05-05 11:40:08 +00:00
|
|
|
__ bind(&check_zero_length);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ SmiTest(length);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_zero, &compare_chars, Label::kNear);
|
2011-05-05 11:40:08 +00:00
|
|
|
__ Move(rax, Smi::FromInt(EQUAL));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Compare characters.
|
|
|
|
__ bind(&compare_chars);
|
2011-05-11 09:12:16 +00:00
|
|
|
Label strings_not_equal;
|
2011-05-06 14:19:51 +00:00
|
|
|
GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2,
|
2011-05-11 09:12:16 +00:00
|
|
|
&strings_not_equal, Label::kNear);
|
2011-05-05 11:40:08 +00:00
|
|
|
|
|
|
|
// Characters are equal.
|
|
|
|
__ Move(rax, Smi::FromInt(EQUAL));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Characters are not equal.
|
|
|
|
__ bind(&strings_not_equal);
|
|
|
|
__ Move(rax, Smi::FromInt(NOT_EQUAL));
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm,
|
|
|
|
Register left,
|
|
|
|
Register right,
|
|
|
|
Register scratch1,
|
|
|
|
Register scratch2,
|
|
|
|
Register scratch3,
|
|
|
|
Register scratch4) {
|
|
|
|
// Ensure that you can always subtract a string length from a non-negative
|
|
|
|
// number (e.g. another length).
|
|
|
|
STATIC_ASSERT(String::kMaxLength < 0x7fffffff);
|
|
|
|
|
|
|
|
// Find minimum length and length difference.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch1, FieldOperand(left, String::kLengthOffset));
|
|
|
|
__ movp(scratch4, scratch1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ SmiSub(scratch4,
|
|
|
|
scratch4,
|
2010-09-16 07:24:15 +00:00
|
|
|
FieldOperand(right, String::kLengthOffset));
|
2010-08-25 09:44:44 +00:00
|
|
|
// Register scratch4 now holds left.length - right.length.
|
|
|
|
const Register length_difference = scratch4;
|
2011-05-10 09:03:42 +00:00
|
|
|
Label left_shorter;
|
|
|
|
__ j(less, &left_shorter, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
// The right string isn't longer that the left one.
|
|
|
|
// Get the right string's length by subtracting the (non-negative) difference
|
|
|
|
// from the left string's length.
|
2010-09-16 07:24:15 +00:00
|
|
|
__ SmiSub(scratch1, scratch1, length_difference);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&left_shorter);
|
|
|
|
// Register scratch1 now holds Min(left.length, right.length).
|
|
|
|
const Register min_length = scratch1;
|
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
Label compare_lengths;
|
2010-08-25 09:44:44 +00:00
|
|
|
// If min-length is zero, go directly to comparing lengths.
|
|
|
|
__ SmiTest(min_length);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(zero, &compare_lengths, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2011-05-06 14:19:51 +00:00
|
|
|
// Compare loop.
|
2011-05-11 09:12:16 +00:00
|
|
|
Label result_not_equal;
|
2011-05-06 14:19:51 +00:00
|
|
|
GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2,
|
2013-12-10 14:28:41 +00:00
|
|
|
&result_not_equal,
|
|
|
|
// In debug-code mode, SmiTest below might push
|
|
|
|
// the target label outside the near range.
|
|
|
|
Label::kFar);
|
2011-05-06 14:19:51 +00:00
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
// Completed loop without finding different characters.
|
|
|
|
// Compare lengths (precomputed).
|
|
|
|
__ bind(&compare_lengths);
|
|
|
|
__ SmiTest(length_difference);
|
2013-01-09 15:47:53 +00:00
|
|
|
Label length_not_equal;
|
|
|
|
__ j(not_zero, &length_not_equal, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Result is EQUAL.
|
|
|
|
__ Move(rax, Smi::FromInt(EQUAL));
|
|
|
|
__ ret(0);
|
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
Label result_greater;
|
2013-01-09 15:47:53 +00:00
|
|
|
Label result_less;
|
|
|
|
__ bind(&length_not_equal);
|
|
|
|
__ j(greater, &result_greater, Label::kNear);
|
|
|
|
__ jmp(&result_less, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ bind(&result_not_equal);
|
|
|
|
// Unequal comparison of left to right, either character or length.
|
2013-01-09 15:47:53 +00:00
|
|
|
__ j(above, &result_greater, Label::kNear);
|
|
|
|
__ bind(&result_less);
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Result is LESS.
|
|
|
|
__ Move(rax, Smi::FromInt(LESS));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Result is GREATER.
|
|
|
|
__ bind(&result_greater);
|
|
|
|
__ Move(rax, Smi::FromInt(GREATER));
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-06 14:19:51 +00:00
|
|
|
void StringCompareStub::GenerateAsciiCharsCompareLoop(
|
|
|
|
MacroAssembler* masm,
|
|
|
|
Register left,
|
|
|
|
Register right,
|
|
|
|
Register length,
|
|
|
|
Register scratch,
|
2011-05-11 09:12:16 +00:00
|
|
|
Label* chars_not_equal,
|
|
|
|
Label::Distance near_jump) {
|
2011-05-06 14:19:51 +00:00
|
|
|
// Change index to run from -length to -1 by adding length to string
|
|
|
|
// start. This means that loop ends when index reaches zero, which
|
|
|
|
// doesn't need an additional compare.
|
|
|
|
__ SmiToInteger32(length, length);
|
|
|
|
__ lea(left,
|
2012-11-15 13:31:27 +00:00
|
|
|
FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize));
|
2011-05-06 14:19:51 +00:00
|
|
|
__ lea(right,
|
2012-11-15 13:31:27 +00:00
|
|
|
FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize));
|
2011-05-06 14:19:51 +00:00
|
|
|
__ neg(length);
|
|
|
|
Register index = length; // index = -length;
|
|
|
|
|
|
|
|
// Compare loop.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label loop;
|
2011-05-06 14:19:51 +00:00
|
|
|
__ bind(&loop);
|
|
|
|
__ movb(scratch, Operand(left, index, times_1, 0));
|
|
|
|
__ cmpb(scratch, Operand(right, index, times_1, 0));
|
2011-05-11 09:12:16 +00:00
|
|
|
__ j(not_equal, chars_not_equal, near_jump);
|
2012-03-09 13:12:59 +00:00
|
|
|
__ incq(index);
|
2011-05-06 14:19:51 +00:00
|
|
|
__ j(not_zero, &loop);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
void StringCompareStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label runtime;
|
|
|
|
|
|
|
|
// Stack frame on entry.
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0] : return address
|
|
|
|
// rsp[8] : right string
|
|
|
|
// rsp[16] : left string
|
2010-08-25 09:44:44 +00:00
|
|
|
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, args.GetArgumentOperand(0)); // left
|
|
|
|
__ movp(rax, args.GetArgumentOperand(1)); // right
|
2010-08-25 09:44:44 +00:00
|
|
|
|
|
|
|
// Check for identity.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_same;
|
2010-08-25 09:44:44 +00:00
|
|
|
__ cmpq(rdx, rax);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, ¬_same, Label::kNear);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ Move(rax, Smi::FromInt(EQUAL));
|
2011-03-23 11:13:07 +00:00
|
|
|
Counters* counters = masm->isolate()->counters();
|
|
|
|
__ IncrementCounter(counters->string_compare_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(¬_same);
|
|
|
|
|
|
|
|
// Check that both are sequential ASCII strings.
|
|
|
|
__ JumpIfNotBothSequentialAsciiStrings(rdx, rax, rcx, rbx, &runtime);
|
|
|
|
|
2012-01-16 12:38:59 +00:00
|
|
|
// Inline comparison of ASCII strings.
|
2011-03-23 11:13:07 +00:00
|
|
|
__ IncrementCounter(counters->string_compare_native(), 1);
|
2010-08-25 09:44:44 +00:00
|
|
|
// Drop arguments from the stack
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PopReturnAddressTo(rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
__ addq(rsp, Immediate(2 * kPointerSize));
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PushReturnAddressFrom(rcx);
|
2010-08-25 09:44:44 +00:00
|
|
|
GenerateCompareFlatAsciiStrings(masm, rdx, rax, rcx, rbx, rdi, r8);
|
|
|
|
|
|
|
|
// Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater)
|
|
|
|
// tagged as a small integer.
|
|
|
|
__ bind(&runtime);
|
|
|
|
__ TailCallRuntime(Runtime::kStringCompare, 2, 1);
|
|
|
|
}
|
|
|
|
|
2011-03-02 09:28:04 +00:00
|
|
|
|
2014-01-20 17:09:24 +00:00
|
|
|
void ArrayPushStub::Generate(MacroAssembler* masm) {
|
|
|
|
int argc = arguments_count();
|
|
|
|
|
|
|
|
StackArgumentsAccessor args(rsp, argc);
|
|
|
|
if (argc == 0) {
|
|
|
|
// Noop, return the length.
|
|
|
|
__ movp(rax, FieldOperand(rdx, JSArray::kLengthOffset));
|
|
|
|
__ ret((argc + 1) * kPointerSize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Isolate* isolate = masm->isolate();
|
|
|
|
|
|
|
|
if (argc != 1) {
|
|
|
|
__ TailCallExternalReference(
|
|
|
|
ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Label call_builtin, attempt_to_grow_elements, with_write_barrier;
|
|
|
|
|
|
|
|
// Get the elements array of the object.
|
|
|
|
__ movp(rdi, FieldOperand(rdx, JSArray::kElementsOffset));
|
|
|
|
|
|
|
|
if (IsFastSmiOrObjectElementsKind(elements_kind())) {
|
|
|
|
// Check that the elements are in fast mode and writable.
|
|
|
|
__ Cmp(FieldOperand(rdi, HeapObject::kMapOffset),
|
|
|
|
isolate->factory()->fixed_array_map());
|
|
|
|
__ j(not_equal, &call_builtin);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the array's length into rax and calculate new length.
|
|
|
|
__ SmiToInteger32(rax, FieldOperand(rdx, JSArray::kLengthOffset));
|
|
|
|
STATIC_ASSERT(FixedArray::kMaxLength < Smi::kMaxValue);
|
|
|
|
__ addl(rax, Immediate(argc));
|
|
|
|
|
|
|
|
// Get the elements' length into rcx.
|
|
|
|
__ SmiToInteger32(rcx, FieldOperand(rdi, FixedArray::kLengthOffset));
|
|
|
|
|
|
|
|
// Check if we could survive without allocation.
|
|
|
|
__ cmpl(rax, rcx);
|
|
|
|
|
|
|
|
if (IsFastSmiOrObjectElementsKind(elements_kind())) {
|
|
|
|
__ j(greater, &attempt_to_grow_elements);
|
|
|
|
|
|
|
|
// Check if value is a smi.
|
|
|
|
__ movp(rcx, args.GetArgumentOperand(1));
|
|
|
|
__ JumpIfNotSmi(rcx, &with_write_barrier);
|
|
|
|
|
|
|
|
// Store the value.
|
|
|
|
__ movp(FieldOperand(rdi,
|
|
|
|
rax,
|
|
|
|
times_pointer_size,
|
|
|
|
FixedArray::kHeaderSize - argc * kPointerSize),
|
|
|
|
rcx);
|
|
|
|
} else {
|
|
|
|
__ j(greater, &call_builtin);
|
|
|
|
|
|
|
|
__ movp(rcx, args.GetArgumentOperand(1));
|
|
|
|
__ StoreNumberToDoubleElements(
|
|
|
|
rcx, rdi, rax, xmm0, &call_builtin, argc * kDoubleSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save new length.
|
|
|
|
__ Integer32ToSmiField(FieldOperand(rdx, JSArray::kLengthOffset), rax);
|
|
|
|
|
|
|
|
__ Integer32ToSmi(rax, rax); // Return new length as smi.
|
|
|
|
__ ret((argc + 1) * kPointerSize);
|
|
|
|
|
|
|
|
if (IsFastDoubleElementsKind(elements_kind())) {
|
|
|
|
__ bind(&call_builtin);
|
|
|
|
__ TailCallExternalReference(
|
|
|
|
ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&with_write_barrier);
|
|
|
|
|
|
|
|
if (IsFastSmiElementsKind(elements_kind())) {
|
|
|
|
if (FLAG_trace_elements_transitions) __ jmp(&call_builtin);
|
|
|
|
|
|
|
|
__ Cmp(FieldOperand(rcx, HeapObject::kMapOffset),
|
|
|
|
isolate->factory()->heap_number_map());
|
|
|
|
__ j(equal, &call_builtin);
|
|
|
|
|
|
|
|
ElementsKind target_kind = IsHoleyElementsKind(elements_kind())
|
|
|
|
? FAST_HOLEY_ELEMENTS : FAST_ELEMENTS;
|
|
|
|
__ movp(rbx, ContextOperand(rsi, Context::GLOBAL_OBJECT_INDEX));
|
|
|
|
__ movp(rbx, FieldOperand(rbx, GlobalObject::kNativeContextOffset));
|
|
|
|
__ movp(rbx, ContextOperand(rbx, Context::JS_ARRAY_MAPS_INDEX));
|
|
|
|
const int header_size = FixedArrayBase::kHeaderSize;
|
|
|
|
// Verify that the object can be transitioned in place.
|
|
|
|
const int origin_offset = header_size + elements_kind() * kPointerSize;
|
|
|
|
__ movp(rdi, FieldOperand(rbx, origin_offset));
|
|
|
|
__ cmpq(rdi, FieldOperand(rdx, HeapObject::kMapOffset));
|
|
|
|
__ j(not_equal, &call_builtin);
|
|
|
|
|
|
|
|
const int target_offset = header_size + target_kind * kPointerSize;
|
|
|
|
__ movp(rbx, FieldOperand(rbx, target_offset));
|
|
|
|
ElementsTransitionGenerator::GenerateMapChangeElementsTransition(
|
|
|
|
masm, DONT_TRACK_ALLOCATION_SITE, NULL);
|
|
|
|
__ movp(rdi, FieldOperand(rdx, JSArray::kElementsOffset));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save new length.
|
|
|
|
__ Integer32ToSmiField(FieldOperand(rdx, JSArray::kLengthOffset), rax);
|
|
|
|
|
|
|
|
// Store the value.
|
|
|
|
__ lea(rdx, FieldOperand(rdi,
|
|
|
|
rax, times_pointer_size,
|
|
|
|
FixedArray::kHeaderSize - argc * kPointerSize));
|
|
|
|
__ movp(Operand(rdx, 0), rcx);
|
|
|
|
|
|
|
|
__ RecordWrite(rdi, rdx, rcx, kDontSaveFPRegs, EMIT_REMEMBERED_SET,
|
|
|
|
OMIT_SMI_CHECK);
|
|
|
|
|
|
|
|
__ Integer32ToSmi(rax, rax); // Return new length as smi.
|
|
|
|
__ ret((argc + 1) * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&attempt_to_grow_elements);
|
|
|
|
if (!FLAG_inline_new) {
|
|
|
|
__ bind(&call_builtin);
|
|
|
|
__ TailCallExternalReference(
|
|
|
|
ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
__ movp(rbx, args.GetArgumentOperand(1));
|
|
|
|
// Growing elements that are SMI-only requires special handling in case the
|
|
|
|
// new element is non-Smi. For now, delegate to the builtin.
|
|
|
|
Label no_fast_elements_check;
|
|
|
|
__ JumpIfSmi(rbx, &no_fast_elements_check);
|
|
|
|
__ movp(rcx, FieldOperand(rdx, HeapObject::kMapOffset));
|
|
|
|
__ CheckFastObjectElements(rcx, &call_builtin, Label::kFar);
|
|
|
|
__ bind(&no_fast_elements_check);
|
|
|
|
|
|
|
|
ExternalReference new_space_allocation_top =
|
|
|
|
ExternalReference::new_space_allocation_top_address(isolate);
|
|
|
|
ExternalReference new_space_allocation_limit =
|
|
|
|
ExternalReference::new_space_allocation_limit_address(isolate);
|
|
|
|
|
|
|
|
const int kAllocationDelta = 4;
|
|
|
|
ASSERT(kAllocationDelta >= argc);
|
|
|
|
// Load top.
|
|
|
|
__ Load(rcx, new_space_allocation_top);
|
|
|
|
|
|
|
|
// Check if it's the end of elements.
|
|
|
|
__ lea(rdx, FieldOperand(rdi,
|
|
|
|
rax, times_pointer_size,
|
|
|
|
FixedArray::kHeaderSize - argc * kPointerSize));
|
|
|
|
__ cmpq(rdx, rcx);
|
|
|
|
__ j(not_equal, &call_builtin);
|
|
|
|
__ addq(rcx, Immediate(kAllocationDelta * kPointerSize));
|
|
|
|
Operand limit_operand = masm->ExternalOperand(new_space_allocation_limit);
|
|
|
|
__ cmpq(rcx, limit_operand);
|
|
|
|
__ j(above, &call_builtin);
|
|
|
|
|
|
|
|
// We fit and could grow elements.
|
|
|
|
__ Store(new_space_allocation_top, rcx);
|
|
|
|
|
|
|
|
// Push the argument...
|
|
|
|
__ movp(Operand(rdx, 0), rbx);
|
|
|
|
// ... and fill the rest with holes.
|
|
|
|
__ LoadRoot(kScratchRegister, Heap::kTheHoleValueRootIndex);
|
|
|
|
for (int i = 1; i < kAllocationDelta; i++) {
|
|
|
|
__ movp(Operand(rdx, i * kPointerSize), kScratchRegister);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsFastObjectElementsKind(elements_kind())) {
|
|
|
|
// We know the elements array is in new space so we don't need the
|
|
|
|
// remembered set, but we just pushed a value onto it so we may have to tell
|
|
|
|
// the incremental marker to rescan the object that we just grew. We don't
|
|
|
|
// need to worry about the holes because they are in old space and already
|
|
|
|
// marked black.
|
|
|
|
__ RecordWrite(rdi, rdx, rbx, kDontSaveFPRegs, OMIT_REMEMBERED_SET);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Restore receiver to rdx as finish sequence assumes it's here.
|
|
|
|
__ movp(rdx, args.GetReceiverOperand());
|
|
|
|
|
|
|
|
// Increment element's and array's sizes.
|
|
|
|
__ SmiAddConstant(FieldOperand(rdi, FixedArray::kLengthOffset),
|
|
|
|
Smi::FromInt(kAllocationDelta));
|
|
|
|
|
|
|
|
// Make new length a smi before returning it.
|
|
|
|
__ Integer32ToSmi(rax, rax);
|
|
|
|
__ movp(FieldOperand(rdx, JSArray::kLengthOffset), rax);
|
|
|
|
|
|
|
|
__ ret((argc + 1) * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(&call_builtin);
|
|
|
|
__ TailCallExternalReference(
|
|
|
|
ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-02 15:31:27 +00:00
|
|
|
void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- rdx : left
|
|
|
|
// -- rax : right
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -----------------------------------
|
|
|
|
Isolate* isolate = masm->isolate();
|
|
|
|
|
|
|
|
// Load rcx with the allocation site. We stick an undefined dummy value here
|
|
|
|
// and replace it with the real allocation site later when we instantiate this
|
|
|
|
// stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate().
|
|
|
|
__ Move(rcx, handle(isolate->heap()->undefined_value()));
|
|
|
|
|
|
|
|
// Make sure that we actually patched the allocation site.
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
__ testb(rcx, Immediate(kSmiTagMask));
|
2014-01-09 12:41:05 +00:00
|
|
|
__ Assert(not_equal, kExpectedAllocationSite);
|
2014-01-02 15:31:27 +00:00
|
|
|
__ Cmp(FieldOperand(rcx, HeapObject::kMapOffset),
|
|
|
|
isolate->factory()->allocation_site_map());
|
|
|
|
__ Assert(equal, kExpectedAllocationSite);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tail call into the stub that handles binary operations with allocation
|
|
|
|
// sites.
|
|
|
|
BinaryOpWithAllocationSiteStub stub(state_);
|
|
|
|
__ TailCallStub(&stub);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void ICCompareStub::GenerateSmis(MacroAssembler* masm) {
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(state_ == CompareIC::SMI);
|
2011-05-11 09:12:16 +00:00
|
|
|
Label miss;
|
|
|
|
__ JumpIfNotBothSmi(rdx, rax, &miss, Label::kNear);
|
2011-01-19 10:17:18 +00:00
|
|
|
|
|
|
|
if (GetCondition() == equal) {
|
|
|
|
// For equality we do not care about the sign of the result.
|
2011-02-08 07:49:59 +00:00
|
|
|
__ subq(rax, rdx);
|
2011-01-19 10:17:18 +00:00
|
|
|
} else {
|
2011-05-10 09:03:42 +00:00
|
|
|
Label done;
|
2011-02-08 07:49:59 +00:00
|
|
|
__ subq(rdx, rax);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(no_overflow, &done, Label::kNear);
|
2011-01-19 10:17:18 +00:00
|
|
|
// Correct sign of result in case of overflow.
|
2012-11-20 15:57:10 +00:00
|
|
|
__ not_(rdx);
|
2011-01-19 10:17:18 +00:00
|
|
|
__ bind(&done);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rax, rdx);
|
2011-01-19 10:17:18 +00:00
|
|
|
}
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 14:43:57 +00:00
|
|
|
void ICCompareStub::GenerateNumbers(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::NUMBER);
|
2011-01-19 10:17:18 +00:00
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
Label generic_stub;
|
2012-03-02 13:40:14 +00:00
|
|
|
Label unordered, maybe_undefined1, maybe_undefined2;
|
2011-05-10 09:03:42 +00:00
|
|
|
Label miss;
|
2011-01-19 10:17:18 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
if (left_ == CompareIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(rdx, &miss);
|
|
|
|
}
|
|
|
|
if (right_ == CompareIC::SMI) {
|
|
|
|
__ JumpIfNotSmi(rax, &miss);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load left and right operand.
|
|
|
|
Label done, left, left_smi, right_smi;
|
|
|
|
__ JumpIfSmi(rax, &right_smi, Label::kNear);
|
2013-11-08 10:52:07 +00:00
|
|
|
__ CompareMap(rax, masm->isolate()->factory()->heap_number_map());
|
2012-03-02 13:40:14 +00:00
|
|
|
__ j(not_equal, &maybe_undefined1, Label::kNear);
|
2012-11-14 15:59:45 +00:00
|
|
|
__ movsd(xmm1, FieldOperand(rax, HeapNumber::kValueOffset));
|
|
|
|
__ jmp(&left, Label::kNear);
|
|
|
|
__ bind(&right_smi);
|
|
|
|
__ SmiToInteger32(rcx, rax); // Can't clobber rax yet.
|
2013-09-13 07:59:48 +00:00
|
|
|
__ Cvtlsi2sd(xmm1, rcx);
|
2012-11-14 15:59:45 +00:00
|
|
|
|
|
|
|
__ bind(&left);
|
|
|
|
__ JumpIfSmi(rdx, &left_smi, Label::kNear);
|
2013-11-08 10:52:07 +00:00
|
|
|
__ CompareMap(rdx, masm->isolate()->factory()->heap_number_map());
|
2012-03-02 13:40:14 +00:00
|
|
|
__ j(not_equal, &maybe_undefined2, Label::kNear);
|
2011-01-19 10:17:18 +00:00
|
|
|
__ movsd(xmm0, FieldOperand(rdx, HeapNumber::kValueOffset));
|
2012-11-14 15:59:45 +00:00
|
|
|
__ jmp(&done);
|
|
|
|
__ bind(&left_smi);
|
|
|
|
__ SmiToInteger32(rcx, rdx); // Can't clobber rdx yet.
|
2013-09-13 07:59:48 +00:00
|
|
|
__ Cvtlsi2sd(xmm0, rcx);
|
2011-01-19 10:17:18 +00:00
|
|
|
|
2012-11-14 15:59:45 +00:00
|
|
|
__ bind(&done);
|
2011-01-19 10:17:18 +00:00
|
|
|
// Compare operands
|
|
|
|
__ ucomisd(xmm0, xmm1);
|
|
|
|
|
|
|
|
// Don't base result on EFLAGS when a NaN is involved.
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(parity_even, &unordered, Label::kNear);
|
2011-01-19 10:17:18 +00:00
|
|
|
|
|
|
|
// Return a result of -1, 0, or 1, based on EFLAGS.
|
|
|
|
// Performing mov, because xor would destroy the flag register.
|
|
|
|
__ movl(rax, Immediate(0));
|
|
|
|
__ movl(rcx, Immediate(0));
|
|
|
|
__ setcc(above, rax); // Add one to zero if carry clear and not equal.
|
|
|
|
__ sbbq(rax, rcx); // Subtract one if below (aka. carry set).
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&unordered);
|
|
|
|
__ bind(&generic_stub);
|
2012-11-14 15:59:45 +00:00
|
|
|
ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC,
|
|
|
|
CompareIC::GENERIC);
|
2013-02-27 12:33:24 +00:00
|
|
|
__ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET);
|
2011-01-19 10:17:18 +00:00
|
|
|
|
2012-03-02 13:40:14 +00:00
|
|
|
__ bind(&maybe_undefined1);
|
|
|
|
if (Token::IsOrderedRelationalCompareOp(op_)) {
|
|
|
|
__ Cmp(rax, masm->isolate()->factory()->undefined_value());
|
|
|
|
__ j(not_equal, &miss);
|
2012-11-14 15:59:45 +00:00
|
|
|
__ JumpIfSmi(rdx, &unordered);
|
2012-03-02 13:40:14 +00:00
|
|
|
__ CmpObjectType(rdx, HEAP_NUMBER_TYPE, rcx);
|
|
|
|
__ j(not_equal, &maybe_undefined2, Label::kNear);
|
|
|
|
__ jmp(&unordered);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&maybe_undefined2);
|
|
|
|
if (Token::IsOrderedRelationalCompareOp(op_)) {
|
|
|
|
__ Cmp(rdx, masm->isolate()->factory()->undefined_value());
|
|
|
|
__ j(equal, &unordered);
|
|
|
|
}
|
|
|
|
|
2011-01-19 10:17:18 +00:00
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::INTERNALIZED_STRING);
|
2011-05-09 13:30:04 +00:00
|
|
|
ASSERT(GetCondition() == equal);
|
|
|
|
|
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = rdx;
|
|
|
|
Register right = rax;
|
|
|
|
Register tmp1 = rcx;
|
|
|
|
Register tmp2 = rbx;
|
|
|
|
|
|
|
|
// Check that both operands are heap objects.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label miss;
|
2011-05-09 13:30:04 +00:00
|
|
|
Condition cond = masm->CheckEitherSmi(left, right, tmp1);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(cond, &miss, Label::kNear);
|
2011-05-09 13:30:04 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Check that both operands are internalized strings.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
|
|
|
|
__ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
|
2011-05-09 13:30:04 +00:00
|
|
|
__ movzxbq(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
|
|
|
|
__ movzxbq(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
|
2013-07-19 11:29:11 +00:00
|
|
|
STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0);
|
|
|
|
__ or_(tmp1, tmp2);
|
|
|
|
__ testb(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask));
|
|
|
|
__ j(not_zero, &miss, Label::kNear);
|
2011-05-09 13:30:04 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Internalized strings are compared by identity.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label done;
|
2011-05-09 13:30:04 +00:00
|
|
|
__ cmpq(left, right);
|
|
|
|
// Make sure rax is non-zero. At this point input operands are
|
|
|
|
// guaranteed to be non-zero.
|
|
|
|
ASSERT(right.is(rax));
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, &done, Label::kNear);
|
2011-05-09 13:30:04 +00:00
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ Move(rax, Smi::FromInt(EQUAL));
|
|
|
|
__ bind(&done);
|
|
|
|
__ ret(0);
|
|
|
|
|
2013-03-01 13:28:55 +00:00
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) {
|
|
|
|
ASSERT(state_ == CompareIC::UNIQUE_NAME);
|
|
|
|
ASSERT(GetCondition() == equal);
|
|
|
|
|
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = rdx;
|
|
|
|
Register right = rax;
|
|
|
|
Register tmp1 = rcx;
|
|
|
|
Register tmp2 = rbx;
|
|
|
|
|
|
|
|
// Check that both operands are heap objects.
|
|
|
|
Label miss;
|
|
|
|
Condition cond = masm->CheckEitherSmi(left, right, tmp1);
|
|
|
|
__ j(cond, &miss, Label::kNear);
|
|
|
|
|
|
|
|
// Check that both operands are unique names. This leaves the instance
|
|
|
|
// types loaded in tmp1 and tmp2.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
|
|
|
|
__ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
|
2013-03-01 13:28:55 +00:00
|
|
|
__ movzxbq(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
|
|
|
|
__ movzxbq(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
|
|
|
|
|
2013-06-27 13:39:44 +00:00
|
|
|
__ JumpIfNotUniqueName(tmp1, &miss, Label::kNear);
|
|
|
|
__ JumpIfNotUniqueName(tmp2, &miss, Label::kNear);
|
2013-03-01 13:28:55 +00:00
|
|
|
|
|
|
|
// Unique names are compared by identity.
|
|
|
|
Label done;
|
|
|
|
__ cmpq(left, right);
|
|
|
|
// Make sure rax is non-zero. At this point input operands are
|
|
|
|
// guaranteed to be non-zero.
|
|
|
|
ASSERT(right.is(rax));
|
|
|
|
__ j(not_equal, &done, Label::kNear);
|
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ Move(rax, Smi::FromInt(EQUAL));
|
|
|
|
__ bind(&done);
|
|
|
|
__ ret(0);
|
|
|
|
|
2011-05-09 13:30:04 +00:00
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-04 18:30:37 +00:00
|
|
|
void ICCompareStub::GenerateStrings(MacroAssembler* masm) {
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(state_ == CompareIC::STRING);
|
2011-05-04 18:30:37 +00:00
|
|
|
Label miss;
|
|
|
|
|
2012-03-09 13:12:59 +00:00
|
|
|
bool equality = Token::IsEqualityOp(op_);
|
|
|
|
|
2011-05-04 18:30:37 +00:00
|
|
|
// Registers containing left and right operands respectively.
|
|
|
|
Register left = rdx;
|
|
|
|
Register right = rax;
|
|
|
|
Register tmp1 = rcx;
|
|
|
|
Register tmp2 = rbx;
|
|
|
|
Register tmp3 = rdi;
|
|
|
|
|
|
|
|
// Check that both operands are heap objects.
|
|
|
|
Condition cond = masm->CheckEitherSmi(left, right, tmp1);
|
|
|
|
__ j(cond, &miss);
|
|
|
|
|
|
|
|
// Check that both operands are strings. This leaves the instance
|
|
|
|
// types loaded in tmp1 and tmp2.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(tmp1, FieldOperand(left, HeapObject::kMapOffset));
|
|
|
|
__ movp(tmp2, FieldOperand(right, HeapObject::kMapOffset));
|
2011-05-04 18:30:37 +00:00
|
|
|
__ movzxbq(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset));
|
|
|
|
__ movzxbq(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(tmp3, tmp1);
|
2011-05-04 18:30:37 +00:00
|
|
|
STATIC_ASSERT(kNotStringTag != 0);
|
|
|
|
__ or_(tmp3, tmp2);
|
2011-05-09 13:30:04 +00:00
|
|
|
__ testb(tmp3, Immediate(kIsNotStringMask));
|
2011-05-04 18:30:37 +00:00
|
|
|
__ j(not_zero, &miss);
|
|
|
|
|
|
|
|
// Fast check for identical strings.
|
2011-05-10 09:03:42 +00:00
|
|
|
Label not_same;
|
2011-05-04 18:30:37 +00:00
|
|
|
__ cmpq(left, right);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(not_equal, ¬_same, Label::kNear);
|
2011-05-04 18:30:37 +00:00
|
|
|
STATIC_ASSERT(EQUAL == 0);
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
__ Move(rax, Smi::FromInt(EQUAL));
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Handle not identical strings.
|
|
|
|
__ bind(¬_same);
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// Check that both strings are internalized strings. If they are, we're done
|
2013-06-27 13:39:44 +00:00
|
|
|
// because we already know they are not identical. We also know they are both
|
|
|
|
// strings.
|
2012-03-09 13:12:59 +00:00
|
|
|
if (equality) {
|
|
|
|
Label do_compare;
|
2013-07-19 11:29:11 +00:00
|
|
|
STATIC_ASSERT(kInternalizedTag == 0);
|
|
|
|
__ or_(tmp1, tmp2);
|
|
|
|
__ testb(tmp1, Immediate(kIsNotInternalizedMask));
|
|
|
|
__ j(not_zero, &do_compare, Label::kNear);
|
2012-03-09 13:12:59 +00:00
|
|
|
// Make sure rax is non-zero. At this point input operands are
|
|
|
|
// guaranteed to be non-zero.
|
|
|
|
ASSERT(right.is(rax));
|
|
|
|
__ ret(0);
|
|
|
|
__ bind(&do_compare);
|
|
|
|
}
|
2011-05-04 18:30:37 +00:00
|
|
|
|
|
|
|
// Check that both strings are sequential ASCII.
|
|
|
|
Label runtime;
|
|
|
|
__ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime);
|
|
|
|
|
|
|
|
// Compare flat ASCII strings. Returns when done.
|
2012-03-09 13:12:59 +00:00
|
|
|
if (equality) {
|
|
|
|
StringCompareStub::GenerateFlatAsciiStringEquals(
|
|
|
|
masm, left, right, tmp1, tmp2);
|
|
|
|
} else {
|
|
|
|
StringCompareStub::GenerateCompareFlatAsciiStrings(
|
|
|
|
masm, left, right, tmp1, tmp2, tmp3, kScratchRegister);
|
|
|
|
}
|
2011-05-04 18:30:37 +00:00
|
|
|
|
|
|
|
// Handle more complex cases in runtime.
|
|
|
|
__ bind(&runtime);
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PopReturnAddressTo(tmp1);
|
2011-05-04 18:30:37 +00:00
|
|
|
__ push(left);
|
|
|
|
__ push(right);
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PushReturnAddressFrom(tmp1);
|
2012-03-09 13:12:59 +00:00
|
|
|
if (equality) {
|
|
|
|
__ TailCallRuntime(Runtime::kStringEquals, 2, 1);
|
|
|
|
} else {
|
|
|
|
__ TailCallRuntime(Runtime::kStringCompare, 2, 1);
|
|
|
|
}
|
2011-05-04 18:30:37 +00:00
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
void ICCompareStub::GenerateObjects(MacroAssembler* masm) {
|
2012-11-14 15:59:45 +00:00
|
|
|
ASSERT(state_ == CompareIC::OBJECT);
|
2011-05-10 09:03:42 +00:00
|
|
|
Label miss;
|
2011-01-19 10:17:18 +00:00
|
|
|
Condition either_smi = masm->CheckEitherSmi(rdx, rax);
|
2011-05-10 09:03:42 +00:00
|
|
|
__ j(either_smi, &miss, Label::kNear);
|
2011-01-19 10:17:18 +00:00
|
|
|
|
|
|
|
__ CmpObjectType(rax, JS_OBJECT_TYPE, rcx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2011-01-19 10:17:18 +00:00
|
|
|
__ CmpObjectType(rdx, JS_OBJECT_TYPE, rcx);
|
2011-05-11 13:26:07 +00:00
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
2011-01-19 10:17:18 +00:00
|
|
|
|
|
|
|
ASSERT(GetCondition() == equal);
|
|
|
|
__ subq(rax, rdx);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-09 09:26:14 +00:00
|
|
|
void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) {
|
|
|
|
Label miss;
|
|
|
|
Condition either_smi = masm->CheckEitherSmi(rdx, rax);
|
|
|
|
__ j(either_smi, &miss, Label::kNear);
|
|
|
|
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, FieldOperand(rax, HeapObject::kMapOffset));
|
|
|
|
__ movp(rbx, FieldOperand(rdx, HeapObject::kMapOffset));
|
2011-12-09 09:26:14 +00:00
|
|
|
__ Cmp(rcx, known_map_);
|
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
|
|
|
__ Cmp(rbx, known_map_);
|
|
|
|
__ j(not_equal, &miss, Label::kNear);
|
|
|
|
|
|
|
|
__ subq(rax, rdx);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
__ bind(&miss);
|
|
|
|
GenerateMiss(masm);
|
|
|
|
}
|
|
|
|
|
2011-01-19 10:17:18 +00:00
|
|
|
|
2011-12-09 09:26:14 +00:00
|
|
|
void ICCompareStub::GenerateMiss(MacroAssembler* masm) {
|
2011-09-15 11:30:45 +00:00
|
|
|
{
|
2011-12-09 09:26:14 +00:00
|
|
|
// Call the runtime system in a fresh internal frame.
|
|
|
|
ExternalReference miss =
|
|
|
|
ExternalReference(IC_Utility(IC::kCompareIC_Miss), masm->isolate());
|
|
|
|
|
2011-09-15 11:30:45 +00:00
|
|
|
FrameScope scope(masm, StackFrame::INTERNAL);
|
|
|
|
__ push(rdx);
|
|
|
|
__ push(rax);
|
2011-12-09 09:26:14 +00:00
|
|
|
__ push(rdx);
|
|
|
|
__ push(rax);
|
2011-09-15 11:30:45 +00:00
|
|
|
__ Push(Smi::FromInt(op_));
|
|
|
|
__ CallExternalReference(miss, 3);
|
2011-01-19 10:17:18 +00:00
|
|
|
|
2011-12-09 09:26:14 +00:00
|
|
|
// Compute the entry point of the rewritten stub.
|
|
|
|
__ lea(rdi, FieldOperand(rax, Code::kHeaderSize));
|
|
|
|
__ pop(rax);
|
|
|
|
__ pop(rdx);
|
|
|
|
}
|
2011-01-19 10:17:18 +00:00
|
|
|
|
|
|
|
// Do a tail call to the rewritten stub.
|
|
|
|
__ jmp(rdi);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2011-02-03 12:50:50 +00:00
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm,
|
|
|
|
Label* miss,
|
|
|
|
Label* done,
|
|
|
|
Register properties,
|
|
|
|
Handle<Name> name,
|
|
|
|
Register r0) {
|
|
|
|
ASSERT(name->IsUniqueName());
|
2011-10-25 09:24:49 +00:00
|
|
|
// If names of slots in range from 1 to kProbes - 1 for the hash value are
|
|
|
|
// not equal to the name and kProbes-th slot is not used (its name is the
|
|
|
|
// undefined value), it guarantees the hash table doesn't contain the
|
|
|
|
// property. It's true even if some slots represent deleted properties
|
2012-02-28 08:32:44 +00:00
|
|
|
// (their names are the hole value).
|
2011-10-25 09:24:49 +00:00
|
|
|
for (int i = 0; i < kInlinedProbes; i++) {
|
|
|
|
// r0 points to properties hash.
|
|
|
|
// Compute the masked index: (hash + i + i * i) & mask.
|
|
|
|
Register index = r0;
|
|
|
|
// Capacity is smi 2^n.
|
|
|
|
__ SmiToInteger32(index, FieldOperand(properties, kCapacityOffset));
|
|
|
|
__ decl(index);
|
|
|
|
__ and_(index,
|
2013-03-04 15:00:57 +00:00
|
|
|
Immediate(name->Hash() + NameDictionary::GetProbeOffset(i)));
|
2011-10-25 09:24:49 +00:00
|
|
|
|
|
|
|
// Scale the index by multiplying by the entry size.
|
2013-03-04 15:00:57 +00:00
|
|
|
ASSERT(NameDictionary::kEntrySize == 3);
|
2011-10-25 09:24:49 +00:00
|
|
|
__ lea(index, Operand(index, index, times_2, 0)); // index *= 3.
|
|
|
|
|
|
|
|
Register entity_name = r0;
|
|
|
|
// Having undefined at this place means the name is not contained.
|
|
|
|
ASSERT_EQ(kSmiTagSize, 1);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(entity_name, Operand(properties,
|
2011-10-25 09:24:49 +00:00
|
|
|
index,
|
|
|
|
times_pointer_size,
|
|
|
|
kElementsStartOffset - kHeapObjectTag));
|
|
|
|
__ Cmp(entity_name, masm->isolate()->factory()->undefined_value());
|
|
|
|
__ j(equal, done);
|
|
|
|
|
|
|
|
// Stop if found the property.
|
2013-03-04 15:00:57 +00:00
|
|
|
__ Cmp(entity_name, Handle<Name>(name));
|
2011-10-25 09:24:49 +00:00
|
|
|
__ j(equal, miss);
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
Label good;
|
2012-02-28 08:32:44 +00:00
|
|
|
// Check for the hole and skip.
|
|
|
|
__ CompareRoot(entity_name, Heap::kTheHoleValueRootIndex);
|
2013-03-04 15:00:57 +00:00
|
|
|
__ j(equal, &good, Label::kNear);
|
2012-02-28 08:32:44 +00:00
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
// Check if the entry name is not a unique name.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset));
|
2013-06-27 13:39:44 +00:00
|
|
|
__ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset),
|
|
|
|
miss);
|
2013-03-04 15:00:57 +00:00
|
|
|
__ bind(&good);
|
2011-10-25 09:24:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP);
|
2011-10-25 09:24:49 +00:00
|
|
|
__ Push(Handle<Object>(name));
|
|
|
|
__ push(Immediate(name->Hash()));
|
|
|
|
__ CallStub(&stub);
|
|
|
|
__ testq(r0, r0);
|
|
|
|
__ j(not_zero, miss);
|
|
|
|
__ jmp(done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
// Probe the name dictionary in the |elements| register. Jump to the
|
2011-05-05 12:30:57 +00:00
|
|
|
// |done| label if a property with the given name is found leaving the
|
|
|
|
// index into the dictionary in |r1|. Jump to the |miss| label
|
|
|
|
// otherwise.
|
2013-03-04 15:00:57 +00:00
|
|
|
void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm,
|
|
|
|
Label* miss,
|
|
|
|
Label* done,
|
|
|
|
Register elements,
|
|
|
|
Register name,
|
|
|
|
Register r0,
|
|
|
|
Register r1) {
|
2011-10-27 07:59:12 +00:00
|
|
|
ASSERT(!elements.is(r0));
|
|
|
|
ASSERT(!elements.is(r1));
|
|
|
|
ASSERT(!name.is(r0));
|
|
|
|
ASSERT(!name.is(r1));
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
__ AssertName(name);
|
2011-05-05 12:30:57 +00:00
|
|
|
|
|
|
|
__ SmiToInteger32(r0, FieldOperand(elements, kCapacityOffset));
|
|
|
|
__ decl(r0);
|
|
|
|
|
|
|
|
for (int i = 0; i < kInlinedProbes; i++) {
|
|
|
|
// Compute the masked index: (hash + i + i * i) & mask.
|
2013-03-04 15:00:57 +00:00
|
|
|
__ movl(r1, FieldOperand(name, Name::kHashFieldOffset));
|
|
|
|
__ shrl(r1, Immediate(Name::kHashShift));
|
2011-05-05 12:30:57 +00:00
|
|
|
if (i > 0) {
|
2013-03-04 15:00:57 +00:00
|
|
|
__ addl(r1, Immediate(NameDictionary::GetProbeOffset(i)));
|
2011-05-05 12:30:57 +00:00
|
|
|
}
|
|
|
|
__ and_(r1, r0);
|
|
|
|
|
|
|
|
// Scale the index by multiplying by the entry size.
|
2013-03-04 15:00:57 +00:00
|
|
|
ASSERT(NameDictionary::kEntrySize == 3);
|
2011-05-05 12:30:57 +00:00
|
|
|
__ lea(r1, Operand(r1, r1, times_2, 0)); // r1 = r1 * 3
|
|
|
|
|
|
|
|
// Check if the key is identical to the name.
|
|
|
|
__ cmpq(name, Operand(elements, r1, times_pointer_size,
|
|
|
|
kElementsStartOffset - kHeapObjectTag));
|
|
|
|
__ j(equal, done);
|
|
|
|
}
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
NameDictionaryLookupStub stub(elements, r0, r1, POSITIVE_LOOKUP);
|
2011-05-05 12:30:57 +00:00
|
|
|
__ push(name);
|
2013-03-04 15:00:57 +00:00
|
|
|
__ movl(r0, FieldOperand(name, Name::kHashFieldOffset));
|
|
|
|
__ shrl(r0, Immediate(Name::kHashShift));
|
2011-05-05 12:30:57 +00:00
|
|
|
__ push(r0);
|
|
|
|
__ CallStub(&stub);
|
|
|
|
|
|
|
|
__ testq(r0, r0);
|
|
|
|
__ j(zero, miss);
|
|
|
|
__ jmp(done);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
void NameDictionaryLookupStub::Generate(MacroAssembler* masm) {
|
2011-09-15 11:30:45 +00:00
|
|
|
// This stub overrides SometimesSetsUpAFrame() to return false. That means
|
|
|
|
// we cannot call anything that could cause a GC from this stub.
|
2011-05-05 12:30:57 +00:00
|
|
|
// Stack frame on entry:
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0 * kPointerSize] : return address.
|
|
|
|
// rsp[1 * kPointerSize] : key's hash.
|
|
|
|
// rsp[2 * kPointerSize] : key.
|
2011-05-05 12:30:57 +00:00
|
|
|
// Registers:
|
2013-03-04 15:00:57 +00:00
|
|
|
// dictionary_: NameDictionary to probe.
|
2011-05-05 12:30:57 +00:00
|
|
|
// result_: used as scratch.
|
|
|
|
// index_: will hold an index of entry if lookup is successful.
|
|
|
|
// might alias with result_.
|
|
|
|
// Returns:
|
|
|
|
// result_ is zero if lookup failed, non zero otherwise.
|
|
|
|
|
|
|
|
Label in_dictionary, maybe_in_dictionary, not_in_dictionary;
|
|
|
|
|
|
|
|
Register scratch = result_;
|
|
|
|
|
|
|
|
__ SmiToInteger32(scratch, FieldOperand(dictionary_, kCapacityOffset));
|
|
|
|
__ decl(scratch);
|
|
|
|
__ push(scratch);
|
|
|
|
|
|
|
|
// If names of slots in range from 1 to kProbes - 1 for the hash value are
|
|
|
|
// not equal to the name and kProbes-th slot is not used (its name is the
|
|
|
|
// undefined value), it guarantees the hash table doesn't contain the
|
|
|
|
// property. It's true even if some slots represent deleted properties
|
|
|
|
// (their names are the null value).
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER,
|
|
|
|
kPointerSize);
|
2011-05-05 12:30:57 +00:00
|
|
|
for (int i = kInlinedProbes; i < kTotalProbes; i++) {
|
|
|
|
// Compute the masked index: (hash + i + i * i) & mask.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, args.GetArgumentOperand(1));
|
2011-05-05 12:30:57 +00:00
|
|
|
if (i > 0) {
|
2013-03-04 15:00:57 +00:00
|
|
|
__ addl(scratch, Immediate(NameDictionary::GetProbeOffset(i)));
|
2011-05-05 12:30:57 +00:00
|
|
|
}
|
|
|
|
__ and_(scratch, Operand(rsp, 0));
|
|
|
|
|
|
|
|
// Scale the index by multiplying by the entry size.
|
2013-03-04 15:00:57 +00:00
|
|
|
ASSERT(NameDictionary::kEntrySize == 3);
|
2011-05-05 12:30:57 +00:00
|
|
|
__ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3.
|
|
|
|
|
|
|
|
// Having undefined at this place means the name is not contained.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, Operand(dictionary_,
|
2011-05-05 12:30:57 +00:00
|
|
|
index_,
|
|
|
|
times_pointer_size,
|
|
|
|
kElementsStartOffset - kHeapObjectTag));
|
|
|
|
|
|
|
|
__ Cmp(scratch, masm->isolate()->factory()->undefined_value());
|
|
|
|
__ j(equal, ¬_in_dictionary);
|
|
|
|
|
|
|
|
// Stop if found the property.
|
2013-08-27 01:21:39 +00:00
|
|
|
__ cmpq(scratch, args.GetArgumentOperand(0));
|
2011-05-05 12:30:57 +00:00
|
|
|
__ j(equal, &in_dictionary);
|
|
|
|
|
|
|
|
if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) {
|
2013-03-04 15:00:57 +00:00
|
|
|
// If we hit a key that is not a unique name during negative
|
|
|
|
// lookup we have to bailout as this key might be equal to the
|
2011-05-05 12:30:57 +00:00
|
|
|
// key we are looking for.
|
|
|
|
|
2013-03-04 15:00:57 +00:00
|
|
|
// Check if the entry name is not a unique name.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, FieldOperand(scratch, HeapObject::kMapOffset));
|
2013-06-27 13:39:44 +00:00
|
|
|
__ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset),
|
|
|
|
&maybe_in_dictionary);
|
2011-05-05 12:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&maybe_in_dictionary);
|
|
|
|
// If we are doing negative lookup then probing failure should be
|
|
|
|
// treated as a lookup success. For positive lookup probing failure
|
|
|
|
// should be treated as lookup failure.
|
|
|
|
if (mode_ == POSITIVE_LOOKUP) {
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, Immediate(0));
|
2011-05-05 12:30:57 +00:00
|
|
|
__ Drop(1);
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&in_dictionary);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, Immediate(1));
|
2011-05-05 12:30:57 +00:00
|
|
|
__ Drop(1);
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
|
|
|
|
__ bind(¬_in_dictionary);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(scratch, Immediate(0));
|
2011-05-05 12:30:57 +00:00
|
|
|
__ Drop(1);
|
|
|
|
__ ret(2 * kPointerSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-27 12:33:24 +00:00
|
|
|
void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(
|
|
|
|
Isolate* isolate) {
|
2011-09-19 18:36:47 +00:00
|
|
|
StoreBufferOverflowStub stub1(kDontSaveFPRegs);
|
2013-12-02 09:46:35 +00:00
|
|
|
stub1.GetCode(isolate);
|
2011-09-19 18:36:47 +00:00
|
|
|
StoreBufferOverflowStub stub2(kSaveFPRegs);
|
2013-12-02 09:46:35 +00:00
|
|
|
stub2.GetCode(isolate);
|
2011-09-19 18:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-09-27 11:31:26 +00:00
|
|
|
bool CodeStub::CanUseFPRegisters() {
|
|
|
|
return true; // Always have SSE2 on x64.
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Takes the input in 3 registers: address_ value_ and object_. A pointer to
|
|
|
|
// the value has just been written into the object, now this stub makes sure
|
|
|
|
// we keep the GC informed. The word in the object where the value has been
|
|
|
|
// written is in the address register.
|
|
|
|
void RecordWriteStub::Generate(MacroAssembler* masm) {
|
|
|
|
Label skip_to_incremental_noncompacting;
|
|
|
|
Label skip_to_incremental_compacting;
|
|
|
|
|
|
|
|
// The first two instructions are generated with labels so as to get the
|
|
|
|
// offset fixed up correctly by the bind(Label*) call. We patch it back and
|
|
|
|
// forth between a compare instructions (a nop in this position) and the
|
|
|
|
// real branch when we start and stop incremental heap marking.
|
|
|
|
// See RecordWriteStub::Patch for details.
|
|
|
|
__ jmp(&skip_to_incremental_noncompacting, Label::kNear);
|
|
|
|
__ jmp(&skip_to_incremental_compacting, Label::kFar);
|
|
|
|
|
|
|
|
if (remembered_set_action_ == EMIT_REMEMBERED_SET) {
|
2011-09-20 13:32:27 +00:00
|
|
|
__ RememberedSetHelper(object_,
|
|
|
|
address_,
|
|
|
|
value_,
|
|
|
|
save_fp_regs_mode_,
|
|
|
|
MacroAssembler::kReturnAtEnd);
|
2011-09-19 18:36:47 +00:00
|
|
|
} else {
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&skip_to_incremental_noncompacting);
|
|
|
|
GenerateIncremental(masm, INCREMENTAL);
|
|
|
|
|
|
|
|
__ bind(&skip_to_incremental_compacting);
|
|
|
|
GenerateIncremental(masm, INCREMENTAL_COMPACTION);
|
|
|
|
|
|
|
|
// Initial mode of the stub is expected to be STORE_BUFFER_ONLY.
|
|
|
|
// Will be checked in IncrementalMarking::ActivateGeneratedStub.
|
|
|
|
masm->set_byte_at(0, kTwoByteNopInstruction);
|
|
|
|
masm->set_byte_at(2, kFiveByteNopInstruction);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) {
|
|
|
|
regs_.Save(masm);
|
|
|
|
|
|
|
|
if (remembered_set_action_ == EMIT_REMEMBERED_SET) {
|
|
|
|
Label dont_need_remembered_set;
|
|
|
|
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(regs_.scratch0(), Operand(regs_.address(), 0));
|
2011-09-19 18:36:47 +00:00
|
|
|
__ JumpIfNotInNewSpace(regs_.scratch0(),
|
|
|
|
regs_.scratch0(),
|
|
|
|
&dont_need_remembered_set);
|
|
|
|
|
|
|
|
__ CheckPageFlag(regs_.object(),
|
|
|
|
regs_.scratch0(),
|
|
|
|
1 << MemoryChunk::SCAN_ON_SCAVENGE,
|
|
|
|
not_zero,
|
|
|
|
&dont_need_remembered_set);
|
|
|
|
|
|
|
|
// First notify the incremental marker if necessary, then update the
|
|
|
|
// remembered set.
|
|
|
|
CheckNeedsToInformIncrementalMarker(
|
|
|
|
masm, kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, mode);
|
2014-03-03 13:27:59 +00:00
|
|
|
InformIncrementalMarker(masm);
|
2011-09-19 18:36:47 +00:00
|
|
|
regs_.Restore(masm);
|
2011-09-20 13:32:27 +00:00
|
|
|
__ RememberedSetHelper(object_,
|
|
|
|
address_,
|
|
|
|
value_,
|
|
|
|
save_fp_regs_mode_,
|
|
|
|
MacroAssembler::kReturnAtEnd);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
__ bind(&dont_need_remembered_set);
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckNeedsToInformIncrementalMarker(
|
|
|
|
masm, kReturnOnNoNeedToInformIncrementalMarker, mode);
|
2014-03-03 13:27:59 +00:00
|
|
|
InformIncrementalMarker(masm);
|
2011-09-19 18:36:47 +00:00
|
|
|
regs_.Restore(masm);
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-03 13:27:59 +00:00
|
|
|
void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm) {
|
2011-09-19 18:36:47 +00:00
|
|
|
regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_);
|
|
|
|
Register address =
|
2013-04-24 12:01:08 +00:00
|
|
|
arg_reg_1.is(regs_.address()) ? kScratchRegister : regs_.address();
|
2011-09-19 18:36:47 +00:00
|
|
|
ASSERT(!address.is(regs_.object()));
|
2013-04-24 12:01:08 +00:00
|
|
|
ASSERT(!address.is(arg_reg_1));
|
2011-09-19 18:36:47 +00:00
|
|
|
__ Move(address, regs_.address());
|
2013-04-24 12:01:08 +00:00
|
|
|
__ Move(arg_reg_1, regs_.object());
|
2012-11-22 07:05:20 +00:00
|
|
|
// TODO(gc) Can we just set address arg2 in the beginning?
|
2013-04-24 12:01:08 +00:00
|
|
|
__ Move(arg_reg_2, address);
|
|
|
|
__ LoadAddress(arg_reg_3,
|
|
|
|
ExternalReference::isolate_address(masm->isolate()));
|
2011-09-19 18:36:47 +00:00
|
|
|
int argument_count = 3;
|
|
|
|
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
__ PrepareCallCFunction(argument_count);
|
2014-03-03 13:27:59 +00:00
|
|
|
__ CallCFunction(
|
|
|
|
ExternalReference::incremental_marking_record_write_function(
|
|
|
|
masm->isolate()),
|
|
|
|
argument_count);
|
2011-09-19 18:36:47 +00:00
|
|
|
regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void RecordWriteStub::CheckNeedsToInformIncrementalMarker(
|
|
|
|
MacroAssembler* masm,
|
|
|
|
OnNoNeedToInformIncrementalMarker on_no_need,
|
|
|
|
Mode mode) {
|
|
|
|
Label on_black;
|
|
|
|
Label need_incremental;
|
|
|
|
Label need_incremental_pop_object;
|
|
|
|
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask));
|
2012-09-26 11:35:42 +00:00
|
|
|
__ and_(regs_.scratch0(), regs_.object());
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(regs_.scratch1(),
|
2012-09-26 11:35:42 +00:00
|
|
|
Operand(regs_.scratch0(),
|
|
|
|
MemoryChunk::kWriteBarrierCounterOffset));
|
|
|
|
__ subq(regs_.scratch1(), Immediate(1));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(Operand(regs_.scratch0(),
|
2012-09-26 11:35:42 +00:00
|
|
|
MemoryChunk::kWriteBarrierCounterOffset),
|
|
|
|
regs_.scratch1());
|
|
|
|
__ j(negative, &need_incremental);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
// Let's look at the color of the object: If it is not black we don't have
|
|
|
|
// to inform the incremental marker.
|
|
|
|
__ JumpIfBlack(regs_.object(),
|
|
|
|
regs_.scratch0(),
|
|
|
|
regs_.scratch1(),
|
|
|
|
&on_black,
|
|
|
|
Label::kNear);
|
|
|
|
|
|
|
|
regs_.Restore(masm);
|
|
|
|
if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
|
2011-09-20 13:32:27 +00:00
|
|
|
__ RememberedSetHelper(object_,
|
|
|
|
address_,
|
|
|
|
value_,
|
|
|
|
save_fp_regs_mode_,
|
|
|
|
MacroAssembler::kReturnAtEnd);
|
2011-09-19 18:36:47 +00:00
|
|
|
} else {
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&on_black);
|
|
|
|
|
|
|
|
// Get the value from the slot.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(regs_.scratch0(), Operand(regs_.address(), 0));
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
if (mode == INCREMENTAL_COMPACTION) {
|
|
|
|
Label ensure_not_white;
|
|
|
|
|
|
|
|
__ CheckPageFlag(regs_.scratch0(), // Contains value.
|
|
|
|
regs_.scratch1(), // Scratch.
|
|
|
|
MemoryChunk::kEvacuationCandidateMask,
|
|
|
|
zero,
|
|
|
|
&ensure_not_white,
|
|
|
|
Label::kNear);
|
|
|
|
|
|
|
|
__ CheckPageFlag(regs_.object(),
|
|
|
|
regs_.scratch1(), // Scratch.
|
|
|
|
MemoryChunk::kSkipEvacuationSlotsRecordingMask,
|
|
|
|
zero,
|
|
|
|
&need_incremental);
|
|
|
|
|
|
|
|
__ bind(&ensure_not_white);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We need an extra register for this, so we push the object register
|
|
|
|
// temporarily.
|
|
|
|
__ push(regs_.object());
|
|
|
|
__ EnsureNotWhite(regs_.scratch0(), // The value.
|
|
|
|
regs_.scratch1(), // Scratch.
|
|
|
|
regs_.object(), // Scratch.
|
|
|
|
&need_incremental_pop_object,
|
|
|
|
Label::kNear);
|
|
|
|
__ pop(regs_.object());
|
|
|
|
|
|
|
|
regs_.Restore(masm);
|
|
|
|
if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) {
|
2011-09-20 13:32:27 +00:00
|
|
|
__ RememberedSetHelper(object_,
|
|
|
|
address_,
|
|
|
|
value_,
|
|
|
|
save_fp_regs_mode_,
|
|
|
|
MacroAssembler::kReturnAtEnd);
|
2011-09-19 18:36:47 +00:00
|
|
|
} else {
|
|
|
|
__ ret(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&need_incremental_pop_object);
|
|
|
|
__ pop(regs_.object());
|
|
|
|
|
|
|
|
__ bind(&need_incremental);
|
|
|
|
|
|
|
|
// Fall through when we need to inform the incremental marker.
|
|
|
|
}
|
|
|
|
|
2011-11-08 10:10:24 +00:00
|
|
|
|
|
|
|
void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
2013-07-03 15:36:49 +00:00
|
|
|
// -- rax : element value to store
|
|
|
|
// -- rcx : element index as smi
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -- rsp[8] : array literal index in function
|
|
|
|
// -- rsp[16] : array literal
|
2013-06-14 06:06:00 +00:00
|
|
|
// clobbers rbx, rdx, rdi
|
2011-11-08 10:10:24 +00:00
|
|
|
// -----------------------------------
|
|
|
|
|
|
|
|
Label element_done;
|
|
|
|
Label double_elements;
|
|
|
|
Label smi_element;
|
|
|
|
Label slow_elements;
|
|
|
|
Label fast_elements;
|
|
|
|
|
2013-06-14 06:06:00 +00:00
|
|
|
// Get array literal index, array literal and its map.
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 2, ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rdx, args.GetArgumentOperand(1));
|
|
|
|
__ movp(rbx, args.GetArgumentOperand(0));
|
|
|
|
__ movp(rdi, FieldOperand(rbx, JSObject::kMapOffset));
|
2013-06-14 06:06:00 +00:00
|
|
|
|
2011-11-11 14:49:16 +00:00
|
|
|
__ CheckFastElements(rdi, &double_elements);
|
2011-11-08 10:10:24 +00:00
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
// FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS
|
2011-11-11 14:49:16 +00:00
|
|
|
__ JumpIfSmi(rax, &smi_element);
|
2012-05-23 14:24:29 +00:00
|
|
|
__ CheckFastSmiElements(rdi, &fast_elements);
|
2011-11-08 10:10:24 +00:00
|
|
|
|
2011-11-11 14:49:16 +00:00
|
|
|
// Store into the array literal requires a elements transition. Call into
|
|
|
|
// the runtime.
|
2011-11-08 10:10:24 +00:00
|
|
|
|
|
|
|
__ bind(&slow_elements);
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PopReturnAddressTo(rdi);
|
2011-11-08 10:10:24 +00:00
|
|
|
__ push(rbx);
|
|
|
|
__ push(rcx);
|
|
|
|
__ push(rax);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
|
2011-11-08 10:10:24 +00:00
|
|
|
__ push(FieldOperand(rbx, JSFunction::kLiteralsOffset));
|
|
|
|
__ push(rdx);
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PushReturnAddressFrom(rdi);
|
2011-11-08 13:16:56 +00:00
|
|
|
__ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1);
|
2011-11-08 10:10:24 +00:00
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
// Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object.
|
2011-11-11 14:49:16 +00:00
|
|
|
__ bind(&fast_elements);
|
|
|
|
__ SmiToInteger32(kScratchRegister, rcx);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
|
2011-11-11 14:49:16 +00:00
|
|
|
__ lea(rcx, FieldOperand(rbx, kScratchRegister, times_pointer_size,
|
|
|
|
FixedArrayBase::kHeaderSize));
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(Operand(rcx, 0), rax);
|
2011-11-11 14:49:16 +00:00
|
|
|
// Update the write barrier for the array store.
|
|
|
|
__ RecordWrite(rbx, rcx, rax,
|
|
|
|
kDontSaveFPRegs,
|
|
|
|
EMIT_REMEMBERED_SET,
|
|
|
|
OMIT_SMI_CHECK);
|
|
|
|
__ ret(0);
|
|
|
|
|
2012-05-23 14:24:29 +00:00
|
|
|
// Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or
|
|
|
|
// FAST_*_ELEMENTS, and value is Smi.
|
2011-11-11 14:49:16 +00:00
|
|
|
__ bind(&smi_element);
|
|
|
|
__ SmiToInteger32(kScratchRegister, rcx);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, FieldOperand(rbx, JSObject::kElementsOffset));
|
|
|
|
__ movp(FieldOperand(rbx, kScratchRegister, times_pointer_size,
|
2011-11-11 14:49:16 +00:00
|
|
|
FixedArrayBase::kHeaderSize), rax);
|
|
|
|
__ ret(0);
|
|
|
|
|
|
|
|
// Array literal has ElementsKind of FAST_DOUBLE_ELEMENTS.
|
|
|
|
__ bind(&double_elements);
|
|
|
|
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(r9, FieldOperand(rbx, JSObject::kElementsOffset));
|
2011-11-11 14:49:16 +00:00
|
|
|
__ SmiToInteger32(r11, rcx);
|
|
|
|
__ StoreNumberToDoubleElements(rax,
|
|
|
|
r9,
|
|
|
|
r11,
|
|
|
|
xmm0,
|
|
|
|
&slow_elements);
|
|
|
|
__ ret(0);
|
2011-11-08 10:10:24 +00:00
|
|
|
}
|
|
|
|
|
2012-07-17 15:18:15 +00:00
|
|
|
|
2013-01-29 09:12:20 +00:00
|
|
|
void StubFailureTrampolineStub::Generate(MacroAssembler* masm) {
|
2013-04-04 17:55:43 +00:00
|
|
|
CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs);
|
2013-02-27 12:33:24 +00:00
|
|
|
__ Call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET);
|
2013-02-05 08:09:32 +00:00
|
|
|
int parameter_count_offset =
|
|
|
|
StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset;
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rbx, MemOperand(rbp, parameter_count_offset));
|
2013-01-29 09:12:20 +00:00
|
|
|
masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE);
|
2013-08-02 13:42:02 +00:00
|
|
|
__ PopReturnAddressTo(rcx);
|
2013-04-02 11:28:01 +00:00
|
|
|
int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE
|
|
|
|
? kPointerSize
|
|
|
|
: 0;
|
|
|
|
__ lea(rsp, MemOperand(rsp, rbx, times_pointer_size, additional_offset));
|
2013-02-05 08:09:32 +00:00
|
|
|
__ jmp(rcx); // Return to IC Miss stub, continuation still on stack.
|
2013-01-29 09:12:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-07-17 15:18:15 +00:00
|
|
|
void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) {
|
2013-06-28 13:40:41 +00:00
|
|
|
if (masm->isolate()->function_entry_hook() != NULL) {
|
2012-07-17 15:18:15 +00:00
|
|
|
ProfileEntryHookStub stub;
|
|
|
|
masm->CallStub(&stub);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ProfileEntryHookStub::Generate(MacroAssembler* masm) {
|
2013-06-28 13:40:41 +00:00
|
|
|
// This stub can be called from essentially anywhere, so it needs to save
|
|
|
|
// all volatile and callee-save registers.
|
|
|
|
const size_t kNumSavedRegisters = 2;
|
|
|
|
__ push(arg_reg_1);
|
|
|
|
__ push(arg_reg_2);
|
2012-07-17 15:18:15 +00:00
|
|
|
|
|
|
|
// Calculate the original stack pointer and store it in the second arg.
|
2014-01-20 01:52:21 +00:00
|
|
|
__ lea(arg_reg_2,
|
|
|
|
Operand(rsp, kNumSavedRegisters * kRegisterSize + kPCOnStackSize));
|
2012-07-17 15:18:15 +00:00
|
|
|
|
|
|
|
// Calculate the function address to the first arg.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(arg_reg_1, Operand(rsp, kNumSavedRegisters * kRegisterSize));
|
2013-06-28 13:40:41 +00:00
|
|
|
__ subq(arg_reg_1, Immediate(Assembler::kShortCallInstructionLength));
|
|
|
|
|
|
|
|
// Save the remainder of the volatile registers.
|
|
|
|
masm->PushCallerSaved(kSaveFPRegs, arg_reg_1, arg_reg_2);
|
2012-07-17 15:18:15 +00:00
|
|
|
|
|
|
|
// Call the entry hook function.
|
2014-01-08 07:02:02 +00:00
|
|
|
__ Move(rax, FUNCTION_ADDR(masm->isolate()->function_entry_hook()),
|
2014-01-24 01:45:53 +00:00
|
|
|
Assembler::RelocInfoNone());
|
2012-07-17 15:18:15 +00:00
|
|
|
|
|
|
|
AllowExternalCallThatCantCauseGC scope(masm);
|
|
|
|
|
|
|
|
const int kArgumentCount = 2;
|
|
|
|
__ PrepareCallCFunction(kArgumentCount);
|
|
|
|
__ CallCFunction(rax, kArgumentCount);
|
|
|
|
|
|
|
|
// Restore volatile regs.
|
2013-06-28 13:40:41 +00:00
|
|
|
masm->PopCallerSaved(kSaveFPRegs, arg_reg_1, arg_reg_2);
|
|
|
|
__ pop(arg_reg_2);
|
|
|
|
__ pop(arg_reg_1);
|
2012-07-17 15:18:15 +00:00
|
|
|
|
|
|
|
__ Ret();
|
|
|
|
}
|
|
|
|
|
2013-04-25 16:00:32 +00:00
|
|
|
|
|
|
|
template<class T>
|
2013-09-12 17:59:41 +00:00
|
|
|
static void CreateArrayDispatch(MacroAssembler* masm,
|
|
|
|
AllocationSiteOverrideMode mode) {
|
|
|
|
if (mode == DISABLE_ALLOCATION_SITES) {
|
2014-01-09 15:07:23 +00:00
|
|
|
T stub(GetInitialFastElementsKind(), mode);
|
2013-04-25 16:00:32 +00:00
|
|
|
__ TailCallStub(&stub);
|
2013-09-12 17:59:41 +00:00
|
|
|
} else if (mode == DONT_OVERRIDE) {
|
|
|
|
int last_index = GetSequenceIndexFromFastElementsKind(
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND);
|
|
|
|
for (int i = 0; i <= last_index; ++i) {
|
|
|
|
Label next;
|
|
|
|
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
|
|
|
|
__ cmpl(rdx, Immediate(kind));
|
|
|
|
__ j(not_equal, &next);
|
|
|
|
T stub(kind);
|
|
|
|
__ TailCallStub(&stub);
|
|
|
|
__ bind(&next);
|
|
|
|
}
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2013-09-12 17:59:41 +00:00
|
|
|
// If we reached this point there is a problem.
|
|
|
|
__ Abort(kUnexpectedElementsKindInArrayConstructor);
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2013-04-25 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-12 17:59:41 +00:00
|
|
|
static void CreateArrayDispatchOneArgument(MacroAssembler* masm,
|
|
|
|
AllocationSiteOverrideMode mode) {
|
2014-01-21 16:04:39 +00:00
|
|
|
// rbx - allocation site (if mode != DISABLE_ALLOCATION_SITES)
|
2013-09-12 17:59:41 +00:00
|
|
|
// rdx - kind (if mode != DISABLE_ALLOCATION_SITES)
|
2013-04-25 16:00:32 +00:00
|
|
|
// rax - number of arguments
|
|
|
|
// rdi - constructor?
|
2013-07-03 15:36:49 +00:00
|
|
|
// rsp[0] - return address
|
|
|
|
// rsp[8] - last argument
|
2013-04-25 16:00:32 +00:00
|
|
|
Handle<Object> undefined_sentinel(
|
|
|
|
masm->isolate()->heap()->undefined_value(),
|
|
|
|
masm->isolate());
|
|
|
|
|
|
|
|
Label normal_sequence;
|
2013-09-12 17:59:41 +00:00
|
|
|
if (mode == DONT_OVERRIDE) {
|
|
|
|
ASSERT(FAST_SMI_ELEMENTS == 0);
|
|
|
|
ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1);
|
|
|
|
ASSERT(FAST_ELEMENTS == 2);
|
|
|
|
ASSERT(FAST_HOLEY_ELEMENTS == 3);
|
|
|
|
ASSERT(FAST_DOUBLE_ELEMENTS == 4);
|
|
|
|
ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5);
|
|
|
|
|
|
|
|
// is the low bit set? If so, we are holey and that is good.
|
|
|
|
__ testb(rdx, Immediate(1));
|
|
|
|
__ j(not_zero, &normal_sequence);
|
|
|
|
}
|
2013-04-25 16:00:32 +00:00
|
|
|
|
|
|
|
// look at the first argument
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 1, ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, args.GetArgumentOperand(0));
|
2013-04-25 16:00:32 +00:00
|
|
|
__ testq(rcx, rcx);
|
|
|
|
__ j(zero, &normal_sequence);
|
|
|
|
|
2013-09-12 17:59:41 +00:00
|
|
|
if (mode == DISABLE_ALLOCATION_SITES) {
|
|
|
|
ElementsKind initial = GetInitialFastElementsKind();
|
|
|
|
ElementsKind holey_initial = GetHoleyElementsKind(initial);
|
2013-06-28 13:16:14 +00:00
|
|
|
|
2013-09-12 17:59:41 +00:00
|
|
|
ArraySingleArgumentConstructorStub stub_holey(holey_initial,
|
|
|
|
DISABLE_ALLOCATION_SITES);
|
|
|
|
__ TailCallStub(&stub_holey);
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2013-09-12 17:59:41 +00:00
|
|
|
__ bind(&normal_sequence);
|
|
|
|
ArraySingleArgumentConstructorStub stub(initial,
|
|
|
|
DISABLE_ALLOCATION_SITES);
|
2013-04-25 16:00:32 +00:00
|
|
|
__ TailCallStub(&stub);
|
2013-09-12 17:59:41 +00:00
|
|
|
} else if (mode == DONT_OVERRIDE) {
|
|
|
|
// We are going to create a holey array, but our kind is non-holey.
|
2014-02-10 21:38:17 +00:00
|
|
|
// Fix kind and retry (only if we have an allocation site in the slot).
|
2013-09-12 17:59:41 +00:00
|
|
|
__ incl(rdx);
|
2014-01-21 16:04:39 +00:00
|
|
|
|
2013-09-12 17:59:41 +00:00
|
|
|
if (FLAG_debug_code) {
|
2013-09-20 09:27:40 +00:00
|
|
|
Handle<Map> allocation_site_map =
|
|
|
|
masm->isolate()->factory()->allocation_site_map();
|
2014-01-21 16:04:39 +00:00
|
|
|
__ Cmp(FieldOperand(rbx, 0), allocation_site_map);
|
|
|
|
__ Assert(equal, kExpectedAllocationSite);
|
2013-09-12 17:59:41 +00:00
|
|
|
}
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2013-11-14 12:05:09 +00:00
|
|
|
// Save the resulting elements kind in type info. We can't just store r3
|
|
|
|
// in the AllocationSite::transition_info field because elements kind is
|
|
|
|
// restricted to a portion of the field...upper bits need to be left alone.
|
|
|
|
STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
|
2014-01-21 16:04:39 +00:00
|
|
|
__ SmiAddConstant(FieldOperand(rbx, AllocationSite::kTransitionInfoOffset),
|
2013-11-14 12:05:09 +00:00
|
|
|
Smi::FromInt(kFastElementsKindPackedToHoley));
|
2013-09-12 17:59:41 +00:00
|
|
|
|
|
|
|
__ bind(&normal_sequence);
|
|
|
|
int last_index = GetSequenceIndexFromFastElementsKind(
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND);
|
|
|
|
for (int i = 0; i <= last_index; ++i) {
|
|
|
|
Label next;
|
|
|
|
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
|
|
|
|
__ cmpl(rdx, Immediate(kind));
|
|
|
|
__ j(not_equal, &next);
|
|
|
|
ArraySingleArgumentConstructorStub stub(kind);
|
|
|
|
__ TailCallStub(&stub);
|
|
|
|
__ bind(&next);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reached this point there is a problem.
|
|
|
|
__ Abort(kUnexpectedElementsKindInArrayConstructor);
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2013-04-25 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) {
|
|
|
|
int to_index = GetSequenceIndexFromFastElementsKind(
|
|
|
|
TERMINAL_FAST_ELEMENTS_KIND);
|
|
|
|
for (int i = 0; i <= to_index; ++i) {
|
|
|
|
ElementsKind kind = GetFastElementsKindFromSequenceIndex(i);
|
|
|
|
T stub(kind);
|
2013-12-02 09:46:35 +00:00
|
|
|
stub.GetCode(isolate);
|
2014-01-07 15:58:25 +00:00
|
|
|
if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) {
|
2014-01-09 15:07:23 +00:00
|
|
|
T stub1(kind, DISABLE_ALLOCATION_SITES);
|
2013-12-02 09:46:35 +00:00
|
|
|
stub1.GetCode(isolate);
|
2013-06-04 12:48:51 +00:00
|
|
|
}
|
2013-04-25 16:00:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) {
|
|
|
|
ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>(
|
|
|
|
isolate);
|
|
|
|
ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>(
|
|
|
|
isolate);
|
|
|
|
ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>(
|
|
|
|
isolate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime(
|
|
|
|
Isolate* isolate) {
|
|
|
|
ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS };
|
|
|
|
for (int i = 0; i < 2; i++) {
|
|
|
|
// For internal arrays we only need a few things
|
|
|
|
InternalArrayNoArgumentConstructorStub stubh1(kinds[i]);
|
2013-12-02 09:46:35 +00:00
|
|
|
stubh1.GetCode(isolate);
|
2013-06-05 10:43:18 +00:00
|
|
|
InternalArraySingleArgumentConstructorStub stubh2(kinds[i]);
|
2013-12-02 09:46:35 +00:00
|
|
|
stubh2.GetCode(isolate);
|
2013-06-05 10:43:18 +00:00
|
|
|
InternalArrayNArgumentsConstructorStub stubh3(kinds[i]);
|
2013-12-02 09:46:35 +00:00
|
|
|
stubh3.GetCode(isolate);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2013-09-12 17:59:41 +00:00
|
|
|
void ArrayConstructorStub::GenerateDispatchToArrayStub(
|
|
|
|
MacroAssembler* masm,
|
|
|
|
AllocationSiteOverrideMode mode) {
|
|
|
|
if (argument_count_ == ANY) {
|
|
|
|
Label not_zero_case, not_one_case;
|
|
|
|
__ testq(rax, rax);
|
|
|
|
__ j(not_zero, ¬_zero_case);
|
|
|
|
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
|
|
|
|
|
|
|
|
__ bind(¬_zero_case);
|
|
|
|
__ cmpl(rax, Immediate(1));
|
|
|
|
__ j(greater, ¬_one_case);
|
|
|
|
CreateArrayDispatchOneArgument(masm, mode);
|
|
|
|
|
|
|
|
__ bind(¬_one_case);
|
|
|
|
CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
|
|
|
|
} else if (argument_count_ == NONE) {
|
|
|
|
CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode);
|
|
|
|
} else if (argument_count_ == ONE) {
|
|
|
|
CreateArrayDispatchOneArgument(masm, mode);
|
|
|
|
} else if (argument_count_ == MORE_THAN_ONE) {
|
|
|
|
CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode);
|
|
|
|
} else {
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-25 16:00:32 +00:00
|
|
|
void ArrayConstructorStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
2013-07-03 15:36:49 +00:00
|
|
|
// -- rax : argc
|
2014-03-07 09:10:18 +00:00
|
|
|
// -- rbx : feedback vector (fixed array or megamorphic symbol)
|
2014-02-10 21:38:17 +00:00
|
|
|
// -- rdx : slot index (if ebx is fixed array)
|
2013-07-03 15:36:49 +00:00
|
|
|
// -- rdi : constructor
|
2013-04-25 16:00:32 +00:00
|
|
|
// -- rsp[0] : return address
|
2013-07-03 15:36:49 +00:00
|
|
|
// -- rsp[8] : last argument
|
2013-04-25 16:00:32 +00:00
|
|
|
// -----------------------------------
|
2014-03-07 09:10:18 +00:00
|
|
|
Handle<Object> megamorphic_sentinel =
|
|
|
|
TypeFeedbackInfo::MegamorphicSentinel(masm->isolate());
|
2013-04-25 16:00:32 +00:00
|
|
|
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// The array construct code is only set for the global and natives
|
|
|
|
// builtin Array functions which always have maps.
|
|
|
|
|
|
|
|
// Initial map for the builtin Array function should be a map.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
|
2013-04-25 16:00:32 +00:00
|
|
|
// Will both indicate a NULL and a Smi.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
Condition not_smi = NegateCondition(masm->CheckSmi(rcx));
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Check(not_smi, kUnexpectedInitialMapForArrayFunction);
|
2013-04-25 16:00:32 +00:00
|
|
|
__ CmpObjectType(rcx, MAP_TYPE, rcx);
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Check(equal, kUnexpectedInitialMapForArrayFunction);
|
2013-04-25 16:00:32 +00:00
|
|
|
|
2014-03-07 09:10:18 +00:00
|
|
|
// We should either have the megamorphic symbol in rbx or a valid
|
|
|
|
// fixed array.
|
2013-04-25 16:00:32 +00:00
|
|
|
Label okay_here;
|
2014-02-10 21:38:17 +00:00
|
|
|
Handle<Map> fixed_array_map = masm->isolate()->factory()->fixed_array_map();
|
2014-03-07 09:10:18 +00:00
|
|
|
__ Cmp(rbx, megamorphic_sentinel);
|
2013-04-25 16:00:32 +00:00
|
|
|
__ j(equal, &okay_here);
|
2014-02-10 21:38:17 +00:00
|
|
|
__ Cmp(FieldOperand(rbx, 0), fixed_array_map);
|
|
|
|
__ Assert(equal, kExpectedFixedArrayInRegisterRbx);
|
|
|
|
|
2014-03-07 09:10:18 +00:00
|
|
|
// rdx should be a smi if we don't have the megamorphic symbol in rbx.
|
2014-02-10 21:38:17 +00:00
|
|
|
__ AssertSmi(rdx);
|
|
|
|
|
2013-04-25 16:00:32 +00:00
|
|
|
__ bind(&okay_here);
|
|
|
|
}
|
|
|
|
|
2013-09-12 17:59:41 +00:00
|
|
|
Label no_info;
|
2014-03-07 09:10:18 +00:00
|
|
|
// If the feedback slot is the megamorphic sentinel, or contains anything
|
|
|
|
// other than an AllocationSite, call an array constructor that doesn't use
|
|
|
|
// AllocationSites.
|
|
|
|
__ Cmp(rbx, megamorphic_sentinel);
|
2013-06-25 16:31:07 +00:00
|
|
|
__ j(equal, &no_info);
|
2014-02-10 21:38:17 +00:00
|
|
|
__ SmiToInteger32(rdx, rdx);
|
|
|
|
__ movp(rbx, FieldOperand(rbx, rdx, times_pointer_size,
|
|
|
|
FixedArray::kHeaderSize));
|
|
|
|
__ Integer32ToSmi(rdx, rdx);
|
2014-01-21 16:04:39 +00:00
|
|
|
__ Cmp(FieldOperand(rbx, 0),
|
2013-09-20 09:27:40 +00:00
|
|
|
masm->isolate()->factory()->allocation_site_map());
|
2013-07-08 14:41:54 +00:00
|
|
|
__ j(not_equal, &no_info);
|
2013-07-08 10:02:16 +00:00
|
|
|
|
2013-11-14 12:05:09 +00:00
|
|
|
// Only look at the lower 16 bits of the transition info.
|
2014-01-21 16:04:39 +00:00
|
|
|
__ movp(rdx, FieldOperand(rbx, AllocationSite::kTransitionInfoOffset));
|
2013-06-25 16:31:07 +00:00
|
|
|
__ SmiToInteger32(rdx, rdx);
|
2013-11-14 12:05:09 +00:00
|
|
|
STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0);
|
|
|
|
__ and_(rdx, Immediate(AllocationSite::ElementsKindBits::kMask));
|
2013-09-12 17:59:41 +00:00
|
|
|
GenerateDispatchToArrayStub(masm, DONT_OVERRIDE);
|
2013-06-25 16:31:07 +00:00
|
|
|
|
2013-09-12 17:59:41 +00:00
|
|
|
__ bind(&no_info);
|
|
|
|
GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES);
|
2013-04-25 16:00:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-05 10:43:18 +00:00
|
|
|
void InternalArrayConstructorStub::GenerateCase(
|
|
|
|
MacroAssembler* masm, ElementsKind kind) {
|
|
|
|
Label not_zero_case, not_one_case;
|
|
|
|
Label normal_sequence;
|
|
|
|
|
|
|
|
__ testq(rax, rax);
|
|
|
|
__ j(not_zero, ¬_zero_case);
|
|
|
|
InternalArrayNoArgumentConstructorStub stub0(kind);
|
|
|
|
__ TailCallStub(&stub0);
|
|
|
|
|
|
|
|
__ bind(¬_zero_case);
|
|
|
|
__ cmpl(rax, Immediate(1));
|
|
|
|
__ j(greater, ¬_one_case);
|
|
|
|
|
|
|
|
if (IsFastPackedElementsKind(kind)) {
|
|
|
|
// We might need to create a holey array
|
|
|
|
// look at the first argument
|
2013-08-27 01:21:39 +00:00
|
|
|
StackArgumentsAccessor args(rsp, 1, ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, args.GetArgumentOperand(0));
|
2013-06-05 10:43:18 +00:00
|
|
|
__ testq(rcx, rcx);
|
|
|
|
__ j(zero, &normal_sequence);
|
|
|
|
|
|
|
|
InternalArraySingleArgumentConstructorStub
|
|
|
|
stub1_holey(GetHoleyElementsKind(kind));
|
|
|
|
__ TailCallStub(&stub1_holey);
|
|
|
|
}
|
|
|
|
|
|
|
|
__ bind(&normal_sequence);
|
|
|
|
InternalArraySingleArgumentConstructorStub stub1(kind);
|
|
|
|
__ TailCallStub(&stub1);
|
|
|
|
|
|
|
|
__ bind(¬_one_case);
|
|
|
|
InternalArrayNArgumentsConstructorStub stubN(kind);
|
|
|
|
__ TailCallStub(&stubN);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InternalArrayConstructorStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
2013-07-03 15:36:49 +00:00
|
|
|
// -- rax : argc
|
|
|
|
// -- rdi : constructor
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -- rsp[8] : last argument
|
2013-06-05 10:43:18 +00:00
|
|
|
// -----------------------------------
|
|
|
|
|
|
|
|
if (FLAG_debug_code) {
|
|
|
|
// The array construct code is only set for the global and natives
|
|
|
|
// builtin Array functions which always have maps.
|
|
|
|
|
|
|
|
// Initial map for the builtin Array function should be a map.
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
|
2013-06-05 10:43:18 +00:00
|
|
|
// Will both indicate a NULL and a Smi.
|
|
|
|
STATIC_ASSERT(kSmiTag == 0);
|
|
|
|
Condition not_smi = NegateCondition(masm->CheckSmi(rcx));
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Check(not_smi, kUnexpectedInitialMapForArrayFunction);
|
2013-06-05 10:43:18 +00:00
|
|
|
__ CmpObjectType(rcx, MAP_TYPE, rcx);
|
2013-08-02 09:53:11 +00:00
|
|
|
__ Check(equal, kUnexpectedInitialMapForArrayFunction);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 16:31:07 +00:00
|
|
|
// Figure out the right elements kind
|
2014-01-20 04:59:40 +00:00
|
|
|
__ movp(rcx, FieldOperand(rdi, JSFunction::kPrototypeOrInitialMapOffset));
|
2013-06-05 10:43:18 +00:00
|
|
|
|
2013-06-25 16:31:07 +00:00
|
|
|
// Load the map's "bit field 2" into |result|. We only need the first byte,
|
|
|
|
// but the following masking takes care of that anyway.
|
|
|
|
__ movzxbq(rcx, FieldOperand(rcx, Map::kBitField2Offset));
|
|
|
|
// Retrieve elements_kind from bit field 2.
|
|
|
|
__ and_(rcx, Immediate(Map::kElementsKindMask));
|
|
|
|
__ shr(rcx, Immediate(Map::kElementsKindShift));
|
2013-06-05 10:43:18 +00:00
|
|
|
|
2013-06-25 16:31:07 +00:00
|
|
|
if (FLAG_debug_code) {
|
|
|
|
Label done;
|
2013-06-05 10:43:18 +00:00
|
|
|
__ cmpl(rcx, Immediate(FAST_ELEMENTS));
|
2013-06-25 16:31:07 +00:00
|
|
|
__ j(equal, &done);
|
|
|
|
__ cmpl(rcx, Immediate(FAST_HOLEY_ELEMENTS));
|
|
|
|
__ Assert(equal,
|
2013-08-02 09:53:11 +00:00
|
|
|
kInvalidElementsKindForInternalArrayOrInternalPackedArray);
|
2013-06-25 16:31:07 +00:00
|
|
|
__ bind(&done);
|
|
|
|
}
|
2013-06-05 10:43:18 +00:00
|
|
|
|
2013-06-25 16:31:07 +00:00
|
|
|
Label fast_elements_case;
|
|
|
|
__ cmpl(rcx, Immediate(FAST_ELEMENTS));
|
|
|
|
__ j(equal, &fast_elements_case);
|
|
|
|
GenerateCase(masm, FAST_HOLEY_ELEMENTS);
|
2013-06-05 10:43:18 +00:00
|
|
|
|
2013-06-25 16:31:07 +00:00
|
|
|
__ bind(&fast_elements_case);
|
|
|
|
GenerateCase(masm, FAST_ELEMENTS);
|
2013-06-05 10:43:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-27 09:57:54 +00:00
|
|
|
void CallApiFunctionStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- rax : callee
|
|
|
|
// -- rbx : call_data
|
|
|
|
// -- rcx : holder
|
|
|
|
// -- rdx : api_function_address
|
|
|
|
// -- rsi : context
|
|
|
|
// --
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -- rsp[8] : last argument
|
|
|
|
// -- ...
|
|
|
|
// -- rsp[argc * 8] : first argument
|
|
|
|
// -- rsp[(argc + 1) * 8] : receiver
|
|
|
|
// -----------------------------------
|
|
|
|
|
|
|
|
Register callee = rax;
|
|
|
|
Register call_data = rbx;
|
|
|
|
Register holder = rcx;
|
|
|
|
Register api_function_address = rdx;
|
|
|
|
Register return_address = rdi;
|
|
|
|
Register context = rsi;
|
|
|
|
|
|
|
|
int argc = ArgumentBits::decode(bit_field_);
|
2014-02-14 14:13:06 +00:00
|
|
|
bool is_store = IsStoreBits::decode(bit_field_);
|
2014-01-27 09:57:54 +00:00
|
|
|
bool call_data_undefined = CallDataUndefinedBits::decode(bit_field_);
|
|
|
|
|
|
|
|
typedef FunctionCallbackArguments FCA;
|
|
|
|
|
|
|
|
STATIC_ASSERT(FCA::kContextSaveIndex == 6);
|
|
|
|
STATIC_ASSERT(FCA::kCalleeIndex == 5);
|
|
|
|
STATIC_ASSERT(FCA::kDataIndex == 4);
|
|
|
|
STATIC_ASSERT(FCA::kReturnValueOffset == 3);
|
|
|
|
STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2);
|
|
|
|
STATIC_ASSERT(FCA::kIsolateIndex == 1);
|
|
|
|
STATIC_ASSERT(FCA::kHolderIndex == 0);
|
|
|
|
STATIC_ASSERT(FCA::kArgsLength == 7);
|
|
|
|
|
|
|
|
__ PopReturnAddressTo(return_address);
|
|
|
|
|
|
|
|
// context save
|
|
|
|
__ push(context);
|
|
|
|
// load context from callee
|
|
|
|
__ movp(context, FieldOperand(callee, JSFunction::kContextOffset));
|
|
|
|
|
|
|
|
// callee
|
|
|
|
__ push(callee);
|
|
|
|
|
|
|
|
// call data
|
|
|
|
__ push(call_data);
|
|
|
|
Register scratch = call_data;
|
|
|
|
if (!call_data_undefined) {
|
|
|
|
__ LoadRoot(scratch, Heap::kUndefinedValueRootIndex);
|
|
|
|
}
|
|
|
|
// return value
|
|
|
|
__ push(scratch);
|
|
|
|
// return value default
|
|
|
|
__ push(scratch);
|
|
|
|
// isolate
|
|
|
|
__ Move(scratch,
|
|
|
|
ExternalReference::isolate_address(masm->isolate()));
|
|
|
|
__ push(scratch);
|
|
|
|
// holder
|
|
|
|
__ push(holder);
|
|
|
|
|
|
|
|
__ movp(scratch, rsp);
|
|
|
|
// Push return address back on stack.
|
|
|
|
__ PushReturnAddressFrom(return_address);
|
|
|
|
|
|
|
|
// Allocate the v8::Arguments structure in the arguments' space since
|
|
|
|
// it's not controlled by GC.
|
|
|
|
const int kApiStackSpace = 4;
|
|
|
|
|
|
|
|
__ PrepareCallApiFunction(kApiStackSpace);
|
|
|
|
|
|
|
|
// FunctionCallbackInfo::implicit_args_.
|
|
|
|
__ movp(StackSpaceOperand(0), scratch);
|
|
|
|
__ addq(scratch, Immediate((argc + FCA::kArgsLength - 1) * kPointerSize));
|
|
|
|
__ movp(StackSpaceOperand(1), scratch); // FunctionCallbackInfo::values_.
|
|
|
|
__ Set(StackSpaceOperand(2), argc); // FunctionCallbackInfo::length_.
|
|
|
|
// FunctionCallbackInfo::is_construct_call_.
|
|
|
|
__ Set(StackSpaceOperand(3), 0);
|
|
|
|
|
|
|
|
#if defined(__MINGW64__) || defined(_WIN64)
|
|
|
|
Register arguments_arg = rcx;
|
|
|
|
Register callback_arg = rdx;
|
|
|
|
#else
|
|
|
|
Register arguments_arg = rdi;
|
|
|
|
Register callback_arg = rsi;
|
|
|
|
#endif
|
|
|
|
|
2014-01-27 11:13:50 +00:00
|
|
|
// It's okay if api_function_address == callback_arg
|
2014-01-27 09:57:54 +00:00
|
|
|
// but not arguments_arg
|
|
|
|
ASSERT(!api_function_address.is(arguments_arg));
|
|
|
|
|
|
|
|
// v8::InvocationCallback's argument.
|
|
|
|
__ lea(arguments_arg, StackSpaceOperand(0));
|
|
|
|
|
|
|
|
Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
|
|
|
|
|
2014-02-14 14:13:06 +00:00
|
|
|
// Accessor for FunctionCallbackInfo and first js arg.
|
|
|
|
StackArgumentsAccessor args_from_rbp(rbp, FCA::kArgsLength + 1,
|
2014-01-27 09:57:54 +00:00
|
|
|
ARGUMENTS_DONT_CONTAIN_RECEIVER);
|
|
|
|
Operand context_restore_operand = args_from_rbp.GetArgumentOperand(
|
2014-02-14 14:13:06 +00:00
|
|
|
FCA::kArgsLength - FCA::kContextSaveIndex);
|
|
|
|
// Stores return the first js argument
|
2014-01-27 09:57:54 +00:00
|
|
|
Operand return_value_operand = args_from_rbp.GetArgumentOperand(
|
2014-02-14 14:13:06 +00:00
|
|
|
is_store ? 0 : FCA::kArgsLength - FCA::kReturnValueOffset);
|
2014-01-27 09:57:54 +00:00
|
|
|
__ CallApiFunctionAndReturn(
|
|
|
|
api_function_address,
|
|
|
|
thunk_address,
|
|
|
|
callback_arg,
|
|
|
|
argc + FCA::kArgsLength + 1,
|
|
|
|
return_value_operand,
|
2014-02-14 14:13:06 +00:00
|
|
|
&context_restore_operand);
|
2014-01-27 09:57:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-30 12:15:51 +00:00
|
|
|
void CallApiGetterStub::Generate(MacroAssembler* masm) {
|
|
|
|
// ----------- S t a t e -------------
|
|
|
|
// -- rsp[0] : return address
|
|
|
|
// -- rsp[8] : name
|
|
|
|
// -- rsp[16 - kArgsLength*8] : PropertyCallbackArguments object
|
|
|
|
// -- ...
|
|
|
|
// -- r8 : api_function_address
|
|
|
|
// -----------------------------------
|
|
|
|
|
|
|
|
#if defined(__MINGW64__) || defined(_WIN64)
|
|
|
|
Register getter_arg = r8;
|
|
|
|
Register accessor_info_arg = rdx;
|
|
|
|
Register name_arg = rcx;
|
|
|
|
#else
|
|
|
|
Register getter_arg = rdx;
|
|
|
|
Register accessor_info_arg = rsi;
|
|
|
|
Register name_arg = rdi;
|
|
|
|
#endif
|
|
|
|
Register api_function_address = r8;
|
|
|
|
Register scratch = rax;
|
|
|
|
|
|
|
|
// v8::Arguments::values_ and handler for name.
|
|
|
|
const int kStackSpace = PropertyCallbackArguments::kArgsLength + 1;
|
|
|
|
|
|
|
|
// Allocate v8::AccessorInfo in non-GCed stack space.
|
|
|
|
const int kArgStackSpace = 1;
|
|
|
|
|
2014-02-07 02:21:18 +00:00
|
|
|
__ lea(name_arg, Operand(rsp, kPCOnStackSize));
|
2014-01-30 12:15:51 +00:00
|
|
|
|
|
|
|
__ PrepareCallApiFunction(kArgStackSpace);
|
|
|
|
__ lea(scratch, Operand(name_arg, 1 * kPointerSize));
|
|
|
|
|
|
|
|
// v8::PropertyAccessorInfo::args_.
|
|
|
|
__ movp(StackSpaceOperand(0), scratch);
|
|
|
|
|
|
|
|
// The context register (rsi) has been saved in PrepareCallApiFunction and
|
|
|
|
// could be used to pass arguments.
|
|
|
|
__ lea(accessor_info_arg, StackSpaceOperand(0));
|
|
|
|
|
|
|
|
Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
|
|
|
|
|
|
|
|
// It's okay if api_function_address == getter_arg
|
|
|
|
// but not accessor_info_arg or name_arg
|
|
|
|
ASSERT(!api_function_address.is(accessor_info_arg) &&
|
|
|
|
!api_function_address.is(name_arg));
|
|
|
|
|
|
|
|
// The name handler is counted as an argument.
|
|
|
|
StackArgumentsAccessor args(rbp, PropertyCallbackArguments::kArgsLength);
|
|
|
|
Operand return_value_operand = args.GetArgumentOperand(
|
|
|
|
PropertyCallbackArguments::kArgsLength - 1 -
|
|
|
|
PropertyCallbackArguments::kReturnValueOffset);
|
|
|
|
__ CallApiFunctionAndReturn(api_function_address,
|
|
|
|
thunk_address,
|
|
|
|
getter_arg,
|
|
|
|
kStackSpace,
|
|
|
|
return_value_operand,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 09:44:44 +00:00
|
|
|
#undef __
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_TARGET_ARCH_X64
|