test/script/basic/run-octane.js

Wed, 01 Oct 2014 07:47:24 -0700

author
asaha
date
Wed, 01 Oct 2014 07:47:24 -0700
changeset 1023
6a8ecdeae4a9
parent 963
e2497b11a021
child 1028
d79265f2fa92
permissions
-rw-r--r--

Added tag jdk8u40-b08 for changeset 89551828b279

     1 /*
     2  * Copyright (c) 2010, 2013, 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  */
    24 /**
    25  * @subtest
    26  */
    27 var payload = __DIR__ + "octane-payload.js";
    28 load(payload);
    30 var runtime = undefined;
    31 var verbose = false;
    33 var numberOfIterations = 5;
    35 function endsWith(str, suffix) {
    36     return str.indexOf(suffix, str.length - suffix.length) !== -1;
    37 }
    39 function should_compile_only(name) {
    40     return (typeof compile_only !== 'undefined')
    41 }
    43 function load_bench(arg) {
    45     for (var idx = 0; idx < arg.files.length; idx++) {
    46     var f = arg.files[idx];
    47     var file = f.split('/');
    48     var file_name = path + file[file.length - 1];
    50     var compile_and_return = should_compile_only(file_name);
    51     if (compile_and_return) {
    52         if (typeof compile_only === 'undefined') { //for a run, skip compile onlies, don't even compile them
    53         return true;
    54         }
    55     }
    57     print_verbose(arg, "loading '" + arg.name + "' [" + f + "]...");
    58     load(file_name);
    59     }
    61     if (typeof arg.before !== 'undefined') {
    62     arg.before();
    63     }
    65     if (compile_and_return) {
    66     print_always(arg, "Compiled OK");
    67     }
    68     return !compile_and_return;
    70 }
    73 function run_one_benchmark(arg, iters) {
    75     if (!load_bench(arg)) {
    76     return;
    77     }
    79     var success = true;
    80     var current_name;
    82     if (iters == undefined) {
    83     iters = numberOfIterations;
    84     } else {
    85     numberOfIterations = iters;
    86     }
    88     var benchmarks = eval(arg.suite + ".benchmarks");
    89     var min_score  = 1e9;
    90     var max_score  = 0;
    91     var mean_score = 0;
    93     try {
    94     for (var x = 0; x < benchmarks.length ; x++) {
    95         //do warmup run
    96         //reset random number generator needed as of octane 9 before each run
    97         BenchmarkSuite.ResetRNG();
    98         benchmarks[x].Setup();
    99     }
   100     BenchmarkSuite.ResetRNG();
   101     print_verbose(arg, "running '" + arg.name + "' for " + iters + " iterations of no less than " + min_time + " seconds");
   103     var scores = [];
   105     var min_time_ms = min_time * 1000;
   106     var len = benchmarks.length;
   108     for (var it = 0; it < iters + 1; it++) {
   109         //every iteration must take a minimum of 10 secs
   110         var ops = 0;
   111         var elapsed = 0;
   112         var start = new Date;
   113         do {
   114         for (var i = 0; i < len; i++) {
   115             benchmarks[i].run();
   116             //important - no timing here like elapsed = new Date() - start, as in the
   117             //original harness. This will make timing very non-deterministic.
   118             //NOTHING else must live in this loop
   119         }
   120         ops += len;
   121         elapsed = new Date - start;
   122         } while (elapsed < min_time * 1000);
   124         var score = ops / elapsed * 1000 * 60;
   125         scores.push(score);
   126         var name = it == 0 ? "warmup" : "iteration " + it;
   127         print_verbose(arg, name + " finished " + score.toFixed(0) + " ops/minute");
   128     }
   130     for (var x = 0; x < benchmarks.length ; x++) {
   131         benchmarks[x].TearDown();
   132     }
   134     for (var x = 1; x < iters + 1 ; x++) {
   135         mean_score += scores[x];
   136         min_score = Math.min(min_score, scores[x]);
   137         max_score = Math.max(max_score, scores[x]);
   138     }
   139     mean_score /= iters;
   140     } catch (e) {
   141     print_always(arg, "*** Aborted and setting score to zero. Reason: " + e);
   142     if (e instanceof java.lang.Throwable) {
   143         e.printStackTrace();
   144     }
   145     mean_score = min_score = max_score = 0;
   146     scores = [0];
   147     }
   149     var res = mean_score.toFixed(0);
   150     if (verbose) {
   151     res += " ops/minute (" + min_score.toFixed(0) + "-" + max_score.toFixed(0) + "), warmup=" + scores[0].toFixed(0);
   152     }
   153     print_always(arg, res);
   154 }
   156 function runtime_string() {
   157     return runtime == undefined ? "" : ("[" + runtime + "] ");
   158 }
   160 function print_always(arg, x) {
   161     print(runtime_string() + "[" + arg.name + "] " + x);
   162 }
   164 function print_verbose(arg, x) {
   165     if (verbose) {
   166     print_always(arg, x)
   167     }
   168 }
   170 function run_suite(tests, iters) {
   171     for (var idx = 0; idx < tests.length; idx++) {
   172     run_one_benchmark(tests[idx], iters);
   173     }
   174 }
   176 var args = [];
   178 if (typeof $ARGS !== 'undefined') {
   179     args = $ARGS;
   180 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
   181     args = arguments;
   182 }
   184 var new_args = [];
   185 for (i in args) {
   186     if (args[i].toString().indexOf(' ') != -1) {
   187     args[i] = args[i].replace(/\/$/, '');
   188     var s = args[i].split(' ');
   189     for (j in s) {
   190         new_args.push(s[j]);
   191     }
   192     } else {
   193     new_args.push(args[i]);
   194     }
   195 }
   197 if (new_args.length != 0) {
   198     args = new_args;
   199 }
   201 var tests_found = [];
   202 var iters = undefined;
   203 var min_time = 5;
   205 for (var i = 0; i < args.length; i++) {
   206     arg = args[i];
   207     if (arg == "--iterations") {
   208     iters = +args[++i];
   209     if (isNaN(iters)) {
   210         throw "'--iterations' must be followed by integer";
   211     }
   212     } else if (arg == "--runtime") {
   213     runtime = args[++i];
   214     } else if (arg == "--verbose") {
   215     verbose = true;
   216     } else if (arg == "--min-time") {
   217     min_time = +args[++i];
   218     if (isNaN(iters)) {
   219         throw "'--min-time' must be followed by integer";
   220     }
   221     } else if (arg == "") {
   222     continue; //skip
   223     } else {
   224     var found = false;
   225     for (j in tests) {
   226         if (tests[j].name === arg) {
   227         tests_found.push(tests[j]);
   228         found = true;
   229         break;
   230         }
   231     }
   232     if (!found) {
   233         var str = "unknown test name: '" + arg + "' -- valid names are: ";
   234         for (j in tests) {
   235         if (j != 0) {
   236             str += ", ";
   237         }
   238         str += "'" + tests[j].name + "'";
   239         }
   240         throw str;
   241     }
   242     }
   243 }
   245 if (tests_found.length == 0) {
   246     for (i in tests) {
   247     tests_found.push(tests[i]);
   248     }
   249 }
   251 // returns false for rhino, v8 and all other javascript runtimes, true for Nashorn
   252 function is_this_nashorn() {
   253     return typeof Error.dumpStack == 'function'
   254 }
   256 if (is_this_nashorn()) {
   257     try {
   258     read = readFully;
   259     } catch (e) {
   260     print("ABORTING: Cannot find 'readFully'. You must have scripting enabled to use this test harness. (-scripting)");
   261     throw e;
   262     }
   263 }
   265 // run tests in alphabetical order by name
   266 tests_found.sort(function(a, b) {
   267     if (a.name < b.name) {
   268     return -1;
   269     } else if (a.name > b.name) {
   270     return 1;
   271     } else {
   272     return 0;
   273     }
   274 });
   276 load(path + 'base.js');
   277 run_suite(tests_found, iters);

mercurial