1b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Copyright 2013 the V8 project authors. All rights reserved. 21e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// Redistribution and use in source and binary forms, with or without 31e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// modification, are permitted provided that the following conditions are 41e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// met: 51e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// 61e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// * Redistributions of source code must retain the above copyright 71e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// notice, this list of conditions and the following disclaimer. 81e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// * Redistributions in binary form must reproduce the above 91e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// copyright notice, this list of conditions and the following 101e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// disclaimer in the documentation and/or other materials provided 111e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// with the distribution. 121e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// * Neither the name of Google Inc. nor the names of its 131e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// contributors may be used to endorse or promote products derived 141e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// from this software without specific prior written permission. 151e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// 161e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 171e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 181e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 191e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 201e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 211e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 221e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 261e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block 283fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch// Flags: --allow-natives-syntax 29b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Flags: --concurrent-recompilation --block-concurrent-recompilation 30014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// Flags: --nostress-opt 31014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch 32014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// --nostress-opt is in place because this particular optimization 33014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// (guaranteeing that the Array prototype chain has no elements) is 34014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// maintained isolate-wide. Once it's been "broken" by the change 35014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// to the Object prototype below, future compiles will not use the 36014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// optimization anymore, and the code will remain optimized despite 37014dc512cdd3e367bee49a713fdc5ed92584a3e5Ben Murdoch// additional changes to the prototype chain. 381e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block 39b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochif (!%IsConcurrentRecompilationSupported()) { 40b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch print("Concurrent recompilation is disabled. Skipping this test."); 41b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch quit(); 42b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch} 433fb3ca8c7ca439d408449a395897395c0faae8d1Ben Murdoch 44b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochfunction f1(a, i) { 45b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch return a[i] + 0.5; 461e0659c275bb392c045087af4f6b0d7565cb3d77Steve Block} 47e0cee9b3ed82e2391fd85d118aeaa4ea361c687dBen Murdoch 48b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdochvar arr = [0.0,,2.5]; 49b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0.5, f1(arr, 0)); 50b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0.5, f1(arr, 0)); 51b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch 52b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Optimized code of f1 depends on initial object and array maps. 53b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%OptimizeFunctionOnNextCall(f1, "concurrent"); 54b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Kick off recompilation; 55b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(0.5, f1(arr, 0)); 56b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Invalidate current initial object map after compile graph has been created. 57b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochObject.prototype[1] = 1.5; 58b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertEquals(2, f1(arr, 1)); 59b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Not yet optimized since concurrent recompilation is blocked. 60b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertUnoptimized(f1, "no sync"); 61b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Let concurrent recompilation proceed. 62b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%UnblockConcurrentRecompilation(); 63b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// Sync with background thread to conclude optimization, which bails out 64b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch// due to map dependency. 65b8a8cc1952d61a2f3a2568848933943a543b5d3eBen MurdochassertUnoptimized(f1, "sync"); 66b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch//Clear type info for stress runs. 67b8a8cc1952d61a2f3a2568848933943a543b5d3eBen Murdoch%ClearFunctionTypeFeedback(f1); 68