1bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// Copyright 2013 the V8 project authors. All rights reserved.
2bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// Redistribution and use in source and binary forms, with or without
3bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// modification, are permitted provided that the following conditions are
4bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// met:
5bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//
6bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//     * Redistributions of source code must retain the above copyright
7bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//       notice, this list of conditions and the following disclaimer.
8bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//     * Redistributions in binary form must reproduce the above
9bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//       copyright notice, this list of conditions and the following
10bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//       disclaimer in the documentation and/or other materials provided
11bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//       with the distribution.
12bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//     * Neither the name of Google Inc. nor the names of its
13bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//       contributors may be used to endorse or promote products derived
14bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//       from this software without specific prior written permission.
15bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org//
16bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org
28bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// Flags: --expose-gc --allow-natives-syntax
29bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org
30bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgfunction f() {
31bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  return 23;
32bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org}
33bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org
34bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgfunction call(o) {
35bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  return o['']();
36bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org}
37bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org
38bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgfunction test() {
39bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  var o1 = %ToFastProperties(Object.create({ foo:1 }, { '': { value:f }}));
40bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  var o2 = %ToFastProperties(Object.create({ bar:1 }, { '': { value:f }}));
41bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  var o3 = %ToFastProperties(Object.create({ baz:1 }, { '': { value:f }}));
42bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  var o4 = %ToFastProperties(Object.create({ qux:1 }, { '': { value:f }}));
43bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  var o5 = %ToFastProperties(Object.create({ loo:1 }, { '': { value:f }}));
44bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  // Called twice on o1 to turn monomorphic.
45bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  assertEquals(23, call(o1));
46bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  assertEquals(23, call(o1));
47bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  // Called on four other objects to turn megamorphic.
48bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  assertEquals(23, call(o2));
49bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  assertEquals(23, call(o3));
50bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  assertEquals(23, call(o4));
51bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  assertEquals(23, call(o5));
52bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org  return o1;
53bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org}
54bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org
55bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// Fill stub cache with entries.
56bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgtest();
57bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org
58bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// Clear stub cache during GC.
59bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orggc();
60bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org
61bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// Turn IC megamorphic again.
62bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgvar oboom = test();
63bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org
64bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org// Optimize with previously cleared stub cache.
65bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.org%OptimizeFunctionOnNextCall(call);
66bf9432e3965b385e2e8df3701b710c105f5b3eb7ulan@chromium.orgassertEquals(23, call(oboom));
67