1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/test/compiler/7047069/Test7047069.java Fri May 27 12:47:48 2011 -0700 1.3 @@ -0,0 +1,200 @@ 1.4 +/* 1.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +/** 1.29 + * @test 1.30 + * @bug 7047069 1.31 + * @summary Array can dynamically change size when assigned to an object field 1.32 + * 1.33 + * @run main/othervm -Xbatch Test7047069 1.34 + */ 1.35 + 1.36 +import java.util.*; 1.37 +import java.awt.geom.*; 1.38 + 1.39 +public class Test7047069 { 1.40 + static boolean verbose; 1.41 + 1.42 + static final int GROW_SIZE = 24; // Multiple of cubic & quad curve size 1.43 + 1.44 + float squareflat; // Square of the flatness parameter 1.45 + // for testing against squared lengths 1.46 + 1.47 + int limit; // Maximum number of recursion levels 1.48 + 1.49 + float hold[] = new float[14]; // The cache of interpolated coords 1.50 + // Note that this must be long enough 1.51 + // to store a full cubic segment and 1.52 + // a relative cubic segment to avoid 1.53 + // aliasing when copying the coords 1.54 + // of a curve to the end of the array. 1.55 + // This is also serendipitously equal 1.56 + // to the size of a full quad segment 1.57 + // and 2 relative quad segments. 1.58 + 1.59 + int holdEnd; // The index of the last curve segment 1.60 + // being held for interpolation 1.61 + 1.62 + int holdIndex; // The index of the curve segment 1.63 + // that was last interpolated. This 1.64 + // is the curve segment ready to be 1.65 + // returned in the next call to 1.66 + // currentSegment(). 1.67 + 1.68 + int levels[]; // The recursion level at which 1.69 + // each curve being held in storage 1.70 + // was generated. 1.71 + 1.72 + int levelIndex; // The index of the entry in the 1.73 + // levels array of the curve segment 1.74 + // at the holdIndex 1.75 + 1.76 + public static void subdivide(float src[], int srcoff, 1.77 + float left[], int leftoff, 1.78 + float right[], int rightoff) 1.79 + { 1.80 + float x1 = src[srcoff + 0]; 1.81 + float y1 = src[srcoff + 1]; 1.82 + float ctrlx = src[srcoff + 2]; 1.83 + float ctrly = src[srcoff + 3]; 1.84 + float x2 = src[srcoff + 4]; 1.85 + float y2 = src[srcoff + 5]; 1.86 + if (left != null) { 1.87 + left[leftoff + 0] = x1; 1.88 + left[leftoff + 1] = y1; 1.89 + } 1.90 + if (right != null) { 1.91 + right[rightoff + 4] = x2; 1.92 + right[rightoff + 5] = y2; 1.93 + } 1.94 + x1 = (x1 + ctrlx) / 2f; 1.95 + y1 = (y1 + ctrly) / 2f; 1.96 + x2 = (x2 + ctrlx) / 2f; 1.97 + y2 = (y2 + ctrly) / 2f; 1.98 + ctrlx = (x1 + x2) / 2f; 1.99 + ctrly = (y1 + y2) / 2f; 1.100 + if (left != null) { 1.101 + left[leftoff + 2] = x1; 1.102 + left[leftoff + 3] = y1; 1.103 + left[leftoff + 4] = ctrlx; 1.104 + left[leftoff + 5] = ctrly; 1.105 + } 1.106 + if (right != null) { 1.107 + right[rightoff + 0] = ctrlx; 1.108 + right[rightoff + 1] = ctrly; 1.109 + right[rightoff + 2] = x2; 1.110 + right[rightoff + 3] = y2; 1.111 + } 1.112 + } 1.113 + 1.114 + public static double getFlatnessSq(float coords[], int offset) { 1.115 + return Line2D.ptSegDistSq(coords[offset + 0], coords[offset + 1], 1.116 + coords[offset + 4], coords[offset + 5], 1.117 + coords[offset + 2], coords[offset + 3]); 1.118 + } 1.119 + 1.120 + public Test7047069() { 1.121 + this.squareflat = .0001f * .0001f; 1.122 + holdIndex = hold.length - 6; 1.123 + holdEnd = hold.length - 2; 1.124 + hold[holdIndex + 0] = (float) (Math.random() * 100); 1.125 + hold[holdIndex + 1] = (float) (Math.random() * 100); 1.126 + hold[holdIndex + 2] = (float) (Math.random() * 100); 1.127 + hold[holdIndex + 3] = (float) (Math.random() * 100); 1.128 + hold[holdIndex + 4] = (float) (Math.random() * 100); 1.129 + hold[holdIndex + 5] = (float) (Math.random() * 100); 1.130 + levelIndex = 0; 1.131 + this.limit = 10; 1.132 + this.levels = new int[limit + 1]; 1.133 + } 1.134 + 1.135 + /* 1.136 + * Ensures that the hold array can hold up to (want) more values. 1.137 + * It is currently holding (hold.length - holdIndex) values. 1.138 + */ 1.139 + void ensureHoldCapacity(int want) { 1.140 + if (holdIndex - want < 0) { 1.141 + int have = hold.length - holdIndex; 1.142 + int newsize = hold.length + GROW_SIZE; 1.143 + float newhold[] = new float[newsize]; 1.144 + System.arraycopy(hold, holdIndex, 1.145 + newhold, holdIndex + GROW_SIZE, 1.146 + have); 1.147 + if (verbose) System.err.println("old hold = "+hold+"["+hold.length+"]"); 1.148 + if (verbose) System.err.println("replacement hold = "+newhold+"["+newhold.length+"]"); 1.149 + hold = newhold; 1.150 + if (verbose) System.err.println("new hold = "+hold+"["+hold.length+"]"); 1.151 + if (verbose) System.err.println("replacement hold still = "+newhold+"["+newhold.length+"]"); 1.152 + holdIndex += GROW_SIZE; 1.153 + holdEnd += GROW_SIZE; 1.154 + } 1.155 + } 1.156 + 1.157 + private boolean next() { 1.158 + if (holdIndex >= holdEnd) { 1.159 + return false; 1.160 + } 1.161 + 1.162 + int level = levels[levelIndex]; 1.163 + while (level < limit) { 1.164 + if (getFlatnessSq(hold, holdIndex) < squareflat) { 1.165 + break; 1.166 + } 1.167 + 1.168 + ensureHoldCapacity(4); 1.169 + subdivide(hold, holdIndex, 1.170 + hold, holdIndex - 4, 1.171 + hold, holdIndex); 1.172 + holdIndex -= 4; 1.173 + 1.174 + // Now that we have subdivided, we have constructed 1.175 + // two curves of one depth lower than the original 1.176 + // curve. One of those curves is in the place of 1.177 + // the former curve and one of them is in the next 1.178 + // set of held coordinate slots. We now set both 1.179 + // curves level values to the next higher level. 1.180 + level++; 1.181 + levels[levelIndex] = level; 1.182 + levelIndex++; 1.183 + levels[levelIndex] = level; 1.184 + } 1.185 + 1.186 + // This curve segment is flat enough, or it is too deep 1.187 + // in recursion levels to try to flatten any more. The 1.188 + // two coordinates at holdIndex+4 and holdIndex+5 now 1.189 + // contain the endpoint of the curve which can be the 1.190 + // endpoint of an approximating line segment. 1.191 + holdIndex += 4; 1.192 + levelIndex--; 1.193 + return true; 1.194 + } 1.195 + 1.196 + public static void main(String argv[]) { 1.197 + verbose = (argv.length > 0); 1.198 + for (int i = 0; i < 100000; i++) { 1.199 + Test7047069 st = new Test7047069(); 1.200 + while (st.next()) {} 1.201 + } 1.202 + } 1.203 +}