1 /* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 public class InlinedArrayCloneTestCase implements Runnable { 25 private Test_ia32 executionController; 26 27 public InlinedArrayCloneTestCase(Test_ia32 executionController) { 28 this.executionController = executionController; 29 } 30 31 /* 32 * Please leave following two methods (invokeArrayClone and verifyArguments) 33 * static. 34 * 35 * It does not really matter if these methods are static or instance, 36 * original issue could be reproduced in both cases, but if these methods 37 * are static then it is much easier to understand that reproduced issue 38 * is actually interpreter's stack corruption. 39 * 40 * If these methods are non-static, then interpreter's stack will contain 41 * invalid 'this' pointer required for instance's method call and 42 * verifyArguments' call may throw NullPointerException. There was another 43 * issue w/ NPE after deoptimization addressed by JDK-6833129, so NPE looks 44 * a little bit confusing. 45 * 46 * If these methods are static then after deptimization we'll get incorrect 47 * arguments values in verifyArguments. 48 * Something like "2, -1289936896, 3, 4" instead of "1, 2, 3, 4". 49 * This information tells much more about actual issue comparing to NPE, 50 * so it's preferable to leave these methods static. 51 */ 52 private static int verifyArguments(int i1, int i2, LoadedClass[] arr, 53 int i3, int i4) { 54 if (!(i1==1 && i2==2 && i3==3 && i4==4)) { 55 throw new RuntimeException(String.format( 56 "Arguments have unexpected values: %d, %d, %d, %d", 57 i1, i2, i3, i4)); 58 } 59 return arr.length; 60 } 61 62 private static int invokeArrayClone(LoadedClass[] a) { 63 return InlinedArrayCloneTestCase.verifyArguments(1, 2, a.clone(), 3, 4); 64 } 65 66 @Override 67 public void run() { 68 LoadedClass[] array = executionController.getArray(); 69 int length; 70 71 while (executionController.continueExecution()) { 72 try { 73 length = InlinedArrayCloneTestCase.invokeArrayClone(array); 74 } catch (Throwable e) { 75 e.printStackTrace(); 76 executionController.setTestFailed(); 77 return; 78 } 79 if (length != array.length) { 80 System.out.println(String.format("f(array) returned %d " 81 + "instead of %d.", length, array.length)); 82 executionController.setTestFailed(); 83 } 84 } 85 } 86 }