nashorn/test/script/basic/run-octane.js
author attila
Thu, 31 Jan 2013 18:34:42 +0100
changeset 16206 83069fa0935b
parent 16201 889ddb179cdf
child 16525 1409942e618e
permissions -rw-r--r--
8006529: Methods always get callee - it should be conditional Summary: This commit streamlines the bytecode function signatures, prologue, local variable use, scope creation, and invocation. It started out quite innocently when we noticed that we always emit __callee__ parameters for all functions even when they are not needed, but it turned out to be quite a deep rabbit hole. In the end, I identified exact conditions when functions need to have a callee parameter, when they need to receive parent scope, when they need to create their own scope, when they need to have variable arity signature, and when they need to have an "arguments" object, and made sure that callee parameters in signatures only show up when they are needed, that parent function's scope is only passed to a child function when it is needed, that the function only creates its own scope when it is needed. In crypto.js, the number of scopes dropped from 446 to 244, and the number of callees dropped from 315 to 145. Reviewed-by: jlaskey, lagergren

/*
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 * 
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 * 
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 * 
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

/**
 * @subtest
 */

var tests = [
    "box2d.js",
    "code-load.js",
    "crypto.js", 
    "deltablue.js", 
    "earley-boyer.js", 
    "gbemu.js",	     
    "navier-stokes.js", 
    "pdfjs.js",
    "raytrace.js",
    "regexp.js", 
    "richards.js", 
    "splay.js" 
];

// hack, teardown breaks things defined in the global space, making it impossible
// to do multiple consecutive benchmark runs with the same harness. I think it's a bug
// that the setup and teardown aren't each others constructor and destructor but rather
// that the benchmarks rely on partial global state. For shame, Octane! 
var ignoreTeardown = [
    { name: "box2d.js" },
    { name: "gbemu.js" },
];

var dir = (typeof(__DIR__) == 'undefined') ? "test/script/basic/" : __DIR__;

// TODO: why is this path hard coded when it's defined in project properties?
var path = dir + "../external/octane/";

var runtime = "";
var verbose = false;

var numberOfIterations = 5;

function endsWith(str, suffix) {
    return str.indexOf(suffix, str.length - suffix.length) !== -1;
}

function run_one_benchmark(arg, iters) {

    var file_name;
    var file = arg.split('/');
    if (file.length == 1) {
        file = arg.split('\\');
    }    

    //trim off trailing path separators
    while (file[file.length - 1].indexOf(".js") == -1) {
	file.pop();
    }
    file_name = file[file.length - 1];

    if (typeof compile_only !== 'undefined') {
	print("Compiling... " + file_name);
    }

    load(path + 'base.js');
    load(arg);
    
    if (typeof compile_only !== 'undefined') {
	print("Compiled OK: " + file_name);
	print("");
	return;
    }
    
    var success = true;
    var hiscore = 0;
    var loscore = 10e8;
    var current_name;
    
    function PrintResult(name, result) {
	current_name = name;
    }
        
    function PrintError(name, error) {
	current_name = name;
	PrintResult(name, error);
	success = false;
    }
        
    function PrintScore(score) {
	if (success) {
	    if (+score >= hiscore) {
		hiscore = +score;
	    }
	    if (+score <= loscore) {
		loscore = +score;
	    }
	}

	if (verbose) {
	    print("Score: " + score);
	}
    }
    
    if (iters == undefined) {
	iters = numberOfIterations;
    } else {
	numberOfIterations = iters;
    }

    print(runtime + ": running " + file_name + "...");

    for (var i = 0; i < numberOfIterations; i++) {
	var callbacks =
	    { NotifyResult: PrintResult,
	      NotifyError: PrintError,
	      NotifyScore: PrintScore };	

	for (j in ignoreTeardown) {
	    var ignore = ignoreTeardown[j];
	    if (endsWith(arg, ignore.name)) {
		var teardownOverride = ignore.teardown;
		if (!teardownOverride) {
		    teardownOverride = function() {};
		}

		for (k in BenchmarkSuite.suites) {
		    var benchmarks = BenchmarkSuite.suites[k].benchmarks;
		    for (l in benchmarks) {
			benchmarks[l].TearDown = teardownOverride;
		    }
                }
		break;
	    }
	}
	
	BenchmarkSuite.RunSuites(callbacks);
    }
    
    var start = "Score: ";
    if (runtime != "") {
	start = runtime + ": ";
    } 
    print(start + current_name + ' (version ' + BenchmarkSuite.version + '): ' + loscore + '-' + hiscore);
}

function run_suite(tests, iters) {
    for (var idx = 0; idx < tests.length; idx++) {
	run_one_benchmark(tests[idx], iters, false);
    }
}

runtime = "command line";

var args = [];
if (typeof $ARGS !== 'undefined') {
    args = $ARGS;
} else if (typeof arguments !== 'undefined' && arguments.length != 0) {
    args = arguments;
}  

var new_args = [];
for (i in args) {
    if (args[i].toString().indexOf(' ') != -1) {
	args[i] = args[i].replace(/\/$/, '');
	var s = args[i].split(' ');
	for (j in s) {
	    new_args.push(s[j]);
	}
    } else {
	new_args.push(args[i]);
    }
}

if (new_args.length != 0) {
    args = new_args;
}

var tests_found = [];
var iters = undefined;

for (var i = 0; i < args.length; i++) { 
    arg = args[i];
    if (arg == "--iterations") {
	iters = +args[++i];
    } else if (arg == "--runtime") {
	runtime = args[++i];
    } else if (arg == "--verbose") {
	verbose = true;
    } else if (arg == "") {
	continue; //skip
    } else {
	tests_found.push(arg);
    }
}

if (tests_found.length == 0) {    
    for (i in tests) {
	tests_found.push(path + tests[i]);
    }
} 

tests_found.sort();

run_suite(tests_found, iters);