Only pass isolate parameter to C helper functions that need it.

Review URL: http://codereview.chromium.org/6778018

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7450 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
vitalyr@chromium.org 2011-03-30 18:05:16 +00:00
parent ed36cde5d0
commit d89c753152
19 changed files with 89 additions and 95 deletions

View File

@ -5361,8 +5361,9 @@ void CodeGenerator::GenerateRandomHeapNumber(
// by computing:
// ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
if (Isolate::Current()->cpu_features()->IsSupported(VFP3)) {
__ PrepareCallCFunction(0, r1);
__ CallCFunction(ExternalReference::random_uint32_function(isolate()), 0);
__ PrepareCallCFunction(1, r0);
__ mov(r0, Operand(ExternalReference::isolate_address()));
__ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
CpuFeatures::Scope scope(VFP3);
// 0x41300000 is the top half of 1.0 x 2^20 as a double.
@ -5380,10 +5381,11 @@ void CodeGenerator::GenerateRandomHeapNumber(
__ vstr(d7, r0, HeapNumber::kValueOffset);
frame_->EmitPush(r4);
} else {
__ PrepareCallCFunction(2, r0);
__ mov(r0, Operand(r4));
__ PrepareCallCFunction(1, r1);
__ mov(r1, Operand(ExternalReference::isolate_address()));
__ CallCFunction(
ExternalReference::fill_heap_number_with_random_function(isolate()), 1);
ExternalReference::fill_heap_number_with_random_function(isolate()), 2);
frame_->EmitPush(r0);
}
}

View File

@ -586,14 +586,16 @@ void Deoptimizer::EntryGenerator::Generate() {
// Allocate a new deoptimizer object.
// Pass four arguments in r0 to r3 and fifth argument on stack.
__ PrepareCallCFunction(5, r5);
__ PrepareCallCFunction(6, r5);
__ ldr(r0, MemOperand(fp, JavaScriptFrameConstants::kFunctionOffset));
__ mov(r1, Operand(type())); // bailout type,
// r2: bailout id already loaded.
// r3: code address or 0 already loaded.
__ str(r4, MemOperand(sp, 0 * kPointerSize)); // Fp-to-sp delta.
__ mov(r5, Operand(ExternalReference::isolate_address()));
__ str(r5, MemOperand(sp, 1 * kPointerSize)); // Isolate.
// Call Deoptimizer::New().
__ CallCFunction(ExternalReference::new_deoptimizer_function(isolate), 5);
__ CallCFunction(ExternalReference::new_deoptimizer_function(isolate), 6);
// Preserve "deoptimizer" object in register r0 and get the input
// frame descriptor pointer to r1 (deoptimizer->input_);

View File

@ -2803,8 +2803,9 @@ void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) {
// by computing:
// ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
if (isolate()->cpu_features()->IsSupported(VFP3)) {
__ PrepareCallCFunction(0, r1);
__ CallCFunction(ExternalReference::random_uint32_function(isolate()), 0);
__ PrepareCallCFunction(1, r0);
__ mov(r0, Operand(ExternalReference::isolate_address()));
__ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
CpuFeatures::Scope scope(VFP3);
// 0x41300000 is the top half of 1.0 x 2^20 as a double.
@ -2822,10 +2823,11 @@ void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) {
__ vstr(d7, r0, HeapNumber::kValueOffset);
__ mov(r0, r4);
} else {
__ PrepareCallCFunction(2, r0);
__ mov(r0, Operand(r4));
__ PrepareCallCFunction(1, r1);
__ mov(r1, Operand(ExternalReference::isolate_address()));
__ CallCFunction(
ExternalReference::fill_heap_number_with_random_function(isolate()), 1);
ExternalReference::fill_heap_number_with_random_function(isolate()), 2);
}
context()->Plug(r0);

View File

