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