OpenJDK / jigsaw / jake / jdk
changeset 14189:3c09abf433f0
Merge
author | amurillo |
---|---|
date | Tue, 22 Sep 2015 11:01:54 -0700 |
parents | 95636dbc11e3 200804e4ba28 |
children | 69f78bcd65f8 |
files | src/java.base/share/native/libfdlibm/e_pow.c src/java.base/share/native/libfdlibm/w_pow.c src/java.desktop/share/classes/sun/awt/image/AbstractMultiResolutionImage.java src/java.desktop/share/classes/sun/awt/image/MultiResolutionImage.java |
diffstat | 92 files changed, 5018 insertions(+), 2770 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags Thu Sep 17 09:19:40 2015 -0700 +++ b/.hgtags Tue Sep 22 11:01:54 2015 -0700 @@ -324,3 +324,4 @@ d99c2ffdd0f15753e69126583688f2f075a0a5e8 jdk9-b79 4947810137ae53abba3028cc366af953d90fa81a jdk9-b80 fdc13a2d32867ca3c57b7fa2620c6b59c83168cb jdk9-b81 +b10b64263b563e21f055c881444f625ec618b826 jdk9-b82
--- a/make/lib/CoreLibraries.gmk Thu Sep 17 09:19:40 2015 -0700 +++ b/make/lib/CoreLibraries.gmk Tue Sep 22 11:01:54 2015 -0700 @@ -239,8 +239,13 @@ ########################################################################################## +ifeq ($(OPENJDK_TARGET_OS), aix) + LIBJIMAGE_TOOLCHAIN := TOOLCHAIN_LINK_CXX +endif # OPENJDK_TARGET_OS aix + $(eval $(call SetupNativeCompilation,BUILD_LIBJIMAGE, \ LIBRARY := jimage, \ + TOOLCHAIN := $(LIBJIMAGE_TOOLCHAIN), \ OUTPUT_DIR := $(INSTALL_LIBRARIES_HERE), \ OPTIMIZATION := LOW, \ SRC := $(JDK_TOPDIR)/src/java.base/share/native/libjimage \
--- a/make/mapfiles/libjava/mapfile-vers Thu Sep 17 09:19:40 2015 -0700 +++ b/make/mapfiles/libjava/mapfile-vers Tue Sep 22 11:01:54 2015 -0700 @@ -150,7 +150,6 @@ Java_java_lang_StrictMath_exp; Java_java_lang_StrictMath_log; Java_java_lang_StrictMath_log10; - Java_java_lang_StrictMath_pow; Java_java_lang_StrictMath_sin; Java_java_lang_StrictMath_sqrt; Java_java_lang_StrictMath_cbrt;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.base/share/classes/java/lang/FdLibm.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,383 @@ +/* + * Copyright (c) 1998, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package java.lang; + +/** + * Port of the "Freely Distributable Math Library", version 5.3, from C to Java. + * + * <p>The C version of fdlibm relied on the idiom of pointer aliasing + * a 64-bit double floating-point value as a two-element array of + * 32-bit integers and reading and writing the two halves of the + * double independently. This coding pattern was problematic to C + * optimizers and not directly expressible in Java. Therefore, rather + * than a memory level overlay, if portions of a double need to be + * operated on as integer values, the standard library methods for + * bitwise floating-point to integer conversion, + * Double.longBitsToDouble and Double.doubleToRawLongBits, are directly + * or indirectly used . + * + * <p>The C version of fdlibm also took some pains to signal the + * correct IEEE 754 exceptional conditions divide by zero, invalid, + * overflow and underflow. For example, overflow would be signaled by + * {@code huge * huge} where {@code huge} was a large constant that + * would overflow when squared. Since IEEE floating-point exceptional + * handling is not supported natively in the JVM, such coding patterns + * have been omitted from this port. For example, rather than {@code + * return huge * huge}, this port will use {@code return INFINITY}. + */ +class FdLibm { + // Constants used by multiple algorithms + private static final double INFINITY = Double.POSITIVE_INFINITY; + + private FdLibm() { + throw new UnsupportedOperationException("No instances for you."); + } + + /** + * Return the low-order 32 bits of the double argument as an int. + */ + private static int __LO(double x) { + long transducer = Double.doubleToRawLongBits(x); + return (int)transducer; + } + + /** + * Return a double with its low-order bits of the second argument + * and the high-order bits of the first argument.. + */ + private static double __LO(double x, int low) { + long transX = Double.doubleToRawLongBits(x); + return Double.longBitsToDouble((transX & 0xFFFF_FFFF_0000_0000L)|low ); + } + + /** + * Return the high-order 32 bits of the double argument as an int. + */ + private static int __HI(double x) { + long transducer = Double.doubleToRawLongBits(x); + return (int)(transducer >> 32); + } + + /** + * Return a double with its high-order bits of the second argument + * and the low-order bits of the first argument.. + */ + private static double __HI(double x, int high) { + long transX = Double.doubleToRawLongBits(x); + return Double.longBitsToDouble((transX & 0x0000_0000_FFFF_FFFFL)|( ((long)high)) << 32 ); + } + + /** + * Compute x**y + * n + * Method: Let x = 2 * (1+f) + * 1. Compute and return log2(x) in two pieces: + * log2(x) = w1 + w2, + * where w1 has 53 - 24 = 29 bit trailing zeros. + * 2. Perform y*log2(x) = n+y' by simulating muti-precision + * arithmetic, where |y'| <= 0.5. + * 3. Return x**y = 2**n*exp(y'*log2) + * + * Special cases: + * 1. (anything) ** 0 is 1 + * 2. (anything) ** 1 is itself + * 3. (anything) ** NAN is NAN + * 4. NAN ** (anything except 0) is NAN + * 5. +-(|x| > 1) ** +INF is +INF + * 6. +-(|x| > 1) ** -INF is +0 + * 7. +-(|x| < 1) ** +INF is +0 + * 8. +-(|x| < 1) ** -INF is +INF + * 9. +-1 ** +-INF is NAN + * 10. +0 ** (+anything except 0, NAN) is +0 + * 11. -0 ** (+anything except 0, NAN, odd integer) is +0 + * 12. +0 ** (-anything except 0, NAN) is +INF + * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF + * 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) + * 15. +INF ** (+anything except 0,NAN) is +INF + * 16. +INF ** (-anything except 0,NAN) is +0 + * 17. -INF ** (anything) = -0 ** (-anything) + * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) + * 19. (-anything except 0 and inf) ** (non-integer) is NAN + * + * Accuracy: + * pow(x,y) returns x**y nearly rounded. In particular + * pow(integer,integer) + * always returns the correct integer provided it is + * representable. + */ + public static class Pow { + public static strictfp double compute(final double x, final double y) { + double z; + double r, s, t, u, v, w; + int i, j, k, n; + + // y == zero: x**0 = 1 + if (y == 0.0) + return 1.0; + + // +/-NaN return x + y to propagate NaN significands + if (Double.isNaN(x) || Double.isNaN(y)) + return x + y; + + final double y_abs = Math.abs(y); + double x_abs = Math.abs(x); + // Special values of y + if (y == 2.0) { + return x * x; + } else if (y == 0.5) { + if (x >= -Double.MAX_VALUE) // Handle x == -infinity later + return Math.sqrt(x + 0.0); // Add 0.0 to properly handle x == -0.0 + } else if (y_abs == 1.0) { // y is +/-1 + return (y == 1.0) ? x : 1.0 / x; + } else if (y_abs == INFINITY) { // y is +/-infinity + if (x_abs == 1.0) + return y - y; // inf**+/-1 is NaN + else if (x_abs > 1.0) // (|x| > 1)**+/-inf = inf, 0 + return (y >= 0) ? y : 0.0; + else // (|x| < 1)**-/+inf = inf, 0 + return (y < 0) ? -y : 0.0; + } + + final int hx = __HI(x); + int ix = hx & 0x7fffffff; + + /* + * When x < 0, determine if y is an odd integer: + * y_is_int = 0 ... y is not an integer + * y_is_int = 1 ... y is an odd int + * y_is_int = 2 ... y is an even int + */ + int y_is_int = 0; + if (hx < 0) { + if (y_abs >= 0x1.0p53) // |y| >= 2^53 = 9.007199254740992E15 + y_is_int = 2; // y is an even integer since ulp(2^53) = 2.0 + else if (y_abs >= 1.0) { // |y| >= 1.0 + long y_abs_as_long = (long) y_abs; + if ( ((double) y_abs_as_long) == y_abs) { + y_is_int = 2 - (int)(y_abs_as_long & 0x1L); + } + } + } + + // Special value of x + if (x_abs == 0.0 || + x_abs == INFINITY || + x_abs == 1.0) { + z = x_abs; // x is +/-0, +/-inf, +/-1 + if (y < 0.0) + z = 1.0/z; // z = (1/|x|) + if (hx < 0) { + if (((ix - 0x3ff00000) | y_is_int) == 0) { + z = (z-z)/(z-z); // (-1)**non-int is NaN + } else if (y_is_int == 1) + z = -1.0 * z; // (x < 0)**odd = -(|x|**odd) + } + return z; + } + + n = (hx >> 31) + 1; + + // (x < 0)**(non-int) is NaN + if ((n | y_is_int) == 0) + return (x-x)/(x-x); + + s = 1.0; // s (sign of result -ve**odd) = -1 else = 1 + if ( (n | (y_is_int - 1)) == 0) + s = -1.0; // (-ve)**(odd int) + + double p_h, p_l, t1, t2; + // |y| is huge + if (y_abs > 0x1.0p31) { // if |y| > 2**31 + final double INV_LN2 = 0x1.7154_7652_b82fep0; // 1.44269504088896338700e+00 = 1/ln2 + final double INV_LN2_H = 0x1.715476p0; // 1.44269502162933349609e+00 = 24 bits of 1/ln2 + final double INV_LN2_L = 0x1.4ae0_bf85_ddf44p-26; // 1.92596299112661746887e-08 = 1/ln2 tail + + // Over/underflow if x is not close to one + if (x_abs < 0x1.fffffp-1) // |x| < 0.9999995231628418 + return (y < 0.0) ? s * INFINITY : s * 0.0; + if (x_abs > 1.0) // |x| > 1.0 + return (y > 0.0) ? s * INFINITY : s * 0.0; + /* + * now |1-x| is tiny <= 2**-20, sufficient to compute + * log(x) by x - x^2/2 + x^3/3 - x^4/4 + */ + t = x_abs - 1.0; // t has 20 trailing zeros + w = (t * t) * (0.5 - t * (0.3333333333333333333333 - t * 0.25)); + u = INV_LN2_H * t; // INV_LN2_H has 21 sig. bits + v = t * INV_LN2_L - w * INV_LN2; + t1 = u + v; + t1 =__LO(t1, 0); + t2 = v - (t1 - u); + } else { + final double CP = 0x1.ec70_9dc3_a03fdp-1; // 9.61796693925975554329e-01 = 2/(3ln2) + final double CP_H = 0x1.ec709ep-1; // 9.61796700954437255859e-01 = (float)cp + final double CP_L = -0x1.e2fe_0145_b01f5p-28; // -7.02846165095275826516e-09 = tail of CP_H + + double z_h, z_l, ss, s2, s_h, s_l, t_h, t_l; + n = 0; + // Take care of subnormal numbers + if (ix < 0x00100000) { + x_abs *= 0x1.0p53; // 2^53 = 9007199254740992.0 + n -= 53; + ix = __HI(x_abs); + } + n += ((ix) >> 20) - 0x3ff; + j = ix & 0x000fffff; + // Determine interval + ix = j | 0x3ff00000; // Normalize ix + if (j <= 0x3988E) + k = 0; // |x| <sqrt(3/2) + else if (j < 0xBB67A) + k = 1; // |x| <sqrt(3) + else { + k = 0; + n += 1; + ix -= 0x00100000; + } + x_abs = __HI(x_abs, ix); + + // Compute ss = s_h + s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) + + final double BP[] = {1.0, + 1.5}; + final double DP_H[] = {0.0, + 0x1.2b80_34p-1}; // 5.84962487220764160156e-01 + final double DP_L[] = {0.0, + 0x1.cfde_b43c_fd006p-27};// 1.35003920212974897128e-08 + + // Poly coefs for (3/2)*(log(x)-2s-2/3*s**3 + final double L1 = 0x1.3333_3333_33303p-1; // 5.99999999999994648725e-01 + final double L2 = 0x1.b6db_6db6_fabffp-2; // 4.28571428578550184252e-01 + final double L3 = 0x1.5555_5518_f264dp-2; // 3.33333329818377432918e-01 + final double L4 = 0x1.1746_0a91_d4101p-2; // 2.72728123808534006489e-01 + final double L5 = 0x1.d864_a93c_9db65p-3; // 2.30660745775561754067e-01 + final double L6 = 0x1.a7e2_84a4_54eefp-3; // 2.06975017800338417784e-01 + u = x_abs - BP[k]; // BP[0]=1.0, BP[1]=1.5 + v = 1.0 / (x_abs + BP[k]); + ss = u * v; + s_h = ss; + s_h = __LO(s_h, 0); + // t_h=x_abs + BP[k] High + t_h = 0.0; + t_h = __HI(t_h, ((ix >> 1) | 0x20000000) + 0x00080000 + (k << 18) ); + t_l = x_abs - (t_h - BP[k]); + s_l = v * ((u - s_h * t_h) - s_h * t_l); + // Compute log(x_abs) + s2 = ss * ss; + r = s2 * s2* (L1 + s2 * (L2 + s2 * (L3 + s2 * (L4 + s2 * (L5 + s2 * L6))))); + r += s_l * (s_h + ss); + s2 = s_h * s_h; + t_h = 3.0 + s2 + r; + t_h = __LO(t_h, 0); + t_l = r - ((t_h - 3.0) - s2); + // u+v = ss*(1+...) + u = s_h * t_h; + v = s_l * t_h + t_l * ss; + // 2/(3log2)*(ss + ...) + p_h = u + v; + p_h = __LO(p_h, 0); + p_l = v - (p_h - u); + z_h = CP_H * p_h; // CP_H + CP_L = 2/(3*log2) + z_l = CP_L * p_h + p_l * CP + DP_L[k]; + // log2(x_abs) = (ss + ..)*2/(3*log2) = n + DP_H + z_h + z_l + t = (double)n; + t1 = (((z_h + z_l) + DP_H[k]) + t); + t1 = __LO(t1, 0); + t2 = z_l - (((t1 - t) - DP_H[k]) - z_h); + } + + // Split up y into (y1 + y2) and compute (y1 + y2) * (t1 + t2) + double y1 = y; + y1 = __LO(y1, 0); + p_l = (y - y1) * t1 + y * t2; + p_h = y1 * t1; + z = p_l + p_h; + j = __HI(z); + i = __LO(z); + if (j >= 0x40900000) { // z >= 1024 + if (((j - 0x40900000) | i)!=0) // if z > 1024 + return s * INFINITY; // Overflow + else { + final double OVT = 8.0085662595372944372e-0017; // -(1024-log2(ovfl+.5ulp)) + if (p_l + OVT > z - p_h) + return s * INFINITY; // Overflow + } + } else if ((j & 0x7fffffff) >= 0x4090cc00 ) { // z <= -1075 + if (((j - 0xc090cc00) | i)!=0) // z < -1075 + return s * 0.0; // Underflow + else { + if (p_l <= z - p_h) + return s * 0.0; // Underflow + } + } + /* + * Compute 2**(p_h+p_l) + */ + // Poly coefs for (3/2)*(log(x)-2s-2/3*s**3 + final double P1 = 0x1.5555_5555_5553ep-3; // 1.66666666666666019037e-01 + final double P2 = -0x1.6c16_c16b_ebd93p-9; // -2.77777777770155933842e-03 + final double P3 = 0x1.1566_aaf2_5de2cp-14; // 6.61375632143793436117e-05 + final double P4 = -0x1.bbd4_1c5d_26bf1p-20; // -1.65339022054652515390e-06 + final double P5 = 0x1.6376_972b_ea4d0p-25; // 4.13813679705723846039e-08 + final double LG2 = 0x1.62e4_2fef_a39efp-1; // 6.93147180559945286227e-01 + final double LG2_H = 0x1.62e43p-1; // 6.93147182464599609375e-01 + final double LG2_L = -0x1.05c6_10ca_86c39p-29; // -1.90465429995776804525e-09 + i = j & 0x7fffffff; + k = (i >> 20) - 0x3ff; + n = 0; + if (i > 0x3fe00000) { // if |z| > 0.5, set n = [z + 0.5] + n = j + (0x00100000 >> (k + 1)); + k = ((n & 0x7fffffff) >> 20) - 0x3ff; // new k for n + t = 0.0; + t = __HI(t, (n & ~(0x000fffff >> k)) ); + n = ((n & 0x000fffff) | 0x00100000) >> (20 - k); + if (j < 0) + n = -n; + p_h -= t; + } + t = p_l + p_h; + t = __LO(t, 0); + u = t * LG2_H; + v = (p_l - (t - p_h)) * LG2 + t * LG2_L; + z = u + v; + w = v - (z - u); + t = z * z; + t1 = z - t * (P1 + t * (P2 + t * (P3 + t * (P4 + t * P5)))); + r = (z * t1)/(t1 - 2.0) - (w + z * w); + z = 1.0 - (r - z); + j = __HI(z); + j += (n << 20); + if ((j >> 20) <= 0) + z = Math.scalb(z, n); // subnormal output + else { + int z_hi = __HI(z); + z_hi += (n << 20); + z = __HI(z, z_hi); + } + return s * z; + } + } +}
--- a/src/java.base/share/classes/java/lang/StrictMath.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/classes/java/lang/StrictMath.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -643,7 +643,9 @@ * @param b the exponent. * @return the value {@code a}<sup>{@code b}</sup>. */ - public static native double pow(double a, double b); + public static double pow(double a, double b) { + return FdLibm.Pow.compute(a, b); + } /** * Returns the closest {@code int} to the argument, with ties
--- a/src/java.base/share/classes/java/util/stream/Collectors.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/classes/java/util/stream/Collectors.java Tue Sep 22 11:01:54 2015 -0700 @@ -504,7 +504,7 @@ */ public static <T> Collector<T, ?, Long> counting() { - return reducing(0L, e -> 1L, Long::sum); + return summingLong(e -> 1L); } /**
--- a/src/java.base/share/classes/sun/security/util/KeyStoreDelegator.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/classes/sun/security/util/KeyStoreDelegator.java Tue Sep 22 11:01:54 2015 -0700 @@ -210,62 +210,60 @@ } else { // First try the primary keystore then try the secondary keystore - try (InputStream bufferedStream = new BufferedInputStream(stream)) { - bufferedStream.mark(Integer.MAX_VALUE); + InputStream bufferedStream = new BufferedInputStream(stream); + bufferedStream.mark(Integer.MAX_VALUE); + + try { + keystore = primaryKeyStore.newInstance(); + type = primaryType; + keystore.engineLoad(bufferedStream, password); + + } catch (Exception e) { + + // incorrect password + if (e instanceof IOException && + e.getCause() instanceof UnrecoverableKeyException) { + throw (IOException)e; + } try { - keystore = primaryKeyStore.newInstance(); - type = primaryType; + // Ignore secondary keystore when no compatibility mode + if (!compatModeEnabled) { + throw e; + } + + keystore = secondaryKeyStore.newInstance(); + type = secondaryType; + bufferedStream.reset(); keystore.engineLoad(bufferedStream, password); - } catch (Exception e) { + if (debug != null) { + debug.println("WARNING: switching from " + + primaryType + " to " + secondaryType + + " keystore file format has altered the " + + "keystore security level"); + } + + } catch (InstantiationException | + IllegalAccessException e2) { + // can safely ignore + + } catch (IOException | + NoSuchAlgorithmException | + CertificateException e3) { // incorrect password - if (e instanceof IOException && - e.getCause() instanceof UnrecoverableKeyException) { + if (e3 instanceof IOException && + e3.getCause() instanceof UnrecoverableKeyException) { + throw (IOException)e3; + } + // rethrow the outer exception + if (e instanceof IOException) { throw (IOException)e; - } - - try { - // Ignore secondary keystore when no compatibility mode - if (!compatModeEnabled) { - throw e; - } - - keystore = secondaryKeyStore.newInstance(); - type = secondaryType; - bufferedStream.reset(); - keystore.engineLoad(bufferedStream, password); - - if (debug != null) { - debug.println("WARNING: switching from " + - primaryType + " to " + secondaryType + - " keystore file format has altered the " + - "keystore security level"); - } - - } catch (InstantiationException | - IllegalAccessException e2) { - // can safely ignore - - } catch (IOException | - NoSuchAlgorithmException | - CertificateException e3) { - - // incorrect password - if (e3 instanceof IOException && - e3.getCause() instanceof - UnrecoverableKeyException) { - throw (IOException)e3; - } - // rethrow the outer exception - if (e instanceof IOException) { - throw (IOException)e; - } else if (e instanceof CertificateException) { - throw (CertificateException)e; - } else if (e instanceof NoSuchAlgorithmException) { - throw (NoSuchAlgorithmException)e; - } + } else if (e instanceof CertificateException) { + throw (CertificateException)e; + } else if (e instanceof NoSuchAlgorithmException) { + throw (NoSuchAlgorithmException)e; } } }
--- a/src/java.base/share/native/libfdlibm/e_pow.c Thu Sep 17 09:19:40 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,320 +0,0 @@ - -/* - * Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* __ieee754_pow(x,y) return x**y - * - * n - * Method: Let x = 2 * (1+f) - * 1. Compute and return log2(x) in two pieces: - * log2(x) = w1 + w2, - * where w1 has 53-24 = 29 bit trailing zeros. - * 2. Perform y*log2(x) = n+y' by simulating muti-precision - * arithmetic, where |y'|<=0.5. - * 3. Return x**y = 2**n*exp(y'*log2) - * - * Special cases: - * 1. (anything) ** 0 is 1 - * 2. (anything) ** 1 is itself - * 3. (anything) ** NAN is NAN - * 4. NAN ** (anything except 0) is NAN - * 5. +-(|x| > 1) ** +INF is +INF - * 6. +-(|x| > 1) ** -INF is +0 - * 7. +-(|x| < 1) ** +INF is +0 - * 8. +-(|x| < 1) ** -INF is +INF - * 9. +-1 ** +-INF is NAN - * 10. +0 ** (+anything except 0, NAN) is +0 - * 11. -0 ** (+anything except 0, NAN, odd integer) is +0 - * 12. +0 ** (-anything except 0, NAN) is +INF - * 13. -0 ** (-anything except 0, NAN, odd integer) is +INF - * 14. -0 ** (odd integer) = -( +0 ** (odd integer) ) - * 15. +INF ** (+anything except 0,NAN) is +INF - * 16. +INF ** (-anything except 0,NAN) is +0 - * 17. -INF ** (anything) = -0 ** (-anything) - * 18. (-anything) ** (integer) is (-1)**(integer)*(+anything**integer) - * 19. (-anything except 0 and inf) ** (non-integer) is NAN - * - * Accuracy: - * pow(x,y) returns x**y nearly rounded. In particular - * pow(integer,integer) - * always returns the correct integer provided it is - * representable. - * - * Constants : - * The hexadecimal values are the intended ones for the following - * constants. The decimal values may be used, provided that the - * compiler will convert from decimal to binary accurately enough - * to produce the hexadecimal values shown. - */ - -#include "fdlibm.h" - -#ifdef __STDC__ -static const double -#else -static double -#endif -bp[] = {1.0, 1.5,}, -dp_h[] = { 0.0, 5.84962487220764160156e-01,}, /* 0x3FE2B803, 0x40000000 */ -dp_l[] = { 0.0, 1.35003920212974897128e-08,}, /* 0x3E4CFDEB, 0x43CFD006 */ -zero = 0.0, -one = 1.0, -two = 2.0, -two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */ -huge = 1.0e300, -tiny = 1.0e-300, - /* poly coefs for (3/2)*(log(x)-2s-2/3*s**3 */ -L1 = 5.99999999999994648725e-01, /* 0x3FE33333, 0x33333303 */ -L2 = 4.28571428578550184252e-01, /* 0x3FDB6DB6, 0xDB6FABFF */ -L3 = 3.33333329818377432918e-01, /* 0x3FD55555, 0x518F264D */ -L4 = 2.72728123808534006489e-01, /* 0x3FD17460, 0xA91D4101 */ -L5 = 2.30660745775561754067e-01, /* 0x3FCD864A, 0x93C9DB65 */ -L6 = 2.06975017800338417784e-01, /* 0x3FCA7E28, 0x4A454EEF */ -P1 = 1.66666666666666019037e-01, /* 0x3FC55555, 0x5555553E */ -P2 = -2.77777777770155933842e-03, /* 0xBF66C16C, 0x16BEBD93 */ -P3 = 6.61375632143793436117e-05, /* 0x3F11566A, 0xAF25DE2C */ -P4 = -1.65339022054652515390e-06, /* 0xBEBBBD41, 0xC5D26BF1 */ -P5 = 4.13813679705723846039e-08, /* 0x3E663769, 0x72BEA4D0 */ -lg2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ -lg2_h = 6.93147182464599609375e-01, /* 0x3FE62E43, 0x00000000 */ -lg2_l = -1.90465429995776804525e-09, /* 0xBE205C61, 0x0CA86C39 */ -ovt = 8.0085662595372944372e-0017, /* -(1024-log2(ovfl+.5ulp)) */ -cp = 9.61796693925975554329e-01, /* 0x3FEEC709, 0xDC3A03FD =2/(3ln2) */ -cp_h = 9.61796700954437255859e-01, /* 0x3FEEC709, 0xE0000000 =(float)cp */ -cp_l = -7.02846165095275826516e-09, /* 0xBE3E2FE0, 0x145B01F5 =tail of cp_h*/ -ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */ -ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/ -ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/ - -#ifdef __STDC__ - double __ieee754_pow(double x, double y) -#else - double __ieee754_pow(x,y) - double x, y; -#endif -{ - double z,ax,z_h,z_l,p_h,p_l; - double y1,t1,t2,r,s,t,u,v,w; - int i0,i1,i,j,k,yisint,n; - int hx,hy,ix,iy; - unsigned lx,ly; - - i0 = ((*(int*)&one)>>29)^1; i1=1-i0; - hx = __HI(x); lx = __LO(x); - hy = __HI(y); ly = __LO(y); - ix = hx&0x7fffffff; iy = hy&0x7fffffff; - - /* y==zero: x**0 = 1 */ - if((iy|ly)==0) return one; - - /* +-NaN return x+y */ - if(ix > 0x7ff00000 || ((ix==0x7ff00000)&&(lx!=0)) || - iy > 0x7ff00000 || ((iy==0x7ff00000)&&(ly!=0))) - return x+y; - - /* determine if y is an odd int when x < 0 - * yisint = 0 ... y is not an integer - * yisint = 1 ... y is an odd int - * yisint = 2 ... y is an even int - */ - yisint = 0; - if(hx<0) { - if(iy>=0x43400000) yisint = 2; /* even integer y */ - else if(iy>=0x3ff00000) { - k = (iy>>20)-0x3ff; /* exponent */ - if(k>20) { - j = ly>>(52-k); - if((j<<(52-k))==ly) yisint = 2-(j&1); - } else if(ly==0) { - j = iy>>(20-k); - if((j<<(20-k))==iy) yisint = 2-(j&1); - } - } - } - - /* special value of y */ - if(ly==0) { - if (iy==0x7ff00000) { /* y is +-inf */ - if(((ix-0x3ff00000)|lx)==0) - return y - y; /* inf**+-1 is NaN */ - else if (ix >= 0x3ff00000)/* (|x|>1)**+-inf = inf,0 */ - return (hy>=0)? y: zero; - else /* (|x|<1)**-,+inf = inf,0 */ - return (hy<0)?-y: zero; - } - if(iy==0x3ff00000) { /* y is +-1 */ - if(hy<0) return one/x; else return x; - } - if(hy==0x40000000) return x*x; /* y is 2 */ - if(hy==0x3fe00000) { /* y is 0.5 */ - if(hx>=0) /* x >= +0 */ - return sqrt(x); - } - } - - ax = fabs(x); - /* special value of x */ - if(lx==0) { - if(ix==0x7ff00000||ix==0||ix==0x3ff00000){ - z = ax; /*x is +-0,+-inf,+-1*/ - if(hy<0) z = one/z; /* z = (1/|x|) */ - if(hx<0) { - if(((ix-0x3ff00000)|yisint)==0) { - z = (z-z)/(z-z); /* (-1)**non-int is NaN */ - } else if(yisint==1) - z = -1.0*z; /* (x<0)**odd = -(|x|**odd) */ - } - return z; - } - } - - n = (hx>>31)+1; - - /* (x<0)**(non-int) is NaN */ - if((n|yisint)==0) return (x-x)/(x-x); - - s = one; /* s (sign of result -ve**odd) = -1 else = 1 */ - if((n|(yisint-1))==0) s = -one;/* (-ve)**(odd int) */ - - /* |y| is huge */ - if(iy>0x41e00000) { /* if |y| > 2**31 */ - if(iy>0x43f00000){ /* if |y| > 2**64, must o/uflow */ - if(ix<=0x3fefffff) return (hy<0)? huge*huge:tiny*tiny; - if(ix>=0x3ff00000) return (hy>0)? huge*huge:tiny*tiny; - } - /* over/underflow if x is not close to one */ - if(ix<0x3fefffff) return (hy<0)? s*huge*huge:s*tiny*tiny; - if(ix>0x3ff00000) return (hy>0)? s*huge*huge:s*tiny*tiny; - /* now |1-x| is tiny <= 2**-20, suffice to compute - log(x) by x-x^2/2+x^3/3-x^4/4 */ - t = ax-one; /* t has 20 trailing zeros */ - w = (t*t)*(0.5-t*(0.3333333333333333333333-t*0.25)); - u = ivln2_h*t; /* ivln2_h has 21 sig. bits */ - v = t*ivln2_l-w*ivln2; - t1 = u+v; - __LO(t1) = 0; - t2 = v-(t1-u); - } else { - double ss,s2,s_h,s_l,t_h,t_l; - n = 0; - /* take care subnormal number */ - if(ix<0x00100000) - {ax *= two53; n -= 53; ix = __HI(ax); } - n += ((ix)>>20)-0x3ff; - j = ix&0x000fffff; - /* determine interval */ - ix = j|0x3ff00000; /* normalize ix */ - if(j<=0x3988E) k=0; /* |x|<sqrt(3/2) */ - else if(j<0xBB67A) k=1; /* |x|<sqrt(3) */ - else {k=0;n+=1;ix -= 0x00100000;} - __HI(ax) = ix; - - /* compute ss = s_h+s_l = (x-1)/(x+1) or (x-1.5)/(x+1.5) */ - u = ax-bp[k]; /* bp[0]=1.0, bp[1]=1.5 */ - v = one/(ax+bp[k]); - ss = u*v; - s_h = ss; - __LO(s_h) = 0; - /* t_h=ax+bp[k] High */ - t_h = zero; - __HI(t_h)=((ix>>1)|0x20000000)+0x00080000+(k<<18); - t_l = ax - (t_h-bp[k]); - s_l = v*((u-s_h*t_h)-s_h*t_l); - /* compute log(ax) */ - s2 = ss*ss; - r = s2*s2*(L1+s2*(L2+s2*(L3+s2*(L4+s2*(L5+s2*L6))))); - r += s_l*(s_h+ss); - s2 = s_h*s_h; - t_h = 3.0+s2+r; - __LO(t_h) = 0; - t_l = r-((t_h-3.0)-s2); - /* u+v = ss*(1+...) */ - u = s_h*t_h; - v = s_l*t_h+t_l*ss; - /* 2/(3log2)*(ss+...) */ - p_h = u+v; - __LO(p_h) = 0; - p_l = v-(p_h-u); - z_h = cp_h*p_h; /* cp_h+cp_l = 2/(3*log2) */ - z_l = cp_l*p_h+p_l*cp+dp_l[k]; - /* log2(ax) = (ss+..)*2/(3*log2) = n + dp_h + z_h + z_l */ - t = (double)n; - t1 = (((z_h+z_l)+dp_h[k])+t); - __LO(t1) = 0; - t2 = z_l-(((t1-t)-dp_h[k])-z_h); - } - - /* split up y into y1+y2 and compute (y1+y2)*(t1+t2) */ - y1 = y; - __LO(y1) = 0; - p_l = (y-y1)*t1+y*t2; - p_h = y1*t1; - z = p_l+p_h; - j = __HI(z); - i = __LO(z); - if (j>=0x40900000) { /* z >= 1024 */ - if(((j-0x40900000)|i)!=0) /* if z > 1024 */ - return s*huge*huge; /* overflow */ - else { - if(p_l+ovt>z-p_h) return s*huge*huge; /* overflow */ - } - } else if((j&0x7fffffff)>=0x4090cc00 ) { /* z <= -1075 */ - if(((j-0xc090cc00)|i)!=0) /* z < -1075 */ - return s*tiny*tiny; /* underflow */ - else { - if(p_l<=z-p_h) return s*tiny*tiny; /* underflow */ - } - } - /* - * compute 2**(p_h+p_l) - */ - i = j&0x7fffffff; - k = (i>>20)-0x3ff; - n = 0; - if(i>0x3fe00000) { /* if |z| > 0.5, set n = [z+0.5] */ - n = j+(0x00100000>>(k+1)); - k = ((n&0x7fffffff)>>20)-0x3ff; /* new k for n */ - t = zero; - __HI(t) = (n&~(0x000fffff>>k)); - n = ((n&0x000fffff)|0x00100000)>>(20-k); - if(j<0) n = -n; - p_h -= t; - } - t = p_l+p_h; - __LO(t) = 0; - u = t*lg2_h; - v = (p_l-(t-p_h))*lg2+t*lg2_l; - z = u+v; - w = v-(z-u); - t = z*z; - t1 = z - t*(P1+t*(P2+t*(P3+t*(P4+t*P5)))); - r = (z*t1)/(t1-two)-(w+z*w); - z = one-(r-z); - j = __HI(z); - j += (n<<20); - if((j>>20)<=0) z = scalbn(z,n); /* subnormal output */ - else __HI(z) += (n<<20); - return s*z; -}
--- a/src/java.base/share/native/libfdlibm/fdlibm.h Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libfdlibm/fdlibm.h Tue Sep 22 11:01:54 2015 -0700 @@ -133,7 +133,6 @@ extern double log10 __P((double)); extern double modf __P((double, double *)); -extern double pow __P((double, double)); extern double sqrt __P((double)); extern double ceil __P((double)); @@ -187,7 +186,6 @@ extern double __ieee754_exp __P((double)); extern double __ieee754_cosh __P((double)); extern double __ieee754_fmod __P((double,double)); -extern double __ieee754_pow __P((double,double)); extern double __ieee754_log10 __P((double)); extern double __ieee754_sinh __P((double)); extern double __ieee754_hypot __P((double,double));
--- a/src/java.base/share/native/libfdlibm/w_pow.c Thu Sep 17 09:19:40 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ - - -/* - * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ - -/* - * wrapper pow(x,y) return x**y - */ - -#include "fdlibm.h" - - -#ifdef __STDC__ - double pow(double x, double y) /* wrapper pow */ -#else - double pow(x,y) /* wrapper pow */ - double x,y; -#endif -{ -#ifdef _IEEE_LIBM - return __ieee754_pow(x,y); -#else - double z; - z=__ieee754_pow(x,y); - if(_LIB_VERSION == _IEEE_|| isnan(y)) return z; - if(isnan(x)) { - if(y==0.0) - return __kernel_standard(x,y,42); /* pow(NaN,0.0) */ - else - return z; - } - if(x==0.0){ - if(y==0.0) - return __kernel_standard(x,y,20); /* pow(0.0,0.0) */ - if(finite(y)&&y<0.0) - return __kernel_standard(x,y,23); /* pow(0.0,negative) */ - return z; - } - if(!finite(z)) { - if(finite(x)&&finite(y)) { - if(isnan(z)) - return __kernel_standard(x,y,24); /* pow neg**non-int */ - else - return __kernel_standard(x,y,21); /* pow overflow */ - } - } - if(z==0.0&&finite(x)&&finite(y)) - return __kernel_standard(x,y,22); /* pow underflow */ - return z; -#endif -}
--- a/src/java.base/share/native/libjava/StrictMath.c Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjava/StrictMath.c Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -101,12 +101,6 @@ } JNIEXPORT jdouble JNICALL -Java_java_lang_StrictMath_pow(JNIEnv *env, jclass unused, jdouble d1, jdouble d2) -{ - return (jdouble) jpow((double)d1, (double)d2); -} - -JNIEXPORT jdouble JNICALL Java_java_lang_StrictMath_IEEEremainder(JNIEnv *env, jclass unused, jdouble dividend, jdouble divisor)
--- a/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/ImageNativeSubstrate.cpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,7 +4,9 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #include <string.h>
--- a/src/java.base/share/native/libjimage/endian.cpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/endian.cpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,11 +4,13 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #include "endian.hpp" @@ -27,20 +28,20 @@ // Most modern compilers optimize the bswap routines to native instructions. inline static u2 bswap_16(u2 x) { - return ((x & 0xFF) << 8) | - ((x >> 8) & 0xFF); + return ((x & 0xFF) << 8) | + ((x >> 8) & 0xFF); } inline static u4 bswap_32(u4 x) { - return ((x & 0xFF) << 24) | - ((x & 0xFF00) << 8) | - ((x >> 8) & 0xFF00) | - ((x >> 24) & 0xFF); + return ((x & 0xFF) << 24) | + ((x & 0xFF00) << 8) | + ((x >> 8) & 0xFF00) | + ((x >> 24) & 0xFF); } inline static u8 bswap_64(u8 x) { - return (u8)bswap_32((u4)x) << 32 | - (u8)bswap_32((u4)(x >> 32)); + return (u8)bswap_32((u4)x) << 32 | + (u8)bswap_32((u4)(x >> 32)); } u2 NativeEndian::get(u2 x) { return x; } @@ -76,27 +77,27 @@ SwappingEndian SwappingEndian::_swapping; Endian* Endian::get_handler(bool big_endian) { - // If requesting little endian on a little endian machine or - // big endian on a big endian machine use native handler - if (big_endian == is_big_endian()) { - return NativeEndian::get_native(); - } else { - // Use swapping handler. - return SwappingEndian::get_swapping(); - } + // If requesting little endian on a little endian machine or + // big endian on a big endian machine use native handler + if (big_endian == is_big_endian()) { + return NativeEndian::get_native(); + } else { + // Use swapping handler. + return SwappingEndian::get_swapping(); + } } // Return a platform u2 from an array in which Big Endian is applied. u2 Endian::get_java(u1* x) { - return (u2) (x[0]<<8 | x[1]); + return (u2) (x[0]<<8 | x[1]); } // Add a platform u2 to the array as a Big Endian u2 void Endian::set_java(u1* p, u2 x) { - p[0] = (x >> 8) & 0xff; - p[1] = x & 0xff; + p[0] = (x >> 8) & 0xff; + p[1] = x & 0xff; } Endian* Endian::get_native_handler() { - return NativeEndian::get_native(); + return NativeEndian::get_native(); }
--- a/src/java.base/share/native/libjimage/endian.hpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/endian.hpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,11 +4,13 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #ifndef LIBJIMAGE_ENDIAN_HPP @@ -36,89 +37,89 @@ // To retrieve a value using the approprate endian, use one of the overloaded // calls to get. To set a value, then use one of the overloaded set calls. // Ex. -// s4 value; // Imported value; -// ... -// Endian* endian = Endian::get_handler(true); // Use big endian -// s4 corrected = endian->get(value); -// endian->set(value, 1); +// s4 value; // Imported value; +// ... +// Endian* endian = Endian::get_handler(true); // Use big endian +// s4 corrected = endian->get(value); +// endian->set(value, 1); // class Endian { public: - virtual u2 get(u2 x) = 0; - virtual u4 get(u4 x) = 0; - virtual u8 get(u8 x) = 0; - virtual s2 get(s2 x) = 0; - virtual s4 get(s4 x) = 0; - virtual s8 get(s8 x) = 0; + virtual u2 get(u2 x) = 0; + virtual u4 get(u4 x) = 0; + virtual u8 get(u8 x) = 0; + virtual s2 get(s2 x) = 0; + virtual s4 get(s4 x) = 0; + virtual s8 get(s8 x) = 0; - virtual void set(u2& x, u2 y) = 0; - virtual void set(u4& x, u4 y) = 0; - virtual void set(u8& x, u8 y) = 0; - virtual void set(s2& x, s2 y) = 0; - virtual void set(s4& x, s4 y) = 0; - virtual void set(s8& x, s8 y) = 0; + virtual void set(u2& x, u2 y) = 0; + virtual void set(u4& x, u4 y) = 0; + virtual void set(u8& x, u8 y) = 0; + virtual void set(s2& x, s2 y) = 0; + virtual void set(s4& x, s4 y) = 0; + virtual void set(s8& x, s8 y) = 0; - // Quick little endian test. - static bool is_little_endian() { u4 x = 1; return *(u1 *)&x != 0; } + // Quick little endian test. + static bool is_little_endian() { u4 x = 1; return *(u1 *)&x != 0; } - // Quick big endian test. - static bool is_big_endian() { return !is_little_endian(); } + // Quick big endian test. + static bool is_big_endian() { return !is_little_endian(); } - // Select an appropriate endian handler. - static Endian* get_handler(bool big_endian); + // Select an appropriate endian handler. + static Endian* get_handler(bool big_endian); - // Return the native endian handler. - static Endian* get_native_handler(); + // Return the native endian handler. + static Endian* get_native_handler(); - // get platform u2 from Java Big endian - static u2 get_java(u1* x); - // set platform u2 to Java Big endian - static void set_java(u1* p, u2 x); + // get platform u2 from Java Big endian + static u2 get_java(u1* x); + // set platform u2 to Java Big endian + static void set_java(u1* p, u2 x); }; // Normal endian handling. class NativeEndian : public Endian { private: - static NativeEndian _native; + static NativeEndian _native; public: - u2 get(u2 x); - u4 get(u4 x); - u8 get(u8 x); - s2 get(s2 x); - s4 get(s4 x); - s8 get(s8 x); + u2 get(u2 x); + u4 get(u4 x); + u8 get(u8 x); + s2 get(s2 x); + s4 get(s4 x); + s8 get(s8 x); - void set(u2& x, u2 y); - void set(u4& x, u4 y); - void set(u8& x, u8 y); - void set(s2& x, s2 y); - void set(s4& x, s4 y); - void set(s8& x, s8 y); + void set(u2& x, u2 y); + void set(u4& x, u4 y); + void set(u8& x, u8 y); + void set(s2& x, s2 y); + void set(s4& x, s4 y); + void set(s8& x, s8 y); - static Endian* get_native() { return &_native; } + static Endian* get_native() { return &_native; } }; // Swapping endian handling. class SwappingEndian : public Endian { private: - static SwappingEndian _swapping; + static SwappingEndian _swapping; public: - u2 get(u2 x); - u4 get(u4 x); - u8 get(u8 x); - s2 get(s2 x); - s4 get(s4 x); - s8 get(s8 x); + u2 get(u2 x); + u4 get(u4 x); + u8 get(u8 x); + s2 get(s2 x); + s4 get(s4 x); + s8 get(s8 x); - void set(u2& x, u2 y); - void set(u4& x, u4 y); - void set(u8& x, u8 y); - void set(s2& x, s2 y); - void set(s4& x, s4 y); - void set(s8& x, s8 y); + void set(u2& x, u2 y); + void set(u4& x, u4 y); + void set(u8& x, u8 y); + void set(s2& x, s2 y); + void set(s4& x, s4 y); + void set(s8& x, s8 y); - static Endian* get_swapping() { return &_swapping; } + static Endian* get_swapping() { return &_swapping; } }; #endif // LIBJIMAGE_ENDIAN_HPP
--- a/src/java.base/share/native/libjimage/imageDecompressor.cpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/imageDecompressor.cpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,11 +4,13 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * @@ -19,10 +21,8 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ - #include "jni.h" #include "imageDecompressor.hpp" #include "endian.hpp" @@ -32,16 +32,17 @@ #include <dlfcn.h> #endif -typedef jboolean (JNICALL *ZipInflateFully_t)(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg); -static ZipInflateFully_t ZipInflateFully = NULL; +typedef jboolean (JNICALL *ZipInflateFully_t)(void *inBuf, jlong inLen, + void *outBuf, jlong outLen, char **pmsg); +static ZipInflateFully_t ZipInflateFully = NULL; #ifndef WIN32 - #define JNI_LIB_PREFIX "lib" - #ifdef __APPLE__ - #define JNI_LIB_SUFFIX ".dylib" - #else - #define JNI_LIB_SUFFIX ".so" - #endif + #define JNI_LIB_PREFIX "lib" + #ifdef __APPLE__ + #define JNI_LIB_SUFFIX ".dylib" + #else + #define JNI_LIB_SUFFIX ".so" + #endif #endif /** @@ -50,21 +51,21 @@ * @return the address of the entry point or NULL */ static void* findEntry(const char* name) { - void *addr = NULL; + void *addr = NULL; #ifdef WIN32 - HMODULE handle = GetModuleHandle("zip.dll"); - if (handle == NULL) { - return NULL; - } - addr = (void*) GetProcAddress(handle, name); - return addr; + HMODULE handle = GetModuleHandle("zip.dll"); + if (handle == NULL) { + return NULL; + } + addr = (void*) GetProcAddress(handle, name); + return addr; #else - addr = dlopen(JNI_LIB_PREFIX "zip" JNI_LIB_SUFFIX, RTLD_GLOBAL|RTLD_LAZY); - if (addr == NULL) { - return NULL; - } - addr = dlsym(addr, name); - return addr; + addr = dlopen(JNI_LIB_PREFIX "zip" JNI_LIB_SUFFIX, RTLD_GLOBAL|RTLD_LAZY); + if (addr == NULL) { + return NULL; + } + addr = dlsym(addr, name); + return addr; #endif } @@ -74,87 +75,87 @@ int ImageDecompressor::_decompressors_num = 0; ImageDecompressor** ImageDecompressor::_decompressors = NULL; void ImageDecompressor::image_decompressor_init() { - if (_decompressors == NULL) { - ZipInflateFully = (ZipInflateFully_t) findEntry("ZIP_InflateFully"); - assert(ZipInflateFully != NULL && "ZIP decompressor not found."); - _decompressors_num = 2; - _decompressors = new ImageDecompressor*[_decompressors_num]; - _decompressors[0] = new ZipDecompressor("zip"); - _decompressors[1] = new SharedStringDecompressor("compact-cp"); - } + if (_decompressors == NULL) { + ZipInflateFully = (ZipInflateFully_t) findEntry("ZIP_InflateFully"); + assert(ZipInflateFully != NULL && "ZIP decompressor not found."); + _decompressors_num = 2; + _decompressors = new ImageDecompressor*[_decompressors_num]; + _decompressors[0] = new ZipDecompressor("zip"); + _decompressors[1] = new SharedStringDecompressor("compact-cp"); + } } void ImageDecompressor::image_decompressor_close() { - delete _decompressors; + delete _decompressors; } /* * Locate decompressor. */ ImageDecompressor* ImageDecompressor::get_decompressor(const char * decompressor_name) { - image_decompressor_init(); - for (int i = 0; i < _decompressors_num; i++) { - ImageDecompressor* decompressor = _decompressors[i]; - assert(decompressor != NULL && "Decompressors not initialized."); - if (strcmp(decompressor->get_name(), decompressor_name) == 0) { - return decompressor; + image_decompressor_init(); + for (int i = 0; i < _decompressors_num; i++) { + ImageDecompressor* decompressor = _decompressors[i]; + assert(decompressor != NULL && "Decompressors not initialized."); + if (strcmp(decompressor->get_name(), decompressor_name) == 0) { + return decompressor; + } } - } - assert(false && "No decompressor found."); - return NULL; + assert(false && "No decompressor found."); + return NULL; } /* * Decompression entry point. Called from ImageFileReader::get_resource. */ void ImageDecompressor::decompress_resource(u1* compressed, u1* uncompressed, - u4 uncompressed_size, const ImageStrings* strings) { - bool has_header = false; - u1* decompressed_resource = compressed; - u1* compressed_resource = compressed; + u4 uncompressed_size, const ImageStrings* strings) { + bool has_header = false; + u1* decompressed_resource = compressed; + u1* compressed_resource = compressed; - // Resource could have been transformed by a stack of decompressors. - // Iterate and decompress resources until there is no more header. - do { - ResourceHeader _header; - memcpy(&_header, compressed_resource, sizeof (ResourceHeader)); - has_header = _header._magic == ResourceHeader::resource_header_magic; - if (has_header) { - // decompressed_resource array contains the result of decompression - decompressed_resource = new u1[_header._uncompressed_size]; - // Retrieve the decompressor name - const char* decompressor_name = strings->get(_header._decompressor_name_offset); - assert(decompressor_name && "image decompressor not found"); - // Retrieve the decompressor instance - ImageDecompressor* decompressor = get_decompressor(decompressor_name); - assert(decompressor && "image decompressor not found"); - u1* compressed_resource_base = compressed_resource; - compressed_resource += ResourceHeader::resource_header_length; - // Ask the decompressor to decompress the compressed content - decompressor->decompress_resource(compressed_resource, decompressed_resource, - &_header, strings); - if (compressed_resource_base != compressed) { - delete compressed_resource_base; - } - compressed_resource = decompressed_resource; - } - } while (has_header); - memcpy(uncompressed, decompressed_resource, uncompressed_size); - delete decompressed_resource; + // Resource could have been transformed by a stack of decompressors. + // Iterate and decompress resources until there is no more header. + do { + ResourceHeader _header; + memcpy(&_header, compressed_resource, sizeof (ResourceHeader)); + has_header = _header._magic == ResourceHeader::resource_header_magic; + if (has_header) { + // decompressed_resource array contains the result of decompression + decompressed_resource = new u1[_header._uncompressed_size]; + // Retrieve the decompressor name + const char* decompressor_name = strings->get(_header._decompressor_name_offset); + assert(decompressor_name && "image decompressor not found"); + // Retrieve the decompressor instance + ImageDecompressor* decompressor = get_decompressor(decompressor_name); + assert(decompressor && "image decompressor not found"); + u1* compressed_resource_base = compressed_resource; + compressed_resource += ResourceHeader::resource_header_length; + // Ask the decompressor to decompress the compressed content + decompressor->decompress_resource(compressed_resource, decompressed_resource, + &_header, strings); + if (compressed_resource_base != compressed) { + delete compressed_resource_base; + } + compressed_resource = decompressed_resource; + } + } while (has_header); + memcpy(uncompressed, decompressed_resource, uncompressed_size); + delete decompressed_resource; } // Zip decompressor void ZipDecompressor::decompress_resource(u1* data, u1* uncompressed, - ResourceHeader* header, const ImageStrings* strings) { - char* msg = NULL; - jboolean res = ZipDecompressor::decompress(data, header->_size, uncompressed, - header->_uncompressed_size, &msg); - assert(res && "decompression failed"); + ResourceHeader* header, const ImageStrings* strings) { + char* msg = NULL; + jboolean res = ZipDecompressor::decompress(data, header->_size, uncompressed, + header->_uncompressed_size, &msg); + assert(res && "decompression failed"); } jboolean ZipDecompressor::decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg) { - return (*ZipInflateFully)(in, inSize, out, outSize, pmsg); + return (*ZipInflateFully)(in, inSize, out, outSize, pmsg); } // END Zip Decompressor @@ -163,141 +164,143 @@ // array index is the constant pool tag. value is size. // eg: array[5] = 8; means size of long is 8 bytes. -const u1 SharedStringDecompressor::sizes[] = {0, 0, 0, 4, 4, 8, 8, 2, 2, 4, 4, 4, 4, 0, 0, 3, 2, 0, 4}; +const u1 SharedStringDecompressor::sizes[] = { + 0, 0, 0, 4, 4, 8, 8, 2, 2, 4, 4, 4, 4, 0, 0, 3, 2, 0, 4 +}; /** * Recreate the class by reconstructing the constant pool. */ void SharedStringDecompressor::decompress_resource(u1* data, - u1* uncompressed_resource, - ResourceHeader* header, const ImageStrings* strings) { - u1* uncompressed_base = uncompressed_resource; - u1* data_base = data; - int header_size = 8; // magic + major + minor - memcpy(uncompressed_resource, data, header_size + 2); //+ cp count - uncompressed_resource += header_size + 2; - data += header_size; - u2 cp_count = Endian::get_java(data); - data += 2; - for (int i = 1; i < cp_count; i++) { - u1 tag = *data; - data += 1; - switch (tag) { + u1* uncompressed_resource, + ResourceHeader* header, const ImageStrings* strings) { + u1* uncompressed_base = uncompressed_resource; + u1* data_base = data; + int header_size = 8; // magic + major + minor + memcpy(uncompressed_resource, data, header_size + 2); //+ cp count + uncompressed_resource += header_size + 2; + data += header_size; + u2 cp_count = Endian::get_java(data); + data += 2; + for (int i = 1; i < cp_count; i++) { + u1 tag = *data; + data += 1; + switch (tag) { - case externalized_string: - { // String in Strings table - *uncompressed_resource = 1; - uncompressed_resource += 1; - int i = decompress_int(data); - const char * string = strings->get(i); - int str_length = (int) strlen(string); - Endian::set_java(uncompressed_resource, str_length); - uncompressed_resource += 2; - memcpy(uncompressed_resource, string, str_length); - uncompressed_resource += str_length; - break; - } - // Descriptor String has been split and types added to Strings table - case externalized_string_descriptor: - { - *uncompressed_resource = 1; - uncompressed_resource += 1; - int descriptor_index = decompress_int(data); - int indexes_length = decompress_int(data); - u1* length_address = uncompressed_resource; - uncompressed_resource += 2; - int desc_length = 0; - const char * desc_string = strings->get(descriptor_index); - if (indexes_length > 0) { - u1* indexes_base = data; - data += indexes_length; - char c = *desc_string; - do { - *uncompressed_resource = c; - uncompressed_resource++; - desc_length += 1; - /* - * Every L character is the marker we are looking at in order - * to reconstruct the descriptor. Each time an L is found, then - * we retrieve the couple token/token at the current index and - * add it to the descriptor. - * "(L;I)V" and "java/lang","String" couple of tokens, - * this becomes "(Ljava/lang/String;I)V" - */ - if (c == 'L') { - int index = decompress_int(indexes_base); - const char * pkg = strings->get(index); - int str_length = (int) strlen(pkg); - // the case where we have a package. - // reconstruct the type full name - if (str_length > 0) { - int len = str_length + 1; - char* fullpkg = new char[len]; - char* pkg_base = fullpkg; - memcpy(fullpkg, pkg, str_length); - fullpkg += str_length; - *fullpkg = '/'; - memcpy(uncompressed_resource, pkg_base, len); + case externalized_string: + { // String in Strings table + *uncompressed_resource = 1; + uncompressed_resource += 1; + int i = decompress_int(data); + const char * string = strings->get(i); + int str_length = (int) strlen(string); + Endian::set_java(uncompressed_resource, str_length); + uncompressed_resource += 2; + memcpy(uncompressed_resource, string, str_length); + uncompressed_resource += str_length; + break; + } + // Descriptor String has been split and types added to Strings table + case externalized_string_descriptor: + { + *uncompressed_resource = 1; + uncompressed_resource += 1; + int descriptor_index = decompress_int(data); + int indexes_length = decompress_int(data); + u1* length_address = uncompressed_resource; + uncompressed_resource += 2; + int desc_length = 0; + const char * desc_string = strings->get(descriptor_index); + if (indexes_length > 0) { + u1* indexes_base = data; + data += indexes_length; + char c = *desc_string; + do { + *uncompressed_resource = c; + uncompressed_resource++; + desc_length += 1; + /* + * Every L character is the marker we are looking at in order + * to reconstruct the descriptor. Each time an L is found, then + * we retrieve the couple token/token at the current index and + * add it to the descriptor. + * "(L;I)V" and "java/lang","String" couple of tokens, + * this becomes "(Ljava/lang/String;I)V" + */ + if (c == 'L') { + int index = decompress_int(indexes_base); + const char * pkg = strings->get(index); + int str_length = (int) strlen(pkg); + // the case where we have a package. + // reconstruct the type full name + if (str_length > 0) { + int len = str_length + 1; + char* fullpkg = new char[len]; + char* pkg_base = fullpkg; + memcpy(fullpkg, pkg, str_length); + fullpkg += str_length; + *fullpkg = '/'; + memcpy(uncompressed_resource, pkg_base, len); + uncompressed_resource += len; + delete pkg_base; + desc_length += len; + } else { // Empty package + // Nothing to do. + } + int classIndex = decompress_int(indexes_base); + const char * clazz = strings->get(classIndex); + int clazz_length = (int) strlen(clazz); + memcpy(uncompressed_resource, clazz, clazz_length); + uncompressed_resource += clazz_length; + desc_length += clazz_length; + } + desc_string += 1; + c = *desc_string; + } while (c != '\0'); + } else { + desc_length = (int) strlen(desc_string); + memcpy(uncompressed_resource, desc_string, desc_length); + uncompressed_resource += desc_length; + } + Endian::set_java(length_address, desc_length); + break; + } + + case constant_utf8: + { // UTF-8 + *uncompressed_resource = tag; + uncompressed_resource += 1; + u2 str_length = Endian::get_java(data); + int len = str_length + 2; + memcpy(uncompressed_resource, data, len); uncompressed_resource += len; - delete pkg_base; - desc_length += len; - } else { // Empty package - // Nothing to do. - } - int classIndex = decompress_int(indexes_base); - const char * clazz = strings->get(classIndex); - int clazz_length = (int) strlen(clazz); - memcpy(uncompressed_resource, clazz, clazz_length); - uncompressed_resource += clazz_length; - desc_length += clazz_length; + data += len; + break; } - desc_string += 1; - c = *desc_string; - } while (c != '\0'); - } else { - desc_length = (int) strlen(desc_string); - memcpy(uncompressed_resource, desc_string, desc_length); - uncompressed_resource += desc_length; + + case constant_long: + case constant_double: + { + i++; + } + default: + { + *uncompressed_resource = tag; + uncompressed_resource += 1; + int size = sizes[tag]; + memcpy(uncompressed_resource, data, size); + uncompressed_resource += size; + data += size; + } } - Endian::set_java(length_address, desc_length); - break; - } - - case constant_utf8: - { // UTF-8 - *uncompressed_resource = tag; - uncompressed_resource += 1; - u2 str_length = Endian::get_java(data); - int len = str_length + 2; - memcpy(uncompressed_resource, data, len); - uncompressed_resource += len; - data += len; - break; - } - - case constant_long: - case constant_double: - { - i++; - } - default: - { - *uncompressed_resource = tag; - uncompressed_resource += 1; - int size = sizes[tag]; - memcpy(uncompressed_resource, data, size); - uncompressed_resource += size; - data += size; - } } - } - u4 remain = header->_size - (int)(data - data_base); - u4 computed = (u4)(uncompressed_resource - uncompressed_base) + remain; - if (header->_uncompressed_size != computed) - printf("Failure, expecting %d but getting %d\n", header->_uncompressed_size, - computed); - assert(header->_uncompressed_size == computed && - "Constant Pool reconstruction failed"); - memcpy(uncompressed_resource, data, remain); + u4 remain = header->_size - (int)(data - data_base); + u4 computed = (u4)(uncompressed_resource - uncompressed_base) + remain; + if (header->_uncompressed_size != computed) + printf("Failure, expecting %d but getting %d\n", header->_uncompressed_size, + computed); + assert(header->_uncompressed_size == computed && + "Constant Pool reconstruction failed"); + memcpy(uncompressed_resource, data, remain); } /* @@ -308,25 +311,25 @@ * Example of compression: 1 is compressed on 1 byte: 10100001 */ int SharedStringDecompressor::decompress_int(unsigned char*& value) { - int len = 4; - int res = 0; - char b1 = *value; - if (is_compressed((signed char)b1)) { // compressed - len = get_compressed_length(b1); - char clearedValue = b1 &= 0x1F; - if (len == 1) { - res = clearedValue; + int len = 4; + int res = 0; + char b1 = *value; + if (is_compressed((signed char)b1)) { // compressed + len = get_compressed_length(b1); + char clearedValue = b1 &= 0x1F; + if (len == 1) { + res = clearedValue; + } else { + res = (clearedValue & 0xFF) << 8 * (len - 1); + for (int i = 1; i < len; i++) { + res |= (value[i]&0xFF) << 8 * (len - i - 1); + } + } } else { - res = (clearedValue & 0xFF) << 8 * (len - 1); - for (int i = 1; i < len; i++) { - res |= (value[i]&0xFF) << 8 * (len - i - 1); - } + res = (value[0] & 0xFF) << 24 | (value[1]&0xFF) << 16 | + (value[2]&0xFF) << 8 | (value[3]&0xFF); } - } else { - res = (value[0] & 0xFF) << 24 | (value[1]&0xFF) << 16 | - (value[2]&0xFF) << 8 | (value[3]&0xFF); - } - value += len; - return res; + value += len; + return res; } // END Shared String decompressor
--- a/src/java.base/share/native/libjimage/imageDecompressor.hpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/imageDecompressor.hpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,11 +4,13 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #ifndef LIBJIMAGE_IMAGEDECOMPRESSOR_HPP @@ -47,16 +48,16 @@ * have been used to compress the resource. */ struct ResourceHeader { - /* Length of header, needed to retrieve content offset */ - static const u1 resource_header_length = 21; - /* magic bytes that identifies a compressed resource header*/ - static const u4 resource_header_magic = 0xCAFEFAFA; - u4 _magic; // Resource header - u4 _size; // Resource size - u4 _uncompressed_size; // Expected uncompressed size - u4 _decompressor_name_offset; // Strings table decompressor offset - u4 _decompressor_config_offset; // Strings table config offset - u1 _is_terminal; // Last decompressor 1, otherwise 0. + /* Length of header, needed to retrieve content offset */ + static const u1 resource_header_length = 21; + /* magic bytes that identifies a compressed resource header*/ + static const u4 resource_header_magic = 0xCAFEFAFA; + u4 _magic; // Resource header + u4 _size; // Resource size + u4 _uncompressed_size; // Expected uncompressed size + u4 _decompressor_name_offset; // Strings table decompressor offset + u4 _decompressor_config_offset; // Strings table config offset + u1 _is_terminal; // Last decompressor 1, otherwise 0. }; /* @@ -77,36 +78,36 @@ class ImageDecompressor { private: - const char* _name; + const char* _name; - /* - * Array of concrete decompressors. This array is used to retrieve the decompressor - * that can handle resource decompression. - */ - static ImageDecompressor** _decompressors; - /** - * Num of decompressors - */ - static int _decompressors_num; - /* - * Identifier of a decompressor. This name is the identification key to retrieve - * decompressor from a resource header. - */ - inline const char* get_name() const { return _name; } + /* + * Array of concrete decompressors. This array is used to retrieve the decompressor + * that can handle resource decompression. + */ + static ImageDecompressor** _decompressors; + /** + * Num of decompressors + */ + static int _decompressors_num; + /* + * Identifier of a decompressor. This name is the identification key to retrieve + * decompressor from a resource header. + */ + inline const char* get_name() const { return _name; } protected: - ImageDecompressor(const char* name) : _name(name) { - } - virtual void decompress_resource(u1* data, u1* uncompressed, - ResourceHeader* header, const ImageStrings* strings) = 0; + ImageDecompressor(const char* name) : _name(name) { + } + virtual void decompress_resource(u1* data, u1* uncompressed, + ResourceHeader* header, const ImageStrings* strings) = 0; public: - static void image_decompressor_init(); - static void image_decompressor_close(); - static ImageDecompressor* get_decompressor(const char * decompressor_name) ; - static void decompress_resource(u1* compressed, u1* uncompressed, - u4 uncompressed_size, const ImageStrings* strings); + static void image_decompressor_init(); + static void image_decompressor_close(); + static ImageDecompressor* get_decompressor(const char * decompressor_name) ; + static void decompress_resource(u1* compressed, u1* uncompressed, + u4 uncompressed_size, const ImageStrings* strings); }; /** @@ -114,10 +115,10 @@ */ class ZipDecompressor : public ImageDecompressor { public: - ZipDecompressor(const char* sym) : ImageDecompressor(sym) { } - void decompress_resource(u1* data, u1* uncompressed, ResourceHeader* header, - const ImageStrings* strings); - static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg); + ZipDecompressor(const char* sym) : ImageDecompressor(sym) { } + void decompress_resource(u1* data, u1* uncompressed, ResourceHeader* header, + const ImageStrings* strings); + static jboolean decompress(void *in, u8 inSize, void *out, u8 outSize, char **pmsg); }; /* @@ -131,32 +132,34 @@ */ class SharedStringDecompressor : public ImageDecompressor { private: - // the constant pool tag for UTF8 string located in strings table - static const int externalized_string = 23; - // the constant pool tag for UTF8 descriptors string located in strings table - static const int externalized_string_descriptor = 25; - // the constant pool tag for UTF8 - static const int constant_utf8 = 1; - // the constant pool tag for long - static const int constant_long = 5; - // the constant pool tag for double - static const int constant_double = 6; - // array index is the constant pool tag. value is size. - // eg: array[5] = 8; means size of long is 8 bytes. - static const u1 sizes[]; - // bit 5 and 6 are used to store the length of the compressed integer. - // size can be 1 (01), 2 (10), 3 (11). - // 0x60 ==> 0110000 - static const int compressed_index_size_mask = 0x60; - /* - * mask the length bits (5 and 6) and move to the right 5 bits. - */ - inline static int get_compressed_length(char c) { return ((char) (c & compressed_index_size_mask) >> 5); } - inline static bool is_compressed(signed char b1) { return b1 < 0; } - static int decompress_int(unsigned char*& value); + // the constant pool tag for UTF8 string located in strings table + static const int externalized_string = 23; + // the constant pool tag for UTF8 descriptors string located in strings table + static const int externalized_string_descriptor = 25; + // the constant pool tag for UTF8 + static const int constant_utf8 = 1; + // the constant pool tag for long + static const int constant_long = 5; + // the constant pool tag for double + static const int constant_double = 6; + // array index is the constant pool tag. value is size. + // eg: array[5] = 8; means size of long is 8 bytes. + static const u1 sizes[]; + // bit 5 and 6 are used to store the length of the compressed integer. + // size can be 1 (01), 2 (10), 3 (11). + // 0x60 ==> 0110000 + static const int compressed_index_size_mask = 0x60; + /* + * mask the length bits (5 and 6) and move to the right 5 bits. + */ + inline static int get_compressed_length(char c) { + return ((char) (c & compressed_index_size_mask) >> 5); + } + inline static bool is_compressed(signed char b1) { return b1 < 0; } + static int decompress_int(unsigned char*& value); public: - SharedStringDecompressor(const char* sym) : ImageDecompressor(sym){} - void decompress_resource(u1* data, u1* uncompressed, ResourceHeader* header, - const ImageStrings* strings); + SharedStringDecompressor(const char* sym) : ImageDecompressor(sym){} + void decompress_resource(u1* data, u1* uncompressed, ResourceHeader* header, + const ImageStrings* strings); }; #endif // LIBJIMAGE_IMAGEDECOMPRESSOR_HPP
--- a/src/java.base/share/native/libjimage/imageFile.cpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/imageFile.cpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,11 +4,13 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #include <assert.h> @@ -50,268 +51,268 @@ // Compute the Perfect Hashing hash code for the supplied UTF-8 string. s4 ImageStrings::hash_code(const char* string, s4 seed) { - // Access bytes as unsigned. - u1* bytes = (u1*)string; - // Compute hash code. - for (u1 byte = *bytes++; byte; byte = *bytes++) { - seed = (seed * HASH_MULTIPLIER) ^ byte; - } - // Ensure the result is not signed. - return seed & 0x7FFFFFFF; + // Access bytes as unsigned. + u1* bytes = (u1*)string; + // Compute hash code. + for (u1 byte = *bytes++; byte; byte = *bytes++) { + seed = (seed * HASH_MULTIPLIER) ^ byte; + } + // Ensure the result is not signed. + return seed & 0x7FFFFFFF; } // Match up a string in a perfect hash table. // Returns the index where the name should be. // Result still needs validation for precise match (false positive.) s4 ImageStrings::find(Endian* endian, const char* name, s4* redirect, u4 length) { - // If the table is empty, then short cut. - if (!redirect || !length) { + // If the table is empty, then short cut. + if (!redirect || !length) { + return NOT_FOUND; + } + // Compute the basic perfect hash for name. + s4 hash_code = ImageStrings::hash_code(name); + // Modulo table size. + s4 index = hash_code % length; + // Get redirect entry. + // value == 0 then not found + // value < 0 then -1 - value is true index + // value > 0 then value is seed for recomputing hash. + s4 value = endian->get(redirect[index]); + // if recompute is required. + if (value > 0 ) { + // Entry collision value, need to recompute hash. + hash_code = ImageStrings::hash_code(name, value); + // Modulo table size. + return hash_code % length; + } else if (value < 0) { + // Compute direct index. + return -1 - value; + } + // No entry found. return NOT_FOUND; - } - // Compute the basic perfect hash for name. - s4 hash_code = ImageStrings::hash_code(name); - // Modulo table size. - s4 index = hash_code % length; - // Get redirect entry. - // value == 0 then not found - // value < 0 then -1 - value is true index - // value > 0 then value is seed for recomputing hash. - s4 value = endian->get(redirect[index]); - // if recompute is required. - if (value > 0 ) { - // Entry collision value, need to recompute hash. - hash_code = ImageStrings::hash_code(name, value); - // Modulo table size. - return hash_code % length; - } else if (value < 0) { - // Compute direct index. - return -1 - value; - } - // No entry found. - return NOT_FOUND; } // Test to see if UTF-8 string begins with the start UTF-8 string. If so, // return non-NULL address of remaining portion of string. Otherwise, return -// NULL. Used to test sections of a path without copying from image string +// NULL. Used to test sections of a path without copying from image string // table. const char* ImageStrings::starts_with(const char* string, const char* start) { - char ch1, ch2; - // Match up the strings the best we can. - while ((ch1 = *string) && (ch2 = *start)) { - if (ch1 != ch2) { - // Mismatch, return NULL. - return NULL; + char ch1, ch2; + // Match up the strings the best we can. + while ((ch1 = *string) && (ch2 = *start)) { + if (ch1 != ch2) { + // Mismatch, return NULL. + return NULL; + } + // Next characters. + string++, start++; } - // Next characters. - string++, start++; - } - // Return remainder of string. - return string; + // Return remainder of string. + return string; } // Inflates the attribute stream into individual values stored in the long // array _attributes. This allows an attribute value to be quickly accessed by // direct indexing. Unspecified values default to zero (from constructor.) void ImageLocation::set_data(u1* data) { - // Deflate the attribute stream into an array of attributes. - u1 byte; - // Repeat until end header is found. - while ((byte = *data)) { - // Extract kind from header byte. - u1 kind = attribute_kind(byte); - assert(kind < ATTRIBUTE_COUNT && "invalid image location attribute"); - // Extract length of data (in bytes). - u1 n = attribute_length(byte); - // Read value (most significant first.) - _attributes[kind] = attribute_value(data + 1, n); - // Position to next attribute by skipping attribute header and data bytes. - data += n + 1; - } + // Deflate the attribute stream into an array of attributes. + u1 byte; + // Repeat until end header is found. + while ((byte = *data)) { + // Extract kind from header byte. + u1 kind = attribute_kind(byte); + assert(kind < ATTRIBUTE_COUNT && "invalid image location attribute"); + // Extract length of data (in bytes). + u1 n = attribute_length(byte); + // Read value (most significant first.) + _attributes[kind] = attribute_value(data + 1, n); + // Position to next attribute by skipping attribute header and data bytes. + data += n + 1; + } } // Zero all attribute values. void ImageLocation::clear_data() { - // Set defaults to zero. - memset(_attributes, 0, sizeof(_attributes)); + // Set defaults to zero. + memset(_attributes, 0, sizeof(_attributes)); } // ImageModuleData constructor maps out sub-tables for faster access. ImageModuleData::ImageModuleData(const ImageFileReader* image_file, - const char* module_data_name) : - _image_file(image_file), - _endian(image_file->endian()), - _strings(image_file->get_strings()) { - // Retrieve the resource containing the module data for the image file. - ImageLocation location; - bool found = image_file->find_location(module_data_name, location); - if (found) { - u8 data_size = location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED); - _data = new u1[(size_t)data_size]; - _image_file->get_resource(location, _data); - // Map out the header. - _header = (Header*)_data; - // Get the package to module entry count. - u4 ptm_count = _header->ptm_count(_endian); - // Get the module to package entry count. - u4 mtp_count = _header->mtp_count(_endian); - // Compute the offset of the package to module perfect hash redirect. - u4 ptm_redirect_offset = sizeof(Header); - // Compute the offset of the package to module data. - u4 ptm_data_offset = ptm_redirect_offset + ptm_count * sizeof(s4); - // Compute the offset of the module to package perfect hash redirect. - u4 mtp_redirect_offset = ptm_data_offset + ptm_count * sizeof(PTMData); - // Compute the offset of the module to package data. - u4 mtp_data_offset = mtp_redirect_offset + mtp_count * sizeof(s4); - // Compute the offset of the module to package tables. - u4 mtp_packages_offset = mtp_data_offset + mtp_count * sizeof(MTPData); - // Compute the address of the package to module perfect hash redirect. - _ptm_redirect = (s4*)(_data + ptm_redirect_offset); - // Compute the address of the package to module data. - _ptm_data = (PTMData*)(_data + ptm_data_offset); - // Compute the address of the module to package perfect hash redirect. - _mtp_redirect = (s4*)(_data + mtp_redirect_offset); - // Compute the address of the module to package data. - _mtp_data = (MTPData*)(_data + mtp_data_offset); - // Compute the address of the module to package tables. - _mtp_packages = (s4*)(_data + mtp_packages_offset); - } else { - // No module data present. - _data = NULL; - _header = NULL; - _ptm_redirect = NULL; - _ptm_data = NULL; - _mtp_redirect = NULL; - _mtp_data = NULL; - _mtp_packages = NULL; - } + const char* module_data_name) : + _image_file(image_file), + _endian(image_file->endian()), + _strings(image_file->get_strings()) { + // Retrieve the resource containing the module data for the image file. + ImageLocation location; + bool found = image_file->find_location(module_data_name, location); + if (found) { + u8 data_size = location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED); + _data = new u1[(size_t)data_size]; + _image_file->get_resource(location, _data); + // Map out the header. + _header = (Header*)_data; + // Get the package to module entry count. + u4 ptm_count = _header->ptm_count(_endian); + // Get the module to package entry count. + u4 mtp_count = _header->mtp_count(_endian); + // Compute the offset of the package to module perfect hash redirect. + u4 ptm_redirect_offset = sizeof(Header); + // Compute the offset of the package to module data. + u4 ptm_data_offset = ptm_redirect_offset + ptm_count * sizeof(s4); + // Compute the offset of the module to package perfect hash redirect. + u4 mtp_redirect_offset = ptm_data_offset + ptm_count * sizeof(PTMData); + // Compute the offset of the module to package data. + u4 mtp_data_offset = mtp_redirect_offset + mtp_count * sizeof(s4); + // Compute the offset of the module to package tables. + u4 mtp_packages_offset = mtp_data_offset + mtp_count * sizeof(MTPData); + // Compute the address of the package to module perfect hash redirect. + _ptm_redirect = (s4*)(_data + ptm_redirect_offset); + // Compute the address of the package to module data. + _ptm_data = (PTMData*)(_data + ptm_data_offset); + // Compute the address of the module to package perfect hash redirect. + _mtp_redirect = (s4*)(_data + mtp_redirect_offset); + // Compute the address of the module to package data. + _mtp_data = (MTPData*)(_data + mtp_data_offset); + // Compute the address of the module to package tables. + _mtp_packages = (s4*)(_data + mtp_packages_offset); + } else { + // No module data present. + _data = NULL; + _header = NULL; + _ptm_redirect = NULL; + _ptm_data = NULL; + _mtp_redirect = NULL; + _mtp_data = NULL; + _mtp_packages = NULL; + } } // Release module data resource. ImageModuleData::~ImageModuleData() { - if (_data) { - delete _data; - } + if (_data) { + delete _data; + } } // Return the name of the module data resource. Ex. "./lib/modules/file.jimage" // yields "file.jdata" void ImageModuleData::module_data_name(char* buffer, const char* image_file_name) { - // Locate the last slash in the file name path. - const char* slash = strrchr(image_file_name, FileSeparator); - // Trim the path to name and extension. - const char* name = slash ? slash + 1 : (char *)image_file_name; - // Locate the extension period. - const char* dot = strrchr(name, '.'); - assert(dot && "missing extension on jimage name"); - // Trim to only base name. - int length = (int)(dot - name); - strncpy(buffer, name, length); - buffer[length] = '\0'; - // Append extension. - strcat(buffer, ".jdata"); + // Locate the last slash in the file name path. + const char* slash = strrchr(image_file_name, FileSeparator); + // Trim the path to name and extension. + const char* name = slash ? slash + 1 : (char *)image_file_name; + // Locate the extension period. + const char* dot = strrchr(name, '.'); + assert(dot && "missing extension on jimage name"); + // Trim to only base name. + int length = (int)(dot - name); + strncpy(buffer, name, length); + buffer[length] = '\0'; + // Append extension. + strcat(buffer, ".jdata"); } -// Return the module in which a package resides. Returns NULL if not found. +// Return the module in which a package resides. Returns NULL if not found. const char* ImageModuleData::package_to_module(const char* package_name) { - // Test files may contain no module data. - if (_data != NULL) { - // Search the package to module table. - s4 index = ImageStrings::find(_endian, package_name, _ptm_redirect, - _header->ptm_count(_endian)); - // If entry is found. - if (index != ImageStrings::NOT_FOUND) { - // Retrieve the package to module entry. - PTMData* data = _ptm_data + index; - // Verify that it is the correct data. - if (strcmp(package_name, get_string(data->name_offset(_endian))) != 0) { - return NULL; - } - // Return the module name. - return get_string(data->module_name_offset(_endian)); + // Test files may contain no module data. + if (_data != NULL) { + // Search the package to module table. + s4 index = ImageStrings::find(_endian, package_name, _ptm_redirect, + _header->ptm_count(_endian)); + // If entry is found. + if (index != ImageStrings::NOT_FOUND) { + // Retrieve the package to module entry. + PTMData* data = _ptm_data + index; + // Verify that it is the correct data. + if (strcmp(package_name, get_string(data->name_offset(_endian))) != 0) { + return NULL; + } + // Return the module name. + return get_string(data->module_name_offset(_endian)); + } } - } - return NULL; + return NULL; } // Returns all the package names in a module in a NULL terminated array. // Returns NULL if module not found. const char** ImageModuleData::module_to_packages(const char* module_name) { - // Test files may contain no module data. - if (_data != NULL) { - // Search the module to package table. - s4 index = ImageStrings::find(_endian, module_name, _mtp_redirect, - _header->mtp_count(_endian)); - // If entry is found. - if (index != ImageStrings::NOT_FOUND) { - // Retrieve the module to package entry. - MTPData* data = _mtp_data + index; - // Verify that it is the correct data. - if (strcmp(module_name, get_string(data->name_offset(_endian))) != 0) { - return NULL; - } - // Construct an array of all the package entries. - u4 count = data->package_count(_endian); - const char** packages = new const char*[count + 1]; - s4 package_offset = data->package_offset(_endian); - for (u4 i = 0; i < count; i++) { - u4 package_name_offset = mtp_package(package_offset + i); - const char* package_name = get_string(package_name_offset); - packages[i] = package_name; - } - packages[count] = NULL; - return packages; + // Test files may contain no module data. + if (_data != NULL) { + // Search the module to package table. + s4 index = ImageStrings::find(_endian, module_name, _mtp_redirect, + _header->mtp_count(_endian)); + // If entry is found. + if (index != ImageStrings::NOT_FOUND) { + // Retrieve the module to package entry. + MTPData* data = _mtp_data + index; + // Verify that it is the correct data. + if (strcmp(module_name, get_string(data->name_offset(_endian))) != 0) { + return NULL; + } + // Construct an array of all the package entries. + u4 count = data->package_count(_endian); + const char** packages = new const char*[count + 1]; + s4 package_offset = data->package_offset(_endian); + for (u4 i = 0; i < count; i++) { + u4 package_name_offset = mtp_package(package_offset + i); + const char* package_name = get_string(package_name_offset); + packages[i] = package_name; + } + packages[count] = NULL; + return packages; + } } - } - return NULL; + return NULL; } // Manage a table of open image files. This table allows multiple access points // to share an open image. ImageFileReaderTable::ImageFileReaderTable() : _count(0), _max(_growth) { - _table = new ImageFileReader*[_max]; + _table = new ImageFileReader*[_max]; } ImageFileReaderTable::~ImageFileReaderTable() { - delete _table; + delete _table; } // Add a new image entry to the table. void ImageFileReaderTable::add(ImageFileReader* image) { - if (_count == _max) { - _max += _growth; - _table = static_cast<ImageFileReader**>(realloc(_table, _max * sizeof(ImageFileReader*))); - } - _table[_count++] = image; + if (_count == _max) { + _max += _growth; + _table = static_cast<ImageFileReader**>(realloc(_table, _max * sizeof(ImageFileReader*))); + } + _table[_count++] = image; } // Remove an image entry from the table. void ImageFileReaderTable::remove(ImageFileReader* image) { - s4 last = _count - 1; - for (s4 i = 0; _count; i++) { - if (_table[i] == image) { - if (i != last) { - _table[i] = _table[last]; - _count = last; - } - break; + s4 last = _count - 1; + for (s4 i = 0; _count; i++) { + if (_table[i] == image) { + if (i != last) { + _table[i] = _table[last]; + _count = last; + } + break; + } } - } - if (_count != 0 && _count == _max - _growth) { - _max -= _growth; - _table = static_cast<ImageFileReader**>(realloc(_table, _max * sizeof(ImageFileReader*))); - } + if (_count != 0 && _count == _max - _growth) { + _max -= _growth; + _table = static_cast<ImageFileReader**>(realloc(_table, _max * sizeof(ImageFileReader*))); + } } // Determine if image entry is in table. bool ImageFileReaderTable::contains(ImageFileReader* image) { - for (s4 i = 0; _count; i++) { - if (_table[i] == image) { - return true; + for (s4 i = 0; _count; i++) { + if (_table[i] == image) { + return true; + } } - } - return false; + return false; } // Table to manage multiple opens of an image file. @@ -321,362 +322,362 @@ // Open an image file, reuse structure if file already open. ImageFileReader* ImageFileReader::open(const char* name, bool big_endian) { - { - // Lock out _reader_table. + { + // Lock out _reader_table. + SimpleCriticalSectionLock cs(&_reader_table_lock); + // Search for an exist image file. + for (u4 i = 0; i < _reader_table.count(); i++) { + // Retrieve table entry. + ImageFileReader* reader = _reader_table.get(i); + // If name matches, then reuse (bump up use count.) + if (strcmp(reader->name(), name) == 0) { + reader->inc_use(); + return reader; + } + } + } // Unlock the mutex + + // Need a new image reader. + ImageFileReader* reader = new ImageFileReader(name, big_endian); + bool opened = reader->open(); + // If failed to open. + if (!opened) { + delete reader; + return NULL; + } + + // Lock to update SimpleCriticalSectionLock cs(&_reader_table_lock); // Search for an exist image file. for (u4 i = 0; i < _reader_table.count(); i++) { - // Retrieve table entry. - ImageFileReader* reader = _reader_table.get(i); - // If name matches, then reuse (bump up use count.) - if (strcmp(reader->name(), name) == 0) { - reader->inc_use(); - return reader; - } + // Retrieve table entry. + ImageFileReader* existing_reader = _reader_table.get(i); + // If name matches, then reuse (bump up use count.) + if (strcmp(existing_reader->name(), name) == 0) { + existing_reader->inc_use(); + reader->close(); + delete reader; + return existing_reader; + } } - } // Unlock the mutex - - // Need a new image reader. - ImageFileReader* reader = new ImageFileReader(name, big_endian); - bool opened = reader->open(); - // If failed to open. - if (!opened) { - delete reader; - return NULL; - } - - // Lock to update - SimpleCriticalSectionLock cs(&_reader_table_lock); - // Search for an exist image file. - for (u4 i = 0; i < _reader_table.count(); i++) { - // Retrieve table entry. - ImageFileReader* existing_reader = _reader_table.get(i); - // If name matches, then reuse (bump up use count.) - if (strcmp(existing_reader->name(), name) == 0) { - existing_reader->inc_use(); - reader->close(); - delete reader; - return existing_reader; - } - } - // Bump use count and add to table. - reader->inc_use(); - _reader_table.add(reader); - return reader; + // Bump use count and add to table. + reader->inc_use(); + _reader_table.add(reader); + return reader; } // Close an image file if the file is not in use elsewhere. void ImageFileReader::close(ImageFileReader *reader) { - // Lock out _reader_table. - SimpleCriticalSectionLock cs(&_reader_table_lock); - // If last use then remove from table and then close. - if (reader->dec_use()) { - _reader_table.remove(reader); - delete reader; - } + // Lock out _reader_table. + SimpleCriticalSectionLock cs(&_reader_table_lock); + // If last use then remove from table and then close. + if (reader->dec_use()) { + _reader_table.remove(reader); + delete reader; + } } // Return an id for the specifed ImageFileReader. u8 ImageFileReader::readerToID(ImageFileReader *reader) { - // ID is just the cloaked reader address. - return (u8)reader; + // ID is just the cloaked reader address. + return (u8)reader; } // Validate the image id. bool ImageFileReader::idCheck(u8 id) { - // Make sure the ID is a managed (_reader_table) reader. - SimpleCriticalSectionLock cs(&_reader_table_lock); - return _reader_table.contains((ImageFileReader*)id); + // Make sure the ID is a managed (_reader_table) reader. + SimpleCriticalSectionLock cs(&_reader_table_lock); + return _reader_table.contains((ImageFileReader*)id); } // Return an id for the specifed ImageFileReader. ImageFileReader* ImageFileReader::idToReader(u8 id) { - assert(idCheck(id) && "invalid image id"); - return (ImageFileReader*)id; + assert(idCheck(id) && "invalid image id"); + return (ImageFileReader*)id; } // Constructor intializes to a closed state. ImageFileReader::ImageFileReader(const char* name, bool big_endian) { - // Copy the image file name. - int len = (int) strlen(name) + 1; - _name = new char[len]; - strncpy(_name, name, len); - // Initialize for a closed file. - _fd = -1; - _endian = Endian::get_handler(big_endian); - _index_data = NULL; + // Copy the image file name. + int len = (int) strlen(name) + 1; + _name = new char[len]; + strncpy(_name, name, len); + // Initialize for a closed file. + _fd = -1; + _endian = Endian::get_handler(big_endian); + _index_data = NULL; } // Close image and free up data structures. ImageFileReader::~ImageFileReader() { - // Ensure file is closed. - close(); - // Free up name. - if (_name) { - delete _name; - _name = NULL; - } + // Ensure file is closed. + close(); + // Free up name. + if (_name) { + delete _name; + _name = NULL; + } } // Open image file for read access. bool ImageFileReader::open() { - char buffer[IMAGE_MAX_PATH]; + char buffer[IMAGE_MAX_PATH]; - // If file exists open for reading. - _fd = osSupport::openReadOnly(_name); - if (_fd == -1) { - return false; - } - // Retrieve the file size. - _file_size = osSupport::size(_name); - // Read image file header and verify it has a valid header. - size_t header_size = sizeof(ImageHeader); - if (_file_size < header_size || - !read_at((u1*)&_header, header_size, 0) || - _header.magic(_endian) != IMAGE_MAGIC || - _header.major_version(_endian) != MAJOR_VERSION || - _header.minor_version(_endian) != MINOR_VERSION) { - close(); - return false; - } - // Size of image index. - _index_size = index_size(); - // Make sure file is large enough to contain the index. - if (_file_size < _index_size) { - return false; - } - // Determine how much of the image is memory mapped. - size_t map_size = (size_t)(MemoryMapImage ? _file_size : _index_size); - // Memory map image (minimally the index.) - _index_data = (u1*)osSupport::map_memory(_fd, _name, 0, map_size); - assert(_index_data && "image file not memory mapped"); - // Retrieve length of index perfect hash table. - u4 length = table_length(); - // Compute offset of the perfect hash table redirect table. - u4 redirect_table_offset = (u4)header_size; - // Compute offset of index attribute offsets. - u4 offsets_table_offset = redirect_table_offset + length * sizeof(s4); - // Compute offset of index location attribute data. - u4 location_bytes_offset = offsets_table_offset + length * sizeof(u4); - // Compute offset of index string table. - u4 string_bytes_offset = location_bytes_offset + locations_size(); - // Compute address of the perfect hash table redirect table. - _redirect_table = (s4*)(_index_data + redirect_table_offset); - // Compute address of index attribute offsets. - _offsets_table = (u4*)(_index_data + offsets_table_offset); - // Compute address of index location attribute data. - _location_bytes = _index_data + location_bytes_offset; - // Compute address of index string table. - _string_bytes = _index_data + string_bytes_offset; + // If file exists open for reading. + _fd = osSupport::openReadOnly(_name); + if (_fd == -1) { + return false; + } + // Retrieve the file size. + _file_size = osSupport::size(_name); + // Read image file header and verify it has a valid header. + size_t header_size = sizeof(ImageHeader); + if (_file_size < header_size || + !read_at((u1*)&_header, header_size, 0) || + _header.magic(_endian) != IMAGE_MAGIC || + _header.major_version(_endian) != MAJOR_VERSION || + _header.minor_version(_endian) != MINOR_VERSION) { + close(); + return false; + } + // Size of image index. + _index_size = index_size(); + // Make sure file is large enough to contain the index. + if (_file_size < _index_size) { + return false; + } + // Determine how much of the image is memory mapped. + size_t map_size = (size_t)(MemoryMapImage ? _file_size : _index_size); + // Memory map image (minimally the index.) + _index_data = (u1*)osSupport::map_memory(_fd, _name, 0, map_size); + assert(_index_data && "image file not memory mapped"); + // Retrieve length of index perfect hash table. + u4 length = table_length(); + // Compute offset of the perfect hash table redirect table. + u4 redirect_table_offset = (u4)header_size; + // Compute offset of index attribute offsets. + u4 offsets_table_offset = redirect_table_offset + length * sizeof(s4); + // Compute offset of index location attribute data. + u4 location_bytes_offset = offsets_table_offset + length * sizeof(u4); + // Compute offset of index string table. + u4 string_bytes_offset = location_bytes_offset + locations_size(); + // Compute address of the perfect hash table redirect table. + _redirect_table = (s4*)(_index_data + redirect_table_offset); + // Compute address of index attribute offsets. + _offsets_table = (u4*)(_index_data + offsets_table_offset); + // Compute address of index location attribute data. + _location_bytes = _index_data + location_bytes_offset; + // Compute address of index string table. + _string_bytes = _index_data + string_bytes_offset; - // Initialize the module data - ImageModuleData::module_data_name(buffer, _name); - module_data = new ImageModuleData(this, buffer); - // Successful open. - return true; + // Initialize the module data + ImageModuleData::module_data_name(buffer, _name); + module_data = new ImageModuleData(this, buffer); + // Successful open. + return true; } // Close image file. void ImageFileReader::close() { - // Deallocate the index. - if (_index_data) { - osSupport::unmap_memory((char*)_index_data, _index_size); - _index_data = NULL; - } - // Close file. - if (_fd != -1) { - osSupport::close(_fd); - _fd = -1; - } + // Deallocate the index. + if (_index_data) { + osSupport::unmap_memory((char*)_index_data, _index_size); + _index_data = NULL; + } + // Close file. + if (_fd != -1) { + osSupport::close(_fd); + _fd = -1; + } } // Read directly from the file. bool ImageFileReader::read_at(u1* data, u8 size, u8 offset) const { - return (u8)osSupport::read(_fd, (char*)data, size, offset) == size; + return (u8)osSupport::read(_fd, (char*)data, size, offset) == size; } -// Find the location attributes associated with the path. Returns true if +// Find the location attributes associated with the path. Returns true if // the location is found, false otherwise. bool ImageFileReader::find_location(const char* path, ImageLocation& location) const { - // Locate the entry in the index perfect hash table. - s4 index = ImageStrings::find(_endian, path, _redirect_table, table_length()); - // If is found. - if (index != ImageStrings::NOT_FOUND) { - // Get address of first byte of location attribute stream. - u1* data = get_location_data(index); - // Expand location attributes. - location.set_data(data); - // Make sure result is not a false positive. - return verify_location(location, path); - } - return false; + // Locate the entry in the index perfect hash table. + s4 index = ImageStrings::find(_endian, path, _redirect_table, table_length()); + // If is found. + if (index != ImageStrings::NOT_FOUND) { + // Get address of first byte of location attribute stream. + u1* data = get_location_data(index); + // Expand location attributes. + location.set_data(data); + // Make sure result is not a false positive. + return verify_location(location, path); + } + return false; } // Find the location index and size associated with the path. // Returns the location index and size if the location is found, 0 otherwise. u4 ImageFileReader::find_location_index(const char* path, u8 *size) const { - // Locate the entry in the index perfect hash table. - s4 index = ImageStrings::find(_endian, path, _redirect_table, table_length()); - // If found. - if (index != ImageStrings::NOT_FOUND) { - // Get address of first byte of location attribute stream. - u4 offset = get_location_offset(index); - u1* data = get_location_offset_data(offset); - // Expand location attributes. - ImageLocation location(data); - // Make sure result is not a false positive. - if (verify_location(location, path)) { - *size = (jlong)location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED); - return offset; + // Locate the entry in the index perfect hash table. + s4 index = ImageStrings::find(_endian, path, _redirect_table, table_length()); + // If found. + if (index != ImageStrings::NOT_FOUND) { + // Get address of first byte of location attribute stream. + u4 offset = get_location_offset(index); + u1* data = get_location_offset_data(offset); + // Expand location attributes. + ImageLocation location(data); + // Make sure result is not a false positive. + if (verify_location(location, path)) { + *size = (jlong)location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED); + return offset; + } } - } - return 0; // not found + return 0; // not found } // Assemble the location path from the string fragments indicated in the location attributes. void ImageFileReader::location_path(ImageLocation& location, char* path, size_t max) const { - // Manage the image string table. - ImageStrings strings(_string_bytes, _header.strings_size(_endian)); - // Position to first character of the path buffer. - char* next = path; - // Temp for string length. - size_t length; - // Get module string. - const char* module = location.get_attribute(ImageLocation::ATTRIBUTE_MODULE, strings); - // If module string is not empty string. - if (*module != '\0') { - // Get length of module name. - length = strlen(module); + // Manage the image string table. + ImageStrings strings(_string_bytes, _header.strings_size(_endian)); + // Position to first character of the path buffer. + char* next = path; + // Temp for string length. + size_t length; + // Get module string. + const char* module = location.get_attribute(ImageLocation::ATTRIBUTE_MODULE, strings); + // If module string is not empty string. + if (*module != '\0') { + // Get length of module name. + length = strlen(module); + // Make sure there is no buffer overflow. + assert(next - path + length + 2 < max && "buffer overflow"); + // Append '/module/'. + *next++ = '/'; + strncpy(next, module, length); next += length; + *next++ = '/'; + } + // Get parent (package) string. + const char* parent = location.get_attribute(ImageLocation::ATTRIBUTE_PARENT, strings); + // If parent string is not empty string. + if (*parent != '\0') { + // Get length of module string. + length = strlen(parent); + // Make sure there is no buffer overflow. + assert(next - path + length + 1 < max && "buffer overflow"); + // Append 'patent/' . + strncpy(next, parent, length); next += length; + *next++ = '/'; + } + // Get base name string. + const char* base = location.get_attribute(ImageLocation::ATTRIBUTE_BASE, strings); + // Get length of base name. + length = strlen(base); // Make sure there is no buffer overflow. - assert(next - path + length + 2 < max && "buffer overflow"); - // Append '/module/'. - *next++ = '/'; - strncpy(next, module, length); next += length; - *next++ = '/'; - } - // Get parent (package) string. - const char* parent = location.get_attribute(ImageLocation::ATTRIBUTE_PARENT, strings); - // If parent string is not empty string. - if (*parent != '\0') { - // Get length of module string. - length = strlen(parent); + assert(next - path + length < max && "buffer overflow"); + // Append base name. + strncpy(next, base, length); next += length; + // Get extension string. + const char* extension = location.get_attribute(ImageLocation::ATTRIBUTE_EXTENSION, strings); + // If extension string is not empty string. + if (*extension != '\0') { + // Get length of extension string. + length = strlen(extension); + // Make sure there is no buffer overflow. + assert(next - path + length + 1 < max && "buffer overflow"); + // Append '.extension' . + *next++ = '.'; + strncpy(next, extension, length); next += length; + } // Make sure there is no buffer overflow. - assert(next - path + length + 1 < max && "buffer overflow"); - // Append 'patent/' . - strncpy(next, parent, length); next += length; - *next++ = '/'; - } - // Get base name string. - const char* base = location.get_attribute(ImageLocation::ATTRIBUTE_BASE, strings); - // Get length of base name. - length = strlen(base); - // Make sure there is no buffer overflow. - assert(next - path + length < max && "buffer overflow"); - // Append base name. - strncpy(next, base, length); next += length; - // Get extension string. - const char* extension = location.get_attribute(ImageLocation::ATTRIBUTE_EXTENSION, strings); - // If extension string is not empty string. - if (*extension != '\0') { - // Get length of extension string. - length = strlen(extension); - // Make sure there is no buffer overflow. - assert(next - path + length + 1 < max && "buffer overflow"); - // Append '.extension' . - *next++ = '.'; - strncpy(next, extension, length); next += length; - } - // Make sure there is no buffer overflow. - assert((size_t)(next - path) < max && "buffer overflow"); - // Terminate string. - *next = '\0'; + assert((size_t)(next - path) < max && "buffer overflow"); + // Terminate string. + *next = '\0'; } // Verify that a found location matches the supplied path (without copying.) bool ImageFileReader::verify_location(ImageLocation& location, const char* path) const { - // Manage the image string table. - ImageStrings strings(_string_bytes, _header.strings_size(_endian)); - // Position to first character of the path string. - const char* next = path; - // Get module name string. - const char* module = location.get_attribute(ImageLocation::ATTRIBUTE_MODULE, strings); - // If module string is not empty. - if (*module != '\0') { - // Compare '/module/' . - if (*next++ != '/') return false; - if (!(next = ImageStrings::starts_with(next, module))) return false; - if (*next++ != '/') return false; - } - // Get parent (package) string - const char* parent = location.get_attribute(ImageLocation::ATTRIBUTE_PARENT, strings); - // If parent string is not empty string. - if (*parent != '\0') { - // Compare 'parent/' . - if (!(next = ImageStrings::starts_with(next, parent))) return false; - if (*next++ != '/') return false; - } - // Get base name string. - const char* base = location.get_attribute(ImageLocation::ATTRIBUTE_BASE, strings); - // Compare with basne name. - if (!(next = ImageStrings::starts_with(next, base))) return false; - // Get extension string. - const char* extension = location.get_attribute(ImageLocation::ATTRIBUTE_EXTENSION, strings); - // If extension is not empty. - if (*extension != '\0') { - // Compare '.extension' . - if (*next++ != '.') return false; - if (!(next = ImageStrings::starts_with(next, extension))) return false; - } - // True only if complete match and no more characters. - return *next == '\0'; + // Manage the image string table. + ImageStrings strings(_string_bytes, _header.strings_size(_endian)); + // Position to first character of the path string. + const char* next = path; + // Get module name string. + const char* module = location.get_attribute(ImageLocation::ATTRIBUTE_MODULE, strings); + // If module string is not empty. + if (*module != '\0') { + // Compare '/module/' . + if (*next++ != '/') return false; + if (!(next = ImageStrings::starts_with(next, module))) return false; + if (*next++ != '/') return false; + } + // Get parent (package) string + const char* parent = location.get_attribute(ImageLocation::ATTRIBUTE_PARENT, strings); + // If parent string is not empty string. + if (*parent != '\0') { + // Compare 'parent/' . + if (!(next = ImageStrings::starts_with(next, parent))) return false; + if (*next++ != '/') return false; + } + // Get base name string. + const char* base = location.get_attribute(ImageLocation::ATTRIBUTE_BASE, strings); + // Compare with basne name. + if (!(next = ImageStrings::starts_with(next, base))) return false; + // Get extension string. + const char* extension = location.get_attribute(ImageLocation::ATTRIBUTE_EXTENSION, strings); + // If extension is not empty. + if (*extension != '\0') { + // Compare '.extension' . + if (*next++ != '.') return false; + if (!(next = ImageStrings::starts_with(next, extension))) return false; + } + // True only if complete match and no more characters. + return *next == '\0'; } // Return the resource for the supplied location offset. void ImageFileReader::get_resource(u4 offset, u1* uncompressed_data) const { - // Get address of first byte of location attribute stream. - u1* data = get_location_offset_data(offset); - // Expand location attributes. - ImageLocation location(data); - // Read the data - get_resource(location, uncompressed_data); + // Get address of first byte of location attribute stream. + u1* data = get_location_offset_data(offset); + // Expand location attributes. + ImageLocation location(data); + // Read the data + get_resource(location, uncompressed_data); } // Return the resource for the supplied location. void ImageFileReader::get_resource(ImageLocation& location, u1* uncompressed_data) const { - // Retrieve the byte offset and size of the resource. - u8 offset = location.get_attribute(ImageLocation::ATTRIBUTE_OFFSET); - u8 uncompressed_size = location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED); - u8 compressed_size = location.get_attribute(ImageLocation::ATTRIBUTE_COMPRESSED); - // If the resource is compressed. - if (compressed_size != 0) { - u1* compressed_data; - // If not memory mapped read in bytes. - if (!MemoryMapImage) { - // Allocate buffer for compression. - compressed_data = new u1[(u4)compressed_size]; - // Read bytes from offset beyond the image index. - bool is_read = read_at(compressed_data, compressed_size, _index_size + offset); - assert(is_read && "error reading from image or short read"); + // Retrieve the byte offset and size of the resource. + u8 offset = location.get_attribute(ImageLocation::ATTRIBUTE_OFFSET); + u8 uncompressed_size = location.get_attribute(ImageLocation::ATTRIBUTE_UNCOMPRESSED); + u8 compressed_size = location.get_attribute(ImageLocation::ATTRIBUTE_COMPRESSED); + // If the resource is compressed. + if (compressed_size != 0) { + u1* compressed_data; + // If not memory mapped read in bytes. + if (!MemoryMapImage) { + // Allocate buffer for compression. + compressed_data = new u1[(u4)compressed_size]; + // Read bytes from offset beyond the image index. + bool is_read = read_at(compressed_data, compressed_size, _index_size + offset); + assert(is_read && "error reading from image or short read"); + } else { + compressed_data = get_data_address() + offset; + } + // Get image string table. + const ImageStrings strings = get_strings(); + // Decompress resource. + ImageDecompressor::decompress_resource(compressed_data, uncompressed_data, (u4)uncompressed_size, + &strings); + // If not memory mapped then release temporary buffer. + if (!MemoryMapImage) { + delete compressed_data; + } } else { - compressed_data = get_data_address() + offset; + // Read bytes from offset beyond the image index. + bool is_read = read_at(uncompressed_data, uncompressed_size, _index_size + offset); + assert(is_read && "error reading from image or short read"); } - // Get image string table. - const ImageStrings strings = get_strings(); - // Decompress resource. - ImageDecompressor::decompress_resource(compressed_data, uncompressed_data, (u4)uncompressed_size, - &strings); - // If not memory mapped then release temporary buffer. - if (!MemoryMapImage) { - delete compressed_data; - } - } else { - // Read bytes from offset beyond the image index. - bool is_read = read_at(uncompressed_data, uncompressed_size, _index_size + offset); - assert(is_read && "error reading from image or short read"); - } } // Return the ImageModuleData for this image ImageModuleData * ImageFileReader::get_image_module_data() { - return module_data; + return module_data; }
--- a/src/java.base/share/native/libjimage/imageFile.hpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/imageFile.hpp Tue Sep 22 11:01:54 2015 -0700 @@ -1,14 +1,16 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #ifndef LIBJIMAGE_IMAGEFILE_HPP @@ -145,52 +146,52 @@ // Manage image file string table. class ImageStrings { private: - u1* _data; // Data bytes for strings. - u4 _size; // Number of bytes in the string table. + u1* _data; // Data bytes for strings. + u4 _size; // Number of bytes in the string table. public: - enum { - // Not found result from find routine. - NOT_FOUND = -1, - // Prime used to generate hash for Perfect Hashing. - HASH_MULTIPLIER = 0x01000193 - }; + enum { + // Not found result from find routine. + NOT_FOUND = -1, + // Prime used to generate hash for Perfect Hashing. + HASH_MULTIPLIER = 0x01000193 + }; - ImageStrings(u1* data, u4 size) : _data(data), _size(size) {} + ImageStrings(u1* data, u4 size) : _data(data), _size(size) {} - // Return the UTF-8 string beginning at offset. - inline const char* get(u4 offset) const { - assert(offset < _size && "offset exceeds string table size"); - return (const char*)(_data + offset); - } + // Return the UTF-8 string beginning at offset. + inline const char* get(u4 offset) const { + assert(offset < _size && "offset exceeds string table size"); + return (const char*)(_data + offset); + } - // Compute the Perfect Hashing hash code for the supplied UTF-8 string. - inline static u4 hash_code(const char* string) { - return hash_code(string, HASH_MULTIPLIER); - } + // Compute the Perfect Hashing hash code for the supplied UTF-8 string. + inline static u4 hash_code(const char* string) { + return hash_code(string, HASH_MULTIPLIER); + } - // Compute the Perfect Hashing hash code for the supplied string, starting at seed. - static s4 hash_code(const char* string, s4 seed); + // Compute the Perfect Hashing hash code for the supplied string, starting at seed. + static s4 hash_code(const char* string, s4 seed); - // Match up a string in a perfect hash table. Result still needs validation - // for precise match. - static s4 find(Endian* endian, const char* name, s4* redirect, u4 length); + // Match up a string in a perfect hash table. Result still needs validation + // for precise match. + static s4 find(Endian* endian, const char* name, s4* redirect, u4 length); - // Test to see if UTF-8 string begins with the start UTF-8 string. If so, - // return non-NULL address of remaining portion of string. Otherwise, return - // NULL. Used to test sections of a path without copying from image string - // table. - static const char* starts_with(const char* string, const char* start); + // Test to see if UTF-8 string begins with the start UTF-8 string. If so, + // return non-NULL address of remaining portion of string. Otherwise, return + // NULL. Used to test sections of a path without copying from image string + // table. + static const char* starts_with(const char* string, const char* start); - // Test to see if UTF-8 string begins with start char. If so, return non-NULL - // address of remaining portion of string. Otherwise, return NULL. Used - // to test a character of a path without copying. - inline static const char* starts_with(const char* string, const char ch) { - return *string == ch ? string + 1 : NULL; - } + // Test to see if UTF-8 string begins with start char. If so, return non-NULL + // address of remaining portion of string. Otherwise, return NULL. Used + // to test a character of a path without copying. + inline static const char* starts_with(const char* string, const char ch) { + return *string == ch ? string + 1 : NULL; + } }; -// Manage image file location attribute data. Within an image, a location's -// attributes are compressed into a stream of bytes. An attribute stream is +// Manage image file location attribute data. Within an image, a location's +// attributes are compressed into a stream of bytes. An attribute stream is // composed of individual attribute sequences. Each attribute sequence begins with // a header byte containing the attribute 'kind' (upper 5 bits of header) and the // 'length' less 1 (lower 3 bits of header) of bytes that follow containing the @@ -208,91 +209,91 @@ // // Notes: // - Even though ATTRIBUTE_END is used to mark the end of the attribute stream, -// streams will contain zero byte values to represent lesser significant bits. -// Thus, detecting a zero byte is not sufficient to detect the end of an attribute -// stream. +// streams will contain zero byte values to represent lesser significant bits. +// Thus, detecting a zero byte is not sufficient to detect the end of an attribute +// stream. // - ATTRIBUTE_OFFSET represents the number of bytes from the beginning of the region -// storing the resources. Thus, in an image this represents the number of bytes -// after the index. +// storing the resources. Thus, in an image this represents the number of bytes +// after the index. // - Currently, compressed resources are represented by having a non-zero -// ATTRIBUTE_COMPRESSED value. This represents the number of bytes stored in the -// image, and the value of ATTRIBUTE_UNCOMPRESSED represents number of bytes of the -// inflated resource in memory. If the ATTRIBUTE_COMPRESSED is zero then the value -// of ATTRIBUTE_UNCOMPRESSED represents both the number of bytes in the image and -// in memory. In the future, additional compression techniques will be used and -// represented differently. +// ATTRIBUTE_COMPRESSED value. This represents the number of bytes stored in the +// image, and the value of ATTRIBUTE_UNCOMPRESSED represents number of bytes of the +// inflated resource in memory. If the ATTRIBUTE_COMPRESSED is zero then the value +// of ATTRIBUTE_UNCOMPRESSED represents both the number of bytes in the image and +// in memory. In the future, additional compression techniques will be used and +// represented differently. // - Package strings include trailing slash and extensions include prefix period. // class ImageLocation { public: - enum { - ATTRIBUTE_END, // End of attribute stream marker - ATTRIBUTE_MODULE, // String table offset of module name - ATTRIBUTE_PARENT, // String table offset of resource path parent - ATTRIBUTE_BASE, // String table offset of resource path base - ATTRIBUTE_EXTENSION, // String table offset of resource path extension - ATTRIBUTE_OFFSET, // Container byte offset of resource - ATTRIBUTE_COMPRESSED, // In image byte size of the compressed resource - ATTRIBUTE_UNCOMPRESSED, // In memory byte size of the uncompressed resource - ATTRIBUTE_COUNT // Number of attribute kinds - }; + enum { + ATTRIBUTE_END, // End of attribute stream marker + ATTRIBUTE_MODULE, // String table offset of module name + ATTRIBUTE_PARENT, // String table offset of resource path parent + ATTRIBUTE_BASE, // String table offset of resource path base + ATTRIBUTE_EXTENSION, // String table offset of resource path extension + ATTRIBUTE_OFFSET, // Container byte offset of resource + ATTRIBUTE_COMPRESSED, // In image byte size of the compressed resource + ATTRIBUTE_UNCOMPRESSED, // In memory byte size of the uncompressed resource + ATTRIBUTE_COUNT // Number of attribute kinds + }; private: - // Values of inflated attributes. - u8 _attributes[ATTRIBUTE_COUNT]; + // Values of inflated attributes. + u8 _attributes[ATTRIBUTE_COUNT]; - // Return the attribute value number of bytes. - inline static u1 attribute_length(u1 data) { - return (data & 0x7) + 1; - } + // Return the attribute value number of bytes. + inline static u1 attribute_length(u1 data) { + return (data & 0x7) + 1; + } - // Return the attribute kind. - inline static u1 attribute_kind(u1 data) { - u1 kind = data >> 3; - assert(kind < ATTRIBUTE_COUNT && "invalid attribute kind"); - return kind; - } + // Return the attribute kind. + inline static u1 attribute_kind(u1 data) { + u1 kind = data >> 3; + assert(kind < ATTRIBUTE_COUNT && "invalid attribute kind"); + return kind; + } - // Return the attribute length. - inline static u8 attribute_value(u1* data, u1 n) { - assert(0 < n && n <= 8 && "invalid attribute value length"); - u8 value = 0; - // Most significant bytes first. - for (u1 i = 0; i < n; i++) { - value <<= 8; - value |= data[i]; + // Return the attribute length. + inline static u8 attribute_value(u1* data, u1 n) { + assert(0 < n && n <= 8 && "invalid attribute value length"); + u8 value = 0; + // Most significant bytes first. + for (u1 i = 0; i < n; i++) { + value <<= 8; + value |= data[i]; + } + return value; } - return value; - } public: - ImageLocation() { - clear_data(); - } + ImageLocation() { + clear_data(); + } - ImageLocation(u1* data) { - clear_data(); - set_data(data); - } + ImageLocation(u1* data) { + clear_data(); + set_data(data); + } - // Inflates the attribute stream into individual values stored in the long - // array _attributes. This allows an attribute value to be quickly accessed by - // direct indexing. Unspecified values default to zero. - void set_data(u1* data); + // Inflates the attribute stream into individual values stored in the long + // array _attributes. This allows an attribute value to be quickly accessed by + // direct indexing. Unspecified values default to zero. + void set_data(u1* data); - // Zero all attribute values. - void clear_data(); + // Zero all attribute values. + void clear_data(); - // Retrieve an attribute value from the inflated array. - inline u8 get_attribute(u1 kind) const { - assert(ATTRIBUTE_END < kind && kind < ATTRIBUTE_COUNT && "invalid attribute kind"); - return _attributes[kind]; - } + // Retrieve an attribute value from the inflated array. + inline u8 get_attribute(u1 kind) const { + assert(ATTRIBUTE_END < kind && kind < ATTRIBUTE_COUNT && "invalid attribute kind"); + return _attributes[kind]; + } - // Retrieve an attribute string value from the inflated array. - inline const char* get_attribute(u4 kind, const ImageStrings& strings) const { - return strings.get((u4)get_attribute(kind)); - } + // Retrieve an attribute string value from the inflated array. + inline const char* get_attribute(u4 kind, const ImageStrings& strings) const { + return strings.get((u4)get_attribute(kind)); + } }; // @@ -306,133 +307,133 @@ // padding for hash table lookup.) // // Format: -// Count of package to module entries -// Count of module to package entries -// Perfect Hash redirect table[Count of package to module entries] -// Package to module entries[Count of package to module entries] -// Offset to package name in string table -// Offset to module name in string table -// Perfect Hash redirect table[Count of module to package entries] -// Module to package entries[Count of module to package entries] -// Offset to module name in string table -// Count of packages in module -// Offset to first package in packages table -// Packages[] -// Offset to package name in string table +// Count of package to module entries +// Count of module to package entries +// Perfect Hash redirect table[Count of package to module entries] +// Package to module entries[Count of package to module entries] +// Offset to package name in string table +// Offset to module name in string table +// Perfect Hash redirect table[Count of module to package entries] +// Module to package entries[Count of module to package entries] +// Offset to module name in string table +// Count of packages in module +// Offset to first package in packages table +// Packages[] +// Offset to package name in string table // // Manage the image module meta data. class ImageModuleData { - class Header { - private: - u4 _ptm_count; // Count of package to module entries - u4 _mtp_count; // Count of module to package entries - public: - inline u4 ptm_count(Endian* endian) const { return endian->get(_ptm_count); } - inline u4 mtp_count(Endian* endian) const { return endian->get(_mtp_count); } - }; + class Header { + private: + u4 _ptm_count; // Count of package to module entries + u4 _mtp_count; // Count of module to package entries + public: + inline u4 ptm_count(Endian* endian) const { return endian->get(_ptm_count); } + inline u4 mtp_count(Endian* endian) const { return endian->get(_mtp_count); } + }; - // Hashtable entry - class HashData { - private: - u4 _name_offset; // Name offset in string table - public: - inline s4 name_offset(Endian* endian) const { return endian->get(_name_offset); } - }; + // Hashtable entry + class HashData { + private: + u4 _name_offset; // Name offset in string table + public: + inline s4 name_offset(Endian* endian) const { return endian->get(_name_offset); } + }; - // Package to module hashtable entry - class PTMData : public HashData { - private: - u4 _module_name_offset; // Module name offset in string table - public: - inline s4 module_name_offset(Endian* endian) const { return endian->get(_module_name_offset); } - }; + // Package to module hashtable entry + class PTMData : public HashData { + private: + u4 _module_name_offset; // Module name offset in string table + public: + inline s4 module_name_offset(Endian* endian) const { return endian->get(_module_name_offset); } + }; - // Module to package hashtable entry - class MTPData : public HashData { - private: - u4 _package_count; // Number of packages in module - u4 _package_offset; // Offset in package list - public: - inline u4 package_count(Endian* endian) const { return endian->get(_package_count); } - inline u4 package_offset(Endian* endian) const { return endian->get(_package_offset); } - }; + // Module to package hashtable entry + class MTPData : public HashData { + private: + u4 _package_count; // Number of packages in module + u4 _package_offset; // Offset in package list + public: + inline u4 package_count(Endian* endian) const { return endian->get(_package_count); } + inline u4 package_offset(Endian* endian) const { return endian->get(_package_offset); } + }; - const ImageFileReader* _image_file; // Source image file - Endian* _endian; // Endian handler - ImageStrings _strings; // Image file strings - u1* _data; // Module data resource data - u8 _data_size; // Size of resource data - Header* _header; // Module data header - s4* _ptm_redirect; // Package to module hashtable redirect - PTMData* _ptm_data; // Package to module data - s4* _mtp_redirect; // Module to packages hashtable redirect - MTPData* _mtp_data; // Module to packages data - s4* _mtp_packages; // Package data (name offsets) + const ImageFileReader* _image_file; // Source image file + Endian* _endian; // Endian handler + ImageStrings _strings; // Image file strings + u1* _data; // Module data resource data + u8 _data_size; // Size of resource data + Header* _header; // Module data header + s4* _ptm_redirect; // Package to module hashtable redirect + PTMData* _ptm_data; // Package to module data + s4* _mtp_redirect; // Module to packages hashtable redirect + MTPData* _mtp_data; // Module to packages data + s4* _mtp_packages; // Package data (name offsets) - // Return a string from the string table. - inline const char* get_string(u4 offset) { - return _strings.get(offset); - } + // Return a string from the string table. + inline const char* get_string(u4 offset) { + return _strings.get(offset); + } - inline u4 mtp_package(u4 index) { - return _endian->get(_mtp_packages[index]); - } + inline u4 mtp_package(u4 index) { + return _endian->get(_mtp_packages[index]); + } public: - ImageModuleData(const ImageFileReader* image_file, const char* module_data_name); - ~ImageModuleData(); + ImageModuleData(const ImageFileReader* image_file, const char* module_data_name); + ~ImageModuleData(); - // Return the name of the module data resource. - static void module_data_name(char* buffer, const char* image_file_name); + // Return the name of the module data resource. + static void module_data_name(char* buffer, const char* image_file_name); - // Return the module in which a package resides. Returns NULL if not found. - const char* package_to_module(const char* package_name); + // Return the module in which a package resides. Returns NULL if not found. + const char* package_to_module(const char* package_name); - // Returns all the package names in a module in a NULL terminated array. - // Returns NULL if module not found. - const char** module_to_packages(const char* module_name); + // Returns all the package names in a module in a NULL terminated array. + // Returns NULL if module not found. + const char** module_to_packages(const char* module_name); }; // Image file header, starting at offset 0. class ImageHeader { private: - u4 _magic; // Image file marker - u4 _version; // Image file major version number - u4 _flags; // Image file flags - u4 _resource_count; // Number of resources in file - u4 _table_length; // Number of slots in index tables - u4 _locations_size; // Number of bytes in attribute table - u4 _strings_size; // Number of bytes in string table + u4 _magic; // Image file marker + u4 _version; // Image file major version number + u4 _flags; // Image file flags + u4 _resource_count; // Number of resources in file + u4 _table_length; // Number of slots in index tables + u4 _locations_size; // Number of bytes in attribute table + u4 _strings_size; // Number of bytes in string table public: - u4 magic() const { return _magic; } - u4 magic(Endian* endian) const { return endian->get(_magic); } - void set_magic(Endian* endian, u4 magic) { return endian->set(_magic, magic); } + u4 magic() const { return _magic; } + u4 magic(Endian* endian) const { return endian->get(_magic); } + void set_magic(Endian* endian, u4 magic) { return endian->set(_magic, magic); } - u4 major_version(Endian* endian) const { return endian->get(_version) >> 16; } - u4 minor_version(Endian* endian) const { return endian->get(_version) & 0xFFFF; } - void set_version(Endian* endian, u4 major_version, u4 minor_version) { - return endian->set(_version, major_version << 16 | minor_version); - } + u4 major_version(Endian* endian) const { return endian->get(_version) >> 16; } + u4 minor_version(Endian* endian) const { return endian->get(_version) & 0xFFFF; } + void set_version(Endian* endian, u4 major_version, u4 minor_version) { + return endian->set(_version, major_version << 16 | minor_version); + } - u4 flags(Endian* endian) const { return endian->get(_flags); } - void set_flags(Endian* endian, u4 value) { return endian->set(_flags, value); } + u4 flags(Endian* endian) const { return endian->get(_flags); } + void set_flags(Endian* endian, u4 value) { return endian->set(_flags, value); } - u4 resource_count(Endian* endian) const { return endian->get(_resource_count); } - void set_resource_count(Endian* endian, u4 count) { return endian->set(_resource_count, count); } + u4 resource_count(Endian* endian) const { return endian->get(_resource_count); } + void set_resource_count(Endian* endian, u4 count) { return endian->set(_resource_count, count); } - u4 table_length(Endian* endian) const { return endian->get(_table_length); } - void set_table_length(Endian* endian, u4 count) { return endian->set(_table_length, count); } + u4 table_length(Endian* endian) const { return endian->get(_table_length); } + void set_table_length(Endian* endian, u4 count) { return endian->set(_table_length, count); } - u4 locations_size(Endian* endian) const { return endian->get(_locations_size); } - void set_locations_size(Endian* endian, u4 size) { return endian->set(_locations_size, size); } + u4 locations_size(Endian* endian) const { return endian->get(_locations_size); } + void set_locations_size(Endian* endian, u4 size) { return endian->set(_locations_size, size); } - u4 strings_size(Endian* endian) const { return endian->get(_strings_size); } - void set_strings_size(Endian* endian, u4 size) { return endian->set(_strings_size, size); } + u4 strings_size(Endian* endian) const { return endian->get(_strings_size); } + void set_strings_size(Endian* endian, u4 size) { return endian->set(_strings_size, size); } }; -// Max path length limit independent of platform. Windows max path is 1024, -// other platforms use 4096. The JCK fails several tests when 1024 is used. +// Max path length limit independent of platform. Windows max path is 1024, +// other platforms use 4096. The JCK fails several tests when 1024 is used. #define IMAGE_MAX_PATH 4096 class ImageFileReader; @@ -441,29 +442,29 @@ // to share an open image. class ImageFileReaderTable { private: - const static u4 _growth = 8; // Growth rate of the table - u4 _count; // Number of entries in the table - u4 _max; // Maximum number of entries allocated - ImageFileReader** _table; // Growable array of entries + const static u4 _growth = 8; // Growth rate of the table + u4 _count; // Number of entries in the table + u4 _max; // Maximum number of entries allocated + ImageFileReader** _table; // Growable array of entries public: - ImageFileReaderTable(); - ~ImageFileReaderTable(); + ImageFileReaderTable(); + ~ImageFileReaderTable(); - // Return the number of entries. - inline u4 count() { return _count; } + // Return the number of entries. + inline u4 count() { return _count; } - // Return the ith entry from the table. - inline ImageFileReader* get(u4 i) { return _table[i]; } + // Return the ith entry from the table. + inline ImageFileReader* get(u4 i) { return _table[i]; } - // Add a new image entry to the table. - void add(ImageFileReader* image); + // Add a new image entry to the table. + void add(ImageFileReader* image); - // Remove an image entry from the table. - void remove(ImageFileReader* image); + // Remove an image entry from the table. + void remove(ImageFileReader* image); - // Determine if image entry is in table. - bool contains(ImageFileReader* image); + // Determine if image entry is in table. + bool contains(ImageFileReader* image); }; // Manage the image file. @@ -473,176 +474,176 @@ // index is then memory mapped to allow load on demand and sharing. The // -XX:+MemoryMapImage flag determines if the entire file is loaded (server use.) // An image can be used by Hotspot and multiple reference points in the JDK, thus -// it is desirable to share a reader. To accomodate sharing, a share table is +// it is desirable to share a reader. To accomodate sharing, a share table is // defined (see ImageFileReaderTable in imageFile.cpp) To track the number of // uses, ImageFileReader keeps a use count (_use). Use is incremented when -// 'opened' by reference point and decremented when 'closed'. Use of zero +// 'opened' by reference point and decremented when 'closed'. Use of zero // leads the ImageFileReader to be actually closed and discarded. class ImageFileReader { private: - // Manage a number of image files such that an image can be shared across - // multiple uses (ex. loader.) - static ImageFileReaderTable _reader_table; + // Manage a number of image files such that an image can be shared across + // multiple uses (ex. loader.) + static ImageFileReaderTable _reader_table; - char* _name; // Name of image - s4 _use; // Use count - int _fd; // File descriptor - Endian* _endian; // Endian handler - u8 _file_size; // File size in bytes - ImageHeader _header; // Image header - size_t _index_size; // Total size of index - u1* _index_data; // Raw index data - s4* _redirect_table; // Perfect hash redirect table - u4* _offsets_table; // Location offset table - u1* _location_bytes; // Location attributes - u1* _string_bytes; // String table - ImageModuleData *module_data; // The ImageModuleData for this image + char* _name; // Name of image + s4 _use; // Use count + int _fd; // File descriptor + Endian* _endian; // Endian handler + u8 _file_size; // File size in bytes + ImageHeader _header; // Image header + size_t _index_size; // Total size of index + u1* _index_data; // Raw index data + s4* _redirect_table; // Perfect hash redirect table + u4* _offsets_table; // Location offset table + u1* _location_bytes; // Location attributes + u1* _string_bytes; // String table + ImageModuleData *module_data; // The ImageModuleData for this image - ImageFileReader(const char* name, bool big_endian); - ~ImageFileReader(); + ImageFileReader(const char* name, bool big_endian); + ~ImageFileReader(); - // Compute number of bytes in image file index. - inline size_t index_size() { - return sizeof(ImageHeader) + - table_length() * sizeof(u4) * 2 + locations_size() + strings_size(); - } + // Compute number of bytes in image file index. + inline size_t index_size() { + return sizeof(ImageHeader) + + table_length() * sizeof(u4) * 2 + locations_size() + strings_size(); + } public: - enum { - // Image file marker. - IMAGE_MAGIC = 0xCAFEDADA, - // Endian inverted Image file marker. - IMAGE_MAGIC_INVERT = 0xDADAFECA, - // Image file major version number. - MAJOR_VERSION = 1, - // Image file minor version number. - MINOR_VERSION = 0 - }; + enum { + // Image file marker. + IMAGE_MAGIC = 0xCAFEDADA, + // Endian inverted Image file marker. + IMAGE_MAGIC_INVERT = 0xDADAFECA, + // Image file major version number. + MAJOR_VERSION = 1, + // Image file minor version number. + MINOR_VERSION = 0 + }; - // Open an image file, reuse structure if file already open. - static ImageFileReader* open(const char* name, bool big_endian = Endian::is_big_endian()); + // Open an image file, reuse structure if file already open. + static ImageFileReader* open(const char* name, bool big_endian = Endian::is_big_endian()); - // Close an image file if the file is not in use elsewhere. - static void close(ImageFileReader *reader); + // Close an image file if the file is not in use elsewhere. + static void close(ImageFileReader *reader); - // Return an id for the specifed ImageFileReader. - static u8 readerToID(ImageFileReader *reader); + // Return an id for the specifed ImageFileReader. + static u8 readerToID(ImageFileReader *reader); - // Validate the image id. - static bool idCheck(u8 id); + // Validate the image id. + static bool idCheck(u8 id); - // Return an id for the specifed ImageFileReader. - static ImageFileReader* idToReader(u8 id); + // Return an id for the specifed ImageFileReader. + static ImageFileReader* idToReader(u8 id); - // Open image file for read access. - bool open(); + // Open image file for read access. + bool open(); - // Close image file. - void close(); + // Close image file. + void close(); - // Read directly from the file. - bool read_at(u1* data, u8 size, u8 offset) const; + // Read directly from the file. + bool read_at(u1* data, u8 size, u8 offset) const; - inline Endian* endian() const { return _endian; } + inline Endian* endian() const { return _endian; } - // Retrieve name of image file. - inline const char* name() const { - return _name; - } + // Retrieve name of image file. + inline const char* name() const { + return _name; + } - // Retrieve size of image file. - inline u8 file_size() const { - return _file_size; - } + // Retrieve size of image file. + inline u8 file_size() const { + return _file_size; + } - // Return first address of index data. - inline u1* get_index_address() const { - return _index_data; - } + // Return first address of index data. + inline u1* get_index_address() const { + return _index_data; + } - // Return first address of resource data. - inline u1* get_data_address() const { - return _index_data + _index_size; - } + // Return first address of resource data. + inline u1* get_data_address() const { + return _index_data + _index_size; + } - // Get the size of the index data. - size_t get_index_size() const { - return _index_size; - } + // Get the size of the index data. + size_t get_index_size() const { + return _index_size; + } - inline u4 table_length() const { - return _header.table_length(_endian); - } + inline u4 table_length() const { + return _header.table_length(_endian); + } - inline u4 locations_size() const { - return _header.locations_size(_endian); - } + inline u4 locations_size() const { + return _header.locations_size(_endian); + } - inline u4 strings_size()const { - return _header.strings_size(_endian); - } + inline u4 strings_size()const { + return _header.strings_size(_endian); + } - inline u4* offsets_table() const { - return _offsets_table; - } + inline u4* offsets_table() const { + return _offsets_table; + } - // Increment use count. - inline void inc_use() { - _use++; - } + // Increment use count. + inline void inc_use() { + _use++; + } - // Decrement use count. - inline bool dec_use() { - return --_use == 0; - } + // Decrement use count. + inline bool dec_use() { + return --_use == 0; + } - // Return a string table accessor. - inline const ImageStrings get_strings() const { - return ImageStrings(_string_bytes, _header.strings_size(_endian)); - } + // Return a string table accessor. + inline const ImageStrings get_strings() const { + return ImageStrings(_string_bytes, _header.strings_size(_endian)); + } - // Return location attribute stream at offset. - inline u1* get_location_offset_data(u4 offset) const { - assert((u4)offset < _header.locations_size(_endian) && - "offset exceeds location attributes size"); - return offset != 0 ? _location_bytes + offset : NULL; - } + // Return location attribute stream at offset. + inline u1* get_location_offset_data(u4 offset) const { + assert((u4)offset < _header.locations_size(_endian) && + "offset exceeds location attributes size"); + return offset != 0 ? _location_bytes + offset : NULL; + } - // Return location attribute stream for location i. - inline u1* get_location_data(u4 index) const { - return get_location_offset_data(get_location_offset(index)); - } + // Return location attribute stream for location i. + inline u1* get_location_data(u4 index) const { + return get_location_offset_data(get_location_offset(index)); + } - // Return the location offset for index. - inline u4 get_location_offset(u4 index) const { - assert((u4)index < _header.table_length(_endian) && - "index exceeds location count"); - return _endian->get(_offsets_table[index]); - } + // Return the location offset for index. + inline u4 get_location_offset(u4 index) const { + assert((u4)index < _header.table_length(_endian) && + "index exceeds location count"); + return _endian->get(_offsets_table[index]); + } - // Find the location attributes associated with the path. Returns true if - // the location is found, false otherwise. - bool find_location(const char* path, ImageLocation& location) const; + // Find the location attributes associated with the path. Returns true if + // the location is found, false otherwise. + bool find_location(const char* path, ImageLocation& location) const; - // Find the location index and size associated with the path. - // Returns the location index and size if the location is found, - // ImageFileReader::NOT_FOUND otherwise. - u4 find_location_index(const char* path, u8 *size) const; + // Find the location index and size associated with the path. + // Returns the location index and size if the location is found, + // ImageFileReader::NOT_FOUND otherwise. + u4 find_location_index(const char* path, u8 *size) const; - // Assemble the location path. - void location_path(ImageLocation& location, char* path, size_t max) const; + // Assemble the location path. + void location_path(ImageLocation& location, char* path, size_t max) const; - // Verify that a found location matches the supplied path. - bool verify_location(ImageLocation& location, const char* path) const; + // Verify that a found location matches the supplied path. + bool verify_location(ImageLocation& location, const char* path) const; - // Return the resource for the supplied location index. - void get_resource(u4 index, u1* uncompressed_data) const; + // Return the resource for the supplied location index. + void get_resource(u4 index, u1* uncompressed_data) const; - // Return the resource for the supplied path. - void get_resource(ImageLocation& location, u1* uncompressed_data) const; + // Return the resource for the supplied path. + void get_resource(ImageLocation& location, u1* uncompressed_data) const; - // Return the ImageModuleData for this image - ImageModuleData * get_image_module_data(); + // Return the ImageModuleData for this image + ImageModuleData * get_image_module_data(); }; #endif // LIBJIMAGE_IMAGEFILE_HPP
--- a/src/java.base/share/native/libjimage/inttypes.hpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/inttypes.hpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,7 +4,9 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #ifndef LIBJIMAGE_INTTYPES_HPP
--- a/src/java.base/share/native/libjimage/jimage.cpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/jimage.cpp Tue Sep 22 11:01:54 2015 -0700 @@ -1,10 +1,12 @@ /* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #include <string.h> @@ -97,7 +98,8 @@ * * Ex. * jlong size; - * JImageLocationRef location = (*JImageFindResource)(image, "java.base", "9.0", "java/lang/String.class", &size); + * JImageLocationRef location = (*JImageFindResource)(image, + * "java.base", "9.0", "java/lang/String.class", &size); */ extern "C" JImageLocationRef JIMAGE_FindResource(JImageFile* image, const char* module_name, const char* version, const char* name, @@ -129,7 +131,8 @@ * * Ex. * jlong size; - * JImageLocationRef* location = (*JImageFindResource)(image, "java.base", "9.0", "java/lang/String.class", &size); + * JImageLocationRef location = (*JImageFindResource)(image, + * "java.base", "9.0", "java/lang/String.class", &size); * char* buffer = new char[size]; * (*JImageGetResource)(image, location, buffer, size); */ @@ -148,7 +151,8 @@ * required. All strings are utf-8, zero byte terminated.file. * * Ex. - * bool ctw_visitor(JImageFile* jimage, const char* module_name, const char* version, const char* package, const char* name, const char* extension, void* arg) { + * bool ctw_visitor(JImageFile* jimage, const char* module_name, const char* version, + * const char* package, const char* name, const char* extension, void* arg) { * if (strcmp(extension, “class”) == 0) { * char path[JIMAGE_MAX_PATH]; * Thread* THREAD = Thread::current();
--- a/src/java.base/share/native/libjimage/jimage.hpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/jimage.hpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,7 +4,9 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #include "jni.h" @@ -111,7 +112,8 @@ * * Ex. * jlong size; - * JImageLocationRef location = (*JImageFindResource)(image, "java.base", "9.0", "java/lang/String.class", &size); + * JImageLocationRef location = (*JImageFindResource)(image, + * "java.base", "9.0", "java/lang/String.class", &size); */ extern "C" JImageLocationRef JIMAGE_FindResource(JImageFile* jimage, const char* module_name, const char* version, const char* name, @@ -132,7 +134,8 @@ * * Ex. * jlong size; - * JImageLocationRef location = (*JImageFindResource)(image, "java.base", "9.0", "java/lang/String.class", &size); + * JImageLocationRef location = (*JImageFindResource)(image, + * "java.base", "9.0", "java/lang/String.class", &size); * char* buffer = new char[size]; * (*JImageGetResource)(image, location, buffer, size); */ @@ -152,7 +155,8 @@ * required. All strings are utf-8, zero byte terminated.file. * * Ex. - * bool ctw_visitor(JImageFile* jimage, const char* module_name, const char* version, const char* package, const char* name, const char* extension, void* arg) { + * bool ctw_visitor(JImageFile* jimage, const char* module_name, const char* version, + * const char* package, const char* name, const char* extension, void* arg) { * if (strcmp(extension, “class”) == 0) { * char path[JIMAGE_MAX_PATH]; * Thread* THREAD = Thread::current();
--- a/src/java.base/share/native/libjimage/osSupport.hpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/share/native/libjimage/osSupport.hpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,7 +4,9 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #ifndef LIBJIMAGE_OSSUPPORT_HPP
--- a/src/java.base/unix/native/libjimage/osSupport_unix.cpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/unix/native/libjimage/osSupport_unix.cpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,7 +4,9 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -19,10 +21,8 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ - #include <sys/types.h> #include <sys/stat.h> #include <sys/mman.h>
--- a/src/java.base/windows/native/libjimage/osSupport_windows.cpp Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.base/windows/native/libjimage/osSupport_windows.cpp Tue Sep 22 11:01:54 2015 -0700 @@ -4,7 +4,9 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -19,7 +21,6 @@ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. - * */ #include <windows.h>
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaCaret.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaCaret.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -36,19 +36,27 @@ import javax.swing.text.*; @SuppressWarnings("serial") // Superclass is not serializable across versions -public class AquaCaret extends DefaultCaret implements UIResource, PropertyChangeListener { - final boolean isMultiLineEditor; - final JTextComponent c; +public class AquaCaret extends DefaultCaret + implements UIResource, PropertyChangeListener { - boolean mFocused = false; + private boolean isMultiLineEditor; + private boolean mFocused = false; + private boolean fPainting = false; - public AquaCaret(final Window inParentWindow, final JTextComponent inComponent) { - super(); - c = inComponent; - isMultiLineEditor = (c instanceof JTextArea || c instanceof JEditorPane); - inComponent.addPropertyChangeListener(this); + @Override + public void install(final JTextComponent c) { + super.install(c); + isMultiLineEditor = c instanceof JTextArea || c instanceof JEditorPane; + c.addPropertyChangeListener(this); } + @Override + public void deinstall(final JTextComponent c) { + c.removePropertyChangeListener(this); + super.deinstall(c); + } + + @Override protected Highlighter.HighlightPainter getSelectionPainter() { return AquaHighlighter.getInstance(); } @@ -56,11 +64,13 @@ /** * Only show the flashing caret if the selection range is zero */ + @Override public void setVisible(boolean e) { if (e) e = getDot() == getMark(); super.setVisible(e); } + @Override protected void fireStateChanged() { // If we have focus the caret should only flash if the range length is zero if (mFocused) setVisible(getComponent().isEditable()); @@ -68,6 +78,7 @@ super.fireStateChanged(); } + @Override public void propertyChange(final PropertyChangeEvent evt) { final String propertyName = evt.getPropertyName(); @@ -87,6 +98,7 @@ // --- FocusListener methods -------------------------- private boolean shouldSelectAllOnFocus = true; + @Override public void focusGained(final FocusEvent e) { final JTextComponent component = getComponent(); if (!component.isEnabled() || !component.isEditable()) { @@ -122,12 +134,13 @@ super.focusGained(e); } + @Override public void focusLost(final FocusEvent e) { mFocused = false; shouldSelectAllOnFocus = true; if (isMultiLineEditor) { setVisible(false); - c.repaint(); + getComponent().repaint(); } else { super.focusLost(e); } @@ -136,6 +149,7 @@ // This fixes the problem where when on the mac you have to ctrl left click to // get popup triggers the caret has code that only looks at button number. // see radar # 3125390 + @Override public void mousePressed(final MouseEvent e) { if (!e.isPopupTrigger()) { super.mousePressed(e); @@ -153,6 +167,7 @@ * @param r the current location of the caret * @see #paint */ + @Override protected synchronized void damage(final Rectangle r) { if (r == null || fPainting) return; @@ -182,12 +197,12 @@ repaint(); } - boolean fPainting = false; - - // See <rdar://problem/3833837> 1.4.2_05-141.3: JTextField performance with Aqua L&F - // We are getting into a circular condition with the BasicCaret paint code since it doesn't know about the fact that our - // damage routine above elminates the border. Sadly we can't easily change either one, so we will - // add a painting flag and not damage during a repaint. + // See <rdar://problem/3833837> 1.4.2_05-141.3: JTextField performance with + // Aqua L&F. We are getting into a circular condition with the BasicCaret + // paint code since it doesn't know about the fact that our damage routine + // above elminates the border. Sadly we can't easily change either one, so + // we will add a painting flag and not damage during a repaint. + @Override public void paint(final Graphics g) { if (isVisible()) { fPainting = true;
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaEditorPaneUI.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaEditorPaneUI.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -39,6 +39,7 @@ } boolean oldDragState = false; + @Override protected void installDefaults(){ super.installDefaults(); if(!GraphicsEnvironment.isHeadless()){ @@ -47,6 +48,7 @@ } } + @Override protected void uninstallDefaults(){ if(!GraphicsEnvironment.isHeadless()){ getComponent().setDragEnabled(oldDragState); @@ -55,12 +57,14 @@ } FocusListener focusListener; + @Override protected void installListeners(){ super.installListeners(); focusListener = createFocusListener(); getComponent().addFocusListener(focusListener); } + @Override protected void installKeyboardActions() { super.installKeyboardActions(); AquaKeyBindings bindings = AquaKeyBindings.instance(); @@ -69,6 +73,7 @@ bindings.installAquaUpDownActions(c); } + @Override protected void uninstallListeners(){ getComponent().removeFocusListener(focusListener); super.uninstallListeners(); @@ -78,12 +83,12 @@ return new AquaFocusHandler(); } - protected Caret createCaret(){ - final Window owningWindow = SwingUtilities.getWindowAncestor(getComponent()); - final AquaCaret returnValue = new AquaCaret(owningWindow, getComponent()); - return returnValue; + @Override + protected Caret createCaret() { + return new AquaCaret(); } + @Override protected Highlighter createHighlighter(){ return new AquaHighlighter(); }
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaImageFactory.java Tue Sep 22 11:01:54 2015 -0700 @@ -46,7 +46,7 @@ import com.apple.laf.AquaIcon.SystemIcon; import com.apple.laf.AquaUtils.RecyclableObject; import com.apple.laf.AquaUtils.RecyclableSingleton; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; import sun.awt.image.MultiResolutionCachedImage; public class AquaImageFactory {
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameUI.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaInternalFrameUI.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -66,6 +66,7 @@ protected Color fNotSelectedTextColor; AquaInternalFrameBorder fAquaBorder; + private ResizeBox resizeBox; // for button tracking boolean fMouseOverPressedButton; @@ -96,6 +97,7 @@ } /// Inherit (but be careful to check everything they call): + @Override public void installUI(final JComponent c) { // super.installUI(c); // Swing 1.1.1 has a bug in installUI - it doesn't check for null northPane frame = (JInternalFrame)c; @@ -125,12 +127,14 @@ c.setBorder(new CompoundUIBorder(fIsPallet ? paletteWindowShadow.get() : documentWindowShadow.get(), c.getBorder())); } + @Override protected void installDefaults() { super.installDefaults(); fSelectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground"); fNotSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground"); } + @Override public void setSouthPane(final JComponent c) { if (southPane != null) { frame.remove(southPane); @@ -144,6 +148,7 @@ } static final RecyclableSingleton<Icon> closeIcon = new RecyclableSingleton<Icon>() { + @Override protected Icon getInstance() { return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_CLOSE_BOX); } @@ -153,6 +158,7 @@ } static final RecyclableSingleton<Icon> minimizeIcon = new RecyclableSingleton<Icon>() { + @Override protected Icon getInstance() { return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_COLLAPSE_BOX); } @@ -162,6 +168,7 @@ } static final RecyclableSingleton<Icon> zoomIcon = new RecyclableSingleton<Icon>() { + @Override protected Icon getInstance() { return new AquaInternalFrameButtonIcon(Widget.TITLE_BAR_ZOOM_BOX); } @@ -175,6 +182,7 @@ painter.state.set(widget); } + @Override public void paintIcon(final Component c, final Graphics g, final int x, final int y) { painter.state.set(getStateFor(c)); super.paintIcon(c, g, x, y); @@ -184,28 +192,24 @@ return State.ROLLOVER; } + @Override public int getIconWidth() { return 19; } + @Override public int getIconHeight() { return 19; } } + @Override protected void installKeyboardActions() { } //$ Not Mac-ish - should we support? - protected ResizeBox resizeBox; + @Override protected void installComponents() { final JLayeredPane layeredPane = frame.getLayeredPane(); - if (resizeBox != null) { - resizeBox.removeListeners(); - layeredPane.removeComponentListener(resizeBox); - layeredPane.remove(resizeBox); - resizeBox = null; - } - resizeBox = new ResizeBox(layeredPane); resizeBox.repositionResizeBox(); @@ -218,6 +222,7 @@ } /// Inherit all the listeners - that's the main reason we subclass Basic! + @Override protected void installListeners() { fPropertyListener = new PropertyListener(); frame.addPropertyChangeListener(fPropertyListener); @@ -225,22 +230,36 @@ } // uninstallDefaults - // uninstallComponents + + @Override + protected void uninstallComponents() { + super.uninstallComponents(); + final JLayeredPane layeredPane = frame.getLayeredPane(); + resizeBox.removeListeners(); + layeredPane.removeComponentListener(resizeBox); + layeredPane.remove(resizeBox); + resizeBox = null; + } + + @Override protected void uninstallListeners() { super.uninstallListeners(); frame.removePropertyChangeListener(fPropertyListener); } + @Override protected void uninstallKeyboardActions() { } // Called when a DesktopIcon replaces an InternalFrame & vice versa //protected void replacePane(JComponent currentPane, JComponent newPane) {} + @Override protected void installMouseHandlers(final JComponent c) { c.addMouseListener(borderListener); c.addMouseMotionListener(borderListener); } + @Override protected void deinstallMouseHandlers(final JComponent c) { c.removeMouseListener(borderListener); c.removeMouseMotionListener(borderListener); @@ -256,6 +275,7 @@ return map; } + @Override public Dimension getPreferredSize(JComponent x) { Dimension preferredSize = super.getPreferredSize(x); Dimension minimumSize = frame.getMinimumSize(); @@ -268,6 +288,7 @@ return preferredSize; } + @Override public void setNorthPane(final JComponent c) { replacePane(northPane, c); northPane = c; @@ -278,6 +299,7 @@ * and adds it to the frame. * Reverse process for the <code>currentPane</code>. */ + @Override protected void replacePane(final JComponent currentPane, final JComponent newPane) { if (currentPane != null) { deinstallMouseHandlers(currentPane); @@ -290,6 +312,7 @@ } // Our "Border" listener is shared by the AquaDesktopIcon + @Override protected MouseInputAdapter createBorderListener(final JInternalFrame w) { return new AquaBorderListener(); } @@ -374,6 +397,7 @@ protected final int RESIZE_NONE = 0; private boolean discardRelease = false; + @Override public void mouseClicked(final MouseEvent e) { if (didForwardEvent(e)) return; @@ -406,6 +430,7 @@ fAquaBorder.repaintButtonArea(frame); } + @Override public void mouseReleased(final MouseEvent e) { if (didForwardEvent(e)) return; @@ -461,6 +486,7 @@ resizeDir = RESIZE_NONE; } + @Override public void mousePressed(final MouseEvent e) { if (didForwardEvent(e)) return; @@ -527,6 +553,7 @@ return true; } + @Override public void mouseDragged(final MouseEvent e) { // do not forward drags // if (didForwardEvent(e)) return; @@ -576,6 +603,7 @@ return; } + @Override public void mouseMoved(final MouseEvent e) { if (didForwardEvent(e)) return; updateRollover(e); @@ -614,7 +642,11 @@ if (hitComponent == null || hitComponent == frame) return false; final Point hitComponentPoint = SwingUtilities.convertPoint(pane, parentPoint, hitComponent); - hitComponent.dispatchEvent(new MouseEvent(hitComponent, e.getID(), e.getWhen(), e.getModifiers(), hitComponentPoint.x, hitComponentPoint.y, e.getClickCount(), e.isPopupTrigger(), e.getButton())); + hitComponent.dispatchEvent( + new MouseEvent(hitComponent, e.getID(), e.getWhen(), + e.getModifiers(), hitComponentPoint.x, + hitComponentPoint.y, e.getClickCount(), + e.isPopupTrigger(), e.getButton())); return true; } @@ -668,6 +700,7 @@ } class PropertyListener implements PropertyChangeListener { + @Override public void propertyChange(final PropertyChangeEvent e) { final String name = e.getPropertyName(); if (FRAME_TYPE.equals(name)) { @@ -704,14 +737,17 @@ } // end class PaletteListener static final InternalFrameShadow documentWindowShadow = new InternalFrameShadow() { + @Override Border getForegroundShadowBorder() { return new AquaUtils.SlicedShadowBorder(new Painter() { + @Override public void paint(final Graphics g, final int x, final int y, final int w, final int h) { g.setColor(new Color(0, 0, 0, 196)); g.fillRoundRect(x, y, w, h, 16, 16); g.fillRect(x, y + h - 16, w, 16); } }, new Painter() { + @Override public void paint(final Graphics g, int x, int y, int w, int h) { g.setColor(new Color(0, 0, 0, 64)); g.drawLine(x + 2, y - 8, x + w - 2, y - 8); @@ -720,14 +756,17 @@ 0, 7, 1.1f, 1.0f, 24, 51, 51, 25, 25, 25, 25); } + @Override Border getBackgroundShadowBorder() { return new AquaUtils.SlicedShadowBorder(new Painter() { + @Override public void paint(final Graphics g, final int x, final int y, final int w, final int h) { g.setColor(new Color(0, 0, 0, 128)); g.fillRoundRect(x - 3, y - 8, w + 6, h, 16, 16); g.fillRect(x - 3, y + h - 20, w + 6, 19); } }, new Painter() { + @Override public void paint(final Graphics g, int x, int y, int w, int h) { g.setColor(new Color(0, 0, 0, 32)); g.drawLine(x, y - 11, x + w - 1, y - 11); @@ -738,8 +777,10 @@ }; static final InternalFrameShadow paletteWindowShadow = new InternalFrameShadow() { + @Override Border getForegroundShadowBorder() { return new AquaUtils.SlicedShadowBorder(new Painter() { + @Override public void paint(final Graphics g, final int x, final int y, final int w, final int h) { g.setColor(new Color(0, 0, 0, 128)); g.fillRect(x, y + 3, w, h - 3); @@ -748,6 +789,7 @@ 0, 3, 1.0f, 1.0f, 10, 25, 25, 12, 12, 12, 12); } + @Override Border getBackgroundShadowBorder() { return getForegroundShadowBorder(); } @@ -762,19 +804,23 @@ abstract Border getForegroundShadowBorder(); abstract Border getBackgroundShadowBorder(); + @Override protected Border getInstance() { final Border fgShadow = getForegroundShadowBorder(); final Border bgShadow = getBackgroundShadowBorder(); return new Border() { + @Override public Insets getBorderInsets(final Component c) { return fgShadow.getBorderInsets(c); } + @Override public boolean isBorderOpaque() { return false; } + @Override public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int w, final int h) { if (((JInternalFrame)c).isSelected()) { fgShadow.paintBorder(c, g, x, y, w, h); @@ -790,6 +836,7 @@ @Override protected Icon getInstance() { return new AquaIcon.ScalingJRSUIIcon(11, 11) { + @Override public void initIconPainter(final AquaPainter<JRSUIState> iconState) { iconState.state.set(Widget.GROW_BOX_TEXTURED); iconState.state.set(WindowType.UTILITY); @@ -799,12 +846,15 @@ }; @SuppressWarnings("serial") // Superclass is not serializable across versions - class ResizeBox extends JLabel implements MouseListener, MouseMotionListener, MouseWheelListener, ComponentListener, PropertyChangeListener, UIResource { - final JLayeredPane layeredPane; - Dimension originalSize; - Point originalLocation; + private final class ResizeBox extends JLabel + implements MouseListener, MouseMotionListener, MouseWheelListener, + ComponentListener, PropertyChangeListener, UIResource { - public ResizeBox(final JLayeredPane layeredPane) { + private final JLayeredPane layeredPane; + private Dimension originalSize; + private Point originalLocation; + + ResizeBox(final JLayeredPane layeredPane) { super(RESIZE_ICON.get()); setSize(11, 11); this.layeredPane = layeredPane; @@ -895,14 +945,18 @@ return c; } + @Override public void mouseClicked(final MouseEvent e) { forwardEventToFrame(e); } + @Override public void mouseEntered(final MouseEvent e) { } + @Override public void mouseExited(final MouseEvent e) { } + @Override public void mousePressed(final MouseEvent e) { if (frame == null) return; @@ -916,6 +970,7 @@ forwardEventToFrame(e); } + @Override public void mouseReleased(final MouseEvent e) { if (originalLocation != null) { resizeInternalFrame(e.getPoint()); @@ -927,13 +982,16 @@ forwardEventToFrame(e); } + @Override public void mouseDragged(final MouseEvent e) { resizeInternalFrame(e.getPoint()); repositionResizeBox(); } + @Override public void mouseMoved(final MouseEvent e) { } + @Override public void mouseWheelMoved(final MouseWheelEvent e) { final Point pt = new Point(); final Component c = getComponentToForwardTo(e, pt); @@ -945,20 +1003,25 @@ e.getPreciseWheelRotation())); } + @Override public void componentResized(final ComponentEvent e) { repositionResizeBox(); } + @Override public void componentShown(final ComponentEvent e) { repositionResizeBox(); } + @Override public void componentMoved(final ComponentEvent e) { repositionResizeBox(); } + @Override public void componentHidden(final ComponentEvent e) { } + @Override public void propertyChange(final PropertyChangeEvent evt) { if (!"resizable".equals(evt.getPropertyName())) return; setVisible(Boolean.TRUE.equals(evt.getNewValue()));
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaSpinnerUI.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaSpinnerUI.java Tue Sep 22 11:01:54 2015 -0700 @@ -49,12 +49,14 @@ * so we can't subclass! */ public class AquaSpinnerUI extends SpinnerUI { - private static final RecyclableSingleton<? extends PropertyChangeListener> propertyChangeListener = new RecyclableSingletonFromDefaultConstructor<PropertyChangeHandler>(PropertyChangeHandler.class); + private static final RecyclableSingleton<? extends PropertyChangeListener> propertyChangeListener + = new RecyclableSingletonFromDefaultConstructor<>(PropertyChangeHandler.class); static PropertyChangeListener getPropertyChangeListener() { return propertyChangeListener.get(); } - private static final RecyclableSingleton<ArrowButtonHandler> nextButtonHandler = new RecyclableSingleton<ArrowButtonHandler>() { + private static final RecyclableSingleton<ArrowButtonHandler> nextButtonHandler + = new RecyclableSingleton<ArrowButtonHandler>() { @Override protected ArrowButtonHandler getInstance() { return new ArrowButtonHandler("increment", true); @@ -63,7 +65,8 @@ static ArrowButtonHandler getNextButtonHandler() { return nextButtonHandler.get(); } - private static final RecyclableSingleton<ArrowButtonHandler> previousButtonHandler = new RecyclableSingleton<ArrowButtonHandler>() { + private static final RecyclableSingleton<ArrowButtonHandler> previousButtonHandler + = new RecyclableSingleton<ArrowButtonHandler>() { @Override protected ArrowButtonHandler getInstance() { return new ArrowButtonHandler("decrement", false); @@ -73,8 +76,10 @@ return previousButtonHandler.get(); } - JSpinner spinner; - SpinPainter spinPainter; + private JSpinner spinner; + private SpinPainter spinPainter; + private TransparentButton next; + private TransparentButton prev; public static ComponentUI createUI(final JComponent c) { return new AquaSpinnerUI(); @@ -87,12 +92,13 @@ } boolean wasOpaque; + @Override public void installUI(final JComponent c) { this.spinner = (JSpinner)c; installDefaults(); installListeners(); - final TransparentButton next = createNextButton(); - final TransparentButton prev = createPreviousButton(); + next = createNextButton(); + prev = createPreviousButton(); spinPainter = new SpinPainter(next, prev); maybeAdd(next, "Next"); @@ -111,11 +117,21 @@ spinner.setOpaque(false); } + @Override public void uninstallUI(final JComponent c) { uninstallDefaults(); uninstallListeners(); spinner.setOpaque(wasOpaque); + spinPainter = null; spinner = null; + // AquaButtonUI install some listeners to all parents, which means that + // we need to uninstall UI here to remove those listeners, because after + // we remove them from spinner we lost the latest reference to them, + // and our standard uninstallUI machinery will not call them. + next.getUI().uninstallUI(next); + prev.getUI().uninstallUI(prev); + next = null; + prev = null; c.removeAll(); } @@ -164,6 +180,7 @@ /** * {@inheritDoc} */ + @Override public int getBaseline(JComponent c, int width, int height) { super.getBaseline(c, width, height); JComponent editor = spinner.getEditor(); @@ -182,6 +199,7 @@ /** * {@inheritDoc} */ + @Override public Component.BaselineResizeBehavior getBaselineResizeBehavior( JComponent c) { super.getBaselineResizeBehavior(c); @@ -200,8 +218,10 @@ interceptRepaints = true; } + @Override public void paint(final Graphics g) {} + @Override public void repaint() { // only intercept repaints if we are after this has been initialized // otherwise we can't talk to our containing class @@ -315,6 +335,7 @@ return (src instanceof JSpinner) ? (JSpinner)src : null; } + @Override public void actionPerformed(final ActionEvent e) { if (!(e.getSource() instanceof javax.swing.Timer)) { // Most likely resulting from being in ActionMap. @@ -423,6 +444,7 @@ return -1; } + @Override public void mousePressed(final MouseEvent e) { if (!SwingUtilities.isLeftMouseButton(e) || !e.getComponent().isEnabled()) return; spinner = eventToSpinner(e); @@ -431,13 +453,17 @@ focusSpinnerIfNecessary(); } + @Override public void mouseReleased(final MouseEvent e) { autoRepeatTimer.stop(); spinner = null; } + @Override public void mouseClicked(final MouseEvent e) {} + @Override public void mouseEntered(final MouseEvent e) {} + @Override public void mouseExited(final MouseEvent e) {} /** @@ -485,6 +511,7 @@ } } + @Override public void paint(final Graphics g) { if (spinner.isOpaque()) { g.setColor(spinner.getBackground()); @@ -511,6 +538,7 @@ painter.paint(g, spinner, 0, 0, bounds.width, bounds.height); } + @Override public Dimension getPreferredSize() { final Size size = AquaUtilControlSize.getUserSizeFrom(this); @@ -533,6 +561,7 @@ private Component editor = null; private Component painter = null; + @Override public void addLayoutComponent(final String name, final Component c) { if ("Next".equals(name)) { nextButton = c; @@ -545,6 +574,7 @@ } } + @Override public void removeLayoutComponent(Component c) { if (c == nextButton) { c = null; @@ -561,6 +591,7 @@ return (c == null) ? new Dimension(0, 0) : c.getPreferredSize(); } + @Override public Dimension preferredLayoutSize(final Container parent) { // Dimension nextD = preferredSize(nextButton); // Dimension previousD = preferredSize(previousButton); @@ -579,6 +610,7 @@ return size; } + @Override public Dimension minimumLayoutSize(final Container parent) { return preferredLayoutSize(parent); } @@ -589,6 +621,7 @@ } } + @Override public void layoutContainer(final Container parent) { final Insets insets = parent.getInsets(); final int availWidth = parent.getWidth() - (insets.left + insets.right); @@ -629,6 +662,7 @@ * property changes are delegated to protected methods. */ static class PropertyChangeHandler implements PropertyChangeListener { + @Override public void propertyChange(final PropertyChangeEvent e) { final String propertyName = e.getPropertyName(); final JSpinner spinner = (JSpinner)(e.getSource());
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -95,6 +95,17 @@ super.assureRectsCreated(tabCount); } + @Override + protected void uninstallListeners() { + // We're not just a mouseListener, we're a mouseMotionListener + if (mouseListener instanceof MouseHandler) { + final MouseHandler mh = (MouseHandler) mouseListener; + mh.dispose(); + tabPane.removeMouseMotionListener(mh); + } + super.uninstallListeners(); + } + protected void uninstallDefaults() { contentDrawingInsets.set(0, 0, 0, 0); } @@ -409,7 +420,15 @@ paintTabNormalFromRect(g, tabPlacement, rects[tabIndex], tabIndex, fIconRect, fTextRect, active, frameActive, isLeftToRight); } - protected void paintTabNormalFromRect(final Graphics g, final int tabPlacement, final Rectangle tabRect, final int nonRectIndex, final Rectangle iconRect, final Rectangle textRect, final boolean active, final boolean frameActive, final boolean isLeftToRight) { + protected void paintTabNormalFromRect(final Graphics g, + final int tabPlacement, + final Rectangle tabRect, + final int nonRectIndex, + final Rectangle iconRect, + final Rectangle textRect, + final boolean active, + final boolean frameActive, + final boolean isLeftToRight) { final int selectedIndex = tabPane.getSelectedIndex(); final boolean isSelected = selectedIndex == nonRectIndex; @@ -420,7 +439,12 @@ paintContents(g, tabPlacement, nonRectIndex, tabRect, iconRect, textRect, isSelected); } - protected void paintCUITab(final Graphics g, final int tabPlacement, final Rectangle tabRect, final boolean isSelected, final boolean frameActive, final boolean isLeftToRight, final int nonRectIndex) { + protected void paintCUITab(final Graphics g, final int tabPlacement, + final Rectangle tabRect, + final boolean isSelected, + final boolean frameActive, + final boolean isLeftToRight, + final int nonRectIndex) { final int tabCount = tabPane.getTabCount(); final boolean needsLeftScrollTab = visibleTabState.needsLeftScrollTab(); @@ -835,14 +859,20 @@ } } - public class MouseHandler extends MouseInputAdapter implements ActionListener { - protected int trackingTab = -3; - protected Timer popupTimer = new Timer(500, this); + class MouseHandler extends MouseInputAdapter implements ActionListener { - public MouseHandler() { + int trackingTab = -3; + private final Timer popupTimer = new Timer(500, this); + + MouseHandler() { popupTimer.setRepeats(false); } + void dispose (){ + popupTimer.removeActionListener(this); + popupTimer.stop(); + } + public void mousePressed(final MouseEvent e) { final JTabbedPane pane = (JTabbedPane)e.getSource(); if (!pane.isEnabled()) {
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTextAreaUI.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTextAreaUI.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,6 +42,7 @@ } AquaFocusHandler handler; + @Override protected void installListeners() { super.installListeners(); @@ -53,6 +54,7 @@ AquaUtilControlSize.addSizePropertyListener(c); } + @Override protected void uninstallListeners() { final JTextComponent c = getComponent(); @@ -66,6 +68,7 @@ } boolean oldDragState = false; + @Override protected void installDefaults() { if (!GraphicsEnvironment.isHeadless()) { oldDragState = getComponent().getDragEnabled(); @@ -74,6 +77,7 @@ super.installDefaults(); } + @Override protected void uninstallDefaults() { if (!GraphicsEnvironment.isHeadless()) { getComponent().setDragEnabled(oldDragState); @@ -81,7 +85,9 @@ super.uninstallDefaults(); } - // Install a default keypress action which handles Cmd and Option keys properly + // Install a default keypress action which handles Cmd and Option keys + // properly + @Override protected void installKeyboardActions() { super.installKeyboardActions(); AquaKeyBindings bindings = AquaKeyBindings.instance(); @@ -90,13 +96,12 @@ bindings.installAquaUpDownActions(c); } + @Override protected Caret createCaret() { - final JTextComponent c = getComponent(); - final Window owningWindow = SwingUtilities.getWindowAncestor(c); - final AquaCaret returnValue = new AquaCaret(owningWindow, c); - return returnValue; + return new AquaCaret(); } + @Override protected Highlighter createHighlighter() { return new AquaHighlighter(); }
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTextFieldUI.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTextFieldUI.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -42,6 +42,7 @@ protected JComponentPainter delegate; protected AquaFocusHandler handler; + @Override protected void installListeners() { super.installListeners(); @@ -55,6 +56,7 @@ AquaTextFieldSearch.installSearchFieldListener(c); } + @Override protected void uninstallListeners() { final JTextComponent c = getComponent(); AquaTextFieldSearch.uninstallSearchFieldListener(c); @@ -67,6 +69,7 @@ } boolean oldDragState = false; + @Override protected void installDefaults() { if (!GraphicsEnvironment.isHeadless()) { oldDragState = getComponent().getDragEnabled(); @@ -76,6 +79,7 @@ super.installDefaults(); } + @Override protected void uninstallDefaults() { super.uninstallDefaults(); @@ -84,12 +88,15 @@ } } - // Install a default keypress action which handles Cmd and Option keys properly + // Install a default keypress action which handles Cmd and Option keys + // properly + @Override protected void installKeyboardActions() { super.installKeyboardActions(); AquaKeyBindings.instance().setDefaultAction(getKeymapName()); } + @Override protected Rectangle getVisibleEditorRect() { final Rectangle rect = super.getVisibleEditorRect(); if (rect == null) return null; @@ -102,6 +109,7 @@ return rect; } + @Override protected void paintSafely(final Graphics g) { paintBackgroundSafely(g); super.paintSafely(g); @@ -149,20 +157,23 @@ // the common case final int shrinkage = AquaTextFieldBorder.getShrinkageFor(c, height); - g.fillRect(insets.left - 2, insets.top - shrinkage - 1, width - insets.right - insets.left + 4, height - insets.bottom - insets.top + shrinkage * 2 + 2); + g.fillRect(insets.left - 2, insets.top - shrinkage - 1, + width - insets.right - insets.left + 4, + height - insets.bottom - insets.top + shrinkage * 2 + 2); } + @Override protected void paintBackground(final Graphics g) { // we have already ensured that the background is painted to our liking // by paintBackgroundSafely(), called from paintSafely(). } + @Override protected Caret createCaret() { - final JTextComponent c = getComponent(); - final Window owningWindow = SwingUtilities.getWindowAncestor(c); - return new AquaCaret(owningWindow, c); + return new AquaCaret(); } + @Override protected Highlighter createHighlighter() { return new AquaHighlighter(); }
--- a/src/java.desktop/macosx/classes/com/apple/laf/AquaTextPaneUI.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/com/apple/laf/AquaTextPaneUI.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,6 +43,7 @@ } AquaFocusHandler handler; + @Override protected void installListeners() { super.installListeners(); final JComponent c = getComponent(); @@ -52,6 +53,7 @@ AquaUtilControlSize.addSizePropertyListener(c); } + @Override protected void uninstallListeners() { final JComponent c = getComponent(); AquaUtilControlSize.removeSizePropertyListener(c); @@ -62,6 +64,7 @@ } boolean oldDragState = false; + @Override protected void installDefaults() { final JTextComponent c = getComponent(); if (!GraphicsEnvironment.isHeadless()) { @@ -71,6 +74,7 @@ super.installDefaults(); } + @Override protected void uninstallDefaults() { if (!GraphicsEnvironment.isHeadless()) { getComponent().setDragEnabled(oldDragState); @@ -78,7 +82,9 @@ super.uninstallDefaults(); } - // Install a default keypress action which handles Cmd and Option keys properly + // Install a default keypress action which handles Cmd and Option keys + // properly + @Override protected void installKeyboardActions() { super.installKeyboardActions(); AquaKeyBindings bindings = AquaKeyBindings.instance(); @@ -88,12 +94,12 @@ bindings.installAquaUpDownActions(c); } + @Override protected Caret createCaret() { - final JTextComponent c = getComponent(); - final Window owningWindow = SwingUtilities.getWindowAncestor(c); - return new AquaCaret(owningWindow, c); + return new AquaCaret(); } + @Override protected Highlighter createHighlighter() { return new AquaHighlighter(); }
--- a/src/java.desktop/macosx/classes/sun/lwawt/macosx/CImage.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/macosx/classes/sun/lwawt/macosx/CImage.java Tue Sep 22 11:01:54 2015 -0700 @@ -31,7 +31,7 @@ import java.util.Arrays; import java.util.List; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; import sun.awt.image.MultiResolutionCachedImage; import sun.awt.image.SunWritableRaster;
--- a/src/java.desktop/share/classes/com/sun/media/sound/SoftMidiAudioFileReader.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/com/sun/media/sound/SoftMidiAudioFileReader.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,10 +25,8 @@ package com.sun.media.sound; -import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.URL; import javax.sound.midi.InvalidMidiDataException; import javax.sound.midi.MetaMessage; @@ -44,28 +42,27 @@ import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.UnsupportedAudioFileException; -import javax.sound.sampled.spi.AudioFileReader; /** * MIDI File Audio Renderer/Reader. * * @author Karl Helgason */ -public final class SoftMidiAudioFileReader extends AudioFileReader { +public final class SoftMidiAudioFileReader extends SunFileReader { - public static final Type MIDI = new Type("MIDI", "mid"); - private static AudioFormat format = new AudioFormat(44100, 16, 2, true, false); + private static final Type MIDI = new Type("MIDI", "mid"); - public AudioFileFormat getAudioFileFormat(Sequence seq) - throws UnsupportedAudioFileException, IOException { + private static final AudioFormat format = new AudioFormat(44100, 16, 2, + true, false); + private static AudioFileFormat getAudioFileFormat(final Sequence seq) { long totallen = seq.getMicrosecondLength() / 1000000; long len = (long) (format.getFrameRate() * (totallen + 4)); return new AudioFileFormat(MIDI, format, (int) len); } - public AudioInputStream getAudioInputStream(Sequence seq) - throws UnsupportedAudioFileException, IOException { + private AudioInputStream getAudioInputStream(final Sequence seq) + throws InvalidMidiDataException { AudioSynthesizer synth = (AudioSynthesizer) new SoftSynthesizer(); AudioInputStream stream; Receiver recv; @@ -73,7 +70,7 @@ stream = synth.openStream(format, null); recv = synth.getReceiver(); } catch (MidiUnavailableException e) { - throw new IOException(e.toString()); + throw new InvalidMidiDataException(e.toString()); } float divtype = seq.getDivisionType(); Track[] tracks = seq.getTracks(); @@ -111,7 +108,7 @@ if (((MetaMessage) msg).getType() == 0x51) { byte[] data = ((MetaMessage) msg).getData(); if (data.length < 3) { - throw new UnsupportedAudioFileException(); + throw new InvalidMidiDataException(); } mpq = ((data[0] & 0xff) << 16) | ((data[1] & 0xff) << 8) | (data[2] & 0xff); @@ -128,91 +125,25 @@ return stream; } - public AudioInputStream getAudioInputStream(InputStream inputstream) + @Override + public AudioInputStream getAudioInputStream(final InputStream stream) throws UnsupportedAudioFileException, IOException { - - inputstream.mark(200); - Sequence seq; + stream.mark(200); try { - seq = MidiSystem.getSequence(inputstream); - } catch (InvalidMidiDataException e) { - inputstream.reset(); - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - inputstream.reset(); + return getAudioInputStream(MidiSystem.getSequence(stream)); + } catch (final InvalidMidiDataException ignored) { + stream.reset(); throw new UnsupportedAudioFileException(); } - return getAudioInputStream(seq); } - public AudioFileFormat getAudioFileFormat(URL url) + @Override + AudioFileFormat getAudioFileFormatImpl(final InputStream stream) throws UnsupportedAudioFileException, IOException { - Sequence seq; try { - seq = MidiSystem.getSequence(url); - } catch (InvalidMidiDataException e) { - throw new UnsupportedAudioFileException(); - } catch (IOException e) { + return getAudioFileFormat(MidiSystem.getSequence(stream)); + } catch (final InvalidMidiDataException ignored) { throw new UnsupportedAudioFileException(); } - return getAudioFileFormat(seq); - } - - public AudioFileFormat getAudioFileFormat(File file) - throws UnsupportedAudioFileException, IOException { - Sequence seq; - try { - seq = MidiSystem.getSequence(file); - } catch (InvalidMidiDataException e) { - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - throw new UnsupportedAudioFileException(); - } - return getAudioFileFormat(seq); - } - - public AudioInputStream getAudioInputStream(URL url) - throws UnsupportedAudioFileException, IOException { - Sequence seq; - try { - seq = MidiSystem.getSequence(url); - } catch (InvalidMidiDataException e) { - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - throw new UnsupportedAudioFileException(); - } - return getAudioInputStream(seq); - } - - public AudioInputStream getAudioInputStream(File file) - throws UnsupportedAudioFileException, IOException { - if (!file.getName().toLowerCase().endsWith(".mid")) - throw new UnsupportedAudioFileException(); - Sequence seq; - try { - seq = MidiSystem.getSequence(file); - } catch (InvalidMidiDataException e) { - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - throw new UnsupportedAudioFileException(); - } - return getAudioInputStream(seq); - } - - public AudioFileFormat getAudioFileFormat(InputStream inputstream) - throws UnsupportedAudioFileException, IOException { - - inputstream.mark(200); - Sequence seq; - try { - seq = MidiSystem.getSequence(inputstream); - } catch (InvalidMidiDataException e) { - inputstream.reset(); - throw new UnsupportedAudioFileException(); - } catch (IOException e) { - inputstream.reset(); - throw new UnsupportedAudioFileException(); - } - return getAudioFileFormat(seq); } }
--- a/src/java.desktop/share/classes/com/sun/media/sound/SunFileReader.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/com/sun/media/sound/SunFileReader.java Tue Sep 22 11:01:54 2015 -0700 @@ -52,10 +52,6 @@ try { return getAudioFileFormatImpl(stream); } finally { - // According to specification the following is not strictly - // necessary, if we got correct format. But it was implemented like - // that in 1.3.0 - 1.8. So I leave it as it was, but it seems - // specification should be updated. stream.reset(); } }
--- a/src/java.desktop/share/classes/java/awt/EventQueue.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/java/awt/EventQueue.java Tue Sep 22 11:01:54 2015 -0700 @@ -899,11 +899,13 @@ } } - // Wake up EDT waiting in getNextEvent(), so it can - // pick up a new EventQueue. Post the waking event before - // topQueue.nextQueue is assigned, otherwise the event would - // go newEventQueue - topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable)); + if (topQueue.dispatchThread != null) { + // Wake up EDT waiting in getNextEvent(), so it can + // pick up a new EventQueue. Post the waking event before + // topQueue.nextQueue is assigned, otherwise the event would + // go newEventQueue + topQueue.postEventPrivate(new InvocationEvent(topQueue, dummyRunnable)); + } newEventQueue.previousQueue = topQueue; topQueue.nextQueue = newEventQueue;
--- a/src/java.desktop/share/classes/java/awt/Font.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/java/awt/Font.java Tue Sep 22 11:01:54 2015 -0700 @@ -128,7 +128,9 @@ * <p> * For a discussion of the relative advantages and disadvantages of using * physical or logical fonts, see the - * <a href="http://www.oracle.com/technetwork/java/javase/tech/faq-jsp-138165.html">Internationalization FAQ</a> + * <a href="https://docs.oracle.com/javase/tutorial/2d/text/fonts.html#advantages-and-disadvantages"> + * Physical and Logical Fonts</a> + * in <a href="https://docs.oracle.com/javase/tutorial/index.html">The Java Tutorials</a> * document. * * <h3>Font Faces and Names</h3>
--- a/src/java.desktop/share/classes/java/awt/RenderingHints.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/java/awt/RenderingHints.java Tue Sep 22 11:01:54 2015 -0700 @@ -955,6 +955,64 @@ SunHints.VALUE_STROKE_PURE; /** + * Image resolution variant hint key. + * The {@code RESOLUTION_VARIANT} hint controls which image resolution + * variant should be chosen for image drawing. + * + * <ul> + * <li>{@link #VALUE_RESOLUTION_VARIANT_DEFAULT} + * <li>{@link #VALUE_RESOLUTION_VARIANT_BASE} + * <li>{@link #VALUE_RESOLUTION_VARIANT_SIZE_FIT} + * <li>{@link #VALUE_RESOLUTION_VARIANT_DPI_FIT} + * </ul> + * @since 1.9 + */ + public static final Key KEY_RESOLUTION_VARIANT = + SunHints.KEY_RESOLUTION_VARIANT; + + /** + * Image resolution variant hint value -- an image resolution variant is + * chosen based on a default heuristic which may depend on the policies + * of the platform + * + * @see #KEY_RESOLUTION_VARIANT + * @since 1.9 + */ + public static final Object VALUE_RESOLUTION_VARIANT_DEFAULT = + SunHints.VALUE_RESOLUTION_VARIANT_DEFAULT; + + /** + * Image resolution variant hint value -- the standard resolution of an image + * is always used. + * + * @see #KEY_RESOLUTION_VARIANT + * @since 1.9 + */ + public static final Object VALUE_RESOLUTION_VARIANT_BASE = + SunHints.VALUE_RESOLUTION_VARIANT_BASE; + + /** + * Image resolution variant hint value -- an image resolution variant is + * chosen based on the DPI of the screen and the transform in the Graphics2D + * context. + * + * @see #KEY_RESOLUTION_VARIANT + * @since 1.9 + */ + public static final Object VALUE_RESOLUTION_VARIANT_SIZE_FIT = + SunHints.VALUE_RESOLUTION_VARIANT_SIZE_FIT; + + /** + * Image resolution variant hint value -- an image resolution variant is + * chosen based only on the DPI of the screen. + * + * @see #KEY_RESOLUTION_VARIANT + * @since 1.9 + */ + public static final Object VALUE_RESOLUTION_VARIANT_DPI_FIT = + SunHints.VALUE_RESOLUTION_VARIANT_DPI_FIT; + + /** * Constructs a new object with keys and values initialized * from the specified Map object which may be null. * @param init a map of key/value pairs to initialize the hints
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.desktop/share/classes/java/awt/image/AbstractMultiResolutionImage.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.awt.image; + +import java.awt.Graphics; +import java.awt.Image; + +/** + * This class provides default implementations of several {@code Image} methods + * for classes that want to implement the {@MultiResolutionImage} interface. + * + * For example, + * <pre> {@code + * public class CustomMultiResolutionImage extends AbstractMultiResolutionImage { + * + * final Image[] resolutionVariants; + * + * public CustomMultiResolutionImage(Image... resolutionVariants) { + * this.resolutionVariants = resolutionVariants; + * } + * + * public Image getResolutionVariant( + * double destImageWidth, double destImageHeight) { + * // return a resolution variant based on the given destination image size + * } + * + * public List<Image> getResolutionVariants() { + * return Collections.unmodifiableList(Arrays.asList(resolutionVariants)); + * } + * + * protected Image getBaseImage() { + * return resolutionVariants[0]; + * } + * } + * } </pre> + * + * @see java.awt.Image + * @see java.awt.image.MultiResolutionImage + * + * @since 1.9 + */ +public abstract class AbstractMultiResolutionImage extends java.awt.Image + implements MultiResolutionImage { + + @Override + public int getWidth(ImageObserver observer) { + return getBaseImage().getWidth(observer); + } + + @Override + public int getHeight(ImageObserver observer) { + return getBaseImage().getHeight(observer); + } + + @Override + public ImageProducer getSource() { + return getBaseImage().getSource(); + } + + @Override + public Graphics getGraphics() { + throw new UnsupportedOperationException("getGraphics() not supported" + + " on Multi-Resolution Images"); + } + + @Override + public Object getProperty(String name, ImageObserver observer) { + return getBaseImage().getProperty(name, observer); + } + + /** + * Return the base image representing the best version of the image for + * rendering at the default width and height. + * + * @return the base image of the set of multi-resolution images + * + * @since 1.9 + */ + protected abstract Image getBaseImage(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.desktop/share/classes/java/awt/image/BaseMultiResolutionImage.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,150 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.awt.image; + +import java.awt.Image; +import java.util.List; +import java.util.Arrays; +import java.util.Collections; +import java.util.Objects; + +/** + * This class is an array-based implementation of + * the {@code AbstractMultiResolutionImage} class. + * + * This class will implement the + * {@code getResolutionVariant(double destImageWidth, double destImageHeight)} + * method using a simple algorithm which will return the first image variant + * in the array that is large enough to satisfy the rendering request. The + * last image in the array will be returned if no suitable image is found + * that is as large as the rendering request. + * <p> + * For best effect the array of images should be sorted with each image being + * both wider and taller than the previous image. The base image need not be + * the first image in the array. No exception will be thrown if the images + * are not sorted as suggested. + * + * @see java.awt.Image + * @see java.awt.image.MultiResolutionImage + * @see java.awt.image.AbstractMultiResolutionImage + * + * @since 1.9 + */ +public class BaseMultiResolutionImage extends AbstractMultiResolutionImage { + + private final int baseImageIndex; + private final Image[] resolutionVariants; + + /** + * Creates a multi-resolution image with the given resolution variants. + * The first resolution variant is used as the base image. + * + * @param resolutionVariants array of resolution variants sorted by image size + * @throws IllegalArgumentException if null or zero-length array is passed + * @throws NullPointerException if the specified {@code resolutionVariants} + * contains one or more null elements + * + * @since 1.9 + */ + public BaseMultiResolutionImage(Image... resolutionVariants) { + this(0, resolutionVariants); + } + + /** + * Creates a multi-resolution image with the given base image index and + * resolution variants. + * + * @param baseImageIndex the index of base image in the resolution variants + * array + * @param resolutionVariants array of resolution variants sorted by image size + * @throws IllegalArgumentException if null or zero-length array is passed + * @throws NullPointerException if the specified {@code resolutionVariants} + * contains one or more null elements + * @throws IndexOutOfBoundsException if {@code baseImageIndex} is + * negative or greater than or equal to {@code resolutionVariants} + * length. + * + * @since 1.9 + */ + public BaseMultiResolutionImage(int baseImageIndex, + Image... resolutionVariants) { + + if (resolutionVariants == null || resolutionVariants.length == 0) { + throw new IllegalArgumentException( + "Null or zero-length array is passed"); + } + + if (baseImageIndex < 0 || baseImageIndex >= resolutionVariants.length) { + throw new IndexOutOfBoundsException("Invalid base image index: " + + baseImageIndex); + } + + this.baseImageIndex = baseImageIndex; + this.resolutionVariants = Arrays.copyOf(resolutionVariants, + resolutionVariants.length); + + for (Image resolutionVariant : this.resolutionVariants) { + Objects.requireNonNull(resolutionVariant, + "Resolution variant can't be null"); + } + } + + @Override + public Image getResolutionVariant(double destImageWidth, + double destImageHeight) { + + checkSize(destImageWidth, destImageHeight); + + for (Image rvImage : resolutionVariants) { + if (destImageWidth <= rvImage.getWidth(null) + && destImageHeight <= rvImage.getHeight(null)) { + return rvImage; + } + } + return resolutionVariants[resolutionVariants.length - 1]; + } + + private static void checkSize(double width, double height) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) cannot be <= 0", width, height)); + } + + if (!Double.isFinite(width) || !Double.isFinite(height)) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) is not finite", width, height)); + } + } + + @Override + public List<Image> getResolutionVariants() { + return Collections.unmodifiableList(Arrays.asList(resolutionVariants)); + } + + @Override + protected Image getBaseImage() { + return resolutionVariants[baseImageIndex]; + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/java.desktop/share/classes/java/awt/image/MultiResolutionImage.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package java.awt.image; + +import java.awt.Image; +import java.util.List; + +/** + * This interface is designed to be an optional additional API supported by + * some implementations of {@link java.awt.Image} to allow them to provide + * alternate images for various rendering resolutions. The various + * {@code Graphics.drawImage(...)} variant methods will consult the methods + * of this interface if it is implemented on the argument {@code Image} object + * in order to choose the best representation to use for each rendering operation. + * <p> + * The {@code MultiResolutionImage} interface should be implemented by any + * subclass of {@code java.awt.Image} whose instances are intended to provide + * image resolution variants according to the given image width and height. + * For convenience, toolkit images obtained from + * {@code Toolkit.getImage(String name)} and {@code Toolkit.getImage(URL url)} + * will implement this interface on platforms that support naming conventions + * for resolution variants of stored image media and the + * {@code AbstractMultiResolutionImage} and {@code BaseMultiResolutionImage} + * classes are provided to facilitate easy construction of custom multi-resolution + * images from a list of related images. + * + * @see java.awt.Image + * @see java.awt.image.AbstractMultiResolutionImage + * @see java.awt.image.BaseMultiResolutionImage + * @see java.awt.Toolkit#getImage(java.lang.String filename) + * @see java.awt.Toolkit#getImage(java.net.URL url) + * + * @since 1.9 + */ +public interface MultiResolutionImage { + + /** + * Gets a specific image that is the best variant to represent + * this logical image at the indicated size. + * + * @param destImageWidth the width of the destination image, in pixels. + * @param destImageHeight the height of the destination image, in pixels. + * @return image resolution variant. + * @throws IllegalArgumentException if {@code destImageWidth} or + * {@code destImageHeight} is less than or equal to zero, infinity, + * or NaN. + * + * @since 1.9 + */ + Image getResolutionVariant(double destImageWidth, double destImageHeight); + + /** + * Gets a readable list of all resolution variants. + * The list must be nonempty and contain at least one resolution variant. + * <p> + * Note that many implementations might return an unmodifiable list. + * <p> + * @return list of resolution variants. + * @since 1.9 + */ + public List<Image> getResolutionVariants(); +} \ No newline at end of file
--- a/src/java.desktop/share/classes/java/beans/XMLEncoder.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/java/beans/XMLEncoder.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -614,10 +614,12 @@ } if (isArgument && target instanceof Field && methodName.equals("get")) { - Field f = (Field)target; - writeln("<object class=" + quote(f.getDeclaringClass().getName()) + - " field=" + quote(f.getName()) + "/>"); - return; + Field f = (Field) target; + if (Modifier.isStatic(f.getModifiers())) { + writeln("<object class=" + quote(f.getDeclaringClass().getName()) + + " field=" + quote(f.getName()) + "/>"); + return; + } } Class<?> primitiveType = primitiveTypeFor(value.getClass());
--- a/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -912,9 +912,9 @@ * must point to valid audio file data. The implementation of this method * may require multiple parsers to examine the stream to determine whether * they support it. These parsers must be able to mark the stream, read - * enough data to determine whether they support the stream, and, if not, - * reset the stream's read pointer to its original position. If the input - * stream does not support these operations, this method may fail with an + * enough data to determine whether they support the stream, and reset the + * stream's read pointer to its original position. If the input stream does + * not support these operations, this method may fail with an * {@code IOException}. * * @param stream the input stream from which file format information should @@ -1025,9 +1025,9 @@ * must point to valid audio file data. The implementation of this method * may require multiple parsers to examine the stream to determine whether * they support it. These parsers must be able to mark the stream, read - * enough data to determine whether they support the stream, and, if not, - * reset the stream's read pointer to its original position. If the input - * stream does not support these operation, this method may fail with an + * enough data to determine whether they support the stream, and reset the + * stream's read pointer to its original position. If the input stream does + * not support these operation, this method may fail with an * {@code IOException}. * * @param stream the input stream from which the {@code AudioInputStream}
--- a/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/javax/sound/sampled/spi/AudioFileReader.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -49,9 +49,9 @@ * must point to valid audio file data. In general, audio file readers may * need to read some data from the stream before determining whether they * support it. These parsers must be able to mark the stream, read enough - * data to determine whether they support the stream, and, if not, reset the - * stream's read pointer to its original position. If the input stream does - * not support this, this method may fail with an {@code IOException}. + * data to determine whether they support the stream, and reset the stream's + * read pointer to its original position. If the input stream does not + * support this, this method may fail with an {@code IOException}. * * @param stream the input stream from which file format information should * be extracted @@ -101,9 +101,9 @@ * must point to valid audio file data. In general, audio file readers may * need to read some data from the stream before determining whether they * support it. These parsers must be able to mark the stream, read enough - * data to determine whether they support the stream, and, if not, reset the - * stream's read pointer to its original position. If the input stream does - * not support this, this method may fail with an {@code IOException}. + * data to determine whether they support the stream, and reset the stream's + * read pointer to its original position. If the input stream does not + * support this, this method may fail with an {@code IOException}. * * @param stream the input stream from which the {@code AudioInputStream} * should be constructed
--- a/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTableHeaderUI.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -403,6 +403,7 @@ protected void uninstallListeners() { header.removeMouseListener(mouseInputListener); header.removeMouseMotionListener(mouseInputListener); + header.removeFocusListener(focusListener); mouseInputListener = null; }
--- a/src/java.desktop/share/classes/javax/swing/text/DefaultCaret.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/javax/swing/text/DefaultCaret.java Tue Sep 22 11:01:54 2015 -0700 @@ -860,6 +860,7 @@ Highlighter.HighlightPainter p = getSelectionPainter(); try { selectionTag = h.addHighlight(p0, p1, p); + updateOwnsSelection(); } catch (BadLocationException bl) { selectionTag = null; } @@ -870,6 +871,7 @@ Highlighter h = component.getHighlighter(); h.removeHighlight(selectionTag); selectionTag = null; + updateOwnsSelection(); } } } @@ -1110,6 +1112,7 @@ if (selectionTag != null) { h.removeHighlight(selectionTag); selectionTag = null; + updateOwnsSelection(); } // otherwise, change or add the highlight } else { @@ -1120,6 +1123,7 @@ Highlighter.HighlightPainter p = getSelectionPainter(); selectionTag = h.addHighlight(p0, p1, p); } + updateOwnsSelection(); } catch (BadLocationException e) { throw new StateInvariantError("Bad caret position"); } @@ -1170,6 +1174,7 @@ if (this.dot != dot || this.dotBias != dotBias || selectionTag != null || forceCaretPositionChange) { changeCaretPosition(dot, dotBias); + updateOwnsSelection(); } this.markBias = this.dotBias; this.markLTR = dotLTR; @@ -1177,6 +1182,7 @@ if ((h != null) && (selectionTag != null)) { h.removeHighlight(selectionTag); selectionTag = null; + updateOwnsSelection(); } } @@ -1925,6 +1931,13 @@ } } + /** + * Updates ownsSelection based on text selection in the caret. + */ + private void updateOwnsSelection() { + ownsSelection = (selectionTag != null) + && SwingUtilities2.canAccessSystemClipboard(); + } private class DefaultFilterBypass extends NavigationFilter.FilterBypass { public Caret getCaret() {
--- a/src/java.desktop/share/classes/sun/awt/SunHints.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/sun/awt/SunHints.java Tue Sep 22 11:01:54 2015 -0700 @@ -257,8 +257,10 @@ */ @Native public static final int INTKEY_RESOLUTION_VARIANT = 9; @Native public static final int INTVAL_RESOLUTION_VARIANT_DEFAULT = 0; - @Native public static final int INTVAL_RESOLUTION_VARIANT_OFF = 1; - @Native public static final int INTVAL_RESOLUTION_VARIANT_ON = 2; + @Native public static final int INTVAL_RESOLUTION_VARIANT_BASE = 1; + @Native public static final int INTVAL_RESOLUTION_VARIANT_SIZE_FIT = 2; + @Native public static final int INTVAL_RESOLUTION_VARIANT_DPI_FIT = 3; + /** * LCD text contrast control hint key. * Value is "100" to make discontiguous with the others which @@ -466,15 +468,23 @@ public static final Object VALUE_RESOLUTION_VARIANT_DEFAULT = new SunHints.Value(KEY_RESOLUTION_VARIANT, SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT, - "Choose image resolutions based on a default heuristic"); - public static final Object VALUE_RESOLUTION_VARIANT_OFF = + "Choose image resolutions based on a default" + + "heuristic"); + public static final Object VALUE_RESOLUTION_VARIANT_BASE = new SunHints.Value(KEY_RESOLUTION_VARIANT, - SunHints.INTVAL_RESOLUTION_VARIANT_OFF, + SunHints.INTVAL_RESOLUTION_VARIANT_BASE, "Use only the standard resolution of an image"); - public static final Object VALUE_RESOLUTION_VARIANT_ON = + public static final Object VALUE_RESOLUTION_VARIANT_SIZE_FIT = new SunHints.Value(KEY_RESOLUTION_VARIANT, - SunHints.INTVAL_RESOLUTION_VARIANT_ON, - "Always use resolution-specific variants of images"); + SunHints.INTVAL_RESOLUTION_VARIANT_SIZE_FIT, + "Choose image resolutions based on the DPI" + + "of the screen and transform" + + "in the Graphics2D context"); + public static final Object VALUE_RESOLUTION_VARIANT_DPI_FIT = + new SunHints.Value(KEY_RESOLUTION_VARIANT, + SunHints.INTVAL_RESOLUTION_VARIANT_DPI_FIT, + "Choose image resolutions based only on the DPI" + + " of the screen"); public static class LCDContrastKey extends Key {
--- a/src/java.desktop/share/classes/sun/awt/SunToolkit.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/sun/awt/SunToolkit.java Tue Sep 22 11:01:54 2015 -0700 @@ -60,7 +60,7 @@ import sun.awt.image.ByteArrayImageSource; import sun.awt.image.FileImageSource; import sun.awt.image.ImageRepresentation; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; import sun.awt.image.MultiResolutionToolkitImage; import sun.awt.image.ToolkitImage; import sun.awt.image.URLImageSource;
--- a/src/java.desktop/share/classes/sun/awt/image/AbstractMultiResolutionImage.java Thu Sep 17 09:19:40 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package sun.awt.image; - -import java.awt.Graphics; -import java.awt.Image; -import java.awt.image.*; - -/** - * This class provides default implementations for the - * <code>MultiResolutionImage</code> interface. The developer needs only - * to subclass this abstract class and define the <code>getResolutionVariant</code>, - * <code>getResolutionVariants</code>, and <code>getBaseImage</code> methods. - * - * - * For example, - * {@code - * public class CustomMultiResolutionImage extends AbstractMultiResolutionImage { - * - * int baseImageIndex; - * Image[] resolutionVariants; - * - * public CustomMultiResolutionImage(int baseImageIndex, - * Image... resolutionVariants) { - * this.baseImageIndex = baseImageIndex; - * this.resolutionVariants = resolutionVariants; - * } - * - * @Override - * public Image getResolutionVariant(float logicalDPIX, float logicalDPIY, - * float baseImageWidth, float baseImageHeight, - * float destImageWidth, float destImageHeight) { - * // return a resolution variant based on the given logical DPI, - * // base image size, or destination image size - * } - * - * @Override - * public List<Image> getResolutionVariants() { - * return Arrays.asList(resolutionVariants); - * } - * - * protected Image getBaseImage() { - * return resolutionVariants[baseImageIndex]; - * } - * } - * } - * - * @see java.awt.Image - * @see java.awt.image.MultiResolutionImage - * - * @since 1.9 - */ -public abstract class AbstractMultiResolutionImage extends java.awt.Image - implements MultiResolutionImage { - - /** - * @inheritDoc - */ - @Override - public int getWidth(ImageObserver observer) { - return getBaseImage().getWidth(null); - } - - /** - * @inheritDoc - */ - @Override - public int getHeight(ImageObserver observer) { - return getBaseImage().getHeight(null); - } - - /** - * @inheritDoc - */ - @Override - public ImageProducer getSource() { - return getBaseImage().getSource(); - } - - /** - * @inheritDoc - */ - @Override - public Graphics getGraphics() { - return getBaseImage().getGraphics(); - - } - - /** - * @inheritDoc - */ - @Override - public Object getProperty(String name, ImageObserver observer) { - return getBaseImage().getProperty(name, observer); - } - - /** - * @return base image - */ - protected abstract Image getBaseImage(); -}
--- a/src/java.desktop/share/classes/sun/awt/image/MultiResolutionCachedImage.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/sun/awt/image/MultiResolutionCachedImage.java Tue Sep 22 11:01:54 2015 -0700 @@ -33,6 +33,7 @@ import java.util.function.Function; import java.util.function.BiFunction; import java.util.stream.Collectors; +import java.awt.image.AbstractMultiResolutionImage; public class MultiResolutionCachedImage extends AbstractMultiResolutionImage { @@ -58,7 +59,10 @@ } @Override - public Image getResolutionVariant(int width, int height) { + public Image getResolutionVariant(double destWidth, double destHeight) { + checkSize(destWidth, destHeight); + int width = (int) Math.ceil(destWidth); + int height = (int) Math.ceil(destHeight); ImageCache cache = ImageCache.getInstance(); ImageCacheKey key = new ImageCacheKey(this, width, height); Image resolutionVariant = cache.getImage(key); @@ -70,11 +74,23 @@ return resolutionVariant; } + private static void checkSize(double width, double height) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) cannot be <= 0", width, height)); + } + + if (!Double.isFinite(width) || !Double.isFinite(height)) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) is not finite", width, height)); + } + } + @Override public List<Image> getResolutionVariants() { return Arrays.stream(sizes).map((Function<Dimension2D, Image>) size - -> getResolutionVariant((int) size.getWidth(), - (int) size.getHeight())).collect(Collectors.toList()); + -> getResolutionVariant(size.getWidth(), size.getHeight())) + .collect(Collectors.toList()); } public MultiResolutionCachedImage map(Function<Image, Image> mapper) {
--- a/src/java.desktop/share/classes/sun/awt/image/MultiResolutionImage.java Thu Sep 17 09:19:40 2015 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - */ -package sun.awt.image; - -import java.awt.Image; -import java.util.List; - -/** - * This interface is designed to provide a set of images at various resolutions. - * - * The <code>MultiResolutionImage</code> interface should be implemented by any - * class whose instances are intended to provide image resolution variants - * according to the given image width and height. - * - * For example, - * <pre> - * {@code - * public class ScaledImage extends BufferedImage - * implements MultiResolutionImage { - * - * @Override - * public Image getResolutionVariant(int width, int height) { - * return ((width <= getWidth() && height <= getHeight())) - * ? this : highResolutionImage; - * } - * - * @Override - * public List<Image> getResolutionVariants() { - * return Arrays.asList(this, highResolutionImage); - * } - * } - * }</pre> - * - * It is recommended to cache image variants for performance reasons. - * - * <b>WARNING</b>: This class is an implementation detail. This API may change - * between update release, and it may even be removed or be moved in some other - * package(s)/class(es). - */ -public interface MultiResolutionImage { - - /** - * Provides an image with necessary resolution which best fits to the given - * image width and height. - * - * @param width the desired image resolution width. - * @param height the desired image resolution height. - * @return image resolution variant. - * - * @since 1.8 - */ - public Image getResolutionVariant(int width, int height); - - /** - * Gets list of all resolution variants including the base image - * - * @return list of resolution variants. - * @since 1.8 - */ - public List<Image> getResolutionVariants(); -}
--- a/src/java.desktop/share/classes/sun/awt/image/MultiResolutionToolkitImage.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/sun/awt/image/MultiResolutionToolkitImage.java Tue Sep 22 11:01:54 2015 -0700 @@ -26,6 +26,7 @@ import java.awt.Image; import java.awt.image.ImageObserver; +import java.awt.image.MultiResolutionImage; import java.util.Arrays; import java.util.List; import sun.misc.SoftCache; @@ -40,11 +41,24 @@ } @Override - public Image getResolutionVariant(int width, int height) { - return ((width <= getWidth() && height <= getHeight())) + public Image getResolutionVariant(double destWidth, double destHeight) { + checkSize(destWidth, destHeight); + return ((destWidth <= getWidth() && destHeight <= getHeight())) ? this : resolutionVariant; } + private static void checkSize(double width, double height) { + if (width <= 0 || height <= 0) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) cannot be <= 0", width, height)); + } + + if (!Double.isFinite(width) || !Double.isFinite(height)) { + throw new IllegalArgumentException(String.format( + "Width (%s) or height (%s) is not finite", width, height)); + } + } + public Image getResolutionVariant() { return resolutionVariant; }
--- a/src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.desktop/share/classes/sun/java2d/SunGraphics2D.java Tue Sep 22 11:01:54 2015 -0700 @@ -94,7 +94,7 @@ import sun.misc.PerformanceLogger; import java.lang.annotation.Native; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; import static java.awt.geom.AffineTransform.TYPE_FLIP; import static java.awt.geom.AffineTransform.TYPE_MASK_SCALE; @@ -3087,9 +3087,8 @@ // end of text rendering methods private boolean isHiDPIImage(final Image img) { - return (SurfaceManager.getImageScale(img) != 1) || - (resolutionVariantHint != SunHints.INTVAL_RESOLUTION_VARIANT_OFF - && img instanceof MultiResolutionImage); + return (SurfaceManager.getImageScale(img) != 1) + || img instanceof MultiResolutionImage; } private boolean drawHiDPIImage(Image img, int dx1, int dy1, int dx2, @@ -3175,25 +3174,42 @@ int type = transform.getType(); int dw = dx2 - dx1; int dh = dy2 - dy1; - double destRegionWidth; - double destRegionHeight; - - if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) { - destRegionWidth = dw; - destRegionHeight = dh; - } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) { - destRegionWidth = dw * transform.getScaleX(); - destRegionHeight = dh * transform.getScaleY(); + + double destImageWidth; + double destImageHeight; + + if (resolutionVariantHint == SunHints.INTVAL_RESOLUTION_VARIANT_BASE) { + destImageWidth = srcWidth; + destImageHeight = srcHeight; + } else if (resolutionVariantHint == SunHints.INTVAL_RESOLUTION_VARIANT_DPI_FIT) { + AffineTransform configTransform = getDefaultTransform(); + if (configTransform.isIdentity()) { + destImageWidth = srcWidth; + destImageHeight = srcHeight; + } else { + destImageWidth = srcWidth * configTransform.getScaleX(); + destImageHeight = srcHeight * configTransform.getScaleY(); + } } else { - destRegionWidth = dw * Math.hypot( - transform.getScaleX(), transform.getShearY()); - destRegionHeight = dh * Math.hypot( - transform.getShearX(), transform.getScaleY()); + double destRegionWidth; + double destRegionHeight; + + if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP)) == 0) { + destRegionWidth = dw; + destRegionHeight = dh; + } else if ((type & ~(TYPE_TRANSLATION | TYPE_FLIP | TYPE_MASK_SCALE)) == 0) { + destRegionWidth = dw * transform.getScaleX(); + destRegionHeight = dh * transform.getScaleY(); + } else { + destRegionWidth = dw * Math.hypot( + transform.getScaleX(), transform.getShearY()); + destRegionHeight = dh * Math.hypot( + transform.getShearX(), transform.getScaleY()); + } + destImageWidth = Math.abs(srcWidth * destRegionWidth / sw); + destImageHeight = Math.abs(srcHeight * destRegionHeight / sh); } - int destImageWidth = (int) Math.abs(srcWidth * destRegionWidth / sw); - int destImageHeight = (int) Math.abs(srcHeight * destRegionHeight / sh); - Image resolutionVariant = img.getResolutionVariant(destImageWidth, destImageHeight);
--- a/src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java Thu Sep 17 09:19:40 2015 -0700 +++ b/src/java.naming/share/classes/com/sun/jndi/ldap/LdapClient.java Tue Sep 22 11:01:54 2015 -0700 @@ -494,16 +494,14 @@ */ void processConnectionClosure() { // Notify listeners - synchronized (unsolicited) { - if (unsolicited.size() > 0) { - String msg; - if (conn != null) { - msg = conn.host + ":" + conn.port + " connection closed"; - } else { - msg = "Connection closed"; - } - notifyUnsolicited(new CommunicationException(msg)); + if (unsolicited.size() > 0) { + String msg; + if (conn != null) { + msg = conn.host + ":" + conn.port + " connection closed"; + } else { + msg = "Connection closed"; } + notifyUnsolicited(new CommunicationException(msg)); } // Remove from pool @@ -1499,13 +1497,8 @@ if (debug > 0) { System.err.println("LdapClient.removeUnsolicited" + ctx); } - synchronized (unsolicited) { - if (unsolicited.size() == 0) { - return; - } unsolicited.removeElement(ctx); } - } // NOTE: Cannot be synchronized because this is called asynchronously // by the reader thread in Connection. Instead, sync on 'unsolicited' Vector. @@ -1513,30 +1506,35 @@ if (debug > 0) { System.err.println("LdapClient.processUnsolicited"); } - synchronized (unsolicited) { - try { - // Parse the response - LdapResult res = new LdapResult(); + try { + // Parse the response + LdapResult res = new LdapResult(); - ber.parseSeq(null); // init seq - ber.parseInt(); // msg id; should be 0; ignored - if (ber.parseByte() != LDAP_REP_EXTENSION) { - throw new IOException( - "Unsolicited Notification must be an Extended Response"); - } - ber.parseLength(); - parseExtResponse(ber, res); + ber.parseSeq(null); // init seq + ber.parseInt(); // msg id; should be 0; ignored + if (ber.parseByte() != LDAP_REP_EXTENSION) { + throw new IOException( + "Unsolicited Notification must be an Extended Response"); + } + ber.parseLength(); + parseExtResponse(ber, res); - if (DISCONNECT_OID.equals(res.extensionId)) { - // force closing of connection - forceClose(pooled); - } + if (DISCONNECT_OID.equals(res.extensionId)) { + // force closing of connection + forceClose(pooled); + } + LdapCtx first = null; + UnsolicitedNotification notice = null; + + synchronized (unsolicited) { if (unsolicited.size() > 0) { + first = unsolicited.elementAt(0); + // Create an UnsolicitedNotification using the parsed data // Need a 'ctx' object because we want to use the context's // list of provider control factories. - UnsolicitedNotification notice = new UnsolicitedResponseImpl( + notice = new UnsolicitedResponseImpl( res.extensionId, res.extensionValue, res.referrals, @@ -1544,42 +1542,45 @@ res.errorMessage, res.matchedDN, (res.resControls != null) ? - unsolicited.elementAt(0).convertControls(res.resControls) : + first.convertControls(res.resControls) : null); + } + } - // Fire UnsolicitedNotification events to listeners - notifyUnsolicited(notice); + if (notice != null) { + // Fire UnsolicitedNotification events to listeners + notifyUnsolicited(notice); - // If "disconnect" notification, - // notify unsolicited listeners via NamingException - if (DISCONNECT_OID.equals(res.extensionId)) { - notifyUnsolicited( - new CommunicationException("Connection closed")); - } + // If "disconnect" notification, + // notify unsolicited listeners via NamingException + if (DISCONNECT_OID.equals(res.extensionId)) { + notifyUnsolicited( + new CommunicationException("Connection closed")); } - } catch (IOException e) { - if (unsolicited.size() == 0) - return; // no one registered; ignore + } + } catch (IOException e) { + NamingException ne = new CommunicationException( + "Problem parsing unsolicited notification"); + ne.setRootCause(e); - NamingException ne = new CommunicationException( - "Problem parsing unsolicited notification"); - ne.setRootCause(e); + notifyUnsolicited(ne); - notifyUnsolicited(ne); - - } catch (NamingException e) { - notifyUnsolicited(e); - } + } catch (NamingException e) { + notifyUnsolicited(e); } } private void notifyUnsolicited(Object e) { - for (int i = 0; i < unsolicited.size(); i++) { - unsolicited.elementAt(i).fireUnsolicited(e); + Vector<LdapCtx> unsolicitedCopy; + synchronized (unsolicited) { + unsolicitedCopy = new Vector<>(unsolicited); + if (e instanceof NamingException) { + unsolicited.setSize(0); // no more listeners after exception + } } - if (e instanceof NamingException) { - unsolicited.setSize(0); // no more listeners after exception + for (int i = 0; i < unsolicitedCopy.size(); i++) { + unsolicitedCopy.elementAt(i).fireUnsolicited(e); } }
--- a/test/com/sun/corba/cachedSocket/7056731.sh Thu Sep 17 09:19:40 2015 -0700 +++ b/test/com/sun/corba/cachedSocket/7056731.sh Tue Sep 22 11:01:54 2015 -0700 @@ -64,12 +64,12 @@ sleep 2 #give orbd time to start echo "started orb" echo "starting server" -${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -cp . HelloServer -ORBInitialPort $PORT -ORBInitialHost localhost & +${JAVA} ${TESTVMOPTS} -cp . HelloServer -ORBInitialPort $PORT -ORBInitialHost localhost & SERVER_PROC=$! sleep 2 #give server time to start echo "started server" echo "starting client (debug mode)" -${TESTJAVA}${FS}bin${FS}java ${TESTVMOPTS} -cp . -agentlib:jdwp=transport=dt_socket,server=y,address=8000 HelloClient -ORBInitialPort $PORT -ORBInitialHost localhost > client.$$ 2>&1 & +${JAVA} ${TESTVMOPTS} -cp . -agentlib:jdwp=transport=dt_socket,server=y,address=8000 HelloClient -ORBInitialPort $PORT -ORBInitialHost localhost > client.$$ 2>&1 & JVM_PROC=$! sleep 2 #give jvm/debugger/client time to start @@ -97,7 +97,7 @@ echo "clear com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.unregisterWaiter" sleep 2; echo "resume 1"; -)| ${TESTJAVA}${FS}bin${FS}jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8000 +)| ${COMPILEJAVA}${FS}bin${FS}jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8000 sleep 5 # give time for Client to throw exception
--- a/test/java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/awt/Choice/UnfocusableToplevel/UnfocusableToplevel.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2015 Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* @test - @bug 6566434 + @bug 6566434 8039467 @library ../../regtesthelpers @build Util Sysout AbstractTest @summary Choice in unfocusable window responds to keyboard @@ -63,6 +63,18 @@ w.setLayout(new FlowLayout()); w.setSize(200, 200); + // Note that Window w is non focusable. Key press events will not be + // consumed by w, but by any previously focused window & this can + // disturb the environment. So creating tempFrameToHoldFocus frame, + // to consume key press events. + Frame tempFrameToHoldFocus = new Frame(); + tempFrameToHoldFocus.setVisible(true); + Util.waitForIdle(robot); + + tempFrameToHoldFocus.requestFocus(); + Util.clickOnComp(tempFrameToHoldFocus, robot); + Util.waitForIdle(robot); + ch.addKeyListener(new KeyAdapter(){ public void keyTyped(KeyEvent e){ traceEvent("keytyped", e); @@ -94,6 +106,10 @@ testKeys(); Util.waitForIdle(robot); + + tempFrameToHoldFocus.dispose(); + w.dispose(); + f.dispose(); } private static void testKeys(){
--- a/test/java/awt/Cursor/MultiResolutionCursorTest/MultiResolutionCursorTest.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/awt/Cursor/MultiResolutionCursorTest/MultiResolutionCursorTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -25,19 +25,16 @@ import java.awt.Cursor; import java.awt.Dialog; import java.awt.Frame; -import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Label; import java.awt.Point; import java.awt.TextArea; import java.awt.Toolkit; +import java.awt.image.BaseMultiResolutionImage; import java.awt.image.BufferedImage; -import java.util.LinkedList; -import java.util.List; import javax.swing.JApplet; import jdk.testlibrary.OSInfo; -import sun.awt.image.MultiResolutionImage; /** * @test @@ -52,7 +49,7 @@ public class MultiResolutionCursorTest extends JApplet { //Declare things used in the test, like buttons and labels here - static final int sizes[] = {16, 32, 128}; + static final int sizes[] = {8, 16, 32, 128}; static final Color colors[] = {Color.WHITE, Color.RED, Color.GREEN, Color.BLUE}; public void init() { @@ -87,7 +84,12 @@ setVisible(true); validate(); - final Image image = new MultiResolutionCursor(); + final Image image = new BaseMultiResolutionImage( + createResolutionVariant(0), + createResolutionVariant(1), + createResolutionVariant(2), + createResolutionVariant(3) + ); int center = sizes[0] / 2; Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor( @@ -101,53 +103,14 @@ frame.setVisible(true); }// start() - - static class MultiResolutionCursor extends BufferedImage implements MultiResolutionImage { - - List<Image> highResolutionImages; - - public MultiResolutionCursor() { - super(sizes[0], sizes[0], BufferedImage.TYPE_INT_RGB); - - draw(getGraphics(), 0); - highResolutionImages = new LinkedList<>(); - highResolutionImages.add(this); - - for (int i = 1; i < sizes.length; i++) { - BufferedImage highResolutionImage = - new BufferedImage(sizes[i], sizes[i], BufferedImage.TYPE_INT_RGB); - draw(highResolutionImage.getGraphics(), i); - highResolutionImages.add(highResolutionImage); - } - } - - @Override - public Image getResolutionVariant(int width, int height) { - - for (int i = 0; i < sizes.length; i++) { - Image image = highResolutionImages.get(i); - int w = image.getWidth(null); - int h = image.getHeight(null); - - if (width <= w && height <= h) { - return image; - } - } - - return highResolutionImages.get(highResolutionImages.size() - 1); - } - - void draw(Graphics graphics, int index) { - Graphics2D g2 = (Graphics2D) graphics; - Color color = colors[index]; - g2.setColor(color); - g2.fillRect(0, 0, sizes[index], sizes[index]); - } - - @Override - public List<Image> getResolutionVariants() { - return highResolutionImages; - } + static BufferedImage createResolutionVariant(int i) { + BufferedImage resolutionVariant = new BufferedImage(sizes[i], sizes[i], + BufferedImage.TYPE_INT_RGB); + Graphics2D g2 = resolutionVariant.createGraphics(); + g2.setColor(colors[i]); + g2.fillRect(0, 0, sizes[i], sizes[i]); + g2.dispose(); + return resolutionVariant; } }// class BlockedWindowTest
--- a/test/java/awt/Focus/RequestOnCompWithNullParent/RequestOnCompWithNullParent1.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/awt/Focus/RequestOnCompWithNullParent/RequestOnCompWithNullParent1.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,19 +24,14 @@ /* @test @bug 6418028 - @summary java/awt/Focus/RequestOnCompWithNullParent/RequestOnCompWithNullParent_Barrier.java fails @author oleg.sukhodolsky: area=awt.focus @library ../../regtesthelpers + @modules java.desktop/java.awt.peer + java.desktop/sun.awt @build Util @run main RequestOnCompWithNullParent1 */ -/** - * RequestOnCompWithNullParent1.java - * - * summary: java/awt/Focus/RequestOnCompWithNullParent/RequestOnCompWithNullParent_Barrier.java fails - */ - import java.awt.*; import java.awt.event.*; import java.awt.peer.ButtonPeer; @@ -46,26 +41,21 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Proxy; -import test.java.awt.regtesthelpers.Util; -//*** global search and replace RequestOnCompWithNullParent1 with name of the test *** +import sun.awt.AWTAccessor; -public class RequestOnCompWithNullParent1 -{ +public class RequestOnCompWithNullParent1 { - private static void init() { - //*** Create instructions for the user here *** - String[] instructions = - { - "This is an AUTOMATIC test, simply wait until it is done.", - "The result (passed or failed) will be shown in the", - "message window below." - }; - Sysout.createDialog( ); - Sysout.printInstructions( instructions ); + public static void main(final String[] args) throws Exception { + Frame frame = new Frame("test for 6418028"); + try { + test(frame); + } finally { + frame.dispose(); + } + } - - Frame frame = new Frame("test for 6418028"); + private static void test(final Frame frame) throws Exception { frame.setLayout(new FlowLayout()); Button btn1 = new Button("Button1"); frame.add(btn1); @@ -80,153 +70,26 @@ }); frame.setVisible(true); - Util.waitForIdle(null); + new Robot().waitForIdle(); btn2.instrumentPeer(); btn2.requestFocusInWindow(); btn2.restorePeer(); - frame.dispose(); - RequestOnCompWithNullParent1.pass(); - }//End init() - - - - /***************************************************** - * Standard Test Machinery Section - * DO NOT modify anything in this section -- it's a - * standard chunk of code which has all of the - * synchronisation necessary for the test harness. - * By keeping it the same in all tests, it is easier - * to read and understand someone else's test, as - * well as insuring that all tests behave correctly - * with the test harness. - * There is a section following this for test- - * classes - ******************************************************/ - private static boolean theTestPassed = false; - private static boolean testGeneratedInterrupt = false; - private static String failureMessage = ""; - - private static Thread mainThread = null; - - private static int sleepTime = 300000; - - // Not sure about what happens if multiple of this test are - // instantiated in the same VM. Being static (and using - // static vars), it aint gonna work. Not worrying about - // it for now. - public static void main( String args[] ) throws InterruptedException - { - mainThread = Thread.currentThread(); - try - { - init(); - } - catch( TestPassedException e ) - { - //The test passed, so just return from main and harness will - // interepret this return as a pass - return; - } - //At this point, neither test pass nor test fail has been - // called -- either would have thrown an exception and ended the - // test, so we know we have multiple threads. - - //Test involves other threads, so sleep and wait for them to - // called pass() or fail() - try - { - Thread.sleep( sleepTime ); - //Timed out, so fail the test - throw new RuntimeException( "Timed out after " + sleepTime/1000 + " seconds" ); - } - catch (InterruptedException e) - { - //The test harness may have interrupted the test. If so, rethrow the exception - // so that the harness gets it and deals with it. - if( ! testGeneratedInterrupt ) throw e; - - //reset flag in case hit this code more than once for some reason (just safety) - testGeneratedInterrupt = false; - - if ( theTestPassed == false ) - { - throw new RuntimeException( failureMessage ); - } - } - - }//main - - public static synchronized void setTimeoutTo( int seconds ) - { - sleepTime = seconds * 1000; } - - public static synchronized void pass() - { - Sysout.println( "The test passed." ); - Sysout.println( "The test is over, hit Ctl-C to stop Java VM" ); - //first check if this is executing in main thread - if ( mainThread == Thread.currentThread() ) - { - //Still in the main thread, so set the flag just for kicks, - // and throw a test passed exception which will be caught - // and end the test. - theTestPassed = true; - throw new TestPassedException(); - } - theTestPassed = true; - testGeneratedInterrupt = true; - mainThread.interrupt(); - }//pass() - - public static synchronized void fail() - { - //test writer didn't specify why test failed, so give generic - fail( "it just plain failed! :-)" ); - } - - public static synchronized void fail( String whyFailed ) - { - Sysout.println( "The test failed: " + whyFailed ); - Sysout.println( "The test is over, hit Ctl-C to stop Java VM" ); - //check if this called from main thread - if ( mainThread == Thread.currentThread() ) - { - //If main thread, fail now 'cause not sleeping - throw new RuntimeException( whyFailed ); - } - theTestPassed = false; - testGeneratedInterrupt = true; - failureMessage = whyFailed; - mainThread.interrupt(); - }//fail() - -}// class RequestOnCompWithNullParent1 - -//This exception is used to exit from any level of call nesting -// when it's determined that the test has passed, and immediately -// end the test. -class TestPassedException extends RuntimeException -{ } -//*********** End Standard Test Machinery Section ********** - - -//************ Begin classes defined for the test **************** - class TestButton extends Button { ButtonPeer origPeer; ButtonPeer proxiedPeer; /** Creates a new instance of TestButton */ - public TestButton(String text) { + TestButton(String text) { super(text); } public void instrumentPeer() { - origPeer = (ButtonPeer) getPeer(); + origPeer = AWTAccessor.getComponentAccessor().getPeer(this); + InvocationHandler handler = new InvocationHandler() { public Object invoke(Object proxy, Method method, Object[] args) { if (method.getName().equals("requestFocus")) { @@ -248,7 +111,9 @@ } }; - proxiedPeer = (ButtonPeer) Proxy.newProxyInstance(ButtonPeer.class.getClassLoader(), new Class[] {ButtonPeer.class}, handler); + proxiedPeer = (ButtonPeer) Proxy.newProxyInstance( + ButtonPeer.class.getClassLoader(), + new Class[] {ButtonPeer.class}, handler); setPeer(proxiedPeer); } @@ -275,145 +140,3 @@ } } } -//************** End classes defined for the test ******************* - - - - -/**************************************************** - Standard Test Machinery - DO NOT modify anything below -- it's a standard - chunk of code whose purpose is to make user - interaction uniform, and thereby make it simpler - to read and understand someone else's test. - ****************************************************/ - -/** - This is part of the standard test machinery. - It creates a dialog (with the instructions), and is the interface - for sending text messages to the user. - To print the instructions, send an array of strings to Sysout.createDialog - WithInstructions method. Put one line of instructions per array entry. - To display a message for the tester to see, simply call Sysout.println - with the string to be displayed. - This mimics System.out.println but works within the test harness as well - as standalone. - */ - -class Sysout -{ - private static TestDialog dialog; - - public static void createDialogWithInstructions( String[] instructions ) - { - dialog = new TestDialog( new Frame(), "Instructions" ); - dialog.printInstructions( instructions ); - dialog.setVisible(true); - println( "Any messages for the tester will display here." ); - } - - public static void createDialog( ) - { - dialog = new TestDialog( new Frame(), "Instructions" ); - String[] defInstr = { "Instructions will appear here. ", "" } ; - dialog.printInstructions( defInstr ); - dialog.setVisible(true); - println( "Any messages for the tester will display here." ); - } - - - public static void printInstructions( String[] instructions ) - { - dialog.printInstructions( instructions ); - } - - - public static void println( String messageIn ) - { - dialog.displayMessage( messageIn ); - System.out.println(messageIn); - } - -}// Sysout class - -/** - This is part of the standard test machinery. It provides a place for the - test instructions to be displayed, and a place for interactive messages - to the user to be displayed. - To have the test instructions displayed, see Sysout. - To have a message to the user be displayed, see Sysout. - Do not call anything in this dialog directly. - */ -class TestDialog extends Dialog -{ - - TextArea instructionsText; - TextArea messageText; - int maxStringLength = 80; - - //DO NOT call this directly, go through Sysout - public TestDialog( Frame frame, String name ) - { - super( frame, name ); - int scrollBoth = TextArea.SCROLLBARS_BOTH; - instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); - add( "North", instructionsText ); - - messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); - add("Center", messageText); - - pack(); - - setVisible(true); - }// TestDialog() - - //DO NOT call this directly, go through Sysout - public void printInstructions( String[] instructions ) - { - //Clear out any current instructions - instructionsText.setText( "" ); - - //Go down array of instruction strings - - String printStr, remainingStr; - for( int i=0; i < instructions.length; i++ ) - { - //chop up each into pieces maxSringLength long - remainingStr = instructions[ i ]; - while( remainingStr.length() > 0 ) - { - //if longer than max then chop off first max chars to print - if( remainingStr.length() >= maxStringLength ) - { - //Try to chop on a word boundary - int posOfSpace = remainingStr. - lastIndexOf( ' ', maxStringLength - 1 ); - - if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; - - printStr = remainingStr.substring( 0, posOfSpace + 1 ); - remainingStr = remainingStr.substring( posOfSpace + 1 ); - } - //else just print - else - { - printStr = remainingStr; - remainingStr = ""; - } - - instructionsText.append( printStr + "\n" ); - - }// while - - }// for - - }//printInstructions() - - //DO NOT call this directly, go through Sysout - public void displayMessage( String messageIn ) - { - messageText.append( messageIn + "\n" ); - System.out.println(messageIn); - } - -}// TestDialog class
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Modal/InvisibleParentTest/InvisibleParentTest.html Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,45 @@ +<!-- + Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + + This code is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License version 2 only, as + published by the Free Software Foundation. + + This code is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + version 2 for more details (a copy is included in the LICENSE file that + accompanied this code). + + You should have received a copy of the GNU General Public License version + 2 along with this work; if not, write to the Free Software Foundation, + Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + + Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + or visit www.oracle.com if you need additional information or have any + questions. +--> + +<html> +<!-- + @test + @bug 6401700 6412803 + @requires (os.family != "windows") + @summary Tests that modal dialog is shown on the screen and +iconified/restored correctly if its parent window is invisible + @author artem.ananiev: area=awt.modal + @run applet/manual=yesno InvisibleParentTest.html + --> +<head> +<title> InvisibleParentTest </title> +</head> +<body> + +<h1>InvisibleParentTest<br>Bug ID: 6401700, 6412803</h1> + +<p> See the dialog box (usually in upper left corner) for instructions</p> + +<APPLET CODE="InvisibleParentTest.class" WIDTH=200 HEIGHT=200></APPLET> +</body> +</html>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Modal/InvisibleParentTest/InvisibleParentTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + test + @bug 6401700 6412803 + @summary Tests that modal dialog is shown on the screen and +iconified/restored correctly if some of its blocked windows are invisible + @author artem.ananiev: area=awt.modal + @run applet/manual=yesno InvisibleParentTest.html +*/ + +import java.applet.Applet; +import java.awt.BorderLayout; +import java.awt.Button; +import java.awt.Component; +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.TextArea; +import java.awt.Window; + +public class InvisibleParentTest extends Applet +{ + public void init() + { + setLayout(new BorderLayout()); + + String[] instructions = + { + "If your system is Windows, press PASS button.", + "When the test starts two windows should appear: frame G1 and", + " dialog D1. Another one frame F1 should be minimized.", + " If the dialog is not shown (minimizied), press FAIL button.", + "Then minimize frame G1 and restore F1. If the dialog D1 is not", + " restored together with F1, press FAIL, else PASS" + }; + Sysout.createDialogWithInstructions( instructions ); + } + + public void start () + { + Button b; + + setSize (200,200); + setVisible(true); + validate(); + + Component c = this; + while ((c != null) && !(c instanceof Window)) + { + c = c.getParent(); + } + if (c != null) + { + ((Window)c).setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); + } + + Frame f1 = new Frame("F1"); + f1.setBounds(100, 300, 100, 100); + f1.setVisible(true); + f1.setExtendedState(Frame.ICONIFIED); + + Frame g1 = new Frame("G1"); + g1.setBounds(150, 350, 100, 100); + g1.setVisible(true); + + final Dialog d1 = new Dialog((Frame)null, "D1", Dialog.ModalityType.APPLICATION_MODAL); + d1.setBounds(200, 400, 100, 100); + new Thread(new Runnable() + { + public void run() + { + d1.setVisible(true); + } + }).start(); + } +} + +/**************************************************** + Standard Test Machinery + DO NOT modify anything below -- it's a standard + chunk of code whose purpose is to make user + interaction uniform, and thereby make it simpler + to read and understand someone else's test. + ****************************************************/ + +/** + This is part of the standard test machinery. + It creates a dialog (with the instructions), and is the interface + for sending text messages to the user. + To print the instructions, send an array of strings to Sysout.createDialog + WithInstructions method. Put one line of instructions per array entry. + To display a message for the tester to see, simply call Sysout.println + with the string to be displayed. + This mimics System.out.println but works within the test harness as well + as standalone. + */ + +class Sysout +{ + private static TestDialog dialog; + + public static void createDialogWithInstructions( String[] instructions ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + dialog.printInstructions( instructions ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + public static void createDialog( ) + { + dialog = new TestDialog( new Frame(), "Instructions" ); + String[] defInstr = { "Instructions will appear here. ", "" } ; + dialog.printInstructions( defInstr ); + dialog.setVisible(true); + println( "Any messages for the tester will display here." ); + } + + + public static void printInstructions( String[] instructions ) + { + dialog.printInstructions( instructions ); + } + + + public static void println( String messageIn ) + { + dialog.displayMessage( messageIn ); + } + +}// Sysout class + +/** + This is part of the standard test machinery. It provides a place for the + test instructions to be displayed, and a place for interactive messages + to the user to be displayed. + To have the test instructions displayed, see Sysout. + To have a message to the user be displayed, see Sysout. + Do not call anything in this dialog directly. + */ +class TestDialog extends Dialog +{ + + TextArea instructionsText; + TextArea messageText; + int maxStringLength = 80; + + //DO NOT call this directly, go through Sysout + public TestDialog( Frame frame, String name ) + { + super( frame, name ); + setModalExclusionType(Dialog.ModalExclusionType.APPLICATION_EXCLUDE); + int scrollBoth = TextArea.SCROLLBARS_BOTH; + instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth ); + add( "North", instructionsText ); + + messageText = new TextArea( "", 5, maxStringLength, scrollBoth ); + add("Center", messageText); + + pack(); + + setVisible(true); + }// TestDialog() + + //DO NOT call this directly, go through Sysout + public void printInstructions( String[] instructions ) + { + //Clear out any current instructions + instructionsText.setText( "" ); + + //Go down array of instruction strings + + String printStr, remainingStr; + for( int i=0; i < instructions.length; i++ ) + { + //chop up each into pieces maxSringLength long + remainingStr = instructions[ i ]; + while( remainingStr.length() > 0 ) + { + //if longer than max then chop off first max chars to print + if( remainingStr.length() >= maxStringLength ) + { + //Try to chop on a word boundary + int posOfSpace = remainingStr. + lastIndexOf( ' ', maxStringLength - 1 ); + + if( posOfSpace <= 0 ) posOfSpace = maxStringLength - 1; + + printStr = remainingStr.substring( 0, posOfSpace + 1 ); + remainingStr = remainingStr.substring( posOfSpace + 1 ); + } + //else just print + else + { + printStr = remainingStr; + remainingStr = ""; + } + + instructionsText.append( printStr + "\n" ); + + }// while + + }// for + + }//printInstructions() + + //DO NOT call this directly, go through Sysout + public void displayMessage( String messageIn ) + { + messageText.append( messageIn + "\n" ); + System.out.println(messageIn); + } + +}// TestDialog class
--- a/test/java/awt/PrintJob/Text/StringWidth.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/awt/PrintJob/Text/StringWidth.java Tue Sep 22 11:01:54 2015 -0700 @@ -23,7 +23,6 @@ import java.awt.*; import java.util.Properties; -import sun.awt.*; public class StringWidth extends Frame {
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Toolkit/AutoShutdown/EventQueuePush/EventQueuePushAutoshutdown.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + test + @bug 8081485 + @summary tests that a program terminates automatically after EventQueue.push() + @author Anton Nashatyrev : area=toolkit +*/ + +import java.awt.*; + +public class EventQueuePushAutoshutdown implements Runnable { + private volatile int status = 2; + + public EventQueuePushAutoshutdown() throws Exception { + Runtime.getRuntime().addShutdownHook(new Thread(this)); + Thread thread = new Thread() { + @Override + public void run() { + status = 0; + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + status = 1; + System.exit(status); + } + } + }; + thread.setDaemon(true); + thread.start(); + + System.setProperty("java.awt.headless", "true"); + final EventQueue systemQueue = Toolkit.getDefaultToolkit().getSystemEventQueue(); + systemQueue.push(new EventQueue()); + EventQueue.invokeAndWait(new Runnable() { + @Override + public void run() { + System.out.println("Activated EDT"); + } + }); + System.out.println("After EDT activation"); + } + + public static void main(String[] args) throws Exception { + new EventQueuePushAutoshutdown(); + } + + @Override + public void run() { + Runtime.getRuntime().halt(status); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Toolkit/AutoShutdown/EventQueuePush/EventQueuePushAutoshutdown.sh Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,159 @@ +#!/bin/ksh -p + +# +# Copyright (c) 20015, Oracle and/or its affiliates. All rights reserved. +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# This code is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License version 2 only, as +# published by the Free Software Foundation. +# +# This code is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +# version 2 for more details (a copy is included in the LICENSE file that +# accompanied this code). +# +# You should have received a copy of the GNU General Public License version +# 2 along with this work; if not, write to the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA +# or visit www.oracle.com if you need additional information or have any +# questions. +# + +# +# @test EventQueuePushAutoshutdown.sh +# @bug 8081485 +# @summary tests that a program terminates automatically +# after EventQueue.push() +# @author Anton Nashatyrev : area=toolkit +# +# @compile EventQueuePushAutoshutdown.java +# @run shell EventQueuePushAutoshutdown.sh + + +# Beginning of subroutines: +status=1 + +#Call this from anywhere to fail the test with an error message +# usage: fail "reason why the test failed" +fail() + { echo "The test failed :-(" + echo "$*" 1>&2 + echo "exit status was $status" + exit $status + } #end of fail() + +#Call this from anywhere to pass the test with a message +# usage: pass "reason why the test passed if applicable" +pass() + { echo "The test passed!!!" + echo "$*" 1>&2 + exit 0 + } #end of pass() + +# end of subroutines + + +# The beginning of the script proper +OS=`uname -s` +case "$OS" in + SunOS | Linux | Darwin | CYGWIN* ) + FILESEP="/" + ;; + + Windows_95 | Windows_98 | Windows_NT | Windows_ME ) + FILESEP="\\" + ;; + + # catch all other OSs + * ) + echo "Unrecognized system! $OS" + fail "Unrecognized system! $OS" + ;; +esac + + +# Want this test to run standalone as well as in the harness, so do the +# following to copy the test's directory into the harness's scratch directory +# and set all appropriate variables: + +if [ -z "${TESTJAVA}" ] ; then + # TESTJAVA is not set, so the test is running stand-alone. + # TESTJAVA holds the path to the root directory of the build of the JDK + # to be tested. That is, any java files run explicitly in this shell + # should use TESTJAVA in the path to the java interpreter. + # So, we'll set this to the JDK spec'd on the command line. If none + # is given on the command line, tell the user that and use a cheesy + # default. + # THIS IS THE JDK BEING TESTED. + if [ -n "$1" ] ; + then TESTJAVA=$1 + else fail "no JDK specified on command line!" + fi + TESTSRC=. + TESTCLASSES=. + STANDALONE=1; +fi +echo "JDK under test is: $TESTJAVA" + +#Deal with .class files: +if [ -n "${STANDALONE}" ] ; + then + #if standalone, remind user to cd to dir. containing test before running it + echo "Just a reminder: cd to the dir containing this test when running it" + # then compile all .java files (if there are any) into .class files + if [ -a *.java ] ; + then echo "Reminder, this test should be in its own directory with all" + echo "supporting files it needs in the directory with it." + ${TESTJAVA}/bin/javac ./*.java ; + fi + # else in harness so copy all the class files from where jtreg put them + # over to the scratch directory this test is running in. + else cp ${TESTCLASSES}/*.class . ; +fi + +#if in test harness, then copy the entire directory that the test is in over +# to the scratch directory. This catches any support files needed by the test. +if [ -z "${STANDALONE}" ] ; + then cp ${TESTSRC}/* . +fi + +#Just before executing anything, make sure it has executable permission! +chmod 777 ./* + +############### YOUR TEST CODE HERE!!!!!!! ############# + +#All files required for the test should be in the same directory with +# this file. If converting a standalone test to run with the harness, +# as long as all files are in the same directory and it returns 0 for +# pass, you should be able to cut and paste it into here and it will +# run with the test harness. + +${TESTJAVA}/bin/java EventQueuePushAutoshutdown + +############### END YOUR TEST CODE !!!!! ############ +#Be sure the last command executed above this line returns 0 for success, +# something non-zero for failure. +status=$? + +# pass or fail the test based on status of the command +case "$status" in + 0 ) + pass "" + ;; + + 1 ) + fail "The program didn't automatically shut down" + ;; + + * ) + fail "The program terminated unexpectedly!" + ;; +esac + +#For additional examples of how to write platform independent KSH scripts, +# see the jtreg file itself. It is a KSH script for both Solaris and Win32 +
--- a/test/java/awt/image/MultiResolutionImage/NSImageToMultiResolutionImageTest.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/awt/image/MultiResolutionImage/NSImageToMultiResolutionImageTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -23,15 +23,17 @@ import java.awt.Image; import java.awt.Toolkit; -import sun.awt.OSInfo; -import sun.awt.image.MultiResolutionImage; +import java.awt.image.MultiResolutionImage; +import jdk.testlibrary.OSInfo; + /* * @test * @bug 8033534 8035069 * @summary [macosx] Get MultiResolution image from native system * @author Alexander Scherbatiy - * @modules java.desktop/sun.awt - * java.desktop/sun.awt.image + * @modules java.desktop/sun.awt.image + * @library /lib/testlibrary + * @build jdk.testlibrary.OSInfo * @run main NSImageToMultiResolutionImageTest */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/image/MultiResolutionImageCommonTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,207 @@ +/* + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import sun.awt.SunHints; +import java.awt.geom.AffineTransform; +import java.util.Arrays; +import java.util.List; +import java.awt.image.MultiResolutionImage; + +/** + * @test @bug 8011059 + * @author Alexander Scherbatiy + * @summary Test MultiResolution image loading and painting with various scaling + * combinations + * @modules java.desktop/sun.awt + * java.desktop/sun.awt.image + */ +public class MultiResolutionImageCommonTest { + + private static final int IMAGE_WIDTH = 300; + private static final int IMAGE_HEIGHT = 200; + private static final Color COLOR_1X = Color.GREEN; + private static final Color COLOR_2X = Color.BLUE; + + public static void main(String[] args) throws Exception { + testCustomMultiResolutionImage(); + System.out.println("Test passed."); + } + + public static void testCustomMultiResolutionImage() { + testCustomMultiResolutionImage(false); + testCustomMultiResolutionImage(true); + } + + public static void testCustomMultiResolutionImage( + boolean enableImageScaling) { + + Image image = new MultiResolutionBufferedImage(); + + // Same image size + BufferedImage bufferedImage = new BufferedImage( + IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, 0, 0, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); + + // Twice image size + bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, + BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, + 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, + 3 * IMAGE_HEIGHT / 2), enableImageScaling); + + // Scale 2x + bufferedImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.scale(2, 2); + g2d.drawImage(image, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + + // Rotate + bufferedImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, + BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, 0, 0, null); + g2d.rotate(Math.PI / 4); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); + + // Scale 2x and Rotate + bufferedImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.scale(-2, 2); + g2d.rotate(-Math.PI / 10); + g2d.drawImage(image, -IMAGE_WIDTH, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + + // General Transform + bufferedImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + float delta = 0.05f; + float cos = 1 - delta * delta / 2; + float sin = 1 + delta; + AffineTransform transform + = new AffineTransform(2 * cos, 0.1, 0.3, -2 * sin, 10, -5); + g2d.setTransform(transform); + g2d.drawImage(image, 0, -IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + + int D = 10; + // From Source to small Destination region + bufferedImage = new BufferedImage( + IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2, + IMAGE_WIDTH - D, IMAGE_HEIGHT - D, + D, D, IMAGE_WIDTH - D, IMAGE_HEIGHT - D, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); + + // From Source to large Destination region + bufferedImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + g2d = (Graphics2D) bufferedImage.getGraphics(); + setImageScalingHint(g2d, enableImageScaling); + g2d.drawImage(image, D, D, 2 * IMAGE_WIDTH - D, 2 * IMAGE_HEIGHT - D, + IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2, + IMAGE_WIDTH - D, IMAGE_HEIGHT - D, null); + checkColor(bufferedImage.getRGB( + 3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + } + + static class MultiResolutionBufferedImage extends BufferedImage + implements MultiResolutionImage { + + Image highResolutionImage; + + public MultiResolutionBufferedImage() { + super(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + highResolutionImage = new BufferedImage( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, + BufferedImage.TYPE_INT_RGB); + draw(getGraphics(), 1); + draw(highResolutionImage.getGraphics(), 2); + } + + final void draw(Graphics graphics, float resolution) { + Graphics2D g2 = (Graphics2D) graphics; + g2.scale(resolution, resolution); + g2.setColor((resolution == 1) ? COLOR_1X : COLOR_2X); + g2.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT); + } + + @Override + public Image getResolutionVariant( + double destImageWidth, double destImageHeight) { + return ((destImageWidth <= getWidth() && destImageHeight <= getHeight())) + ? this : highResolutionImage; + } + + @Override + public List<Image> getResolutionVariants() { + return Arrays.asList(this, highResolutionImage); + } + } + + static void setImageScalingHint( + Graphics2D g2d, boolean enableImageScaling) { + g2d.setRenderingHint(SunHints.KEY_RESOLUTION_VARIANT, enableImageScaling + ? RenderingHints.VALUE_RESOLUTION_VARIANT_DEFAULT + : RenderingHints.VALUE_RESOLUTION_VARIANT_BASE); + } + + static void checkColor(int rgb, boolean isImageScaled) { + + if (!isImageScaled && COLOR_1X.getRGB() != rgb) { + throw new RuntimeException("Wrong 1x color: " + new Color(rgb)); + } + + if (isImageScaled && COLOR_2X.getRGB() != rgb) { + throw new RuntimeException("Wrong 2x color" + new Color(rgb)); + } + } + +}
--- a/test/java/awt/image/MultiResolutionImageTest.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/awt/image/MultiResolutionImageTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -31,25 +31,24 @@ import java.lang.reflect.Method; import java.net.URL; import javax.imageio.ImageIO; -import sun.awt.OSInfo; import sun.awt.SunHints; import java.awt.MediaTracker; -import java.awt.geom.AffineTransform; +import java.awt.RenderingHints; import java.awt.image.ImageObserver; -import java.util.Arrays; -import java.util.List; import javax.swing.JPanel; -import sun.awt.SunToolkit; -import sun.awt.image.MultiResolutionImage; +import jdk.testlibrary.Platform; +import java.awt.image.MultiResolutionImage; /** - * @test - * @bug 8011059 + * @test @bug 8011059 * @author Alexander Scherbatiy * @summary [macosx] Make JDK demos look perfect on retina displays + * @library /lib/testlibrary/ + * @build jdk.testlibrary.Platform + * @requires (os.family == "mac") * @modules java.desktop/sun.awt * java.desktop/sun.awt.image - * @run main MultiResolutionImageTest CUSTOM + * java.desktop/sun.lwawt.macosx * @run main MultiResolutionImageTest TOOLKIT_PREPARE * @run main MultiResolutionImageTest TOOLKIT_LOAD * @run main MultiResolutionImageTest TOOLKIT @@ -70,149 +69,29 @@ if (args.length == 0) { throw new RuntimeException("Not found a test"); } + String test = args[0]; + System.out.println("TEST: " + test); - String test = args[0]; - - System.out.println("TEST: " + test); - System.out.println("CHECK OS: " + checkOS()); - - if ("CUSTOM".equals(test)) { - testCustomMultiResolutionImage(); - } else if (checkOS()) { - switch (test) { - case "CUSTOM": - break; - case "TOOLKIT_PREPARE": - testToolkitMultiResolutionImagePrepare(); - break; - case "TOOLKIT_LOAD": - testToolkitMultiResolutionImageLoad(); - break; - case "TOOLKIT": - testToolkitMultiResolutionImage(); - testImageNameTo2xParsing(); - break; - default: - throw new RuntimeException("Unknown test: " + test); - } + // To automatically pass the test if the test is not run using JTReg. + if (!Platform.isOSX()) { + System.out.println("Non-Mac platform detected. Passing the test"); + return; } - } - - static boolean checkOS() { - return OSInfo.getOSType() == OSInfo.OSType.MACOSX; - } - - public static void testCustomMultiResolutionImage() { - testCustomMultiResolutionImage(false); - testCustomMultiResolutionImage(true); - } - - public static void testCustomMultiResolutionImage(boolean enableImageScaling) { - - Image image = new MultiResolutionBufferedImage(); - - // Same image size - BufferedImage bufferedImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); - Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, 0, 0, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); - - // Twice image size - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - - // Scale 2x - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.scale(2, 2); - g2d.drawImage(image, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - - // Rotate - bufferedImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, 0, 0, null); - g2d.rotate(Math.PI / 4); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); - - // Scale 2x and Rotate - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.scale(-2, 2); - g2d.rotate(-Math.PI / 10); - g2d.drawImage(image, -IMAGE_WIDTH, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - - // General Transform - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - float delta = 0.05f; - float cos = 1 - delta * delta / 2; - float sin = 1 + delta; - AffineTransform transform = new AffineTransform(2 * cos, 0.1, 0.3, -2 * sin, 10, -5); - g2d.setTransform(transform); - g2d.drawImage(image, 0, -IMAGE_HEIGHT, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - - int D = 10; - // From Source to small Destination region - bufferedImage = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2, IMAGE_WIDTH - D, IMAGE_HEIGHT - D, - D, D, IMAGE_WIDTH - D, IMAGE_HEIGHT - D, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); - - // From Source to large Destination region - bufferedImage = new BufferedImage(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - g2d = (Graphics2D) bufferedImage.getGraphics(); - setImageScalingHint(g2d, enableImageScaling); - g2d.drawImage(image, D, D, 2 * IMAGE_WIDTH - D, 2 * IMAGE_HEIGHT - D, - IMAGE_WIDTH / 2, IMAGE_HEIGHT / 2, IMAGE_WIDTH - D, IMAGE_HEIGHT - D, null); - checkColor(bufferedImage.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); - } - - static class MultiResolutionBufferedImage extends BufferedImage - implements MultiResolutionImage { - - Image highResolutionImage; - - public MultiResolutionBufferedImage() { - super(IMAGE_WIDTH, IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - highResolutionImage = new BufferedImage( - 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); - draw(getGraphics(), 1); - draw(highResolutionImage.getGraphics(), 2); + switch (test) { + case "TOOLKIT_PREPARE": + testToolkitMultiResolutionImagePrepare(); + break; + case "TOOLKIT_LOAD": + testToolkitMultiResolutionImageLoad(); + break; + case "TOOLKIT": + testToolkitMultiResolutionImage(); + testImageNameTo2xParsing(); + break; + default: + throw new RuntimeException("Unknown test: " + test); } - - void draw(Graphics graphics, float resolution) { - Graphics2D g2 = (Graphics2D) graphics; - g2.scale(resolution, resolution); - g2.setColor((resolution == 1) ? COLOR_1X : COLOR_2X); - g2.fillRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT); - } - - @Override - public Image getResolutionVariant(int width, int height) { - return ((width <= getWidth() && height <= getHeight())) - ? this : highResolutionImage; - } - - @Override - public List<Image> getResolutionVariants() { - return Arrays.asList(this, highResolutionImage); - } + System.out.println("Test passed."); } static void testToolkitMultiResolutionImagePrepare() throws Exception { @@ -224,8 +103,9 @@ Image image = Toolkit.getDefaultToolkit().getImage(fileName); - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); - toolkit.prepareImage(image, IMAGE_WIDTH, IMAGE_HEIGHT, new LoadImageObserver(image)); + Toolkit toolkit = Toolkit.getDefaultToolkit(); + toolkit.prepareImage(image, IMAGE_WIDTH, IMAGE_HEIGHT, + new LoadImageObserver(image)); testToolkitMultiResolutionImageLoad(image); } @@ -240,7 +120,8 @@ testToolkitMultiResolutionImageLoad(image); } - static void testToolkitMultiResolutionImageLoad(Image image) throws Exception { + static void testToolkitMultiResolutionImageLoad(Image image) + throws Exception { MediaTracker tracker = new MediaTracker(new JPanel()); tracker.addImage(image, 0); @@ -256,7 +137,7 @@ int h = image.getHeight(null); Image resolutionVariant = ((MultiResolutionImage) image) - .getResolutionVariant(2 * w, 2 * h); + .getResolutionVariant(2 * w, 2 * h); if (image == resolutionVariant) { throw new RuntimeException("Resolution variant is not loaded"); @@ -267,9 +148,10 @@ static void testImageLoaded(Image image) { - SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); + Toolkit toolkit = Toolkit.getDefaultToolkit(); - int flags = toolkit.checkImage(image, IMAGE_WIDTH, IMAGE_WIDTH, new SilentImageObserver()); + int flags = toolkit.checkImage(image, IMAGE_WIDTH, IMAGE_WIDTH, + new SilentImageObserver()); if ((flags & (ImageObserver.FRAMEBITS | ImageObserver.ALLBITS)) == 0) { throw new RuntimeException("Image is not loaded!"); } @@ -278,7 +160,8 @@ static class SilentImageObserver implements ImageObserver { @Override - public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + public boolean imageUpdate(Image img, int infoflags, int x, int y, + int width, int height) { throw new RuntimeException("Observer should not be called!"); } } @@ -292,21 +175,25 @@ } @Override - public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + public boolean imageUpdate(Image img, int infoflags, int x, int y, + int width, int height) { if (image != img) { - throw new RuntimeException("Original image is not passed to the observer"); + throw new RuntimeException("Original image is not passed " + + "to the observer"); } if ((infoflags & ImageObserver.WIDTH) != 0) { if (width != IMAGE_WIDTH) { - throw new RuntimeException("Original width is not passed to the observer"); + throw new RuntimeException("Original width is not passed " + + "to the observer"); } } if ((infoflags & ImageObserver.HEIGHT) != 0) { if (height != IMAGE_HEIGHT) { - throw new RuntimeException("Original height is not passed to the observer"); + throw new RuntimeException("Original height is not passed " + + "to the observer"); } } @@ -335,7 +222,8 @@ testToolkitMultiResolutionImage(image, true); } - static void testToolkitMultiResolutionImageChache(String fileName, URL url) { + static void testToolkitMultiResolutionImageChache(String fileName, + URL url) { Image img1 = Toolkit.getDefaultToolkit().getImage(fileName); if (!(img1 instanceof MultiResolutionImage)) { @@ -358,8 +246,8 @@ } } - static void testToolkitMultiResolutionImage(Image image, boolean enableImageScaling) - throws Exception { + static void testToolkitMultiResolutionImage(Image image, + boolean enableImageScaling) throws Exception { MediaTracker tracker = new MediaTracker(new JPanel()); tracker.addImage(image, 0); @@ -368,15 +256,16 @@ throw new RuntimeException("Error during image loading"); } - final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); + final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, + IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g1x = (Graphics2D) bufferedImage1x.getGraphics(); setImageScalingHint(g1x, false); g1x.drawImage(image, 0, 0, null); - checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false); + checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, + 3 * IMAGE_HEIGHT / 4), false); Image resolutionVariant = ((MultiResolutionImage) image). - getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); + getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); if (resolutionVariant == null) { throw new RuntimeException("Resolution variant is null"); @@ -390,23 +279,28 @@ } final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, - 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics(); setImageScalingHint(g2x, enableImageScaling); - g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); - checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling); + g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, + 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null); + checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, + 3 * IMAGE_HEIGHT / 2), enableImageScaling); if (!(image instanceof MultiResolutionImage)) { throw new RuntimeException("Not a MultiResolutionImage"); } - MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image; + MultiResolutionImage multiResolutionImage + = (MultiResolutionImage) image; - Image image1x = multiResolutionImage.getResolutionVariant(IMAGE_WIDTH, IMAGE_HEIGHT); - Image image2x = multiResolutionImage.getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); + Image image1x = multiResolutionImage.getResolutionVariant( + IMAGE_WIDTH, IMAGE_HEIGHT); + Image image2x = multiResolutionImage.getResolutionVariant( + 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT); if (image1x.getWidth(null) * 2 != image2x.getWidth(null) - || image1x.getHeight(null) * 2 != image2x.getHeight(null)) { + || image1x.getHeight(null) * 2 != image2x.getHeight(null)) { throw new RuntimeException("Wrong resolution variant size"); } } @@ -416,13 +310,15 @@ ImageObserver observer = new ImageObserver() { @Override - public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + public boolean imageUpdate(Image img, int infoflags, int x, int y, + int width, int height) { if (img != image) { throw new RuntimeException("Wrong image in observer"); } - if ((infoflags & (ImageObserver.ERROR | ImageObserver.ABORT)) != 0) { + if ((infoflags & (ImageObserver.ERROR | ImageObserver.ABORT)) + != 0) { throw new RuntimeException("Error during image loading"); } @@ -432,18 +328,20 @@ }; final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH, - 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); + 2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB); Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics(); setImageScalingHint(g2x, true); - g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, observer); + g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, + IMAGE_WIDTH, IMAGE_HEIGHT, observer); } - static void setImageScalingHint(Graphics2D g2d, boolean enableImageScaling) { + static void setImageScalingHint(Graphics2D g2d, + boolean enableImageScaling) { g2d.setRenderingHint(SunHints.KEY_RESOLUTION_VARIANT, enableImageScaling - ? SunHints.VALUE_RESOLUTION_VARIANT_ON - : SunHints.VALUE_RESOLUTION_VARIANT_OFF); + ? RenderingHints.VALUE_RESOLUTION_VARIANT_DEFAULT + : RenderingHints.VALUE_RESOLUTION_VARIANT_BASE); } static void checkColor(int rgb, boolean isImageScaled) { @@ -468,8 +366,9 @@ } static void generateImage(int scale) throws Exception { - BufferedImage image = new BufferedImage(scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT, - BufferedImage.TYPE_INT_RGB); + BufferedImage image = new BufferedImage( + scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT, + BufferedImage.TYPE_INT_RGB); Graphics g = image.getGraphics(); g.setColor(scale == 1 ? COLOR_1X : COLOR_2X); g.fillRect(0, 0, scale * IMAGE_WIDTH, scale * IMAGE_HEIGHT); @@ -493,7 +392,7 @@ } throw new RuntimeException("Test name " + testName - + ", result name: " + resultName); + + ", result name: " + resultName); } for (URL[] testURLs : TEST_URLS) { @@ -510,7 +409,7 @@ } throw new RuntimeException("Test url: " + testURL - + ", result url: " + resultURL); + + ", result url: " + resultURL); } } @@ -521,19 +420,22 @@ } static String getTestScaledImageName(String name) throws Exception { - Method method = getScalableImageMethod("getScaledImageName", String.class); + Method method = getScalableImageMethod( + "getScaledImageName", String.class); return (String) method.invoke(null, name); } private static boolean isValidPath(String path) { return !path.isEmpty() && !path.endsWith("/") && !path.endsWith(".") - && !path.contains("@2x"); + && !path.contains("@2x"); } private static Method getScalableImageMethod(String name, - Class... parameterTypes) throws Exception { + Class... parameterTypes) throws Exception { Toolkit toolkit = Toolkit.getDefaultToolkit(); - Method method = toolkit.getClass().getDeclaredMethod(name, parameterTypes); + Method method = toolkit.getClass() + . + getDeclaredMethod(name, parameterTypes); method.setAccessible(true); return method; } @@ -604,9 +506,11 @@ {new URL("jar:file:/dir/Java2D.jar!/images/image.ext"), new URL("jar:file:/dir/Java2D.jar!/images/image@2x.ext")}, {new URL("jar:file:/aaa.bbb/Java2D.jar!/images/image.ext"), - new URL("jar:file:/aaa.bbb/Java2D.jar!/images/image@2x.ext")}, + new URL("jar:file:/aaa.bbb/Java2D.jar!/" + + "images/image@2x.ext")}, {new URL("jar:file:/dir/Java2D.jar!/aaa.bbb/image.ext"), - new URL("jar:file:/dir/Java2D.jar!/aaa.bbb/image@2x.ext")},}; + new URL("jar:file:/dir/Java2D.jar!/" + + "aaa.bbb/image@2x.ext")},}; } catch (Exception e) { throw new RuntimeException(e); } @@ -615,7 +519,8 @@ static class PreloadedImageObserver implements ImageObserver { @Override - public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + public boolean imageUpdate(Image img, int infoflags, int x, int y, + int width, int height) { throw new RuntimeException("Image should be already preloaded"); } }
--- a/test/java/awt/image/RescaleOp/RescaleAlphaTest.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/awt/image/RescaleOp/RescaleAlphaTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -22,8 +22,8 @@ */ /** * @test - * @bug 8080287 - * @run RescaleAlphaTest + * @bug 8080287 8136354 + * @run main RescaleAlphaTest * @summary RescaleOp with scaleFactor/alpha should copy alpha to destination * channel */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/image/multiresolution/BaseMultiResolutionImageTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,204 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import java.awt.Dimension; +import java.awt.Image; +import java.awt.image.BufferedImage; +import java.awt.image.BaseMultiResolutionImage; +import java.awt.image.MultiResolutionImage; +import java.util.List; + +/** + * @test + * @bug 8029339 + * @author Alexander Scherbatiy + * @summary Custom MultiResolution image support on HiDPI displays + * @run main BaseMultiResolutionImageTest + */ +public class BaseMultiResolutionImageTest { + + public static void main(String[] args) { + testZeroRVIMages(); + testNullRVIMages(); + testNullRVIMage(); + testIOOBException(); + testRVSizes(); + testBaseMRImage(); + } + + static void testZeroRVIMages() { + try { + new BaseMultiResolutionImage(); + } catch (IllegalArgumentException ignored) { + return; + } + throw new RuntimeException("IllegalArgumentException is not thrown!"); + } + + static void testNullRVIMages() { + try { + new BaseMultiResolutionImage(null); + } catch (IllegalArgumentException ignored) { + return; + } + throw new RuntimeException("IllegalArgumentException is not thrown!"); + } + + static void testNullRVIMage() { + + Image baseImage = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); + + try { + new BaseMultiResolutionImage(baseImage, null); + } catch (NullPointerException ignored) { + return; + } + throw new RuntimeException("NullPointerException is not thrown!"); + } + + static void testIOOBException() { + + for (int baseImageIndex : new int[]{-3, 2, 4}) { + try { + new BaseMultiResolutionImage(baseImageIndex, + createRVImage(0), createRVImage(1)); + } catch (IndexOutOfBoundsException ignored) { + continue; + } + + throw new RuntimeException("IndexOutOfBoundsException is not thrown!"); + } + } + + static void testRVSizes() { + + int imageSize = getSize(1); + + double[][] sizeArray = { + {-imageSize, imageSize}, + {2 * imageSize, -2 * imageSize}, + {Double.POSITIVE_INFINITY, imageSize}, + {Double.POSITIVE_INFINITY, -imageSize}, + {imageSize, Double.NEGATIVE_INFINITY}, + {-imageSize, Double.NEGATIVE_INFINITY}, + {Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY}, + {Double.NaN, imageSize}, + {imageSize, Double.NaN}, + {Double.NaN, Double.NaN}, + {Double.POSITIVE_INFINITY, Double.NaN} + }; + + for (double[] sizes : sizeArray) { + try { + MultiResolutionImage mrImage = new BaseMultiResolutionImage( + 0, createRVImage(0), createRVImage(1)); + mrImage.getResolutionVariant(sizes[0], sizes[1]); + } catch (IllegalArgumentException ignored) { + continue; + } + + throw new RuntimeException("IllegalArgumentException is not thrown!"); + } + } + + static void testBaseMRImage() { + int baseIndex = 1; + int length = 3; + BufferedImage[] resolutionVariants = new BufferedImage[length]; + for (int i = 0; i < length; i++) { + resolutionVariants[i] = createRVImage(i); + } + + BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage(baseIndex, + resolutionVariants); + + List<Image> rvImageList = mrImage.getResolutionVariants(); + if (rvImageList.size() != length) { + throw new RuntimeException("Wrong size of resolution variants list!"); + } + + for (int i = 0; i < length; i++) { + int imageSize = getSize(i); + Image testRVImage = mrImage.getResolutionVariant(imageSize, imageSize); + + if (testRVImage != resolutionVariants[i]) { + throw new RuntimeException("Wrong resolution variant!"); + } + + if (rvImageList.get(i) != resolutionVariants[i]) { + throw new RuntimeException("Wrong resolution variant!"); + } + } + + BufferedImage baseImage = resolutionVariants[baseIndex]; + + if (baseImage.getWidth() != mrImage.getWidth(null) + || baseImage.getHeight() != mrImage.getHeight(null)) { + throw new RuntimeException("Base image is wrong!"); + } + + boolean passed = false; + + try { + rvImageList.set(0, createRVImage(10)); + } catch (Exception e) { + passed = true; + } + + if (!passed) { + throw new RuntimeException("Resolution variants list is modifiable!"); + } + + passed = false; + + try { + rvImageList.remove(0); + } catch (Exception e) { + passed = true; + } + + if (!passed) { + throw new RuntimeException("Resolution variants list is modifiable!"); + } + + passed = false; + + try { + rvImageList.add(0, createRVImage(10)); + } catch (Exception e) { + passed = true; + } + + if (!passed) { + throw new RuntimeException("Resolution variants list is modifiable!"); + } + } + + private static int getSize(int i) { + return 8 * (i + 1); + } + + private static BufferedImage createRVImage(int i) { + return new BufferedImage(getSize(i), getSize(i), + BufferedImage.TYPE_INT_RGB); + } +}
--- a/test/java/awt/image/multiresolution/MultiResolutionCachedImageTest.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/awt/image/multiresolution/MultiResolutionCachedImageTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -98,7 +98,7 @@ } @Override - public Image getResolutionVariant(int width, int height) { + public Image getResolutionVariant(double width, double height) { if (width == size || height == size) { throw new RuntimeException("Base image is requested!"); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/image/multiresolution/MultiResolutionRenderingHintsTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,218 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import java.awt.Color; +import java.awt.Graphics; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.Image; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.awt.image.BaseMultiResolutionImage; +import static java.awt.RenderingHints.KEY_RESOLUTION_VARIANT; +import static java.awt.RenderingHints.VALUE_RESOLUTION_VARIANT_BASE; +import static java.awt.RenderingHints.VALUE_RESOLUTION_VARIANT_DPI_FIT; +import static java.awt.RenderingHints.VALUE_RESOLUTION_VARIANT_SIZE_FIT; +import static java.awt.RenderingHints.VALUE_RESOLUTION_VARIANT_DEFAULT; +import java.awt.geom.AffineTransform; +import java.awt.image.ColorModel; +import java.awt.image.Raster; +import sun.java2d.StateTrackable; +import sun.java2d.SunGraphics2D; +import sun.java2d.SurfaceData; +import sun.java2d.loops.SurfaceType; + +/** + * @test + * @bug 8029339 + * @author Alexander Scherbatiy + * @summary Custom MultiResolution image support on HiDPI displays + * @modules java.desktop/sun.java2d + * @run main MultiResolutionRenderingHintsTest + */ +public class MultiResolutionRenderingHintsTest { + + private static final int BASE_SIZE = 200; + private static final Color[] COLORS = { + Color.CYAN, Color.GREEN, Color.BLUE, Color.ORANGE, Color.RED, Color.PINK + }; + + public static void main(String[] args) throws Exception { + + int length = COLORS.length; + BufferedImage[] resolutionVariants = new BufferedImage[length]; + for (int i = 0; i < length; i++) { + resolutionVariants[i] = createRVImage(getSize(i), COLORS[i]); + } + + BaseMultiResolutionImage mrImage = new BaseMultiResolutionImage( + resolutionVariants); + + // base + Color color = getImageColor(VALUE_RESOLUTION_VARIANT_BASE, mrImage, 2, 3); + if (!getColorForScale(1).equals(color)) { + throw new RuntimeException("Wrong base resolution variant!"); + } + + // dpi fit + color = getImageColor(VALUE_RESOLUTION_VARIANT_DPI_FIT, mrImage, 2, 3); + if (!getColorForScale(2).equals(color)) { + throw new RuntimeException("Resolution variant is not based on dpi!"); + } + + // size fit + color = getImageColor(VALUE_RESOLUTION_VARIANT_SIZE_FIT, mrImage, 2, 3); + if (!getColorForScale(6).equals(color)) { + throw new RuntimeException("Resolution variant is not based on" + + " rendered size!"); + } + + // default + // depends on the policies of the platform + // just check that exception is not thrown + getImageColor(VALUE_RESOLUTION_VARIANT_DEFAULT, mrImage, 2, 3); + } + + private static Color getColorForScale(int scale) { + return COLORS[scale - 1]; + } + + private static Color getImageColor(final Object renderingHint, Image image, + double configScale, double graphicsScale) { + + int width = image.getWidth(null); + int height = image.getHeight(null); + + TestSurfaceData surface = new TestSurfaceData(width, height, configScale); + SunGraphics2D g2d = new SunGraphics2D(surface, + Color.BLACK, Color.BLACK, null); + g2d.setRenderingHint(KEY_RESOLUTION_VARIANT, renderingHint); + g2d.scale(graphicsScale, graphicsScale); + g2d.drawImage(image, 0, 0, null); + g2d.dispose(); + return surface.getColor(width / 2, height / 2); + } + + private static int getSize(int i) { + return (i + 1) * BASE_SIZE; + } + + private static BufferedImage createRVImage(int size, Color color) { + BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_RGB); + Graphics g = image.createGraphics(); + g.setColor(Color.BLACK); + g.fillRect(0, 0, size, size); + g.setColor(color); + g.fillOval(0, 0, size, size); + g.dispose(); + return image; + } + + static class TestGraphicsConfig extends GraphicsConfiguration { + + private final double scale; + + TestGraphicsConfig(double scale) { + this.scale = scale; + } + + @Override + public GraphicsDevice getDevice() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ColorModel getColorModel() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public ColorModel getColorModel(int transparency) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public AffineTransform getDefaultTransform() { + return AffineTransform.getScaleInstance(scale, scale); + } + + @Override + public AffineTransform getNormalizingTransform() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Rectangle getBounds() { + throw new UnsupportedOperationException("Not supported yet."); + } + } + + static class TestSurfaceData extends SurfaceData { + + private final int width; + private final int height; + private final GraphicsConfiguration gc; + private final BufferedImage buffImage; + private final double scale; + + public TestSurfaceData(int width, int height, double scale) { + super(StateTrackable.State.DYNAMIC, SurfaceType.Custom, ColorModel.getRGBdefault()); + this.scale = scale; + gc = new TestGraphicsConfig(scale); + this.width = (int) Math.ceil(scale * width); + this.height = (int) Math.ceil(scale * height); + buffImage = new BufferedImage(this.width, this.height, + BufferedImage.TYPE_INT_RGB); + } + + Color getColor(int x, int y) { + int sx = (int) Math.ceil(x * scale); + int sy = (int) Math.ceil(y * scale); + return new Color(buffImage.getRGB(sx, sy)); + } + + @Override + public SurfaceData getReplacement() { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public GraphicsConfiguration getDeviceConfiguration() { + return gc; + } + + @Override + public Raster getRaster(int x, int y, int w, int h) { + return buffImage.getRaster(); + } + + @Override + public Rectangle getBounds() { + return new Rectangle(0, 0, width, height); + } + + @Override + public Object getDestination() { + throw new UnsupportedOperationException("Not supported yet."); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/beans/XMLEncoder/ReferenceToNonStaticField.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,164 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.awt.font.TextAttribute; + +/** + * @test + * @bug 8060027 + */ +public final class ReferenceToNonStaticField + extends AbstractTest<ReferenceToNonStaticField.TestValue> { + + public static final class TestValue { + + // reference to static field + public TextAttribute font_default = TextAttribute.FONT; + public TextAttribute family_default = TextAttribute.FAMILY; + public TextAttribute family_set1; // will be set to the same as default + public TextAttribute family_set2; // will be set to the same as default + public TextAttribute family_set3; // will be set to the same as default + + // primitive small + public int int_1_default = 1; + public int int_10_default = 10; + public int int_10_set1; // will be set to the same as default + public int int_10_set2; // will be set to the same as default + public int int_10_set3; // will be set to the same as default + + // primitive big + public int int_1000_default = 1000; + public int int_2000_default = 2000; + public int int_2000_set1; // will be set to the same as default + public int int_2000_set2; // will be set to the same as default + public int int_2000_set3; // will be set to the same as default + + // wrappers + public Integer integer_1_default = new Integer(1); + public Integer integer_10_default = new Integer(10); + public Integer integer_10_set1; // will be set to the same as default + public Integer integer_10_set2; // will be set to the same as default + public Integer integer_10_set3; // will be set to the same as default + + public TestValue() { + } + + public TestValue(final Object ignored) { + // set some fields to non-default values, so they will be saved + family_set1 = family_default; + family_set3 = family_default; + family_set2 = family_default; + int_10_set1 = int_10_default; + int_10_set2 = int_10_default; + int_10_set3 = int_10_default; + int_2000_set1 = int_2000_default; + int_2000_set2 = int_2000_default; + int_2000_set3 = int_2000_default; + integer_10_set1 = integer_10_default; + integer_10_set2 = integer_10_default; + integer_10_set3 = integer_10_default; + } + } + + public static void main(final String[] args) { + new ReferenceToNonStaticField().test(true); + } + + protected TestValue getObject() { + return new TestValue(new Object()); + } + + @Override + protected void validate(final TestValue before,final TestValue after) { + super.validate(before, after); + validate(before); + validate(after); + } + + private static void validate(final TestValue object) { + // reference to static field + if (object.font_default != TextAttribute.FONT) { + throw new Error("Wrong font_default: " + object.font_default); + } + if (object.family_default != TextAttribute.FAMILY) { + throw new Error("Wrong family_default: " + object.family_default); + } + if (object.family_set1 != object.family_default) { + throw new Error("Wrong family_set1: " + object.family_set1); + } + if (object.family_set2 != object.family_default) { + throw new Error("Wrong family_set2: " + object.family_set2); + } + if (object.family_set3 != object.family_default) { + throw new Error("Wrong family_set3: " + object.family_set3); + } + // primitive small + if (object.int_1_default != 1) { + throw new Error("Wrong int_1_default: " + object.int_1_default); + } + if (object.int_10_default != 10) { + throw new Error("Wrong int_10_default: " + object.int_10_default); + } + if (object.int_10_set1 != object.int_10_default) { + throw new Error("Wrong int_10_set1: " + object.int_10_set1); + } + if (object.int_10_set2 != object.int_10_default) { + throw new Error("Wrong int_10_set2: " + object.int_10_set2); + } + if (object.int_10_set3 != object.int_10_default) { + throw new Error("Wrong int_10_set3: " + object.int_10_set3); + } + // primitive big + if (object.int_1000_default != 1000) { + throw new Error("Wrong int_1000_default: " + object.int_1000_default); + } + if (object.int_2000_default != 2000) { + throw new Error("Wrong int_2000_default: " + object.int_2000_default); + } + if (object.int_2000_set1 != object.int_2000_default) { + throw new Error("Wrong int_2000_set1: " + object.int_2000_set1); + } + if (object.int_2000_set2 != object.int_2000_default) { + throw new Error("Wrong int_2000_set2: " + object.int_2000_set2); + } + if (object.int_2000_set3 != object.int_2000_default) { + throw new Error("Wrong int_2000_set3: " + object.int_2000_set3); + } + // wrappers + if (!object.integer_1_default.equals(new Integer(1))) { + throw new Error("Wrong integer_1_default: " + object.integer_1_default); + } + if (!object.integer_10_default.equals(new Integer(10))) { + throw new Error("Wrong integer_10_default: " + object.integer_10_default); + } + if (object.integer_10_set1 != object.integer_10_default) { + throw new Error("Wrong integer_10_set1: " + object.integer_10_set1); + } + if (object.integer_10_set2 != object.integer_10_default) { + throw new Error("Wrong integer_10_set2: " + object.integer_10_set2); + } + if (object.integer_10_set3 != object.integer_10_default) { + throw new Error("Wrong integer_10_set3: " + object.integer_10_set3); + } + } +}
--- a/test/java/lang/Math/PowTests.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/lang/Math/PowTests.java Tue Sep 22 11:01:54 2015 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -23,7 +23,7 @@ /* * @test - * @bug 4984407 5033578 + * @bug 4984407 5033578 8134795 * @summary Tests for {Math, StrictMath}.pow * @author Joseph D. Darcy */ @@ -88,12 +88,19 @@ /* > -oo */ -Double.MAX_VALUE, /**/ (double)Long.MIN_VALUE, /**/ (double) -((1L<<53)+2L), + -0x1.0p65, + -0x1.0000000000001p64, + -0x1.0p64, /**/ (double) -((1L<<53)), /**/ (double) -((1L<<53)-1L), /**/ -((double)Integer.MAX_VALUE + 4.0), /**/ (double)Integer.MIN_VALUE - 1.0, /**/ (double)Integer.MIN_VALUE, /**/ (double)Integer.MIN_VALUE + 1.0, + -0x1.0p31 + 2.0, + -0x1.0p31 + 1.0, + -0x1.0000000000001p31, + -0x1.0p31, /**/ -Math.PI, /**/ -3.0, /**/ -Math.E, @@ -103,6 +110,8 @@ -1.0, /* > -1.0 */ -0.9999999999999999, // nextAfter(-1.0, +oo) /* > -1.0 */ -0.9999999999999998, + -0x1.fffffp-1, + -0x1.ffffeffffffffp-1, /**/ -0.5, /**/ -1.0/3.0, /* < 0.0 */ -Double.MIN_VALUE, @@ -111,6 +120,8 @@ /* > 0.0 */ +Double.MIN_VALUE, /**/ +1.0/3.0, /**/ +0.5, + +0x1.ffffeffffffffp-1, + +0x1.fffffp-1, /**/ +0.9999999999999998, /* < +1.0 */ +0.9999999999999999, // nextAfter(-1.0, +oo) +1.0, @@ -120,6 +131,10 @@ /**/ +Math.E, /**/ +3.0, /**/ +Math.PI, + 0x1.0p31, + 0x1.0000000000001p31, + 0x1.0p31 + 1.0, + 0x1.0p31 + 2.0, /**/ -(double)Integer.MIN_VALUE - 1.0, /**/ -(double)Integer.MIN_VALUE, /**/ -(double)Integer.MIN_VALUE + 1.0, @@ -127,6 +142,9 @@ /**/ (double) ((1L<<53)-1L), /**/ (double) ((1L<<53)), /**/ (double) ((1L<<53)+2L), + 0x1.0p64, + 0x1.0000000000001p64, + 0x1.0p65, /**/ -(double)Long.MIN_VALUE, /* < oo */ Double.MAX_VALUE, Double.POSITIVE_INFINITY, @@ -257,7 +275,7 @@ } static boolean isFinite(double a) { - return (0.0*a == 0); + return (0.0 * a == 0); } /**
--- a/test/java/lang/ProcessHandle/OnExitTest.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/lang/ProcessHandle/OnExitTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -96,8 +96,6 @@ ConcurrentHashMap<ProcessHandle, ProcessHandle> processes = new ConcurrentHashMap<>(); List<ProcessHandle> children = getChildren(ProcessHandle.current()); children.forEach(ProcessUtil::printProcess); - Assert.assertEquals(children.size(), 0, - "Expected to start with zero children; " + children); JavaChild proc = JavaChild.spawnJavaChild("stdin"); procHandle = proc.toHandle(); @@ -186,10 +184,6 @@ children.forEach(p -> printProcess(p, "after onExit:")); Assert.assertEquals(proc.isAlive(), false, "destroyed process is alive:: %s%n" + proc); - - List<ProcessHandle> children2 = getAllChildren(procHandle); - printf(" children2: %s%n", children2.toString()); - Assert.assertEquals(children2.size(), 0, "After onExit, expected no children"); } catch (IOException | InterruptedException ex) { Assert.fail(ex.getMessage()); } finally {
--- a/test/java/lang/ProcessHandle/TreeTest.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/lang/ProcessHandle/TreeTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -29,6 +29,7 @@ import java.util.Arrays; import java.util.List; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -67,8 +68,6 @@ printf("self pid: %d%n", self.getPid()); printDeep(self, ""); - long count = getChildren(self).size(); - Assert.assertEquals(count, 0, "Start with zero children"); for (int i = 0; i < MAXCHILDREN; i++) { // spawn and wait for instructions @@ -124,8 +123,10 @@ spawned.stream() .map(Process::toHandle) .filter(ProcessHandle::isAlive) - .forEach(ph -> printDeep(ph, "test1 cleanup: ")); - destroyProcessTree(ProcessHandle.current()); + .forEach(ph -> { + printDeep(ph, "test1 cleanup: "); + ph.destroyForcibly(); + }); } } @@ -135,18 +136,29 @@ @Test public static void test2() { try { + ConcurrentHashMap<ProcessHandle, ProcessHandle> processes = new ConcurrentHashMap<>(); + ProcessHandle self = ProcessHandle.current(); List<ProcessHandle> initialChildren = getChildren(self); long count = initialChildren.size(); if (count > 0) { initialChildren.forEach(p -> printDeep(p, "test2 initial unexpected: ")); - Assert.assertEquals(count, 0, "Start with zero children (except Windows conhost.exe)"); } JavaChild p1 = JavaChild.spawnJavaChild("stdin"); ProcessHandle p1Handle = p1.toHandle(); printf(" p1 pid: %d%n", p1.getPid()); + // Gather the PIDs from the output of the spawing process + p1.forEachOutputLine((s) -> { + String[] split = s.trim().split(" "); + if (split.length == 3 && split[1].equals("spawn")) { + Long child = Long.valueOf(split[2]); + Long parent = Long.valueOf(split[0].split(":")[0]); + processes.put(ProcessHandle.of(child).get(), ProcessHandle.of(parent).get()); + } + }); + int spawnNew = 3; p1.sendAction("spawn", spawnNew, "stdin"); @@ -160,18 +172,33 @@ int spawnNewSub = 2; p1.sendAction("child", "spawn", spawnNewSub, "stdin"); - // For each spawned child, wait for its children - for (ProcessHandle p : subprocesses) { - List<ProcessHandle> grandChildren = waitForChildren(p, spawnNewSub); + // Poll until all 9 child processes exist or the timeout is reached + int expected = 9; + long timeout = jdk.testlibrary.Utils.adjustTimeout(10L); + Instant endTimeout = Instant.now().plusSeconds(timeout); + do { + Thread.sleep(200L); + printf(" subprocess count: %d, waiting for %d%n", processes.size(), expected); + } while (processes.size() < expected && + Instant.now().isBefore(endTimeout)); + + if (processes.size() < expected) { + printf("WARNING: not all children have been started. Can't complete test.%n"); + printf(" You can try to increase the timeout or%n"); + printf(" you can try to use a faster VM (i.e. not a debug version).%n"); } + // show the complete list of children (for debug) List<ProcessHandle> allChildren = getAllChildren(p1Handle); printf(" allChildren: %s%n", allChildren.stream().map(p -> p.getPid()) .collect(Collectors.toList())); - for (ProcessHandle ph : allChildren) { - Assert.assertEquals(ph.isAlive(), true, "Child should be alive: " + ph); - } + + // Verify that all spawned children show up in the allChildrenList + processes.forEach((p, parent) -> { + Assert.assertEquals(p.isAlive(), true, "Child should be alive: " + p); + Assert.assertTrue(allChildren.contains(p), "Spawned child should be listed in allChildren: " + p); + }); // Closing JavaChild's InputStream will cause all children to exit p1.getOutputStream().close(); @@ -185,15 +212,12 @@ } p1.waitFor(); // wait for spawned process to exit - List<ProcessHandle> remaining = getChildren(self); - remaining.forEach(ph -> Assert.assertFalse(ph.isAlive(), + // Verify spawned processes are no longer alive + processes.forEach((ph, parent) -> Assert.assertFalse(ph.isAlive(), "process should not be alive: " + ph)); } catch (IOException | InterruptedException t) { t.printStackTrace(); throw new RuntimeException(t); - } finally { - // Cleanup any left over processes - destroyProcessTree(ProcessHandle.current()); } } @@ -202,6 +226,8 @@ */ @Test public static void test3() { + ConcurrentHashMap<ProcessHandle, ProcessHandle> processes = new ConcurrentHashMap<>(); + try { ProcessHandle self = ProcessHandle.current(); @@ -209,44 +235,53 @@ ProcessHandle p1Handle = p1.toHandle(); printf(" p1: %s%n", p1.getPid()); - List<ProcessHandle> subprocesses = getChildren(self); - long count = subprocesses.size(); - Assert.assertEquals(count, 1, "Wrong number of spawned children"); - int newChildren = 3; // Spawn children and have them wait p1.sendAction("spawn", newChildren, "stdin"); + // Gather the PIDs from the output of the spawing process + p1.forEachOutputLine((s) -> { + String[] split = s.trim().split(" "); + if (split.length == 3 && split[1].equals("spawn")) { + Long child = Long.valueOf(split[2]); + Long parent = Long.valueOf(split[0].split(":")[0]); + processes.put(ProcessHandle.of(child).get(), ProcessHandle.of(parent).get()); + } + }); + // Wait for the new processes and save the list - subprocesses = waitForAllChildren(p1Handle, newChildren); - Assert.assertEquals(subprocesses.size(), newChildren, "Wrong number of children"); + List<ProcessHandle> allChildren = waitForAllChildren(p1Handle, newChildren); - p1.children().filter(TreeTest::isNotWindowsConsole) - .forEach(ProcessHandle::destroyForcibly); + // Verify that all spawned children are alive, show up in the allChildren list + // then destroy them + processes.forEach((p, parent) -> { + Assert.assertEquals(p.isAlive(), true, "Child should be alive: " + p); + Assert.assertTrue(allChildren.contains(p), "Spawned child should be listed in allChildren: " + p); + p.destroyForcibly(); + }); - self.children().filter(TreeTest::isNotWindowsConsole) - .forEach(ProcessHandle::destroyForcibly); - - for (ProcessHandle p : subprocesses) { + processes.forEach((p, parent) -> { while (p.isAlive()) { - Thread.sleep(100L); // It will happen but don't burn the cpu + try { + Thread.sleep(100L); // It will happen but don't burn the cpu + } catch (InterruptedException ie) { + // try again + } } - } + }); + p1.destroyForcibly(); + p1.waitFor(); List<ProcessHandle> remaining = getAllChildren(self); - remaining.retainAll(subprocesses); - if (remaining.size() > 0) { - remaining.forEach(p -> printProcess(p, " remaining: ")); - Assert.fail("Subprocess(es) should have exited"); - } + remaining = remaining.stream().filter(processes::contains).collect(Collectors.toList()); + Assert.assertEquals(remaining.size(), 0, "Subprocess(es) should have exited: " + remaining); } catch (IOException ioe) { Assert.fail("Spawn of subprocess failed", ioe); } catch (InterruptedException inte) { Assert.fail("InterruptedException", inte); } finally { - // Cleanup any left over processes - destroyProcessTree(ProcessHandle.current()); + processes.forEach((p, parent) -> p.destroyForcibly()); } } @@ -302,9 +337,10 @@ @Test public static void test5() { int factor = 2; + JavaChild p1 = null; Instant start = Instant.now(); try { - JavaChild p1 = JavaChild.spawnJavaChild("stdin"); + p1 = JavaChild.spawnJavaChild("stdin"); ProcessHandle p1Handle = p1.toHandle(); printf("Spawning %d x %d x %d processes, pid: %d%n", @@ -340,7 +376,9 @@ Assert.fail("Unexpected Exception", ex); } finally { printf("Duration: %s%n", Duration.between(start, Instant.now())); - destroyProcessTree(ProcessHandle.current()); + if (p1 != null) { + p1.destroyForcibly(); + } } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/security/KeyStore/CheckInputStream.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 8136534 + * @summary The input stream supplied to KeyStore.load should remain open. + */ + +import java.io.*; +import java.security.*; + +public class CheckInputStream { + private final static String DIR = System.getProperty("test.src", "."); + private static final char[] PASSWORD = "passphrase".toCharArray(); + private static final String KEYSTORE = DIR + "/keystore.jks"; + + public static final void main(String[] args) throws Exception { + + KeyStore keystore = KeyStore.getInstance("JKS"); + try (FileInputStream inStream = new FileInputStream(KEYSTORE)) { + System.out.println("Loading JKS keystore: " + KEYSTORE); + keystore.load(inStream, PASSWORD); + // check that the stream is still open + inStream.available(); + System.out.println("OK"); + } + } +}
--- a/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CountTest.java Thu Sep 17 09:19:40 2015 -0700 +++ b/test/java/util/stream/test/org/openjdk/tests/java/util/stream/CountTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -31,6 +31,7 @@ import java.util.HashSet; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import java.util.stream.DoubleStream; import java.util.stream.DoubleStreamTestDataProvider; import java.util.stream.IntStream; @@ -61,6 +62,12 @@ expectedResult(expectedCount). exercise(); + // Test counting collector + withData(data). + terminal(s -> s, s -> s.collect(Collectors.counting())). + expectedResult(expectedCount). + exercise(); + // Test with stateful distinct op that is a barrier or lazy // depending if source is not already distinct and encounter order is // preserved or not
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/security/auth/login/JAASConfigSyntaxCheck/JAASConfigSyntaxTest.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,57 @@ + +/** + * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License version 2 only, as published by + * the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more + * details (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License version 2 + * along with this work; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA or + * visit www.oracle.com if you need additional information or have any + * questions. + */ + +import javax.security.auth.login.LoginContext; + +/** + * @test + * @bug 8050461 + * @summary Test should throw Configuration error if configuration file contains + * syntax error + * @build SampleLoginModule JAASConfigSyntaxTest + * @run main/othervm -Djava.security.auth.login.config=file:${test.src}/JAASSynWithOutApplication.config JAASConfigSyntaxTest + * @run main/othervm -Djava.security.auth.login.config=file:${test.src}/JAASSynWithOutBraces.config JAASConfigSyntaxTest + * @run main/othervm -Djava.security.auth.login.config=file:${test.src}/JAASSynWithOutFlag.config JAASConfigSyntaxTest + * @run main/othervm -Djava.security.auth.login.config=file:${test.src}/JAASSynWithOutLoginModule.config JAASConfigSyntaxTest + * @run main/othervm -Djava.security.auth.login.config=file:${test.src}/JAASSynWithOutSemiColen.config JAASConfigSyntaxTest + */ +public class JAASConfigSyntaxTest { + + private static final String TEST_NAME = "JAASConfigSyntaxTest"; + + public static void main(String[] args) throws Exception { + try { + LoginContext lc = new LoginContext(TEST_NAME); + lc.login(); + throw new RuntimeException("Test Case Failed, did not get " + + "expected exception"); + } catch (Exception ex) { + if (ex.getMessage().contains("java.io.IOException: " + + "Configuration Error:")) { + System.out.println("Test case passed"); + } else { + throw new RuntimeException(ex); + } + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/security/auth/login/JAASConfigSyntaxCheck/JAASSynWithOutApplication.config Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,5 @@ +{ +SampleLoginModule Required; +SampleLoginModule Required; +SampleLoginModule Required; +}; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/security/auth/login/JAASConfigSyntaxCheck/JAASSynWithOutBraces.config Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,5 @@ +JAASConfigSyntaxTest +SampleLoginModule Required; +SampleLoginModule Required; +SampleLoginModule Required; +; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/security/auth/login/JAASConfigSyntaxCheck/JAASSynWithOutFlag.config Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,5 @@ +JAASConfigSyntaxTest{ +SampleLoginModule ; +SampleLoginModule ; +SampleLoginModule ; +}; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/security/auth/login/JAASConfigSyntaxCheck/JAASSynWithOutLoginModule.config Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,5 @@ +JAASConfigSyntaxTest{ +; +; +; +}; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/security/auth/login/JAASConfigSyntaxCheck/JAASSynWithOutSemiColen.config Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,5 @@ +JAASConfigSyntaxTest{ +SampleLoginModule Required; +SampleLoginModule Required +SampleLoginModule Required; +}; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/security/auth/login/JAASConfigSyntaxCheck/SampleLoginModule.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License version 2 only, as published by + * the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + * A PARTICULAR PURPOSE. See the GNU General Public License version 2 for more + * details (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU General Public License version 2 + * along with this work; if not, write to the Free Software Foundation, Inc., 51 + * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA or + * visit www.oracle.com if you need additional information or have any + * questions. + */ + +import static java.lang.System.out; +import java.util.Map; +import javax.security.auth.Subject; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.login.LoginException; +import javax.security.auth.spi.LoginModule; + +/** + * Login module which passes all the time + */ + +public class SampleLoginModule implements LoginModule { + + private final String name; + + public SampleLoginModule() { + name = this.getClass().getName(); + } + + @Override + public void initialize(Subject subject, CallbackHandler callbackHandler, + Map<String, ?> sharedState, Map<String, ?> options) { + } + + @Override + public boolean login() throws LoginException { + out.println(name + " Login method of AbstractLoginModule is called "); + out.println(name + ":login:PASS"); + return true; + } + + @Override + public boolean commit() throws LoginException { + out.println("Commit of AbstractLoginModule is called"); + out.println(name + ":commit:PASS"); + return true; + + } + + @Override + public boolean abort() throws LoginException { + out.println("Abourt is called in AbstractLoginModule"); + out.println(name + ":abort:PASS"); + return true; + } + + @Override + public boolean logout() throws LoginException { + out.println("logout is called in AbstractLoginModule"); + out.println(name + ":logout:PASS"); + return true; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/javax/sound/sampled/FileReader/RepeatedFormatReader.java Tue Sep 22 11:01:54 2015 -0700 @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; + +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.UnsupportedAudioFileException; + +/** + * @test + * @bug 8133677 + * @summary Subsequent read from the same stream should work + */ +public final class RepeatedFormatReader { + + // Stubs + + private static byte[] headerMIDI = {0x4d, 0x54, 0x68, 0x64, // MThd + 0, 0, 0, 6, // read header length + 0, 0, // type + 0, 0, // numtracks + 0, 1, // timing + }; + + private