attila@963: /* attila@963: * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. attila@963: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. attila@963: * attila@963: * This code is free software; you can redistribute it and/or modify it attila@963: * under the terms of the GNU General Public License version 2 only, as attila@963: * published by the Free Software Foundation. attila@963: * attila@963: * This code is distributed in the hope that it will be useful, but WITHOUT attila@963: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or attila@963: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License attila@963: * version 2 for more details (a copy is included in the LICENSE file that attila@963: * accompanied this code). attila@963: * attila@963: * You should have received a copy of the GNU General Public License version attila@963: * 2 along with this work; if not, write to the Free Software Foundation, attila@963: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. attila@963: * attila@963: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA attila@963: * or visit www.oracle.com if you need additional information or have any attila@963: * questions. attila@963: */ attila@963: attila@963: /** attila@963: * JDK-8046905: apply on apply is broken attila@963: * attila@963: * @test attila@963: * @run attila@963: */ attila@963: attila@963: var apply = Function.prototype.apply; attila@963: var call = Function.prototype.call; attila@963: var sort = Array.prototype.sort; attila@963: var join = Array.prototype.join; attila@963: attila@963: // Running three times so that we test an already linked call site too: attila@963: // i==0: linking initially with assumed optimistic returned type int. attila@963: // i==1: linking after deoptimization with returned type Object. attila@963: // i==2: re-running code linked in previous iteration. This will attila@963: // properly exercise the guards too. attila@963: print("1 level of apply") attila@963: for(i = 0; i < 3; ++i) { attila@963: print(sort.apply([4,3,2,1])) attila@963: } attila@963: print("2 levels of apply") attila@963: for(i = 0; i < 3; ++i) { attila@963: print(apply.apply(sort,[[4,3,2,1]])) attila@963: } attila@963: print("3 levels of apply") attila@963: for(i = 0; i < 3; ++i) { attila@963: print(apply.apply(apply,[sort,[[4,3,2,1]]])) attila@963: } attila@963: print("4 levels of apply") attila@963: for(i = 0; i < 3; ++i) { attila@963: print(apply.apply(apply,[apply,[sort,[[4,3,2,1]]]])) attila@963: } attila@963: print("5 levels of apply") attila@963: for(i = 0; i < 3; ++i) { attila@963: print(apply.apply(apply,[apply,[apply,[sort,[[4,3,2,1]]]]])) attila@963: } attila@963: print("Many levels of apply!") attila@963: for(i = 0; i < 3; ++i) { attila@963: 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: } attila@963: attila@963: print("different invocations that'll trigger relinking") attila@963: var invocation = [sort,[[4,3,2,1]]]; attila@963: for(i = 0; i < 4; ++i) { attila@963: print(apply.apply(apply,[apply,invocation])) attila@963: // First change after i==1, so it relinks an otherwise stable linkage attila@963: if(i == 1) { attila@963: invocation = [sort,[[8,7,6,5]]]; attila@963: } else if(i == 2) { attila@963: invocation = [join,[[8,7,6,5],["-"]]]; attila@963: } attila@963: } attila@963: attila@963: print("Many levels of call!") attila@963: for(i = 0; i < 3; ++i) { attila@963: 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: } attila@963: attila@963: print("call apply call apply call... a lot"); attila@963: for(i = 0; i < 3; ++i) { attila@963: print(apply.call(call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [sort, [4,3,2,1]]]]]]])) attila@963: } attila@963: attila@963: print("apply call apply call apply... a lot"); attila@963: for(i = 0; i < 3; ++i) { attila@963: print(call.apply(apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, sort, [[4,3,2,1]]]]]]]]])) attila@963: }