JDK-8046905.js revision 904:6afee63aa1cc
1139804Simp/* 2185435Sbz * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. 3185435Sbz * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4191673Sjamie * 5185435Sbz * This code is free software; you can redistribute it and/or modify it 6190466Sjamie * under the terms of the GNU General Public License version 2 only, as 7185404Sbz * published by the Free Software Foundation. 8185404Sbz * 9185404Sbz * This code is distributed in the hope that it will be useful, but WITHOUT 10185404Sbz * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11185404Sbz * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12185404Sbz * version 2 for more details (a copy is included in the LICENSE file that 13185404Sbz * accompanied this code). 14185404Sbz * 15185404Sbz * You should have received a copy of the GNU General Public License version 16185404Sbz * 2 along with this work; if not, write to the Free Software Foundation, 17185404Sbz * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18185404Sbz * 19185404Sbz * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20185404Sbz * or visit www.oracle.com if you need additional information or have any 21185404Sbz * questions. 22185404Sbz */ 23185404Sbz 24185404Sbz/** 25185404Sbz * JDK-8046905: apply on apply is broken 26185404Sbz * 2746197Sphk * @test 2846155Sphk * @run 29116182Sobrien */ 30116182Sobrien 31116182Sobrienvar apply = Function.prototype.apply; 32193066Sjamievar call = Function.prototype.call; 33185435Sbzvar sort = Array.prototype.sort; 34185435Sbzvar join = Array.prototype.join; 35185435Sbz 36131177Spjd// Running three times so that we test an already linked call site too: 3746155Sphk// i==0: linking initially with assumed optimistic returned type int. 3846155Sphk// i==1: linking after deoptimization with returned type Object. 3946155Sphk// i==2: re-running code linked in previous iteration. This will 4046155Sphk// properly exercise the guards too. 4146155Sphkprint("1 level of apply") 4246155Sphkfor(i = 0; i < 3; ++i) { 4346155Sphk print(sort.apply([4,3,2,1])) 44192895Sjamie} 45164032Srwatsonprint("2 levels of apply") 4646155Sphkfor(i = 0; i < 3; ++i) { 47124882Srwatson print(apply.apply(sort,[[4,3,2,1]])) 48177785Skib} 4946155Sphkprint("3 levels of apply") 5087275Srwatsonfor(i = 0; i < 3; ++i) { 5187275Srwatson print(apply.apply(apply,[sort,[[4,3,2,1]]])) 52168401Spjd} 53193066Sjamieprint("4 levels of apply") 54113275Smikefor(i = 0; i < 3; ++i) { 55147185Spjd print(apply.apply(apply,[apply,[sort,[[4,3,2,1]]]])) 56113275Smike} 5746155Sphkprint("5 levels of apply") 58113275Smikefor(i = 0; i < 3; ++i) { 5957163Srwatson print(apply.apply(apply,[apply,[apply,[sort,[[4,3,2,1]]]]])) 60113275Smike} 61196019Srwatsonprint("Many levels of apply!") 6246155Sphkfor(i = 0; i < 3; ++i) { 63196019Srwatson 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]]]]]]]]]]]]]]]]]]]]]])) 64196019Srwatson} 6546155Sphk 66196019Srwatsonprint("different invocations that'll trigger relinking") 67185435Sbzvar invocation = [sort,[[4,3,2,1]]]; 68185435Sbzfor(i = 0; i < 4; ++i) { 69185435Sbz print(apply.apply(apply,[apply,invocation])) 70185435Sbz // First change after i==1, so it relinks an otherwise stable linkage 71185435Sbz if(i == 1) { 72185435Sbz invocation = [sort,[[8,7,6,5]]]; 7346155Sphk } else if(i == 2) { 74163606Srwatson invocation = [join,[[8,7,6,5],["-"]]]; 75163606Srwatson } 76195944Sjamie} 77195944Sjamie 7846155Sphkprint("Many levels of call!") 7946155Sphkfor(i = 0; i < 3; ++i) { 80192895Sjamie 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])) 81192895Sjamie} 82192895Sjamie 83192895Sjamieprint("call apply call apply call... a lot"); 84192895Sjamiefor(i = 0; i < 3; ++i) { 85192895Sjamie print(apply.call(call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [sort, [4,3,2,1]]]]]]])) 86192895Sjamie} 87192895Sjamie 88194762Sjamieprint("apply call apply call apply... a lot"); 89195944Sjamiefor(i = 0; i < 3; ++i) { 90192895Sjamie print(call.apply(apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, apply, [call, sort, [[4,3,2,1]]]]]]]]])) 91196176Sbz} 92196176Sbz