1 /*
   2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  * 
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  * 
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  * 
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  * 
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * JDK-8059835: Optimistic splitting doesn't work with let and const
  26  *
  27  * @test
  28  * @run
  29  * @option --language=es6
  30  * @option -Dnashorn.compiler.splitter.threshold=100
  31  * @fork
  32  */
  33 
  34 function f() {
  35     let sum = 0;
  36     const c = 13;
  37     if (true) {
  38         let x = 0;
  39         const y = 1;
  40         x += 1;
  41         x += 1;
  42         x += 1;
  43         x += 1;
  44         x += 1;
  45         x += 1;
  46         x += 1;
  47         x += 1;
  48         x += 1;
  49         x += 1;
  50         x += 1;
  51         x += 1;
  52         x += 1;
  53         x += 1;
  54         x += 1;
  55         x += 1;
  56         x += 1;
  57         x += 1;
  58         x += 1;
  59         x += 1;
  60         x += 1;
  61         x += 1;
  62         x += 1;
  63         x += 1;
  64         x += 1;
  65         x += 1;
  66         x += 1;
  67         x += 1;
  68         x += 1;
  69         x += 1;
  70         x += 1;
  71         x += 1;
  72         x += 1;
  73         sum += x;
  74         sum += y;
  75     }
  76     outer: while (true) {
  77         let x = 0;
  78         const y = 1;
  79         x += 1;
  80         x += 1;
  81         x += 1;
  82         x += 1;
  83         x += 1;
  84         x += 1;
  85         x += 1;
  86         x += 1;
  87         x += 1;
  88         x += 1;
  89         x += 1;
  90         x += 1;
  91         x += 1;
  92         x += 1;
  93         x += 1;
  94         x += 1;
  95         x += 1;
  96         x += 1;
  97         x += 1;
  98         x += 1;
  99         x += 1;
 100         x += 1;
 101         x += 1;
 102         x += 1;
 103         x += 1;
 104         x += 1;
 105         x += 1;
 106         x += 1;
 107         x += 1;
 108         x += 1;
 109         x += 1;
 110         x += 1;
 111         sum += x;
 112         sum += y;
 113         sum += c;
 114         let i = 0;
 115         const k = 1;
 116         while (true) {
 117             x += k;
 118             if (++i === 10) {
 119                 break outer;
 120             }
 121         }
 122         x += k;
 123     }
 124     return sum;
 125 }
 126 
 127 function g() {
 128     let sum = 0;
 129     const c = 13;
 130     if (true) {
 131         let x = 0;
 132         const y = 1;
 133         x += 1;
 134         x += 1;
 135         x += 1;
 136         x += 1;
 137         x += 1;
 138         x += 1;
 139         x += 1;
 140         x += 1;
 141         x += 1;
 142         x += 1;
 143         x += 1;
 144         x += 1;
 145         x += 1;
 146         x += 1;
 147         x += 1;
 148         x += 1;
 149         x += 1;
 150         x += 1;
 151         x += 1;
 152         x += 1;
 153         x += 1;
 154         x += 1;
 155         x += 1;
 156         x += 1;
 157         x += 1;
 158         x += 1;
 159         x += 1;
 160         x += 1;
 161         x += 1;
 162         x += 1;
 163         x += 1;
 164         x += 1;
 165         x += 1;
 166         sum += x;
 167         sum += y;
 168     }
 169     outer: while (true) {
 170         let x = 0;
 171         const y = 1;
 172         x += 1;
 173         x += 1;
 174         x += 1;
 175         x += 1;
 176         x += 1;
 177         x += 1;
 178         x += 1;
 179         x += 1;
 180         x += 1;
 181         x += 1;
 182         x += 1;
 183         x += 1;
 184         x += 1;
 185         x += 1;
 186         x += 1;
 187         x += 1;
 188         x += 1;
 189         x += 1;
 190         x += 1;
 191         x += 1;
 192         x += 1;
 193         x += 1;
 194         x += 1;
 195         x += 1;
 196         x += 1;
 197         x += 1;
 198         x += 1;
 199         x += 1;
 200         x += 1;
 201         x += 1;
 202         x += 1;
 203         x += 1;
 204         sum += x;
 205         sum += y;
 206         sum += c;
 207         let i = 0;
 208         const k = 1;
 209         while (true) {
 210             x += k;
 211             if (++i === 10) return 'abc';
 212         }
 213         x += k;
 214     }
 215     return sum;
 216 }
 217 
 218 Assert.assertTrue(f() === 80);
 219 Assert.assertTrue(g() === 'abc');