@ -1799,9 +1799,10 @@ MaybeObject* MacroAssembler::TryCallApiFunctionAndReturn(
bind(&delete_allocated_handles);
str(r5, MemOperand(r7, kLimitOffset));
mov(r4, r0);
PrepareCallCFunction(0, r5);
PrepareCallCFunction(1, r5);
mov(r0, Operand(ExternalReference::isolate_address()));
CallCFunction(
ExternalReference::delete_handle_scope_extensions(isolate()), 0);
ExternalReference::delete_handle_scope_extensions(isolate()), 1);
mov(r0, r4);
jmp(&leave_exit_frame);
@ -2797,9 +2798,6 @@ static const int kRegisterPassedArguments = 4;
void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) {
int frame_alignment = ActivationFrameAlignment();
// Reserve space for Isolate address which is always passed as last parameter
num_arguments += 1;
// Up to four simple arguments are passed in registers r0..r3.
int stack_passed_arguments = (num_arguments <= kRegisterPassedArguments) ?
0 : num_arguments - kRegisterPassedArguments;
@ -2836,19 +2834,6 @@ void MacroAssembler::CallCFunctionHelper(Register function,
ExternalReference function_reference,
Register scratch,
int num_arguments) {
// Push Isolate address as the last argument.
if (num_arguments < kRegisterPassedArguments) {
Register arg_to_reg[] = {r0, r1, r2, r3};
Register r = arg_to_reg[num_arguments];
mov(r, Operand(ExternalReference::isolate_address()));
} else {
int stack_passed_arguments = num_arguments - kRegisterPassedArguments;
// Push Isolate address on the stack after the arguments.
mov(scratch, Operand(ExternalReference::isolate_address()));
str(scratch, MemOperand(sp, stack_passed_arguments * kPointerSize));
}
num_arguments += 1;
// Make sure that the stack is aligned before calling a C function unless
// running in the simulator. The simulator has its own alignment check which
// provides more information.

View File

@ -347,7 +347,7 @@ void RegExpMacroAssemblerARM::CheckNotBackReferenceIgnoreCase(
__ sub(current_input_offset(), r2, end_of_input_address());
} else {
ASSERT(mode_ == UC16);
int argument_count = 3;
int argument_count = 4;
__ PrepareCallCFunction(argument_count, r2);
// r0 - offset of start of capture
@ -358,6 +358,7 @@ void RegExpMacroAssemblerARM::CheckNotBackReferenceIgnoreCase(
// r0: Address byte_offset1 - Address captured substring's start.
// r1: Address byte_offset2 - Address of current character position.
// r2: size_t byte_length - length of capture in bytes(!)
// r3: Isolate* isolate
// Address of start of capture.
__ add(r0, r0, Operand(end_of_input_address()));
@ -367,6 +368,8 @@ void RegExpMacroAssemblerARM::CheckNotBackReferenceIgnoreCase(
__ mov(r4, Operand(r1));
// Address of current input position.
__ add(r1, current_input_offset(), Operand(end_of_input_address()));
// Isolate.
__ mov(r3, Operand(ExternalReference::isolate_address()));
ExternalReference function =
ExternalReference::re_case_insensitive_compare_uc16(masm_->isolate());
@ -778,10 +781,11 @@ Handle<Object> RegExpMacroAssemblerARM::GetCode(Handle<String> source) {
Label grow_failed;
// Call GrowStack(backtrack_stackpointer(), &stack_base)
static const int num_arguments = 2;
static const int num_arguments = 3;
__ PrepareCallCFunction(num_arguments, r0);
__ mov(r0, backtrack_stackpointer());
__ add(r1, frame_pointer(), Operand(kStackHighEnd));
__ mov(r2, Operand(ExternalReference::isolate_address()));
ExternalReference grow_stack =
ExternalReference::re_grow_stack(masm_->isolate());
__ CallCFunction(grow_stack, num_arguments);

View File

@ -199,8 +199,7 @@ void Deoptimizer::HandleWeakDeoptimizedCode(
}
void Deoptimizer::ComputeOutputFrames(Deoptimizer* deoptimizer,
Isolate* isolate) {
void Deoptimizer::ComputeOutputFrames(Deoptimizer* deoptimizer) {
deoptimizer->DoComputeOutputFrames();
}

View File

@ -192,7 +192,7 @@ class Deoptimizer : public Malloced {
void InsertHeapNumberValues(int index, JavaScriptFrame* frame);
static void ComputeOutputFrames(Deoptimizer* deoptimizer, Isolate* isolate);
static void ComputeOutputFrames(Deoptimizer* deoptimizer);
static Address GetDeoptimizationEntry(int id, BailoutType type);
static int GetDeoptimizationId(Address addr, BailoutType type);

View File

@ -7448,9 +7448,10 @@ void CodeGenerator::GenerateRandomHeapNumber(
__ bind(&heapnumber_allocated);
__ PrepareCallCFunction(0, ebx);
__ PrepareCallCFunction(1, ebx);
__ mov(Operand(esp, 0), Immediate(ExternalReference::isolate_address()));
__ CallCFunction(ExternalReference::random_uint32_function(masm()->isolate()),
0);
1);
// Convert 32 random bits in eax to 0.(32 random bits) in a double
// by computing:

View File

@ -641,14 +641,16 @@ void Deoptimizer::EntryGenerator::Generate() {
__ neg(edx);
// Allocate a new deoptimizer object.
__ PrepareCallCFunction(5, eax);
__ PrepareCallCFunction(6, eax);
__ mov(eax, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset));
__ mov(Operand(esp, 0 * kPointerSize), eax); // Function.
__ mov(Operand(esp, 1 * kPointerSize), Immediate(type())); // Bailout type.
__ mov(Operand(esp, 2 * kPointerSize), ebx); // Bailout id.
__ mov(Operand(esp, 3 * kPointerSize), ecx); // Code address or 0.
__ mov(Operand(esp, 4 * kPointerSize), edx); // Fp-to-sp delta.
__ CallCFunction(ExternalReference::new_deoptimizer_function(isolate), 5);
__ mov(Operand(esp, 5 * kPointerSize),
Immediate(ExternalReference::isolate_address()));
__ CallCFunction(ExternalReference::new_deoptimizer_function(isolate), 6);
// Preserve deoptimizer object in register eax and get the input
// frame descriptor pointer.

View File

@ -2717,9 +2717,10 @@ void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) {
__ bind(&heapnumber_allocated);
__ PrepareCallCFunction(0, ebx);
__ PrepareCallCFunction(1, ebx);
__ mov(Operand(esp, 0), Immediate(ExternalReference::isolate_address()));
__ CallCFunction(ExternalReference::random_uint32_function(isolate()),
0);
1);
// Convert 32 random bits in eax to 0.(32 random bits) in a double
// by computing:

View File

@ -1988,17 +1988,14 @@ void MacroAssembler::JumpIfNotBothSequentialAsciiStrings(Register object1,
void MacroAssembler::PrepareCallCFunction(int num_arguments, Register scratch) {
// Reserve space for Isolate address which is always passed as last parameter
num_arguments += 1;
int frameAlignment = OS::ActivationFrameAlignment();
if (frameAlignment != 0) {
int frame_alignment = OS::ActivationFrameAlignment();
if (frame_alignment != 0) {
// Make stack end at alignment and make room for num_arguments words
// and the original value of esp.
mov(scratch, esp);
sub(Operand(esp), Immediate((num_arguments + 1) * kPointerSize));
ASSERT(IsPowerOf2(frameAlignment));
and_(esp, -frameAlignment);
ASSERT(IsPowerOf2(frame_alignment));
and_(esp, -frame_alignment);
mov(Operand(esp, num_arguments * kPointerSize), scratch);
} else {
sub(Operand(esp), Immediate(num_arguments * kPointerSize));
@ -2016,11 +2013,6 @@ void MacroAssembler::CallCFunction(ExternalReference function,
void MacroAssembler::CallCFunction(Register function,
int num_arguments) {
// Pass current isolate address as additional parameter.
mov(Operand(esp, num_arguments * kPointerSize),
Immediate(ExternalReference::isolate_address()));
num_arguments += 1;
// Check stack alignment.
if (emit_debug_code()) {
CheckStackAlignment();
@ -2030,7 +2022,7 @@ void MacroAssembler::CallCFunction(Register function,
if (OS::ActivationFrameAlignment() != 0) {
mov(esp, Operand(esp, num_arguments * kPointerSize));
} else {
add(Operand(esp), Immediate(num_arguments * sizeof(int32_t)));
add(Operand(esp), Immediate(num_arguments * kPointerSize));
}
}

View File

@ -372,14 +372,18 @@ void RegExpMacroAssemblerIA32::CheckNotBackReferenceIgnoreCase(
__ push(backtrack_stackpointer());
__ push(ebx);
static const int argument_count = 3;
static const int argument_count = 4;
__ PrepareCallCFunction(argument_count, ecx);
// Put arguments into allocated stack area, last argument highest on stack.
// Parameters are
// Address byte_offset1 - Address captured substring's start.
// Address byte_offset2 - Address of current character position.
// size_t byte_length - length of capture in bytes(!)
// Isolate* isolate
// Set isolate.
__ mov(Operand(esp, 3 * kPointerSize),
Immediate(ExternalReference::isolate_address()));
// Set byte_length.
__ mov(Operand(esp, 2 * kPointerSize), ebx);
// Set byte_offset2.
@ -838,8 +842,10 @@ Handle<Object> RegExpMacroAssemblerIA32::GetCode(Handle<String> source) {
__ push(edi);
// Call GrowStack(backtrack_stackpointer())
static const int num_arguments = 2;
static const int num_arguments = 3;
__ PrepareCallCFunction(num_arguments, ebx);
__ mov(Operand(esp, 2 * kPointerSize),
Immediate(ExternalReference::isolate_address()));
__ lea(eax, Operand(ebp, kStackHighEnd));
__ mov(Operand(esp, 1 * kPointerSize), eax);
__ mov(Operand(esp, 0 * kPointerSize), backtrack_stackpointer());

View File

@ -171,8 +171,8 @@ typedef union {
} double_int_union;
Object* V8::FillHeapNumberWithRandom(Object* heap_number) {
uint64_t random_bits = Random(Isolate::Current());
Object* V8::FillHeapNumberWithRandom(Object* heap_number, Isolate* isolate) {
uint64_t random_bits = Random(isolate);
// Make a double* from address (heap_number + sizeof(double)).
double_int_union* r = reinterpret_cast<double_int_union*>(
reinterpret_cast<char*>(heap_number) +

View File

@ -101,7 +101,8 @@ class V8 : public AllStatic {
// use a separate random state for internal random number
// generation.
static uint32_t RandomPrivate(Isolate* isolate);
static Object* FillHeapNumberWithRandom(Object* heap_number);
static Object* FillHeapNumberWithRandom(Object* heap_number,
Isolate* isolate);
// Idle notification directly from the API.
static bool IdleNotification();

View File

@ -6438,8 +6438,13 @@ void CodeGenerator::GenerateRandomHeapNumber(
// Return a random uint32 number in rax.
// The fresh HeapNumber is in rbx, which is callee-save on both x64 ABIs.
__ PrepareCallCFunction(0);
__ CallCFunction(ExternalReference::random_uint32_function(isolate()), 0);
__ PrepareCallCFunction(1);
#ifdef _WIN64
__ LoadAddress(rcx, ExternalReference::isolate_address());
#else
__ LoadAddress(rdi, ExternalReference::isolate_address());
#endif
__ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
// Convert 32 random bits in rax to 0.(32 random bits) in a double
// by computing:

View File

@ -663,23 +663,26 @@ void Deoptimizer::EntryGenerator::Generate() {
__ neg(arg5);
// Allocate a new deoptimizer object.
__ PrepareCallCFunction(5);
__ PrepareCallCFunction(6);
__ movq(rax, Operand(rbp, JavaScriptFrameConstants::kFunctionOffset));
__ movq(arg1, rax);
__ movq(arg2, Immediate(type()));
// Args 3 and 4 are already in the right registers.
// On windows put the argument on the stack (PrepareCallCFunction have
// created space for this). On linux pass the argument in r8.
// On windows put the arguments on the stack (PrepareCallCFunction
// has created space for this). On linux pass the arguments in r8 and r9.
#ifdef _WIN64
__ movq(Operand(rsp, 4 * kPointerSize), arg5);
__ LoadAddress(arg5, ExternalReference::isolate_address());
__ movq(Operand(rsp, 5 * kPointerSize), arg5);
#else
__ movq(r8, arg5);
__ LoadAddress(r9, ExternalReference::isolate_address());
#endif
Isolate* isolate = masm()->isolate();
__ CallCFunction(ExternalReference::new_deoptimizer_function(isolate), 5);
__ CallCFunction(ExternalReference::new_deoptimizer_function(isolate), 6);
// Preserve deoptimizer object in register rax and get the input
// frame descriptor pointer.
__ movq(rbx, Operand(rax, Deoptimizer::input_offset()));
@ -722,10 +725,11 @@ void Deoptimizer::EntryGenerator::Generate() {
// Compute the output frame in the deoptimizer.
__ push(rax);
__ PrepareCallCFunction(1);
__ PrepareCallCFunction(2);
__ movq(arg1, rax);
__ LoadAddress(arg2, ExternalReference::isolate_address());
__ CallCFunction(
ExternalReference::compute_output_frames_function(isolate), 1);
ExternalReference::compute_output_frames_function(isolate), 2);
__ pop(rax);
// Replace the current frame with the output frames.

View File

@ -2693,8 +2693,13 @@ void FullCodeGenerator::EmitRandomHeapNumber(ZoneList<Expression*>* args) {
// Return a random uint32 number in rax.
// The fresh HeapNumber is in rbx, which is callee-save on both x64 ABIs.
__ PrepareCallCFunction(0);
__ CallCFunction(ExternalReference::random_uint32_function(isolate()), 0);
__ PrepareCallCFunction(1);
#ifdef _WIN64
__ LoadAddress(rcx, ExternalReference::isolate_address());
#else
__ LoadAddress(rdi, ExternalReference::isolate_address());
#endif
__ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
// Convert 32 random bits in rax to 0.(32 random bits) in a double
// by computing:

View File

@ -2851,9 +2851,6 @@ void MacroAssembler::PrepareCallCFunction(int num_arguments) {
ASSERT(frame_alignment != 0);
ASSERT(num_arguments >= 0);
// Reserve space for Isolate address which is always passed as last parameter
num_arguments += 1;
// Make stack end at alignment and allocate space for arguments and old rsp.
movq(kScratchRegister, rsp);
ASSERT(IsPowerOf2(frame_alignment));
@ -2873,26 +2870,6 @@ void MacroAssembler::CallCFunction(ExternalReference function,
void MacroAssembler::CallCFunction(Register function, int num_arguments) {
// Pass current isolate address as additional parameter.
if (num_arguments < kRegisterPassedArguments) {
#ifdef _WIN64
// First four arguments are passed in registers on Windows.
Register arg_to_reg[] = {rcx, rdx, r8, r9};
#else
// First six arguments are passed in registers on other platforms.
Register arg_to_reg[] = {rdi, rsi, rdx, rcx, r8, r9};
#endif
Register reg = arg_to_reg[num_arguments];
LoadAddress(reg, ExternalReference::isolate_address());
} else {
// Push Isolate pointer after all parameters.
int argument_slots_on_stack =
ArgumentStackSlotsForCFunctionCall(num_arguments);
LoadAddress(kScratchRegister, ExternalReference::isolate_address());
movq(Operand(rsp, argument_slots_on_stack * kPointerSize),
kScratchRegister);
}
// Check stack alignment.
if (emit_debug_code()) {
CheckStackAlignment();
@ -2901,7 +2878,6 @@ void MacroAssembler::CallCFunction(Register function, int num_arguments) {
call(function);
ASSERT(OS::ActivationFrameAlignment() != 0);
ASSERT(num_arguments >= 0);
num_arguments += 1;
int argument_slots_on_stack =
ArgumentStackSlotsForCFunctionCall(num_arguments);
movq(rsp, Operand(rsp, argument_slots_on_stack * kPointerSize));

View File

@ -402,13 +402,14 @@ void RegExpMacroAssemblerX64::CheckNotBackReferenceIgnoreCase(
#endif
__ push(backtrack_stackpointer());
static const int num_arguments = 3;
static const int num_arguments = 4;
__ PrepareCallCFunction(num_arguments);
// Put arguments into parameter registers. Parameters are
// Address byte_offset1 - Address captured substring's start.
// Address byte_offset2 - Address of current character position.
// size_t byte_length - length of capture in bytes(!)
// Isolate* isolate
#ifdef _WIN64
// Compute and set byte_offset1 (start of capture).
__ lea(rcx, Operand(rsi, rdx, times_1, 0));
@ -416,6 +417,8 @@ void RegExpMacroAssemblerX64::CheckNotBackReferenceIgnoreCase(
__ lea(rdx, Operand(rsi, rdi, times_1, 0));
// Set byte_length.
__ movq(r8, rbx);
// Isolate.
__ LoadAddress(r9, ExternalReference::isolate_address());
#else // AMD64 calling convention
// Compute byte_offset2 (current position = rsi+rdi).
__ lea(rax, Operand(rsi, rdi, times_1, 0));
@ -425,6 +428,8 @@ void RegExpMacroAssemblerX64::CheckNotBackReferenceIgnoreCase(
__ movq(rsi, rax);
// Set byte_length.
__ movq(rdx, rbx);
// Isolate.
__ LoadAddress(rcx, ExternalReference::isolate_address());
#endif
ExternalReference compare =
ExternalReference::re_case_insensitive_compare_uc16(masm_.isolate());
@ -919,16 +924,18 @@ Handle<Object> RegExpMacroAssemblerX64::GetCode(Handle<String> source) {
#endif
// Call GrowStack(backtrack_stackpointer())
static const int num_arguments = 2;
static const int num_arguments = 3;
__ PrepareCallCFunction(num_arguments);
#ifdef _WIN64
// Microsoft passes parameters in rcx, rdx.
// Microsoft passes parameters in rcx, rdx, r8.
// First argument, backtrack stackpointer, is already in rcx.
__ lea(rdx, Operand(rbp, kStackHighEnd)); // Second argument
__ LoadAddress(r8, ExternalReference::isolate_address());
#else
// AMD64 ABI passes parameters in rdi, rsi.
// AMD64 ABI passes parameters in rdi, rsi, rdx.
__ movq(rdi, backtrack_stackpointer()); // First argument.
__ lea(rsi, Operand(rbp, kStackHighEnd)); // Second argument.
__ LoadAddress(rdx, ExternalReference::isolate_address());
#endif
ExternalReference grow_stack =
ExternalReference::re_grow_stack(masm_.isolate());