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

jlaskey@3 1 /*
jlaskey@7 2 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
jlaskey@3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
attila@962 4 *
jlaskey@3 5 * This code is free software; you can redistribute it and/or modify it
jlaskey@3 6 * under the terms of the GNU General Public License version 2 only, as
jlaskey@3 7 * published by the Free Software Foundation.
attila@962 8 *
jlaskey@3 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jlaskey@3 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jlaskey@3 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jlaskey@3 12 * version 2 for more details (a copy is included in the LICENSE file that
jlaskey@3 13 * accompanied this code).
attila@962 14 *
jlaskey@3 15 * You should have received a copy of the GNU General Public License version
jlaskey@3 16 * 2 along with this work; if not, write to the Free Software Foundation,
jlaskey@3 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
attila@962 18 *
jlaskey@3 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jlaskey@3 20 * or visit www.oracle.com if you need additional information or have any
jlaskey@3 21 * questions.
jlaskey@3 22 */
jlaskey@3 23
jlaskey@3 24 /**
jlaskey@3 25 * @subtest
jlaskey@3 26 */
attila@963 27 var payload = __DIR__ + "octane-payload.js";
attila@963 28 load(payload);
jlaskey@3 29
attila@963 30 var runtime = undefined;
jlaskey@3 31 var verbose = false;
jlaskey@3 32
jlaskey@3 33 var numberOfIterations = 5;
jlaskey@3 34
jlaskey@3 35 function endsWith(str, suffix) {
jlaskey@3 36 return str.indexOf(suffix, str.length - suffix.length) !== -1;
jlaskey@3 37 }
jlaskey@3 38
lagergren@139 39 function should_compile_only(name) {
lagergren@295 40 return (typeof compile_only !== 'undefined')
lagergren@139 41 }
lagergren@139 42
lagergren@693 43 function load_bench(arg) {
lagergren@693 44
lagergren@693 45 for (var idx = 0; idx < arg.files.length; idx++) {
attila@962 46 var f = arg.files[idx];
attila@962 47 var file = f.split('/');
attila@962 48 var file_name = path + file[file.length - 1];
attila@962 49
attila@962 50 var compile_and_return = should_compile_only(file_name);
attila@962 51 if (compile_and_return) {
attila@962 52 if (typeof compile_only === 'undefined') { //for a run, skip compile onlies, don't even compile them
attila@962 53 return true;
attila@962 54 }
attila@962 55 }
attila@962 56
attila@962 57 print_verbose(arg, "loading '" + arg.name + "' [" + f + "]...");
attila@962 58 load(file_name);
lagergren@693 59 }
lagergren@693 60
attila@963 61 if (typeof arg.before !== 'undefined') {
attila@963 62 arg.before();
attila@963 63 }
attila@963 64
lagergren@693 65 if (compile_and_return) {
attila@962 66 print_always(arg, "Compiled OK");
lagergren@693 67 }
lagergren@693 68 return !compile_and_return;
lagergren@693 69
lagergren@693 70 }
lagergren@693 71
attila@963 72
jlaskey@3 73 function run_one_benchmark(arg, iters) {
lagergren@693 74
lagergren@693 75 if (!load_bench(arg)) {
attila@962 76 return;
attila@962 77 }
attila@962 78
jlaskey@3 79 var success = true;
jlaskey@3 80 var current_name;
attila@962 81
jlaskey@3 82 if (iters == undefined) {
attila@962 83 iters = numberOfIterations;
jlaskey@3 84 } else {
attila@962 85 numberOfIterations = iters;
jlaskey@3 86 }
attila@962 87
lagergren@295 88 var benchmarks = eval(arg.suite + ".benchmarks");
lagergren@295 89 var min_score = 1e9;
lagergren@295 90 var max_score = 0;
lagergren@295 91 var mean_score = 0;
lagergren@298 92
lagergren@298 93 try {
attila@962 94 for (var x = 0; x < benchmarks.length ; x++) {
attila@962 95 //do warmup run
attila@962 96 //reset random number generator needed as of octane 9 before each run
attila@962 97 BenchmarkSuite.ResetRNG();
attila@962 98 benchmarks[x].Setup();
attila@962 99 }
attila@962 100 BenchmarkSuite.ResetRNG();
attila@963 101 print_verbose(arg, "running '" + arg.name + "' for " + iters + " iterations of no less than " + min_time + " seconds");
lagergren@298 102
attila@962 103 var scores = [];
lagergren@298 104
attila@962 105 var min_time_ms = min_time * 1000;
attila@962 106 var len = benchmarks.length;
attila@962 107
attila@962 108 for (var it = 0; it < iters + 1; it++) {
attila@962 109 //every iteration must take a minimum of 10 secs
attila@962 110 var ops = 0;
attila@962 111 var elapsed = 0;
attila@962 112 var start = new Date;
attila@962 113 do {
attila@962 114 for (var i = 0; i < len; i++) {
attila@962 115 benchmarks[i].run();
attila@962 116 //important - no timing here like elapsed = new Date() - start, as in the
attila@962 117 //original harness. This will make timing very non-deterministic.
attila@962 118 //NOTHING else must live in this loop
attila@962 119 }
attila@962 120 ops += len;
attila@962 121 elapsed = new Date - start;
attila@962 122 } while (elapsed < min_time * 1000);
attila@962 123
attila@962 124 var score = ops / elapsed * 1000 * 60;
attila@962 125 scores.push(score);
attila@962 126 var name = it == 0 ? "warmup" : "iteration " + it;
attila@962 127 print_verbose(arg, name + " finished " + score.toFixed(0) + " ops/minute");
attila@962 128 }
attila@962 129
attila@962 130 for (var x = 0; x < benchmarks.length ; x++) {
attila@962 131 benchmarks[x].TearDown();
attila@962 132 }
attila@962 133
attila@962 134 for (var x = 1; x < iters + 1 ; x++) {
attila@962 135 mean_score += scores[x];
attila@962 136 min_score = Math.min(min_score, scores[x]);
attila@962 137 max_score = Math.max(max_score, scores[x]);
attila@962 138 }
attila@962 139 mean_score /= iters;
lagergren@298 140 } catch (e) {
attila@963 141 print_always(arg, "*** Aborted and setting score to zero. Reason: " + e);
attila@963 142 if (e instanceof java.lang.Throwable) {
attila@963 143 e.printStackTrace();
attila@963 144 }
attila@962 145 mean_score = min_score = max_score = 0;
attila@962 146 scores = [0];
lagergren@295 147 }
lagergren@298 148
lagergren@693 149 var res = mean_score.toFixed(0);
lagergren@295 150 if (verbose) {
attila@962 151 res += " ops/minute (" + min_score.toFixed(0) + "-" + max_score.toFixed(0) + "), warmup=" + scores[0].toFixed(0);
lagergren@295 152 }
lagergren@693 153 print_always(arg, res);
lagergren@295 154 }
jlaskey@3 155
attila@963 156 function runtime_string() {
attila@963 157 return runtime == undefined ? "" : ("[" + runtime + "] ");
attila@963 158 }
attila@963 159
lagergren@693 160 function print_always(arg, x) {
attila@963 161 print(runtime_string() + "[" + arg.name + "] " + x);
lagergren@295 162 }
jlaskey@3 163
lagergren@693 164 function print_verbose(arg, x) {
lagergren@295 165 if (verbose) {
attila@962 166 print_always(arg, x)
jlaskey@3 167 }
jlaskey@3 168 }
jlaskey@3 169
jlaskey@3 170 function run_suite(tests, iters) {
jlaskey@3 171 for (var idx = 0; idx < tests.length; idx++) {
attila@962 172 run_one_benchmark(tests[idx], iters);
jlaskey@3 173 }
jlaskey@3 174 }
jlaskey@3 175
jlaskey@3 176 var args = [];
lagergren@298 177
jlaskey@3 178 if (typeof $ARGS !== 'undefined') {
jlaskey@3 179 args = $ARGS;
jlaskey@3 180 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
jlaskey@3 181 args = arguments;
attila@962 182 }
jlaskey@3 183
jlaskey@3 184 var new_args = [];
jlaskey@3 185 for (i in args) {
jlaskey@3 186 if (args[i].toString().indexOf(' ') != -1) {
attila@962 187 args[i] = args[i].replace(/\/$/, '');
attila@962 188 var s = args[i].split(' ');
attila@962 189 for (j in s) {
attila@962 190 new_args.push(s[j]);
attila@962 191 }
jlaskey@3 192 } else {
attila@962 193 new_args.push(args[i]);
jlaskey@3 194 }
jlaskey@3 195 }
jlaskey@3 196
jlaskey@3 197 if (new_args.length != 0) {
jlaskey@3 198 args = new_args;
jlaskey@3 199 }
jlaskey@3 200
jlaskey@3 201 var tests_found = [];
jlaskey@3 202 var iters = undefined;
lagergren@295 203 var min_time = 5;
jlaskey@3 204
attila@962 205 for (var i = 0; i < args.length; i++) {
jlaskey@3 206 arg = args[i];
jlaskey@3 207 if (arg == "--iterations") {
attila@962 208 iters = +args[++i];
attila@963 209 if (isNaN(iters)) {
attila@963 210 throw "'--iterations' must be followed by integer";
attila@963 211 }
jlaskey@3 212 } else if (arg == "--runtime") {
attila@962 213 runtime = args[++i];
jlaskey@3 214 } else if (arg == "--verbose") {
attila@962 215 verbose = true;
lagergren@295 216 } else if (arg == "--min-time") {
attila@962 217 min_time = +args[++i];
attila@963 218 if (isNaN(iters)) {
attila@963 219 throw "'--min-time' must be followed by integer";
attila@963 220 }
jlaskey@3 221 } else if (arg == "") {
attila@962 222 continue; //skip
jlaskey@3 223 } else {
attila@962 224 var found = false;
attila@962 225 for (j in tests) {
attila@962 226 if (tests[j].name === arg) {
attila@962 227 tests_found.push(tests[j]);
attila@962 228 found = true;
attila@962 229 break;
attila@962 230 }
attila@962 231 }
attila@962 232 if (!found) {
attila@962 233 var str = "unknown test name: '" + arg + "' -- valid names are: ";
attila@962 234 for (j in tests) {
attila@962 235 if (j != 0) {
attila@962 236 str += ", ";
attila@962 237 }
attila@962 238 str += "'" + tests[j].name + "'";
attila@962 239 }
attila@962 240 throw str;
attila@962 241 }
jlaskey@3 242 }
jlaskey@3 243 }
jlaskey@3 244
attila@962 245 if (tests_found.length == 0) {
jlaskey@3 246 for (i in tests) {
attila@962 247 tests_found.push(tests[i]);
jlaskey@3 248 }
attila@962 249 }
jlaskey@3 250
attila@963 251 // returns false for rhino, v8 and all other javascript runtimes, true for Nashorn
attila@963 252 function is_this_nashorn() {
attila@963 253 return typeof Error.dumpStack == 'function'
attila@963 254 }
attila@963 255
attila@963 256 if (is_this_nashorn()) {
attila@963 257 try {
attila@963 258 read = readFully;
attila@963 259 } catch (e) {
attila@963 260 print("ABORTING: Cannot find 'readFully'. You must have scripting enabled to use this test harness. (-scripting)");
attila@963 261 throw e;
attila@963 262 }
attila@963 263 }
attila@963 264
attila@963 265 // run tests in alphabetical order by name
attila@963 266 tests_found.sort(function(a, b) {
attila@963 267 if (a.name < b.name) {
attila@963 268 return -1;
attila@963 269 } else if (a.name > b.name) {
attila@963 270 return 1;
attila@963 271 } else {
attila@963 272 return 0;
attila@963 273 }
attila@963 274 });
jlaskey@3 275
lagergren@295 276 load(path + 'base.js');
jlaskey@3 277 run_suite(tests_found, iters);

mercurial