Convert function.name to API-style accessor and make CallApiGetterStub serializable.

BUG=
R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/254783003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@21002 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
ulan@chromium.org 2014-04-28 08:26:35 +00:00
parent 2fe0f48d39
commit 60b14ea631
18 changed files with 132 additions and 83 deletions

View File

@ -947,21 +947,47 @@ Handle<AccessorInfo> Accessors::FunctionLengthInfo(
//
Object* Accessors::FunctionGetName(Isolate* isolate,
Object* object,
void*) {
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
return holder == NULL
? isolate->heap()->undefined_value()
: holder->shared()->name();
void Accessors::FunctionNameGetter(
v8::Local<v8::String> name,
const v8::PropertyCallbackInfo<v8::Value>& info) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(info.GetIsolate());
HandleScope scope(isolate);
Handle<Object> object = Utils::OpenHandle(*info.This());
MaybeHandle<JSFunction> maybe_function;
{
DisallowHeapAllocation no_allocation;
JSFunction* function = FindInstanceOf<JSFunction>(isolate, *object);
if (function != NULL) maybe_function = Handle<JSFunction>(function);
}
Handle<JSFunction> function;
Handle<Object> result;
if (maybe_function.ToHandle(&function)) {
result = Handle<Object>(function->shared()->name(), isolate);
} else {
result = isolate->factory()->undefined_value();
}
info.GetReturnValue().Set(Utils::ToLocal(result));
}
const AccessorDescriptor Accessors::FunctionName = {
FunctionGetName,
ReadOnlySetAccessor,
0
};
void Accessors::FunctionNameSetter(
v8::Local<v8::String> name,
v8::Local<v8::Value> val,
const v8::PropertyCallbackInfo<void>& info) {
// Do nothing.
}
Handle<AccessorInfo> Accessors::FunctionNameInfo(
Isolate* isolate, PropertyAttributes attributes) {
return MakeAccessor(isolate,
isolate->factory()->name_string(),
&FunctionNameGetter,
&FunctionNameSetter,
attributes);
}
//

View File

@ -37,12 +37,12 @@ namespace internal {
// The list of accessor descriptors. This is a second-order macro
// taking a macro to be applied to all accessor descriptor names.
#define ACCESSOR_DESCRIPTOR_LIST(V) \
V(FunctionName) \
V(FunctionArguments) \
V(FunctionCaller) \
V(ArrayLength)
#define ACCESSOR_INFO_LIST(V) \
V(FunctionName) \
V(FunctionLength) \
V(FunctionPrototype) \
V(ScriptColumnOffset) \

View File

@ -5107,11 +5107,8 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) {
__ str(ip, MemOperand(r0, 3 * kPointerSize));
const int kStackUnwindSpace = argc + FCA::kArgsLength + 1;
Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL;
ApiFunction thunk_fun(thunk_address);
ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type,
isolate());
ExternalReference thunk_ref =
ExternalReference::invoke_function_callback(isolate());
AllowExternalCallThatCantCauseGC scope(masm);
MemOperand context_restore_operand(
@ -5157,12 +5154,8 @@ void CallApiGetterStub::Generate(MacroAssembler* masm) {
const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
ExternalReference::Type thunk_type =
ExternalReference::PROFILING_GETTER_CALL;
ApiFunction thunk_fun(thunk_address);
ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type,
isolate());
ExternalReference thunk_ref =
ExternalReference::invoke_accessor_getter_callback(isolate());
__ CallApiFunctionAndReturn(api_function_address,
thunk_ref,
kStackUnwindSpace,

View File

@ -2351,10 +2351,7 @@ void MacroAssembler::CallApiFunctionAndReturn(
Label profiler_disabled;
Label end_profiler_check;
bool* is_profiling_flag =
isolate()->cpu_profiler()->is_profiling_address();
STATIC_ASSERT(sizeof(*is_profiling_flag) == 1);
mov(r9, Operand(reinterpret_cast<int32_t>(is_profiling_flag)));
mov(r9, Operand(ExternalReference::is_profiling_address(isolate())));
ldrb(r9, MemOperand(r9, 0));
cmp(r9, Operand(0));
b(eq, &profiler_disabled);

View File

@ -5326,11 +5326,8 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) {
__ Stp(x10, xzr, MemOperand(x0, 2 * kPointerSize));
const int kStackUnwindSpace = argc + FCA::kArgsLength + 1;
Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL;
ApiFunction thunk_fun(thunk_address);
ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type,
isolate());
ExternalReference thunk_ref =
ExternalReference::invoke_function_callback(isolate());
AllowExternalCallThatCantCauseGC scope(masm);
MemOperand context_restore_operand(
@ -5383,12 +5380,8 @@ void CallApiGetterStub::Generate(MacroAssembler* masm) {
const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
ExternalReference::Type thunk_type =
ExternalReference::PROFILING_GETTER_CALL;
ApiFunction thunk_fun(thunk_address);
ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type,
isolate());
ExternalReference thunk_ref =
ExternalReference::invoke_accessor_getter_callback(isolate());
const int spill_offset = 1 + kApiStackSpace;
__ CallApiFunctionAndReturn(api_function_address,

View File

@ -1683,9 +1683,7 @@ void MacroAssembler::CallApiFunctionAndReturn(
Label profiler_disabled;
Label end_profiler_check;
bool* is_profiling_flag = isolate()->cpu_profiler()->is_profiling_address();
STATIC_ASSERT(sizeof(*is_profiling_flag) == 1);
Mov(x10, reinterpret_cast<uintptr_t>(is_profiling_flag));
Mov(x10, ExternalReference::is_profiling_address(isolate()));
Ldrb(w10, MemOperand(x10));
Cbz(w10, &profiler_disabled);
Mov(x3, thunk_ref);

View File

@ -39,6 +39,7 @@
#include "builtins.h"
#include "counters.h"
#include "cpu.h"
#include "cpu-profiler.h"
#include "debug.h"
#include "deoptimizer.h"
#include "execution.h"
@ -1317,6 +1318,30 @@ ExternalReference ExternalReference::address_of_uint32_bias() {
}
ExternalReference ExternalReference::is_profiling_address(Isolate* isolate) {
return ExternalReference(isolate->cpu_profiler()->is_profiling_address());
}
ExternalReference ExternalReference::invoke_function_callback(
Isolate* isolate) {
Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL;
ApiFunction thunk_fun(thunk_address);
return ExternalReference(&thunk_fun, thunk_type, isolate);
}
ExternalReference ExternalReference::invoke_accessor_getter_callback(
Isolate* isolate) {
Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
ExternalReference::Type thunk_type =
ExternalReference::PROFILING_GETTER_CALL;
ApiFunction thunk_fun(thunk_address);
return ExternalReference(&thunk_fun, thunk_type, isolate);
}
#ifndef V8_INTERPRETED_REGEXP
ExternalReference ExternalReference::re_check_stack_guard_state(

View File

@ -861,6 +861,10 @@ class ExternalReference BASE_EMBEDDED {
static ExternalReference cpu_features();
static ExternalReference is_profiling_address(Isolate* isolate);
static ExternalReference invoke_function_callback(Isolate* isolate);
static ExternalReference invoke_accessor_getter_callback(Isolate* isolate);
Address address() const { return reinterpret_cast<Address>(address_); }
// Function Debug::Break()

View File

@ -388,7 +388,6 @@ void Genesis::SetFunctionInstanceDescriptor(
int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5;
Map::EnsureDescriptorSlack(map, size);
Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
Handle<Foreign> args(factory()->NewForeign(&Accessors::FunctionArguments));
Handle<Foreign> caller(factory()->NewForeign(&Accessors::FunctionCaller));
PropertyAttributes attribs = static_cast<PropertyAttributes>(
@ -401,8 +400,11 @@ void Genesis::SetFunctionInstanceDescriptor(
length, attribs);
map->AppendDescriptor(&d);
}
Handle<AccessorInfo> name =
Accessors::FunctionNameInfo(isolate(), attribs);
{ // Add name.
CallbacksDescriptor d(factory()->name_string(), name, attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(name->name())),
name, attribs);
map->AppendDescriptor(&d);
}
{ // Add arguments.
@ -519,7 +521,6 @@ void Genesis::SetStrictFunctionInstanceDescriptor(
int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5;
Map::EnsureDescriptorSlack(map, size);
Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
Handle<AccessorPair> arguments(factory()->NewAccessorPair());
Handle<AccessorPair> caller(factory()->NewAccessorPair());
PropertyAttributes rw_attribs =
@ -534,8 +535,11 @@ void Genesis::SetStrictFunctionInstanceDescriptor(
length, ro_attribs);
map->AppendDescriptor(&d);
}
Handle<AccessorInfo> name =
Accessors::FunctionNameInfo(isolate(), ro_attribs);
{ // Add name.
CallbacksDescriptor d(factory()->name_string(), name, ro_attribs);
CallbacksDescriptor d(Handle<Name>(Name::cast(name->name())),
name, ro_attribs);
map->AppendDescriptor(&d);
}
{ // Add arguments.

View File

@ -5001,7 +5001,8 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) {
__ lea(scratch, ApiParameterOperand(2));
__ mov(ApiParameterOperand(0), scratch);
Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
ExternalReference thunk_ref =
ExternalReference::invoke_function_callback(isolate());
Operand context_restore_operand(ebp,
(2 + FCA::kContextSaveIndex) * kPointerSize);
@ -5014,7 +5015,7 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) {
}
Operand return_value_operand(ebp, return_value_offset * kPointerSize);
__ CallApiFunctionAndReturn(api_function_address,
thunk_address,
thunk_ref,
ApiParameterOperand(1),
argc + FCA::kArgsLength + 1,
return_value_operand,
@ -5049,10 +5050,11 @@ void CallApiGetterStub::Generate(MacroAssembler* masm) {
__ add(scratch, Immediate(kPointerSize));
__ mov(ApiParameterOperand(1), scratch); // arguments pointer.
Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
ExternalReference thunk_ref =
ExternalReference::invoke_accessor_getter_callback(isolate());
__ CallApiFunctionAndReturn(api_function_address,
thunk_address,
thunk_ref,
ApiParameterOperand(2),
kStackSpace,
Operand(ebp, 7 * kPointerSize),

View File

@ -2300,7 +2300,7 @@ void MacroAssembler::PrepareCallApiFunction(int argc) {
void MacroAssembler::CallApiFunctionAndReturn(
Register function_address,
Address thunk_address,
ExternalReference thunk_ref,
Operand thunk_last_arg,
int stack_space,
Operand return_value_operand,
@ -2331,17 +2331,15 @@ void MacroAssembler::CallApiFunctionAndReturn(
Label profiler_disabled;
Label end_profiler_check;
bool* is_profiling_flag =
isolate()->cpu_profiler()->is_profiling_address();
STATIC_ASSERT(sizeof(*is_profiling_flag) == 1);
mov(eax, Immediate(reinterpret_cast<Address>(is_profiling_flag)));
mov(eax, Immediate(ExternalReference::is_profiling_address(isolate())));
cmpb(Operand(eax, 0), 0);
j(zero, &profiler_disabled);
// Additional parameter is the address of the actual getter function.
mov(thunk_last_arg, function_address);
// Call the api function.
call(thunk_address, RelocInfo::RUNTIME_ENTRY);
mov(eax, Immediate(thunk_ref));
call(eax);
jmp(&end_profiler_check);
bind(&profiler_disabled);

View File

@ -807,7 +807,7 @@ class MacroAssembler: public Assembler {
// caller-save registers. Restores context. On return removes
// stack_space * kPointerSize (GCed).
void CallApiFunctionAndReturn(Register function_address,
Address thunk_address,
ExternalReference thunk_ref,
Operand thunk_last_arg,
int stack_space,
Operand return_value_operand,

View File

@ -5305,11 +5305,8 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) {
__ sw(zero_reg, MemOperand(a0, 3 * kPointerSize));
const int kStackUnwindSpace = argc + FCA::kArgsLength + 1;
Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
ExternalReference::Type thunk_type = ExternalReference::PROFILING_API_CALL;
ApiFunction thunk_fun(thunk_address);
ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type,
isolate());
ExternalReference thunk_ref =
ExternalReference::invoke_function_callback(isolate());
AllowExternalCallThatCantCauseGC scope(masm);
MemOperand context_restore_operand(
@ -5355,12 +5352,8 @@ void CallApiGetterStub::Generate(MacroAssembler* masm) {
const int kStackUnwindSpace = PropertyCallbackArguments::kArgsLength + 1;
Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
ExternalReference::Type thunk_type =
ExternalReference::PROFILING_GETTER_CALL;
ApiFunction thunk_fun(thunk_address);
ExternalReference thunk_ref = ExternalReference(&thunk_fun, thunk_type,
isolate());
ExternalReference thunk_ref =
ExternalReference::invoke_accessor_getter_callback(isolate());
__ CallApiFunctionAndReturn(api_function_address,
thunk_ref,
kStackUnwindSpace,

View File

@ -3929,10 +3929,7 @@ void MacroAssembler::CallApiFunctionAndReturn(
Label profiler_disabled;
Label end_profiler_check;
bool* is_profiling_flag =
isolate()->cpu_profiler()->is_profiling_address();
STATIC_ASSERT(sizeof(*is_profiling_flag) == 1);
li(t9, reinterpret_cast<int32_t>(is_profiling_flag));
li(t9, Operand(ExternalReference::is_profiling_address(isolate())));
lb(t9, MemOperand(t9, 0));
Branch(&profiler_disabled, eq, t9, Operand(zero_reg));

View File

@ -554,6 +554,26 @@ void ExternalReferenceTable::PopulateTable(Isolate* isolate) {
62,
"Code::MarkCodeAsExecuted");
Add(ExternalReference::is_profiling_address(isolate).address(),
UNCLASSIFIED,
63,
"CpuProfiler::is_profiling");
Add(ExternalReference::scheduled_exception_address(isolate).address(),
UNCLASSIFIED,
64,
"Isolate::scheduled_exception");
Add(ExternalReference::invoke_function_callback(isolate).address(),
UNCLASSIFIED,
65,
"InvokeFunctionCallback");
Add(ExternalReference::invoke_accessor_getter_callback(isolate).address(),
UNCLASSIFIED,
66,
"InvokeAccessorGetterCallback");
// Add a small set of deopt entry addresses to encoder without generating the
// deopt table code, which isn't possible at deserialization time.
HandleScope scope(isolate);

View File

@ -4856,7 +4856,8 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) {
// v8::InvocationCallback's argument.
__ leap(arguments_arg, StackSpaceOperand(0));
Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback);
ExternalReference thunk_ref =
ExternalReference::invoke_function_callback(isolate());
// Accessor for FunctionCallbackInfo and first js arg.
StackArgumentsAccessor args_from_rbp(rbp, FCA::kArgsLength + 1,
@ -4868,7 +4869,7 @@ void CallApiFunctionStub::Generate(MacroAssembler* masm) {
is_store ? 0 : FCA::kArgsLength - FCA::kReturnValueOffset);
__ CallApiFunctionAndReturn(
api_function_address,
thunk_address,
thunk_ref,
callback_arg,
argc + FCA::kArgsLength + 1,
return_value_operand,
@ -4915,7 +4916,8 @@ void CallApiGetterStub::Generate(MacroAssembler* masm) {
// could be used to pass arguments.
__ leap(accessor_info_arg, StackSpaceOperand(0));
Address thunk_address = FUNCTION_ADDR(&InvokeAccessorGetterCallback);
ExternalReference thunk_ref =
ExternalReference::invoke_accessor_getter_callback(isolate());
// It's okay if api_function_address == getter_arg
// but not accessor_info_arg or name_arg
@ -4928,7 +4930,7 @@ void CallApiGetterStub::Generate(MacroAssembler* masm) {
PropertyCallbackArguments::kArgsLength - 1 -
PropertyCallbackArguments::kReturnValueOffset);
__ CallApiFunctionAndReturn(api_function_address,
thunk_address,
thunk_ref,
getter_arg,
kStackSpace,
return_value_operand,

View File

@ -667,7 +667,7 @@ void MacroAssembler::PrepareCallApiFunction(int arg_stack_space) {
void MacroAssembler::CallApiFunctionAndReturn(
Register function_address,
Address thunk_address,
ExternalReference thunk_ref,
Register thunk_last_arg,
int stack_space,
Operand return_value_operand,
@ -714,16 +714,13 @@ void MacroAssembler::CallApiFunctionAndReturn(
Label profiler_disabled;
Label end_profiler_check;
bool* is_profiling_flag =
isolate()->cpu_profiler()->is_profiling_address();
STATIC_ASSERT(sizeof(*is_profiling_flag) == 1);
Move(rax, is_profiling_flag, RelocInfo::EXTERNAL_REFERENCE);
Move(rax, ExternalReference::is_profiling_address(isolate()));
cmpb(Operand(rax, 0), Immediate(0));
j(zero, &profiler_disabled);
// Third parameter is the address of the actual getter function.
Move(thunk_last_arg, function_address);
Move(rax, thunk_address, RelocInfo::EXTERNAL_REFERENCE);
Move(rax, thunk_ref);
jmp(&end_profiler_check);
bind(&profiler_disabled);

View File

@ -1313,7 +1313,7 @@ class MacroAssembler: public Assembler {
// caller-save registers. Restores context. On return removes
// stack_space * kPointerSize (GCed).
void CallApiFunctionAndReturn(Register function_address,
Address thunk_address,
ExternalReference thunk_ref,
Register thunk_last_arg,
int stack_space,
Operand return_value_operand,