Revision: 15111
Author:   [email protected]
Date:     Thu Jun 13 03:18:28 2013
Log:      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
[email protected]
TEST=mjsunit/regress/regress-2691

Review URL: https://codereview.chromium.org/15455002
http://code.google.com/p/v8/source/detail?r=15111

Added:
 /branches/bleeding_edge/test/mjsunit/regress/regress-2691.js
Modified:
 /branches/bleeding_edge/src/arm/full-codegen-arm.cc
 /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc
 /branches/bleeding_edge/src/x64/full-codegen-x64.cc

=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/regress/regress-2691.js Thu Jun 13 03:18:28 2013
@@ -0,0 +1,34 @@
+// 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);
=======================================
--- /branches/bleeding_edge/src/arm/full-codegen-arm.cc Wed Jun 12 08:03:44 2013 +++ /branches/bleeding_edge/src/arm/full-codegen-arm.cc Thu Jun 13 03:18:28 2013
@@ -2035,16 +2035,13 @@
       __ 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 @@
       __ 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);
=======================================
--- /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Wed Jun 12 08:03:44 2013 +++ /branches/bleeding_edge/src/ia32/full-codegen-ia32.cc Thu Jun 13 03:18:28 2013
@@ -1994,15 +1994,13 @@
       __ 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 @@

       // 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);
=======================================
--- /branches/bleeding_edge/src/x64/full-codegen-x64.cc Wed Jun 12 08:03:44 2013 +++ /branches/bleeding_edge/src/x64/full-codegen-x64.cc Thu Jun 13 03:18:28 2013
@@ -2017,16 +2017,13 @@
       __ 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 @@
       __ 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);

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to