nashorn/test/script/trusted/optimistic_recompilation.js
author mnunez
Tue, 29 Apr 2014 16:00:53 +0200
changeset 24748 69787da7c664
child 24769 de4dcfa9380f
permissions -rw-r--r--
8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework Reviewed-by: attila, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24748
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
     1
/*
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
     4
 *
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
     7
 * published by the Free Software Foundation.
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
     8
 *
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    13
 * accompanied this code).
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    14
 *
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    18
 *
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    21
 * questions.
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    22
 */
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    23
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    24
/** 
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    25
 * Ask Debug for an event log of favourable events instead of using --log flags printing to screen 
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    26
 * @test
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    27
 * @bug 8037086,8038398
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    28
 * @fork
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    29
 * @option -Dnashorn.debug=true
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    30
 * @option --log=recompile:quiet
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    31
 */
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    32
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    33
var forName       = java.lang.Class["forName(String)"];
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    34
var RuntimeEvent  = forName("jdk.nashorn.internal.runtime.events.RuntimeEvent").static;
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    35
var getValue      = RuntimeEvent.class.getMethod("getValue");
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    36
var RewriteException = forName("jdk.nashorn.internal.runtime.RewriteException").static;
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    37
var getReturnType    = RewriteException.class.getMethod("getReturnType");
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    38
var RecompilationEvent = forName("jdk.nashorn.internal.runtime.events.RecompilationEvent").static;
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    39
var getReturnValue     = RecompilationEvent.class.getMethod("getReturnValue");
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    40
var setReturnTypeAndValue = [];
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    41
var expectedValues = [];
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    42
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    43
function checkExpectedRecompilation(f, expectedValues, testCase) {
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    44
    Debug.clearRuntimeEvents();
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    45
    print(f());
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    46
    events = Debug.getRuntimeEvents();
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    47
    //make sure we got runtime events
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    48
    print("events = " + (events.toString().indexOf("RuntimeEvent") != -1)); 
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    49
    if (events.length ==  expectedValues.length) {
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    50
        for (var i in events) {
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    51
            var e = events[i];
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    52
            var returnValue = getReturnValue.invoke(e);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    53
            if (typeof returnValue != 'undefined') {
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    54
	        setReturnTypeAndValue[i] = [getReturnType.invoke(getValue.invoke(e)), returnValue];
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    55
            } else {
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    56
                returnValue = "undefined";
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    57
                setReturnTypeAndValue[i] = [getReturnType.invoke(getValue.invoke(e)), returnValue];
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    58
            }
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    59
            if (!setReturnTypeAndValue[i].toString().equals(expectedValues[i].toString())) {
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    60
                fail("The return values are not as expected. Expected value: " + expectedValues[i] + " and got: " + setReturnTypeAndValue[i] + " in test case: " + f);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    61
            }
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    62
        }
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    63
    } else {
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    64
        fail("Number of Deoptimizing recompilation is not correct, expected: " + expectedValues.length + " and found: " + events.length + " in test case: " + f);       
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    65
    }    
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    66
}
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    67
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    68
checkExpectedRecompilation(function divisionByZeroTest() {var x = { a: 2, b:1 }; x.a = Number.POSITIVE_INFINITY; x.b = 0; print(x.a/x.b); return 1;}, 
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    69
                           expectedValues =[['double', 'Infinity']]);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    70
checkExpectedRecompilation(function divisionWithRemainderTest() {var x = { a: 7, b:2 }; print(x.a/x.b); return 1;}, expectedValues =[['double', '3.5']]);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    71
checkExpectedRecompilation(function infinityMultiplicationTest() {var x = { a: Number.POSITIVE_INFINITY, b: Number.POSITIVE_INFINITY}; print(x.a*x.b); return 1;}, 
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    72
                           expectedValues =[['double', 'Infinity']]);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    73
checkExpectedRecompilation(function maxValueMultiplicationTest() {var x = { a: Number.MAX_VALUE, b: Number.MAX_VALUE}; print(x.a*x.b); return 1;}, 
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    74
                           expectedValues =[['double', '1.7976931348623157e+308']]);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    75
checkExpectedRecompilation(function divisionByInfinityTest() {var x = { a: -1, b: Number.POSITIVE_INFINITY}; print(x.a/x.b); return 1;}, 
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    76
                           expectedValues =[['double', 'Infinity']]);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    77
checkExpectedRecompilation(function divisionByStringTest() {var x = { a: Number.POSITIVE_INFINITY, b: 'Hello'}; print(x.a/x.b); return 1;}, 
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    78
                           expectedValues =[['double', 'Infinity']]);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    79
checkExpectedRecompilation(function nestedFunctionTest() {var a=3,b,c; function f() {var x = 2, y =1; function g(){var y = x; var z = a; z = x*y; print(a*b)} g()}f(); return 1;}, 
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    80
                           expectedValues =[['object', 'undefined']]);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    81
checkExpectedRecompilation(function functionTest(a,b,c) { d = (a + b) * c; print(d); return 1;}, expectedValues =[['double', 'NaN']]);
69787da7c664 8038398: OptimisticRecompilationTest fails on staging repo nashorn/jdk9/nashorn due to test framework
mnunez
parents:
diff changeset
    82
checkExpectedRecompilation(function andTest(a,b) { d = a && b; print(d); return 1;}, expectedValues =[['object', 'undefined']]);