test/script/basic/JDK-8046905.js

Mon, 03 Nov 2014 09:49:52 +0100

author
attila
date
Mon, 03 Nov 2014 09:49:52 +0100
changeset 1090
99571b7922c0
parent 963
e2497b11a021
permissions
-rw-r--r--

8059443: NPE when unboxing return values
Reviewed-by: lagergren, sundar

attila@963 1 /*
attila@963 2 * Copyright (c) 2010, 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 * JDK-8046905: apply on apply is broken
attila@963 26 *
attila@963 27 * @test
attila@963 28 * @run
attila@963 29 */
attila@963 30
attila@963 31 var apply = Function.prototype.apply;
attila@963 32 var call = Function.prototype.call;
attila@963 33 var sort = Array.prototype.sort;
attila@963 34 var join = Array.prototype.join;
attila@963 35
attila@963 36 // Running three times so that we test an already linked call site too:
attila@963 37 // i==0: linking initially with assumed optimistic returned type int.
attila@963 38 // i==1: linking after deoptimization with returned type Object.
attila@963 39 // i==2: re-running code linked in previous iteration. This will
attila@963 40 // properly exercise the guards too.
attila@963 41 print("1 level of apply")
attila@963 42 for(i = 0; i < 3; ++i) {
attila@963 43 print(sort.apply([4,3,2,1]))
attila@963 44 }
attila@963 45 print("2 levels of apply")
attila@963 46 for(i = 0; i < 3; ++i) {
attila@963 47 print(apply.apply(sort,[[4,3,2,1]]))
attila@963 48 }
attila@963 49 print("3 levels of apply")
attila@963 50 for(i = 0; i < 3; ++i) {
attila@963 51 print(apply.apply(apply,[sort,[[4,3,2,1]]]))
attila@963 52 }
attila@963 53 print("4 levels of apply")
attila@963 54 for(i = 0; i < 3; ++i) {
attila@963 55 print(apply.apply(apply,[apply,[sort,[[4,3,2,1]]]]))
attila@963 56 }
attila@963 57 print("5 levels of apply")
attila@963 58 for(i = 0; i < 3; ++i) {
attila@963 59 print(apply.apply(apply,[apply,[apply,[sort,[[4,3,2,1]]]]]))
attila@963 60 }
attila@963 61 print("Many levels of apply!")
attila@963 62 for(i = 0; i < 3; ++i) {
attila@963 63 print(apply.apply(apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[apply,[sort,[[4,3,2,1]]]]]]]]]]]]]]]]]]]]]]))
attila@963 64 }
attila@963 65
attila@963 66 print("different invocations that'll trigger relinking")
attila@963 67 var invocation = [sort,[[4,3,2,1]]];
attila@963 68 for(i = 0; i < 4; ++i) {
attila@963 69 print(apply.apply(apply,[apply,invocation]))
attila@963 70 // First change after i==1, so it relinks an otherwise stable linkage
attila@963 71 if(i == 1) {
attila@963 72 invocation = [sort,[[8,7,6,5]]];
attila@963 73 } else if(i == 2) {
attila@963 74 invocation = [join,[[8,7,6,5],["-"]]];
attila@963 75 }
attila@963 76 }
attila@963 77
attila@963 78 print("Many levels of call!")
attila@963 79 for(i = 0; i < 3; ++i) {
attila@963 80 print(call.call(call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,call,sort,[4,3,2,1]))
attila@963 81 }
attila@963 82
attila@963 83 print("call apply call apply call... a lot");
attila@963 84 for(i = 0; i < 3; ++i) {
attila@963 85 print(apply.call(call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [sort, [4,3,2,1]]]]]]]))
attila@963 86 }
attila@963 87
attila@963 88 print("apply call apply call apply... a lot");
attila@963 89 for(i = 0; i < 3; ++i) {
attila@963 90 print(call.apply(apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, sort, [[4,3,2,1]]]]]]]]]))
attila@963 91 }

mercurial