Commit 09fcac5e authored by wingo@igalia.com's avatar wingo@igalia.com

Use keyed-call inline caches in delegating yield

Since we can't assume anything about the shape of the iterator in a
yield* (delegating yield), use an IC to do the next() and throw()
iterator method calls.

BUG=v8:2691
R=rossberg@chromium.org
TEST=mjsunit/regress/regress-2691

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15111 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 67c9cd82
......@@ -2035,16 +2035,13 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
__ LoadRoot(r0, Heap::kUndefinedValueRootIndex);
__ b(&l_next);
// catch (e) { receiver = iter; f = iter.throw; arg = e; goto l_call; }
// catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
__ bind(&l_catch);
handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
__ LoadRoot(r2, Heap::kthrow_stringRootIndex); // "throw"
__ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter
__ push(r3); // iter
__ push(r0); // exception
__ mov(r0, r3); // iter
__ LoadRoot(r2, Heap::kthrow_stringRootIndex); // "throw"
Handle<Code> throw_ic = isolate()->builtins()->LoadIC_Initialize();
CallIC(throw_ic); // iter.throw in r0
__ jmp(&l_call);
// try { received = yield result.value }
......@@ -2065,31 +2062,18 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
__ bind(&l_resume); // received in r0
__ PopTryHandler();
// receiver = iter; f = iter.next; arg = received;
// receiver = iter; f = 'next'; arg = received;
__ bind(&l_next);
__ LoadRoot(r2, Heap::knext_stringRootIndex); // "next"
__ ldr(r3, MemOperand(sp, 1 * kPointerSize)); // iter
__ push(r3); // iter
__ push(r0); // received
__ mov(r0, r3); // iter
__ LoadRoot(r2, Heap::knext_stringRootIndex); // "next"
Handle<Code> next_ic = isolate()->builtins()->LoadIC_Initialize();
CallIC(next_ic); // iter.next in r0
// result = f.call(receiver, arg);
// result = receiver[f](arg);
__ bind(&l_call);
Label l_call_runtime;
__ JumpIfSmi(r0, &l_call_runtime);
__ CompareObjectType(r0, r1, r1, JS_FUNCTION_TYPE);
__ b(ne, &l_call_runtime);
__ mov(r1, r0);
ParameterCount count(1);
__ InvokeFunction(r1, count, CALL_FUNCTION,
NullCallWrapper(), CALL_AS_METHOD);
Handle<Code> ic = isolate()->stub_cache()->ComputeKeyedCallInitialize(1);
CallIC(ic);
__ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset));
__ jmp(&l_loop);
__ bind(&l_call_runtime);
__ push(r0);
__ CallRuntime(Runtime::kCall, 3);
// val = result.value; if (!result.done) goto l_try;
__ bind(&l_loop);
......
......@@ -1994,15 +1994,13 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
__ mov(eax, isolate()->factory()->undefined_value());
__ jmp(&l_next);
// catch (e) { receiver = iter; f = iter.throw; arg = e; goto l_call; }
// catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
__ bind(&l_catch);
handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
__ mov(edx, Operand(esp, 1 * kPointerSize)); // iter
__ push(edx); // iter
__ push(eax); // exception
__ mov(ecx, isolate()->factory()->throw_string()); // "throw"
Handle<Code> throw_ic = isolate()->builtins()->LoadIC_Initialize();
CallIC(throw_ic); // iter.throw in eax
__ push(ecx); // "throw"
__ push(Operand(esp, 2 * kPointerSize)); // iter
__ push(eax); // exception
__ jmp(&l_call);
// try { received = yield result.value }
......@@ -2024,28 +2022,17 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
// receiver = iter; f = iter.next; arg = received;
__ bind(&l_next);
__ mov(edx, Operand(esp, 1 * kPointerSize)); // iter
__ push(edx); // iter
__ push(eax); // received
__ mov(ecx, isolate()->factory()->next_string()); // "next"
Handle<Code> next_ic = isolate()->builtins()->LoadIC_Initialize();
CallIC(next_ic); // iter.next in eax
__ push(ecx);
__ push(Operand(esp, 2 * kPointerSize)); // iter
__ push(eax); // received
// result = f.call(receiver, arg);
// result = receiver[f](arg);
__ bind(&l_call);
Label l_call_runtime;
__ JumpIfSmi(eax, &l_call_runtime);
__ CmpObjectType(eax, JS_FUNCTION_TYPE, ebx);
__ j(not_equal, &l_call_runtime);
__ mov(edi, eax);
ParameterCount count(1);
__ InvokeFunction(edi, count, CALL_FUNCTION,
NullCallWrapper(), CALL_AS_METHOD);
Handle<Code> ic = isolate()->stub_cache()->ComputeKeyedCallInitialize(1);
CallIC(ic);
__ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset));
__ jmp(&l_loop);
__ bind(&l_call_runtime);
__ push(eax);
__ CallRuntime(Runtime::kCall, 3);
__ Drop(1); // The key is still on the stack; drop it.
// val = result.value; if (!result.done) goto l_try;
__ bind(&l_loop);
......
......@@ -2017,16 +2017,13 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
__ LoadRoot(rax, Heap::kUndefinedValueRootIndex);
__ jmp(&l_next);
// catch (e) { receiver = iter; f = iter.throw; arg = e; goto l_call; }
// catch (e) { receiver = iter; f = 'throw'; arg = e; goto l_call; }
__ bind(&l_catch);
handler_table()->set(expr->index(), Smi::FromInt(l_catch.pos()));
__ movq(rcx, Operand(rsp, 1 * kPointerSize)); // iter
__ push(rcx); // iter
__ push(rax); // exception
__ movq(rax, rcx); // iter
__ LoadRoot(rcx, Heap::kthrow_stringRootIndex); // "throw"
Handle<Code> throw_ic = isolate()->builtins()->LoadIC_Initialize();
CallIC(throw_ic); // iter.throw in rax
__ push(rcx);
__ push(Operand(rsp, 2 * kPointerSize)); // iter
__ push(rax); // exception
__ jmp(&l_call);
// try { received = yield result.value }
......@@ -2046,31 +2043,19 @@ void FullCodeGenerator::VisitYield(Yield* expr) {
__ bind(&l_resume); // received in rax
__ PopTryHandler();
// receiver = iter; f = iter.next; arg = received;
// receiver = iter; f = 'next'; arg = received;
__ bind(&l_next);
__ movq(rcx, Operand(rsp, 1 * kPointerSize)); // iter
__ push(rcx); // iter
__ push(rax); // received
__ movq(rax, rcx); // iter
__ LoadRoot(rcx, Heap::knext_stringRootIndex); // "next"
Handle<Code> next_ic = isolate()->builtins()->LoadIC_Initialize();
CallIC(next_ic); // iter.next in rax
__ push(rcx);
__ push(Operand(rsp, 2 * kPointerSize)); // iter
__ push(rax); // received
// result = f.call(receiver, arg);
// result = receiver[f](arg);
__ bind(&l_call);
Label l_call_runtime;
__ JumpIfSmi(rax, &l_call_runtime);
__ CmpObjectType(rax, JS_FUNCTION_TYPE, rbx);
__ j(not_equal, &l_call_runtime);
__ movq(rdi, rax);
ParameterCount count(1);
__ InvokeFunction(rdi, count, CALL_FUNCTION,
NullCallWrapper(), CALL_AS_METHOD);
Handle<Code> ic = isolate()->stub_cache()->ComputeKeyedCallInitialize(1);
CallIC(ic);
__ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset));
__ jmp(&l_loop);
__ bind(&l_call_runtime);
__ push(rax);
__ CallRuntime(Runtime::kCall, 3);
__ Drop(1); // The key is still on the stack; drop it.
// val = result.value; if (!result.done) goto l_try;
__ bind(&l_loop);
......
// Copyright 2013 the V8 project authors. All rights reserved.
// 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.
// Flags: --harmony-generators
// Check that yield* on non-objects raises a TypeError.
assertThrows('(function*() { yield* 10 })().next()', TypeError);
assertThrows('(function*() { yield* {} })().next()', TypeError);
assertThrows('(function*() { yield* undefined })().next()', TypeError);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment