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  */
  23 
  24 /**
  25  * Make sure that we run with the class cache off to so that every
  26  * run produces compile time and with optimistic type info caching
  27  * and persistent code store off, for the same reasons. These last two
  28  * are currently default, but this is not guaranteed to be the case
  29  * forever, so make this test future safe, we specify them explicitly
  30  *
  31  * This means that if you use this subtest as a compilation test
  32  * harness, pass the arguments:
  33  *
  34  * -scripting -Dnashorn.typeInfo.disabled=true --class-cache-size=0
  35  * --persistent-code-cache=false
  36  *
  37  * @subtest
  38  */
  39 
  40 load(__DIR__ + 'octane-payload.js');
  41 
  42 var DEFAULT_ITERS = 1; //default is one iteration through each benchmark
  43 var iters = DEFAULT_ITERS;
  44 var args = [];
  45 
  46 if (typeof $ARGS !== 'undefined') {
  47     args = $ARGS;
  48 } else if (typeof arguments !== 'undefined' && arguments.length != 0) {
  49     args = arguments;
  50 }
  51 
  52 var onlyTheseTests = [];
  53 var verbose = false;
  54 
  55 for (var i = 0; i < args.length; ) {
  56     var arg = args[i];
  57     if (arg === '--iterations') {
  58     iters = +args[++i];
  59     } else if (arg === '--verbose') {
  60     verbose = true;
  61     } else {
  62     onlyTheseTests.push(arg);
  63     }
  64     i++;
  65 }
  66 
  67 if (isNaN(iters)) {
  68     iters = DEFAULT_ITERS;
  69 }
  70 
  71 if (iters != DEFAULT_ITERS) {
  72     print("Running " + iters + " iterations of each compilation.");
  73 }
  74 
  75 function print_if_verbose(x) {
  76     if (verbose) {
  77     print(x);
  78     }
  79 }
  80 
  81 function contains(a, obj) {
  82     for (var i = 0; i < a.length; i++) {
  83         if (a[i] === obj) {
  84             return true;
  85         }
  86     }
  87     return false;
  88 }
  89 
  90 var testsCompiled = [];
  91 
  92 for (var j in tests) {
  93     var test_name = tests[j].name;
  94     var files = tests[j].files;
  95 
  96     if (onlyTheseTests.length > 0 && !contains(onlyTheseTests, test_name)) {
  97     print_if_verbose("Skipping " + test_name);
  98     continue;
  99     }
 100 
 101     if (!contains(testsCompiled, test_name)) {
 102     testsCompiled.push(test_name);
 103     }
 104 
 105     var str = "Compiling '" + test_name + "'...";
 106     if (files.length > 1) {
 107     str += " (" + files.length + " files)";
 108     }
 109     if (iters != 1) {
 110     str += " (" + iters + " times)";
 111     }
 112     str + "...";
 113     print(str);
 114 
 115     for (var iteration = 0; iteration < iters; iteration++) {
 116 
 117     //get a new global to avoid symbol pollution and reloads of base
 118     //in the same namespace
 119     var newGlobal = loadWithNewGlobal({script:'this', name:'test'});
 120 
 121     //load base into the new global so we get BenchmarkSuite etc
 122     newGlobal.load(base);
 123 
 124     //load all files in the single benchmark
 125     for (var k in files) {
 126         var file = files[k];
 127         if (iteration >= 0) { //only display message on first iteration
 128         var str2 = "\t";
 129         if (iters > 1) {
 130             str2 += " [iteration " + (iteration + 1) + "]";
 131         }
 132         str2 += " processing file: " + file + "...";
 133         print_if_verbose(str2);
 134         }
 135         newGlobal.load(new java.io.File(path + file).toURL());
 136     }
 137     }
 138     print("Done.");
 139 }
 140 
 141 if (testsCompiled.length == 0) {
 142     print("Error: no tests given to compile");
 143 }