Home | History | Annotate | Download | only in mjsunit
      1 // Copyright 2013 the V8 project authors. All rights reserved.
      2 // Redistribution and use in source and binary forms, with or without
      3 // modification, are permitted provided that the following conditions are
      4 // met:
      5 //
      6 //     * Redistributions of source code must retain the above copyright
      7 //       notice, this list of conditions and the following disclaimer.
      8 //     * Redistributions in binary form must reproduce the above
      9 //       copyright notice, this list of conditions and the following
     10 //       disclaimer in the documentation and/or other materials provided
     11 //       with the distribution.
     12 //     * Neither the name of Google Inc. nor the names of its
     13 //       contributors may be used to endorse or promote products derived
     14 //       from this software without specific prior written permission.
     15 //
     16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 // Flags: --allow-natives-syntax
     29 
     30 deopt_trigger = 0;
     31 side_effect = 0;
     32 
     33 function test(a, b, c, d, e, v) {
     34   // This test expects some specific input values.
     35   assertEquals(10.0, a);
     36   assertEquals(20.0, b);
     37   assertEquals(30.0, c);
     38   assertEquals(40.0, d);
     39   assertEquals(50.0, e);
     40   assertEquals(1.5, v);
     41 
     42   // Perform a few double calculations.
     43   a = a * 0.1;
     44   b = b * 0.2;
     45   c = c * 0.3;
     46   d = d * 0.4;
     47   e = e * 0.5;
     48 
     49   // Write to a field of a global object. As for any side effect, a HSimulate
     50   // will be introduced after the instructions to support this. If we deopt
     51   // later in this function, the execution will resume in full-codegen after
     52   // this point.
     53   side_effect++;
     54   // The following field of the global object will be deleted to force a deopt.
     55   // If we use type feedback to deopt, then tests ran with --stress-opt will
     56   // not deopt after a few iteration.
     57   // If we use %DeoptimizeFunction, all values will be on the frame due to the
     58   // call and we will not exercise the translation mechanism handling fp
     59   // registers.
     60   deopt_trigger = v;
     61 
     62   // Do a few more calculations using the previous values after our deopt point
     63   // so the floating point registers which hold those values are recorded in the
     64   // environment and will be used during deoptimization.
     65   a = a * v;
     66   b = b * v;
     67   c = c * v;
     68   d = d * v;
     69   e = e * v;
     70 
     71   // Check that we got the expected results.
     72   assertEquals(1.5,  a);
     73   assertEquals(6,    b);
     74   assertEquals(13.5, c);
     75   assertEquals(24,   d);
     76   assertEquals(37.5, e);
     77 }
     78 
     79 
     80 test(10.0, 20.0, 30.0, 40.0, 50.0, 1.5);
     81 test(10.0, 20.0, 30.0, 40.0, 50.0, 1.5);
     82 %OptimizeFunctionOnNextCall(test);
     83 test(10.0, 20.0, 30.0, 40.0, 50.0, 1.5);
     84 assertTrue(2 != %GetOptimizationStatus(test));
     85 
     86 // By deleting the field we are forcing the code to deopt when the field is
     87 // read on next execution.
     88 delete deopt_trigger;
     89 test(10.0, 20.0, 30.0, 40.0, 50.0, 1.5);
     90 assertTrue(1 != %GetOptimizationStatus(test));
     91