nashorn/test/script/basic/ranges_payload.js
author sundar
Thu, 13 Mar 2014 15:58:24 +0530
changeset 23374 f470afc89c6c
parent 17756 daaa1e643f71
permissions -rw-r--r--
8015958: DataView constructor is not defined Reviewed-by: attila, hannesw, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17756
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
     1
/*
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
     4
 * 
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
     7
 * published by the Free Software Foundation.
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
     8
 * 
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    13
 * accompanied this code).
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    14
 * 
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    18
 * 
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    21
 * questions.
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    22
 */
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    23
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    24
/**
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    25
 * range analysis test. check that computation return values are correct
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    26
 * both with and without range analysis
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    27
 *
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    28
 * @subtest
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    29
 */
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    30
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    31
function f(c) {
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    32
    var v = c & 0xffff;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    33
    var w = v & 0xfff;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    34
    var x = v * w;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    35
    return x;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    36
}
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    37
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    38
function g() {
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    39
    var sum = 0;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    40
    for (var x = 0; x < 4711; x++) {
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    41
	sum += x;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    42
    }
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    43
    return sum;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    44
}
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    45
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    46
function g2() {
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    47
    var sum = 0;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    48
    //make sure we overflow
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    49
    var displacement = 0x7ffffffe;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    50
    for (var x = displacement; x < (displacement + 2); x++) {
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    51
	sum += x;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    52
    }
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    53
    return sum;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    54
}
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    55
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    56
//mostly provide code coverage for all the range operations    
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    57
function h() {
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    58
    var sum = 0;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    59
    sum += 4711;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    60
    sum &= 0xffff;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    61
    sum /= 2;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    62
    sum *= 2;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    63
    sum -= 4;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    64
    sum |= 2;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    65
    sum ^= 17;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    66
    sum = sum % 10000;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    67
    sum = -sum;
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    68
    return sum
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    69
}
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    70
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    71
print(f(17));
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    72
print(g());
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    73
print(g2());
daaa1e643f71 8006069: Range analysis first iteration, runtime specializations
lagergren
parents:
diff changeset
    74
print(h());